@rapidmx/web-client 0.15.1 → 0.16.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.
Files changed (189) hide show
  1. package/README.md +373 -373
  2. package/apps/admin/branding/index.tsx +39 -39
  3. package/apps/admin/data-requests/index.tsx +482 -480
  4. package/apps/admin/domains/[uid].tsx +164 -164
  5. package/apps/admin/escrow-scopes/[uid].tsx +348 -348
  6. package/apps/admin/index.tsx +127 -124
  7. package/apps/admin/mailboxes/[uid].tsx +269 -224
  8. package/apps/admin/mailboxes/new/index.tsx +28 -28
  9. package/apps/admin/plugins/index.tsx +15 -15
  10. package/apps/admin/retention-policy/index.tsx +39 -39
  11. package/apps/admin/signing-certificates/index.tsx +343 -343
  12. package/apps/escrow/audit-log/index.tsx +196 -196
  13. package/apps/escrow/matters/[uid].tsx +621 -621
  14. package/apps/shared/auth/adminAccess.ts +99 -99
  15. package/apps/shared/components/admin/layout/AdminShell.tsx +378 -378
  16. package/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.tsx +238 -0
  17. package/apps/shared/components/admin/mailboxes/EscrowScopeCard.tsx +152 -152
  18. package/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.tsx +194 -0
  19. package/apps/shared/components/admin/settings/BrandingForm.tsx +423 -423
  20. package/apps/shared/components/admin/settings/EncryptionPolicyForm.tsx +119 -119
  21. package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +50 -3
  22. package/apps/shared/components/admin/settings/MailboxPolicyForm.tsx +198 -198
  23. package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1545
  24. package/apps/shared/components/admin/settings/RetentionPolicyForm.tsx +182 -182
  25. package/apps/shared/components/admin/setup/EscrowSetupStep.tsx +288 -288
  26. package/apps/shared/components/admin/setup/SetupWizard.tsx +444 -444
  27. package/apps/shared/components/admin/usePagedList.tsx +129 -129
  28. package/apps/shared/components/calendar/EventEditor.tsx +5 -10
  29. package/apps/shared/components/calendar/EventFormParts.tsx +16 -47
  30. package/apps/shared/components/calendar/EventModal.tsx +206 -206
  31. package/apps/shared/components/calendar/GuestInput.tsx +100 -0
  32. package/apps/shared/components/calendar/MonthView.tsx +185 -185
  33. package/apps/shared/components/calendar/RecurrenceEditor.tsx +227 -227
  34. package/apps/shared/components/calendar/RequestChangeForm.tsx +23 -54
  35. package/apps/shared/components/calendar/SplitDayView.tsx +144 -144
  36. package/apps/shared/components/calendar/TimeGridView.tsx +246 -246
  37. package/apps/shared/components/calendar/allDay.ts +124 -124
  38. package/apps/shared/components/calendar/eventForm.ts +2 -2
  39. package/apps/shared/components/calendar/eventFormat.ts +49 -22
  40. package/apps/shared/components/calendar/layout/CalendarShell.tsx +201 -200
  41. package/apps/shared/components/contacts/ContactForm.tsx +383 -383
  42. package/apps/shared/components/contacts/ContactsSidebar.tsx +1 -1
  43. package/apps/shared/components/contacts/ContactsToolbar.tsx +103 -98
  44. package/apps/shared/components/contacts/layout/ContactsShell.tsx +217 -216
  45. package/apps/shared/components/escrow/layout/EscrowShell.tsx +155 -155
  46. package/apps/shared/components/layout/AppShell.tsx +480 -480
  47. package/apps/shared/components/layout/FloatingActionButton.tsx +31 -0
  48. package/apps/shared/components/layout/KeyEnrollmentGate.tsx +398 -398
  49. package/apps/shared/components/layout/MailboxProvisioning.tsx +168 -168
  50. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -315
  51. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -84
  52. package/apps/shared/components/layout/UserMenu.tsx +439 -424
  53. package/apps/shared/components/mail/ConversationList.tsx +323 -323
  54. package/apps/shared/components/mail/ConversationThreadPane.tsx +612 -491
  55. package/apps/shared/components/mail/MailSelectionBar.tsx +236 -227
  56. package/apps/shared/components/mail/MessageDetailPane.tsx +1559 -1559
  57. package/apps/shared/components/mail/compose/ComposeContext.tsx +312 -312
  58. package/apps/shared/components/mail/compose/ComposeToolbar.tsx +422 -422
  59. package/apps/shared/components/mail/compose/ComposeWindow.tsx +1681 -1677
  60. package/apps/shared/components/mail/compose/RecipientInput.tsx +54 -11
  61. package/apps/shared/components/mail/compose/RichTextEditor.tsx +147 -147
  62. package/apps/shared/components/mail/compose/composeFlushRegistry.ts +60 -60
  63. package/apps/shared/components/mail/compose/quotedBody.ts +161 -161
  64. package/apps/shared/components/mail/layout/FolderBadgeChip.tsx +21 -0
  65. package/apps/shared/components/mail/layout/MailShell.tsx +137 -113
  66. package/apps/shared/components/mail/layout/SidebarSection.tsx +66 -0
  67. package/apps/shared/components/mail/reading/PendingMessageCard.tsx +68 -0
  68. package/apps/shared/components/mail/verificationSeals.ts +125 -125
  69. package/apps/shared/components/rules/RuleBuilder.tsx +311 -311
  70. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -344
  71. package/apps/shared/components/settings/layout/SettingsShell.tsx +255 -254
  72. package/apps/shared/components/tasks/TasksSidebar.tsx +1 -1
  73. package/apps/shared/components/tasks/layout/TasksShell.tsx +218 -217
  74. package/apps/shared/keyboard/GlobalShortcuts.tsx +51 -51
  75. package/apps/shared/keyboard/ShortcutProvider.tsx +62 -62
  76. package/apps/shared/keyboard/ShortcutsDialog.tsx +84 -84
  77. package/apps/shared/keyboard/dispatch.ts +124 -124
  78. package/apps/shared/keyboard/format.ts +89 -89
  79. package/apps/shared/keyboard/keymap.ts +114 -114
  80. package/apps/shared/keyboard/registry.ts +65 -65
  81. package/apps/shared/keyboard/targets.ts +79 -79
  82. package/apps/shared/mail/folderCounts.ts +17 -0
  83. package/apps/shared/mail/folderTree.ts +143 -143
  84. package/apps/shared/mail/listAllPages.ts +39 -39
  85. package/apps/shared/mail/newMailNotifications.ts +171 -171
  86. package/apps/shared/mail/outbox/outgoingReplies.ts +192 -0
  87. package/apps/shared/mail/outbox/sendJob.ts +19 -1
  88. package/apps/shared/mail/outbox/sendOutcomes.ts +13 -4
  89. package/apps/shared/mail/primaryMailbox.ts +71 -0
  90. package/apps/shared/mail/useCollapsedSections.ts +146 -0
  91. package/apps/shared/mail/useMailConnection.ts +205 -203
  92. package/apps/shared/mail/useMailLiveUpdates.ts +277 -277
  93. package/apps/shared/mail/useMarkMessageRead.ts +47 -47
  94. package/apps/shared/mail/useNewMailNotifications.ts +178 -178
  95. package/apps/shared/navigation/AppRouter.tsx +300 -300
  96. package/apps/shared/navigation/routerContext.tsx +83 -83
  97. package/apps/shared/notifications/store.ts +560 -560
  98. package/apps/shared/search/LocalIndexLifecycle.tsx +114 -114
  99. package/apps/shared/search/crossMailboxSearch.ts +169 -0
  100. package/apps/shared/search/localIndexBuilder.ts +481 -481
  101. package/apps/shared/signing/enrollmentStorage.ts +33 -33
  102. package/apps/shared/signing/enrollmentTracker.ts +385 -385
  103. package/apps/shared/signing/enrollmentView.ts +251 -251
  104. package/apps/shared/signing/useNow.ts +19 -19
  105. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -90
  106. package/apps/shared/styles/app.css +396 -386
  107. package/apps/www/calendar/index.tsx +578 -571
  108. package/apps/www/contacts/[uid].tsx +109 -109
  109. package/apps/www/contacts/index.tsx +6 -0
  110. package/apps/www/index.tsx +2847 -2479
  111. package/apps/www/messages/[uid].tsx +135 -135
  112. package/apps/www/settings/auto-reply/index.tsx +133 -133
  113. package/apps/www/settings/encryption/index.tsx +1287 -1287
  114. package/apps/www/settings/filters/[uid].tsx +176 -176
  115. package/apps/www/settings/filters/index.tsx +102 -102
  116. package/apps/www/settings/filters/new/index.tsx +140 -140
  117. package/apps/www/settings/labels/index.tsx +204 -204
  118. package/apps/www/settings/privacy/index.tsx +492 -492
  119. package/apps/www/settings/profile/index.tsx +248 -248
  120. package/apps/www/settings/read-receipts/index.tsx +147 -147
  121. package/apps/www/settings/sharing/index.tsx +256 -256
  122. package/apps/www/settings/signatures/[uid].tsx +172 -172
  123. package/apps/www/settings/signatures/index.tsx +88 -88
  124. package/apps/www/settings/signatures/new/index.tsx +135 -135
  125. package/apps/www/tasks/index.tsx +649 -649
  126. package/dist/apps/admin/data-requests/index.js +1 -1
  127. package/dist/apps/admin/index.js +2 -1
  128. package/dist/apps/admin/mailboxes/[uid].js +12 -2
  129. package/dist/apps/shared/components/admin/layout/AdminShell.js +2 -2
  130. package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.d.ts +35 -0
  131. package/dist/apps/shared/components/admin/mailboxes/EraseLeftoverDataDialog.js +115 -0
  132. package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.d.ts +16 -0
  133. package/dist/apps/shared/components/admin/mailboxes/LeftoverMailboxesSection.js +92 -0
  134. package/dist/apps/shared/components/admin/settings/BrandingForm.js +3 -3
  135. package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +25 -3
  136. package/dist/apps/shared/components/calendar/EventEditor.js +5 -10
  137. package/dist/apps/shared/components/calendar/EventFormParts.d.ts +3 -2
  138. package/dist/apps/shared/components/calendar/EventFormParts.js +5 -16
  139. package/dist/apps/shared/components/calendar/GuestInput.d.ts +45 -0
  140. package/dist/apps/shared/components/calendar/GuestInput.js +30 -0
  141. package/dist/apps/shared/components/calendar/RequestChangeForm.js +11 -22
  142. package/dist/apps/shared/components/calendar/eventForm.d.ts +2 -2
  143. package/dist/apps/shared/components/calendar/eventFormat.d.ts +21 -8
  144. package/dist/apps/shared/components/calendar/eventFormat.js +50 -23
  145. package/dist/apps/shared/components/calendar/layout/CalendarShell.js +3 -2
  146. package/dist/apps/shared/components/contacts/ContactsSidebar.js +1 -1
  147. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  148. package/dist/apps/shared/components/contacts/ContactsToolbar.js +4 -2
  149. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +4 -3
  150. package/dist/apps/shared/components/layout/FloatingActionButton.d.ts +13 -0
  151. package/dist/apps/shared/components/layout/FloatingActionButton.js +9 -0
  152. package/dist/apps/shared/components/layout/UserMenu.d.ts +4 -1
  153. package/dist/apps/shared/components/layout/UserMenu.js +6 -5
  154. package/dist/apps/shared/components/mail/ConversationThreadPane.js +127 -22
  155. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +6 -1
  156. package/dist/apps/shared/components/mail/MailSelectionBar.js +3 -3
  157. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -4
  158. package/dist/apps/shared/components/mail/compose/RecipientInput.d.ts +21 -1
  159. package/dist/apps/shared/components/mail/compose/RecipientInput.js +18 -10
  160. package/dist/apps/shared/components/mail/layout/FolderBadgeChip.d.ts +6 -0
  161. package/dist/apps/shared/components/mail/layout/FolderBadgeChip.js +9 -0
  162. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +5 -0
  163. package/dist/apps/shared/components/mail/layout/MailShell.js +64 -45
  164. package/dist/apps/shared/components/mail/layout/SidebarSection.d.ts +23 -0
  165. package/dist/apps/shared/components/mail/layout/SidebarSection.js +16 -0
  166. package/dist/apps/shared/components/mail/reading/PendingMessageCard.d.ts +14 -0
  167. package/dist/apps/shared/components/mail/reading/PendingMessageCard.js +16 -0
  168. package/dist/apps/shared/components/settings/layout/SettingsShell.js +6 -5
  169. package/dist/apps/shared/components/tasks/TasksSidebar.js +1 -1
  170. package/dist/apps/shared/components/tasks/layout/TasksShell.js +4 -3
  171. package/dist/apps/shared/mail/folderCounts.d.ts +10 -0
  172. package/dist/apps/shared/mail/folderCounts.js +12 -0
  173. package/dist/apps/shared/mail/outbox/outgoingReplies.d.ts +80 -0
  174. package/dist/apps/shared/mail/outbox/outgoingReplies.js +131 -0
  175. package/dist/apps/shared/mail/outbox/sendJob.d.ts +5 -1
  176. package/dist/apps/shared/mail/outbox/sendJob.js +14 -1
  177. package/dist/apps/shared/mail/outbox/sendOutcomes.js +13 -4
  178. package/dist/apps/shared/mail/primaryMailbox.d.ts +29 -0
  179. package/dist/apps/shared/mail/primaryMailbox.js +61 -0
  180. package/dist/apps/shared/mail/useCollapsedSections.d.ts +32 -0
  181. package/dist/apps/shared/mail/useCollapsedSections.js +110 -0
  182. package/dist/apps/shared/mail/useMailConnection.js +3 -1
  183. package/dist/apps/shared/search/crossMailboxSearch.d.ts +72 -0
  184. package/dist/apps/shared/search/crossMailboxSearch.js +136 -0
  185. package/dist/apps/shared/styles/app.css +396 -386
  186. package/dist/apps/www/calendar/index.js +3 -2
  187. package/dist/apps/www/contacts/index.js +3 -1
  188. package/dist/apps/www/index.js +426 -189
  189. package/package.json +2 -2
@@ -1,323 +1,323 @@
1
- ///////////////////////////////////////////////////////////////////////////////
2
- // Copyright (C) 2026 Jean-Philippe Steinmetz
3
- // SPDX-License-Identifier: MPL-2.0
4
- ///////////////////////////////////////////////////////////////////////////////
5
- import React, { useState } from "react";
6
- import { HiChevronDown, HiChevronRight, HiOutlineFlag, HiOutlinePaperClip } from "react-icons/hi2";
7
- import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
- import { Message } from "@rapidmx/react-shared/mail/mailApi.js";
9
- import { formatMailAddress } from "@rapidmx/react-shared/mail/mailAddress.js";
10
- import MailAddress from "./MailAddress.js";
11
- import { EncryptedPreview, conversationLooksEncrypted } from "./reading/EncryptedPreview.js";
12
- import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
13
- import { ROW_FOCUS_CLASS, UnreadBar, UnreadLabel, dateClass, isUnread, rowClass, senderClass, subjectClass } from "./unreadStyle.js";
14
- import SwipeRow from "./SwipeRow.js";
15
- import InviteRowChip from "./invite/InviteRowChip.js";
16
-
17
- export interface ConversationListProps {
18
- conversations: ConversationSummary[];
19
- /** The mailbox the conversations were listed from - `listConversationMessages()` is mailbox-scoped. */
20
- mailboxUid: string;
21
- /** The message currently open in the reading pane, so the row standing for it can be marked. */
22
- selectedUid: string | null;
23
- /**
24
- * Opens a conversation in the reading pane, positioned at one of its messages: the one a child row
25
- * stands for, or the conversation's own `latestMessageUid` for a parent row. The conversation goes
26
- * with the uid because the pane shows the whole thread, not just that message.
27
- */
28
- onOpenMessage: (conversation: ConversationSummary, uid: string) => void;
29
- /** Newer copies of messages this list already fetched - the reading pane marks the message it opens as
30
- * read, which this list would otherwise keep showing as unread until the thread is collapsed and
31
- * expanded again. */
32
- messageOverrides?: Record<string, Message>;
33
- /** Called with one of a conversation's own messages carrying the answer the reader just gave to its meeting request (from that row's RSVP chip), so the caller can keep it. An answer given from the conversation's own (parent) row is kept by this list itself. */
34
- onMeetingResponded?: (updated: Message) => void;
35
- /** Turns each parent row into a checkbox row: select mode here ticks whole conversations, since a
36
- * conversation is what this list's rows are. A child row stays a plain "open this message" button - a
37
- * mixed conversation/message selection has no sensible bulk semantics (see `MailListToolbar`). */
38
- selectMode?: boolean;
39
- /** The `conversationId`s currently ticked. */
40
- selectedConversationIds?: Set<string>;
41
- onToggleSelected?: (conversation: ConversationSummary) => void;
42
- /**
43
- * What swiping a parent row does on a phone: right to left archives the conversation (resolving whether it went through), left
44
- * to right asks where to move it. Absent, or `enabled: false` (a desktop), rows don't follow a finger.
45
- */
46
- swipe?: {
47
- enabled: boolean;
48
- onArchive: (conversation: ConversationSummary) => Promise<boolean>;
49
- onMove: (conversation: ConversationSummary) => void;
50
- };
51
- /**
52
- * Whether a conversation's own messages read newest first, matching the order sense the rows themselves
53
- * are in ("Newest on top"). `listConversationMessages()` always answers oldest first - the order a
54
- * thread is read in - so this reverses that copy for display rather than asking for it differently.
55
- */
56
- newestFirst?: boolean;
57
- }
58
-
59
- /** Every participant as `Name <address>`, for the tooltip and the accessible text of the "+N" a crowded row folds them into. */
60
- function participantList(conversation: ConversationSummary): string {
61
- return conversation.participants.map((participant) => formatMailAddress(participant)).join(", ");
62
- }
63
-
64
- /**
65
- * The nested, Outlook-style conversation list: one parent row per conversation - its participants, subject,
66
- * message count, unread count, flag/attachment hints and the latest message's preview - expanding via its
67
- * own chevron into the conversation's individual messages as child rows, fetched on first expand with
68
- * `listConversationMessages()` (one request for the whole thread, across folders, oldest first).
69
- *
70
- * Opening a row opens the whole conversation in `ConversationThreadPane`, positioned at the message the row
71
- * stands for: the latest one for a parent row, that one for a child row.
72
- *
73
- * The chevron is a button of its own beside the row's own button rather than inside it (a button can't
74
- * nest inside a button), so expanding and opening are separately reachable by keyboard and each carries
75
- * its own name.
76
- */
77
- export default function ConversationList({
78
- conversations,
79
- mailboxUid,
80
- selectedUid,
81
- onOpenMessage,
82
- messageOverrides,
83
- onMeetingResponded,
84
- selectMode,
85
- selectedConversationIds,
86
- onToggleSelected,
87
- swipe,
88
- newestFirst,
89
- }: ConversationListProps) {
90
- const [expanded, setExpanded] = useState<Set<string>>(new Set());
91
- const [messagesById, setMessagesById] = useState<Record<string, Message[]>>({});
92
- const [loadingIds, setLoadingIds] = useState<Set<string>>(new Set());
93
- const [errorsById, setErrorsById] = useState<Record<string, string>>({});
94
- // The answers given from a row's RSVP chip, by message uid: a row draws them at once, whichever row (the conversation's, or one of its messages) they were given from.
95
- const [answers, setAnswers] = useState<Record<string, Message["meetingResponse"]>>({});
96
-
97
- function answered(updated: Message) {
98
- setAnswers((prev) => ({ ...prev, [updated.uid]: updated.meetingResponse }));
99
- }
100
-
101
- function toggle(conversation: ConversationSummary) {
102
- const id = conversation.conversationId;
103
- setExpanded((prev) => {
104
- const next = new Set(prev);
105
- if (next.has(id)) {
106
- next.delete(id);
107
- } else {
108
- next.add(id);
109
- }
110
- return next;
111
- });
112
- if (expanded.has(id) || messagesById[id] || loadingIds.has(id)) {
113
- return;
114
- }
115
- setLoadingIds((prev) => new Set(prev).add(id));
116
- setErrorsById((prev) => {
117
- const next = { ...prev };
118
- delete next[id];
119
- return next;
120
- });
121
- listConversationMessages(mailboxUid, id)
122
- .then((loaded) => setMessagesById((prev) => ({ ...prev, [id]: loaded })))
123
- .catch((err) =>
124
- setErrorsById((prev) => ({
125
- ...prev,
126
- [id]: err instanceof ApiRequestError ? err.message : "Could not load this conversation's messages.",
127
- }))
128
- )
129
- .finally(() =>
130
- setLoadingIds((prev) => {
131
- const next = new Set(prev);
132
- next.delete(id);
133
- return next;
134
- })
135
- );
136
- }
137
-
138
- if (conversations.length === 0) {
139
- return <p className="p-4 text-sm text-text-muted">No conversations in this folder.</p>;
140
- }
141
-
142
- return (
143
- // `overflow-x-clip`: the panels a swiped row drags along stand outside its edges (see `SwipeRow`).
144
- <ul className={swipe?.enabled ? "overflow-x-clip" : undefined}>
145
- {conversations.map((conversation) => {
146
- const id = conversation.conversationId;
147
- const isExpanded = expanded.has(id);
148
- const unread = conversation.unreadCount > 0;
149
- const loaded = messagesById[id];
150
- // `listConversationMessages()` answers oldest first; the rows read in whichever sense the
151
- // list itself is arranged in. Copied before reversing - the fetched array is cached.
152
- const children = loaded && newestFirst ? [...loaded].reverse() : loaded;
153
- const panelId = `conversation-messages-${id}`;
154
- const ticked = selectedConversationIds?.has(id) ?? false;
155
- return (
156
- <li key={id}>
157
- <SwipeRow
158
- as="div"
159
- enabled={!!swipe?.enabled && !selectMode}
160
- onArchive={() => swipe!.onArchive(conversation)}
161
- onMove={() => swipe!.onMove(conversation)}
162
- data-message-uid={conversation.latestMessageUid}
163
- data-unread={unread ? "true" : undefined}
164
- className={rowClass({ unread, selected: conversation.latestMessageUid === selectedUid || ticked }, "flex items-stretch")}
165
- >
166
- <UnreadBar unread={unread} />
167
- {selectMode && (
168
- <span className="shrink-0 flex items-center pl-3">
169
- <input
170
- type="checkbox"
171
- checked={ticked}
172
- onChange={() => onToggleSelected?.(conversation)}
173
- aria-label={`Select conversation: ${conversation.subject || "(no subject)"}`}
174
- className="w-4 h-4 accent-primary"
175
- />
176
- </span>
177
- )}
178
- <button
179
- type="button"
180
- onClick={() => toggle(conversation)}
181
- aria-expanded={isExpanded}
182
- aria-controls={panelId}
183
- aria-label={`${isExpanded ? "Collapse" : "Expand"} conversation: ${conversation.subject || "(no subject)"}`}
184
- className={["shrink-0 px-2 text-text-muted hover:text-text", ROW_FOCUS_CLASS].join(" ")}
185
- >
186
- {isExpanded ? (
187
- <HiChevronDown size={16} aria-hidden="true" />
188
- ) : (
189
- <HiChevronRight size={16} aria-hidden="true" />
190
- )}
191
- </button>
192
- {/* The open button and, for a meeting request, its RSVP chip: a button can't hold a button, so the chip is the button's sibling. */}
193
- <div className="flex-1 min-w-0 flex flex-col">
194
- <button
195
- type="button"
196
- data-row-open
197
- onClick={() => onOpenMessage(conversation, conversation.latestMessageUid)}
198
- className={["w-full text-left pr-4 py-3", ROW_FOCUS_CLASS].join(" ")}
199
- >
200
- <UnreadLabel unread={unread} />
201
- <div className="flex items-center justify-between gap-2 text-sm">
202
- {/* The first participant in full - name and address - and the rest as a count, with everyone's
203
- address in its tooltip; the latest sender when the summary lists none. */}
204
- <MailAddress
205
- recipient={conversation.participants[0] ?? conversation.latestFrom}
206
- className={["flex-1", senderClass(unread)].join(" ")}
207
- />
208
- {conversation.participants.length > 1 && (
209
- <span className="text-xs text-text-muted shrink-0 font-normal" title={participantList(conversation)}>
210
- +{conversation.participants.length - 1}
211
- <span className="sr-only"> more: {participantList(conversation)}</span>
212
- </span>
213
- )}
214
- <span className={["text-xs shrink-0", dateClass(unread)].join(" ")}>
215
- {new Date(conversation.latestDate).toLocaleDateString()}
216
- </span>
217
- </div>
218
- <div className={["text-sm truncate", subjectClass(unread)].join(" ")}>{conversation.subject || "(no subject)"}</div>
219
- <div className="text-xs text-text-muted truncate font-normal">
220
- {/* An encrypted latest message has no preview (the server never had its plaintext): say so, with a lock, not nothing. */}
221
- {conversationLooksEncrypted(conversation) ? <EncryptedPreview /> : conversation.latestPreview}
222
- </div>
223
- <div className="flex items-center gap-2 mt-1 text-xs text-text-muted font-normal">
224
- {conversation.messageCount > 1 && <span>{conversation.messageCount} messages</span>}
225
- {/* A one-message conversation's unread state is already the row's own
226
- bolding - counting it "1 unread" on every such row is just noise. */}
227
- {unread && conversation.messageCount > 1 && (
228
- <span className="py-0.5 px-2 rounded-pill bg-primary/15 text-primary-dark font-bold">
229
- {conversation.unreadCount} unread
230
- </span>
231
- )}
232
- {conversation.hasAttachments && (
233
- <HiOutlinePaperClip size={13} aria-label="Has attachments" />
234
- )}
235
- {conversation.flagged && (
236
- <HiOutlineFlag size={13} aria-label="Flagged" className="text-danger" />
237
- )}
238
- </div>
239
- </button>
240
- <InviteRowChip
241
- message={
242
- {
243
- uid: conversation.latestMessageUid,
244
- meetingMethod: conversation.latestMeetingMethod ?? undefined,
245
- meetingResponse:
246
- answers[conversation.latestMessageUid] ??
247
- messageOverrides?.[conversation.latestMessageUid]?.meetingResponse ??
248
- conversation.latestMeetingResponse ??
249
- undefined,
250
- } as Message
251
- }
252
- onResponded={answered}
253
- className="mr-4"
254
- />
255
- </div>
256
- </SwipeRow>
257
- <ul id={panelId} hidden={!isExpanded}>
258
- {errorsById[id] && (
259
- <li role="alert" className="pl-8 pr-4 py-2 text-xs text-danger border-b border-border">
260
- {errorsById[id]}
261
- </li>
262
- )}
263
- {loadingIds.has(id) && (
264
- <li className="pl-8 pr-4 py-2 text-xs text-text-muted border-b border-border">
265
- Loading messages&hellip;
266
- </li>
267
- )}
268
- {children?.map((fetched) => {
269
- const message = messageOverrides?.[fetched.uid] ?? fetched;
270
- const messageUnread = isUnread(message);
271
- return (
272
- <li
273
- key={message.uid}
274
- data-message-uid={message.uid}
275
- data-unread={messageUnread ? "true" : undefined}
276
- className={rowClass({ unread: messageUnread, selected: message.uid === selectedUid })}
277
- >
278
- <UnreadBar unread={messageUnread} />
279
- <button
280
- type="button"
281
- data-row-open
282
- onClick={() => onOpenMessage(conversation, message.uid)}
283
- className={["w-full text-left pl-8 pr-4 py-2", ROW_FOCUS_CLASS].join(" ")}
284
- >
285
- <UnreadLabel unread={messageUnread} />
286
- <div className="flex items-center justify-between gap-2 text-sm">
287
- <MailAddress recipient={message.from} className={senderClass(messageUnread)} />
288
- <span className={["text-xs shrink-0", dateClass(messageUnread)].join(" ")}>
289
- {new Date(message.receivedDate).toLocaleDateString()}
290
- </span>
291
- </div>
292
- <div className="flex items-center gap-2 text-xs text-text-muted font-normal">
293
- <span className="truncate">{message.bodyPreview || (message.encrypted ? <EncryptedPreview /> : null)}</span>
294
- {message.hasAttachments && (
295
- <HiOutlinePaperClip size={12} aria-label="Has attachments" />
296
- )}
297
- {message.flags.flagged && (
298
- <HiOutlineFlag
299
- size={12}
300
- aria-label="Flagged"
301
- className="text-danger"
302
- />
303
- )}
304
- </div>
305
- </button>
306
- <InviteRowChip
307
- message={{ ...message, meetingResponse: answers[message.uid] ?? message.meetingResponse }}
308
- onResponded={(updated) => {
309
- answered(updated);
310
- onMeetingResponded?.(updated);
311
- }}
312
- className="ml-8 mr-4"
313
- />
314
- </li>
315
- );
316
- })}
317
- </ul>
318
- </li>
319
- );
320
- })}
321
- </ul>
322
- );
323
- }
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import React, { useState } from "react";
6
+ import { HiChevronDown, HiChevronRight, HiOutlineFlag, HiOutlinePaperClip } from "react-icons/hi2";
7
+ import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
8
+ import { Message } from "@rapidmx/react-shared/mail/mailApi.js";
9
+ import { formatMailAddress } from "@rapidmx/react-shared/mail/mailAddress.js";
10
+ import MailAddress from "./MailAddress.js";
11
+ import { EncryptedPreview, conversationLooksEncrypted } from "./reading/EncryptedPreview.js";
12
+ import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
13
+ import { ROW_FOCUS_CLASS, UnreadBar, UnreadLabel, dateClass, isUnread, rowClass, senderClass, subjectClass } from "./unreadStyle.js";
14
+ import SwipeRow from "./SwipeRow.js";
15
+ import InviteRowChip from "./invite/InviteRowChip.js";
16
+
17
+ export interface ConversationListProps {
18
+ conversations: ConversationSummary[];
19
+ /** The mailbox the conversations were listed from - `listConversationMessages()` is mailbox-scoped. */
20
+ mailboxUid: string;
21
+ /** The message currently open in the reading pane, so the row standing for it can be marked. */
22
+ selectedUid: string | null;
23
+ /**
24
+ * Opens a conversation in the reading pane, positioned at one of its messages: the one a child row
25
+ * stands for, or the conversation's own `latestMessageUid` for a parent row. The conversation goes
26
+ * with the uid because the pane shows the whole thread, not just that message.
27
+ */
28
+ onOpenMessage: (conversation: ConversationSummary, uid: string) => void;
29
+ /** Newer copies of messages this list already fetched - the reading pane marks the message it opens as
30
+ * read, which this list would otherwise keep showing as unread until the thread is collapsed and
31
+ * expanded again. */
32
+ messageOverrides?: Record<string, Message>;
33
+ /** Called with one of a conversation's own messages carrying the answer the reader just gave to its meeting request (from that row's RSVP chip), so the caller can keep it. An answer given from the conversation's own (parent) row is kept by this list itself. */
34
+ onMeetingResponded?: (updated: Message) => void;
35
+ /** Turns each parent row into a checkbox row: select mode here ticks whole conversations, since a
36
+ * conversation is what this list's rows are. A child row stays a plain "open this message" button - a
37
+ * mixed conversation/message selection has no sensible bulk semantics (see `MailListToolbar`). */
38
+ selectMode?: boolean;
39
+ /** The `conversationId`s currently ticked. */
40
+ selectedConversationIds?: Set<string>;
41
+ onToggleSelected?: (conversation: ConversationSummary) => void;
42
+ /**
43
+ * What swiping a parent row does on a phone: right to left archives the conversation (resolving whether it went through), left
44
+ * to right asks where to move it. Absent, or `enabled: false` (a desktop), rows don't follow a finger.
45
+ */
46
+ swipe?: {
47
+ enabled: boolean;
48
+ onArchive: (conversation: ConversationSummary) => Promise<boolean>;
49
+ onMove: (conversation: ConversationSummary) => void;
50
+ };
51
+ /**
52
+ * Whether a conversation's own messages read newest first, matching the order sense the rows themselves
53
+ * are in ("Newest on top"). `listConversationMessages()` always answers oldest first - the order a
54
+ * thread is read in - so this reverses that copy for display rather than asking for it differently.
55
+ */
56
+ newestFirst?: boolean;
57
+ }
58
+
59
+ /** Every participant as `Name <address>`, for the tooltip and the accessible text of the "+N" a crowded row folds them into. */
60
+ function participantList(conversation: ConversationSummary): string {
61
+ return conversation.participants.map((participant) => formatMailAddress(participant)).join(", ");
62
+ }
63
+
64
+ /**
65
+ * The nested, Outlook-style conversation list: one parent row per conversation - its participants, subject,
66
+ * message count, unread count, flag/attachment hints and the latest message's preview - expanding via its
67
+ * own chevron into the conversation's individual messages as child rows, fetched on first expand with
68
+ * `listConversationMessages()` (one request for the whole thread, across folders, oldest first).
69
+ *
70
+ * Opening a row opens the whole conversation in `ConversationThreadPane`, positioned at the message the row
71
+ * stands for: the latest one for a parent row, that one for a child row.
72
+ *
73
+ * The chevron is a button of its own beside the row's own button rather than inside it (a button can't
74
+ * nest inside a button), so expanding and opening are separately reachable by keyboard and each carries
75
+ * its own name.
76
+ */
77
+ export default function ConversationList({
78
+ conversations,
79
+ mailboxUid,
80
+ selectedUid,
81
+ onOpenMessage,
82
+ messageOverrides,
83
+ onMeetingResponded,
84
+ selectMode,
85
+ selectedConversationIds,
86
+ onToggleSelected,
87
+ swipe,
88
+ newestFirst,
89
+ }: ConversationListProps) {
90
+ const [expanded, setExpanded] = useState<Set<string>>(new Set());
91
+ const [messagesById, setMessagesById] = useState<Record<string, Message[]>>({});
92
+ const [loadingIds, setLoadingIds] = useState<Set<string>>(new Set());
93
+ const [errorsById, setErrorsById] = useState<Record<string, string>>({});
94
+ // The answers given from a row's RSVP chip, by message uid: a row draws them at once, whichever row (the conversation's, or one of its messages) they were given from.
95
+ const [answers, setAnswers] = useState<Record<string, Message["meetingResponse"]>>({});
96
+
97
+ function answered(updated: Message) {
98
+ setAnswers((prev) => ({ ...prev, [updated.uid]: updated.meetingResponse }));
99
+ }
100
+
101
+ function toggle(conversation: ConversationSummary) {
102
+ const id = conversation.conversationId;
103
+ setExpanded((prev) => {
104
+ const next = new Set(prev);
105
+ if (next.has(id)) {
106
+ next.delete(id);
107
+ } else {
108
+ next.add(id);
109
+ }
110
+ return next;
111
+ });
112
+ if (expanded.has(id) || messagesById[id] || loadingIds.has(id)) {
113
+ return;
114
+ }
115
+ setLoadingIds((prev) => new Set(prev).add(id));
116
+ setErrorsById((prev) => {
117
+ const next = { ...prev };
118
+ delete next[id];
119
+ return next;
120
+ });
121
+ listConversationMessages(mailboxUid, id)
122
+ .then((loaded) => setMessagesById((prev) => ({ ...prev, [id]: loaded })))
123
+ .catch((err) =>
124
+ setErrorsById((prev) => ({
125
+ ...prev,
126
+ [id]: err instanceof ApiRequestError ? err.message : "Could not load this conversation's messages.",
127
+ }))
128
+ )
129
+ .finally(() =>
130
+ setLoadingIds((prev) => {
131
+ const next = new Set(prev);
132
+ next.delete(id);
133
+ return next;
134
+ })
135
+ );
136
+ }
137
+
138
+ if (conversations.length === 0) {
139
+ return <p className="p-4 text-sm text-text-muted">No conversations in this folder.</p>;
140
+ }
141
+
142
+ return (
143
+ // `overflow-x-clip`: the panels a swiped row drags along stand outside its edges (see `SwipeRow`).
144
+ <ul className={swipe?.enabled ? "overflow-x-clip" : undefined}>
145
+ {conversations.map((conversation) => {
146
+ const id = conversation.conversationId;
147
+ const isExpanded = expanded.has(id);
148
+ const unread = conversation.unreadCount > 0;
149
+ const loaded = messagesById[id];
150
+ // `listConversationMessages()` answers oldest first; the rows read in whichever sense the
151
+ // list itself is arranged in. Copied before reversing - the fetched array is cached.
152
+ const children = loaded && newestFirst ? [...loaded].reverse() : loaded;
153
+ const panelId = `conversation-messages-${id}`;
154
+ const ticked = selectedConversationIds?.has(id) ?? false;
155
+ return (
156
+ <li key={id}>
157
+ <SwipeRow
158
+ as="div"
159
+ enabled={!!swipe?.enabled && !selectMode}
160
+ onArchive={() => swipe!.onArchive(conversation)}
161
+ onMove={() => swipe!.onMove(conversation)}
162
+ data-message-uid={conversation.latestMessageUid}
163
+ data-unread={unread ? "true" : undefined}
164
+ className={rowClass({ unread, selected: conversation.latestMessageUid === selectedUid || ticked }, "flex items-stretch")}
165
+ >
166
+ <UnreadBar unread={unread} />
167
+ {selectMode && (
168
+ <span className="shrink-0 flex items-center pl-3">
169
+ <input
170
+ type="checkbox"
171
+ checked={ticked}
172
+ onChange={() => onToggleSelected?.(conversation)}
173
+ aria-label={`Select conversation: ${conversation.subject || "(no subject)"}`}
174
+ className="w-4 h-4 accent-primary"
175
+ />
176
+ </span>
177
+ )}
178
+ <button
179
+ type="button"
180
+ onClick={() => toggle(conversation)}
181
+ aria-expanded={isExpanded}
182
+ aria-controls={panelId}
183
+ aria-label={`${isExpanded ? "Collapse" : "Expand"} conversation: ${conversation.subject || "(no subject)"}`}
184
+ className={["shrink-0 px-2 text-text-muted hover:text-text", ROW_FOCUS_CLASS].join(" ")}
185
+ >
186
+ {isExpanded ? (
187
+ <HiChevronDown size={16} aria-hidden="true" />
188
+ ) : (
189
+ <HiChevronRight size={16} aria-hidden="true" />
190
+ )}
191
+ </button>
192
+ {/* The open button and, for a meeting request, its RSVP chip: a button can't hold a button, so the chip is the button's sibling. */}
193
+ <div className="flex-1 min-w-0 flex flex-col">
194
+ <button
195
+ type="button"
196
+ data-row-open
197
+ onClick={() => onOpenMessage(conversation, conversation.latestMessageUid)}
198
+ className={["w-full text-left pr-4 py-3", ROW_FOCUS_CLASS].join(" ")}
199
+ >
200
+ <UnreadLabel unread={unread} />
201
+ <div className="flex items-center justify-between gap-2 text-sm">
202
+ {/* The first participant in full - name and address - and the rest as a count, with everyone's
203
+ address in its tooltip; the latest sender when the summary lists none. */}
204
+ <MailAddress
205
+ recipient={conversation.participants[0] ?? conversation.latestFrom}
206
+ className={["flex-1", senderClass(unread)].join(" ")}
207
+ />
208
+ {conversation.participants.length > 1 && (
209
+ <span className="text-xs text-text-muted shrink-0 font-normal" title={participantList(conversation)}>
210
+ +{conversation.participants.length - 1}
211
+ <span className="sr-only"> more: {participantList(conversation)}</span>
212
+ </span>
213
+ )}
214
+ <span className={["text-xs shrink-0", dateClass(unread)].join(" ")}>
215
+ {new Date(conversation.latestDate).toLocaleDateString()}
216
+ </span>
217
+ </div>
218
+ <div className={["text-sm truncate", subjectClass(unread)].join(" ")}>{conversation.subject || "(no subject)"}</div>
219
+ <div className="text-xs text-text-muted truncate font-normal">
220
+ {/* An encrypted latest message has no preview (the server never had its plaintext): say so, with a lock, not nothing. */}
221
+ {conversationLooksEncrypted(conversation) ? <EncryptedPreview /> : conversation.latestPreview}
222
+ </div>
223
+ <div className="flex items-center gap-2 mt-1 text-xs text-text-muted font-normal">
224
+ {conversation.messageCount > 1 && <span>{conversation.messageCount} messages</span>}
225
+ {/* A one-message conversation's unread state is already the row's own
226
+ bolding - counting it "1 unread" on every such row is just noise. */}
227
+ {unread && conversation.messageCount > 1 && (
228
+ <span className="py-0.5 px-2 rounded-pill bg-primary/15 text-primary-dark font-bold">
229
+ {conversation.unreadCount} unread
230
+ </span>
231
+ )}
232
+ {conversation.hasAttachments && (
233
+ <HiOutlinePaperClip size={13} aria-label="Has attachments" />
234
+ )}
235
+ {conversation.flagged && (
236
+ <HiOutlineFlag size={13} aria-label="Flagged" className="text-danger" />
237
+ )}
238
+ </div>
239
+ </button>
240
+ <InviteRowChip
241
+ message={
242
+ {
243
+ uid: conversation.latestMessageUid,
244
+ meetingMethod: conversation.latestMeetingMethod ?? undefined,
245
+ meetingResponse:
246
+ answers[conversation.latestMessageUid] ??
247
+ messageOverrides?.[conversation.latestMessageUid]?.meetingResponse ??
248
+ conversation.latestMeetingResponse ??
249
+ undefined,
250
+ } as Message
251
+ }
252
+ onResponded={answered}
253
+ className="mr-4"
254
+ />
255
+ </div>
256
+ </SwipeRow>
257
+ <ul id={panelId} hidden={!isExpanded}>
258
+ {errorsById[id] && (
259
+ <li role="alert" className="pl-8 pr-4 py-2 text-xs text-danger border-b border-border">
260
+ {errorsById[id]}
261
+ </li>
262
+ )}
263
+ {loadingIds.has(id) && (
264
+ <li className="pl-8 pr-4 py-2 text-xs text-text-muted border-b border-border">
265
+ Loading messages&hellip;
266
+ </li>
267
+ )}
268
+ {children?.map((fetched) => {
269
+ const message = messageOverrides?.[fetched.uid] ?? fetched;
270
+ const messageUnread = isUnread(message);
271
+ return (
272
+ <li
273
+ key={message.uid}
274
+ data-message-uid={message.uid}
275
+ data-unread={messageUnread ? "true" : undefined}
276
+ className={rowClass({ unread: messageUnread, selected: message.uid === selectedUid })}
277
+ >
278
+ <UnreadBar unread={messageUnread} />
279
+ <button
280
+ type="button"
281
+ data-row-open
282
+ onClick={() => onOpenMessage(conversation, message.uid)}
283
+ className={["w-full text-left pl-8 pr-4 py-2", ROW_FOCUS_CLASS].join(" ")}
284
+ >
285
+ <UnreadLabel unread={messageUnread} />
286
+ <div className="flex items-center justify-between gap-2 text-sm">
287
+ <MailAddress recipient={message.from} className={senderClass(messageUnread)} />
288
+ <span className={["text-xs shrink-0", dateClass(messageUnread)].join(" ")}>
289
+ {new Date(message.receivedDate).toLocaleDateString()}
290
+ </span>
291
+ </div>
292
+ <div className="flex items-center gap-2 text-xs text-text-muted font-normal">
293
+ <span className="truncate">{message.bodyPreview || (message.encrypted ? <EncryptedPreview /> : null)}</span>
294
+ {message.hasAttachments && (
295
+ <HiOutlinePaperClip size={12} aria-label="Has attachments" />
296
+ )}
297
+ {message.flags.flagged && (
298
+ <HiOutlineFlag
299
+ size={12}
300
+ aria-label="Flagged"
301
+ className="text-danger"
302
+ />
303
+ )}
304
+ </div>
305
+ </button>
306
+ <InviteRowChip
307
+ message={{ ...message, meetingResponse: answers[message.uid] ?? message.meetingResponse }}
308
+ onResponded={(updated) => {
309
+ answered(updated);
310
+ onMeetingResponded?.(updated);
311
+ }}
312
+ className="ml-8 mr-4"
313
+ />
314
+ </li>
315
+ );
316
+ })}
317
+ </ul>
318
+ </li>
319
+ );
320
+ })}
321
+ </ul>
322
+ );
323
+ }