@rapidmx/web-client 0.10.0 → 0.11.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 (310) hide show
  1. package/README.md +183 -2
  2. package/apps/admin/_layout.tsx +8 -2
  3. package/apps/admin/index.tsx +7 -1
  4. package/apps/admin/ingest-queue/index.tsx +2 -1
  5. package/apps/admin/mailboxes/[uid].tsx +23 -10
  6. package/apps/admin/quarantine/index.tsx +2 -1
  7. package/apps/admin/signing-certificates/index.tsx +343 -0
  8. package/apps/escrow/_layout.tsx +8 -2
  9. package/apps/shared/appearance/AppearanceForm.tsx +392 -0
  10. package/apps/shared/appearance/AppearanceHead.tsx +49 -0
  11. package/apps/shared/appearance/AppearanceProvider.tsx +470 -0
  12. package/apps/shared/appearance/ColorField.tsx +107 -0
  13. package/apps/shared/appearance/appearanceCache.ts +106 -0
  14. package/apps/shared/appearance/appearanceContext.ts +77 -0
  15. package/apps/shared/appearance/bootScript.ts +35 -0
  16. package/apps/shared/appearance/color.ts +169 -0
  17. package/apps/shared/appearance/photo.ts +88 -0
  18. package/apps/shared/appearance/resolvedTheme.ts +67 -0
  19. package/apps/shared/appearance/theme.ts +355 -0
  20. package/apps/shared/components/admin/layout/AdminShell.tsx +22 -10
  21. package/apps/shared/components/admin/mailboxes/ShareAccessCard.tsx +107 -60
  22. package/apps/shared/components/admin/settings/BrandingForm.tsx +24 -0
  23. package/apps/shared/components/admin/settings/PluginsManager.tsx +228 -25
  24. package/apps/shared/components/admin/setup/SetupWizard.tsx +2 -1
  25. package/apps/shared/components/calendar/CalendarListSidebar.tsx +4 -5
  26. package/apps/shared/components/contacts/ContactForm.tsx +11 -5
  27. package/apps/shared/components/contacts/ContactsSidebar.tsx +5 -3
  28. package/apps/shared/components/contacts/ContactsToolbar.tsx +25 -52
  29. package/apps/shared/components/contacts/layout/ContactsShell.tsx +10 -5
  30. package/apps/shared/components/escrow/layout/EscrowShell.tsx +13 -6
  31. package/apps/shared/components/layout/AppShell.tsx +98 -32
  32. package/apps/shared/components/layout/BrandingChrome.tsx +200 -13
  33. package/apps/shared/components/layout/RailIcon.tsx +100 -0
  34. package/apps/shared/components/layout/ResponsiveToolbar.tsx +315 -0
  35. package/apps/shared/components/layout/ThemeSwitch.tsx +84 -0
  36. package/apps/shared/components/layout/UserMenu.tsx +75 -6
  37. package/apps/shared/components/mail/ConversationList.tsx +4 -2
  38. package/apps/shared/components/mail/ConversationThreadPane.tsx +487 -475
  39. package/apps/shared/components/mail/LazyReadingPane.tsx +14 -16
  40. package/apps/shared/components/mail/MailSelectionBar.tsx +2 -10
  41. package/apps/shared/components/mail/MessageDetailPane.tsx +366 -287
  42. package/apps/shared/components/mail/OutboxBadge.tsx +44 -0
  43. package/apps/shared/components/mail/OutboxRowStatus.tsx +31 -0
  44. package/apps/shared/components/mail/compose/ComposeContext.tsx +35 -2
  45. package/apps/shared/components/mail/compose/ComposeWindow.tsx +239 -437
  46. package/apps/shared/components/mail/compose/encryptionRequirement.ts +86 -0
  47. package/apps/shared/components/mail/layout/MailShell.tsx +39 -25
  48. package/apps/shared/components/mail/reading/EncryptedBody.tsx +65 -0
  49. package/apps/shared/components/mail/reading/EncryptedPreview.tsx +35 -0
  50. package/apps/shared/components/mail/reading/MessageBody.tsx +240 -0
  51. package/apps/shared/components/mail/reading/MessageCard.tsx +174 -0
  52. package/apps/shared/components/mail/reading/bodyContent.ts +100 -0
  53. package/apps/shared/components/mail/reading/bodyHtml.ts +298 -0
  54. package/apps/shared/components/mail/reading/color.ts +245 -0
  55. package/apps/shared/components/mail/reading/frameControl.ts +142 -0
  56. package/apps/shared/components/mail/reading/frameDocument.ts +123 -0
  57. package/apps/shared/components/mail/reading/safeDocument.ts +24 -0
  58. package/apps/shared/components/mail/reading/themeAdaptation.ts +221 -0
  59. package/apps/shared/components/mail/reading/themeSurface.ts +90 -0
  60. package/apps/shared/components/mail/reading/viewOriginal.ts +38 -0
  61. package/apps/shared/components/settings/SigningCertificateCard.tsx +344 -0
  62. package/apps/shared/components/settings/layout/SettingsShell.tsx +1 -0
  63. package/apps/shared/components/sharing/PrincipalPicker.tsx +145 -0
  64. package/apps/shared/components/tasks/TasksSidebar.tsx +5 -3
  65. package/apps/shared/components/tasks/layout/TasksShell.tsx +9 -5
  66. package/apps/shared/mail/folderCounts.ts +9 -3
  67. package/apps/shared/mail/folderTree.ts +143 -0
  68. package/apps/shared/mail/outbox/UnlockBridge.tsx +23 -0
  69. package/apps/shared/mail/outbox/composeBridge.ts +69 -0
  70. package/apps/shared/mail/outbox/outboxState.ts +88 -0
  71. package/apps/shared/mail/outbox/pendingSends.ts +146 -0
  72. package/apps/shared/mail/outbox/sendDecision.ts +157 -0
  73. package/apps/shared/mail/outbox/sendJob.ts +427 -0
  74. package/apps/shared/mail/outbox/sendOutcomes.ts +146 -0
  75. package/apps/shared/mail/outbox/sendState.ts +35 -0
  76. package/apps/shared/mail/outbox/useOutboxStatus.ts +61 -0
  77. package/apps/shared/mail/useMailConnection.ts +81 -28
  78. package/apps/shared/mail/useMailLiveUpdates.ts +55 -10
  79. package/apps/shared/mail/useNewMailNotifications.ts +47 -32
  80. package/apps/shared/navigation/AppRouter.tsx +2 -2
  81. package/apps/shared/notifications/NotificationCenter.tsx +215 -0
  82. package/apps/shared/notifications/NotificationHistoryDialog.tsx +90 -0
  83. package/apps/shared/notifications/apiErrors.ts +98 -0
  84. package/apps/shared/notifications/headerOffset.ts +35 -0
  85. package/apps/shared/notifications/pushStatus.ts +56 -0
  86. package/apps/shared/notifications/store.ts +549 -0
  87. package/apps/shared/notifications/systemErrors.ts +63 -0
  88. package/apps/shared/notifications/useNotifications.ts +41 -0
  89. package/apps/shared/signing/enrollmentStorage.ts +33 -0
  90. package/apps/shared/signing/enrollmentTracker.ts +385 -0
  91. package/apps/shared/signing/enrollmentView.ts +251 -0
  92. package/apps/shared/signing/signingInfo.ts +58 -0
  93. package/apps/shared/signing/useNow.ts +19 -0
  94. package/apps/shared/signing/useSigningEnrollmentWatcher.ts +90 -0
  95. package/apps/shared/styles/app.css +80 -0
  96. package/apps/www/_layout.tsx +8 -2
  97. package/apps/www/_routes.ts +1 -0
  98. package/apps/www/calendar/index.tsx +9 -14
  99. package/apps/www/contacts/[uid].tsx +5 -8
  100. package/apps/www/contacts/index.tsx +587 -584
  101. package/apps/www/index.tsx +38 -27
  102. package/apps/www/messages/[uid].tsx +3 -1
  103. package/apps/www/settings/appearance/index.tsx +21 -0
  104. package/apps/www/settings/auto-reply/index.tsx +3 -7
  105. package/apps/www/settings/encryption/index.tsx +151 -116
  106. package/apps/www/settings/filters/[uid].tsx +3 -1
  107. package/apps/www/settings/filters/new/index.tsx +3 -1
  108. package/apps/www/settings/privacy/index.tsx +3 -8
  109. package/apps/www/settings/read-receipts/index.tsx +3 -7
  110. package/apps/www/settings/sharing/index.tsx +44 -65
  111. package/apps/www/settings/signatures/[uid].tsx +3 -1
  112. package/apps/www/settings/signatures/new/index.tsx +3 -2
  113. package/apps/www/tasks/index.tsx +11 -16
  114. package/dist/apps/admin/_layout.d.ts +5 -1
  115. package/dist/apps/admin/_layout.js +3 -2
  116. package/dist/apps/admin/index.js +3 -2
  117. package/dist/apps/admin/ingest-queue/index.js +2 -1
  118. package/dist/apps/admin/mailboxes/[uid].js +9 -6
  119. package/dist/apps/admin/quarantine/index.js +2 -1
  120. package/dist/apps/admin/signing-certificates/index.d.ts +3 -0
  121. package/dist/apps/admin/signing-certificates/index.js +161 -0
  122. package/dist/apps/escrow/_layout.d.ts +5 -1
  123. package/dist/apps/escrow/_layout.js +3 -2
  124. package/dist/apps/shared/appearance/AppearanceForm.d.ts +7 -0
  125. package/dist/apps/shared/appearance/AppearanceForm.js +131 -0
  126. package/dist/apps/shared/appearance/AppearanceHead.d.ts +15 -0
  127. package/dist/apps/shared/appearance/AppearanceHead.js +31 -0
  128. package/dist/apps/shared/appearance/AppearanceProvider.d.ts +32 -0
  129. package/dist/apps/shared/appearance/AppearanceProvider.js +390 -0
  130. package/dist/apps/shared/appearance/ColorField.d.ts +22 -0
  131. package/dist/apps/shared/appearance/ColorField.js +40 -0
  132. package/dist/apps/shared/appearance/appearanceCache.d.ts +45 -0
  133. package/dist/apps/shared/appearance/appearanceCache.js +80 -0
  134. package/dist/apps/shared/appearance/appearanceContext.d.ts +45 -0
  135. package/dist/apps/shared/appearance/appearanceContext.js +29 -0
  136. package/dist/apps/shared/appearance/bootScript.d.ts +16 -0
  137. package/dist/apps/shared/appearance/bootScript.js +33 -0
  138. package/dist/apps/shared/appearance/color.d.ts +65 -0
  139. package/dist/apps/shared/appearance/color.js +132 -0
  140. package/dist/apps/shared/appearance/photo.d.ts +17 -0
  141. package/dist/apps/shared/appearance/photo.js +79 -0
  142. package/dist/apps/shared/appearance/resolvedTheme.d.ts +21 -0
  143. package/dist/apps/shared/appearance/resolvedTheme.js +55 -0
  144. package/dist/apps/shared/appearance/theme.d.ts +111 -0
  145. package/dist/apps/shared/appearance/theme.js +251 -0
  146. package/dist/apps/shared/components/admin/layout/AdminShell.d.ts +1 -1
  147. package/dist/apps/shared/components/admin/layout/AdminShell.js +16 -6
  148. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.d.ts +10 -5
  149. package/dist/apps/shared/components/admin/mailboxes/ShareAccessCard.js +49 -34
  150. package/dist/apps/shared/components/admin/settings/BrandingForm.d.ts +2 -0
  151. package/dist/apps/shared/components/admin/settings/BrandingForm.js +7 -1
  152. package/dist/apps/shared/components/admin/settings/PluginsManager.js +106 -20
  153. package/dist/apps/shared/components/admin/setup/SetupWizard.js +2 -1
  154. package/dist/apps/shared/components/calendar/CalendarListSidebar.js +8 -8
  155. package/dist/apps/shared/components/contacts/ContactForm.js +1 -1
  156. package/dist/apps/shared/components/contacts/ContactsSidebar.js +4 -2
  157. package/dist/apps/shared/components/contacts/ContactsToolbar.d.ts +3 -1
  158. package/dist/apps/shared/components/contacts/ContactsToolbar.js +24 -9
  159. package/dist/apps/shared/components/contacts/layout/ContactsShell.js +4 -1
  160. package/dist/apps/shared/components/escrow/layout/EscrowShell.js +7 -4
  161. package/dist/apps/shared/components/layout/AppShell.d.ts +6 -1
  162. package/dist/apps/shared/components/layout/AppShell.js +59 -13
  163. package/dist/apps/shared/components/layout/BrandingChrome.d.ts +69 -10
  164. package/dist/apps/shared/components/layout/BrandingChrome.js +140 -12
  165. package/dist/apps/shared/components/layout/RailIcon.d.ts +21 -0
  166. package/dist/apps/shared/components/layout/RailIcon.js +85 -0
  167. package/dist/apps/shared/components/layout/ResponsiveToolbar.d.ts +55 -0
  168. package/dist/apps/shared/components/layout/ResponsiveToolbar.js +199 -0
  169. package/dist/apps/shared/components/layout/ThemeSwitch.d.ts +9 -0
  170. package/dist/apps/shared/components/layout/ThemeSwitch.js +54 -0
  171. package/dist/apps/shared/components/layout/UserMenu.d.ts +7 -1
  172. package/dist/apps/shared/components/layout/UserMenu.js +41 -7
  173. package/dist/apps/shared/components/mail/ConversationList.js +3 -2
  174. package/dist/apps/shared/components/mail/ConversationThreadPane.d.ts +2 -1
  175. package/dist/apps/shared/components/mail/ConversationThreadPane.js +42 -20
  176. package/dist/apps/shared/components/mail/LazyReadingPane.js +9 -8
  177. package/dist/apps/shared/components/mail/MailSelectionBar.d.ts +3 -4
  178. package/dist/apps/shared/components/mail/MailSelectionBar.js +2 -3
  179. package/dist/apps/shared/components/mail/MessageDetailPane.d.ts +18 -7
  180. package/dist/apps/shared/components/mail/MessageDetailPane.js +86 -41
  181. package/dist/apps/shared/components/mail/OutboxBadge.d.ts +17 -0
  182. package/dist/apps/shared/components/mail/OutboxBadge.js +18 -0
  183. package/dist/apps/shared/components/mail/OutboxRowStatus.d.ts +10 -0
  184. package/dist/apps/shared/components/mail/OutboxRowStatus.js +19 -0
  185. package/dist/apps/shared/components/mail/compose/ComposeContext.d.ts +8 -0
  186. package/dist/apps/shared/components/mail/compose/ComposeContext.js +28 -3
  187. package/dist/apps/shared/components/mail/compose/ComposeWindow.d.ts +2 -1
  188. package/dist/apps/shared/components/mail/compose/ComposeWindow.js +229 -328
  189. package/dist/apps/shared/components/mail/compose/encryptionRequirement.d.ts +49 -0
  190. package/dist/apps/shared/components/mail/compose/encryptionRequirement.js +35 -0
  191. package/dist/apps/shared/components/mail/layout/MailShell.d.ts +2 -0
  192. package/dist/apps/shared/components/mail/layout/MailShell.js +20 -14
  193. package/dist/apps/shared/components/mail/reading/EncryptedBody.d.ts +21 -0
  194. package/dist/apps/shared/components/mail/reading/EncryptedBody.js +22 -0
  195. package/dist/apps/shared/components/mail/reading/EncryptedPreview.d.ts +18 -0
  196. package/dist/apps/shared/components/mail/reading/EncryptedPreview.js +22 -0
  197. package/dist/apps/shared/components/mail/reading/MessageBody.d.ts +32 -0
  198. package/dist/apps/shared/components/mail/reading/MessageBody.js +136 -0
  199. package/dist/apps/shared/components/mail/reading/MessageCard.d.ts +62 -0
  200. package/dist/apps/shared/components/mail/reading/MessageCard.js +58 -0
  201. package/dist/apps/shared/components/mail/reading/bodyContent.d.ts +38 -0
  202. package/dist/apps/shared/components/mail/reading/bodyContent.js +84 -0
  203. package/dist/apps/shared/components/mail/reading/bodyHtml.d.ts +47 -0
  204. package/dist/apps/shared/components/mail/reading/bodyHtml.js +267 -0
  205. package/dist/apps/shared/components/mail/reading/color.d.ts +63 -0
  206. package/dist/apps/shared/components/mail/reading/color.js +201 -0
  207. package/dist/apps/shared/components/mail/reading/frameControl.d.ts +33 -0
  208. package/dist/apps/shared/components/mail/reading/frameControl.js +120 -0
  209. package/dist/apps/shared/components/mail/reading/frameDocument.d.ts +52 -0
  210. package/dist/apps/shared/components/mail/reading/frameDocument.js +98 -0
  211. package/dist/apps/shared/components/mail/reading/safeDocument.d.ts +3 -0
  212. package/dist/apps/shared/components/mail/reading/safeDocument.js +12 -0
  213. package/dist/apps/shared/components/mail/reading/themeAdaptation.d.ts +56 -0
  214. package/dist/apps/shared/components/mail/reading/themeAdaptation.js +144 -0
  215. package/dist/apps/shared/components/mail/reading/themeSurface.d.ts +17 -0
  216. package/dist/apps/shared/components/mail/reading/themeSurface.js +83 -0
  217. package/dist/apps/shared/components/mail/reading/viewOriginal.d.ts +9 -0
  218. package/dist/apps/shared/components/mail/reading/viewOriginal.js +32 -0
  219. package/dist/apps/shared/components/settings/SigningCertificateCard.d.ts +32 -0
  220. package/dist/apps/shared/components/settings/SigningCertificateCard.js +98 -0
  221. package/dist/apps/shared/components/settings/layout/SettingsShell.js +1 -0
  222. package/dist/apps/shared/components/sharing/PrincipalPicker.d.ts +26 -0
  223. package/dist/apps/shared/components/sharing/PrincipalPicker.js +77 -0
  224. package/dist/apps/shared/components/tasks/TasksSidebar.js +4 -2
  225. package/dist/apps/shared/components/tasks/layout/TasksShell.js +3 -1
  226. package/dist/apps/shared/mail/folderCounts.d.ts +1 -1
  227. package/dist/apps/shared/mail/folderCounts.js +9 -3
  228. package/dist/apps/shared/mail/folderTree.d.ts +55 -0
  229. package/dist/apps/shared/mail/folderTree.js +116 -0
  230. package/dist/apps/shared/mail/outbox/UnlockBridge.d.ts +5 -0
  231. package/dist/apps/shared/mail/outbox/UnlockBridge.js +18 -0
  232. package/dist/apps/shared/mail/outbox/composeBridge.d.ts +34 -0
  233. package/dist/apps/shared/mail/outbox/composeBridge.js +32 -0
  234. package/dist/apps/shared/mail/outbox/outboxState.d.ts +41 -0
  235. package/dist/apps/shared/mail/outbox/outboxState.js +42 -0
  236. package/dist/apps/shared/mail/outbox/pendingSends.d.ts +39 -0
  237. package/dist/apps/shared/mail/outbox/pendingSends.js +109 -0
  238. package/dist/apps/shared/mail/outbox/sendDecision.d.ts +80 -0
  239. package/dist/apps/shared/mail/outbox/sendDecision.js +94 -0
  240. package/dist/apps/shared/mail/outbox/sendJob.d.ts +68 -0
  241. package/dist/apps/shared/mail/outbox/sendJob.js +319 -0
  242. package/dist/apps/shared/mail/outbox/sendOutcomes.d.ts +3 -0
  243. package/dist/apps/shared/mail/outbox/sendOutcomes.js +141 -0
  244. package/dist/apps/shared/mail/outbox/sendState.d.ts +25 -0
  245. package/dist/apps/shared/mail/outbox/sendState.js +8 -0
  246. package/dist/apps/shared/mail/outbox/useOutboxStatus.d.ts +11 -0
  247. package/dist/apps/shared/mail/outbox/useOutboxStatus.js +49 -0
  248. package/dist/apps/shared/mail/useMailConnection.d.ts +9 -8
  249. package/dist/apps/shared/mail/useMailConnection.js +64 -22
  250. package/dist/apps/shared/mail/useMailLiveUpdates.d.ts +17 -4
  251. package/dist/apps/shared/mail/useMailLiveUpdates.js +36 -10
  252. package/dist/apps/shared/mail/useNewMailNotifications.d.ts +4 -10
  253. package/dist/apps/shared/mail/useNewMailNotifications.js +43 -23
  254. package/dist/apps/shared/navigation/AppRouter.js +2 -2
  255. package/dist/apps/shared/notifications/NotificationCenter.d.ts +19 -0
  256. package/dist/apps/shared/notifications/NotificationCenter.js +90 -0
  257. package/dist/apps/shared/notifications/NotificationHistoryDialog.d.ts +10 -0
  258. package/dist/apps/shared/notifications/NotificationHistoryDialog.js +36 -0
  259. package/dist/apps/shared/notifications/apiErrors.d.ts +19 -0
  260. package/dist/apps/shared/notifications/apiErrors.js +86 -0
  261. package/dist/apps/shared/notifications/headerOffset.d.ts +8 -0
  262. package/dist/apps/shared/notifications/headerOffset.js +33 -0
  263. package/dist/apps/shared/notifications/pushStatus.d.ts +9 -0
  264. package/dist/apps/shared/notifications/pushStatus.js +54 -0
  265. package/dist/apps/shared/notifications/store.d.ts +136 -0
  266. package/dist/apps/shared/notifications/store.js +416 -0
  267. package/dist/apps/shared/notifications/systemErrors.d.ts +9 -0
  268. package/dist/apps/shared/notifications/systemErrors.js +58 -0
  269. package/dist/apps/shared/notifications/useNotifications.d.ts +17 -0
  270. package/dist/apps/shared/notifications/useNotifications.js +18 -0
  271. package/dist/apps/shared/signing/enrollmentStorage.d.ts +10 -0
  272. package/dist/apps/shared/signing/enrollmentStorage.js +33 -0
  273. package/dist/apps/shared/signing/enrollmentTracker.d.ts +73 -0
  274. package/dist/apps/shared/signing/enrollmentTracker.js +307 -0
  275. package/dist/apps/shared/signing/enrollmentView.d.ts +57 -0
  276. package/dist/apps/shared/signing/enrollmentView.js +214 -0
  277. package/dist/apps/shared/signing/signingInfo.d.ts +11 -0
  278. package/dist/apps/shared/signing/signingInfo.js +48 -0
  279. package/dist/apps/shared/signing/useNow.d.ts +2 -0
  280. package/dist/apps/shared/signing/useNow.js +18 -0
  281. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.d.ts +16 -0
  282. package/dist/apps/shared/signing/useSigningEnrollmentWatcher.js +87 -0
  283. package/dist/apps/shared/styles/app.css +80 -0
  284. package/dist/apps/www/_layout.d.ts +5 -1
  285. package/dist/apps/www/_layout.js +3 -2
  286. package/dist/apps/www/_routes.js +1 -0
  287. package/dist/apps/www/calendar/index.js +3 -4
  288. package/dist/apps/www/contacts/[uid].js +5 -7
  289. package/dist/apps/www/contacts/index.js +14 -21
  290. package/dist/apps/www/index.js +37 -19
  291. package/dist/apps/www/messages/[uid].js +3 -1
  292. package/dist/apps/www/settings/appearance/index.d.ts +4 -0
  293. package/dist/apps/www/settings/appearance/index.js +13 -0
  294. package/dist/apps/www/settings/auto-reply/index.js +3 -6
  295. package/dist/apps/www/settings/encryption/index.js +103 -95
  296. package/dist/apps/www/settings/filters/[uid].js +3 -1
  297. package/dist/apps/www/settings/filters/new/index.js +3 -1
  298. package/dist/apps/www/settings/privacy/index.js +5 -8
  299. package/dist/apps/www/settings/read-receipts/index.js +3 -6
  300. package/dist/apps/www/settings/sharing/index.js +19 -33
  301. package/dist/apps/www/settings/signatures/[uid].js +3 -1
  302. package/dist/apps/www/settings/signatures/new/index.js +3 -2
  303. package/dist/apps/www/tasks/index.js +8 -14
  304. package/package.json +2 -2
  305. package/apps/shared/components/mail/NewMailToasts.tsx +0 -141
  306. package/apps/shared/components/mail/compose/SendFailureAlert.tsx +0 -48
  307. package/dist/apps/shared/components/mail/NewMailToasts.d.ts +0 -19
  308. package/dist/apps/shared/components/mail/NewMailToasts.js +0 -55
  309. package/dist/apps/shared/components/mail/compose/SendFailureAlert.d.ts +0 -14
  310. package/dist/apps/shared/components/mail/compose/SendFailureAlert.js +0 -11
@@ -0,0 +1,61 @@
1
+ ///////////////////////////////////////////////////////////////////////////////
2
+ // Copyright (C) 2026 Jean-Philippe Steinmetz
3
+ // SPDX-License-Identifier: MPL-2.0
4
+ ///////////////////////////////////////////////////////////////////////////////
5
+ import { useEffect, useMemo, useState } from "react";
6
+ import { listMessages } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ import type { MailboxFolders } from "../../components/mail/layout/MailShell.js";
8
+ import { FolderCount, countOfFolder } from "../folderCounts.js";
9
+ import { OutboxFolderStatus, summarizeOutbox } from "./outboxState.js";
10
+
11
+ /** The most Outbox messages read to say what state they are in; beyond this the pill still shows the folder's own total. */
12
+ export const OUTBOX_STATUS_LIMIT = 50;
13
+
14
+ /**
15
+ * What the messages in each Outbox folder are doing (sending / retrying / failed / scheduled), by folder uid - the second line of the Outbox
16
+ * indicator, next to the folder's own count. A folder only costs a request while it holds something (its count is above zero) and is read again
17
+ * whenever that count or the live updates change, so an empty Outbox - almost always - is free. A failed read keeps what was known.
18
+ */
19
+ export function useOutboxStatus(mailboxFolders: MailboxFolders[], counts: Record<string, FolderCount>, liveTick: number, enabled: boolean): Record<string, OutboxFolderStatus> {
20
+ const [statuses, setStatuses] = useState<Record<string, OutboxFolderStatus>>({});
21
+ const outboxes = useMemo(
22
+ () =>
23
+ mailboxFolders.flatMap((entry) => entry.folders.filter((folder) => folder.type === "outbox")).map((folder) => ({ uid: folder.uid, total: countOfFolder(folder, counts).total })),
24
+ [mailboxFolders, counts],
25
+ );
26
+ const key = outboxes.map((outbox) => `${outbox.uid}:${outbox.total}`).join("|");
27
+
28
+ useEffect(() => {
29
+ if (!enabled) {
30
+ return;
31
+ }
32
+ const occupied = outboxes.filter((outbox) => outbox.total > 0);
33
+ setStatuses((previous) => {
34
+ const emptied = Object.keys(previous).filter((uid) => !occupied.some((outbox) => outbox.uid === uid));
35
+ if (emptied.length === 0) {
36
+ return previous;
37
+ }
38
+ const next = { ...previous };
39
+ for (const uid of emptied) {
40
+ delete next[uid];
41
+ }
42
+ return next;
43
+ });
44
+ let cancelled = false;
45
+ for (const outbox of occupied) {
46
+ listMessages(outbox.uid, { limit: OUTBOX_STATUS_LIMIT }).then(
47
+ (messages) => {
48
+ if (!cancelled) {
49
+ setStatuses((previous) => ({ ...previous, [outbox.uid]: summarizeOutbox(messages) }));
50
+ }
51
+ },
52
+ () => undefined,
53
+ );
54
+ }
55
+ return () => {
56
+ cancelled = true;
57
+ };
58
+ }, [enabled, key, liveTick]);
59
+
60
+ return statuses;
61
+ }
@@ -2,26 +2,25 @@
2
2
  // Copyright (C) 2026 Jean-Philippe Steinmetz
3
3
  // SPDX-License-Identifier: MPL-2.0
4
4
  ///////////////////////////////////////////////////////////////////////////////
5
- import { createContext, useCallback, useEffect, useState } from "react";
5
+ import { createContext, useCallback, useEffect, useRef, useState } from "react";
6
6
  import { ApiRequestError } from "@rapidmx/react-shared/util/api.js";
7
- import { Folder, Mailbox, listFolders, listMailboxes } from "@rapidmx/react-shared/mail/mailApi.js";
7
+ import { Folder, Mailbox, Message, listFolders, listMailboxes } from "@rapidmx/react-shared/mail/mailApi.js";
8
+ import { FOLDER_ORDER, FolderChange, MAIL_FOLDER_TYPES, isMailFolder, knownFolderUids, reconcileFolders, removeFolder, upsertFolder } from "./folderTree.js";
8
9
  import type { MailboxFolders } from "../components/mail/layout/MailShell.js";
9
10
  import { LiveUpdates, useMailLiveUpdates } from "./useMailLiveUpdates.js";
10
- import type { FolderCounts } from "./folderCounts.js";
11
+ import type { CountTracker, FolderCounts } from "./folderCounts.js";
11
12
  import { NewMailNotifications, useNewMailNotifications } from "./useNewMailNotifications.js";
13
+ import { usePushConnectionNotice } from "../notifications/pushStatus.js";
14
+ import { registerOutboxCounter } from "./outbox/sendJob.js";
15
+ import { handleSendEvent } from "./outbox/sendOutcomes.js";
16
+ import { OutboxFolderStatus } from "./outbox/outboxState.js";
17
+ import { useOutboxStatus } from "./outbox/useOutboxStatus.js";
12
18
 
13
19
  /** Page size of the one `listMailboxes()` call. */
14
20
  export const MAILBOX_LIST_LIMIT = 100;
15
21
 
16
- /** Well-known folders sort first in the sidebar, in Gmail/Outlook's conventional order; anything else (incl. `user`) sorts after, alphabetically. */
17
- export const FOLDER_ORDER = ["inbox", "drafts", "outbox", "sent_items", "junk", "archive", "deleted_items"];
18
-
19
- /**
20
- * A mailbox's `calendar`/`contacts`/`tasks`/`notes` folders back their own dedicated apps (see `CalendarShell`/`ContactsShell`/`TasksShell`), not
21
- * Mail - `listFolders()` returns every well-known folder for the mailbox regardless of which app owns it, so Mail's own folder tree filters down
22
- * to just the mail ones itself, or those other apps' folders leak into its sidebar.
23
- */
24
- export const MAIL_FOLDER_TYPES = new Set([...FOLDER_ORDER, "user"]);
22
+ // The sidebar's order and the folders Mail lists live in `folderTree.ts`; re-exported for what already imports them from here.
23
+ export { FOLDER_ORDER, MAIL_FOLDER_TYPES };
25
24
 
26
25
  export type MailConnectionStatus = "checking" | "error" | "ready";
27
26
 
@@ -38,14 +37,22 @@ export interface MailConnection {
38
37
  foldersLoading: boolean;
39
38
  /** Files a folder that was just created (by this client or another) under its mailbox, so the sidebar and every folder picker show it. */
40
39
  onFolderCreated: (folder: Folder) => void;
40
+ /** Says which folders some message the page has met lives in (a list's rows, a conversation's folders): one the sidebar does not know is asked for
41
+ * - its mailbox's folders are listed again, once, debounced - and files it. Each unknown uid is asked about once, so a folder Mail never lists
42
+ * (another app's) cannot make the page ask again and again. */
43
+ noteFolderUids: (folderUids: Iterable<string>) => void;
41
44
  /** Bumped whenever new mail may have arrived - see `useMailLiveUpdates()`. */
42
45
  live: LiveUpdates;
43
46
  /** The folder badges' numbers and how to change them. */
44
47
  folderCounts: FolderCounts;
45
48
  /** The new-mail pop-ups and desktop notifications, and what feeds them. */
46
49
  notifications: NewMailNotifications;
50
+ /** What the messages in each Outbox folder are doing, by folder uid (the Outbox indicator's state) - see `useOutboxStatus()`. */
51
+ outbox: Record<string, OutboxFolderStatus>;
47
52
  }
48
53
 
54
+ const NO_TRACKER: CountTracker = { settle: () => undefined, revert: () => undefined };
55
+
49
56
  /** What the persistent app frame (`AppChrome`) offers to the Mail shell so that it doesn't open a second connection. `null` outside a frame. */
50
57
  export const MailConnectionContext = createContext<MailConnection | null>(null);
51
58
 
@@ -103,7 +110,7 @@ export function useMailConnection({ userUid, enabled, open }: UseMailConnectionO
103
110
  void Promise.all(
104
111
  mailboxes.map((mailbox) =>
105
112
  listFolders(mailbox.uid)
106
- .then((result): MailboxFolders => ({ mailbox, folders: result.filter((f) => MAIL_FOLDER_TYPES.has(f.type)) }))
113
+ .then((result): MailboxFolders => ({ mailbox, folders: result.filter(isMailFolder) }))
107
114
  .catch(
108
115
  (err): MailboxFolders => ({
109
116
  mailbox,
@@ -118,21 +125,19 @@ export function useMailConnection({ userUid, enabled, open }: UseMailConnectionO
118
125
  }, [mailboxes]);
119
126
 
120
127
  /** Files a newly created folder under its own mailbox, leaving every other mailbox's list untouched - and ignoring a type the
121
- * sidebar doesn't list at all, the same filter the fetch above applies. */
122
- const onFolderCreated = useCallback((folder: Folder) => {
123
- if (!MAIL_FOLDER_TYPES.has(folder.type)) {
124
- return;
125
- }
126
- setMailboxFolders((prev) =>
127
- prev.map((entry) =>
128
- // Not one already there: another client's create event can arrive after (or twice, or alongside) our own.
129
- entry.mailbox.uid === folder.mailboxUid && !entry.folders.some((existing) => existing.uid === folder.uid)
130
- ? { ...entry, folders: [...entry.folders, folder] }
131
- : entry,
132
- ),
133
- );
134
- }, []);
128
+ * sidebar doesn't list at all, the same filter the fetch above applies. One already there (another client's create event can arrive
129
+ * after, or twice, or alongside our own) is not added again - see `upsertFolder()`. */
130
+ const onFolderCreated = useCallback((folder: Folder) => setMailboxFolders((prev) => upsertFolder(prev, folder)), []);
131
+ /** A folder was renamed or changed type elsewhere. */
132
+ const onFolderChanged = useCallback((change: FolderChange) => setMailboxFolders((prev) => upsertFolder(prev, change)), []);
133
+ const onFolderDeleted = useCallback((folderUid: string) => setMailboxFolders((prev) => removeFolder(prev, folderUid)), []);
134
+ /** A mailbox's folders as the server just listed them (every count refresh does): folders the tree lacks - one created lazily on the
135
+ * first send, or by another client whose event never arrived - are added. */
136
+ const onFoldersListed = useCallback((listed: Folder[]) => setMailboxFolders((prev) => reconcileFolders(prev, listed)), []);
135
137
 
138
+ const askedFolderUidsRef = useRef(new Set<string>());
139
+ const foldersRef = useRef(mailboxFolders);
140
+ foldersRef.current = mailboxFolders;
136
141
  // New mail without a reload: push events for every folder, plus a safety-net poll. Held in state beside `mailboxFolders` rather than
137
142
  // written into it, so a refreshed unread count never looks like a change of folders to the list on screen (which reloads, and forgets its
138
143
  // selection, whenever the folders do). A pop-up (and, in the background, a desktop notification) for each new message the connection
@@ -143,8 +148,56 @@ export function useMailConnection({ userUid, enabled, open }: UseMailConnectionO
143
148
  mailboxes,
144
149
  mailboxFolders,
145
150
  onFolderCreated,
151
+ onFolderChanged,
152
+ onFolderDeleted,
153
+ onFoldersListed,
146
154
  onMessageCreated: notifications.announce,
155
+ onSendEvent: handleSendEvent,
147
156
  });
157
+ const noteFolderUids = useCallback(
158
+ (folderUids: Iterable<string>) => {
159
+ const known = knownFolderUids(foldersRef.current);
160
+ const asked = askedFolderUidsRef.current;
161
+ let unknown = false;
162
+ for (const uid of folderUids) {
163
+ if (uid && !known.has(uid) && !asked.has(uid)) {
164
+ asked.add(uid);
165
+ unknown = true;
166
+ }
167
+ }
168
+ if (unknown) {
169
+ // The counts' read-back lists every mailbox's folders and files the new ones; a burst is one refresh.
170
+ folderCounts.refresh();
171
+ }
172
+ },
173
+ [folderCounts.refresh],
174
+ );
175
+ // "Connection lost" for more than a few seconds is a subtle pop-up that goes when it is back.
176
+ usePushConnectionNotice(!!userUid && enabled);
177
+
178
+ // The Outbox indicator: a message being sent from this tab counts at once (before the server has heard of it), settled - or taken back - when
179
+ // the server answers (see `sendJob.ts`); once it accepted one, the folders are read again, since the Outbox may not have existed yet.
180
+ const latestRef = useRef({ mailboxFolders, folderCounts });
181
+ latestRef.current = { mailboxFolders, folderCounts };
182
+ useEffect(() => {
183
+ if (!userUid || !enabled) {
184
+ return;
185
+ }
186
+ return registerOutboxCounter(
187
+ (mailboxUid) => {
188
+ const { mailboxFolders: known, folderCounts: counts } = latestRef.current;
189
+ const outbox = known.find((entry) => entry.mailbox.uid === mailboxUid)?.folders.find((folder) => folder.type === "outbox");
190
+ return outbox ? counts.track(null, { folderUid: outbox.uid, flags: { read: true } } as Message) : NO_TRACKER;
191
+ },
192
+ (mailboxUid) => {
193
+ // The server accepted a message: the Outbox (and, on an older server, Sent Items) may just have been made. The counts' read-back lists
194
+ // every mailbox's folders and files the new ones (`onFoldersListed`); this reads the one mailbox at once.
195
+ latestRef.current.folderCounts.refresh(0);
196
+ listFolders(mailboxUid).then(onFoldersListed, () => undefined);
197
+ },
198
+ );
199
+ }, [userUid, enabled, onFoldersListed]);
200
+ const outbox = useOutboxStatus(mailboxFolders, folderCounts.counts, live.tick, !!userUid && enabled);
148
201
 
149
- return { status, error, mailboxes, mailboxFolders, foldersLoading, onFolderCreated, live, folderCounts, notifications };
202
+ return { status, error, mailboxes, mailboxFolders, foldersLoading, onFolderCreated, noteFolderUids, live, folderCounts, notifications, outbox };
150
203
  }
@@ -5,9 +5,11 @@
5
5
  import { useEffect, useMemo, useRef, useState } from "react";
6
6
  import { Folder, Mailbox, Message } from "@rapidmx/react-shared/mail/mailApi.js";
7
7
  import { getPushClient, PushEvent } from "@rapidmx/react-shared/mail/pushClient.js";
8
+ import { SendEvent, parseSendEvent } from "@rapidmx/react-shared/mail/sendEvents.js";
8
9
  import type { MailboxFolders } from "../components/mail/layout/MailShell.js";
9
10
  import { SIGN_OUT_CHANNEL } from "../search/localIndexRpcClient.js";
10
11
  import { FolderCounts, useFolderCounts } from "./folderCounts.js";
12
+ import { FolderChange, sortFolders } from "./folderTree.js";
11
13
 
12
14
  /** How often the safety-net poll runs while the tab is visible. The push socket does the real work; this is for a network
13
15
  * that blocks or silently drops it, and for events published while it was reconnecting (Redis pub/sub is never replayed). */
@@ -34,14 +36,15 @@ const MESSAGE_ACTIONS = new Set(["create", "update", "delete"]);
34
36
 
35
37
  /**
36
38
  * The channels to subscribe to, most important first (the push client keeps the first `PUSH_MAX_CHANNELS`): every
37
- * mailbox's Inbox - where mail lands - then each mailbox's other folders in the sidebar's own order, then the mailbox uids
38
- * themselves (which announce new folders). A folder is a channel of its own; subscribing to a mailbox does not deliver its
39
- * folders' events.
39
+ * mailbox's Inbox - where mail lands - then the mailbox uids themselves (which announce new, renamed and deleted folders, so
40
+ * they must outrank any folder's own mail), then each mailbox's other folders in the sidebar's own order - a folder that has
41
+ * just appeared is filed by its type like any other, so when the server's cap bites it is the last of them that go without live
42
+ * updates. A folder is a channel of its own; subscribing to a mailbox does not deliver its folders' events.
40
43
  */
41
44
  export function pushChannelsFor(mailboxFolders: MailboxFolders[], mailboxes: Mailbox[]): string[] {
42
45
  const inboxes = mailboxFolders.flatMap((entry) => entry.folders.filter((folder) => folder.type === "inbox"));
43
- const others = mailboxFolders.flatMap((entry) => entry.folders.filter((folder) => folder.type !== "inbox"));
44
- return [...new Set([...inboxes, ...others].map((folder) => folder.uid).concat(mailboxes.map((mailbox) => mailbox.uid)))];
46
+ const others = mailboxFolders.flatMap((entry) => sortFolders(entry.folders.filter((folder) => folder.type !== "inbox")));
47
+ return [...new Set([...inboxes.map((folder) => folder.uid), ...mailboxes.map((mailbox) => mailbox.uid), ...others.map((folder) => folder.uid)])];
45
48
  }
46
49
 
47
50
  function isFolder(value: unknown): value is Folder {
@@ -49,6 +52,12 @@ function isFolder(value: unknown): value is Folder {
49
52
  return !!folder && typeof folder.uid === "string" && typeof folder.mailboxUid === "string" && typeof folder.type === "string";
50
53
  }
51
54
 
55
+ /** A `Folder` update event that says the folder's name or type changed (and names the folder): the counts-only ones the server publishes after every message change do not. */
56
+ function isFolderChange(value: unknown): value is FolderChange {
57
+ const change = value as Partial<FolderChange> | null;
58
+ return !!change && typeof change.uid === "string" && (typeof change.name === "string" || typeof change.type === "string");
59
+ }
60
+
52
61
  function isMessage(value: unknown): value is Message {
53
62
  const message = value as Partial<Message> | null;
54
63
  return (
@@ -76,10 +85,20 @@ export interface UseMailLiveUpdatesOptions {
76
85
  mailboxFolders: MailboxFolders[];
77
86
  /** Called with a folder another client (or this one) created, so the sidebar shows it. Called only for one not already known. */
78
87
  onFolderCreated: (folder: Folder) => void;
88
+ /** Called when a folder's name or type was changed elsewhere (a `Folder` update event that says so - one that only carries counts is not this). */
89
+ onFolderChanged?: (change: FolderChange) => void;
90
+ /** Called with the uid of a folder that was deleted elsewhere. */
91
+ onFolderDeleted?: (folderUid: string) => void;
92
+ /** Called with a mailbox's folders as the server just listed them - on every refresh (a message event, the poll, a reconnect, the tab
93
+ * coming back, a send) - so a folder the tree does not know is found whichever way it appeared. */
94
+ onFoldersListed?: (folders: Folder[]) => void;
79
95
  /** Called with each new message the push connection announces (a `create` event) - once per message, never for a list
80
96
  * refetch, the initial load or a reconnect (nothing published while the socket was down is replayed). The caller decides
81
97
  * whether it is worth telling the user about. */
82
98
  onMessageCreated?: (message: Message) => void;
99
+ /** Called with the outcome of a message sent in the background (`send-succeeded`, `send-failed`, `send-retrying`). Every one also
100
+ * refreshes what is on screen (the Outbox and Sent Items lists and counts change with it). */
101
+ onSendEvent?: (event: SendEvent) => void;
83
102
  }
84
103
 
85
104
  export interface MailLiveUpdates {
@@ -101,13 +120,23 @@ export interface MailLiveUpdates {
101
120
  * Sign-out closes the socket for good: another tab's or this one's, heard on the same channel `AppShell` listens on.
102
121
  * Renders nothing and does nothing where there is no window (server-side rendering).
103
122
  */
104
- export function useMailLiveUpdates({ userUid, mailboxes, mailboxFolders, onFolderCreated, onMessageCreated }: UseMailLiveUpdatesOptions): MailLiveUpdates {
123
+ export function useMailLiveUpdates({
124
+ userUid,
125
+ mailboxes,
126
+ mailboxFolders,
127
+ onFolderCreated,
128
+ onFolderChanged,
129
+ onFolderDeleted,
130
+ onFoldersListed,
131
+ onMessageCreated,
132
+ onSendEvent,
133
+ }: UseMailLiveUpdatesOptions): MailLiveUpdates {
105
134
  const [live, setLive] = useState<LiveUpdates>(NO_LIVE_UPDATES);
106
135
  const folders = useMemo(() => mailboxFolders.flatMap((entry) => entry.folders), [mailboxFolders]);
107
- const folderCounts = useFolderCounts(mailboxes, folders);
136
+ const folderCounts = useFolderCounts(mailboxes, folders, onFoldersListed);
108
137
  // The latest inputs, for the long-lived listeners below.
109
- const latestRef = useRef({ mailboxes, mailboxFolders, onFolderCreated, onMessageCreated, folderCounts });
110
- latestRef.current = { mailboxes, mailboxFolders, onFolderCreated, onMessageCreated, folderCounts };
138
+ const latestRef = useRef({ mailboxes, mailboxFolders, onFolderCreated, onFolderChanged, onFolderDeleted, onMessageCreated, onSendEvent, folderCounts });
139
+ latestRef.current = { mailboxes, mailboxFolders, onFolderCreated, onFolderChanged, onFolderDeleted, onMessageCreated, onSendEvent, folderCounts };
111
140
 
112
141
  const channels = useMemo(() => pushChannelsFor(mailboxFolders, mailboxes), [mailboxFolders, mailboxes]);
113
142
  const channelKey = channels.join("|");
@@ -149,7 +178,12 @@ export function useMailLiveUpdates({ userUid, mailboxes, mailboxFolders, onFolde
149
178
  }
150
179
 
151
180
  const offEvent = client.onEvent((event) => {
152
- if (MESSAGE_EVENT.test(event.type) && MESSAGE_ACTIONS.has(event.action ?? "")) {
181
+ const sendEvent = parseSendEvent(event);
182
+ if (sendEvent) {
183
+ // A queued message was relayed (or failed to be): it left Outbox for Sent Items, or stayed there failed - every list and count may have changed.
184
+ latestRef.current.onSendEvent?.(sendEvent);
185
+ schedule();
186
+ } else if (MESSAGE_EVENT.test(event.type) && MESSAGE_ACTIONS.has(event.action ?? "")) {
153
187
  if (event.action === "create" && isMessage(event.data)) {
154
188
  // Once per message, whatever else the event triggers: the badge first, then whoever announces it.
155
189
  if (latestRef.current.folderCounts.noteCreated(event.data)) {
@@ -158,13 +192,24 @@ export function useMailLiveUpdates({ userUid, mailboxes, mailboxFolders, onFolde
158
192
  }
159
193
  schedule(folderOfMessageEvent(event));
160
194
  } else if (FOLDER_EVENT.test(event.type) && event.action === "create" && isFolder(event.data)) {
195
+ // A folder made by the server (on first use, or by another client) or by this one: filed in the sidebar and subscribed to at once (the
196
+ // channel list follows the tree), and its real counts read - all without a reload.
161
197
  const folder = event.data;
162
198
  const known = latestRef.current.mailboxFolders.some((entry) => entry.folders.some((f) => f.uid === folder.uid));
163
199
  if (!known) {
164
200
  latestRef.current.onFolderCreated(folder);
201
+ latestRef.current.folderCounts.refresh(0);
165
202
  }
166
203
  } else if (FOLDER_EVENT.test(event.type) && event.action === "update") {
204
+ if (isFolderChange(event.data)) {
205
+ latestRef.current.onFolderChanged?.(event.data);
206
+ }
167
207
  latestRef.current.folderCounts.applyFolderEvent(event.data);
208
+ } else if (FOLDER_EVENT.test(event.type) && event.action === "delete") {
209
+ const uid = (event.data as { uid?: unknown } | null | undefined)?.uid;
210
+ if (typeof uid === "string") {
211
+ latestRef.current.onFolderDeleted?.(uid);
212
+ }
168
213
  }
169
214
  });
170
215
  // Anything published while the socket was down is gone for good, so every reconnect is followed by a refresh.
@@ -18,11 +18,9 @@ import {
18
18
  setDesktopOfferDismissed,
19
19
  shouldAnnounce,
20
20
  } from "./newMailNotifications.js";
21
+ import { getNotificationsSnapshot, notify } from "../notifications/store.js";
21
22
 
22
- /** The most pop-ups on screen at once; a new one pushes the oldest off. */
23
- export const MAX_TOASTS = 3;
24
-
25
- /** How long a pop-up stays before it goes by itself (while it is neither hovered nor focused, and the tab is in view). */
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). */
26
24
  export const TOAST_DURATION_MS = 8_000;
27
25
 
28
26
  /** At most this many desktop notifications in `DESKTOP_BURST_WINDOW_MS`: a flood of mail is a few notifications, not a hundred. */
@@ -33,11 +31,7 @@ export const DESKTOP_BURST_WINDOW_MS = 30_000;
33
31
  const ANNOUNCED_LIMIT = 500;
34
32
 
35
33
  export interface NewMailNotifications {
36
- /** The pop-ups on screen, oldest first. */
37
- toasts: NewMailNotice[];
38
- /** Takes one off the screen. */
39
- dismiss(uid: string): void;
40
- /** Whether the first pop-up should also offer to turn on desktop notifications: the browser can, has not been asked,
34
+ /** Whether the next pop-up should also offer to turn on desktop notifications: the browser can, has not been asked,
41
35
  * and the user has not said "Not now". */
42
36
  offerDesktop: boolean;
43
37
  /** The offer's "Turn on desktop notifications": asks the browser. Must be called from a click. */
@@ -65,7 +59,8 @@ function defaultOpen(href: string): void {
65
59
  }
66
60
 
67
61
  /**
68
- * New-mail announcements: an in-app pop-up for each message that arrives (`MAX_TOASTS` at most on screen), and - while the tab
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
69
64
  * is in the background and the user has allowed it - a desktop notification with the same content, one per message however
70
65
  * many events name it. `announce()` is what `useMailLiveUpdates()`'s `onMessageCreated` calls; nothing else feeds it, so a
71
66
  * page load, a list refetch and a reconnect never announce anything.
@@ -74,7 +69,6 @@ function defaultOpen(href: string): void {
74
69
  * first pop-up, or from Settings. What the user answered is remembered in `localStorage` (see `newMailNotifications.ts`).
75
70
  */
76
71
  export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defaultOpen }: UseNewMailNotificationsOptions): NewMailNotifications {
77
- const [toasts, setToasts] = useState<NewMailNotice[]>([]);
78
72
  const [permission, setPermission] = useState<DesktopPermission>("unsupported");
79
73
  const [offerDismissed, setOfferDismissed] = useState(true);
80
74
  const folders = useMemo(() => mailboxFolders.flatMap((entry) => entry.folders), [mailboxFolders]);
@@ -90,10 +84,6 @@ export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defa
90
84
  setOfferDismissed(getDesktopOfferDismissed());
91
85
  }, []);
92
86
 
93
- const dismiss = useCallback((uid: string) => {
94
- setToasts((previous) => previous.filter((toast) => toast.uid !== uid));
95
- }, []);
96
-
97
87
  const showDesktop = useCallback((notice: NewMailNotice) => {
98
88
  const now = Date.now();
99
89
  desktopShownRef.current = desktopShownRef.current.filter((at) => now - at < DESKTOP_BURST_WINDOW_MS);
@@ -117,6 +107,24 @@ export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defa
117
107
  }
118
108
  }, []);
119
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
+
120
128
  const announce = useCallback(
121
129
  (message: Message) => {
122
130
  if (!getNewMailPopupsEnabled() || announcedRef.current.has(message.uid)) {
@@ -131,7 +139,29 @@ export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defa
131
139
  announcedRef.current.delete(announcedRef.current.values().next().value!);
132
140
  }
133
141
  const notice = noticeFor(message);
134
- setToasts((previous) => [...previous.filter((toast) => toast.uid !== notice.uid), notice].slice(-MAX_TOASTS));
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
+ });
135
165
  if (desktopPermission() === "granted" && tabIsInBackground()) {
136
166
  showDesktop(notice);
137
167
  }
@@ -139,23 +169,8 @@ export function useNewMailNotifications({ mailboxes, mailboxFolders, open = defa
139
169
  [showDesktop],
140
170
  );
141
171
 
142
- const enableDesktop = useCallback(async () => {
143
- const answer = await requestDesktopPermission();
144
- setPermission(answer);
145
- // Answered either way, so the offer goes: on granted it has done its job, on denied it can't be made again.
146
- setDesktopOfferDismissed(true);
147
- setOfferDismissed(true);
148
- }, []);
149
-
150
- const declineDesktop = useCallback(() => {
151
- setDesktopOfferDismissed(true);
152
- setOfferDismissed(true);
153
- }, []);
154
-
155
172
  return {
156
- toasts,
157
- dismiss,
158
- offerDesktop: permission === "default" && !offerDismissed,
173
+ offerDesktop,
159
174
  enableDesktop,
160
175
  declineDesktop,
161
176
  announce,
@@ -71,8 +71,8 @@ export interface AppRouterProps {
71
71
  }
72
72
 
73
73
  function pickChromeProps(props: Record<string, any>): Omit<AppShellProps, "active"> {
74
- const { userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, trustedRoles, pluginNav } = props;
75
- return { userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, trustedRoles, pluginNav };
74
+ const { userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, trustedRoles, pluginNav, branding, appearance } = props;
75
+ return { userUid, authServerUrl, impersonating, impersonationBaseUrl, trusted, trustedRoles, pluginNav, branding, appearance };
76
76
  }
77
77
 
78
78
  /** The anchor a click/pointer event is on or in, if it is a link. */