courrier multi account restore compose
This commit is contained in:
parent
427392f0d0
commit
5152f9ded0
@ -198,11 +198,8 @@ export default function CourrierPage() {
|
||||
|
||||
// Count unread emails for each account and folder
|
||||
(emails || []).forEach(email => {
|
||||
// Access the 'read' property safely, handling both old and new email formats
|
||||
const emailWithFlags = email as unknown as EmailWithFlags;
|
||||
const isUnread = (!emailWithFlags.read && emailWithFlags.read !== undefined) ||
|
||||
(emailWithFlags.flags && !emailWithFlags.flags.seen) ||
|
||||
false;
|
||||
// Check if email is unread based on flags
|
||||
const isUnread = email.flags && !email.flags.seen;
|
||||
|
||||
// Count unread emails for the specific account and folder
|
||||
if (isUnread && email.accountId && email.folder) {
|
||||
|
||||
@ -3,11 +3,7 @@ import { useSession } from 'next-auth/react';
|
||||
import { useToast } from './use-toast';
|
||||
import { formatEmailForReplyOrForward } from '@/lib/utils/email-formatter';
|
||||
import { getCachedEmailsWithTimeout, refreshEmailsInBackground } from '@/lib/services/prefetch-service';
|
||||
|
||||
export interface EmailAddress {
|
||||
name: string;
|
||||
address: string;
|
||||
}
|
||||
import { EmailAddress, EmailAttachment } from '@/lib/types';
|
||||
|
||||
export interface Email {
|
||||
id: string;
|
||||
@ -16,16 +12,26 @@ export interface Email {
|
||||
cc?: EmailAddress[];
|
||||
bcc?: EmailAddress[];
|
||||
subject: string;
|
||||
content: string;
|
||||
content: {
|
||||
text: string;
|
||||
html: string;
|
||||
};
|
||||
preview?: string;
|
||||
date: string;
|
||||
read: boolean;
|
||||
starred: boolean;
|
||||
attachments?: { filename: string; contentType: string; size: number; content?: string }[];
|
||||
folder: string;
|
||||
date: Date;
|
||||
flags: {
|
||||
seen: boolean;
|
||||
answered: boolean;
|
||||
flagged: boolean;
|
||||
draft: boolean;
|
||||
deleted: boolean;
|
||||
};
|
||||
size: number;
|
||||
hasAttachments: boolean;
|
||||
contentFetched?: boolean;
|
||||
folder: string;
|
||||
contentFetched: boolean;
|
||||
accountId?: string;
|
||||
messageId?: string;
|
||||
attachments?: EmailAttachment[];
|
||||
}
|
||||
|
||||
export interface EmailListResult {
|
||||
@ -311,7 +317,7 @@ export const useCourrier = () => {
|
||||
}
|
||||
|
||||
// Mark the email as read if it's not already
|
||||
if (!email.read) {
|
||||
if (!email.flags.seen) {
|
||||
markEmailAsRead(emailId, true);
|
||||
}
|
||||
} catch (err) {
|
||||
@ -346,12 +352,12 @@ export const useCourrier = () => {
|
||||
|
||||
// Update the email in the list
|
||||
setEmails(emails.map(email =>
|
||||
email.id === emailId ? { ...email, read: isRead } : email
|
||||
email.id === emailId ? { ...email, flags: { ...email.flags, seen: isRead } } : email
|
||||
));
|
||||
|
||||
// If the selected email is the one being marked, update it too
|
||||
if (selectedEmail && selectedEmail.id === emailId) {
|
||||
setSelectedEmail({ ...selectedEmail, read: isRead });
|
||||
setSelectedEmail({ ...selectedEmail, flags: { ...selectedEmail.flags, seen: isRead } });
|
||||
}
|
||||
|
||||
return true;
|
||||
@ -366,7 +372,7 @@ export const useCourrier = () => {
|
||||
const email = emails.find(e => e.id === emailId);
|
||||
if (!email) return;
|
||||
|
||||
const newStarredStatus = !email.starred;
|
||||
const newStarredStatus = !email.flags.flagged;
|
||||
|
||||
try {
|
||||
const response = await fetch(`/api/courrier/${emailId}/star`, {
|
||||
@ -386,12 +392,12 @@ export const useCourrier = () => {
|
||||
|
||||
// Update the email in the list
|
||||
setEmails(emails.map(email =>
|
||||
email.id === emailId ? { ...email, starred: newStarredStatus } : email
|
||||
email.id === emailId ? { ...email, flags: { ...email.flags, flagged: newStarredStatus } } : email
|
||||
));
|
||||
|
||||
// If the selected email is the one being starred, update it too
|
||||
if (selectedEmail && selectedEmail.id === emailId) {
|
||||
setSelectedEmail({ ...selectedEmail, starred: newStarredStatus });
|
||||
setSelectedEmail({ ...selectedEmail, flags: { ...selectedEmail.flags, flagged: newStarredStatus } });
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error toggling star status:', error);
|
||||
@ -546,10 +552,17 @@ export const useCourrier = () => {
|
||||
}, [loadEmails]);
|
||||
|
||||
// Format an email for reply or forward
|
||||
const formatEmailForAction = useCallback((email: Email, type: 'reply' | 'reply-all' | 'forward') => {
|
||||
if (!email) return null;
|
||||
|
||||
return formatEmailForReplyOrForward(email, type);
|
||||
const formatEmailForAction = useCallback((email: Email) => {
|
||||
return {
|
||||
id: email.id,
|
||||
subject: email.subject,
|
||||
from: email.from[0]?.address || '',
|
||||
to: email.to.map(addr => addr.address).join(', '),
|
||||
cc: email.cc?.map(addr => addr.address).join(', '),
|
||||
bcc: email.bcc?.map(addr => addr.address).join(', '),
|
||||
content: email.content.text || email.content.html || '',
|
||||
attachments: email.attachments
|
||||
};
|
||||
}, []);
|
||||
|
||||
// Return all the functionality and state values
|
||||
|
||||
Loading…
Reference in New Issue
Block a user