@cometchat/chat-uikit-react-native 5.4.1 → 5.5.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 (80) hide show
  1. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  2. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  3. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  4. package/android/.gradle/7.4/gc.properties +0 -0
  5. package/android/.gradle/vcs-1/gc.properties +0 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  7. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +542 -5
  8. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
  9. package/ios/CometChatClipboardModule.m +5 -0
  10. package/ios/CometChatClipboardModule.swift +22 -0
  11. package/ios/RichTextEditorView.swift +593 -31
  12. package/ios/RichTextEditorViewManager.m +2 -0
  13. package/ios/RichTextEditorViewManager.swift +16 -0
  14. package/package.json +1 -1
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
  16. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  17. package/src/CometChatConversations/CometChatConversations.tsx +291 -14
  18. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  19. package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
  20. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
  21. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  22. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
  23. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  24. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
  25. package/src/CometChatPinnedMessages/index.ts +5 -0
  26. package/src/CometChatPinnedMessages/style.ts +216 -0
  27. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  28. package/src/CometChatRichTextEditor/index.tsx +27 -1
  29. package/src/CometChatRichTextEditor/types.ts +19 -1
  30. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
  31. package/src/CometChatSavedMessages/index.ts +5 -0
  32. package/src/CometChatSavedMessages/style.ts +159 -0
  33. package/src/CometChatSearch/CometChatSearch.tsx +47 -340
  34. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  35. package/src/index.ts +60 -0
  36. package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
  37. package/src/shared/base/Types.ts +5 -0
  38. package/src/shared/constants/UIKitConstants.ts +13 -0
  39. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
  40. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  41. package/src/shared/events/ListenerInitializer.ts +20 -1
  42. package/src/shared/events/messages.ts +18 -0
  43. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +92 -6
  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 +296 -3
  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/resources/en/translation.json +54 -0
  53. package/src/shared/utils/MarkdownUtils.ts +25 -4
  54. package/src/shared/utils/MessageUtils.tsx +80 -5
  55. package/src/shared/utils/PinConversationHelper.ts +245 -0
  56. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  57. package/src/shared/utils/PinSaveHelper.ts +549 -0
  58. package/src/shared/utils/SavedMessagesHelper.ts +231 -0
  59. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  60. package/src/shared/utils/conversationUtils.ts +8 -1
  61. package/src/shared/utils/stripRichText.ts +7 -0
  62. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
  63. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  64. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  65. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  66. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +1 -0
  67. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  68. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  69. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  70. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  71. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  72. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  73. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  74. package/src/theme/default/default.ts +6 -0
  75. package/src/theme/type.ts +4 -0
  76. package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
  77. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
  78. package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +0 -313
  79. package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +0 -76
  80. package/src/shared/CometChatUiKit/checkAuthSettings-review.md +0 -211
package/src/index.ts CHANGED
@@ -87,10 +87,36 @@ import {
87
87
  UseAudioRecorderReturn,
88
88
  WaveformStyle,
89
89
  messageStatus,
90
+ ThreadSubscriptionConfig,
91
+ applyIncomingReply,
92
+ applyEditedMessage,
93
+ applySentMessage,
94
+ applyOwnIncomingMessage,
95
+ isThreadSubscribed,
96
+ stampThreadSubscribed,
97
+ toggleThreadSubscription,
90
98
  Icon,
91
99
  MenuItemInterface,
92
100
  getCometChatTranslation,
93
101
  getCurrentLanguage,
102
+ // Pin & Save. PinSaveConfig is the opt-in gate — without it on the PUBLIC
103
+ // barrel the feature cannot be switched on by an integrator at all.
104
+ //
105
+ // The three SERVER-owned flags behind it are resolved by the kit itself, at login and on
106
+ // every reconnect (see PinSaveFeatureGates). These are exported so an integrator can read
107
+ // the resolved state or force a re-read after flipping a flag in the dashboard.
108
+ PinSaveConfig,
109
+ PinConversationConfig,
110
+ resolvePinSaveFeatures,
111
+ refreshPinSaveFeatures,
112
+ getPinSaveFeatures,
113
+ resetPinSaveFeatures,
114
+ isConversationPinned,
115
+ isSystemPinnedConversation,
116
+ isPinned,
117
+ isSaved,
118
+ isSystemPin,
119
+ SYSTEM_PINNER,
94
120
  } from "./shared";
95
121
 
96
122
  import { stopStreamingForRunId, startStreamingForRunId, streamingState$, getStreamSpeed, setAIAssistantTools, setQueueCompletionCallback, removeQueueCompletionCallback, IStreamData,QueueCompletionCallback,checkAndTriggerQueueCompletion, getAIAssistantTools, handleWebsocketMessage, messageStream, notifyStreamRenderComplete, onConnected, onConnectionError, onDisconnected, setStreamSpeed, storeAIAssistantMessage, streamConnection$ } from "./shared/services/stream-message.service";
@@ -122,6 +148,14 @@ import {
122
148
  CometChatMessageInformation,
123
149
  CometChatMessageInformationInterface,
124
150
  } from "./CometChatMessageInformation";
151
+ import {
152
+ CometChatSavedMessages,
153
+ CometChatSavedMessagesInterface,
154
+ } from "./CometChatSavedMessages";
155
+ import {
156
+ CometChatPinnedMessages,
157
+ CometChatPinnedMessagesInterface,
158
+ } from "./CometChatPinnedMessages";
125
159
 
126
160
  import {
127
161
  CometChatMessageList,
@@ -138,6 +172,7 @@ import {
138
172
  CometChatCompactMessageComposer,
139
173
  CometChatCompactMessageComposerInterface,
140
174
  SingleLineMessageComposerStyleInterface,
175
+ ComposerInputHandle,
141
176
  } from "./CometChatCompactMessageComposer";
142
177
 
143
178
  import { CometChatAIAssistantChatHistory } from "./CometChatAIAssistantChatHistory";
@@ -252,6 +287,8 @@ export {
252
287
  CometChatMessageComposer,
253
288
  CometChatCompactMessageComposer,
254
289
  CometChatMessageInformation,
290
+ CometChatSavedMessages,
291
+ CometChatPinnedMessages,
255
292
  CometChatMessageList,
256
293
  CometChatMessagePreview,
257
294
  CometChatMessageTemplate,
@@ -297,9 +334,28 @@ export {
297
334
  ThumbnailGenerationExtension,
298
335
  UIKitSettings,
299
336
  messageStatus,
337
+ ThreadSubscriptionConfig,
338
+ applyIncomingReply,
339
+ applySentMessage,
340
+ isThreadSubscribed,
341
+ stampThreadSubscribed,
342
+ toggleThreadSubscription,
300
343
  Icon,
301
344
  getCometChatTranslation,
302
345
  getCurrentLanguage,
346
+ // Pin & Save — the opt-in gate plus the read helpers for custom bubbles.
347
+ PinSaveConfig,
348
+ PinConversationConfig,
349
+ resolvePinSaveFeatures,
350
+ refreshPinSaveFeatures,
351
+ getPinSaveFeatures,
352
+ resetPinSaveFeatures,
353
+ isConversationPinned,
354
+ isSystemPinnedConversation,
355
+ isPinned,
356
+ isSaved,
357
+ isSystemPin,
358
+ SYSTEM_PINNER,
303
359
  CometChatAIAssistantTools,
304
360
  type CometChatConversationStarterProps,
305
361
  type CometChatSmartRepliesProps,
@@ -375,12 +431,15 @@ export type {
375
431
  CometChatListItemInterface,
376
432
  CometChatListStylesInterface,
377
433
  CometChatMessageInformationInterface,
434
+ CometChatSavedMessagesInterface,
435
+ CometChatPinnedMessagesInterface,
378
436
  CometChatMessageInputInterface,
379
437
  CometChatMessageListActionsInterface,
380
438
  CometChatMessageListInterface,
381
439
  CometChatMessageComposerInterface,
382
440
  CometChatCompactMessageComposerInterface,
383
441
  SingleLineMessageComposerStyleInterface,
442
+ ComposerInputHandle,
384
443
  CometChatMessageOption,
385
444
  ActionItemInterface,
386
445
  AdditionalParams,
@@ -440,5 +499,6 @@ export type {
440
499
  EditorVariant,
441
500
  ToolbarOption,
442
501
  SelectionChangeEvent,
502
+ InlineStyleKey,
443
503
  RichTextEditorRef as RichTextEditorRefType,
444
504
  } from './CometChatRichTextEditor/types';
@@ -1,4 +1,9 @@
1
1
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
+ import {
3
+ refreshPinSaveFeatures,
4
+ resetPinSaveFeatures,
5
+ resolvePinSaveFeatures,
6
+ } from "../utils/PinSaveFeatureGates";
2
7
  import { Platform } from "react-native";
3
8
  import { CallingExtension } from "../../calls/CallingExtension";
4
9
  import { CallingPackage } from "../../calls/CallingPackage";
@@ -172,9 +177,17 @@ export class CometChatUIKit {
172
177
  CometChatUIKit.setConversationUpdateSettings(conversationUpdateSettings);
173
178
  }
174
179
  );
180
+ // Pin / Save / Pin-conversation are app settings, not integrator preferences, so the
181
+ // KIT asks for them rather than leaving every integrator to remember. Login is the
182
+ // first point the settings cache is populated. Fire-and-forget: the flags default to
183
+ // off and both read sites are long-press paths, so nothing renders against a
184
+ // half-resolved answer.
185
+ void resolvePinSaveFeatures();
175
186
  },
176
187
  onLoggedOut: () => {
177
188
  CometChatUIKit.removeLoggedInUser();
189
+ // Flags are per-app and the next login may be a different app entirely.
190
+ resetPinSaveFeatures();
178
191
  },
179
192
  })
180
193
  );
@@ -192,6 +205,9 @@ export class CometChatUIKit {
192
205
  ).catch(() => {
193
206
  // Silently ignore — will retry on next reconnection
194
207
  });
208
+ // Same reason the line above re-fetches: a flag flipped in the dashboard should reach
209
+ // a running app on the next reconnection rather than waiting for a restart.
210
+ void refreshPinSaveFeatures();
195
211
  },
196
212
  inConnecting: () => {},
197
213
  onDisconnected: () => {},
@@ -20,6 +20,7 @@ export type AdditionalParams = {
20
20
  disableMentions?: boolean;
21
21
  hideReplyOption?: boolean,
22
22
  hideReplyInThreadOption?: boolean,
23
+ hideThreadSubscriptionOption?: boolean,
23
24
  hideShareMessageOption?: boolean,
24
25
  hideEditMessageOption?: boolean,
25
26
  hideTranslateMessageOption?: boolean,
@@ -30,6 +31,10 @@ export type AdditionalParams = {
30
31
  hideMessageInfoOption?: boolean,
31
32
  hideReportMessageOption?: boolean,
32
33
  hideMarkAsUnreadOption?: boolean,
34
+ hidePinMessageOption?: boolean,
35
+ hideUnpinMessageOption?: boolean,
36
+ hideSaveMessageOption?: boolean,
37
+ hideUnsaveMessageOption?: boolean,
33
38
  hideGroupActionMessages?: boolean,
34
39
  onReplyClick?: (messageId: string) => void;
35
40
  /** DD §9 — message-list rendering. true (default) → new per-type bubbles (render 1..N tiles, incl. a
@@ -100,6 +100,10 @@ export const GroupMemberOptionConstants = {
100
100
 
101
101
  export const ConversationOptionConstants = {
102
102
  delete: "delete",
103
+ // Pin Conversation — pins the whole chat to the top of the list. Two ids rather
104
+ // than one toggle so an integrator can hide one direction independently.
105
+ pin: "pin",
106
+ unpin: "unpin",
103
107
  edit: "edit",
104
108
  reply: "reply",
105
109
  };
@@ -231,6 +235,8 @@ export const MessageOptionConstants = {
231
235
  deleteMessage: "deleteMessage",
232
236
  replyMessage: "replyMessage",
233
237
  replyInThread: "replyInThread",
238
+ /** One id for both titles — the sheet reads Follow/Unfollow off the current state. */
239
+ threadSubscription: "threadSubscription",
234
240
  translateMessage: "translateMessage",
235
241
  reactToMessage: "reactToMessage",
236
242
  messageInformation: "messageInfo",
@@ -243,6 +249,13 @@ export const MessageOptionConstants = {
243
249
  markAsUnread: "markAsUnread",
244
250
  // §8.5 — multi-attachment download all
245
251
  downloadAll: "downloadAll",
252
+ // Pin & Save. Four ids rather than two toggles: the action sheet shows one of
253
+ // each pair at a time, and a consumer hiding "unpin" without hiding "pin" is a
254
+ // real configuration (read-only pinned list, pin once and leave it).
255
+ pinMessage: "pinMessage",
256
+ unpinMessage: "unpinMessage",
257
+ saveMessage: "saveMessage",
258
+ unsaveMessage: "unsaveMessage",
246
259
  };
247
260
 
248
261
  export const CometChatMessageTypes = Object.freeze({
@@ -113,6 +113,9 @@ export class CometChatUIEventHandler {
113
113
  static emitMessageEvent(name: string, param: object) {
114
114
  CometChatUIEventHandler.messageHandlers?.map((listener) => {
115
115
  switch (name) {
116
+ case listener._eventListener?.ccThreadSubscriptionChanged?.name:
117
+ listener._eventListener?.ccThreadSubscriptionChanged?.(param);
118
+ break;
116
119
  case listener._eventListener?.ccMessageDeleted?.name:
117
120
  listener._eventListener?.ccMessageDeleted?.(param);
118
121
  break;
@@ -194,6 +197,37 @@ export class CometChatUIEventHandler {
194
197
  case listener._eventListener?.onMessageModerated?.name:
195
198
  listener._eventListener?.onMessageModerated?.(param);
196
199
  break;
200
+ // Pin & Save realtime. Without these four the SDK parses the socket frame,
201
+ // ListenerInitializer emits it, and the emit lands in a switch that matches
202
+ // nothing — so a pin made by another participant never reaches the message
203
+ // list and only appears on the next fetch.
204
+ case listener._eventListener?.onMessagePinned?.name:
205
+ listener._eventListener?.onMessagePinned?.(param);
206
+ break;
207
+ case listener._eventListener?.onMessageUnpinned?.name:
208
+ listener._eventListener?.onMessageUnpinned?.(param);
209
+ break;
210
+ case listener._eventListener?.onMessageSaved?.name:
211
+ listener._eventListener?.onMessageSaved?.(param);
212
+ break;
213
+ case listener._eventListener?.onMessageUnsaved?.name:
214
+ listener._eventListener?.onMessageUnsaved?.(param);
215
+ break;
216
+ // The cc* half: emitted by the device that PERFORMED the action, so a panel
217
+ // open next to the message list updates without waiting for a socket echo
218
+ // (and in a 1-1, where no echo is coming at all).
219
+ case listener._eventListener?.ccMessagePinned?.name:
220
+ listener._eventListener?.ccMessagePinned?.(param);
221
+ break;
222
+ case listener._eventListener?.ccMessageUnpinned?.name:
223
+ listener._eventListener?.ccMessageUnpinned?.(param);
224
+ break;
225
+ case listener._eventListener?.ccMessageSaved?.name:
226
+ listener._eventListener?.ccMessageSaved?.(param);
227
+ break;
228
+ case listener._eventListener?.ccMessageUnsaved?.name:
229
+ listener._eventListener?.ccMessageUnsaved?.(param);
230
+ break;
197
231
  }
198
232
  });
199
233
  }
@@ -39,6 +39,15 @@ type MessageUIEvents = {
39
39
  onMessageModerated?: Function;
40
40
  onAIAssistantMessageReceived?: Function;
41
41
  onMessageReply?: Function;
42
+ onMessagePinned?: Function;
43
+ onMessageUnpinned?: Function;
44
+ onMessageSaved?: Function;
45
+ onMessageUnsaved?: Function;
46
+ ccMessagePinned?: Function;
47
+ ccMessageUnpinned?: Function;
48
+ ccMessageSaved?: Function;
49
+ ccMessageUnsaved?: Function;
50
+ ccThreadSubscriptionChanged?: Function;
42
51
  };
43
52
  export class MessageUIEventListener {
44
53
  ccMessageSent?: Function = undefined;
@@ -70,7 +79,17 @@ export class MessageUIEventListener {
70
79
  onMessageModerated?: Function = undefined;
71
80
  onAIAssistantMessageReceived?: Function = undefined;
72
81
  onMessageReply?: Function = undefined;
82
+ onMessagePinned?: Function = undefined;
83
+ onMessageUnpinned?: Function = undefined;
84
+ onMessageSaved?: Function = undefined;
85
+ onMessageUnsaved?: Function = undefined;
86
+ ccMessagePinned?: Function = undefined;
87
+ ccMessageUnpinned?: Function = undefined;
88
+ ccMessageSaved?: Function = undefined;
89
+ ccMessageUnsaved?: Function = undefined;
90
+ ccThreadSubscriptionChanged?: Function = undefined;
73
91
  constructor({
92
+ ccThreadSubscriptionChanged,
74
93
  ccMessageSent,
75
94
  ccMessageEdited,
76
95
  ccMessageDeleted,
@@ -100,6 +119,14 @@ export class MessageUIEventListener {
100
119
  onMessageModerated,
101
120
  onAIAssistantMessageReceived,
102
121
  onMessageReply,
122
+ onMessagePinned,
123
+ onMessageUnpinned,
124
+ onMessageSaved,
125
+ onMessageUnsaved,
126
+ ccMessagePinned,
127
+ ccMessageUnpinned,
128
+ ccMessageSaved,
129
+ ccMessageUnsaved,
103
130
  }: MessageUIEvents) {
104
131
  if (!isFalsy(ccMessageError)) this.ccMessageError = ccMessageError;
105
132
  if (!isFalsy(ccMessageDelivered)) this.ccMessageDelivered = ccMessageDelivered;
@@ -137,6 +164,16 @@ export class MessageUIEventListener {
137
164
  if (!isFalsy(onAIAssistantMessageReceived)) this.onAIAssistantMessageReceived = onAIAssistantMessageReceived;
138
165
  if (!isFalsy(onMessageReply)) this.onMessageReply = onMessageReply;
139
166
  if (!isFalsy(onMessageModerated)) this.onMessageModerated = onMessageModerated;
167
+ if (!isFalsy(onMessagePinned)) this.onMessagePinned = onMessagePinned;
168
+ if (!isFalsy(onMessageUnpinned)) this.onMessageUnpinned = onMessageUnpinned;
169
+ if (!isFalsy(onMessageSaved)) this.onMessageSaved = onMessageSaved;
170
+ if (!isFalsy(onMessageUnsaved)) this.onMessageUnsaved = onMessageUnsaved;
171
+ if (!isFalsy(ccMessagePinned)) this.ccMessagePinned = ccMessagePinned;
172
+ if (!isFalsy(ccMessageUnpinned)) this.ccMessageUnpinned = ccMessageUnpinned;
173
+ if (!isFalsy(ccMessageSaved)) this.ccMessageSaved = ccMessageSaved;
174
+ if (!isFalsy(ccMessageUnsaved)) this.ccMessageUnsaved = ccMessageUnsaved;
175
+ if (!isFalsy(ccThreadSubscriptionChanged))
176
+ this.ccThreadSubscriptionChanged = ccThreadSubscriptionChanged;
140
177
  }
141
178
  }
142
179
 
@@ -100,7 +100,26 @@ export class ListenerInitializer {
100
100
  },
101
101
  onCardMessageReceived: (cardMessage: any) => {
102
102
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.onCardMessageReceived, cardMessage);
103
- }
103
+ },
104
+ // Pin & Save realtime (§5.5/§6.6). Each carries a FULL BaseMessage with the
105
+ // pin/save attrs already on it, so a consumer replaces its copy and is done
106
+ // — no getMessageDetails round-trip.
107
+ //
108
+ // Pin/unpin is broadcast to the conversation. Save/unsave is private and
109
+ // reaches only this user's own devices, INCLUDING the one that made the
110
+ // call, which is why the SDK exempts it from the self-session guard.
111
+ onMessagePinned: (message: CometChat.BaseMessage) => {
112
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessagePinned, message);
113
+ },
114
+ onMessageUnpinned: (message: CometChat.BaseMessage) => {
115
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessageUnpinned, message);
116
+ },
117
+ onMessageSaved: (message: CometChat.BaseMessage) => {
118
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessageSaved, message);
119
+ },
120
+ onMessageUnsaved: (message: CometChat.BaseMessage) => {
121
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.onMessageUnsaved, message);
122
+ },
104
123
  });
105
124
  }
106
125
  }
@@ -1,4 +1,11 @@
1
1
  export enum MessageEvents {
2
+ /**
3
+ * The logged-in user's subscription to a thread changed. Emitted optimistically
4
+ * on tap and again on the server's answer (or on revert), so the thread header
5
+ * and the message action sheet never disagree without a refetch.
6
+ * Also the channel an integrator's own thread list should listen on.
7
+ */
8
+ ccThreadSubscriptionChanged = "ccThreadSubscriptionChanged",
2
9
  ccMessageSent = "ccMessageSent",
3
10
  ccMessageDelivered = "ccMessageDelivered",
4
11
  ccMessageRead = "ccMessageRead",
@@ -28,4 +35,15 @@ export enum MessageEvents {
28
35
  onAIAssistantMessageReceived = "onAIAssistantMessageReceived",
29
36
  onMessagesDeliveredToAll = "onMessagesDeliveredToAll",
30
37
  onMessagesReadByAll = "onMessagesReadByAll",
38
+ // Pin & Save (§6.6). The `on*` pair is realtime off the socket; `cc*` is the
39
+ // kit's own optimistic emit, so a consumer can tell "the server said so" from
40
+ // "this device just did it and may still revert".
41
+ onMessagePinned = "onMessagePinned",
42
+ onMessageUnpinned = "onMessageUnpinned",
43
+ onMessageSaved = "onMessageSaved",
44
+ onMessageUnsaved = "onMessageUnsaved",
45
+ ccMessagePinned = "ccMessagePinned",
46
+ ccMessageUnpinned = "ccMessageUnpinned",
47
+ ccMessageSaved = "ccMessageSaved",
48
+ ccMessageUnsaved = "ccMessageUnsaved",
31
49
  }
@@ -2,6 +2,7 @@ import { CometChat } from "@cometchat/chat-sdk-react-native";
2
2
  import React, { JSX } from "react";
3
3
  import { Text, TextStyle, ViewStyle, Platform, Linking, View } from "react-native";
4
4
  import { CometChatTextFormatter } from "../CometChatTextFormatter";
5
+ import { COLOR_OPEN_TAG, HEX_COLOR_REGEX, findColorTag, stripColorTags } from "../richTextWireFormat";
5
6
  import { isTextElement, isViewElement } from "../../utils/elementType";
6
7
 
7
8
  /**
@@ -14,6 +15,8 @@ export interface RichTextStyle {
14
15
  strikethroughStyle?: TextStyle;
15
16
  inlineCodeStyle?: TextStyle;
16
17
  inlineCodeContainerStyle?: TextStyle;
18
+ /** Base style for a `<color=#rrggbb>` run. The token's own hex always overrides `color`. */
19
+ textColorStyle?: TextStyle;
17
20
  codeBlockStyle?: TextStyle;
18
21
  codeBlockContainerStyle?: ViewStyle;
19
22
  blockquoteContainerStyle?: ViewStyle;
@@ -226,6 +229,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
226
229
  if (cleaned.indexOf("`") >= 0) return true;
227
230
  if (cleaned.indexOf("_") >= 0) return true;
228
231
  if (cleaned.indexOf("[") >= 0) return true;
232
+ if (cleaned.indexOf(COLOR_OPEN_TAG) >= 0) return true;
229
233
  if (cleaned.indexOf("- ") >= 0) return true;
230
234
  if (cleaned.indexOf("> ") >= 0) return true;
231
235
  if (cleaned.indexOf("▎ ") >= 0) return true;
@@ -253,7 +257,10 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
253
257
  // Check for single-line ```content``` (opening and closing on same line)
254
258
  const afterOpen = trimmedLine.substring(3);
255
259
  const firstClose = afterOpen.indexOf("```");
256
- if (firstClose > 0) {
260
+ // `>= 0`, not `> 0`: an EMPTY code block is six backticks, so its close sits at offset 0.
261
+ // Reading that as "no close on this line" fell through to the fenced branch below, which
262
+ // swallowed every following line into the code block (ENG-38253).
263
+ if (firstClose >= 0) {
257
264
  const afterClose = afterOpen.substring(firstClose + 3).trim();
258
265
  if (afterClose.length === 0) {
259
266
  // Standalone ```content``` — render as block-level code block (same as fenced)
@@ -271,7 +278,11 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
271
278
  this.style.codeBlockContainerStyle,
272
279
  ]}
273
280
  >
274
- <Text style={[this.style.codeBlockStyle]}>{content}</Text>
281
+ {/* A code block owns its styling, so a `<color=…>` token inside one is not a
282
+ style here — but it must never reach the reader as literal markup either.
283
+ Messages sent before the serializer fix still carry the token inside the
284
+ fence, so strip rather than render (ENG-38253). */}
285
+ <Text style={[this.style.codeBlockStyle]}>{stripColorTags(content)}</Text>
275
286
  </View>
276
287
  );
277
288
  lineIndex++;
@@ -320,7 +331,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
320
331
  this.style.codeBlockStyle,
321
332
  ]}
322
333
  >
323
- {codeLines.join("\n")}
334
+ {stripColorTags(codeLines.join("\n"))}
324
335
  </Text>
325
336
  </View>
326
337
  );
@@ -548,7 +559,7 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
548
559
  const textWithoutMentions = text.replace(MENTION_PATTERN_REGEX, '');
549
560
  if (textWithoutMentions.indexOf("**") < 0 && textWithoutMentions.indexOf("__") < 0 && textWithoutMentions.indexOf("<u>") < 0 &&
550
561
  textWithoutMentions.indexOf("~~") < 0 && textWithoutMentions.indexOf("`") < 0 && textWithoutMentions.indexOf("_") < 0 &&
551
- textWithoutMentions.indexOf("[") < 0) {
562
+ textWithoutMentions.indexOf("[") < 0 && textWithoutMentions.indexOf(COLOR_OPEN_TAG) < 0) {
552
563
  return text;
553
564
  }
554
565
 
@@ -634,6 +645,24 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
634
645
  style={[this.style.inlineCodeContainerStyle, this.style.inlineCodeStyle]}
635
646
  >{restoredContent}</Text>
636
647
  );
648
+ } else if (match.type === "textColor" && match.color) {
649
+ // Re-validate at render time: the hex reaching here came off the wire, and an
650
+ // unparseable value must fall back to the base style rather than reach RN.
651
+ const safeColor = HEX_COLOR_REGEX.test(match.color) ? match.color : undefined;
652
+ // React Native resolves a nested Text's `color` over its parent's, so a run like
653
+ // `<color=#e11d48>\`code\`</color>` rendered in the inline-code foreground and the
654
+ // consumer's colour vanished — visible in the bubble even though the wire carried it
655
+ // (ENG-38248). Push the colour onto the descendants that set their own so it wins,
656
+ // matching the native composer, which also lets a consumer colour override the
657
+ // inline-code default while leaving the code background alone.
658
+ const inner = this.parseInlineFormats(restoredContent);
659
+ const innerContent = safeColor ? this.enforceTextColor(inner, safeColor) : inner;
660
+ elements.push(
661
+ <Text
662
+ key={`fmt-${keyCounter++}`}
663
+ style={safeColor ? [this.style.textColorStyle, { color: safeColor }] : this.style.textColorStyle}
664
+ >{innerContent}</Text>
665
+ );
637
666
  } else {
638
667
  const style = this.getStyleForFormat(match.type);
639
668
  const innerContent = this.parseInlineFormats(restoredContent);
@@ -656,8 +685,11 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
656
685
  return <Text key={`inline-${keyCounter}`}>{elements}</Text>;
657
686
  }
658
687
 
659
- private findNextFormat(text: string): { type: string; content: string; startIndex: number; endIndex: number; url?: string } | null {
660
- const matches: Array<{ type: string; content: string; startIndex: number; endIndex: number; url?: string }> = [];
688
+ private findNextFormat(text: string): { type: string; content: string; startIndex: number; endIndex: number; url?: string; color?: string } | null {
689
+ const matches: Array<{ type: string; content: string; startIndex: number; endIndex: number; url?: string; color?: string }> = [];
690
+
691
+ const textColorMatch = this.findTextColor(text);
692
+ if (textColorMatch) matches.push({ ...textColorMatch, type: "textColor" });
661
693
 
662
694
  const codeBlockMatch = this.findPair(text, "```", "```");
663
695
  if (codeBlockMatch) matches.push({ ...codeBlockMatch, type: "codeBlock" });
@@ -748,6 +780,21 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
748
780
  return null;
749
781
  }
750
782
 
783
+ /**
784
+ * Locates the first `<color=#rrggbb>…</color>` run. The grammar lives in richTextWireFormat
785
+ * so this stays in lock-step with the composer that produces it.
786
+ */
787
+ private findTextColor(text: string): { content: string; startIndex: number; endIndex: number; color: string } | null {
788
+ const match = findColorTag(text);
789
+ if (!match) return null;
790
+ return {
791
+ content: text.substring(match.contentStart, match.contentEnd),
792
+ startIndex: match.startIndex,
793
+ endIndex: match.endIndex,
794
+ color: match.hex,
795
+ };
796
+ }
797
+
751
798
  private findLink(text: string): { type: string; content: string; startIndex: number; endIndex: number; url?: string } | null {
752
799
  const match = LINK_REGEX.exec(text);
753
800
  if (!match) return null;
@@ -818,6 +865,45 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
818
865
  return React.cloneElement(el, {}, ...children);
819
866
  }
820
867
 
868
+ /**
869
+ * Forces `color` onto every descendant that declares its own.
870
+ *
871
+ * Needed because React Native gives a nested `<Text>`'s `color` precedence over its parent's —
872
+ * so wrapping inline code (or bold, or anything else carrying a foreground) in a colour run left
873
+ * the inner style winning and the colour invisible (ENG-38248). Only descendants that actually
874
+ * set a colour are touched; everything else already inherits correctly.
875
+ *
876
+ * Links are deliberately exempt: their colour is an affordance that tells a user the text is
877
+ * tappable, not decoration, so a consumer colour must not repaint it. They are identified by the
878
+ * `onPress` the link branch attaches.
879
+ */
880
+ private enforceTextColor(
881
+ inner: JSX.Element | string,
882
+ color: string
883
+ ): JSX.Element | string {
884
+ if (typeof inner === "string" || !React.isValidElement(inner)) return inner;
885
+
886
+ const el = inner as React.ReactElement<any>;
887
+ if (el.props?.onPress) return inner; // a link — leave its colour alone
888
+
889
+ const children = React.Children.map(el.props.children, (child) =>
890
+ this.enforceTextColor(child as JSX.Element | string, color)
891
+ );
892
+
893
+ const style = el.props.style;
894
+ const flat = Array.isArray(style) ? Object.assign({}, ...style.filter(Boolean)) : style;
895
+ const declaresColor = flat && flat.color !== undefined;
896
+
897
+ if (!declaresColor) {
898
+ return children ? React.cloneElement(el, {}, ...children) : inner;
899
+ }
900
+ return React.cloneElement(
901
+ el,
902
+ { style: Array.isArray(style) ? [...style, { color }] : { ...flat, color } },
903
+ ...(children ?? [])
904
+ );
905
+ }
906
+
821
907
  private getStyleForFormat(type: string): TextStyle {
822
908
  switch (type) {
823
909
  case "bold": return this.style.boldStyle || {};
@@ -11,3 +11,17 @@ export {
11
11
  MentionTextStyle,
12
12
  RichTextStyle,
13
13
  };
14
+
15
+ // Rich-text wire grammar — shared by the composer (producer) and formatter (renderer).
16
+ // Exported so a custom formatter can render the same tokens the built-in one does.
17
+ export {
18
+ COLOR_OPEN_TAG,
19
+ COLOR_CLOSE_TAG,
20
+ HEX_COLOR_REGEX,
21
+ normalizeHex,
22
+ openColorTag,
23
+ matchColorTagAt,
24
+ findColorTag,
25
+ stripColorTags,
26
+ } from "./richTextWireFormat";
27
+ export type { ColorTagMatch } from "./richTextWireFormat";