@rapidmx/web-client 0.14.1 → 0.15.1
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/apps/admin/domains/[uid].tsx +3 -2
- package/apps/shared/appearance/AppearanceForm.tsx +9 -1
- package/apps/shared/calendar/bookingPlugin.ts +100 -0
- package/apps/shared/calendar/calendarLiveUpdates.ts +27 -0
- package/apps/shared/components/admin/layout/AdminShell.tsx +37 -5
- package/apps/shared/components/admin/settings/MailboxCreateForm.tsx +3 -1
- package/apps/shared/components/admin/settings/PluginsManager.tsx +1545 -1491
- package/apps/shared/components/calendar/AppointmentQuickForm.tsx +327 -0
- package/apps/shared/components/calendar/DescriptionEditor.tsx +274 -0
- package/apps/shared/components/calendar/EventDescriptionView.tsx +70 -0
- package/apps/shared/components/calendar/EventDetails.tsx +401 -0
- package/apps/shared/components/calendar/EventEditor.tsx +640 -0
- package/apps/shared/components/calendar/EventExpandedForm.tsx +210 -0
- package/apps/shared/components/calendar/EventFormParts.tsx +622 -0
- package/apps/shared/components/calendar/EventModal.tsx +126 -866
- package/apps/shared/components/calendar/EventQuickForm.tsx +116 -0
- package/apps/shared/components/calendar/EventShell.tsx +202 -0
- package/apps/shared/components/calendar/FindATime.tsx +379 -0
- package/apps/shared/components/calendar/LazyDescriptionEditor.tsx +70 -0
- package/apps/shared/components/calendar/MonthView.tsx +15 -3
- package/apps/shared/components/calendar/QuickCreateFaces.tsx +87 -0
- package/apps/shared/components/calendar/QuickCreateTabs.tsx +81 -0
- package/apps/shared/components/calendar/QuickFaceFrame.tsx +81 -0
- package/apps/shared/components/calendar/RecurrenceEditor.tsx +10 -5
- package/apps/shared/components/calendar/RequestChangeForm.tsx +271 -0
- package/apps/shared/components/calendar/SplitDayView.tsx +6 -5
- package/apps/shared/components/calendar/TaskQuickForm.tsx +289 -0
- package/apps/shared/components/calendar/TimeGridView.tsx +8 -6
- package/apps/shared/components/calendar/eventDialogFields.ts +86 -0
- package/apps/shared/components/calendar/eventForm.ts +108 -0
- package/apps/shared/components/calendar/eventFormat.ts +183 -0
- package/apps/shared/components/calendar/findTimeGrid.ts +90 -0
- package/apps/shared/components/calendar/swipeNavigation.ts +14 -0
- package/apps/shared/components/layout/UserMenu.tsx +80 -28
- package/apps/shared/components/mail/ConversationList.tsx +100 -48
- package/apps/shared/components/mail/ConversationThreadPane.tsx +490 -486
- package/apps/shared/components/mail/InviteCard.tsx +387 -0
- package/apps/shared/components/mail/MessageDetailPane.tsx +24 -2
- package/apps/shared/components/mail/SwipeRow.tsx +120 -0
- package/apps/shared/components/mail/compose/ComposeWindow.tsx +7 -3
- package/apps/shared/components/mail/invite/InviteRowChip.tsx +104 -0
- package/apps/shared/components/mail/invite/InviteRsvpPopover.tsx +271 -0
- package/apps/shared/components/mail/invite/InviteTimeline.tsx +200 -0
- package/apps/shared/components/mail/invite/ProposeTimeForm.tsx +109 -0
- package/apps/shared/components/mail/invite/inviteFormat.ts +110 -0
- package/apps/shared/components/mail/invite/inviteStore.ts +114 -0
- package/apps/shared/components/mail/layout/MailShell.tsx +522 -490
- package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
- package/apps/shared/gestures/useEnterSlide.ts +54 -0
- package/apps/shared/gestures/useSwipe.ts +114 -0
- package/apps/shared/gestures/useSwipeSlide.ts +113 -0
- package/apps/shared/gestures/useWheelPaging.ts +107 -0
- package/apps/shared/mail/newMailNotifications.ts +171 -183
- package/apps/shared/mail/useNewMailNotifications.ts +178 -178
- package/apps/shared/notifications/preferences.ts +36 -0
- package/apps/shared/notifications/store.ts +560 -551
- package/apps/www/_routes.ts +1 -0
- package/apps/www/calendar/index.tsx +139 -37
- package/apps/www/index.tsx +273 -126
- package/apps/www/messages/[uid].tsx +31 -4
- package/apps/www/settings/profile/index.tsx +248 -0
- package/dist/apps/admin/domains/[uid].js +4 -2
- package/dist/apps/shared/appearance/AppearanceForm.js +9 -1
- package/dist/apps/shared/calendar/bookingPlugin.d.ts +50 -0
- package/dist/apps/shared/calendar/bookingPlugin.js +57 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.d.ts +11 -0
- package/dist/apps/shared/calendar/calendarLiveUpdates.js +23 -0
- package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
- package/dist/apps/shared/components/admin/layout/AdminShell.js +7 -3
- package/dist/apps/shared/components/admin/settings/MailboxCreateForm.js +3 -1
- package/dist/apps/shared/components/admin/settings/PluginsManager.js +40 -6
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.d.ts +47 -0
- package/dist/apps/shared/components/calendar/AppointmentQuickForm.js +135 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.d.ts +26 -0
- package/dist/apps/shared/components/calendar/DescriptionEditor.js +192 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventDescriptionView.js +39 -0
- package/dist/apps/shared/components/calendar/EventDetails.d.ts +33 -0
- package/dist/apps/shared/components/calendar/EventDetails.js +137 -0
- package/dist/apps/shared/components/calendar/EventEditor.d.ts +59 -0
- package/dist/apps/shared/components/calendar/EventEditor.js +549 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.d.ts +14 -0
- package/dist/apps/shared/components/calendar/EventExpandedForm.js +44 -0
- package/dist/apps/shared/components/calendar/EventFormParts.d.ts +69 -0
- package/dist/apps/shared/components/calendar/EventFormParts.js +202 -0
- package/dist/apps/shared/components/calendar/EventModal.d.ts +26 -13
- package/dist/apps/shared/components/calendar/EventModal.js +57 -459
- package/dist/apps/shared/components/calendar/EventQuickForm.d.ts +18 -0
- package/dist/apps/shared/components/calendar/EventQuickForm.js +25 -0
- package/dist/apps/shared/components/calendar/EventShell.d.ts +64 -0
- package/dist/apps/shared/components/calendar/EventShell.js +134 -0
- package/dist/apps/shared/components/calendar/FindATime.d.ts +18 -0
- package/dist/apps/shared/components/calendar/FindATime.js +190 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.d.ts +8 -0
- package/dist/apps/shared/components/calendar/LazyDescriptionEditor.js +44 -0
- package/dist/apps/shared/components/calendar/MonthView.d.ts +5 -1
- package/dist/apps/shared/components/calendar/MonthView.js +11 -5
- package/dist/apps/shared/components/calendar/QuickCreateFaces.d.ts +30 -0
- package/dist/apps/shared/components/calendar/QuickCreateFaces.js +44 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.d.ts +24 -0
- package/dist/apps/shared/components/calendar/QuickCreateTabs.js +46 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.d.ts +25 -0
- package/dist/apps/shared/components/calendar/QuickFaceFrame.js +19 -0
- package/dist/apps/shared/components/calendar/RecurrenceEditor.d.ts +4 -1
- package/dist/apps/shared/components/calendar/RecurrenceEditor.js +2 -2
- package/dist/apps/shared/components/calendar/RequestChangeForm.d.ts +36 -0
- package/dist/apps/shared/components/calendar/RequestChangeForm.js +138 -0
- package/dist/apps/shared/components/calendar/SplitDayView.d.ts +3 -2
- package/dist/apps/shared/components/calendar/SplitDayView.js +3 -2
- package/dist/apps/shared/components/calendar/TaskQuickForm.d.ts +40 -0
- package/dist/apps/shared/components/calendar/TaskQuickForm.js +101 -0
- package/dist/apps/shared/components/calendar/TimeGridView.d.ts +4 -2
- package/dist/apps/shared/components/calendar/TimeGridView.js +3 -2
- package/dist/apps/shared/components/calendar/eventDialogFields.d.ts +28 -0
- package/dist/apps/shared/components/calendar/eventDialogFields.js +59 -0
- package/dist/apps/shared/components/calendar/eventForm.d.ts +98 -0
- package/dist/apps/shared/components/calendar/eventForm.js +1 -0
- package/dist/apps/shared/components/calendar/eventFormat.d.ts +67 -0
- package/dist/apps/shared/components/calendar/eventFormat.js +163 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.d.ts +30 -0
- package/dist/apps/shared/components/calendar/findTimeGrid.js +83 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.d.ts +9 -0
- package/dist/apps/shared/components/calendar/swipeNavigation.js +8 -0
- package/dist/apps/shared/components/layout/UserMenu.d.ts +10 -8
- package/dist/apps/shared/components/layout/UserMenu.js +70 -23
- package/dist/apps/shared/components/mail/ConversationList.d.ts +12 -1
- package/dist/apps/shared/components/mail/ConversationList.js +21 -4
- package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +4 -1
- package/dist/apps/shared/components/mail/InviteCard.d.ts +20 -0
- package/dist/apps/shared/components/mail/InviteCard.js +150 -0
- package/dist/apps/shared/components/mail/MessageDetailPane.js +13 -2
- package/dist/apps/shared/components/mail/SwipeRow.d.ts +22 -0
- package/dist/apps/shared/components/mail/SwipeRow.js +71 -0
- package/dist/apps/shared/components/mail/compose/ComposeWindow.js +8 -3
- package/dist/apps/shared/components/mail/invite/InviteRowChip.d.ts +23 -0
- package/dist/apps/shared/components/mail/invite/InviteRowChip.js +46 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.d.ts +20 -0
- package/dist/apps/shared/components/mail/invite/InviteRsvpPopover.js +141 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.d.ts +27 -0
- package/dist/apps/shared/components/mail/invite/InviteTimeline.js +120 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.d.ts +17 -0
- package/dist/apps/shared/components/mail/invite/ProposeTimeForm.js +45 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteFormat.js +94 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.d.ts +28 -0
- package/dist/apps/shared/components/mail/invite/inviteStore.js +95 -0
- package/dist/apps/shared/components/mail/layout/MailShell.d.ts +5 -0
- package/dist/apps/shared/components/mail/layout/MailShell.js +14 -3
- package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
- package/dist/apps/shared/gestures/useEnterSlide.d.ts +14 -0
- package/dist/apps/shared/gestures/useEnterSlide.js +47 -0
- package/dist/apps/shared/gestures/useSwipe.d.ts +45 -0
- package/dist/apps/shared/gestures/useSwipe.js +90 -0
- package/dist/apps/shared/gestures/useSwipeSlide.d.ts +40 -0
- package/dist/apps/shared/gestures/useSwipeSlide.js +95 -0
- package/dist/apps/shared/gestures/useWheelPaging.d.ts +32 -0
- package/dist/apps/shared/gestures/useWheelPaging.js +85 -0
- package/dist/apps/shared/mail/newMailNotifications.d.ts +3 -8
- package/dist/apps/shared/mail/newMailNotifications.js +3 -12
- package/dist/apps/shared/mail/useNewMailNotifications.js +3 -2
- package/dist/apps/shared/notifications/preferences.d.ts +13 -0
- package/dist/apps/shared/notifications/preferences.js +36 -0
- package/dist/apps/shared/notifications/store.d.ts +1 -0
- package/dist/apps/shared/notifications/store.js +7 -23
- package/dist/apps/www/_routes.js +1 -0
- package/dist/apps/www/calendar/index.js +76 -6
- package/dist/apps/www/index.js +140 -39
- package/dist/apps/www/messages/[uid].js +13 -5
- package/dist/apps/www/settings/profile/index.d.ts +4 -0
- package/dist/apps/www/settings/profile/index.js +124 -0
- package/package.json +2 -2
|
@@ -1,487 +1,491 @@
|
|
|
1
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
-
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
-
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
-
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
-
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
-
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
-
import { Attachment, Folder, Message, listAttachments } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
8
|
-
import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
|
|
9
|
-
import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
10
|
-
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
11
|
-
import MessageDetailPane from "./MessageDetailPane.js";
|
|
1
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
2
|
+
// Copyright (C) 2026 Jean-Philippe Steinmetz
|
|
3
|
+
// SPDX-License-Identifier: MPL-2.0
|
|
4
|
+
///////////////////////////////////////////////////////////////////////////////
|
|
5
|
+
import React, { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
6
|
+
import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
|
|
7
|
+
import { Attachment, Folder, Message, listAttachments } from "@rapidmx/react-shared/mail/mailApi.js";
|
|
8
|
+
import { ConversationSummary, listConversationMessages } from "@rapidmx/react-shared/mail/conversationsApi.js";
|
|
9
|
+
import { Label } from "@rapidmx/react-shared/mail/labelsApi.js";
|
|
10
|
+
import Alert from "@rapidmx/react-shared/components/feedback/Alert.js";
|
|
11
|
+
import MessageDetailPane from "./MessageDetailPane.js";
|
|
12
12
|
import { EncryptedPreview, displaySubject } from "./reading/EncryptedPreview.js";
|
|
13
|
-
import { CollapsedCard, SkeletonCards, SubjectCard } from "./reading/MessageCard.js";
|
|
14
|
-
import { useMailShell } from "./layout/MailShell.js";
|
|
15
|
-
import { setReadState } from "../../mail/messageReadState.js";
|
|
16
|
-
import { dateClass, isUnread, senderClass } from "./unreadStyle.js";
|
|
17
|
-
|
|
18
|
-
/** One request's worth of the thread. The server's own default for `listConversationMessages()`. */
|
|
19
|
-
export const THREAD_PAGE_SIZE = 100;
|
|
20
|
-
/**
|
|
21
|
-
* How many of a conversation's messages this pane will load. The server reads at most
|
|
22
|
-
* `CONVERSATION_SCAN_LIMIT` (500) messages when it groups conversations, so a `ConversationSummary` never
|
|
23
|
-
* describes more than this many anyway; the cap is here so a thread that somehow reports more can't turn
|
|
24
|
-
* into an unbounded run of requests. Past it the pane says so and the rest stay readable from the list.
|
|
25
|
-
*/
|
|
26
|
-
export const THREAD_MESSAGE_LIMIT = 500;
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
*
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
*
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
*
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
*
|
|
101
|
-
*
|
|
102
|
-
* and
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
*
|
|
135
|
-
* the
|
|
136
|
-
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
144
|
-
*
|
|
145
|
-
*
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
const
|
|
164
|
-
const [
|
|
165
|
-
const [
|
|
166
|
-
|
|
167
|
-
const [
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
const
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
*
|
|
180
|
-
const
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
const
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
})
|
|
222
|
-
.
|
|
223
|
-
if (generation
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
//
|
|
250
|
-
//
|
|
251
|
-
//
|
|
252
|
-
//
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
const
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
return
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
//
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
) : (
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
13
|
+
import { CollapsedCard, SkeletonCards, SubjectCard } from "./reading/MessageCard.js";
|
|
14
|
+
import { useMailShell } from "./layout/MailShell.js";
|
|
15
|
+
import { setReadState } from "../../mail/messageReadState.js";
|
|
16
|
+
import { dateClass, isUnread, senderClass } from "./unreadStyle.js";
|
|
17
|
+
|
|
18
|
+
/** One request's worth of the thread. The server's own default for `listConversationMessages()`. */
|
|
19
|
+
export const THREAD_PAGE_SIZE = 100;
|
|
20
|
+
/**
|
|
21
|
+
* How many of a conversation's messages this pane will load. The server reads at most
|
|
22
|
+
* `CONVERSATION_SCAN_LIMIT` (500) messages when it groups conversations, so a `ConversationSummary` never
|
|
23
|
+
* describes more than this many anyway; the cap is here so a thread that somehow reports more can't turn
|
|
24
|
+
* into an unbounded run of requests. Past it the pane says so and the rest stay readable from the list.
|
|
25
|
+
*/
|
|
26
|
+
export const THREAD_MESSAGE_LIMIT = 500;
|
|
27
|
+
|
|
28
|
+
/** What the pane needs to know of a conversation up front: the thread itself is loaded by `conversationId`. The subject and
|
|
29
|
+
* count fill the header while it loads, so a caller that only has a message (the mobile route) gives its subject and a count of 1. */
|
|
30
|
+
export type ConversationThreadHead = Pick<ConversationSummary, "conversationId" | "subject" | "messageCount">;
|
|
31
|
+
|
|
32
|
+
export interface ConversationThreadPaneProps {
|
|
33
|
+
conversation: ConversationThreadHead | null;
|
|
34
|
+
/** The mailbox the conversation was listed from - `listConversationMessages()` is mailbox-scoped. */
|
|
35
|
+
mailboxUid: string;
|
|
36
|
+
/**
|
|
37
|
+
* The message the reader opened: the thread is scrolled to it, it takes focus, and it is the *oldest*
|
|
38
|
+
* message left expanded (see `expandedFrom()`). `null`, or a uid this thread doesn't hold, falls back
|
|
39
|
+
* to the newest message - which is also what a parent row means by "open the conversation".
|
|
40
|
+
*/
|
|
41
|
+
selectedUid: string | null;
|
|
42
|
+
/** The mailbox's full folder list. A conversation spans folders (an Inbox message and the Sent Items
|
|
43
|
+
* copy of its reply), so each message's own folder type is looked up against its own `folderUid`. */
|
|
44
|
+
folders: Folder[];
|
|
45
|
+
/** The mailbox's labels, passed through to every expanded message's own `MessageDetailPane`. */
|
|
46
|
+
labels?: Label[];
|
|
47
|
+
/**
|
|
48
|
+
* A newer copy of one of the thread's messages - read, flagged, labelled, classified, recalled - for
|
|
49
|
+
* the caller's own list to stay in step with what was done in here.
|
|
50
|
+
*
|
|
51
|
+
* `previous` is the copy this pane held before the change, where it has one: the conversation row this
|
|
52
|
+
* thread came from is a *summary* (a message count, an unread count), so a list showing those rows has
|
|
53
|
+
* no way to tell "this message has just been read" from "this already-read message was relabelled"
|
|
54
|
+
* without it - which is what left a row reporting "2 unread" after both had been read.
|
|
55
|
+
*/
|
|
56
|
+
onMessagePatched: (updated: Message, previous?: Message) => void;
|
|
57
|
+
/** A message that left the folder being listed (archived, or a scheduled send sent back to Drafts). */
|
|
58
|
+
onMessageRemoved: (updated: Message) => void;
|
|
59
|
+
onLabelCreated?: (label: Label) => void;
|
|
60
|
+
/** A folder created from a message's own Move to prompt, for the folder sidebar to pick up. */
|
|
61
|
+
onFolderCreated?: (folder: Folder) => void;
|
|
62
|
+
/** Registers the keyboard shortcuts (Reply, Reply all, Forward, Archive, Move to) of the message that was opened - see `MessageDetailPane`'s
|
|
63
|
+
* `shortcuts`. The caller turns it off while it is doing something else with the keyboard (select mode). */
|
|
64
|
+
shortcuts?: boolean;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/**
|
|
68
|
+
* Every message from `selectedUid` through to the newest - the run the reader is reading. Anything older
|
|
69
|
+
* stays collapsed to its one-line summary. Selecting the newest message therefore expands just that one.
|
|
70
|
+
*
|
|
71
|
+
* The pane lists newest first (see `loadThread()`), so that run is the opened message together with
|
|
72
|
+
* everything *above* it, and the opened message is the set's **last** entry rather than its first.
|
|
73
|
+
*/
|
|
74
|
+
function expandedFrom(messages: Message[], selectedUid: string | null): Set<string> {
|
|
75
|
+
const index = messages.findIndex((message) => message.uid === selectedUid);
|
|
76
|
+
// `messages` is never empty here (the callers below check), so -1 means "not in this thread" and the
|
|
77
|
+
// newest message - the first entry - is the anchor, exactly as a parent row's own click means.
|
|
78
|
+
const anchor = index === -1 ? 0 : index;
|
|
79
|
+
return new Set(messages.slice(0, anchor + 1).map((message) => message.uid));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* The element a message of this thread actually scrolls inside. The pane is not itself the scroll
|
|
84
|
+
* container in the mail shell - `MailShell`'s own `<main>` is - so an adjustment has to be applied where
|
|
85
|
+
* the scrolling really happens, which is whichever ancestor is both scrollable and overflowing.
|
|
86
|
+
*/
|
|
87
|
+
function scrollingAncestor(node: HTMLElement): HTMLElement {
|
|
88
|
+
for (let el = node.parentElement; el; el = el.parentElement) {
|
|
89
|
+
const overflowY = getComputedStyle(el).overflowY;
|
|
90
|
+
if ((overflowY === "auto" || overflowY === "scroll") && el.scrollHeight > el.clientHeight) {
|
|
91
|
+
return el;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
// Nothing between the row and the root scrolls, so the page itself does - which in standards mode is
|
|
95
|
+
// `documentElement`, the same element `document.scrollingElement` names there.
|
|
96
|
+
return document.documentElement;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
/**
|
|
100
|
+
* The thread's messages, **newest first**, in pages of `THREAD_PAGE_SIZE` up to `THREAD_MESSAGE_LIMIT`.
|
|
101
|
+
*
|
|
102
|
+
* `listConversationMessages()` pages oldest first and has no order of its own to ask for, so the pages are
|
|
103
|
+
* collected in that order - which is also the order the `THREAD_MESSAGE_LIMIT` cap has to apply in, since it
|
|
104
|
+
* is the oldest messages that are dropped when a thread is too long to load - and reversed once at the end.
|
|
105
|
+
* The pane reads newest first always, whatever the *list* is sorted by: it is the reading order for mail,
|
|
106
|
+
* and it means the message a conversation row stands for is the entry at the top.
|
|
107
|
+
*/
|
|
108
|
+
async function loadThread(mailboxUid: string, conversationId: string): Promise<{ messages: Message[]; truncated: boolean }> {
|
|
109
|
+
const messages: Message[] = [];
|
|
110
|
+
let more = true;
|
|
111
|
+
while (more && messages.length < THREAD_MESSAGE_LIMIT) {
|
|
112
|
+
const page = await listConversationMessages(mailboxUid, conversationId, {
|
|
113
|
+
page: messages.length / THREAD_PAGE_SIZE,
|
|
114
|
+
limit: THREAD_PAGE_SIZE,
|
|
115
|
+
});
|
|
116
|
+
messages.push(...page);
|
|
117
|
+
// A short page is the last one; a full page means asking for another.
|
|
118
|
+
more = page.length === THREAD_PAGE_SIZE;
|
|
119
|
+
}
|
|
120
|
+
messages.reverse();
|
|
121
|
+
return { messages, truncated: more };
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/** Whether the browser is showing a focus ring on `element` - it was focused from the keyboard (or by a key press's handler), not by a click. */
|
|
125
|
+
function hasFocusRing(element: HTMLElement): boolean {
|
|
126
|
+
try {
|
|
127
|
+
return element.matches(":focus-visible");
|
|
128
|
+
} catch {
|
|
129
|
+
return false;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
/**
|
|
134
|
+
* The reading pane for the conversation list: the conversation's subject in a card of its own, pinned at the top, and under it the whole thread as
|
|
135
|
+
* a stack of message cards (each exactly as tall as its message; the list scrolls as a whole), **newest at the top**, opened at the message
|
|
136
|
+
* the reader picked. Every message from that one through to the newest is expanded - which in this order is
|
|
137
|
+
* the opened message and the entries above it - and the older ones, below it, are collapsed to a one-line
|
|
138
|
+
* summary (sender, date, preview) that expands on click or Enter. So opening the newest message shows just
|
|
139
|
+
* the top entry expanded, and opening 5 of 10 expands 10 down to 5.
|
|
140
|
+
*
|
|
141
|
+
* Newest first regardless of how the *list* is sorted: the list's own order arranges rows to pick from,
|
|
142
|
+
* while this is one conversation being read, and the entry a conversation row stands for - its latest
|
|
143
|
+
* message - is the one that should be at the top of the pane every time it is opened.
|
|
144
|
+
*
|
|
145
|
+
* Each *expanded* message is a `MessageDetailPane` of its own rather than a reimplementation of it, so the
|
|
146
|
+
* signature and verification badges, the verification-seal and decryption behaviour, the labels chips and
|
|
147
|
+
* menu, the attachments and Reply/Reply All/Forward/Archive all behave exactly as they do in the
|
|
148
|
+
* single-message pane, and each acts on the message it belongs to. A collapsed message mounts none of
|
|
149
|
+
* that - mounting a body iframe per message up front would be wasteful in a long thread.
|
|
150
|
+
*/
|
|
151
|
+
export default function ConversationThreadPane({
|
|
152
|
+
conversation,
|
|
153
|
+
mailboxUid,
|
|
154
|
+
selectedUid,
|
|
155
|
+
folders,
|
|
156
|
+
labels,
|
|
157
|
+
onMessagePatched,
|
|
158
|
+
onMessageRemoved,
|
|
159
|
+
onLabelCreated,
|
|
160
|
+
onFolderCreated,
|
|
161
|
+
shortcuts,
|
|
162
|
+
}: ConversationThreadPaneProps) {
|
|
163
|
+
const { trackMessageChange } = useMailShell();
|
|
164
|
+
const [messages, setMessages] = useState<Message[]>([]);
|
|
165
|
+
const [attachmentsByUid, setAttachmentsByUid] = useState<Record<string, Attachment[]>>({});
|
|
166
|
+
const [expandedUids, setExpandedUids] = useState<Set<string>>(new Set());
|
|
167
|
+
const [truncated, setTruncated] = useState(false);
|
|
168
|
+
const [loading, setLoading] = useState(false);
|
|
169
|
+
const [error, setError] = useState<string | null>(null);
|
|
170
|
+
/** The message to scroll to and focus once it has rendered, or `null` once that has happened. */
|
|
171
|
+
const [pendingFocusUid, setPendingFocusUid] = useState<string | null>(null);
|
|
172
|
+
|
|
173
|
+
// Bumped on every conversation switch - an in-flight load/attachments/mark-read response carrying an
|
|
174
|
+
// older generation belongs to a superseded conversation and is dropped rather than applied.
|
|
175
|
+
const generationRef = useRef(0);
|
|
176
|
+
const markReadRequestedRef = useRef<Set<string>>(new Set());
|
|
177
|
+
const attachmentsRequestedRef = useRef<Set<string>>(new Set());
|
|
178
|
+
/** The `conversationId:selectedUid` the expansion run below has already been applied for, so patching
|
|
179
|
+
* a message (which changes `messages`) doesn't re-expand what the reader has since collapsed. */
|
|
180
|
+
const appliedSelectionRef = useRef<string | null>(null);
|
|
181
|
+
/** Which conversation the messages currently in state belong to. A render with a new conversation and
|
|
182
|
+
* the previous one's messages still in state happens before the load effect has cleared them, and the
|
|
183
|
+
* expansion run below must sit that render out rather than anchor on a message from another thread. */
|
|
184
|
+
const loadedIdRef = useRef<string | null>(null);
|
|
185
|
+
const rowRefs = useRef<Record<string, HTMLLIElement | null>>({});
|
|
186
|
+
const headerRefs = useRef<Record<string, HTMLButtonElement | null>>({});
|
|
187
|
+
/** Where the toggled message's header sat in the viewport before it expanded, so the run below can put
|
|
188
|
+
* it back there - expanding a message above the one being read must not shove that one off-screen. */
|
|
189
|
+
const anchorRef = useRef<{ uid: string; top: number } | null>(null);
|
|
190
|
+
/** The message whose header button had the focus when it was toggled: expanding or collapsing swaps that button for the other state's, so the
|
|
191
|
+
* focus is put back on the new one. */
|
|
192
|
+
const refocusRef = useRef<string | null>(null);
|
|
193
|
+
|
|
194
|
+
const conversationId = conversation?.conversationId;
|
|
195
|
+
|
|
196
|
+
useEffect(() => {
|
|
197
|
+
const generation = ++generationRef.current;
|
|
198
|
+
markReadRequestedRef.current = new Set();
|
|
199
|
+
attachmentsRequestedRef.current = new Set();
|
|
200
|
+
appliedSelectionRef.current = null;
|
|
201
|
+
loadedIdRef.current = null;
|
|
202
|
+
setMessages([]);
|
|
203
|
+
setAttachmentsByUid({});
|
|
204
|
+
setExpandedUids(new Set());
|
|
205
|
+
setTruncated(false);
|
|
206
|
+
setError(null);
|
|
207
|
+
// The message the previous conversation was to be scrolled to went with it; leaving it set would
|
|
208
|
+
// point the run below at a row that is no longer rendered.
|
|
209
|
+
setPendingFocusUid(null);
|
|
210
|
+
if (!conversationId) {
|
|
211
|
+
setLoading(false);
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
setLoading(true);
|
|
215
|
+
loadThread(mailboxUid, conversationId)
|
|
216
|
+
.then((loaded) => {
|
|
217
|
+
if (generation !== generationRef.current) return;
|
|
218
|
+
loadedIdRef.current = conversationId;
|
|
219
|
+
setMessages(loaded.messages);
|
|
220
|
+
setTruncated(loaded.truncated);
|
|
221
|
+
})
|
|
222
|
+
.catch((err) => {
|
|
223
|
+
if (generation !== generationRef.current) return;
|
|
224
|
+
setError(err instanceof ApiRequestError ? err.message : "Could not load this conversation.");
|
|
225
|
+
})
|
|
226
|
+
.finally(() => {
|
|
227
|
+
if (generation === generationRef.current) setLoading(false);
|
|
228
|
+
});
|
|
229
|
+
}, [conversationId, mailboxUid]);
|
|
230
|
+
|
|
231
|
+
// Opening the thread, and opening a different message of the same thread, both set the run of expanded
|
|
232
|
+
// messages and ask for that message to be scrolled to. `messages` is a dependency because the thread's
|
|
233
|
+
// messages arrive after the click that selected one of them; the ref guard keeps a later change to
|
|
234
|
+
// `messages` (a patched copy) from re-running it.
|
|
235
|
+
useEffect(() => {
|
|
236
|
+
if (messages.length === 0 || loadedIdRef.current !== conversationId) return;
|
|
237
|
+
const key = `${conversationId}:${selectedUid}`;
|
|
238
|
+
if (appliedSelectionRef.current === key) return;
|
|
239
|
+
appliedSelectionRef.current = key;
|
|
240
|
+
const expanded = expandedFrom(messages, selectedUid);
|
|
241
|
+
setExpandedUids(expanded);
|
|
242
|
+
// The oldest expanded message is the one that was opened - `expandedFrom()`'s own anchor - which in
|
|
243
|
+
// this newest-first order is the *last* of the run, not the first.
|
|
244
|
+
setPendingFocusUid([...expanded][expanded.size - 1]);
|
|
245
|
+
}, [conversationId, selectedUid, messages]);
|
|
246
|
+
|
|
247
|
+
useLayoutEffect(() => {
|
|
248
|
+
if (!pendingFocusUid) return;
|
|
249
|
+
// The row is always rendered by now: this runs after the DOM update that added the message it
|
|
250
|
+
// names, and that message came out of `messages` in the first place.
|
|
251
|
+
//
|
|
252
|
+
// Scrolled inside the thread's own list and nowhere else. `scrollIntoView()` scrolls *every*
|
|
253
|
+
// scrollable ancestor, the window included, which with a run of full-height messages expanded
|
|
254
|
+
// took the app header and the folder rail off the screen - so the adjustment goes on whichever
|
|
255
|
+
// ancestor actually scrolls, exactly as the toggle below already does it. When that is the page
|
|
256
|
+
// itself, nothing inside the pane scrolls and the row is already in view, so it is left alone.
|
|
257
|
+
const row = rowRefs.current[pendingFocusUid]!;
|
|
258
|
+
const scroller = scrollingAncestor(row);
|
|
259
|
+
if (scroller !== document.documentElement) {
|
|
260
|
+
const rect = row.getBoundingClientRect();
|
|
261
|
+
const top = rect.top - scroller.getBoundingClientRect().top;
|
|
262
|
+
// "nearest": the least that brings it into view, and nothing at all when it is already there.
|
|
263
|
+
if (top < 0 || top + rect.height > scroller.clientHeight) {
|
|
264
|
+
scroller.scrollTop += top;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
// A key press (j, k, the arrows) that opened this thread left the focus on its list row on purpose, so Enter goes on to open the
|
|
268
|
+
// message's page; taking the focus here would make Enter toggle this header instead. A click leaves no focus ring, and hands
|
|
269
|
+
// the focus to the thread as before.
|
|
270
|
+
const active = document.activeElement;
|
|
271
|
+
if (!(active instanceof HTMLElement && active.hasAttribute("data-row-open") && hasFocusRing(active))) {
|
|
272
|
+
// `preventScroll` so focusing doesn't scroll it somewhere else again.
|
|
273
|
+
// (A card's header button is drawn by the message pane, which registers it; a stand-in pane that doesn't has none to focus.)
|
|
274
|
+
headerRefs.current[pendingFocusUid]?.focus({ preventScroll: true });
|
|
275
|
+
}
|
|
276
|
+
setPendingFocusUid(null);
|
|
277
|
+
}, [pendingFocusUid, expandedUids]);
|
|
278
|
+
|
|
279
|
+
// Keeps the message whose header was just clicked where it was on screen. Expanding one above the
|
|
280
|
+
// message being read otherwise pushes everything below it down by however tall the new body is.
|
|
281
|
+
useLayoutEffect(() => {
|
|
282
|
+
const anchor = anchorRef.current;
|
|
283
|
+
if (!anchor) return;
|
|
284
|
+
anchorRef.current = null;
|
|
285
|
+
// The row is still there: the anchor was taken from a rendered row, and toggling never removes one.
|
|
286
|
+
const row = rowRefs.current[anchor.uid]!;
|
|
287
|
+
scrollingAncestor(row).scrollTop += row.getBoundingClientRect().top - anchor.top;
|
|
288
|
+
// The button the reader had focused is gone (a collapsed card and an expanded one each draw their own): keep them where they were.
|
|
289
|
+
if (refocusRef.current === anchor.uid) {
|
|
290
|
+
headerRefs.current[anchor.uid]?.focus({ preventScroll: true });
|
|
291
|
+
}
|
|
292
|
+
refocusRef.current = null;
|
|
293
|
+
}, [expandedUids]);
|
|
294
|
+
|
|
295
|
+
// Attachments and mark-as-read, for expanded messages only - mirrors `mailDetailHooks.ts`'s
|
|
296
|
+
// `useMessageAttachments`/`useMarkMessageRead`, reimplemented here (rather than called in a loop, which
|
|
297
|
+
// the rules of hooks don't allow) because a thread expands several messages at once.
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
const generation = generationRef.current;
|
|
300
|
+
for (const message of messages) {
|
|
301
|
+
const uid = message.uid;
|
|
302
|
+
if (!expandedUids.has(uid)) continue;
|
|
303
|
+
if (message.hasAttachments && !attachmentsRequestedRef.current.has(uid)) {
|
|
304
|
+
attachmentsRequestedRef.current.add(uid);
|
|
305
|
+
listAttachments(message.folderUid, uid)
|
|
306
|
+
.then((loaded) => {
|
|
307
|
+
if (generation === generationRef.current) {
|
|
308
|
+
setAttachmentsByUid((prev) => ({ ...prev, [uid]: loaded }));
|
|
309
|
+
}
|
|
310
|
+
})
|
|
311
|
+
.catch(() => {
|
|
312
|
+
// Best-effort, as in `useMessageAttachments`: no attachments render meanwhile, and
|
|
313
|
+
// forgetting the request lets a later re-expand retry it.
|
|
314
|
+
attachmentsRequestedRef.current.delete(uid);
|
|
315
|
+
});
|
|
316
|
+
}
|
|
317
|
+
if (!markReadRequestedRef.current.has(uid)) {
|
|
318
|
+
// Asked once per opened conversation and per expanding of the message: a failure is not retried from here, because
|
|
319
|
+
// undoing the optimistic change changes `messages`, which would run this effect again and ask again, for ever. A message
|
|
320
|
+
// that is already read is asked about too (there is nothing to send), so marking it unread while it is open - the
|
|
321
|
+
// keyboard's Ctrl+U - doesn't make this run again and read it straight back.
|
|
322
|
+
markReadRequestedRef.current.add(uid);
|
|
323
|
+
if (message.flags.read === true) {
|
|
324
|
+
continue;
|
|
325
|
+
}
|
|
326
|
+
// `message` is this render's copy, so the request carries its current `version`. The row, the conversation row's
|
|
327
|
+
// unread count and the folder badge all change at once; `previous` is what tells the list's conversation row
|
|
328
|
+
// that its count moved (see `setReadState()`).
|
|
329
|
+
void setReadState(message, true, {
|
|
330
|
+
patch: (updated, previous) => {
|
|
331
|
+
if (generation === generationRef.current) {
|
|
332
|
+
patchMessage(updated, previous);
|
|
333
|
+
}
|
|
334
|
+
},
|
|
335
|
+
track: trackMessageChange,
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
}
|
|
339
|
+
}, [expandedUids, messages]);
|
|
340
|
+
|
|
341
|
+
/** A newer copy of one of the thread's messages, kept here and handed to the list - with the copy it
|
|
342
|
+
* replaces where the caller was given one, so a conversation row can tell what actually changed. */
|
|
343
|
+
function patchMessage(updated: Message, previous?: Message) {
|
|
344
|
+
setMessages((prev) => prev.map((message) => (message.uid === updated.uid ? updated : message)));
|
|
345
|
+
onMessagePatched(updated, previous);
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
/** A message that left the folder being listed - it leaves the thread too, as it left the list. */
|
|
349
|
+
function removeMessage(updated: Message) {
|
|
350
|
+
setMessages((prev) => prev.filter((message) => message.uid !== updated.uid));
|
|
351
|
+
onMessageRemoved(updated);
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
function toggleExpanded(uid: string) {
|
|
355
|
+
// Opening a message again asks to mark it read again - that is how one whose request failed is retried.
|
|
356
|
+
markReadRequestedRef.current.delete(uid);
|
|
357
|
+
// The row this button lives in has rendered, so its ref is set.
|
|
358
|
+
anchorRef.current = { uid, top: rowRefs.current[uid]!.getBoundingClientRect().top };
|
|
359
|
+
refocusRef.current = document.activeElement === headerRefs.current[uid] ? uid : null;
|
|
360
|
+
setExpandedUids((prev) => {
|
|
361
|
+
const next = new Set(prev);
|
|
362
|
+
if (next.has(uid)) {
|
|
363
|
+
next.delete(uid);
|
|
364
|
+
} else {
|
|
365
|
+
next.add(uid);
|
|
366
|
+
}
|
|
367
|
+
return next;
|
|
368
|
+
});
|
|
369
|
+
}
|
|
370
|
+
|
|
371
|
+
// The keyboard acts on the message that was opened - or the newest, when the opened one isn't in this thread - never on all the expanded
|
|
372
|
+
// ones at once (each is a `MessageDetailPane`, and two of them must not both answer Ctrl+R).
|
|
373
|
+
const keyboardUid = messages.some((message) => message.uid === selectedUid) ? selectedUid : messages[0]?.uid;
|
|
374
|
+
|
|
375
|
+
function folderTypeOf(message: Message): string | undefined {
|
|
376
|
+
return folders.find((folder) => folder.uid === message.folderUid)?.type;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
if (!conversation) {
|
|
380
|
+
return <p className="p-8 text-sm text-text-muted">Select a conversation to read it.</p>;
|
|
381
|
+
}
|
|
382
|
+
const subject = displaySubject(conversation.subject) || "(no subject)";
|
|
383
|
+
// The newest message that is open carries the Reply / Forward buttons at the foot of its card.
|
|
384
|
+
const footerUid = messages.find((message) => expandedUids.has(message.uid))?.uid;
|
|
385
|
+
|
|
386
|
+
return (
|
|
387
|
+
// The pane is the window's height, not the thread's: a full-height flex column whose header card is fixed and whose list of
|
|
388
|
+
// message cards is the one scrolling, growing child (`min-h-0`, or the list would stretch the column past the pane instead of
|
|
389
|
+
// scrolling inside it). Each card is exactly as tall as its message.
|
|
390
|
+
// The subject card is the same element while the messages load and once they are here (the subject and the count are known from the
|
|
391
|
+
// list's row), so nothing shifts or is drawn again when they arrive: a skeleton card per message (up to three) stands where they will be.
|
|
392
|
+
<div className="flex-1 min-w-0 min-h-0 flex flex-col">
|
|
393
|
+
<SubjectCard
|
|
394
|
+
subject={subject}
|
|
395
|
+
meta={
|
|
396
|
+
loading
|
|
397
|
+
? conversation.messageCount > 1
|
|
398
|
+
? `${conversation.messageCount} messages`
|
|
399
|
+
: undefined
|
|
400
|
+
: error
|
|
401
|
+
? undefined
|
|
402
|
+
: `${messages.length} message${messages.length === 1 ? "" : "s"}`
|
|
403
|
+
}
|
|
404
|
+
>
|
|
405
|
+
{truncated && !loading && !error && (
|
|
406
|
+
<p className="text-xs text-text-muted mt-1">
|
|
407
|
+
Only the oldest {THREAD_MESSAGE_LIMIT} messages of this conversation are shown here. The rest
|
|
408
|
+
are still in the message list.
|
|
409
|
+
</p>
|
|
410
|
+
)}
|
|
411
|
+
</SubjectCard>
|
|
412
|
+
{loading ? (
|
|
413
|
+
<SkeletonCards messageCount={conversation.messageCount} />
|
|
414
|
+
) : error ? (
|
|
415
|
+
<div className="p-2 sm:p-3">
|
|
416
|
+
<Alert>{error}</Alert>
|
|
417
|
+
</div>
|
|
418
|
+
) : (
|
|
419
|
+
<ul className="flex-1 min-h-0 overflow-y-auto p-2 sm:p-3 flex flex-col gap-3">
|
|
420
|
+
{messages.map((message) => {
|
|
421
|
+
const uid = message.uid;
|
|
422
|
+
const expanded = expandedUids.has(uid);
|
|
423
|
+
const bodyId = `thread-message-${uid}`;
|
|
424
|
+
const messageUnread = isUnread(message);
|
|
425
|
+
return (
|
|
426
|
+
<li
|
|
427
|
+
key={uid}
|
|
428
|
+
ref={(node) => {
|
|
429
|
+
rowRefs.current[uid] = node;
|
|
430
|
+
}}
|
|
431
|
+
data-unread={messageUnread ? "true" : undefined}
|
|
432
|
+
>
|
|
433
|
+
{expanded ? (
|
|
434
|
+
<MessageDetailPane
|
|
435
|
+
inThread
|
|
436
|
+
threadSubject={subject}
|
|
437
|
+
threadHeader={{
|
|
438
|
+
bodyId,
|
|
439
|
+
unread: messageUnread,
|
|
440
|
+
onToggle: () => toggleExpanded(uid),
|
|
441
|
+
buttonRef: (node) => {
|
|
442
|
+
headerRefs.current[uid] = node;
|
|
443
|
+
},
|
|
444
|
+
}}
|
|
445
|
+
footer={uid === footerUid}
|
|
446
|
+
shortcuts={!!shortcuts && uid === keyboardUid}
|
|
447
|
+
message={message}
|
|
448
|
+
attachments={attachmentsByUid[uid] ?? []}
|
|
449
|
+
isSentItems={folderTypeOf(message) === "sent_items"}
|
|
450
|
+
isOutbox={folderTypeOf(message) === "outbox"}
|
|
451
|
+
draftsFolderUid={folders.find((folder) => folder.type === "drafts")?.uid}
|
|
452
|
+
folders={folders}
|
|
453
|
+
onMoved={removeMessage}
|
|
454
|
+
onFolderCreated={onFolderCreated}
|
|
455
|
+
onRecalled={patchMessage}
|
|
456
|
+
onReceiptHandled={patchMessage}
|
|
457
|
+
onScheduledSendCanceled={removeMessage}
|
|
458
|
+
onArchived={removeMessage}
|
|
459
|
+
labels={labels}
|
|
460
|
+
onLabelsChanged={patchMessage}
|
|
461
|
+
onLabelCreated={onLabelCreated}
|
|
462
|
+
/>
|
|
463
|
+
) : (
|
|
464
|
+
<>
|
|
465
|
+
<CollapsedCard
|
|
466
|
+
from={message.from}
|
|
467
|
+
date={new Date(message.receivedDate).toLocaleString()}
|
|
468
|
+
preview={message.bodyPreview || (message.encrypted ? <EncryptedPreview /> : "")}
|
|
469
|
+
unread={messageUnread}
|
|
470
|
+
senderClassName={senderClass(messageUnread)}
|
|
471
|
+
dateClassName={dateClass(messageUnread)}
|
|
472
|
+
buttonRef={(node) => {
|
|
473
|
+
headerRefs.current[uid] = node;
|
|
474
|
+
}}
|
|
475
|
+
buttonProps={{
|
|
476
|
+
onClick: () => toggleExpanded(uid),
|
|
477
|
+
"aria-expanded": false,
|
|
478
|
+
"aria-controls": bodyId,
|
|
479
|
+
}}
|
|
480
|
+
/>
|
|
481
|
+
<div id={bodyId} hidden />
|
|
482
|
+
</>
|
|
483
|
+
)}
|
|
484
|
+
</li>
|
|
485
|
+
);
|
|
486
|
+
})}
|
|
487
|
+
</ul>
|
|
488
|
+
)}
|
|
489
|
+
</div>
|
|
490
|
+
);
|
|
491
|
+
}
|