@cometchat/chat-uikit-react-native 5.4.1 → 5.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (105) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +562 -5
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +28 -1
  4. package/ios/CometChatClipboardModule.m +5 -0
  5. package/ios/CometChatClipboardModule.swift +22 -0
  6. package/ios/RichTextEditorView.swift +636 -31
  7. package/ios/RichTextEditorViewManager.m +3 -0
  8. package/ios/RichTextEditorViewManager.swift +24 -0
  9. package/package.json +5 -2
  10. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +283 -64
  11. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  12. package/src/CometChatConversations/CometChatConversations.tsx +299 -15
  13. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
  14. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
  15. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  16. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
  17. package/src/CometChatMessageList/CometChatMessageList.tsx +572 -16
  18. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  19. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +21 -9
  20. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  21. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +964 -0
  22. package/src/CometChatPinnedMessages/index.ts +5 -0
  23. package/src/CometChatPinnedMessages/style.ts +216 -0
  24. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  25. package/src/CometChatRichTextEditor/index.tsx +31 -1
  26. package/src/CometChatRichTextEditor/types.ts +21 -1
  27. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +871 -0
  28. package/src/CometChatSavedMessages/index.ts +5 -0
  29. package/src/CometChatSavedMessages/style.ts +159 -0
  30. package/src/CometChatSearch/CometChatSearch.tsx +71 -341
  31. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  32. package/src/index.ts +60 -0
  33. package/src/shared/CometChatUiKit/CometChatUIKit.ts +18 -1
  34. package/src/shared/base/Types.ts +5 -0
  35. package/src/shared/constants/UIKitConstants.ts +16 -17
  36. package/src/shared/constants/textPatterns.ts +27 -0
  37. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -225
  38. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  39. package/src/shared/events/ListenerInitializer.ts +20 -1
  40. package/src/shared/events/messages.ts +18 -0
  41. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +123 -25
  42. package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
  43. package/src/shared/formatters/applyRawFormatters.ts +31 -0
  44. package/src/shared/formatters/index.ts +14 -0
  45. package/src/shared/formatters/richTextWireFormat.ts +165 -0
  46. package/src/shared/framework/MessageDataSource.tsx +309 -10
  47. package/src/shared/icons/components/thread-follow.tsx +13 -0
  48. package/src/shared/icons/components/thread-unfollow.tsx +13 -0
  49. package/src/shared/icons/components/unsave.tsx +13 -0
  50. package/src/shared/icons/icon-mapping.tsx +6 -0
  51. package/src/shared/index.ts +37 -0
  52. package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
  53. package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
  54. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
  55. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
  72. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
  73. package/src/shared/utils/MarkdownUtils.ts +57 -6
  74. package/src/shared/utils/MessageUtils.tsx +80 -5
  75. package/src/shared/utils/PinConversationHelper.ts +245 -0
  76. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  77. package/src/shared/utils/PinSaveHelper.ts +549 -0
  78. package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
  79. package/src/shared/utils/SavedMessagesHelper.ts +267 -0
  80. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  81. package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
  82. package/src/shared/utils/cloneRequestBuilder.ts +25 -0
  83. package/src/shared/utils/conversationUtils.ts +8 -1
  84. package/src/shared/utils/stripRichText.ts +7 -0
  85. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +32 -0
  86. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  87. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  88. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
  89. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  90. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +5 -1
  91. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
  92. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  93. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  94. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
  95. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
  96. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  97. package/src/shared/views/CometChatList/Header.tsx +8 -2
  98. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  99. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  100. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  101. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
  102. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
  103. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  104. package/src/theme/default/default.ts +6 -0
  105. package/src/theme/type.ts +4 -0
@@ -0,0 +1,427 @@
1
+ /**
2
+ * Kit-side thread subscription — the feature gate, the toggle both entry points call
3
+ * (thread header §6.2, message action sheet §6.3), and the two local mirrors of the
4
+ * server's auto-subscribe behaviour.
5
+ *
6
+ * ── THE MODEL ─────────────────────────────────────────────────────────────────────────
7
+ *
8
+ * **The message object is the source of truth. There is no kit-side cache.**
9
+ *
10
+ * The SDK used to keep a subscription store, infer changes and emit events. It no longer
11
+ * does any of it: it reports the server's flag on the message (`isThreadSubscribed()`) and
12
+ * offers a local setter (`setThreadSubscribed()`) plus two server calls. The mistake the SDK
13
+ * just removed is not one this file reintroduces — every surface reads the flag off the
14
+ * message object it is holding, and when the kit learns of a change it writes the flag back
15
+ * onto the objects it holds so the next read, including one after a remount, is correct.
16
+ *
17
+ * Surfaces do not share message instances (the list, the thread header's parent and a bubble
18
+ * may each hold a copy), so a write to one is invisible to the others. That is what
19
+ * `ccThreadSubscriptionChanged` is for: whoever changes state publishes, and every surface
20
+ * both re-renders and stamps the objects it holds.
21
+ *
22
+ * ── THE ONE RULE ──────────────────────────────────────────────────────────────────────
23
+ *
24
+ * `threadSubscribed` is only populated on responses to requests that ASKED for it. A
25
+ * socket-delivered message carries no flag and reads `false`.
26
+ *
27
+ * **`false` means "the server did not tell me", NOT "the user is unsubscribed".**
28
+ *
29
+ * The one exception is the logged-in user's OWN message, fetched: the author is subscribed
30
+ * by default, so a `false` there is an explicit unsubscribe and nothing may override it.
31
+ *
32
+ * That rule bites hardest on a thread REPLY arriving over the socket — its own flag is
33
+ * `false` whatever the truth, so its bubble would offer "Subscribe" on a thread the user
34
+ * already follows. `applyIncomingReply` fixes it by stamping each arriving reply from the
35
+ * parent, which is the authority.
36
+ *
37
+ * ── THE FOUR CASES ────────────────────────────────────────────────────────────────────
38
+ *
39
+ * 1. **Manual toggle** — `toggleThreadSubscription`. The only case that writes to the server.
40
+ * 2. **You authored the message** — the server subscribes you outright. Stamped locally by
41
+ * `applySentMessage`, because the SEND RESPONSE omits the flag.
42
+ * 3. **A reply @-mentions you** — `applyIncomingReply`. Mirror only.
43
+ * 4. **You sent a reply** — same rule as 2, same call.
44
+ *
45
+ * Cases 2 and 4 collapsed into one when author-subscribed-by-default shipped (staging,
46
+ * 2026-08-19): any message you send subscribes you to its thread. The old "first reply to
47
+ * your own root" mirror was deleted with it — it was a workaround for the author NOT being
48
+ * subscribed until someone replied, and keeping it would risk reviving a subscription the
49
+ * author had cancelled.
50
+ *
51
+ * ── WHO OWNS WHAT ─────────────────────────────────────────────────────────────────────
52
+ *
53
+ * The API sets `threadSubscribed` on FETCHED messages only (confirmed with the backend team,
54
+ * 2026-08-19). Send responses and realtime frames never carry it. So:
55
+ *
56
+ * fetched message → the flag on the object IS the answer. Read it, never override it.
57
+ * sent message → the kit stamps it (applySentMessage).
58
+ * realtime message → the kit stamps it from the parent (applyIncomingReply).
59
+ *
60
+ * Every mirror below exists to cover the two paths the API deliberately does not populate.
61
+ * None of them is waiting on a backend change.
62
+ *
63
+ * Cases 3 and 4 mirror server-side truths for immediate feedback; they never call
64
+ * `subscribeToThread`. Where a mirror and a later fetched flag disagree, the fetched flag
65
+ * wins — it overwrites the object the surface reads.
66
+ */
67
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
68
+ import { CometChatUIEventHandler } from "../events/CometChatUIEventHandler/CometChatUIEventHandler";
69
+ import { MessageEvents } from "../events/messages";
70
+
71
+ /** ≥400 ms per §7.6, so a double-tap can't fire two writes. */
72
+ const DEBOUNCE_MS = 400;
73
+
74
+ /**
75
+ * A11: there is no plan gate, no feature flag and no capability flag in
76
+ * init/app-settings, so the client cannot feature-detect. This boolean is not a
77
+ * temporary scaffold — it is the only control that will ever exist.
78
+ *
79
+ * Default OFF: the integrator opts in. Gate off means NEITHER surface renders,
80
+ * whatever the two per-component visibility flags say.
81
+ */
82
+ export class ThreadSubscriptionConfig {
83
+ /**
84
+ * ON by default, to match the React UI Kit.
85
+ *
86
+ * React has no equivalent switch at all: it ships `hideThreadSubscriptionOption` (default
87
+ * false) on the message list and a matching toggle prop on the thread header, so the feature
88
+ * is visible unless an integrator opts OUT. RN carried an extra global gate defaulting to
89
+ * false on top of those same two props, which meant the identical integration code showed the
90
+ * control on web and nothing on mobile — and the only way to find out was to read the source.
91
+ *
92
+ * The per-instance props remain the real control surface and are ANDed with this, so anyone
93
+ * already calling setEnabled(false) keeps that behaviour.
94
+ */
95
+ private static enabled: boolean = true;
96
+
97
+ public static setEnabled(enabled: boolean): void {
98
+ ThreadSubscriptionConfig.enabled = !!enabled;
99
+ }
100
+
101
+ public static isEnabled(): boolean {
102
+ return ThreadSubscriptionConfig.enabled;
103
+ }
104
+ }
105
+
106
+ /**
107
+ * One in-flight write per parentMessageId, and the last tap time for the debounce.
108
+ *
109
+ * This is NOT subscription state — it is request bookkeeping, and it is deliberately the
110
+ * only module-level map left in this file.
111
+ */
112
+ const inFlight: { [messageId: string]: boolean } = {};
113
+ const lastToggleAt: { [messageId: string]: number } = {};
114
+
115
+ /**
116
+ * The id of the thread a message belongs to — a reply carries its parent's id, a root
117
+ * message IS the thread.
118
+ *
119
+ * Used for exactly two things: the id sent to the server, and matching a
120
+ * `ccThreadSubscriptionChanged` event so one follow flips every bubble in the thread. It is
121
+ * NEVER used to decide which object to read state from — every message carries its own flag
122
+ * and each surface reads its own (§5.7).
123
+ */
124
+ export function getThreadIdFor(message: CometChat.BaseMessage): number {
125
+ const parentId = Number(message?.getParentMessageId?.() ?? 0);
126
+ return parentId > 0 ? parentId : Number(message?.getId?.() ?? 0);
127
+ }
128
+
129
+ /**
130
+ * Does the user follow this message's thread?
131
+ *
132
+ * Reads the message and nothing else. The server stamps `threadSubscribed` on EVERY fetched
133
+ * message in a thread — parent and replies alike — so a fetched reply answers correctly off
134
+ * its own object, exactly like its parent does.
135
+ */
136
+ export function isThreadSubscribed(message: CometChat.BaseMessage): boolean {
137
+ try {
138
+ return message?.isThreadSubscribed?.() === true;
139
+ } catch {
140
+ // A message model older than the accessor renders un-followed rather than throwing;
141
+ // this runs during render, where a throw is a blank screen.
142
+ return false;
143
+ }
144
+ }
145
+
146
+ /**
147
+ * Write the flag onto a message object the caller is holding. Local only — this is the
148
+ * SDK's `setThreadSubscribed`, which never touches the network.
149
+ *
150
+ * Every surface calls this from its `ccThreadSubscriptionChanged` handler, so the objects it
151
+ * holds stay coherent with what it just rendered.
152
+ */
153
+ export function stampThreadSubscribed(
154
+ message: CometChat.BaseMessage | null | undefined,
155
+ subscribed: boolean
156
+ ): void {
157
+ try {
158
+ (message as any)?.setThreadSubscribed?.(subscribed === true);
159
+ } catch {
160
+ // Older model, or a plain object from a path that skipped the parser. Nothing to sync.
161
+ }
162
+ }
163
+
164
+ /** Emitted on the optimistic flip, on the server's answer, and on a revert. */
165
+ function emitChanged(parentMessageId: number, subscribed: boolean, inProgress: boolean): void {
166
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccThreadSubscriptionChanged, {
167
+ parentMessageId: Number(parentMessageId),
168
+ subscribed,
169
+ inProgress,
170
+ });
171
+ }
172
+
173
+ /**
174
+ * Stamp the message the caller is holding and tell every other surface, in one place so the
175
+ * two cannot drift. Mirrors only ever raise to `true` (§ the one rule): a socket frame's
176
+ * silence is not a negative answer, so nothing here may clear a known `true`.
177
+ */
178
+ function mirrorSubscribed(parentMessageId: number, message?: CometChat.BaseMessage): void {
179
+ if (!parentMessageId) return;
180
+ stampThreadSubscribed(message, true);
181
+ emitChanged(parentMessageId, true, false);
182
+ }
183
+
184
+ /**
185
+ * Flips the subscription for a thread. Case 1 — the only path that writes to the server.
186
+ *
187
+ * Resolves with the state that ended up applying — the caller does not need to revert
188
+ * anything itself, but SHOULD show the `thread_subscription_failed` snackbar when this
189
+ * rejects. There is no queue and no retry (§7.6): a Follow tapped offline fails visibly
190
+ * and reverts. Both server calls are idempotent, so a duplicate never errors.
191
+ *
192
+ * @returns {Promise<boolean>} true if the user is now following the thread
193
+ */
194
+ export function toggleThreadSubscription(message: CometChat.BaseMessage): Promise<boolean> {
195
+ const threadId = getThreadIdFor(message);
196
+ const key = String(threadId);
197
+ const now = Date.now();
198
+
199
+ // Debounce and in-flight guard. Both resolve with the CURRENT state rather than
200
+ // rejecting: the tap was ignored, nothing failed.
201
+ if (inFlight[key] || (lastToggleAt[key] && now - lastToggleAt[key] < DEBOUNCE_MS)) {
202
+ return Promise.resolve(isThreadSubscribed(message));
203
+ }
204
+ lastToggleAt[key] = now;
205
+ inFlight[key] = true;
206
+
207
+ const wasSubscribed = isThreadSubscribed(message);
208
+ const optimistic = !wasSubscribed;
209
+
210
+ // Flip the UI first, and stamp the object we were handed with it — there is no cache
211
+ // behind this, so the message IS what the surfaces read.
212
+ stampThreadSubscribed(message, optimistic);
213
+ emitChanged(threadId, optimistic, true);
214
+
215
+ const write = optimistic
216
+ ? CometChat.subscribeToThread(threadId)
217
+ : CometChat.unsubscribeFromThread(threadId);
218
+
219
+ return write.then(
220
+ () => {
221
+ inFlight[key] = false;
222
+ // The resolved call IS the acknowledgement; no event follows it.
223
+ emitChanged(threadId, optimistic, false);
224
+ return optimistic;
225
+ },
226
+ (error: any) => {
227
+ inFlight[key] = false;
228
+ stampThreadSubscribed(message, wasSubscribed);
229
+ emitChanged(threadId, wasSubscribed, false);
230
+ throw error;
231
+ }
232
+ );
233
+ }
234
+
235
+ /**
236
+ * Cases 2 and 4 — you sent a message, so the server subscribed you to its thread.
237
+ *
238
+ * ONE rule covers both now: **any message you send subscribes you to the thread it belongs
239
+ * to** — the parent's, if it is a reply; its own, if it is a root message that may grow one.
240
+ * That is exactly the server's behaviour since the author-subscribed-by-default change
241
+ * (verified on staging 2026-08-19: a fetched message with zero replies reads `true` for its
242
+ * sender, in groups and 1-1 alike, and `false` for everybody else).
243
+ *
244
+ * ⚠️ THIS IS PERMANENT, not a workaround. The API populates `threadSubscribed` on FETCHED
245
+ * messages only — confirmed with the backend team (Siva, 2026-08-19) and measured the same
246
+ * day: neither the plain nor the threaded send response carries it, and neither does a
247
+ * realtime frame. That is the agreed division of responsibility, so covering the send and
248
+ * socket paths is the UI Kit's job and always will be.
249
+ *
250
+ * Do not delete this on the reasoning that "the server subscribes the author now". It does —
251
+ * but it only SAYS so on a fetch, and the sender's own screen is holding a send response.
252
+ *
253
+ * Your own sends never arrive on a listener, so this is the only place the kit learns of them.
254
+ */
255
+ export function applySentMessage(sent: CometChat.BaseMessage): void {
256
+ try {
257
+ const threadId = getThreadIdFor(sent);
258
+ if (threadId > 0) mirrorSubscribed(threadId, sent);
259
+ } catch {
260
+ // A malformed send response must not take the send path down.
261
+ }
262
+ }
263
+
264
+ /**
265
+ * Cases 2b and 4b — a message YOU sent, arriving from ANOTHER of your devices.
266
+ *
267
+ * Sending subscribes you to the thread, wherever you sent it from. But the copy that reaches
268
+ * your other devices comes over the socket, and a socket frame carries no `threadSubscribed`
269
+ * — so without this the message you just wrote on your phone shows "Subscribe to thread" on
270
+ * your tablet until something refetches it.
271
+ *
272
+ * Applies to ROOT messages as much as replies: authoring subscribes you to the thread the
273
+ * message may later grow, so the root case is not a no-op (that was the gap — the incoming
274
+ * path only ever looked at replies, and a root message has no parentMessageId to notice).
275
+ *
276
+ * Deliberately the same call as a local send: "I sent this" is one rule, and where the bytes
277
+ * came from does not change it.
278
+ *
279
+ * @returns true when it handled the message, so the caller can skip the incoming-reply rules
280
+ */
281
+ export function applyOwnIncomingMessage(
282
+ message: CometChat.BaseMessage,
283
+ loggedInUid: string | null
284
+ ): boolean {
285
+ try {
286
+ if (!loggedInUid) return false;
287
+ if (message?.getSender?.()?.getUid?.() !== loggedInUid) return false;
288
+ applySentMessage(message);
289
+ return true;
290
+ } catch {
291
+ return false;
292
+ }
293
+ }
294
+
295
+ /**
296
+ * Case 5 — a message was EDITED to mention you, so the server subscribed you to its thread.
297
+ *
298
+ * Covers all three shapes the edit can take, because it only ever asks the one question the
299
+ * server asks — does the message, as it now stands, mention me:
300
+ *
301
+ * 5a you edit your own message to mention yourself
302
+ * 5b somebody else edits theirs to mention you
303
+ * 5c an edit that PRESERVES an existing mention while changing other text — the mention
304
+ * still stands afterwards, so the subscription still applies. Nothing here compares
305
+ * against the previous version, which is exactly why this case falls out for free.
306
+ *
307
+ * Subscribes to the thread the edited message BELONGS to — its parent's if it is a reply, its
308
+ * own if it is a root — via the same getThreadIdFor() every other path uses.
309
+ *
310
+ * ⚠️ Call this from the EDIT listeners, never from the shared list-replace helper: deletes and
311
+ * reaction updates travel through that same helper, and neither should subscribe anybody.
312
+ */
313
+ export function applyEditedMessage(
314
+ edited: CometChat.BaseMessage,
315
+ loggedInUid: string | null
316
+ ): void {
317
+ try {
318
+ if (!loggedInUid) return;
319
+ if ((edited as any)?.getDeletedAt?.()) return;
320
+ const mentioned = edited?.getMentionedUsers?.() ?? [];
321
+ if (!Array.isArray(mentioned)) return;
322
+ if (!mentioned.some((user: any) => user?.getUid?.() === loggedInUid)) return;
323
+ const threadId = getThreadIdFor(edited);
324
+ if (threadId > 0) mirrorSubscribed(threadId, edited);
325
+ } catch {
326
+ // Mirroring is a nicety; the next fetch corrects it regardless.
327
+ }
328
+ }
329
+
330
+ /**
331
+ * Case 3, plus the socket-`false` correction — an incoming reply from somebody else.
332
+ *
333
+ * ONE server behaviour is mirrored: **you were @mentioned** in the reply, so the server
334
+ * subscribed you.
335
+ *
336
+ * The old "you wrote the parent and this is the FIRST reply" rule is GONE. It existed only
337
+ * because the author was not subscribed until someone replied; since the
338
+ * author-subscribed-by-default change (staging, 2026-08-19) authoring subscribes you
339
+ * outright, applySentMessage stamps that locally at send time, and any refetch confirms it.
340
+ * Re-deriving it from a reply would now be strictly worse — it could resurrect a
341
+ * subscription the author had deliberately cancelled in between.
342
+ *
343
+ * Every OTHER reply changes nothing about the subscription — but it still arrives with
344
+ * `threadSubscribed: false` because it came off the socket, and rendering that verbatim
345
+ * would offer "Subscribe" inside a thread the user already follows. So it inherits the
346
+ * parent's current state. This is why the parent must be held as a whole message and not
347
+ * just an id: an id cannot answer "is this thread followed right now".
348
+ *
349
+ * Nothing here ever writes `false`. A socket frame carries no flag and its silence is not a
350
+ * negative answer.
351
+ *
352
+ * @param reply the incoming reply, from the message listener
353
+ * @param parentMessage the reply's parent, as the consumer has it rendered — pass null if it
354
+ * is not on screen, in which case only the mention rule can fire
355
+ * @param loggedInUid the logged-in user's uid
356
+ */
357
+ export function applyIncomingReply(
358
+ reply: CometChat.BaseMessage,
359
+ parentMessage: CometChat.BaseMessage | null,
360
+ loggedInUid: string | null
361
+ ): void {
362
+ try {
363
+ const parentId = Number(reply?.getParentMessageId?.() ?? 0);
364
+ if (!parentId) return;
365
+
366
+ // Case 3 — mentioned. Stamp both, tell everyone, and MAKE IT STICK.
367
+ const mentioned = reply?.getMentionedUsers?.() ?? [];
368
+ if (
369
+ loggedInUid &&
370
+ Array.isArray(mentioned) &&
371
+ mentioned.some((user: any) => user?.getUid?.() === loggedInUid)
372
+ ) {
373
+ // Read the state BEFORE the mirror below overwrites it — this is what decides whether
374
+ // the server still needs telling.
375
+ const wasSubscribed = parentMessage ? isThreadSubscribed(parentMessage) : false;
376
+
377
+ stampThreadSubscribed(reply, true);
378
+ mirrorSubscribed(parentId, parentMessage ?? undefined);
379
+
380
+ // ENG-38880 — the stamp above is LOCAL. The server does not subscribe you when you are
381
+ // mentioned, so it was the only thing holding the flip, and any refetch replaced it
382
+ // with the server's `false`. The user hit that on the worst possible path: the mention
383
+ // sends them a push, they open the app FROM it, the list loads from a fetch, and the
384
+ // thread they were just pulled into reads "Subscribe to thread".
385
+ //
386
+ // So write it through instead of pretending. The rule — a mention subscribes you — is
387
+ // the product's, stated in the kit's own copy ("Notifications are off until you reply
388
+ // or are mentioned"); this makes the server agree with it.
389
+ //
390
+ // Skipped when the thread is already followed, so an active thread does not fire a
391
+ // write per mention. The call is idempotent, so the fallback when the parent is not on
392
+ // screen (and `wasSubscribed` is unknowable) is simply to send it.
393
+ if (!wasSubscribed) {
394
+ try {
395
+ const write = CometChat.subscribeToThread(parentId);
396
+ // Fire and forget: this is a correction, not the user's action. A failure leaves the
397
+ // optimistic flip in place and the next fetch settles it — the pre-existing
398
+ // behaviour, so failing here is never worse than not having tried.
399
+ if (write && typeof (write as any).catch === "function") {
400
+ (write as any).catch(() => {});
401
+ }
402
+ } catch {
403
+ // An SDK build without the method must not take the message listener down.
404
+ }
405
+ }
406
+ return;
407
+ }
408
+
409
+ if (!parentMessage) return;
410
+
411
+ // Everything else: correct the socket `false` from the authority, without publishing —
412
+ // nothing about the subscription changed, only this object's knowledge of it.
413
+ stampThreadSubscribed(reply, isThreadSubscribed(parentMessage));
414
+ } catch {
415
+ // Mirroring is a nicety; the next fetch corrects it regardless.
416
+ }
417
+ }
418
+
419
+ /**
420
+ * Only for tests — the in-flight/debounce guards are process-wide by design (one user, one
421
+ * session), which otherwise leaks state between test cases.
422
+ * @internal
423
+ */
424
+ export function resetThreadSubscriptionGuards(): void {
425
+ Object.keys(inFlight).forEach((key) => delete inFlight[key]);
426
+ Object.keys(lastToggleAt).forEach((key) => delete lastToggleAt[key]);
427
+ }
@@ -0,0 +1,37 @@
1
+ /**
2
+ * The SDK stub both request-builder helpers test against.
3
+ *
4
+ * build() MUTATES, like the real SDK 4.1.0 — it folds `category` into `categories`.
5
+ * That line is the point of the stub: a kinder mock let a shallow clone through,
6
+ * because the copy shared the caller's array and the push landed on THEIR builder.
7
+ */
8
+ export const messagesRequestBuilderMock = () => ({
9
+ CometChat: {
10
+ MessagesRequestBuilder: class {
11
+ limit?: number;
12
+ savedOnly?: boolean;
13
+ pinnedOnly?: boolean;
14
+ uid?: string;
15
+ guid?: string;
16
+ category?: string;
17
+ categories?: string[];
18
+ setLimit(l: number) { this.limit = l; return this; }
19
+ setSavedOnly(v: boolean) { this.savedOnly = v; return this; }
20
+ setPinnedOnly(v: boolean) { this.pinnedOnly = v; return this; }
21
+ setUID(u: string) { this.uid = u; return this; }
22
+ setGUID(g: string) { this.guid = g; return this; }
23
+ setCategory(c: string) { this.category = c; return this; }
24
+ setCategories(c: string[]) { this.categories = c; return this; }
25
+ build() {
26
+ if (this.category && this.categories) this.categories.push(this.category);
27
+ return {
28
+ __limit: this.limit,
29
+ __savedOnly: this.savedOnly,
30
+ __pinnedOnly: this.pinnedOnly,
31
+ __uid: this.uid,
32
+ __guid: this.guid,
33
+ };
34
+ }
35
+ },
36
+ },
37
+ });
@@ -0,0 +1,25 @@
1
+ import { CometChat } from "@cometchat/chat-sdk-react-native";
2
+
3
+ /**
4
+ * A copy of an integrator's request builder, so a panel can assert its own invariants
5
+ * without writing to the caller's object. See PinnedMessagesHelper for why that matters.
6
+ *
7
+ * Prototype-preserving, so the copy keeps its methods — `{ ...builder }` would not.
8
+ *
9
+ * Arrays are re-pointed, not shared. Every SETTER replaces its array, so sharing looks
10
+ * safe — but `build()` is not a setter and it mutates: SDK 4.1.0 runs
11
+ * `this.categories.push(this.category)` and the same for types. A shallow copy therefore
12
+ * grows the CALLER's array once per build.
13
+ *
14
+ * Dependency-free on purpose: CommonUtils.clone drags the constants barrel (and its
15
+ * CometChat.CALL_STATUS read) into a leaf helper and breaks every narrow SDK mock.
16
+ */
17
+ export const cloneRequestBuilder = (
18
+ builder: CometChat.MessagesRequestBuilder
19
+ ): CometChat.MessagesRequestBuilder => {
20
+ const copy = Object.assign(Object.create(Object.getPrototypeOf(builder)), builder);
21
+ for (const [key, value] of Object.entries(copy)) {
22
+ if (Array.isArray(value)) (copy as unknown as Record<string, unknown>)[key] = [...value];
23
+ }
24
+ return copy;
25
+ };
@@ -7,6 +7,7 @@ import { CometChatUIKit } from "../CometChatUiKit";
7
7
  import { CometChatTheme } from "../../theme/type";
8
8
  import { JSX } from "react";
9
9
  import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/LocalizationManager";
10
+ import { stripMarkdown } from "./MarkdownUtils";
10
11
 
11
12
  const t = getCometChatTranslation();
12
13
 
@@ -28,7 +29,13 @@ export function attachmentCountLabel(type: string, count: number): string {
28
29
  // (Multi-attachment messages are summarized upstream in getLastConversationMessage.)
29
30
  function captionSuffix(message: CometChat.BaseMessage): string {
30
31
  const raw = typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "";
31
- const caption = typeof raw === "string" ? raw.trim() : "";
32
+ // Strip the wire markup. A caption is serialized exactly like a text message, so it can carry
33
+ // `<color=#rrggbb>`, `**bold**`, backticks — and every branch that calls this returns a JSX
34
+ // element, so the conversation list's own stripMarkdown pass (string subtitles only) never runs
35
+ // on it. Without this a single photo captioned in red reads "Photo · <color=#e11d48>hi</color>"
36
+ // in the list. Same defect ENG-38258 reported for a multi-attachment batch; that fix landed in
37
+ // MessageDataSource.getLastConversationMessage and did not cover the single-attachment path.
38
+ const caption = typeof raw === "string" ? stripMarkdown(raw.trim()).trim() : "";
32
39
  return caption ? ` · ${caption}` : "";
33
40
  }
34
41
 
@@ -6,10 +6,17 @@
6
6
  * Only a whitelist of known formatting tags is removed, so legitimate text such
7
7
  * as "make a <product>" or "5 < 10" is preserved.
8
8
  */
9
+ import { stripColorTags } from "../formatters/richTextWireFormat";
10
+
9
11
  export const stripRichText = (input?: string | null): string => {
10
12
  if (!input) return "";
11
13
  let text = input;
12
14
 
15
+ // 0. Remove the rich-text wire format's colour tokens. These are NOT HTML, so the
16
+ // whitelist in step 1 does not (and must not) match them — `<color=#ff0000>` would
17
+ // otherwise reach users verbatim in plain-text previews.
18
+ text = stripColorTags(text);
19
+
13
20
  // 1. Remove the HTML formatting tags the compact composer can emit — bold, italic,
14
21
  // underline, strikethrough, link, ordered/unordered lists, blockquote, inline code
15
22
  // and code-block, plus the structural wrappers these produce. Whitelisted (not a
@@ -1,5 +1,9 @@
1
+ import Clipboard from '@react-native-clipboard/clipboard';
1
2
  import NativeCometChatClipboardModule from './NativeCometChatClipboardModule';
2
3
  import type { ClipboardImageResult } from './NativeCometChatClipboardModule';
4
+ import { stripMarkdown } from '../../utils/MarkdownUtils';
5
+ import { applyRawFormatters } from '../../formatters/applyRawFormatters';
6
+ import type { CometChatTextFormatter } from '../../formatters/CometChatTextFormatter';
3
7
 
4
8
  export type { ClipboardImageResult };
5
9
 
@@ -25,4 +29,32 @@ export const ClipboardPasteHandler = {
25
29
  return null;
26
30
  }
27
31
  },
32
+
33
+ /**
34
+ * Copies message text, preserving inline colour for a paste back into our own composer.
35
+ *
36
+ * Every app gets the plain text with the wire format stripped; only our editor reads the
37
+ * private representation, so `<color=…>` markup can never leak into Notes, mail or another
38
+ * chat app. Falls back to a plain copy when the native module is unavailable — the text
39
+ * still lands on the clipboard, just without colour.
40
+ */
41
+ copyMessageText(raw: string, textFormatters?: Array<CometChatTextFormatter>): void {
42
+ // A consumer's own wire token is rewritten into UI Kit markup first. Without this the strip below
43
+ // does not recognise it, so the token leaks verbatim into Notes or another chat app, and pasting
44
+ // back into our own composer brings it in as literal text instead of styled text.
45
+ const wire = applyRawFormatters(raw, textFormatters);
46
+ // stripMarkdown, not stripColorTags: colour was the only case anyone checked, so `<u>`, `<b>`,
47
+ // `<i>`, `<s>` and every markdown marker went to Notes and mail verbatim — QA saw
48
+ // `<u>fbebf</u>` pasted from a message that read "fbebf" on screen. stripMarkdown removes HTML
49
+ // tags and markdown AND colour, and unlike stripRichText it keeps line breaks, which a copied
50
+ // multi-line message must retain.
51
+ const plain = stripMarkdown(wire);
52
+ if (!NativeCometChatClipboardModule?.setRichText) {
53
+ Clipboard.setString(plain);
54
+ return;
55
+ }
56
+ NativeCometChatClipboardModule.setRichText(plain, wire).catch(() => {
57
+ Clipboard.setString(plain);
58
+ });
59
+ },
28
60
  };
@@ -10,6 +10,12 @@ export interface ClipboardImageResult {
10
10
  interface NativeCometChatClipboardModuleSpec {
11
11
  hasImageInClipboard(): Promise<boolean>;
12
12
  getClipboardImage(): Promise<ClipboardImageResult | null>;
13
+ /**
14
+ * Copies `plain` to the system clipboard for every app, and `wire` under a private
15
+ * representation only our composer reads back — so inline colour survives a copy/paste
16
+ * inside CometChat without leaking `<color=…>` markup to anywhere else.
17
+ */
18
+ setRichText(plain: string, wire: string): Promise<boolean>;
13
19
  }
14
20
 
15
21
  const { CometChatClipboardModule } = NativeModules;
@@ -90,6 +90,10 @@ export const CometChatActionSheet = (props: CometChatActionSheetInterface) => {
90
90
  return (
91
91
  <FlatList
92
92
  key={"list"}
93
+ // The option list scrolls when there are more options than fit — Delete in particular
94
+ // sits below the fold on a long sheet. Without an id there is nothing for a test (or an
95
+ // integrator's own automation) to scroll, so the option exists but can never be tapped.
96
+ testID='ActionSheet.list'
93
97
  keyExtractor={(item) => item.id}
94
98
  data={actionList}
95
99
  numColumns={1}
@@ -24,6 +24,7 @@ import { useCompTheme } from '../../../theme/hook';
24
24
  import { CometChatCaptionText } from '../CometChatCaptionText';
25
25
  import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
26
26
  import { ATTACHMENT_COLLAPSED_LIMIT } from '../../constants/UIKitConstants';
27
+ import { AdditionalParams } from "../../base/Types";
27
28
 
28
29
  const { SoundPlayer, FileManager } = NativeModules;
29
30
  const soundEvents = new NativeEventEmitter(SoundPlayer);
@@ -440,6 +441,8 @@ export interface CometChatAudiosBubbleProps {
440
441
  message: CometChat.MediaMessage;
441
442
  theme: CometChatTheme;
442
443
  style?: CometChatTheme["audiosBubbleStyles"];
444
+ /** Render-time params from the message list — carries the consumer's `textFormatters`. */
445
+ additionalParams?: AdditionalParams;
443
446
  }
444
447
 
445
448
  /**
@@ -451,6 +454,7 @@ export function CometChatAudiosBubble({
451
454
  message,
452
455
  theme,
453
456
  style,
457
+ additionalParams,
454
458
  }: CometChatAudiosBubbleProps) {
455
459
  const compTheme = useCompTheme();
456
460
  const s = deepMerge(
@@ -569,6 +573,7 @@ export function CometChatAudiosBubble({
569
573
  {Boolean(caption) && (
570
574
  <CometChatCaptionText
571
575
  message={message}
576
+ additionalParams={additionalParams}
572
577
  caption={caption}
573
578
  theme={theme}
574
579
  containerStyle={{
@@ -54,11 +54,23 @@ export const CometChatAvatar = (props: CometChatAvatarProps) => {
54
54
  const initials = [...(name || "")].slice(0, 2).join("").toUpperCase();
55
55
 
56
56
  return (
57
- <Text
58
- style={[avatarStyle.textStyle]}
59
- adjustsFontSizeToFit={true}
60
- numberOfLines={1}
61
- >
57
+ // NO adjustsFontSizeToFit (ENG-38886).
58
+ //
59
+ // On iOS that prop shrinks the text to fit the Text's frame — and on the FIRST row a list
60
+ // renders, the frame is not known yet. iOS shrinks to its minimum against that unknown,
61
+ // never recomputes, and the initials end up a few pixels tall in the corner of the circle
62
+ // while every later row in the same list is perfect. Measured 2026-09-04: identical
63
+ // resolved style (20px font, 48px circle) on every row, only the first one broken.
64
+ //
65
+ // It was never earning its keep. Initials are at most two characters and the theme sizes
66
+ // them for its own circle, so there is nothing to shrink in the normal case; it only ever
67
+ // fired when a consumer shrank the container WITHOUT bringing the font down with it. That
68
+ // is a styling mistake and it should look like one, rather than being silently papered
69
+ // over on Android and mangled on iOS — see CometChatPinnedMessages/style.ts, which sizes
70
+ // its own text for its 32px avatar.
71
+ //
72
+ // numberOfLines stays: it keeps a stray long value on one line instead of wrapping.
73
+ <Text style={[avatarStyle.textStyle]} numberOfLines={1}>
62
74
  {initials}
63
75
  </Text>
64
76
  );