fix: empty Trash for shared and group folders #387
This commit is contained in:
@@ -329,7 +329,7 @@ export class DemoJMAPClient implements IJMAPClient {
|
||||
this.recalcMailboxCounts();
|
||||
}
|
||||
|
||||
async emptyMailbox(mailboxId: string): Promise<number> {
|
||||
async emptyMailbox(mailboxId: string, _accountId?: string): Promise<number> {
|
||||
const before = this.data.emails.length;
|
||||
this.data.emails = this.data.emails.filter(e => !e.mailboxIds[mailboxId]);
|
||||
const removed = before - this.data.emails.length;
|
||||
|
||||
@@ -109,7 +109,7 @@ export interface IJMAPClient {
|
||||
accountId?: string,
|
||||
): Promise<void>;
|
||||
moveEmail(emailId: string, toMailboxId: string, accountId?: string): Promise<void>;
|
||||
emptyMailbox(mailboxId: string): Promise<number>;
|
||||
emptyMailbox(mailboxId: string, accountId?: string): Promise<number>;
|
||||
markMailboxAsRead(mailboxId: string, accountId?: string): Promise<number>;
|
||||
markAllAsRead(excludeMailboxIds?: string[], accountId?: string): Promise<number>;
|
||||
markAsSpam(emailId: string, accountId?: string, markAsRead?: boolean): Promise<void>;
|
||||
|
||||
+4
-3
@@ -1445,19 +1445,20 @@ export class JMAPClient implements IJMAPClient {
|
||||
}
|
||||
}
|
||||
|
||||
async emptyMailbox(mailboxId: string): Promise<number> {
|
||||
async emptyMailbox(mailboxId: string, accountId?: string): Promise<number> {
|
||||
const targetAccountId = accountId || this.accountId;
|
||||
let totalDestroyed = 0;
|
||||
let hasMore = true;
|
||||
|
||||
while (hasMore) {
|
||||
const response = await this.request([
|
||||
["Email/query", {
|
||||
accountId: this.accountId,
|
||||
accountId: targetAccountId,
|
||||
filter: { inMailbox: mailboxId },
|
||||
limit: 500,
|
||||
}, "0"],
|
||||
["Email/set", {
|
||||
accountId: this.accountId,
|
||||
accountId: targetAccountId,
|
||||
"#destroy": { resultOf: "0", name: "Email/query", path: "/ids" },
|
||||
}, "1"],
|
||||
]);
|
||||
|
||||
@@ -2438,7 +2438,10 @@ export const useEmailStore = create<EmailStore>((set, get) => ({
|
||||
emptyMailbox: async (client, mailboxId) => {
|
||||
try {
|
||||
set({ isLoading: true, error: null });
|
||||
await resolveActionClient(client).emptyMailbox(mailboxId);
|
||||
const mailbox = resolveActionMailboxes().find(mb => mb.id === mailboxId);
|
||||
const accountId = mailbox?.isShared ? mailbox.accountId : undefined;
|
||||
const jmapMailboxId = mailbox?.originalId || mailboxId;
|
||||
await resolveActionClient(client).emptyMailbox(jmapMailboxId, accountId);
|
||||
|
||||
// Clear emails from local state if we're viewing this mailbox
|
||||
const currentMailbox = get().selectedMailbox;
|
||||
|
||||
Reference in New Issue
Block a user