@open-workspace/email 0.4.2 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +9 -4
- package/alchemy/index.ts +130 -2
- package/drizzle/mailbox/0003_after_0_4_2.sql +180 -0
- package/drizzle/mailbox/meta/0003_snapshot.json +1507 -0
- package/drizzle/mailbox/meta/_journal.json +7 -0
- package/drizzle/mailbox/migrations.js +3 -1
- package/migrations/0002_after_0_4_2.sql +35 -0
- package/migrations/meta/0002_snapshot.json +807 -0
- package/migrations/meta/_journal.json +7 -0
- package/package.json +23 -7
- package/shared/attachment-preview.ts +18 -8
- package/shared/folder-order.ts +31 -6
- package/shared/mail-headers.ts +3 -3
- package/shared/mail-html.ts +25 -0
- package/shared/mail-import.ts +0 -7
- package/shared/mail-received.ts +4 -4
- package/shared/mail-rule-actions.ts +47 -0
- package/shared/mail.ts +70 -4
- package/shared/office-preview.ts +0 -4
- package/shared/pdfjs-assets.ts +1 -3
- package/shared/rich-content.ts +35 -0
- package/shared/signature.ts +15 -0
- package/src/admin/address-auto-reply.tsx +49 -0
- package/src/admin/blocked-senders.tsx +86 -66
- package/src/admin/forward-destinations.tsx +140 -0
- package/src/admin/mail-archive.tsx +134 -0
- package/src/admin/team-signature.tsx +90 -0
- package/src/client.tsx +130 -16
- package/src/mail/attachment-preview-dialog.tsx +13 -5
- package/src/mail/auto-reply-banner.tsx +61 -0
- package/src/mail/blocked-senders.tsx +124 -91
- package/src/mail/compose-window-chrome.tsx +20 -8
- package/src/mail/compose-window.tsx +387 -365
- package/src/mail/composer-asset-bookmarks.ts +47 -12
- package/src/mail/composer-attachment-list.tsx +42 -17
- package/src/mail/composer-editor-document.ts +54 -10
- package/src/mail/composer-editor.tsx +44 -44
- package/src/mail/composer-link-text.ts +42 -0
- package/src/mail/composer-recipient-fields.tsx +25 -16
- package/src/mail/composer-recipients.ts +62 -16
- package/src/mail/composer-session.ts +107 -23
- package/src/mail/composer-toolbar.tsx +15 -1
- package/src/mail/composer-upload-client.ts +29 -1
- package/src/mail/composer-upload-progress.ts +2 -2
- package/src/mail/conversation-actions-model.ts +56 -0
- package/src/mail/conversation-list.tsx +263 -128
- package/src/mail/conversation-loading-skeleton.tsx +165 -90
- package/src/mail/conversation-message.tsx +257 -102
- package/src/mail/conversation-order.ts +12 -0
- package/src/mail/conversation-reply.tsx +313 -189
- package/src/mail/conversation-selection-toolbar.tsx +188 -143
- package/src/mail/conversation-view.tsx +315 -85
- package/src/mail/delivery-indicator.tsx +33 -12
- package/src/mail/draft-attachments.ts +194 -0
- package/src/mail/email-html-body.tsx +97 -53
- package/src/mail/folder-cleanup-bar.tsx +193 -0
- package/src/mail/folder-glyph.tsx +5 -0
- package/src/mail/folder-manager.tsx +71 -38
- package/src/mail/mail-app-bar.tsx +15 -3
- package/src/mail/mail-dock.tsx +19 -3
- package/src/mail/mail-focus.ts +48 -0
- package/src/mail/mail-folders.ts +14 -2
- package/src/mail/mail-layout.css +20 -0
- package/src/mail/mail-mailbox-sheet.tsx +22 -69
- package/src/mail/mail-nav-rail.tsx +7 -4
- package/src/mail/mail-nav.tsx +66 -46
- package/src/mail/mail-prefetch.ts +30 -9
- package/src/mail/mail-primitives.tsx +6 -4
- package/src/mail/mail-queries.ts +122 -20
- package/src/mail/mail-query-cache.ts +1085 -173
- package/src/mail/mail-search-params.ts +35 -0
- package/src/mail/mail-shell.tsx +32 -9
- package/src/mail/mailbox-ai-settings.tsx +56 -42
- package/src/mail/mailbox-realtime.tsx +4 -12
- package/src/mail/mailbox-rules.tsx +898 -0
- package/src/mail/message-actions.tsx +38 -26
- package/src/mail/message-attachments.tsx +20 -12
- package/src/mail/message-body.ts +53 -0
- package/src/mail/message-format.ts +8 -2
- package/src/mail/message-header.tsx +3 -1
- package/src/mail/message-translation.tsx +34 -67
- package/src/mail/original-message-sheet.tsx +63 -50
- package/src/mail/original-message.ts +6 -6
- package/src/mail/pane-splitter.tsx +3 -3
- package/src/mail/pdf-preview.tsx +70 -62
- package/src/mail/plain-message-text.tsx +28 -0
- package/src/mail/print-message.ts +31 -36
- package/src/mail/reader-pane.tsx +134 -103
- package/src/mail/recipient-combobox.tsx +52 -29
- package/src/mail/recipient-field-row.tsx +3 -0
- package/src/mail/rich-content.ts +128 -0
- package/src/mail/sanitize-email-html.ts +53 -32
- package/src/mail/sender-actions.tsx +48 -46
- package/src/mail/sender-authentication.tsx +1 -1
- package/src/mail/sender-dialogs.tsx +67 -43
- package/src/mail/sender-security.tsx +9 -10
- package/src/mail/signature.ts +43 -0
- package/src/mail/translation-html.ts +3 -3
- package/src/mail/types.ts +12 -0
- package/src/mail/use-composer-attachment-preflight.ts +23 -60
- package/src/mail/use-composer-core.ts +286 -0
- package/src/mail/use-composer-navigation.ts +120 -0
- package/src/mail/use-composer-submission.ts +154 -19
- package/src/mail/use-conversation-actions.ts +292 -0
- package/src/mail/use-conversation-position.ts +51 -0
- package/src/mail/use-conversation-selection.ts +192 -89
- package/src/mail/use-draft-autosave.ts +394 -0
- package/src/mail/use-drafts.ts +194 -0
- package/src/mail/use-mail-controller.ts +754 -213
- package/src/mail/use-mail-data.ts +210 -100
- package/src/mail/use-mail-safety.ts +19 -38
- package/src/mail/use-mail-send.ts +18 -6
- package/src/mail/use-pdf-translation.ts +1 -1
- package/src/mail/use-reply-cc.ts +61 -0
- package/src/mail/use-visible-message-read.ts +128 -64
- package/src/pwa/push-key.ts +18 -0
- package/src/pwa/push-subscription.ts +88 -26
- package/src/settings/auto-reply-editor.tsx +454 -0
- package/src/settings/auto-reply-page.tsx +59 -0
- package/src/settings/mail-apps-page.tsx +52 -43
- package/src/settings/notifications-page.tsx +82 -67
- package/src/settings/rich-content-editor.tsx +182 -0
- package/src/settings/settings-queries.ts +57 -0
- package/src/settings/signature-editor.tsx +142 -0
- package/src/settings/signature-page.tsx +70 -0
- package/worker/admin/blocked-sender-routes.ts +10 -16
- package/worker/backups/eml.ts +185 -0
- package/worker/backups/file-parts.ts +140 -0
- package/worker/backups/mail-backup.ts +644 -0
- package/worker/backups/settings-backup.ts +866 -0
- package/worker/backups/stream-eml.ts +73 -0
- package/worker/db/schema.ts +89 -5
- package/worker/jmap/attachment-blobs.ts +113 -0
- package/worker/jmap/blobs.ts +162 -0
- package/worker/jmap/draft-content.ts +42 -0
- package/worker/jmap/drafts.ts +70 -0
- package/worker/jmap/email-body.ts +152 -0
- package/worker/jmap/email-methods.ts +1223 -0
- package/worker/jmap/eventsource.ts +9 -8
- package/worker/jmap/import-methods.ts +205 -0
- package/worker/jmap/mailbox-methods.ts +187 -0
- package/worker/jmap/method-core.ts +379 -0
- package/worker/jmap/methods.ts +108 -1815
- package/worker/jmap/push-subscription-methods.ts +373 -0
- package/worker/jmap/push-types.ts +46 -2
- package/worker/jmap/push.ts +24 -31
- package/worker/jmap/routes.ts +144 -153
- package/worker/jmap/submission-methods.ts +395 -0
- package/worker/mail/access.ts +35 -12
- package/worker/mail/ai-classification.ts +2 -2
- package/worker/mail/archive-object.ts +96 -0
- package/worker/mail/archive-routes.ts +35 -0
- package/worker/mail/archive.ts +682 -0
- package/worker/mail/auth-headers.ts +48 -40
- package/worker/mail/auto-reply-routes.ts +255 -0
- package/worker/mail/auto-reply.ts +243 -0
- package/worker/mail/bimi.ts +53 -36
- package/worker/mail/bootstrap.ts +11 -3
- package/worker/mail/capabilities.ts +69 -0
- package/worker/mail/classification-signals.ts +1 -1
- package/worker/mail/confusables-data.ts +9 -0
- package/worker/mail/conversation-cursor.ts +6 -15
- package/worker/mail/delivery-events.ts +9 -7
- package/worker/mail/delivery-facts.ts +1 -1
- package/worker/mail/demo-routes.ts +3 -3
- package/worker/mail/doh.ts +3 -3
- package/worker/mail/download-links.ts +153 -0
- package/worker/mail/downloads.ts +2 -6
- package/worker/mail/draft-routes.ts +473 -0
- package/worker/mail/draft-sender.ts +54 -0
- package/worker/mail/edge-cache.ts +41 -55
- package/worker/mail/email-routing.ts +123 -0
- package/worker/mail/forward-destinations.ts +114 -0
- package/worker/mail/forward-downloads.ts +115 -0
- package/worker/mail/forward-html.ts +85 -0
- package/worker/mail/header-metadata.ts +2 -5
- package/worker/mail/impersonation.ts +102 -101
- package/worker/mail/import-routes.ts +29 -82
- package/worker/mail/import.ts +130 -0
- package/worker/mail/inbound-delivery.ts +6 -5
- package/worker/mail/inbound.ts +58 -28
- package/worker/mail/ip-intel.ts +8 -17
- package/worker/mail/isolate-cache.ts +1 -1
- package/worker/mail/mailbox-deletion.ts +33 -12
- package/worker/mail/mailbox-directory.ts +39 -65
- package/worker/mail/mailing-list.ts +29 -58
- package/worker/mail/message-security.ts +3 -3
- package/worker/mail/message-view.ts +12 -10
- package/worker/mail/office-conversion.ts +3 -5
- package/worker/mail/office-preview-container.ts +3 -8
- package/worker/mail/outbound-content.ts +139 -65
- package/worker/mail/outbound-delivery.ts +20 -17
- package/worker/mail/outbound-service.ts +34 -9
- package/worker/mail/outbound.ts +146 -75
- package/worker/mail/outgoing-context.ts +60 -30
- package/worker/mail/participants.ts +10 -15
- package/worker/mail/plain-body.ts +39 -0
- package/worker/mail/push-endpoint.ts +17 -0
- package/worker/mail/push-notifications.ts +53 -62
- package/worker/mail/quote-parser.ts +36 -24
- package/worker/mail/receive.ts +146 -39
- package/worker/mail/recipients.ts +1 -1
- package/worker/mail/remote-proxy.ts +3 -3
- package/worker/mail/repeat.ts +1 -1
- package/worker/mail/reply-plan.ts +124 -26
- package/worker/mail/rfc.ts +15 -7
- package/worker/mail/rich-content.ts +207 -0
- package/worker/mail/routes.ts +696 -304
- package/worker/mail/routing.ts +274 -0
- package/worker/mail/rules.ts +230 -0
- package/worker/mail/safety-routes.ts +88 -86
- package/worker/mail/schemas.ts +222 -31
- package/worker/mail/search.ts +25 -2
- package/worker/mail/security-settings.ts +4 -10
- package/worker/mail/send-message.ts +238 -0
- package/worker/mail/sender-intel.ts +12 -20
- package/worker/mail/signature-routes.ts +201 -0
- package/worker/mail/signatures.ts +195 -0
- package/worker/mail/spamhaus.ts +28 -16
- package/worker/mail/storage-keys.ts +35 -0
- package/worker/mail/unsubscribe.ts +19 -41
- package/worker/mail/uploads.ts +192 -80
- package/worker/mail/webhook-source.ts +3 -2
- package/worker/mail/workspace-safety.ts +194 -60
- package/worker/mailbox/demo.ts +13 -15
- package/worker/mailbox/email-index.ts +65 -35
- package/worker/mailbox/folder-model.ts +0 -20
- package/worker/mailbox/import-placement.ts +21 -36
- package/worker/mailbox/inbound-decision.ts +114 -0
- package/worker/mailbox/inbox-counts.ts +45 -25
- package/worker/mailbox/index.ts +756 -3201
- package/worker/mailbox/jmap-change-log.ts +195 -0
- package/worker/mailbox/jmap-email-rows.ts +186 -0
- package/worker/mailbox/jmap-mailboxes.ts +116 -0
- package/worker/mailbox/jmap-placement.ts +139 -0
- package/worker/mailbox/jmap-query-filter.ts +231 -0
- package/worker/mailbox/jmap-store.ts +167 -299
- package/worker/mailbox/mailbox-auto-reply.ts +301 -0
- package/worker/mailbox/mailbox-backup.ts +538 -0
- package/worker/mailbox/mailbox-drafts.ts +417 -0
- package/worker/mailbox/mailbox-folders.ts +242 -0
- package/worker/mailbox/mailbox-import.ts +450 -0
- package/worker/mailbox/mailbox-inbound.ts +934 -0
- package/worker/mailbox/mailbox-jmap.ts +294 -0
- package/worker/mailbox/mailbox-outbound.ts +413 -0
- package/worker/mailbox/mailbox-rules.ts +336 -0
- package/worker/mailbox/mailbox-senders.ts +294 -0
- package/worker/mailbox/mailbox-storage.ts +438 -0
- package/worker/mailbox/mailbox-views.ts +891 -0
- package/worker/mailbox/model.ts +1 -0
- package/worker/mailbox/office-preview-jobs.ts +59 -47
- package/worker/mailbox/placement.ts +933 -0
- package/worker/mailbox/restore-thread.ts +52 -0
- package/worker/mailbox/retention.ts +36 -0
- package/worker/mailbox/schema.ts +200 -1
- package/worker/mailbox/senders.ts +216 -178
- package/worker/mailbox/spam-undo-filing.ts +138 -0
- package/worker/mailbox/spam-undo.ts +240 -0
- package/worker/mailbox/support.ts +416 -0
- package/worker/mcp/mail-action-tools.ts +156 -0
- package/worker/mcp/mail-compose-tools.ts +7 -1
- package/worker/mcp/mail-safety-tools.ts +4 -4
- package/worker/module.ts +23 -4
- package/src/mail/use-compose-submission.ts +0 -208
- package/src/mail/use-reply-submission.ts +0 -114
- package/worker/mail/capped-body.ts +0 -36
|
@@ -1,158 +1,268 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { useState } from "react";
|
|
2
2
|
import { toast } from "sonner";
|
|
3
3
|
|
|
4
|
+
import { conversationFolder } from "../../shared/folder-order";
|
|
5
|
+
import { MAX_BULK_CONVERSATION_COUNT } from "../../shared/mail";
|
|
6
|
+
import { canArchiveOrRestore } from "./conversation-actions-model";
|
|
7
|
+
import { focusListAfter, rowsAround } from "./mail-focus";
|
|
4
8
|
import type { ConversationSummary } from "./types";
|
|
5
|
-
import {
|
|
9
|
+
import { useConversationActions } from "./use-conversation-actions";
|
|
10
|
+
import type { FollowChange } from "./use-conversation-actions";
|
|
11
|
+
import { useDiscardDrafts } from "./use-drafts";
|
|
6
12
|
import type { BulkConversationAction } from "./use-mail-data";
|
|
7
|
-
import { useBulkReport } from "./use-mail-safety";
|
|
8
13
|
|
|
9
|
-
|
|
14
|
+
type SelectedDraft = { id: string; version: number };
|
|
15
|
+
|
|
16
|
+
const EMPTY_SELECTION = new Map<string, SelectedDraft | null>();
|
|
17
|
+
|
|
18
|
+
function selectedDraft(row: ConversationSummary) {
|
|
19
|
+
return row.draftId === null
|
|
20
|
+
? null
|
|
21
|
+
: { id: row.draftId, version: row.draftVersion };
|
|
22
|
+
}
|
|
10
23
|
|
|
11
24
|
type SelectionState = {
|
|
12
25
|
scope: string;
|
|
13
26
|
active: boolean;
|
|
14
|
-
|
|
27
|
+
rows: Map<string, SelectedDraft | null>;
|
|
15
28
|
};
|
|
16
29
|
|
|
30
|
+
function label(count: number) {
|
|
31
|
+
return count === 1 ? "conversation" : "conversations";
|
|
32
|
+
}
|
|
33
|
+
|
|
17
34
|
export function useConversationSelection({
|
|
18
35
|
scope,
|
|
19
36
|
mailboxId,
|
|
20
37
|
folderId,
|
|
21
38
|
conversations,
|
|
39
|
+
follow,
|
|
40
|
+
onDraftsDiscarded,
|
|
22
41
|
}: {
|
|
23
42
|
scope: string;
|
|
24
43
|
mailboxId?: string;
|
|
25
44
|
folderId: string;
|
|
45
|
+
/** Where an action takes conversations, for the view to follow (`followChange`). */
|
|
46
|
+
follow: FollowChange;
|
|
47
|
+
/** Drafts discarded from the list: a composer open on one closes. */
|
|
48
|
+
onDraftsDiscarded: (draftIds: readonly string[]) => void;
|
|
26
49
|
conversations: ConversationSummary[];
|
|
27
50
|
}) {
|
|
28
51
|
const [state, setState] = useState<SelectionState>({
|
|
29
52
|
scope,
|
|
30
53
|
active: false,
|
|
31
|
-
|
|
54
|
+
rows: EMPTY_SELECTION,
|
|
32
55
|
});
|
|
33
56
|
|
|
34
57
|
if (state.scope !== scope) {
|
|
35
58
|
// Scope owns selection. Reset it before rendering the new list so browser
|
|
36
59
|
// Back/Forward cannot revive IDs from an earlier visit to the same scope.
|
|
37
|
-
setState({ scope, active: false,
|
|
60
|
+
setState({ scope, active: false, rows: EMPTY_SELECTION });
|
|
38
61
|
}
|
|
39
62
|
|
|
40
|
-
const
|
|
41
|
-
const
|
|
63
|
+
const actions = useConversationActions({ mailboxId, folderId, follow });
|
|
64
|
+
const discardMutation = useDiscardDrafts();
|
|
42
65
|
const active = state.scope === scope && state.active;
|
|
43
|
-
const
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
selectedIds.has(conversation.conversationId)
|
|
49
|
-
),
|
|
50
|
-
[conversations, selectedIds]
|
|
66
|
+
const selected = active ? state.rows : EMPTY_SELECTION;
|
|
67
|
+
const selectedIds = new Set(selected.keys());
|
|
68
|
+
|
|
69
|
+
const selectedConversations = conversations.filter((conversation) =>
|
|
70
|
+
selectedIds.has(conversation.conversationId)
|
|
51
71
|
);
|
|
52
72
|
|
|
53
73
|
function start() {
|
|
54
|
-
if (
|
|
55
|
-
setState({ scope, active: true,
|
|
74
|
+
if (discardMutation.isPending) return;
|
|
75
|
+
setState({ scope, active: true, rows: EMPTY_SELECTION });
|
|
56
76
|
}
|
|
57
77
|
|
|
78
|
+
// Only this scope's selection: an action finishing after the person
|
|
79
|
+
// moved on leaves the selection they made since.
|
|
58
80
|
function exit() {
|
|
59
|
-
setState(
|
|
81
|
+
setState((current) =>
|
|
82
|
+
current.scope === scope
|
|
83
|
+
? { scope, active: false, rows: EMPTY_SELECTION }
|
|
84
|
+
: current
|
|
85
|
+
);
|
|
60
86
|
}
|
|
61
87
|
|
|
62
|
-
function toggle(
|
|
63
|
-
|
|
88
|
+
function toggle(row: ConversationSummary) {
|
|
89
|
+
const { conversationId } = row;
|
|
90
|
+
|
|
91
|
+
if (discardMutation.isPending) return;
|
|
92
|
+
|
|
93
|
+
if (
|
|
94
|
+
!selectedIds.has(conversationId) &&
|
|
95
|
+
selectedIds.size >= MAX_BULK_CONVERSATION_COUNT
|
|
96
|
+
) {
|
|
97
|
+
toast.warning(
|
|
98
|
+
`Select up to ${MAX_BULK_CONVERSATION_COUNT} conversations at a time.`
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
|
|
64
104
|
setState((current) => {
|
|
65
|
-
const
|
|
105
|
+
const rows = new Map(current.scope === scope ? current.rows : []);
|
|
66
106
|
|
|
67
|
-
if (
|
|
68
|
-
else
|
|
107
|
+
if (rows.has(conversationId)) rows.delete(conversationId);
|
|
108
|
+
else rows.set(conversationId, selectedDraft(row));
|
|
69
109
|
|
|
70
|
-
return { scope, active: true,
|
|
110
|
+
return { scope, active: true, rows };
|
|
71
111
|
});
|
|
72
112
|
}
|
|
73
113
|
|
|
74
114
|
function toggleAllLoaded() {
|
|
75
|
-
if (
|
|
115
|
+
if (discardMutation.isPending) return;
|
|
116
|
+
|
|
117
|
+
if (conversations.length > MAX_BULK_CONVERSATION_COUNT) {
|
|
118
|
+
toast.warning(
|
|
119
|
+
`Select up to ${MAX_BULK_CONVERSATION_COUNT} conversations at a time.`
|
|
120
|
+
);
|
|
121
|
+
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
124
|
+
|
|
76
125
|
setState((current) => {
|
|
77
|
-
const
|
|
126
|
+
const rows = current.scope === scope ? current.rows : EMPTY_SELECTION;
|
|
78
127
|
|
|
79
128
|
const allLoadedSelected =
|
|
80
129
|
conversations.length > 0 &&
|
|
81
130
|
conversations.every((conversation) =>
|
|
82
|
-
|
|
131
|
+
rows.has(conversation.conversationId)
|
|
83
132
|
);
|
|
84
133
|
|
|
85
134
|
return {
|
|
86
135
|
scope,
|
|
87
136
|
active: true,
|
|
88
|
-
|
|
89
|
-
?
|
|
90
|
-
: new
|
|
91
|
-
conversations.map((
|
|
137
|
+
rows: allLoadedSelected
|
|
138
|
+
? EMPTY_SELECTION
|
|
139
|
+
: new Map(
|
|
140
|
+
conversations.map((row) => [
|
|
141
|
+
row.conversationId,
|
|
142
|
+
rows.get(row.conversationId) ?? selectedDraft(row),
|
|
143
|
+
])
|
|
92
144
|
),
|
|
93
145
|
};
|
|
94
146
|
});
|
|
95
147
|
}
|
|
96
148
|
|
|
97
|
-
|
|
98
|
-
|
|
149
|
+
/** The selected conversations an action applies to: read state and spam verdicts concern received mail only. */
|
|
150
|
+
function idsFor(action: BulkConversationAction) {
|
|
151
|
+
const received =
|
|
152
|
+
action.type === "read" ||
|
|
153
|
+
action.type === "report" ||
|
|
154
|
+
action.type === "not_spam";
|
|
99
155
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
(conversation) => conversation.hasIncoming
|
|
104
|
-
)
|
|
105
|
-
: selectedConversations;
|
|
156
|
+
return selectedConversations
|
|
157
|
+
.filter((row) => {
|
|
158
|
+
if (action.type !== "update") return !received || row.hasIncoming;
|
|
106
159
|
|
|
107
|
-
|
|
108
|
-
(conversation) => conversation.conversationId
|
|
109
|
-
);
|
|
160
|
+
if (row.draftId !== null) return false;
|
|
110
161
|
|
|
111
|
-
|
|
112
|
-
const requestedCount = conversationIds.length;
|
|
113
|
-
mutation.mutate(
|
|
114
|
-
{
|
|
115
|
-
mailboxId,
|
|
116
|
-
sourceFolderId: folderId,
|
|
117
|
-
conversationIds,
|
|
118
|
-
action,
|
|
119
|
-
},
|
|
120
|
-
{
|
|
121
|
-
onSuccess: ({ updatedCount }) => {
|
|
122
|
-
const conversationLabel =
|
|
123
|
-
requestedCount === 1 ? "conversation" : "conversations";
|
|
162
|
+
const { mailboxState, folderId: destination } = action.update;
|
|
124
163
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
toast.warning(
|
|
129
|
-
`${updatedCount} of ${requestedCount} ${conversationLabel} ${verb}. The rest no longer matched this action.`
|
|
130
|
-
);
|
|
131
|
-
}
|
|
164
|
+
if (destination !== undefined) {
|
|
165
|
+
return conversationFolder(row) !== (destination ?? "inbox");
|
|
166
|
+
}
|
|
132
167
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
168
|
+
if (mailboxState === "archive" || mailboxState === "active") {
|
|
169
|
+
return canArchiveOrRestore(row, mailboxState);
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
return true;
|
|
173
|
+
})
|
|
174
|
+
.map((conversation) => conversation.conversationId);
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* The toolbar the action was picked in goes with the selection: focus
|
|
179
|
+
* goes to the row after the first selected one that stays, or that row
|
|
180
|
+
* when they all stay (marked read or unread).
|
|
181
|
+
*/
|
|
182
|
+
function focusAfterAction(staying: boolean) {
|
|
183
|
+
focusListAfter(rowsAround(conversations, selectedIds, staying));
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
/** Acts on the selection, which closes at once as the rows change. */
|
|
187
|
+
function run(action: BulkConversationAction, verb: string) {
|
|
188
|
+
focusAfterAction(action.type === "read");
|
|
189
|
+
exit();
|
|
190
|
+
void actions.apply(
|
|
191
|
+
idsFor(action),
|
|
192
|
+
action,
|
|
193
|
+
{
|
|
194
|
+
done: (count) => `${count} ${label(count)} ${verb}`,
|
|
195
|
+
partial: (count, requested) =>
|
|
196
|
+
`${count} of ${requested} ${label(requested)} ${verb}. The rest no longer matched this action.`,
|
|
197
|
+
unchanged: `No ${label(2)} ${verb}. They no longer matched this action.`,
|
|
198
|
+
},
|
|
199
|
+
{ undoable: action.type === "update" }
|
|
137
200
|
);
|
|
138
201
|
}
|
|
139
202
|
|
|
140
|
-
/** Reports the
|
|
203
|
+
/** Reports the received mail of each selected conversation. */
|
|
141
204
|
function report() {
|
|
142
|
-
|
|
205
|
+
focusAfterAction(false);
|
|
206
|
+
exit();
|
|
207
|
+
void actions.apply(
|
|
208
|
+
idsFor({ type: "report" }),
|
|
209
|
+
{ type: "report" },
|
|
210
|
+
{
|
|
211
|
+
done: (count) => `${count} ${label(count)} reported as spam`,
|
|
212
|
+
unchanged: "None of them had mail to report any more",
|
|
213
|
+
},
|
|
214
|
+
{ undoable: true }
|
|
215
|
+
);
|
|
216
|
+
}
|
|
143
217
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
218
|
+
/** Not spam for the received mail of each selected conversation. */
|
|
219
|
+
function notSpam() {
|
|
220
|
+
focusAfterAction(false);
|
|
221
|
+
exit();
|
|
222
|
+
void actions.apply(
|
|
223
|
+
idsFor({ type: "not_spam" }),
|
|
224
|
+
{ type: "not_spam" },
|
|
225
|
+
{
|
|
226
|
+
done: (count) => `${count} ${label(count)} marked as not spam`,
|
|
227
|
+
partial: (count, requested) =>
|
|
228
|
+
`${count} of ${requested} conversations marked as not spam; the rest had left Spam`,
|
|
229
|
+
unchanged: "None of them is in Spam any more",
|
|
230
|
+
},
|
|
231
|
+
{ undoable: true }
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
/** Deletes the selected Drafts rows' drafts. */
|
|
236
|
+
function discardDrafts() {
|
|
237
|
+
// Check the revision the person selected, even if the list refreshed since.
|
|
238
|
+
const drafts = selectedConversations.flatMap(
|
|
239
|
+
(row) => selected.get(row.conversationId) ?? []
|
|
240
|
+
);
|
|
147
241
|
|
|
148
|
-
if (!
|
|
149
|
-
|
|
150
|
-
{ mailboxId,
|
|
242
|
+
if (!mailboxId || !drafts.length) return;
|
|
243
|
+
discardMutation.mutate(
|
|
244
|
+
{ mailboxId, drafts },
|
|
151
245
|
{
|
|
152
|
-
onSuccess: ({
|
|
153
|
-
|
|
154
|
-
|
|
246
|
+
onSuccess: ({ discarded }) => {
|
|
247
|
+
if (discarded.length < drafts.length) {
|
|
248
|
+
const count = discarded.length
|
|
249
|
+
? `${discarded.length} of ${drafts.length} drafts discarded. `
|
|
250
|
+
: "";
|
|
251
|
+
|
|
252
|
+
toast.error(
|
|
253
|
+
`${
|
|
254
|
+
count
|
|
255
|
+
}Drafts changed or were removed. Reopen them before discarding.`
|
|
256
|
+
);
|
|
257
|
+
} else {
|
|
258
|
+
toast.success(
|
|
259
|
+
`${discarded.length} ${discarded.length === 1 ? "draft" : "drafts"} discarded`
|
|
260
|
+
);
|
|
261
|
+
}
|
|
262
|
+
|
|
263
|
+
focusAfterAction(false);
|
|
155
264
|
exit();
|
|
265
|
+
onDraftsDiscarded(discarded);
|
|
156
266
|
},
|
|
157
267
|
onError: (error) => toast.error(error.message),
|
|
158
268
|
}
|
|
@@ -166,17 +276,10 @@ export function useConversationSelection({
|
|
|
166
276
|
allLoadedSelected:
|
|
167
277
|
conversations.length > 0 &&
|
|
168
278
|
selectedConversations.length === conversations.length,
|
|
169
|
-
|
|
170
|
-
(conversation) => conversation.isUnread
|
|
171
|
-
),
|
|
172
|
-
hasSelectedIncoming: selectedConversations.some(
|
|
173
|
-
(conversation) => conversation.hasIncoming
|
|
174
|
-
),
|
|
175
|
-
allSelectedHaveIncoming:
|
|
176
|
-
selectedConversations.length > 0 &&
|
|
177
|
-
selectedConversations.every((conversation) => conversation.hasIncoming),
|
|
178
|
-
pending: mutation.isPending || reportMutation.isPending,
|
|
279
|
+
pending: discardMutation.isPending,
|
|
179
280
|
report,
|
|
281
|
+
notSpam,
|
|
282
|
+
discardDrafts,
|
|
180
283
|
start,
|
|
181
284
|
exit,
|
|
182
285
|
toggle,
|