courrier multi account restore compose
This commit is contained in:
parent
bd0a906796
commit
96fc0fe33e
@ -338,6 +338,64 @@ export const useEmailState = () => {
|
|||||||
payload: { emailId, isRead, accountId: effectiveAccountId }
|
payload: { emailId, isRead, accountId: effectiveAccountId }
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// If email is being marked as read, update the unread count for this folder
|
||||||
|
if (isRead && email && !email.flags.seen) {
|
||||||
|
// Get current count for this folder
|
||||||
|
const currentCount = state.unreadCountMap[effectiveAccountId]?.[normalizedFolder] || 0;
|
||||||
|
if (currentCount > 0) {
|
||||||
|
// Decrement the unread count (minimum 0)
|
||||||
|
dispatch({
|
||||||
|
type: 'UPDATE_UNREAD_COUNT',
|
||||||
|
payload: {
|
||||||
|
accountId: effectiveAccountId,
|
||||||
|
folder: normalizedFolder,
|
||||||
|
count: Math.max(0, currentCount - 1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also update the prefixed version if needed
|
||||||
|
const prefixedFolder = `${effectiveAccountId}:${normalizedFolder}`;
|
||||||
|
const prefixedCount = state.unreadCountMap[effectiveAccountId]?.[prefixedFolder] || 0;
|
||||||
|
if (prefixedCount > 0) {
|
||||||
|
dispatch({
|
||||||
|
type: 'UPDATE_UNREAD_COUNT',
|
||||||
|
payload: {
|
||||||
|
accountId: effectiveAccountId,
|
||||||
|
folder: prefixedFolder,
|
||||||
|
count: Math.max(0, prefixedCount - 1)
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// If email is being marked as unread, increment the count
|
||||||
|
else if (!isRead && email && email.flags.seen) {
|
||||||
|
// Get current count for this folder
|
||||||
|
const currentCount = state.unreadCountMap[effectiveAccountId]?.[normalizedFolder] || 0;
|
||||||
|
|
||||||
|
// Increment the unread count
|
||||||
|
dispatch({
|
||||||
|
type: 'UPDATE_UNREAD_COUNT',
|
||||||
|
payload: {
|
||||||
|
accountId: effectiveAccountId,
|
||||||
|
folder: normalizedFolder,
|
||||||
|
count: currentCount + 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Also update the prefixed version
|
||||||
|
const prefixedFolder = `${effectiveAccountId}:${normalizedFolder}`;
|
||||||
|
const prefixedCount = state.unreadCountMap[effectiveAccountId]?.[prefixedFolder] || 0;
|
||||||
|
dispatch({
|
||||||
|
type: 'UPDATE_UNREAD_COUNT',
|
||||||
|
payload: {
|
||||||
|
accountId: effectiveAccountId,
|
||||||
|
folder: prefixedFolder,
|
||||||
|
count: prefixedCount + 1
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
// Make API call to update on server
|
// Make API call to update on server
|
||||||
const response = await fetch(`/api/courrier/${emailId}/mark-read`, {
|
const response = await fetch(`/api/courrier/${emailId}/mark-read`, {
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user