@cometchat/chat-uikit-react-native 5.4.0 → 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 (72) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +34 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +605 -6
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
  4. package/ios/CometChatClipboardModule.m +5 -0
  5. package/ios/CometChatClipboardModule.swift +22 -0
  6. package/ios/RichTextEditorView.swift +648 -35
  7. package/ios/RichTextEditorViewManager.m +2 -0
  8. package/ios/RichTextEditorViewManager.swift +16 -0
  9. package/package.json +2 -1
  10. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
  11. package/src/CometChatCompactMessageComposer/index.ts +2 -0
  12. package/src/CometChatConversations/CometChatConversations.tsx +291 -14
  13. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
  14. package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
  15. package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
  16. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
  17. package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
  18. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
  19. package/src/CometChatPinnedMessages/index.ts +5 -0
  20. package/src/CometChatPinnedMessages/style.ts +216 -0
  21. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
  22. package/src/CometChatRichTextEditor/index.tsx +27 -1
  23. package/src/CometChatRichTextEditor/types.ts +19 -1
  24. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
  25. package/src/CometChatSavedMessages/index.ts +5 -0
  26. package/src/CometChatSavedMessages/style.ts +159 -0
  27. package/src/CometChatSearch/CometChatSearch.tsx +47 -340
  28. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
  29. package/src/index.ts +60 -0
  30. package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
  31. package/src/shared/base/Types.ts +5 -0
  32. package/src/shared/constants/UIKitConstants.ts +13 -0
  33. package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
  34. package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
  35. package/src/shared/events/ListenerInitializer.ts +20 -1
  36. package/src/shared/events/messages.ts +18 -0
  37. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +95 -8
  38. package/src/shared/formatters/index.ts +14 -0
  39. package/src/shared/formatters/richTextWireFormat.ts +165 -0
  40. package/src/shared/framework/MessageDataSource.tsx +296 -3
  41. package/src/shared/icons/components/thread-follow.tsx +13 -0
  42. package/src/shared/icons/components/thread-unfollow.tsx +13 -0
  43. package/src/shared/icons/components/unsave.tsx +13 -0
  44. package/src/shared/icons/icon-mapping.tsx +6 -0
  45. package/src/shared/index.ts +37 -0
  46. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
  47. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +2 -1
  48. package/src/shared/utils/MarkdownUtils.ts +25 -4
  49. package/src/shared/utils/MessageUtils.tsx +80 -5
  50. package/src/shared/utils/PinConversationHelper.ts +245 -0
  51. package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
  52. package/src/shared/utils/PinSaveHelper.ts +549 -0
  53. package/src/shared/utils/SavedMessagesHelper.ts +231 -0
  54. package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
  55. package/src/shared/utils/conversationUtils.ts +8 -1
  56. package/src/shared/utils/elementType.tsx +38 -0
  57. package/src/shared/utils/stripRichText.ts +7 -0
  58. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
  59. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
  60. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
  61. package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
  62. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +28 -14
  63. package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
  64. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
  65. package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
  66. package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
  67. package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
  68. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
  69. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
  70. package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
  71. package/src/theme/default/default.ts +6 -0
  72. package/src/theme/type.ts +4 -0
@@ -18,6 +18,13 @@ import { DeepPartial } from "../shared/helper/types";
18
18
  import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
19
19
  import { CometChatAIAssistantChatHistory } from "../CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory";
20
20
  import { CometChatTooltipMenu, MenuItemInterface } from "../shared/views/CometChatTooltipMenu";
21
+ import {
22
+ isThreadSubscribed,
23
+ stampThreadSubscribed,
24
+ ThreadSubscriptionConfig,
25
+ toggleThreadSubscription,
26
+ } from "../shared/utils/ThreadSubscriptionHelper";
27
+ import { useToast } from "../shared/helper/useToast";
21
28
  import { skipNextAgentAutoLoad } from "../CometChatMessageList/CometChatMessageList";
22
29
 
23
30
  export type CometChatMessageHeaderInterface = {
@@ -105,6 +112,35 @@ export type CometChatMessageHeaderInterface = {
105
112
  * toggle visibilty of user status.
106
113
  */
107
114
  usersStatusVisibility?: boolean;
115
+ /**
116
+ * The thread's root message. Set this when the header sits above a thread — it is what
117
+ * turns the header into a thread header, and it is the message the follow control acts on.
118
+ *
119
+ * @type {CometChat.BaseMessage}
120
+ */
121
+ parentMessage?: CometChat.BaseMessage;
122
+ /**
123
+ * Toggle visibility for the follow/unfollow control in the header's top bar.
124
+ *
125
+ * §6.2 names this flag on each platform's thread header; on this platform, as on Flutter,
126
+ * the landed design places the bell in the message header's top bar, so the same
127
+ * cross-platform name lives here. One concept, one name, per-platform placement.
128
+ *
129
+ * The control renders only when `parentMessage` is set AND the feature gate
130
+ * (`ThreadSubscriptionConfig.setEnabled`) is on — which is off by default, so an
131
+ * integrator opts in. `false` hides it even when both of those hold.
132
+ *
133
+ * CometChatThreadHeader keeps its own identically-named flag for the replies-row control;
134
+ * an app using this top-bar bell should switch that one off.
135
+ *
136
+ * @type {boolean}
137
+ */
138
+ threadSubscriptionVisibility?: boolean;
139
+ /**
140
+ * Called after the subscription for this thread changes, including the optimistic flip
141
+ * and any revert.
142
+ */
143
+ onThreadSubscriptionChange?: (subscribed: boolean) => void;
108
144
  /**
109
145
  * Flag to hide the new chat button for AI agents (only applies to @agentic users)
110
146
  */
@@ -133,6 +169,17 @@ export type CometChatMessageHeaderInterface = {
133
169
  * Called when the user taps "Conversation Summary" in the options menu.
134
170
  */
135
171
  onConversationSummaryPress?: () => void;
172
+ /**
173
+ * When true, adds "Pinned Messages" as an item inside the ⋮ options menu (§6.3).
174
+ * The kit owns the label and icon so copy stays localised and consistent across
175
+ * integrators, rather than each app hand-rolling the entry via `options`.
176
+ */
177
+ showPinnedMessagesButton?: boolean;
178
+ /**
179
+ * Called when the user taps "Pinned Messages". The host opens
180
+ * CometChatPinnedMessages for this conversation.
181
+ */
182
+ onPinnedMessagesPress?: () => void;
136
183
  };
137
184
 
138
185
  interface Translations {
@@ -165,6 +212,9 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
165
212
  hideVoiceCallButton = false,
166
213
  hideVideoCallButton = false,
167
214
  usersStatusVisibility = true,
215
+ parentMessage,
216
+ threadSubscriptionVisibility = true,
217
+ onThreadSubscriptionChange,
168
218
  hideNewChatButton = false,
169
219
  hideChatHistoryButton = false,
170
220
  onNewChatButtonClick,
@@ -172,6 +222,8 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
172
222
  options,
173
223
  showConversationSummaryButton = false,
174
224
  onConversationSummaryPress,
225
+ showPinnedMessagesButton = false,
226
+ onPinnedMessagesPress,
175
227
  } = props;
176
228
 
177
229
  const [groupObj, setGroupObj] = useState(group);
@@ -184,6 +236,99 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
184
236
  user ? CometChat.RECEIVER_TYPE.USER : group ? CometChat.RECEIVER_TYPE.GROUP : null
185
237
  );
186
238
 
239
+ // ── Thread subscription (§6.2) ───────────────────────────────────────────────
240
+ // Only a header sitting above a thread has anything to follow, and the gate is off until
241
+ // the integrator opts in. Both must hold before the control exists at all.
242
+ const showThreadSubscription =
243
+ !!parentMessage && ThreadSubscriptionConfig.isEnabled() && threadSubscriptionVisibility;
244
+ // The state lives on the message now, so this reads the message, not an id.
245
+ const [threadSubscribed, setThreadSubscribed] = useState<boolean>(() =>
246
+ parentMessage ? isThreadSubscribed(parentMessage) : false
247
+ );
248
+ const { showToast, ToastElement } = useToast();
249
+ const threadListenerId = useRef(
250
+ "header_thread_" + Date.now() + "_" + (++__listenerIdCounter)
251
+ ).current;
252
+
253
+ useEffect(() => {
254
+ if (!parentMessage) return;
255
+ // Re-seed whenever the parent OBJECT changes: a re-fetch produces a new object carrying
256
+ // the server's answer, and a fetched flag always wins over anything mirrored locally.
257
+ setThreadSubscribed(isThreadSubscribed(parentMessage));
258
+ CometChatUIEventHandler.addMessageListener(threadListenerId, {
259
+ // Keep this an INLINE arrow on this exact property. emitMessageEvent dispatches by
260
+ // comparing the emitted name against the handler's Function.name, which JS infers from
261
+ // the property key — hoisting this into a named function elsewhere renames it and the
262
+ // event stops arriving, silently.
263
+ ccThreadSubscriptionChanged: ({ parentMessageId, subscribed }: any) => {
264
+ if (Number(parentMessageId) !== Number(parentMessage.getId())) return;
265
+ // Both halves matter: re-render, AND write the flag back onto the object we hold, so
266
+ // a remount or a direct read does not resurrect the pre-flip value.
267
+ stampThreadSubscribed(parentMessage, !!subscribed);
268
+ setThreadSubscribed(!!subscribed);
269
+ onThreadSubscriptionChange?.(!!subscribed);
270
+ },
271
+ });
272
+ return () => CometChatUIEventHandler.removeMessageListener(threadListenerId);
273
+ }, [parentMessage]);
274
+
275
+ const onThreadSubscriptionPress = useCallback(() => {
276
+ if (!parentMessage) return;
277
+ // The helper owns the debounce, the in-flight guard, the optimistic emit and the revert.
278
+ toggleThreadSubscription(parentMessage).then(
279
+ (subscribed: boolean) => {
280
+ // Both transitions are confirmed. The unsubscribe copy must not promise
281
+ // permanence: replying or being mentioned re-subscribes.
282
+ showToast(
283
+ t(
284
+ subscribed
285
+ ? "THREAD_SUBSCRIPTION_SUBSCRIBED_TOAST"
286
+ : "THREAD_SUBSCRIPTION_UNSUBSCRIBED_TOAST"
287
+ )
288
+ );
289
+ },
290
+ () => showToast(t("THREAD_SUBSCRIPTION_FAILED"))
291
+ );
292
+ }, [parentMessage, showToast, t]);
293
+
294
+ const ThreadSubscriptionButton = useCallback(
295
+ () => (
296
+ <TouchableOpacity
297
+ testID='MessageHeader.followToggle'
298
+ onPress={onThreadSubscriptionPress}
299
+ accessibilityRole='button'
300
+ // State-labelled, NOT action-labelled: the header says what IS, the action sheet
301
+ // says what a tap DOES (§6.5).
302
+ accessibilityLabel={
303
+ threadSubscribed
304
+ ? t("THREAD_SUBSCRIPTION_SUBSCRIBED")
305
+ : t("THREAD_SUBSCRIPTION_SUBSCRIBE")
306
+ }
307
+ accessibilityState={{ selected: threadSubscribed }}
308
+ hitSlop={{ top: 10, bottom: 10, left: 10, right: 10 }}
309
+ >
310
+ <View
311
+ testID={
312
+ threadSubscribed
313
+ ? "MessageHeader.bell.following"
314
+ : "MessageHeader.bell.notFollowing"
315
+ }
316
+ // Fixed width: the two glyphs are 19pt and 22pt wide, so without it the control
317
+ // shifts sideways on every toggle.
318
+ style={{ width: 22, alignItems: "center" }}
319
+ >
320
+ <Icon
321
+ name={threadSubscribed ? "thread-follow" : "thread-unfollow"}
322
+ color={threadSubscribed ? theme.color.primary : theme.color.iconSecondary}
323
+ height={23}
324
+ width={threadSubscribed ? 19 : 22}
325
+ />
326
+ </View>
327
+ </TouchableOpacity>
328
+ ),
329
+ [threadSubscribed, onThreadSubscriptionPress, t, theme]
330
+ );
331
+
187
332
  // Helper function to check if user is agentic
188
333
  const isAgenticUser = useCallback(() => {
189
334
  return userObj?.getRole?.() === '@agentic';
@@ -191,19 +336,26 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
191
336
 
192
337
  // Build menu items following CometChat pattern
193
338
  const buildMenuItems = useCallback((): MenuItemInterface[] => {
194
- const baseItems: MenuItemInterface[] = options ? options({ user: userObj, group: groupObj }) : [];
339
+ const items: MenuItemInterface[] = options ? [...options({ user: userObj, group: groupObj })] : [];
340
+ // Appended, not early-returned: the original wrote `return [...]` inside the
341
+ // summary branch, which meant any item added after it could never appear
342
+ // whenever summary was enabled.
343
+ if (showPinnedMessagesButton && onPinnedMessagesPress) {
344
+ items.push({
345
+ text: t('PINNED_MESSAGES') ?? 'Pinned Messages',
346
+ onPress: onPinnedMessagesPress,
347
+ icon: <Icon name="keep" width={20} height={20} color={theme.color.iconSecondary} />,
348
+ });
349
+ }
195
350
  if (showConversationSummaryButton && onConversationSummaryPress) {
196
- return [
197
- ...baseItems,
198
- {
199
- text: t('ai_conversation_summary_title'),
200
- onPress: onConversationSummaryPress,
201
- icon: <Icon name="ai-conversation-summary" width={20} height={20} color={theme.color.iconSecondary} />,
202
- },
203
- ];
351
+ items.push({
352
+ text: t('ai_conversation_summary_title'),
353
+ onPress: onConversationSummaryPress,
354
+ icon: <Icon name="ai-conversation-summary" width={20} height={20} color={theme.color.iconSecondary} />,
355
+ });
204
356
  }
205
- return baseItems;
206
- }, [options, userObj, groupObj, isAgenticUser, showConversationSummaryButton, onConversationSummaryPress, theme, t]);
357
+ return items;
358
+ }, [options, userObj, groupObj, isAgenticUser, showConversationSummaryButton, onConversationSummaryPress, showPinnedMessagesButton, onPinnedMessagesPress, theme, t]);
207
359
 
208
360
  // Handle option selection
209
361
  const handleOptionSelect = useCallback((item: MenuItemInterface) => {
@@ -237,7 +389,11 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
237
389
  */
238
390
  const BackButton = useCallback(
239
391
  () => (
240
- <TouchableOpacity style={[messageHeaderStyles.backButtonStyle]} onPress={onBack}>
392
+ <TouchableOpacity
393
+ testID='MessageHeader.back'
394
+ style={[messageHeaderStyles.backButtonStyle]}
395
+ onPress={onBack}
396
+ >
241
397
  <Icon
242
398
  name='arrow-back-fill'
243
399
  size={messageHeaderStyles.backButtonIconStyle.width}
@@ -565,6 +721,11 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
565
721
  hideVoiceCallButton,
566
722
  });
567
723
  })()}
724
+ {showThreadSubscription && (
725
+ <View style={{ marginLeft: theme.spacing.padding.p4 }}>
726
+ <ThreadSubscriptionButton />
727
+ </View>
728
+ )}
568
729
  {TrailingView && !isAgenticUser() && (
569
730
  <View style={{ marginLeft: theme.spacing.padding.p4 }}>
570
731
  {TrailingView({ user: userObj, group })}
@@ -572,6 +733,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
572
733
  )}
573
734
  {menuItems.length > 0 && (
574
735
  <TouchableOpacity
736
+ testID='MessageHeader.optionsMenu'
575
737
  style={{ marginLeft: theme.spacing.padding.p2 }}
576
738
  onPress={(e) => {
577
739
  if (e.nativeEvent) {
@@ -613,6 +775,13 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
613
775
  }))}
614
776
  />
615
777
  )}
778
+
779
+ {/* Ungated on purpose. `showToast` only sets state — this is the ONLY thing that
780
+ renders it, so gating the two on different conditions means a toast that fires
781
+ into nothing. The element is null unless a message is pending anyway, so an
782
+ unconditional mount costs a null render and removes a whole class of
783
+ "the toast never appeared" bug. */}
784
+ {ToastElement}
616
785
  </>
617
786
  );
618
787
  };