@rapidmx/web-client 0.15.1 → 0.17.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 +381 -373
- package/apps/admin/branding/index.tsx +39 -39
- package/apps/admin/data-requests/index.tsx +482 -480
- package/apps/admin/distribution-lists/new/index.tsx +3 -1
- package/apps/admin/domains/[uid].tsx +166 -164
- package/apps/admin/domains/new/index.tsx +3 -1
- package/apps/admin/escrow-scopes/[uid].tsx +350 -348
- package/apps/admin/escrow-scopes/new/index.tsx +3 -1
- package/apps/admin/index.tsx +129 -124
- package/apps/admin/mailboxes/[uid].tsx +271 -224
- package/apps/admin/mailboxes/new/index.tsx +30 -28
- package/apps/admin/plugins/index.tsx +15 -15
- package/apps/admin/retention-policy/index.tsx +39 -39
- package/apps/admin/signing-certificates/index.tsx +343 -343
- package/apps/admin/transport-rules/new/index.tsx +3 -1
- package/apps/escrow/audit-log/index.tsx +196 -196
- package/apps/escrow/matters/[uid].tsx +621 -621
- package/apps/escrow/matters/new/index.tsx +3 -1
- package/apps/shared/auth/adminAccess.ts +99 -99
- package/apps/shared/components/admin/layout/AdminShell.tsx +381 -378
- package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -0
- package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
- package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -0
- package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
- package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +50 -3
- package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1545
- package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
- package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
- package/apps/shared/components/admin/setup/SetupWizard.tsx +446 -444
- package/apps/shared/components/admin/usePagedList.tsx +129 -129
- package/apps/shared/components/calendar/EventEditor.tsx +5 -10
- package/apps/shared/components/calendar/EventFormParts.tsx +16 -47
- package/apps/shared/components/calendar/EventModal.tsx +206 -206
- package/apps/shared/components/calendar/GuestInput.tsx +100 -0
- package/apps/shared/components/calendar/MonthView.tsx +185 -185
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
- package/apps/shared/components/calendar/RequestChangeForm.tsx +23 -54
- package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
- package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
- package/apps/shared/components/calendar/allDay.ts +124 -124
- package/apps/shared/components/calendar/eventForm.ts +2 -2
- package/apps/shared/components/calendar/eventFormat.ts +49 -22
- package/apps/shared/components/calendar/layout/CalendarShell.tsx +201 -200
- package/apps/shared/components/contacts/ContactForm.tsx +383 -383
- package/apps/shared/components/contacts/ContactsSidebar.tsx +1 -1
- package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -98
- package/apps/shared/components/contacts/layout/ContactsShell.tsx +218 -216
- package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
- package/apps/shared/components/layout/AppShell.tsx +461 -480
- package/apps/shared/components/layout/FloatingActionButton.tsx +31 -0
- package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
- package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
- package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
- package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
- package/apps/shared/components/layout/UserMenu.tsx +439 -424
- package/apps/shared/components/mail/ConversationList.tsx +323 -323
- package/apps/shared/components/mail/ConversationThreadPane.tsx +613 -491
- package/apps/shared/components/mail/EmptyFolderBar.tsx +41 -0
- package/apps/shared/components/mail/MailSelectionBar.tsx +240 -227
- package/apps/shared/components/mail/MenuButton.tsx +31 -11
- package/apps/shared/components/mail/MessageDetailPane.tsx +1757 -1559
- package/apps/shared/components/mail/PermanentDeleteDialog.tsx +47 -0
- package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
- package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +1681 -1677
- package/apps/shared/components/mail/compose/RecipientInput.tsx +54 -11
- package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
- package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
- package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
- package/apps/shared/components/mail/layout/FolderBadgeChip.tsx +21 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +161 -134
- package/apps/shared/components/mail/layout/SidebarSection.tsx +66 -0
- package/apps/shared/components/mail/reading/MessageMoreMenu.tsx +258 -0
- package/apps/shared/components/mail/reading/MessageSourceDialog.tsx +79 -0
- package/apps/shared/components/mail/reading/PendingMessageCard.tsx +68 -0
- package/apps/shared/components/mail/reading/messageExport.ts +59 -0
- package/apps/shared/components/mail/reading/printMessage.ts +99 -0
- package/apps/shared/components/mail/reading/useMessageActions.ts +443 -0
- package/apps/shared/components/mail/verificationSeals.ts +125 -125
- package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
- package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
- package/apps/shared/components/settings/layout/SettingsShell.tsx +257 -254
- package/apps/shared/components/tasks/TasksSidebar.tsx +1 -1
- package/apps/shared/components/tasks/layout/TasksShell.tsx +219 -217
- package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
- package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
- package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
- package/apps/shared/keyboard/dispatch.ts +124 -124
- package/apps/shared/keyboard/format.ts +89 -89
- package/apps/shared/keyboard/keymap.ts +114 -114
- package/apps/shared/keyboard/registry.ts +65 -65
- package/apps/shared/keyboard/targets.ts +79 -79
- package/apps/shared/mail/folderCounts.ts +17 -0
- package/apps/shared/mail/folderOfType.ts +49 -0
- package/apps/shared/mail/folderTree.ts +143 -143
- package/apps/shared/mail/listAllPages.ts +39 -39
- package/apps/shared/mail/newMailNotifications.ts +171 -171
- package/apps/shared/mail/outbox/outgoingReplies.ts +192 -0
- package/apps/shared/mail/outbox/sendJob.ts +19 -1
- package/apps/shared/mail/outbox/sendOutcomes.ts +13 -4
- package/apps/shared/mail/permanentDelete.ts +160 -0
- package/apps/shared/mail/primaryMailbox.ts +71 -0
- package/apps/shared/mail/reportNotices.ts +66 -0
- package/apps/shared/mail/senderBlocking.ts +141 -0
- package/apps/shared/mail/useCollapsedSections.ts +146 -0
- package/apps/shared/mail/useMailConnection.ts +205 -203
- package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
- package/apps/shared/mail/useMailboxUpdateAccess.ts +60 -0
- package/apps/shared/mail/useMarkMessageRead.ts +47 -47
- package/apps/shared/mail/useNewMailNotifications.ts +178 -178
- package/apps/shared/mail/usePermanentDelete.tsx +160 -0
- package/apps/shared/navigation/frameContext.tsx +1 -1
- package/apps/shared/navigation/index.ts +43 -0
- package/apps/shared/navigation/pageTitle.ts +19 -0
- package/apps/shared/notifications/store.ts +560 -560
- package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
- package/apps/shared/search/crossMailboxSearch.ts +169 -0
- package/apps/shared/search/localIndexBuilder.ts +481 -481
- package/apps/shared/signing/enrollmentStorage.ts +33 -33
- package/apps/shared/signing/enrollmentTracker.ts +385 -385
- package/apps/shared/signing/enrollmentView.ts +251 -251
- package/apps/shared/signing/useNow.ts +19 -19
- package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
- package/apps/shared/styles/app.css +396 -386
- package/apps/www/_shell.tsx +82 -0
- package/apps/www/calendar/index.tsx +581 -571
- package/apps/www/contacts/[uid].tsx +112 -109
- package/apps/www/contacts/index.tsx +14 -3
- package/apps/www/index.tsx +2962 -2479
- package/apps/www/messages/[uid].tsx +139 -135
- package/apps/www/settings/appearance/index.tsx +5 -2
- package/apps/www/settings/auto-reply/index.tsx +136 -133
- package/apps/www/settings/blocked-senders/index.tsx +303 -0
- package/apps/www/settings/encryption/index.tsx +1290 -1287
- package/apps/www/settings/filters/[uid].tsx +179 -176
- package/apps/www/settings/filters/index.tsx +105 -102
- package/apps/www/settings/filters/new/index.tsx +165 -140
- package/apps/www/settings/labels/index.tsx +207 -204
- package/apps/www/settings/privacy/index.tsx +495 -492
- package/apps/www/settings/profile/index.tsx +251 -248
- package/apps/www/settings/read-receipts/index.tsx +150 -147
- package/apps/www/settings/sharing/index.tsx +259 -256
- package/apps/www/settings/signatures/[uid].tsx +175 -172
- package/apps/www/settings/signatures/index.tsx +91 -88
- package/apps/www/settings/signatures/new/index.tsx +138 -135
- package/apps/www/tasks/index.tsx +654 -649
- package/dist/apps/admin/data-requests/index.js +1 -1
- package/dist/apps/admin/distribution-lists/new/index.js +3 -1
- package/dist/apps/admin/domains/[uid].js +3 -1
- package/dist/apps/admin/domains/new/index.js +3 -1
- package/dist/apps/admin/escrow-scopes/[uid].js +3 -1
- package/dist/apps/admin/escrow-scopes/new/index.js +3 -1
- package/dist/apps/admin/index.js +5 -2
- package/dist/apps/admin/mailboxes/[uid].js +15 -3
- package/dist/apps/admin/mailboxes/new/index.js +3 -1
- package/dist/apps/admin/transport-rules/new/index.js +3 -1
- package/dist/apps/escrow/matters/new/index.js +3 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +6 -3
- package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.d.ts +35 -0
- package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.js +115 -0
- package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.d.ts +16 -0
- package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.js +92 -0
- package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +25 -3
- package/dist/apps/shared/components/admin/setup/SetupWizard.js +3 -1
- package/dist/apps/shared/components/calendar/EventEditor.js +5 -10
- package/dist/apps/shared/components/calendar/EventFormParts.d.ts +3 -2
- package/dist/apps/shared/components/calendar/EventFormParts.js +5 -16
- package/dist/apps/shared/components/calendar/GuestInput.d.ts +45 -0
- package/dist/apps/shared/components/calendar/GuestInput.js +30 -0
- package/dist/apps/shared/components/calendar/RequestChangeForm.js +11 -22
- package/dist/apps/shared/components/calendar/eventForm.d.ts +2 -2
- package/dist/apps/shared/components/calendar/eventFormat.d.ts +21 -8
- package/dist/apps/shared/components/calendar/eventFormat.js +50 -23
- package/dist/apps/shared/components/calendar/layout/CalendarShell.js +5 -4
- package/dist/apps/shared/components/contacts/ContactsSidebar.js +1 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
- package/dist/apps/shared/components/contacts/ContactsToolbar.js +4 -2
- package/dist/apps/shared/components/contacts/layout/ContactsShell.js +7 -5
- package/dist/apps/shared/components/layout/AppShell.d.ts +8 -11
- package/dist/apps/shared/components/layout/AppShell.js +24 -33
- package/dist/apps/shared/components/layout/FloatingActionButton.d.ts +13 -0
- package/dist/apps/shared/components/layout/FloatingActionButton.js +9 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +4 -1
- package/dist/apps/shared/components/layout/UserMenu.js +6 -5
- package/dist/apps/shared/components/mail/ConversationThreadPane.js +127 -22
- package/dist/apps/shared/components/mail/EmptyFolderBar.d.ts +18 -0
- package/dist/apps/shared/components/mail/EmptyFolderBar.js +10 -0
- package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +14 -4
- package/dist/apps/shared/components/mail/MailSelectionBar.js +11 -13
- package/dist/apps/shared/components/mail/MenuButton.d.ts +9 -2
- package/dist/apps/shared/components/mail/MenuButton.js +15 -11
- package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +5 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +147 -7
- package/dist/apps/shared/components/mail/PermanentDeleteDialog.d.ts +19 -0
- package/dist/apps/shared/components/mail/PermanentDeleteDialog.js +11 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -4
- package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +21 -1
- package/dist/apps/shared/components/mail/compose/RecipientInput.js +18 -10
- package/dist/apps/shared/components/mail/layout/FolderBadgeChip.d.ts +6 -0
- package/dist/apps/shared/components/mail/layout/FolderBadgeChip.js +9 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +16 -7
- package/dist/apps/shared/components/mail/layout/MailShell.js +78 -65
- package/dist/apps/shared/components/mail/layout/SidebarSection.d.ts +23 -0
- package/dist/apps/shared/components/mail/layout/SidebarSection.js +16 -0
- package/dist/apps/shared/components/mail/reading/MessageMoreMenu.d.ts +56 -0
- package/dist/apps/shared/components/mail/reading/MessageMoreMenu.js +153 -0
- package/dist/apps/shared/components/mail/reading/MessageSourceDialog.d.ts +27 -0
- package/dist/apps/shared/components/mail/reading/MessageSourceDialog.js +27 -0
- package/dist/apps/shared/components/mail/reading/PendingMessageCard.d.ts +14 -0
- package/dist/apps/shared/components/mail/reading/PendingMessageCard.js +16 -0
- package/dist/apps/shared/components/mail/reading/messageExport.d.ts +19 -0
- package/dist/apps/shared/components/mail/reading/messageExport.js +51 -0
- package/dist/apps/shared/components/mail/reading/printMessage.d.ts +30 -0
- package/dist/apps/shared/components/mail/reading/printMessage.js +70 -0
- package/dist/apps/shared/components/mail/reading/useMessageActions.d.ts +57 -0
- package/dist/apps/shared/components/mail/reading/useMessageActions.js +366 -0
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +10 -7
- package/dist/apps/shared/components/tasks/TasksSidebar.js +1 -1
- package/dist/apps/shared/components/tasks/layout/TasksShell.js +7 -5
- package/dist/apps/shared/keyboard/GlobalShortcuts.js +1 -1
- package/dist/apps/shared/mail/folderCounts.d.ts +10 -0
- package/dist/apps/shared/mail/folderCounts.js +12 -0
- package/dist/apps/shared/mail/folderOfType.d.ts +13 -0
- package/dist/apps/shared/mail/folderOfType.js +40 -0
- package/dist/apps/shared/mail/outbox/outgoingReplies.d.ts +80 -0
- package/dist/apps/shared/mail/outbox/outgoingReplies.js +131 -0
- package/dist/apps/shared/mail/outbox/sendJob.d.ts +5 -1
- package/dist/apps/shared/mail/outbox/sendJob.js +14 -1
- package/dist/apps/shared/mail/outbox/sendOutcomes.js +13 -4
- package/dist/apps/shared/mail/permanentDelete.d.ts +62 -0
- package/dist/apps/shared/mail/permanentDelete.js +127 -0
- package/dist/apps/shared/mail/primaryMailbox.d.ts +29 -0
- package/dist/apps/shared/mail/primaryMailbox.js +61 -0
- package/dist/apps/shared/mail/reportNotices.d.ts +21 -0
- package/dist/apps/shared/mail/reportNotices.js +47 -0
- package/dist/apps/shared/mail/senderBlocking.d.ts +26 -0
- package/dist/apps/shared/mail/senderBlocking.js +92 -0
- package/dist/apps/shared/mail/useCollapsedSections.d.ts +32 -0
- package/dist/apps/shared/mail/useCollapsedSections.js +110 -0
- package/dist/apps/shared/mail/useMailConnection.js +3 -1
- package/dist/apps/shared/mail/useMailboxUpdateAccess.d.ts +11 -0
- package/dist/apps/shared/mail/useMailboxUpdateAccess.js +52 -0
- package/dist/apps/shared/mail/usePermanentDelete.d.ts +35 -0
- package/dist/apps/shared/mail/usePermanentDelete.js +96 -0
- package/dist/apps/shared/navigation/frameContext.d.ts +1 -1
- package/dist/apps/shared/navigation/index.d.ts +16 -0
- package/dist/apps/shared/navigation/index.js +34 -0
- package/dist/apps/shared/navigation/pageTitle.d.ts +11 -0
- package/dist/apps/shared/navigation/pageTitle.js +12 -0
- package/dist/apps/shared/search/crossMailboxSearch.d.ts +72 -0
- package/dist/apps/shared/search/crossMailboxSearch.js +136 -0
- package/dist/apps/shared/styles/app.css +396 -386
- package/dist/apps/www/_shell.d.ts +26 -0
- package/dist/apps/www/_shell.js +31 -0
- package/dist/apps/www/calendar/index.d.ts +7 -2
- package/dist/apps/www/calendar/index.js +7 -4
- package/dist/apps/www/contacts/[uid].d.ts +14 -3
- package/dist/apps/www/contacts/[uid].js +5 -3
- package/dist/apps/www/contacts/index.d.ts +7 -2
- package/dist/apps/www/contacts/index.js +8 -4
- package/dist/apps/www/index.d.ts +7 -2
- package/dist/apps/www/index.js +542 -207
- package/dist/apps/www/messages/[uid].d.ts +14 -3
- package/dist/apps/www/messages/[uid].js +7 -5
- package/dist/apps/www/settings/appearance/index.d.ts +8 -2
- package/dist/apps/www/settings/appearance/index.js +4 -2
- package/dist/apps/www/settings/auto-reply/index.d.ts +7 -2
- package/dist/apps/www/settings/auto-reply/index.js +4 -2
- package/dist/apps/www/settings/blocked-senders/index.d.ts +9 -0
- package/dist/apps/www/settings/blocked-senders/index.js +134 -0
- package/dist/apps/www/settings/encryption/index.d.ts +7 -2
- package/dist/apps/www/settings/encryption/index.js +4 -2
- package/dist/apps/www/settings/filters/[uid].d.ts +7 -2
- package/dist/apps/www/settings/filters/[uid].js +4 -2
- package/dist/apps/www/settings/filters/index.d.ts +7 -2
- package/dist/apps/www/settings/filters/index.js +4 -2
- package/dist/apps/www/settings/filters/new/index.d.ts +7 -2
- package/dist/apps/www/settings/filters/new/index.js +28 -5
- package/dist/apps/www/settings/labels/index.d.ts +7 -2
- package/dist/apps/www/settings/labels/index.js +4 -2
- package/dist/apps/www/settings/privacy/index.d.ts +7 -2
- package/dist/apps/www/settings/privacy/index.js +4 -2
- package/dist/apps/www/settings/profile/index.d.ts +7 -2
- package/dist/apps/www/settings/profile/index.js +4 -2
- package/dist/apps/www/settings/read-receipts/index.d.ts +7 -2
- package/dist/apps/www/settings/read-receipts/index.js +4 -2
- package/dist/apps/www/settings/sharing/index.d.ts +7 -2
- package/dist/apps/www/settings/sharing/index.js +4 -2
- package/dist/apps/www/settings/signatures/[uid].d.ts +7 -2
- package/dist/apps/www/settings/signatures/[uid].js +4 -2
- package/dist/apps/www/settings/signatures/index.d.ts +7 -2
- package/dist/apps/www/settings/signatures/index.js +4 -2
- package/dist/apps/www/settings/signatures/new/index.d.ts +7 -2
- package/dist/apps/www/settings/signatures/new/index.js +5 -3
- package/dist/apps/www/tasks/index.d.ts +7 -2
- package/dist/apps/www/tasks/index.js +5 -3
- package/package.json +4 -2
- package/apps/shared/navigation/AppRouter.tsx +0 -300
- package/apps/shared/navigation/idle.ts +0 -45
- package/apps/shared/navigation/routerContext.tsx +0 -83
- package/apps/shared/navigation/routes.ts +0 -72
- package/apps/www/_routedPage.tsx +0 -24
- package/apps/www/_routes.ts +0 -37
- package/dist/apps/shared/navigation/AppRouter.d.ts +0 -52
- package/dist/apps/shared/navigation/AppRouter.js +0 -242
- package/dist/apps/shared/navigation/idle.d.ts +0 -14
- package/dist/apps/shared/navigation/idle.js +0 -43
- package/dist/apps/shared/navigation/routerContext.d.ts +0 -37
- package/dist/apps/shared/navigation/routerContext.js +0 -56
- package/dist/apps/shared/navigation/routes.d.ts +0 -32
- package/dist/apps/shared/navigation/routes.js +0 -37
- package/dist/apps/www/_routedPage.d.ts +0 -12
- package/dist/apps/www/_routedPage.js +0 -19
- package/dist/apps/www/_routes.d.ts +0 -11
- package/dist/apps/www/_routes.js +0 -31
|
@@ -1,47 +1,47 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import { useEffect, useRef } from "react";
|
|
6
|
-
import type { Message } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
-
import { useMailShell } from "../components/mail/layout/MailShell.js";
|
|
8
|
-
import { setReadState } from "./messageReadState.js";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Marks a message read when it is opened in a reading pane, through `setReadState()`: the row and the folder badge change at
|
|
12
|
-
* once. `onPatched` is handed each copy of the message as it changes (the optimistic one, then the server's, or the original
|
|
13
|
-
* again if the server refused).
|
|
14
|
-
*
|
|
15
|
-
* Replaces `@rapidmx/react-shared`'s `useMarkMessageRead`, which waits for the server before telling anyone and drops that
|
|
16
|
-
* answer if the message changes meanwhile - which the optimistic copy itself does. A message is asked for once each time it is
|
|
17
|
-
* opened: one the reader then marks unread stays unread while it is open, and one whose request failed is not retried in a loop
|
|
18
|
-
* (its own revert changes it again), only when it is opened again.
|
|
19
|
-
*/
|
|
20
|
-
export function useMarkMessageRead(message: Message | null, onPatched: (updated: Message, previous?: Message) => void): void {
|
|
21
|
-
const { trackMessageChange } = useMailShell();
|
|
22
|
-
const openUidRef = useRef<string | undefined>(undefined);
|
|
23
|
-
const requestedRef = useRef<Set<string>>(new Set());
|
|
24
|
-
const latestRef = useRef({ onPatched, trackMessageChange });
|
|
25
|
-
latestRef.current = { onPatched, trackMessageChange };
|
|
26
|
-
|
|
27
|
-
useEffect(() => {
|
|
28
|
-
if (message?.uid !== openUidRef.current) {
|
|
29
|
-
// Another message (or none) is open now: whatever was asked about the last one is over.
|
|
30
|
-
openUidRef.current = message?.uid;
|
|
31
|
-
requestedRef.current.clear();
|
|
32
|
-
}
|
|
33
|
-
if (!message || requestedRef.current.has(message.uid)) {
|
|
34
|
-
return;
|
|
35
|
-
}
|
|
36
|
-
// Every opening is asked about once - a message that is already read included, so that marking it unread while it is open (the
|
|
37
|
-
// keyboard's Ctrl+U) doesn't make this run again and read it straight back.
|
|
38
|
-
requestedRef.current.add(message.uid);
|
|
39
|
-
if (message.flags.read === true) {
|
|
40
|
-
return;
|
|
41
|
-
}
|
|
42
|
-
void setReadState(message, true, {
|
|
43
|
-
patch: (updated, previous) => latestRef.current.onPatched(updated, previous),
|
|
44
|
-
track: (previous, next) => latestRef.current.trackMessageChange(previous, next),
|
|
45
|
-
});
|
|
46
|
-
}, [message]);
|
|
47
|
-
}
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { useEffect, useRef } from "react";
|
|
6
|
+
import type { Message } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
+
import { useMailShell } from "../components/mail/layout/MailShell.js";
|
|
8
|
+
import { setReadState } from "./messageReadState.js";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Marks a message read when it is opened in a reading pane, through `setReadState()`: the row and the folder badge change at
|
|
12
|
+
* once. `onPatched` is handed each copy of the message as it changes (the optimistic one, then the server's, or the original
|
|
13
|
+
* again if the server refused).
|
|
14
|
+
*
|
|
15
|
+
* Replaces `@rapidmx/react-shared`'s `useMarkMessageRead`, which waits for the server before telling anyone and drops that
|
|
16
|
+
* answer if the message changes meanwhile - which the optimistic copy itself does. A message is asked for once each time it is
|
|
17
|
+
* opened: one the reader then marks unread stays unread while it is open, and one whose request failed is not retried in a loop
|
|
18
|
+
* (its own revert changes it again), only when it is opened again.
|
|
19
|
+
*/
|
|
20
|
+
export function useMarkMessageRead(message: Message | null, onPatched: (updated: Message, previous?: Message) => void): void {
|
|
21
|
+
const { trackMessageChange } = useMailShell();
|
|
22
|
+
const openUidRef = useRef<string | undefined>(undefined);
|
|
23
|
+
const requestedRef = useRef<Set<string>>(new Set());
|
|
24
|
+
const latestRef = useRef({ onPatched, trackMessageChange });
|
|
25
|
+
latestRef.current = { onPatched, trackMessageChange };
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
if (message?.uid !== openUidRef.current) {
|
|
29
|
+
// Another message (or none) is open now: whatever was asked about the last one is over.
|
|
30
|
+
openUidRef.current = message?.uid;
|
|
31
|
+
requestedRef.current.clear();
|
|
32
|
+
}
|
|
33
|
+
if (!message || requestedRef.current.has(message.uid)) {
|
|
34
|
+
return;
|
|
35
|
+
}
|
|
36
|
+
// Every opening is asked about once - a message that is already read included, so that marking it unread while it is open (the
|
|
37
|
+
// keyboard's Ctrl+U) doesn't make this run again and read it straight back.
|
|
38
|
+
requestedRef.current.add(message.uid);
|
|
39
|
+
if (message.flags.read === true) {
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
void setReadState(message, true, {
|
|
43
|
+
patch: (updated, previous) => latestRef.current.onPatched(updated, previous),
|
|
44
|
+
track: (previous, next) => latestRef.current.trackMessageChange(previous, next),
|
|
45
|
+
});
|
|
46
|
+
}, [message]);
|
|
47
|
+
}
|
|
@@ -1,178 +1,178 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
-
import type { Mailbox, Message } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
-
import type { MailboxFolders } from "../components/mail/layout/MailShell.js";
|
|
8
|
-
import {
|
|
9
|
-
DesktopPermission,
|
|
10
|
-
NewMailNotice,
|
|
11
|
-
desktopPermission,
|
|
12
|
-
getDesktopOfferDismissed,
|
|
13
|
-
noticeFor,
|
|
14
|
-
noticeSender,
|
|
15
|
-
ownAddressesOf,
|
|
16
|
-
requestDesktopPermission,
|
|
17
|
-
setDesktopOfferDismissed,
|
|
18
|
-
shouldAnnounce,
|
|
19
|
-
} from "./newMailNotifications.js";
|
|
20
|
-
import { getNotificationsEnabled } from "../notifications/preferences.js";
|
|
21
|
-
import { getNotificationsSnapshot, notify } from "../notifications/store.js";
|
|
22
|
-
|
|
23
|
-
/** How long a new-mail pop-up stays before it goes by itself (while it is neither hovered nor focused, and the tab is in view). */
|
|
24
|
-
export const TOAST_DURATION_MS = 8_000;
|
|
25
|
-
|
|
26
|
-
/** At most this many desktop notifications in `DESKTOP_BURST_WINDOW_MS`: a flood of mail is a few notifications, not a hundred. */
|
|
27
|
-
export const DESKTOP_BURST_LIMIT = 5;
|
|
28
|
-
export const DESKTOP_BURST_WINDOW_MS = 30_000;
|
|
29
|
-
|
|
30
|
-
/** How many announced message uids are remembered, so an event delivered twice is announced once. */
|
|
31
|
-
const ANNOUNCED_LIMIT = 500;
|
|
32
|
-
|
|
33
|
-
export interface NewMailNotifications {
|
|
34
|
-
/** Whether the next pop-up should also offer to turn on desktop notifications: the browser can, has not been asked,
|
|
35
|
-
* and the user has not said "Not now". */
|
|
36
|
-
offerDesktop: boolean;
|
|
37
|
-
/** The offer's "Turn on desktop notifications": asks the browser. Must be called from a click. */
|
|
38
|
-
enableDesktop(): Promise<void>;
|
|
39
|
-
/** The offer's "Not now": remembered, so it is not made again. */
|
|
40
|
-
declineDesktop(): void;
|
|
41
|
-
/** Announces a message that just arrived - if it is worth it (see `shouldAnnounce()`) and pop-ups are on. Stable. */
|
|
42
|
-
announce(message: Message): void;
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Whether the user is not looking at this tab: it is hidden, or another window has the focus. */
|
|
46
|
-
function tabIsInBackground(): boolean {
|
|
47
|
-
return document.visibilityState === "hidden" || !document.hasFocus();
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
export interface UseNewMailNotificationsOptions {
|
|
51
|
-
mailboxes: Mailbox[];
|
|
52
|
-
mailboxFolders: MailboxFolders[];
|
|
53
|
-
/** Opens a message from a desktop notification's click. Defaults to a plain navigation. */
|
|
54
|
-
open?: (href: string) => void;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
function defaultOpen(href: string): void {
|
|
58
|
-
window.location.href = href;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* New-mail announcements: an in-app pop-up for each message that arrives (a `mail` notification - see `notifications/store.ts`, which owns the
|
|
63
|
-
* stack, its limit of three and the clock), and - while the tab
|
|
64
|
-
* is in the background and the user has allowed it - a desktop notification with the same content, one per message however
|
|
65
|
-
* many events name it. `announce()` is what `useMailLiveUpdates()`'s `onMessageCreated` calls; nothing else feeds it, so a
|
|
66
|
-
* page load, a list refetch and a reconnect never announce anything.
|
|
67
|
-
*
|
|
68
|
-
* Nothing is ever asked of the browser on load: permission is requested only by `enableDesktop()`, from the offer in the
|
|
69
|
-
* first pop-up, or from Settings. What the user answered is remembered in `localStorage` (see `newMailNotifications.ts`).
|
|
70
|
-
*/
|
|
71
|
-
export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defaultOpen }: UseNewMailNotificationsOptions): NewMailNotifications {
|
|
72
|
-
const [permission, setPermission] = useState<DesktopPermission>("unsupported");
|
|
73
|
-
const [offerDismissed, setOfferDismissed] = useState(true);
|
|
74
|
-
const folders = useMemo(() => mailboxFolders.flatMap((entry) => entry.folders), [mailboxFolders]);
|
|
75
|
-
const ownAddresses = useMemo(() => ownAddressesOf(mailboxes), [mailboxes]);
|
|
76
|
-
const latestRef = useRef({ folders, ownAddresses, open });
|
|
77
|
-
latestRef.current = { folders, ownAddresses, open };
|
|
78
|
-
const announcedRef = useRef<Set<string>>(new Set());
|
|
79
|
-
const desktopShownRef = useRef<number[]>([]);
|
|
80
|
-
|
|
81
|
-
// The browser's own state is only read on the client, after hydration, so the server and first client render agree.
|
|
82
|
-
useEffect(() => {
|
|
83
|
-
setPermission(desktopPermission());
|
|
84
|
-
setOfferDismissed(getDesktopOfferDismissed());
|
|
85
|
-
}, []);
|
|
86
|
-
|
|
87
|
-
const showDesktop = useCallback((notice: NewMailNotice) => {
|
|
88
|
-
const now = Date.now();
|
|
89
|
-
desktopShownRef.current = desktopShownRef.current.filter((at) => now - at < DESKTOP_BURST_WINDOW_MS);
|
|
90
|
-
if (desktopShownRef.current.length >= DESKTOP_BURST_LIMIT) {
|
|
91
|
-
return;
|
|
92
|
-
}
|
|
93
|
-
try {
|
|
94
|
-
const notification = new Notification(noticeSender(notice), {
|
|
95
|
-
body: [notice.subject, notice.preview].filter(Boolean).join("\n"),
|
|
96
|
-
// One per message: a duplicate (another tab of this app, a re-delivered event) replaces instead of stacking.
|
|
97
|
-
tag: notice.uid,
|
|
98
|
-
});
|
|
99
|
-
desktopShownRef.current.push(now);
|
|
100
|
-
notification.onclick = () => {
|
|
101
|
-
window.focus();
|
|
102
|
-
notification.close();
|
|
103
|
-
latestRef.current.open(notice.href);
|
|
104
|
-
};
|
|
105
|
-
} catch {
|
|
106
|
-
// Some browsers refuse `new Notification()` outright (a mobile one wanting a service worker): the pop-up is enough.
|
|
107
|
-
}
|
|
108
|
-
}, []);
|
|
109
|
-
|
|
110
|
-
const enableDesktop = useCallback(async () => {
|
|
111
|
-
const answer = await requestDesktopPermission();
|
|
112
|
-
setPermission(answer);
|
|
113
|
-
// Answered either way, so the offer goes: on granted it has done its job, on denied it can't be made again.
|
|
114
|
-
setDesktopOfferDismissed(true);
|
|
115
|
-
setOfferDismissed(true);
|
|
116
|
-
}, []);
|
|
117
|
-
|
|
118
|
-
const declineDesktop = useCallback(() => {
|
|
119
|
-
setDesktopOfferDismissed(true);
|
|
120
|
-
setOfferDismissed(true);
|
|
121
|
-
}, []);
|
|
122
|
-
|
|
123
|
-
// The offer's current state and answers, for the stable `announce` below.
|
|
124
|
-
const offerDesktop = permission === "default" && !offerDismissed;
|
|
125
|
-
const offerRef = useRef({ offered: offerDesktop, enable: enableDesktop, decline: declineDesktop });
|
|
126
|
-
offerRef.current = { offered: offerDesktop, enable: enableDesktop, decline: declineDesktop };
|
|
127
|
-
|
|
128
|
-
const announce = useCallback(
|
|
129
|
-
(message: Message) => {
|
|
130
|
-
if (!getNotificationsEnabled() || announcedRef.current.has(message.uid)) {
|
|
131
|
-
return;
|
|
132
|
-
}
|
|
133
|
-
const { folders: knownFolders, ownAddresses: own } = latestRef.current;
|
|
134
|
-
if (!shouldAnnounce(message, { folders: knownFolders, ownAddresses: own })) {
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
announcedRef.current.add(message.uid);
|
|
138
|
-
if (announcedRef.current.size > ANNOUNCED_LIMIT) {
|
|
139
|
-
announcedRef.current.delete(announcedRef.current.values().next().value!);
|
|
140
|
-
}
|
|
141
|
-
const notice = noticeFor(message);
|
|
142
|
-
const offer = offerRef.current;
|
|
143
|
-
notify({
|
|
144
|
-
id: `mail:${notice.uid}`,
|
|
145
|
-
kind: "mail",
|
|
146
|
-
title: notice.senderName || notice.senderAddress,
|
|
147
|
-
subtitle: notice.senderName ? `<${notice.senderAddress}>` : undefined,
|
|
148
|
-
message: notice.subject,
|
|
149
|
-
preview: notice.preview || undefined,
|
|
150
|
-
href: notice.href,
|
|
151
|
-
timeoutMs: TOAST_DURATION_MS,
|
|
152
|
-
// Actions make a notification sticky; a new-mail pop-up with the offer still goes by itself.
|
|
153
|
-
sticky: false,
|
|
154
|
-
// The offer is made once at a time: on a pop-up only while none of the pop-ups still showing carries it.
|
|
155
|
-
...(offer.offered && !getNotificationsSnapshot().visible.some((item) => item.kind === "mail" && item.actions.length > 0)
|
|
156
|
-
? {
|
|
157
|
-
hint: "Get a desktop notification when mail arrives while this tab is in the background.",
|
|
158
|
-
actions: [
|
|
159
|
-
{ label: "Turn on desktop notifications", onClick: () => void offer.enable() },
|
|
160
|
-
{ label: "Not now", onClick: offer.decline },
|
|
161
|
-
],
|
|
162
|
-
}
|
|
163
|
-
: {}),
|
|
164
|
-
});
|
|
165
|
-
if (desktopPermission() === "granted" && tabIsInBackground()) {
|
|
166
|
-
showDesktop(notice);
|
|
167
|
-
}
|
|
168
|
-
},
|
|
169
|
-
[showDesktop],
|
|
170
|
-
);
|
|
171
|
-
|
|
172
|
-
return {
|
|
173
|
-
offerDesktop,
|
|
174
|
-
enableDesktop,
|
|
175
|
-
declineDesktop,
|
|
176
|
-
announce,
|
|
177
|
-
};
|
|
178
|
-
}
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
6
|
+
import type { Mailbox, Message } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
+
import type { MailboxFolders } from "../components/mail/layout/MailShell.js";
|
|
8
|
+
import {
|
|
9
|
+
DesktopPermission,
|
|
10
|
+
NewMailNotice,
|
|
11
|
+
desktopPermission,
|
|
12
|
+
getDesktopOfferDismissed,
|
|
13
|
+
noticeFor,
|
|
14
|
+
noticeSender,
|
|
15
|
+
ownAddressesOf,
|
|
16
|
+
requestDesktopPermission,
|
|
17
|
+
setDesktopOfferDismissed,
|
|
18
|
+
shouldAnnounce,
|
|
19
|
+
} from "./newMailNotifications.js";
|
|
20
|
+
import { getNotificationsEnabled } from "../notifications/preferences.js";
|
|
21
|
+
import { getNotificationsSnapshot, notify } from "../notifications/store.js";
|
|
22
|
+
|
|
23
|
+
/** How long a new-mail pop-up stays before it goes by itself (while it is neither hovered nor focused, and the tab is in view). */
|
|
24
|
+
export const TOAST_DURATION_MS = 8_000;
|
|
25
|
+
|
|
26
|
+
/** At most this many desktop notifications in `DESKTOP_BURST_WINDOW_MS`: a flood of mail is a few notifications, not a hundred. */
|
|
27
|
+
export const DESKTOP_BURST_LIMIT = 5;
|
|
28
|
+
export const DESKTOP_BURST_WINDOW_MS = 30_000;
|
|
29
|
+
|
|
30
|
+
/** How many announced message uids are remembered, so an event delivered twice is announced once. */
|
|
31
|
+
const ANNOUNCED_LIMIT = 500;
|
|
32
|
+
|
|
33
|
+
export interface NewMailNotifications {
|
|
34
|
+
/** Whether the next pop-up should also offer to turn on desktop notifications: the browser can, has not been asked,
|
|
35
|
+
* and the user has not said "Not now". */
|
|
36
|
+
offerDesktop: boolean;
|
|
37
|
+
/** The offer's "Turn on desktop notifications": asks the browser. Must be called from a click. */
|
|
38
|
+
enableDesktop(): Promise<void>;
|
|
39
|
+
/** The offer's "Not now": remembered, so it is not made again. */
|
|
40
|
+
declineDesktop(): void;
|
|
41
|
+
/** Announces a message that just arrived - if it is worth it (see `shouldAnnounce()`) and pop-ups are on. Stable. */
|
|
42
|
+
announce(message: Message): void;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Whether the user is not looking at this tab: it is hidden, or another window has the focus. */
|
|
46
|
+
function tabIsInBackground(): boolean {
|
|
47
|
+
return document.visibilityState === "hidden" || !document.hasFocus();
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
export interface UseNewMailNotificationsOptions {
|
|
51
|
+
mailboxes: Mailbox[];
|
|
52
|
+
mailboxFolders: MailboxFolders[];
|
|
53
|
+
/** Opens a message from a desktop notification's click. Defaults to a plain navigation. */
|
|
54
|
+
open?: (href: string) => void;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
function defaultOpen(href: string): void {
|
|
58
|
+
window.location.href = href;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* New-mail announcements: an in-app pop-up for each message that arrives (a `mail` notification - see `notifications/store.ts`, which owns the
|
|
63
|
+
* stack, its limit of three and the clock), and - while the tab
|
|
64
|
+
* is in the background and the user has allowed it - a desktop notification with the same content, one per message however
|
|
65
|
+
* many events name it. `announce()` is what `useMailLiveUpdates()`'s `onMessageCreated` calls; nothing else feeds it, so a
|
|
66
|
+
* page load, a list refetch and a reconnect never announce anything.
|
|
67
|
+
*
|
|
68
|
+
* Nothing is ever asked of the browser on load: permission is requested only by `enableDesktop()`, from the offer in the
|
|
69
|
+
* first pop-up, or from Settings. What the user answered is remembered in `localStorage` (see `newMailNotifications.ts`).
|
|
70
|
+
*/
|
|
71
|
+
export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defaultOpen }: UseNewMailNotificationsOptions): NewMailNotifications {
|
|
72
|
+
const [permission, setPermission] = useState<DesktopPermission>("unsupported");
|
|
73
|
+
const [offerDismissed, setOfferDismissed] = useState(true);
|
|
74
|
+
const folders = useMemo(() => mailboxFolders.flatMap((entry) => entry.folders), [mailboxFolders]);
|
|
75
|
+
const ownAddresses = useMemo(() => ownAddressesOf(mailboxes), [mailboxes]);
|
|
76
|
+
const latestRef = useRef({ folders, ownAddresses, open });
|
|
77
|
+
latestRef.current = { folders, ownAddresses, open };
|
|
78
|
+
const announcedRef = useRef<Set<string>>(new Set());
|
|
79
|
+
const desktopShownRef = useRef<number[]>([]);
|
|
80
|
+
|
|
81
|
+
// The browser's own state is only read on the client, after hydration, so the server and first client render agree.
|
|
82
|
+
useEffect(() => {
|
|
83
|
+
setPermission(desktopPermission());
|
|
84
|
+
setOfferDismissed(getDesktopOfferDismissed());
|
|
85
|
+
}, []);
|
|
86
|
+
|
|
87
|
+
const showDesktop = useCallback((notice: NewMailNotice) => {
|
|
88
|
+
const now = Date.now();
|
|
89
|
+
desktopShownRef.current = desktopShownRef.current.filter((at) => now - at < DESKTOP_BURST_WINDOW_MS);
|
|
90
|
+
if (desktopShownRef.current.length >= DESKTOP_BURST_LIMIT) {
|
|
91
|
+
return;
|
|
92
|
+
}
|
|
93
|
+
try {
|
|
94
|
+
const notification = new Notification(noticeSender(notice), {
|
|
95
|
+
body: [notice.subject, notice.preview].filter(Boolean).join("\n"),
|
|
96
|
+
// One per message: a duplicate (another tab of this app, a re-delivered event) replaces instead of stacking.
|
|
97
|
+
tag: notice.uid,
|
|
98
|
+
});
|
|
99
|
+
desktopShownRef.current.push(now);
|
|
100
|
+
notification.onclick = () => {
|
|
101
|
+
window.focus();
|
|
102
|
+
notification.close();
|
|
103
|
+
latestRef.current.open(notice.href);
|
|
104
|
+
};
|
|
105
|
+
} catch {
|
|
106
|
+
// Some browsers refuse `new Notification()` outright (a mobile one wanting a service worker): the pop-up is enough.
|
|
107
|
+
}
|
|
108
|
+
}, []);
|
|
109
|
+
|
|
110
|
+
const enableDesktop = useCallback(async () => {
|
|
111
|
+
const answer = await requestDesktopPermission();
|
|
112
|
+
setPermission(answer);
|
|
113
|
+
// Answered either way, so the offer goes: on granted it has done its job, on denied it can't be made again.
|
|
114
|
+
setDesktopOfferDismissed(true);
|
|
115
|
+
setOfferDismissed(true);
|
|
116
|
+
}, []);
|
|
117
|
+
|
|
118
|
+
const declineDesktop = useCallback(() => {
|
|
119
|
+
setDesktopOfferDismissed(true);
|
|
120
|
+
setOfferDismissed(true);
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
// The offer's current state and answers, for the stable `announce` below.
|
|
124
|
+
const offerDesktop = permission === "default" && !offerDismissed;
|
|
125
|
+
const offerRef = useRef({ offered: offerDesktop, enable: enableDesktop, decline: declineDesktop });
|
|
126
|
+
offerRef.current = { offered: offerDesktop, enable: enableDesktop, decline: declineDesktop };
|
|
127
|
+
|
|
128
|
+
const announce = useCallback(
|
|
129
|
+
(message: Message) => {
|
|
130
|
+
if (!getNotificationsEnabled() || announcedRef.current.has(message.uid)) {
|
|
131
|
+
return;
|
|
132
|
+
}
|
|
133
|
+
const { folders: knownFolders, ownAddresses: own } = latestRef.current;
|
|
134
|
+
if (!shouldAnnounce(message, { folders: knownFolders, ownAddresses: own })) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
announcedRef.current.add(message.uid);
|
|
138
|
+
if (announcedRef.current.size > ANNOUNCED_LIMIT) {
|
|
139
|
+
announcedRef.current.delete(announcedRef.current.values().next().value!);
|
|
140
|
+
}
|
|
141
|
+
const notice = noticeFor(message);
|
|
142
|
+
const offer = offerRef.current;
|
|
143
|
+
notify({
|
|
144
|
+
id: `mail:${notice.uid}`,
|
|
145
|
+
kind: "mail",
|
|
146
|
+
title: notice.senderName || notice.senderAddress,
|
|
147
|
+
subtitle: notice.senderName ? `<${notice.senderAddress}>` : undefined,
|
|
148
|
+
message: notice.subject,
|
|
149
|
+
preview: notice.preview || undefined,
|
|
150
|
+
href: notice.href,
|
|
151
|
+
timeoutMs: TOAST_DURATION_MS,
|
|
152
|
+
// Actions make a notification sticky; a new-mail pop-up with the offer still goes by itself.
|
|
153
|
+
sticky: false,
|
|
154
|
+
// The offer is made once at a time: on a pop-up only while none of the pop-ups still showing carries it.
|
|
155
|
+
...(offer.offered && !getNotificationsSnapshot().visible.some((item) => item.kind === "mail" && item.actions.length > 0)
|
|
156
|
+
? {
|
|
157
|
+
hint: "Get a desktop notification when mail arrives while this tab is in the background.",
|
|
158
|
+
actions: [
|
|
159
|
+
{ label: "Turn on desktop notifications", onClick: () => void offer.enable() },
|
|
160
|
+
{ label: "Not now", onClick: offer.decline },
|
|
161
|
+
],
|
|
162
|
+
}
|
|
163
|
+
: {}),
|
|
164
|
+
});
|
|
165
|
+
if (desktopPermission() === "granted" && tabIsInBackground()) {
|
|
166
|
+
showDesktop(notice);
|
|
167
|
+
}
|
|
168
|
+
},
|
|
169
|
+
[showDesktop],
|
|
170
|
+
);
|
|
171
|
+
|
|
172
|
+
return {
|
|
173
|
+
offerDesktop,
|
|
174
|
+
enableDesktop,
|
|
175
|
+
declineDesktop,
|
|
176
|
+
announce,
|
|
177
|
+
};
|
|
178
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { ReactElement, useRef, useState } from "react";
|
|
6
|
+
import type { Message } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
7
|
+
import PermanentDeleteDialog from "../components/mail/PermanentDeleteDialog.js";
|
|
8
|
+
import { useMailShell } from "../components/mail/layout/MailShell.js";
|
|
9
|
+
import { notifyApiError } from "../notifications/apiErrors.js";
|
|
10
|
+
import { removeLocalEntity } from "../search/localIndexRpcClient.js";
|
|
11
|
+
import {
|
|
12
|
+
EmptyFolderOutcome,
|
|
13
|
+
PurgeOutcome,
|
|
14
|
+
messageCount,
|
|
15
|
+
notifyFolderEmptied,
|
|
16
|
+
notifyPurged,
|
|
17
|
+
purgeFolder,
|
|
18
|
+
purgeMessages,
|
|
19
|
+
} from "./permanentDelete.js";
|
|
20
|
+
|
|
21
|
+
/** The folder "Empty folder" is about. */
|
|
22
|
+
export interface EmptiableFolder {
|
|
23
|
+
uid: string;
|
|
24
|
+
name: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
export interface PermanentDelete {
|
|
28
|
+
/**
|
|
29
|
+
* Asks, then permanently deletes `messages` (Delete in Deleted Items - the Delete menu item of a message card calls this too). Resolves
|
|
30
|
+
* with what came of it once the dialog is gone, and everything a delete has to tell has been told: the folder badges follow, the local
|
|
31
|
+
* search index drops the messages, and a notification says "N messages permanently deleted" or which could not be and why. Resolves
|
|
32
|
+
* `null` - and sends nothing - when the reader cancels, when `messages` is empty, or while another request is already open.
|
|
33
|
+
*/
|
|
34
|
+
requestPermanentDelete: (messages: Message[]) => Promise<PurgeOutcome | null>;
|
|
35
|
+
/**
|
|
36
|
+
* Asks, then permanently deletes everything in `folder`. `count` is how many messages it holds when that is known (the dialog and the
|
|
37
|
+
* notification then say so). Resolves as `requestPermanentDelete()` does; a request that failed outright (the server is down) has said so and resolves an
|
|
38
|
+
* outcome with nothing deleted, so the caller reloads what it lists.
|
|
39
|
+
*/
|
|
40
|
+
requestEmptyFolder: (folder: EmptiableFolder, count?: number) => Promise<EmptyFolderOutcome | null>;
|
|
41
|
+
/** A request is open (the dialog is up, or the delete is on the wire): what should hold every other action of the list meanwhile. */
|
|
42
|
+
busy: boolean;
|
|
43
|
+
/** The confirmation dialog - render it once, anywhere (it is a portal). */
|
|
44
|
+
dialog: ReactElement;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
type Request = { kind: "messages"; messages: Message[] } | { kind: "folder"; folder: EmptiableFolder; count?: number };
|
|
48
|
+
|
|
49
|
+
interface Pending {
|
|
50
|
+
request: Request;
|
|
51
|
+
resolve: (outcome: never) => void;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The one place a permanent delete is confirmed and carried out - for the mail list (the selection bar, the Delete key, Empty folder) and
|
|
56
|
+
* for a message card's own Delete, so all of them ask the same question, delete the same way and report the same way. Call it inside the
|
|
57
|
+
* mail shell (it keeps that shell's folder badges right).
|
|
58
|
+
*
|
|
59
|
+
* The reader always confirms: nothing is remembered between requests.
|
|
60
|
+
*/
|
|
61
|
+
export function usePermanentDelete(): PermanentDelete {
|
|
62
|
+
const { trackMessageChange, refreshFolderCounts } = useMailShell();
|
|
63
|
+
const [pending, setPending] = useState<Pending | null>(null);
|
|
64
|
+
const [running, setRunning] = useState(false);
|
|
65
|
+
// Set at once (state is a render later), so a key pressed twice does not open two dialogs.
|
|
66
|
+
const pendingRef = useRef<Pending | null>(null);
|
|
67
|
+
|
|
68
|
+
function ask<T>(request: Request): Promise<T | null> {
|
|
69
|
+
if (pendingRef.current) {
|
|
70
|
+
return Promise.resolve(null);
|
|
71
|
+
}
|
|
72
|
+
return new Promise<T | null>((resolve) => {
|
|
73
|
+
const next: Pending = { request, resolve };
|
|
74
|
+
pendingRef.current = next;
|
|
75
|
+
setPending(next);
|
|
76
|
+
});
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function requestPermanentDelete(messages: Message[]): Promise<PurgeOutcome | null> {
|
|
80
|
+
return messages.length === 0 ? Promise.resolve(null) : ask<PurgeOutcome>({ kind: "messages", messages });
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function requestEmptyFolder(folder: EmptiableFolder, count?: number): Promise<EmptyFolderOutcome | null> {
|
|
84
|
+
return ask<EmptyFolderOutcome>({ kind: "folder", folder, count });
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Closes the dialog and hands the caller what came of it. */
|
|
88
|
+
function finish(outcome: PurgeOutcome | null) {
|
|
89
|
+
const current = pendingRef.current!;
|
|
90
|
+
pendingRef.current = null;
|
|
91
|
+
setPending(null);
|
|
92
|
+
setRunning(false);
|
|
93
|
+
current.resolve(outcome as never);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** What every delete tells the rest of the page: the badges (each message is one fewer in its folder) and the local search index. */
|
|
97
|
+
function afterDeleted(deleted: Message[]) {
|
|
98
|
+
for (const message of deleted) {
|
|
99
|
+
trackMessageChange(message, null).settle();
|
|
100
|
+
void removeLocalEntity(message.mailboxUid, message.uid);
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
async function confirm() {
|
|
105
|
+
const { request } = pendingRef.current!;
|
|
106
|
+
setRunning(true);
|
|
107
|
+
if (request.kind === "messages") {
|
|
108
|
+
const outcome = await purgeMessages(request.messages);
|
|
109
|
+
afterDeleted(outcome.deleted);
|
|
110
|
+
notifyPurged(outcome);
|
|
111
|
+
finish(outcome);
|
|
112
|
+
return;
|
|
113
|
+
}
|
|
114
|
+
let outcome: EmptyFolderOutcome;
|
|
115
|
+
try {
|
|
116
|
+
outcome = await purgeFolder(request.folder.uid);
|
|
117
|
+
} catch (err) {
|
|
118
|
+
notifyApiError(err, `Couldn't empty ${request.folder.name}`);
|
|
119
|
+
// Part of it may have gone before the failure: the caller reloads rather than assume nothing did.
|
|
120
|
+
outcome = { emptied: false, deleted: [], failed: [] };
|
|
121
|
+
}
|
|
122
|
+
afterDeleted(outcome.deleted);
|
|
123
|
+
// The whole-folder request does not say which messages went, so the counts are read back rather than adjusted.
|
|
124
|
+
refreshFolderCounts();
|
|
125
|
+
if (outcome.emptied || outcome.deleted.length > 0 || outcome.failed.length > 0) {
|
|
126
|
+
notifyFolderEmptied(request.folder.name, outcome, request.count);
|
|
127
|
+
}
|
|
128
|
+
finish(outcome);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function cancel() {
|
|
132
|
+
finish(null);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const request = pending?.request;
|
|
136
|
+
const folderRequest = request?.kind === "folder" ? request : undefined;
|
|
137
|
+
const dialog = (
|
|
138
|
+
<PermanentDeleteDialog
|
|
139
|
+
open={pending !== null}
|
|
140
|
+
title={folderRequest ? `Empty ${folderRequest.folder.name}` : "Delete permanently"}
|
|
141
|
+
message={
|
|
142
|
+
folderRequest
|
|
143
|
+
? `Permanently delete ${
|
|
144
|
+
folderRequest.count === undefined
|
|
145
|
+
? "all items"
|
|
146
|
+
: folderRequest.count === 1
|
|
147
|
+
? "the only item"
|
|
148
|
+
: `all ${folderRequest.count} items`
|
|
149
|
+
} in ${folderRequest.folder.name}? This can't be undone.`
|
|
150
|
+
: `Permanently delete ${messageCount(request?.kind === "messages" ? request.messages.length : 0)}? This can't be undone.`
|
|
151
|
+
}
|
|
152
|
+
confirmLabel={folderRequest ? "Delete all permanently" : "Delete permanently"}
|
|
153
|
+
busy={running}
|
|
154
|
+
onConfirm={() => void confirm()}
|
|
155
|
+
onCancel={cancel}
|
|
156
|
+
/>
|
|
157
|
+
);
|
|
158
|
+
|
|
159
|
+
return { requestPermanentDelete, requestEmptyFolder, busy: pending !== null, dialog };
|
|
160
|
+
}
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import React, { PropsWithChildren, createContext, useContext, useLayoutEffect } from "react";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
|
-
* What the persistent app frame (
|
|
8
|
+
* What the persistent app frame (the webmail's router shell, `apps/www/_shell.tsx`, whose one mounted `AppChrome` never unmounts) offers to what is rendered inside it. `null`
|
|
9
9
|
* outside a frame - a page not shown by the router (an admin page, a plugin page, a test) renders its own chrome.
|
|
10
10
|
*/
|
|
11
11
|
export interface AppFrameContextValue {
|