@cometchat/chat-uikit-react-native 5.5.4 → 5.7.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 (215) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatKeyboardModule.kt +101 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
  3. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  4. package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
  5. package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
  7. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  8. package/ios/CCLocalFileGuard.h +19 -0
  9. package/ios/CCLocalFileGuard.m +34 -0
  10. package/ios/CometChatKeyboardModule.m +9 -0
  11. package/ios/CometChatKeyboardModule.swift +71 -0
  12. package/ios/FileManager.m +70 -6
  13. package/ios/KeyboardLanguageDirection.swift +24 -0
  14. package/ios/RichTextEditorView.swift +253 -51
  15. package/ios/RichTextEditorViewManager.m +1 -0
  16. package/ios/VideoManager.m +1 -1
  17. package/package.json +18 -3
  18. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
  19. package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
  20. package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
  21. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +145 -63
  22. package/src/CometChatCompactMessageComposer/styles.ts +7 -7
  23. package/src/CometChatConversations/CometChatConversations.tsx +276 -147
  24. package/src/CometChatConversations/Skeleton.tsx +4 -1
  25. package/src/CometChatConversations/style.ts +1 -1
  26. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +39 -18
  27. package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
  28. package/src/CometChatGroupMembers/style.ts +6 -4
  29. package/src/CometChatGroups/CometChatGroups.tsx +74 -58
  30. package/src/CometChatGroups/GroupsStyle.ts +1 -1
  31. package/src/CometChatGroups/Skeleton.tsx +4 -1
  32. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +190 -96
  33. package/src/CometChatMessageComposer/styles.tsx +1 -1
  34. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +28 -15
  35. package/src/CometChatMessageHeader/listners.ts +76 -56
  36. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
  37. package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
  38. package/src/CometChatMessageList/CometChatMessageList.tsx +1465 -313
  39. package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
  40. package/src/CometChatMessageList/style.ts +32 -32
  41. package/src/CometChatMessageList/swipeToReply.ts +25 -0
  42. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +81 -10
  43. package/src/CometChatNotificationFeed/style.ts +1 -1
  44. package/src/CometChatNotificationFeed/utils.ts +17 -18
  45. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +82 -3
  46. package/src/CometChatPinnedMessages/style.ts +5 -5
  47. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
  48. package/src/CometChatRichTextEditor/index.tsx +3 -0
  49. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +83 -15
  50. package/src/CometChatSavedMessages/style.ts +3 -3
  51. package/src/CometChatSearch/CometChatSearch.tsx +391 -136
  52. package/src/CometChatSearch/Skeleton.tsx +4 -1
  53. package/src/CometChatSearch/searchLabels.ts +26 -0
  54. package/src/CometChatSearch/style.ts +7 -7
  55. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +34 -8
  56. package/src/CometChatThreadHeader/Header.tsx +2 -2
  57. package/src/CometChatUsers/CometChatUsers.tsx +10 -1
  58. package/src/CometChatUsers/Skeleton.tsx +4 -1
  59. package/src/CometChatUsers/style.ts +1 -1
  60. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +27 -1
  61. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
  62. package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
  63. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
  64. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
  65. package/src/extensions/CollaborativeBubble/style.ts +4 -4
  66. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
  67. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
  68. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
  69. package/src/extensions/LinkPreview/style.ts +6 -6
  70. package/src/extensions/Polls/Header.tsx +1 -1
  71. package/src/extensions/Polls/Polls.tsx +25 -12
  72. package/src/extensions/Polls/PollsBubble.tsx +10 -6
  73. package/src/extensions/Polls/style.ts +4 -4
  74. package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
  75. package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
  76. package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
  77. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
  78. package/src/index.ts +11 -1
  79. package/src/shared/CometChatUiKit/CometChatUIKit.ts +102 -2
  80. package/src/shared/CometChatUiKit/UIKitSettings.ts +28 -0
  81. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  82. package/src/shared/events/index.ts +4 -0
  83. package/src/shared/events/offline.ts +28 -0
  84. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +18 -13
  85. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
  86. package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
  87. package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
  88. package/src/shared/framework/MessageDataSource.tsx +51 -108
  89. package/src/shared/helper/LocalizedDateHelper.ts +64 -4
  90. package/src/shared/helper/helperFunctions.ts +71 -4
  91. package/src/shared/helper/keyboardDirection.ts +54 -0
  92. package/src/shared/helper/layoutDirection.ts +205 -0
  93. package/src/shared/helper/pluralRules.ts +67 -0
  94. package/src/shared/helper/textDirection.ts +118 -0
  95. package/src/shared/icons/Icon.tsx +37 -2
  96. package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
  97. package/src/shared/index.ts +2 -0
  98. package/src/shared/offline/OfflineHub.ts +651 -0
  99. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  100. package/src/shared/offline/OfflineViews.tsx +222 -0
  101. package/src/shared/offline/conversationPins.ts +137 -0
  102. package/src/shared/offline/conversations.ts +325 -0
  103. package/src/shared/offline/frameProbe.ts +24 -0
  104. package/src/shared/offline/gate.ts +94 -0
  105. package/src/shared/offline/groupActions.ts +81 -0
  106. package/src/shared/offline/identity.ts +162 -0
  107. package/src/shared/offline/index.ts +76 -0
  108. package/src/shared/offline/media.ts +247 -0
  109. package/src/shared/offline/notices.ts +84 -0
  110. package/src/shared/offline/reconcile.ts +296 -0
  111. package/src/shared/offline/searchOutcome.ts +62 -0
  112. package/src/shared/offline/send.ts +430 -0
  113. package/src/shared/offline/stateContract.ts +85 -0
  114. package/src/shared/offline/threadReplies.ts +125 -0
  115. package/src/shared/offline/twoPhase.ts +372 -0
  116. package/src/shared/offline/unsentActions.ts +168 -0
  117. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  118. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  119. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  120. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  121. package/src/shared/offline/usePresenceHidden.ts +33 -0
  122. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +2 -0
  123. package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
  124. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -3
  125. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -4
  126. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +74 -3
  127. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +75 -4
  128. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +74 -3
  129. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +74 -3
  130. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +74 -3
  131. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +74 -3
  132. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +74 -3
  133. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +82 -3
  134. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +74 -3
  135. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +74 -3
  136. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +74 -3
  137. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +90 -3
  138. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +74 -3
  139. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +74 -3
  140. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +74 -3
  141. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +74 -3
  142. package/src/shared/services/UploadQueueService.ts +106 -1
  143. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
  144. package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
  145. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  146. package/src/shared/utils/MessageUtils.tsx +14 -14
  147. package/src/shared/utils/PermissionUtil.ts +16 -5
  148. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  149. package/src/shared/utils/attachmentLimits.ts +3 -2
  150. package/src/shared/utils/catchUpCursor.ts +36 -0
  151. package/src/shared/utils/conversationUtils.ts +3 -5
  152. package/src/shared/utils/failedMessageRetry.ts +73 -0
  153. package/src/shared/utils/fileIconFontSize.ts +10 -0
  154. package/src/shared/utils/fileSizeLabel.ts +16 -0
  155. package/src/shared/utils/groupActionText.ts +75 -0
  156. package/src/shared/utils/messageIdentity.ts +38 -0
  157. package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
  158. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
  159. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
  160. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
  161. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +45 -12
  162. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
  163. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +20 -8
  164. package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
  165. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
  166. package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
  167. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
  168. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
  169. package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
  170. package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
  171. package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
  172. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  173. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +65 -15
  174. package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
  175. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +56 -25
  176. package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
  177. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
  178. package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
  179. package/src/shared/views/CometChatList/CometChatList.tsx +478 -21
  180. package/src/shared/views/CometChatList/Header.tsx +5 -2
  181. package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
  182. package/src/shared/views/CometChatList/styles.ts +7 -7
  183. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
  184. package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
  185. package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
  186. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +43 -16
  187. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
  188. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +19 -2
  189. package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
  190. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +59 -12
  191. package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
  192. package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
  193. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
  194. package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
  195. package/src/shared/views/CometChatReportDialog/style.ts +1 -1
  196. package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
  197. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  198. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
  199. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
  200. package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
  201. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
  202. package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
  203. package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
  204. package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
  205. package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
  206. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +58 -24
  207. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  208. package/src/shared/views/SenderLabel.tsx +41 -0
  209. package/src/theme/default/default.ts +1 -1
  210. package/src/theme/type.ts +17 -0
  211. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  212. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  213. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  214. package/android/.gradle/7.4/gc.properties +0 -0
  215. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -0,0 +1,372 @@
1
+ /**
2
+ * Two-phase reads for the offline (ON) path (README §3.3): the cached page first, then the
3
+ * server page, then exactly one terminal. Never used with offline off, where every list keeps
4
+ * today's single Promise-form fetch.
5
+ *
6
+ * One listener object carries every per-entity callback name the SDK may call
7
+ * (`onCachedUsers` / `onServerGroups` / …), so the same reader serves messages, conversations,
8
+ * users, groups, group members and banned members. The SDK still returns its Promise alongside
9
+ * the listener and rejects it offline; it is caught and ignored, because the listener is the
10
+ * channel.
11
+ *
12
+ * @internal
13
+ */
14
+ import { isNotConnectedError } from "./reconcile";
15
+ import { isOfflineOn } from "./gate";
16
+
17
+ export interface TwoPhaseHandlers<T> {
18
+ onCached(page: T[]): void;
19
+ onServer(page: T[]): void;
20
+ /** `notConnected` = an offline read past the cache: keep what is shown. */
21
+ onError(error: unknown, notConnected: boolean): void;
22
+ }
23
+
24
+ const ENTITY_SUFFIXES = [
25
+ "Messages",
26
+ "Conversations",
27
+ "Users",
28
+ "Groups",
29
+ "GroupMembers",
30
+ "BannedGroupMembers",
31
+ "Reactions",
32
+ "FeedItems",
33
+ "NotificationFeedItems",
34
+ "Threads",
35
+ ];
36
+
37
+ /**
38
+ * Run `request.fetchNext(listener)` (or `fetchPrevious`) two-phase. Resolves once the terminal
39
+ * phase (server page or error) has been handled; never rejects. A `stale()` check, evaluated at
40
+ * each phase, drops callbacks of an operation that a newer one (or a logout) superseded.
41
+ */
42
+ export function fetchTwoPhase<T>(
43
+ request: any,
44
+ direction: "next" | "previous",
45
+ handlers: TwoPhaseHandlers<T>,
46
+ stale: () => boolean = () => false
47
+ ): Promise<void> {
48
+ return new Promise<void>((resolve) => {
49
+ let ended = false;
50
+ const end = () => {
51
+ if (!ended) {
52
+ ended = true;
53
+ resolve();
54
+ }
55
+ };
56
+ const onCached = (page: T[]) => {
57
+ if (ended || stale()) return;
58
+ handlers.onCached(Array.isArray(page) ? page : []);
59
+ };
60
+ const onServer = (page: T[]) => {
61
+ if (ended) return;
62
+ if (!stale()) handlers.onServer(Array.isArray(page) ? page : []);
63
+ end();
64
+ };
65
+ const onError = (error: unknown) => {
66
+ if (ended) return;
67
+ if (!stale()) handlers.onError(error, isNotConnectedError(error));
68
+ end();
69
+ };
70
+ const listener: Record<string, Function> = { onError };
71
+ for (const suffix of ENTITY_SUFFIXES) {
72
+ listener[`onCached${suffix}`] = onCached;
73
+ listener[`onServer${suffix}`] = onServer;
74
+ }
75
+ try {
76
+ const run = direction === "previous" ? request?.fetchPrevious : request?.fetchNext;
77
+ if (typeof run !== "function") {
78
+ onError(new Error("request has no fetch method"));
79
+ return;
80
+ }
81
+ const result: any = run.call(request, listener);
82
+ if (result && typeof result.then === "function") result.then(undefined, (error: unknown) => onError(error));
83
+ } catch (error) {
84
+ onError(error);
85
+ }
86
+ });
87
+ }
88
+
89
+ /**
90
+ * Apply a snapshot list's server page over what its cached page showed: server copies replace
91
+ * cached ones in place, cached rows the server no longer returns are dropped, new rows are
92
+ * appended. Rows of other pages stay.
93
+ */
94
+ export function mergeSnapshotPage<T>(current: readonly T[], cachedKeys: ReadonlySet<string>, page: readonly T[], keyOf: (item: T) => string): T[] {
95
+ const serverByKey = new Map(page.map((item) => [keyOf(item), item] as const));
96
+ const next: T[] = [];
97
+ const seen = new Set<string>();
98
+ for (const item of current) {
99
+ const key = keyOf(item);
100
+ if (seen.has(key)) continue;
101
+ const fresh = serverByKey.get(key);
102
+ if (fresh !== undefined) {
103
+ next.push(fresh);
104
+ seen.add(key);
105
+ continue;
106
+ }
107
+ if (cachedKeys.has(key)) continue;
108
+ next.push(item);
109
+ seen.add(key);
110
+ }
111
+ for (const item of page) {
112
+ const key = keyOf(item);
113
+ if (!seen.has(key)) {
114
+ next.push(item);
115
+ seen.add(key);
116
+ }
117
+ }
118
+ return next;
119
+ }
120
+
121
+ /** Append `page` to `current`, skipping keys already shown (cached page of a later page). */
122
+ export function appendUnique<T>(current: readonly T[], page: readonly T[], keyOf: (item: T) => string): T[] {
123
+ const seen = new Set(current.map(keyOf));
124
+ const next = current.slice();
125
+ for (const item of page) {
126
+ const key = keyOf(item);
127
+ if (!seen.has(key)) {
128
+ next.push(item);
129
+ seen.add(key);
130
+ }
131
+ }
132
+ return next;
133
+ }
134
+
135
+ export interface SingleTwoPhaseHandlers<T> {
136
+ /** Fires only on a cache hit. */
137
+ onCached?(item: T): void;
138
+ onServer(item: T): void;
139
+ onError(error: unknown, notConnected: boolean): void;
140
+ }
141
+
142
+ /**
143
+ * A two-phase single read (`getMessageDetails(id, listener)`, `getConversation(with, type,
144
+ * listener)`; BEH-READ-28/32/35): the cached copy on a hit, then the server copy, then exactly
145
+ * one terminal. `run` calls the SDK with the listener; its returned Promise is caught and only
146
+ * used as a terminal when the listener gave none. Never rejects.
147
+ */
148
+ export function getTwoPhase<T>(
149
+ run: (listener: Record<string, Function>) => unknown,
150
+ entity: "Message" | "Conversation",
151
+ handlers: SingleTwoPhaseHandlers<T>,
152
+ stale: () => boolean = () => false
153
+ ): Promise<void> {
154
+ return new Promise<void>((resolve) => {
155
+ let ended = false;
156
+ const end = () => {
157
+ if (!ended) {
158
+ ended = true;
159
+ resolve();
160
+ }
161
+ };
162
+ const onServer = (item: T) => {
163
+ if (ended) return;
164
+ if (!stale()) handlers.onServer(item);
165
+ end();
166
+ };
167
+ const onError = (error: unknown) => {
168
+ if (ended) return;
169
+ if (!stale()) handlers.onError(error, isNotConnectedError(error));
170
+ end();
171
+ };
172
+ const listener: Record<string, Function> = {
173
+ [`onCached${entity}`]: (item: T | undefined) => {
174
+ if (ended || stale() || item === undefined || item === null) return;
175
+ handlers.onCached?.(item);
176
+ },
177
+ [`onServer${entity}`]: onServer,
178
+ onError,
179
+ };
180
+ try {
181
+ const result: any = run(listener);
182
+ if (result && typeof result.then === "function") {
183
+ result.then(
184
+ (value: T) => {
185
+ // An SDK that ignored the listener still answers through its Promise.
186
+ if (!ended) onServer(value);
187
+ },
188
+ (error: unknown) => onError(error)
189
+ );
190
+ }
191
+ } catch (error) {
192
+ onError(error);
193
+ }
194
+ });
195
+ }
196
+
197
+ export interface AroundReadHandlers<M> {
198
+ /**
199
+ * Show the anchored window: the target and the page after it. `phase` is "cached" for the
200
+ * first paint from the device, "server" for the server's copy (which replaces it).
201
+ */
202
+ onPaint(target: M, next: M[], phase: "cached" | "server"): void;
203
+ /** Nothing could be shown: `notConnected` = offline with the target not cached. */
204
+ onError(error: unknown, notConnected: boolean): void;
205
+ /**
206
+ * The cached window is on screen (painted) and the server's answer failed: the rows stay, and
207
+ * the caller reports the error once (D83 rule 2).
208
+ */
209
+ onKeptRowsError?(error: unknown): void;
210
+ }
211
+
212
+ /**
213
+ * Jump to a message / start from the first unread on the offline (ON) path (BEH-READ-29,
214
+ * UIT-READ-08/09): the target (`getMessageDetails`) and the page after it (`fetchNext` anchored
215
+ * on it), both two-phase. The cached pair paints first when both are on the device; the server
216
+ * pair replaces it. Offline, a cached pair stays on screen with no error; a target that was never
217
+ * cached ends with `onError(..., true)`. Resolves when both reads ended; never rejects.
218
+ */
219
+ export function readAroundTwoPhase<M>(
220
+ getTarget: (listener: Record<string, Function>) => unknown,
221
+ nextRequest: any,
222
+ handlers: AroundReadHandlers<M>,
223
+ stale: () => boolean = () => false
224
+ ): Promise<void> {
225
+ let cachedTarget: M | undefined;
226
+ let serverTarget: M | undefined;
227
+ let targetError: unknown;
228
+ let nextError: unknown;
229
+ let cachedNext: M[] | undefined;
230
+ let serverNext: M[] | undefined;
231
+ let targetDone = false;
232
+ let nextDone = false;
233
+ let paintedCached = false;
234
+ let finished = false;
235
+
236
+ const step = () => {
237
+ if (finished || stale()) return;
238
+ if (!paintedCached && cachedTarget !== undefined && (cachedNext !== undefined || nextDone)) {
239
+ paintedCached = true;
240
+ handlers.onPaint(cachedTarget, cachedNext ?? serverNext ?? [], "cached");
241
+ }
242
+ if (!targetDone || !nextDone) return;
243
+ finished = true;
244
+ if (serverTarget !== undefined && serverNext !== undefined) {
245
+ handlers.onPaint(serverTarget, serverNext, "server");
246
+ return;
247
+ }
248
+ if (paintedCached) {
249
+ // Past the server: keep the cached window, and say the server read failed.
250
+ handlers.onKeptRowsError?.(targetError ?? nextError);
251
+ return;
252
+ }
253
+ const target = serverTarget ?? cachedTarget;
254
+ if (target === undefined) {
255
+ handlers.onError(targetError, isNotConnectedError(targetError));
256
+ return;
257
+ }
258
+ handlers.onPaint(target, serverNext ?? cachedNext ?? [], serverTarget !== undefined && serverNext !== undefined ? "server" : "cached");
259
+ };
260
+
261
+ const target = getTwoPhase<M>(
262
+ getTarget,
263
+ "Message",
264
+ {
265
+ onCached: (m) => {
266
+ cachedTarget = m;
267
+ step();
268
+ },
269
+ onServer: (m) => {
270
+ if (m === undefined || m === null) targetError = new Error("message not found");
271
+ else serverTarget = m;
272
+ },
273
+ onError: (error) => {
274
+ targetError = error;
275
+ },
276
+ },
277
+ stale
278
+ ).then(() => {
279
+ targetDone = true;
280
+ step();
281
+ });
282
+ const next = fetchTwoPhase<M>(
283
+ nextRequest,
284
+ "next",
285
+ {
286
+ onCached: (page) => {
287
+ cachedNext = page;
288
+ step();
289
+ },
290
+ onServer: (page) => {
291
+ serverNext = page;
292
+ },
293
+ onError: (error) => {
294
+ // the cached page (if any) stays; the target decides what is shown
295
+ nextError = error;
296
+ },
297
+ },
298
+ stale
299
+ ).then(() => {
300
+ nextDone = true;
301
+ step();
302
+ });
303
+ return Promise.all([target, next]).then(() => undefined);
304
+ }
305
+
306
+ /**
307
+ * A two-phase single read for a caller that needs one value (an anchor id, an unread count): the
308
+ * server copy when the server answers; offline (not-connected), the cached copy when there was a
309
+ * hit; otherwise the error, as the Promise form would give it (UIT-LIFE-11: a chat opened by id
310
+ * offline opens from the cache, or shows today's error when it was never cached).
311
+ */
312
+ export function resolveTwoPhase<T>(run: (listener: Record<string, Function>) => unknown, entity: "Message" | "Conversation"): Promise<T> {
313
+ return new Promise<T>((resolve, reject) => {
314
+ let cached: T | undefined;
315
+ getTwoPhase<T>(run, entity, {
316
+ onCached: (item) => {
317
+ cached = item;
318
+ },
319
+ onServer: (item) => resolve(item),
320
+ onError: (error, notConnected) => {
321
+ if (notConnected && cached !== undefined) resolve(cached);
322
+ else reject(error);
323
+ },
324
+ });
325
+ });
326
+ }
327
+
328
+ export interface ListPage<T> {
329
+ rows: T[];
330
+ /** Offline past the cache: the rows (possibly none) are the device's; more needs a connection. */
331
+ offline: boolean;
332
+ /** With `offline`: the not-connected error the server read ended with (D83: reported to `onError`). */
333
+ error?: unknown;
334
+ /** With `offline`: the SDK gave a cached phase (possibly empty) before the error. */
335
+ cachedDelivered?: boolean;
336
+ }
337
+
338
+ /**
339
+ * One page of a panel list (pinned, saved, reactions, notification feed; README §3.9 U6). The gate
340
+ * is read once for the read. Offline OFF: today's Promise-form fetch, unchanged. Offline ON: the
341
+ * SDK's two-phase read: the server page when it answers, otherwise (not connected) the cached
342
+ * page with `offline: true`, so the panel shows what the device has instead of an error. Any
343
+ * other error rejects as today. `onCached` lets a panel paint the cached page first.
344
+ */
345
+ export function readListPage<T>(
346
+ request: any,
347
+ direction: "next" | "previous",
348
+ options: { onCached?(rows: T[]): void } = {}
349
+ ): Promise<ListPage<T>> {
350
+ if (!isOfflineOn()) {
351
+ const run = direction === "previous" ? request?.fetchPrevious : request?.fetchNext;
352
+ return Promise.resolve(run.call(request)).then((rows: T[]) => ({ rows: Array.isArray(rows) ? rows : [], offline: false }));
353
+ }
354
+ return new Promise<ListPage<T>>((resolve, reject) => {
355
+ let cached: T[] | null = null;
356
+ fetchTwoPhase<T>(request, direction, {
357
+ onCached: (rows) => {
358
+ cached = rows;
359
+ try {
360
+ options.onCached?.(rows);
361
+ } catch {
362
+ /* a paint error must not break the read */
363
+ }
364
+ },
365
+ onServer: (rows) => resolve({ rows, offline: false }),
366
+ onError: (error, notConnected) => {
367
+ if (notConnected) resolve({ rows: cached ?? [], offline: true, error, cachedDelivered: cached !== null });
368
+ else reject(error);
369
+ },
370
+ });
371
+ });
372
+ }
@@ -0,0 +1,168 @@
1
+ /**
2
+ * What an own UNSENT row offers, and what Delete does (BEH-SEND-36; ruling R162 / S73, frozen
3
+ * 2026-11-03, which rewrote BEH-SEND-37 and supersedes UIK-SEND-05's "Copy, no Delete" and the
4
+ * earlier "Delete only after a permanent failure" and "nothing while SENDING" rules).
5
+ *
6
+ * On the sender's own row that has no server id (offline ON path only), a UI kit offers Retry and
7
+ * Delete on every PENDING, SENDING and FAILED (any reason) message, and on a failed row kept in
8
+ * memory that never entered the outbox:
9
+ *
10
+ * | Row | Menu |
11
+ * |-------------------------------------------------------|-----------------|
12
+ * | PENDING | Retry, Delete |
13
+ * | SENDING (on the wire) | Retry, Delete |
14
+ * | FAILED, any reason (TRANSIENT, PERMANENT, unknown, …) | Retry, Delete |
15
+ * | failed (direct), kept in memory, never in the outbox | Retry, Delete |
16
+ *
17
+ * The SDK decides whether it can act: on a message whose send is under way it answers
18
+ * `ERROR_OFFLINE_MESSAGE_IN_FLIGHT` to Retry and to Delete and changes nothing, and the kit shows
19
+ * the short "Sending… try again in a moment" notice (`OfflineHub.raiseSendInFlightNotice`). The
20
+ * kit keeps no in-flight state of its own to hide the menu.
21
+ *
22
+ * Nothing else: no Copy, reply, thread, react, edit, pin, save, mark unread, info, translate,
23
+ * report or forward (they need a server id). With offline off nothing here is reached and the
24
+ * menu is today's.
25
+ *
26
+ * @internal
27
+ */
28
+ import { offlineSdk, sdkConnected } from "./gate";
29
+ import {
30
+ failureReasonOf,
31
+ isOfflineUnsent,
32
+ localIdOf,
33
+ OfflineMessageStatus,
34
+ serverIdOf,
35
+ statusOf,
36
+ } from "./identity";
37
+ import { OfflineHub } from "./OfflineHub";
38
+
39
+ export type UnsentRowState = "pending" | "sending" | "failed";
40
+ export type UnsentAction = "retry" | "delete";
41
+
42
+ export interface UnsentRowInfo {
43
+ state: UnsentRowState;
44
+ /** `MessageFailureReason` of a failed row, `""` when unknown. */
45
+ reason: string;
46
+ /** Failed without entering the outbox: Retry is a fresh send, Delete removes it from the screen. */
47
+ direct: boolean;
48
+ }
49
+
50
+ /** The SDK's offline error codes a Delete can be refused with (R160). */
51
+ export const DISCARD_ERROR = Object.freeze({
52
+ inFlight: "ERROR_OFFLINE_MESSAGE_IN_FLIGHT",
53
+ notFound: "ERROR_OFFLINE_MESSAGE_NOT_FOUND",
54
+ disabled: "ERROR_OFFLINE_DISABLED",
55
+ /** A queued send ended without being sent: the session ended or the cache was reset (Android `ERROR_DISCARDED`). */
56
+ discarded: "ERROR_OFFLINE_MESSAGE_DISCARDED",
57
+ /** The SDK's error for a send made with nobody logged in (Android `ERROR_NOT_LOGGED_IN`). */
58
+ notLoggedIn: "ERROR_USER_NOT_LOGGED_IN",
59
+ });
60
+
61
+ /**
62
+ * The unsent state of an own row, or `null` when it is not an unsent row (it has a server id, or
63
+ * the offline path never touched it). The hub's last reported state wins over the row's status,
64
+ * because a per-send callback can hand over a message object whose status was not updated.
65
+ */
66
+ export function unsentRowInfo(message: any, hub: OfflineHub = OfflineHub.getInstance()): UnsentRowInfo | null {
67
+ if (!message || serverIdOf(message) > 0) return null;
68
+ const directReason = hub.directFailureOf(message);
69
+ if (directReason !== undefined) return { state: "failed", reason: directReason, direct: true };
70
+ if (!isOfflineUnsent(message)) return null;
71
+ const localMessageId = localIdOf(message);
72
+ const status = statusOf(message);
73
+ const reported = hub.stateOf(localMessageId);
74
+ const reasonOf = () => failureReasonOf(message) || hub.failureReasonFor(localMessageId);
75
+ if (reported === "failed") return { state: "failed", reason: reasonOf(), direct: false };
76
+ if (reported === "sending") {
77
+ return { state: status === OfflineMessageStatus.sending ? "sending" : "pending", reason: "", direct: false };
78
+ }
79
+ if (status === OfflineMessageStatus.failed) return { state: "failed", reason: reasonOf(), direct: false };
80
+ if (status === OfflineMessageStatus.sending) return { state: "sending", reason: "", direct: false };
81
+ return { state: "pending", reason: "", direct: false };
82
+ }
83
+
84
+ /**
85
+ * The menu for an unsent row (R162 / S73): Retry and Delete on every unsent row, whatever its
86
+ * state or failure reason. Empty = not an unsent row, today's menu.
87
+ */
88
+ export function unsentActionsOf(info: UnsentRowInfo | null): UnsentAction[] {
89
+ return info ? ["retry", "delete"] : [];
90
+ }
91
+
92
+ /** Whether the row offers Retry right now. */
93
+ export function canRetryUnsent(message: any, hub: OfflineHub = OfflineHub.getInstance()): boolean {
94
+ return unsentActionsOf(unsentRowInfo(message, hub)).includes("retry");
95
+ }
96
+
97
+ export type DeleteUnsentOutcome =
98
+ /** Gone from the device (or the screen, for a direct failure); the row is removed. */
99
+ | { kind: "removed" }
100
+ /** The send is on the wire: the row stays; the "Sending… try again in a moment" notice is up (R162). */
101
+ | { kind: "in_flight"; error: unknown }
102
+ /** The message was sent: delete it on the server through today's path. */
103
+ | { kind: "sent"; serverId: number }
104
+ /** The message was sent but the device is offline: today's not-connected error. */
105
+ | { kind: "not_connected"; error: unknown }
106
+ /** Offline was switched off (kill switch): the row is failed (direct) now. */
107
+ | { kind: "disabled"; error: unknown }
108
+ /** Any other refusal (store blip): the row stays; show today's error. */
109
+ | { kind: "error"; error: unknown };
110
+
111
+ /** The SDK error code of a refusal (`code`, else `name`), or `""`. */
112
+ export function errorCodeOf(error: unknown): string {
113
+ const code = (error as any)?.code ?? (error as any)?.name;
114
+ return typeof code === "string" ? code : "";
115
+ }
116
+
117
+ /**
118
+ * Delete an unsent row (BEH-SEND-36, R162). An outbox row is discarded on the device with
119
+ * `discardLocalMessage(localMessageId)` (works offline, durable; the SDK moves the conversation
120
+ * preview itself and fires no outbox event), then removed from the screen. A direct failure has
121
+ * no outbox row and is removed from the screen only. Never the server delete for a row with no
122
+ * server id. A row whose send is under way is refused by the SDK (`ERROR_OFFLINE_MESSAGE_IN_FLIGHT`,
123
+ * nothing changes) and raises the "Sending… try again in a moment" notice. Never rejects.
124
+ */
125
+ export async function deleteUnsentMessage(message: any, hub: OfflineHub = OfflineHub.getInstance()): Promise<DeleteUnsentOutcome> {
126
+ const localMessageId = localIdOf(message);
127
+ const info = unsentRowInfo(message, hub);
128
+ if (info?.direct || !localMessageId) {
129
+ hub.reportDiscardedByUser(message);
130
+ return { kind: "removed" };
131
+ }
132
+ const sdk = offlineSdk();
133
+ if (typeof sdk?.discardLocalMessage !== "function") {
134
+ return { kind: "error", error: new Error("discardLocalMessage is not available") };
135
+ }
136
+ try {
137
+ await sdk.discardLocalMessage(localMessageId);
138
+ } catch (error) {
139
+ switch (errorCodeOf(error)) {
140
+ case DISCARD_ERROR.inFlight:
141
+ hub.raiseSendInFlightNotice(message);
142
+ return { kind: "in_flight", error };
143
+ case DISCARD_ERROR.notFound: {
144
+ // The SDK no longer holds it: it was sent, or purged with its chat. A row with a server id
145
+ // is a sent message: today's server delete (offline, today's not-connected error). Any
146
+ // other row is removed at once, online or offline, as on Android; if its sent copy still
147
+ // arrives, it is deleted on the server then.
148
+ const serverId = serverIdOf(message) || hub.sentIdFor(localMessageId);
149
+ if (serverId) return sdkConnected() === false ? { kind: "not_connected", error } : { kind: "sent", serverId };
150
+ hub.reportDiscardedByUser(message);
151
+ hub.deleteWhenSent(localMessageId);
152
+ return { kind: "removed" };
153
+ }
154
+ case DISCARD_ERROR.disabled:
155
+ return { kind: "disabled", error };
156
+ default:
157
+ return { kind: "error", error };
158
+ }
159
+ }
160
+ hub.reportDiscardedByUser(message);
161
+ return { kind: "removed" };
162
+ }
163
+
164
+ /** Option ids of the unsent-row menu (stable for integrators' tests and the state contract). */
165
+ export const OFFLINE_OPTION_IDS = Object.freeze({
166
+ retry: "offlineRetryMessage",
167
+ delete: "offlineDeleteMessage",
168
+ });
@@ -0,0 +1,87 @@
1
+ /**
2
+ * React adapter for {@link offlineAttachmentUri} and the playable shim (README §3.8).
3
+ *
4
+ * With offline off it returns `attachment.getUrl()` and does nothing else: its effect returns at
5
+ * once (no lookup, no listener, no timer). On the ON path it starts from the SDK's cached copy (or
6
+ * the URL), swaps in a playable copy when `playable` is set, and re-resolves when the SDK reports
7
+ * that this message's media finished downloading.
8
+ *
9
+ * @internal
10
+ */
11
+ import { useEffect, useRef, useState } from "react";
12
+ import { cachedPathOf, isMediaOutOfReach, offlineAttachmentUri, playableUri, shouldUseCachedMedia } from "./media";
13
+ import { OfflineHub } from "./OfflineHub";
14
+
15
+ function urlKeyOf(url: string): string {
16
+ return String(url ?? "").split("?")[0];
17
+ }
18
+
19
+ export function useOfflineMediaUri(attachment: any, options: { playable?: boolean; uid?: string } = {}): string {
20
+ const initial = offlineAttachmentUri(attachment);
21
+ // Keyed by the attachment's URL, never by the object: a receipt, a reaction or an ack clones the
22
+ // message and its attachments, and a clone of the same media must keep its resolved source (a
23
+ // playing video or voice note would restart, an image would reload).
24
+ const [resolved, setResolved] = useState<{ key: string; uri: string } | null>(null);
25
+ const remote = attachment?.getUrl?.();
26
+ const remoteKey = urlKeyOf(remote);
27
+ const attachmentRef = useRef(attachment);
28
+ attachmentRef.current = attachment;
29
+ // The SDK's cached file as of this render: a string, so a clone with the same file changes nothing.
30
+ const cachedNow = shouldUseCachedMedia() ? cachedPathOf(attachment) : "";
31
+
32
+ useEffect(() => {
33
+ // Offline off: today's URL, nothing else.
34
+ if (!shouldUseCachedMedia()) return;
35
+ let cancelled = false;
36
+ const apply = (cached: string) => {
37
+ if (!cached) return;
38
+ if (!options.playable) {
39
+ if (!cancelled) setResolved((prev) => (prev && prev.key === remoteKey && prev.uri === cached ? prev : { key: remoteKey, uri: cached }));
40
+ return;
41
+ }
42
+ playableUri(cached, attachmentRef.current, options.uid ?? OfflineHub.getInstance().currentUid ?? "").then((uri) => {
43
+ if (!cancelled) setResolved((prev) => (prev && prev.key === remoteKey && prev.uri === uri ? prev : { key: remoteKey, uri }));
44
+ });
45
+ };
46
+ apply(cachedNow);
47
+ const subscription = OfflineHub.getInstance().mediaReady$.subscribe((event) => {
48
+ if (!event.localPath || urlKeyOf(event.urlKey) !== remoteKey) return;
49
+ apply(event.localPath.startsWith("/") ? `file://${event.localPath}` : event.localPath);
50
+ });
51
+ return () => {
52
+ cancelled = true;
53
+ subscription.unsubscribe();
54
+ };
55
+ }, [remoteKey, cachedNow, options.playable, options.uid]);
56
+
57
+ return resolved && resolved.key === remoteKey ? resolved.uri : initial;
58
+ }
59
+
60
+ /**
61
+ * Whether this attachment is out of reach right now (`isMediaOutOfReach`), kept current across a
62
+ * reconnect and a finished download. Offline off: always `false`, with no subscription.
63
+ */
64
+ export function useMediaOutOfReach(attachment: any): boolean {
65
+ const [outOfReach, setOutOfReach] = useState(() => isMediaOutOfReach(attachment));
66
+ const remote = attachment?.getUrl?.();
67
+ const remoteKey = urlKeyOf(remote);
68
+ // By URL and cached file, not object identity: a clone of the same media re-subscribes to nothing.
69
+ const attachmentRef = useRef(attachment);
70
+ attachmentRef.current = attachment;
71
+ const cachedNow = shouldUseCachedMedia() ? cachedPathOf(attachment) : "";
72
+ useEffect(() => {
73
+ if (!shouldUseCachedMedia()) return;
74
+ const hub = OfflineHub.getInstance();
75
+ const update = () => setOutOfReach(isMediaOutOfReach(attachmentRef.current));
76
+ update();
77
+ const subscriptions = [
78
+ hub.connected$.subscribe(update),
79
+ hub.disconnected$.subscribe(update),
80
+ hub.mediaReady$.subscribe((event) => {
81
+ if (urlKeyOf(event.urlKey) === remoteKey) setOutOfReach(false);
82
+ }),
83
+ ];
84
+ return () => subscriptions.forEach((s) => s.unsubscribe());
85
+ }, [remoteKey, cachedNow]);
86
+ return outOfReach;
87
+ }
@@ -0,0 +1,25 @@
1
+ /**
2
+ * For a screen that holds a list of its own, outside `CometChatList` and the message list: run
3
+ * `onConnected` each time the SDK's connection comes back (D83 rule 4: a list that shows its error
4
+ * view because the device was offline reloads once by itself on reconnect). Only a screen that
5
+ * opened with offline on listens; with offline off it never runs, so those screens stay today's.
6
+ * Each reconnect reads the gate again, so a kill switch that turned offline off since the screen
7
+ * opened stops the reload (Android `OfflineReconnectRefill.onConnected`).
8
+ *
9
+ * @internal
10
+ */
11
+ import { useEffect, useRef } from "react";
12
+ import { isOfflineOn } from "./gate";
13
+ import { OfflineHub } from "./OfflineHub";
14
+
15
+ export function useOfflineReconnect(onConnected: () => void): void {
16
+ const onConnectedRef = useRef(onConnected);
17
+ onConnectedRef.current = onConnected;
18
+ useEffect(() => {
19
+ if (!isOfflineOn()) return;
20
+ const subscription = OfflineHub.getInstance().connected$.subscribe(() => {
21
+ if (isOfflineOn()) onConnectedRef.current();
22
+ });
23
+ return () => subscription.unsubscribe();
24
+ }, []);
25
+ }
@@ -0,0 +1,22 @@
1
+ /**
2
+ * For a screen that holds rows of its own, outside `CometChatList` and the message list: run
3
+ * `onEnded` when the session ends (logout, user switch, cache reset; UIK-LIFE-01), so nothing of it
4
+ * shows afterwards. Only a screen that opened with offline on reacts: the hub's login listener also
5
+ * hears a logout with offline off, and that screen stays today's.
6
+ *
7
+ * @internal
8
+ */
9
+ import { useEffect, useRef } from "react";
10
+ import { isOfflineOn } from "./gate";
11
+ import { OfflineHub } from "./OfflineHub";
12
+
13
+ export function useOfflineSessionEnded(onEnded: () => void): void {
14
+ const onEndedRef = useRef(onEnded);
15
+ onEndedRef.current = onEnded;
16
+ useEffect(() => {
17
+ const usedOffline = isOfflineOn();
18
+ if (!usedOffline) return;
19
+ const subscription = OfflineHub.getInstance().session$.subscribe(() => onEndedRef.current());
20
+ return () => subscription.unsubscribe();
21
+ }, []);
22
+ }