@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
@@ -42,8 +42,23 @@ import { Icon } from "../shared/icons/Icon";
42
42
  import { CommonUtils } from "../shared/utils/CommonUtils";
43
43
  import { stripMarkdown, preparePreviewText } from "../shared/utils/MarkdownUtils";
44
44
  import { CometChatRichTextFormatter } from "../shared/formatters/CometChatRichTextFormatter";
45
+ import { applyRawFormatters } from "../shared/formatters/applyRawFormatters";
45
46
  import { getMessagePreviewInternal, applyMentionsFormatting } from "../shared/utils/MessageUtils";
46
47
  import { CometChatBadge } from "../shared/views/CometChatBadge";
48
+ import { useToast } from "../shared/helper/useToast";
49
+ import {
50
+ PinConversationConfig,
51
+ isConversationPinned,
52
+ isSystemPinnedConversation,
53
+ conversationInsertIndex,
54
+ targetOf,
55
+ pinConversation as sdkPinConversation,
56
+ unpinConversation as sdkUnpinConversation,
57
+ isConversationCapError,
58
+ isConversationNotPinnable,
59
+ isConversationFeatureOff,
60
+ resolveConversationCapLimit,
61
+ } from "../shared/utils/PinConversationHelper";
47
62
  import { CometChatConfirmDialog } from "../shared/views/CometChatConfirmDialog";
48
63
  import { CometChatDate } from "../shared/views/CometChatDate";
49
64
  import { CometChatReceipt } from "../shared/views/CometChatReceipt";
@@ -228,6 +243,12 @@ export interface ConversationInterface {
228
243
  * Toggle delete conversation option visibilty.
229
244
  */
230
245
  deleteConversationOptionVisibility?: boolean;
246
+ /**
247
+ * Show Pin/Unpin in the conversation long-press menu. Also requires
248
+ * PinConversationConfig.enable() — the module gate — and the app's
249
+ * `features.ux.conversations.pinned.enabled` server flag.
250
+ */
251
+ pinConversationOptionVisibility?: boolean;
231
252
  /**
232
253
  * Toggle search bar visibility in the conversations header.
233
254
  */
@@ -291,6 +312,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
291
312
  usersStatusVisibility = true,
292
313
  groupTypeVisibility = true,
293
314
  deleteConversationOptionVisibility = true,
315
+ pinConversationOptionVisibility = true,
294
316
  showSearchBar = false,
295
317
  onSearchBarClicked,
296
318
  onSearchTextChanged,
@@ -300,6 +322,140 @@ export const CometChatConversations = (props: ConversationInterface) => {
300
322
 
301
323
  // Reference for accessing CometChatList methods
302
324
  const conversationListRef = React.useRef<CometChatListActionsInterface>(null);
325
+ const { showToast, ToastElement } = useToast();
326
+
327
+ /**
328
+ * Re-seat a conversation at its correct index — the ONE ordering rule, used by
329
+ * pin, unpin and every incoming message.
330
+ *
331
+ * Replaces bare updateAndMoveToFirst, which sent everything to index 0 and so
332
+ * broke two ways once pins existed: a message in a pinned chat reshuffled the
333
+ * pinned block by recency instead of leaving it in its pinned slot, and a message
334
+ * in an unpinned chat jumped it ABOVE the pins.
335
+ *
336
+ * With no pins in the list this is behaviourally identical to
337
+ * updateAndMoveToFirst for a newly-messaged row, so it is a safe generalisation.
338
+ */
339
+ const placeConversation = (row: any) => {
340
+ const id = row?.getConversationId?.();
341
+ if (id === undefined || id === null) return;
342
+
343
+ const all = conversationListRef.current?.getAllListItems?.() ?? [];
344
+ const currentIndex = all.findIndex(
345
+ (o: any) => String(o?.getConversationId?.() ?? "") === String(id)
346
+ );
347
+ const targetIndex = conversationInsertIndex(row, all);
348
+
349
+ // Not moving? Update in place. This is the COMMON case — a message arriving in
350
+ // a pinned chat, which must keep its slot — and it matters for more than
351
+ // efficiency: removeItemFromList flips the list to NO_DATA_FOUND the moment it
352
+ // empties, so a remove-then-add on a single-row list would flash the empty
353
+ // state. Updating in place never empties it.
354
+ // Not in the list at all — a brand-new conversation, or one the user deleted
355
+ // that just received a message. Insert at the ORDERED index, never at 0: a
356
+ // message in a deleted chat must not surface above the user's pins.
357
+ if (currentIndex === -1) {
358
+ conversationListRef.current?.addItemToList(row, targetIndex);
359
+ return;
360
+ }
361
+
362
+ // Not moving? Update in place. This is the COMMON case — a message arriving in
363
+ // a pinned chat, which must keep its slot — and it matters for more than
364
+ // efficiency: removeItemFromList flips the list to NO_DATA_FOUND the moment it
365
+ // empties, so a remove-then-add on a single-row list would flash the empty
366
+ // state. Updating in place never empties it.
367
+ if (currentIndex === targetIndex) {
368
+ conversationListRef.current?.updateList(row);
369
+ return;
370
+ }
371
+
372
+ conversationListRef.current?.removeItemFromList(id);
373
+ conversationListRef.current?.addItemToList(row, targetIndex);
374
+ };
375
+
376
+ /**
377
+ * Pin or unpin a conversation, OPTIMISTICALLY (owner decision).
378
+ *
379
+ * Unlike the message pin/save flow — which applies the server's response because
380
+ * every message call returns the full updated entity — a conversation pin's whole
381
+ * point is the ROW MOVING. Waiting a round trip before it moves reads as a dead
382
+ * tap, so the row moves first and reverts if the server refuses.
383
+ *
384
+ * Placement goes through placeConversation, the same single ordering rule the
385
+ * incoming-message paths use, so pin, unpin and a new message can never disagree
386
+ * about where a row belongs.
387
+ */
388
+ const togglePinConversation = (conversation: CometChat.Conversation) => {
389
+ const target = targetOf(conversation);
390
+ if (!target) return;
391
+
392
+ const wasPinned = isConversationPinned(conversation);
393
+ const clone: any = CommonUtils.clone(conversation);
394
+
395
+
396
+ // Optimistic flip. The timestamp is a local placeholder — the next fetch
397
+ // replaces it with the server's, and only PRESENCE is ever read anyway.
398
+ if (wasPinned) {
399
+ clone.setPinnedAt?.(undefined);
400
+ clone.setPinnedBy?.(undefined);
401
+ placeConversation(clone);
402
+ } else {
403
+ clone.setPinnedAt?.(Math.floor(Date.now() / 1000));
404
+ placeConversation(clone);
405
+ }
406
+
407
+ const call = wasPinned ? sdkUnpinConversation : sdkPinConversation;
408
+ call(target.id, target.type)
409
+ .then((updated: CometChat.Conversation) => {
410
+ // Replace the optimistic guess with the server's own row. The local
411
+ // pinnedAt above was a placeholder; this is the authoritative value, so a
412
+ // later refetch cannot appear to "change" the pin time.
413
+ if (updated) {
414
+ const settled: any = CommonUtils.clone(updated);
415
+ placeConversation(settled);
416
+ }
417
+ showToast(
418
+ wasPinned
419
+ ? (t("CONVERSATION_UNPINNED") ?? "Conversation unpinned")
420
+ : (t("CONVERSATION_PINNED") ?? "Conversation pinned")
421
+ );
422
+ })
423
+ .catch(async (error: any) => {
424
+ // Revert to exactly the object we started from, so a failed pin cannot
425
+ // leave a half-flipped row behind.
426
+ //
427
+ // Through placeConversation, NOT updateList (ENG-38898). The optimistic flip
428
+ // above MOVED the row — that is the whole point of it — so restoring the object
429
+ // is only half the revert. updateList rewrites the row in place and leaves it
430
+ // wherever the optimistic placement put it, which on a refused pin means an
431
+ // unpinned conversation sitting at the top of the list wearing no pin icon.
432
+ // placeConversation re-runs the same ordering rule that moved it and puts it
433
+ // back among the unpinned rows, so a refused pin leaves nothing behind at all.
434
+ placeConversation(CommonUtils.clone(conversation));
435
+
436
+ let messageText: string;
437
+ if (isConversationFeatureOff(error)) {
438
+ messageText = t("PIN_SAVE_FEATURE_OFF") ?? "This feature isn't available for this app.";
439
+ } else if (isConversationNotPinnable(error)) {
440
+ messageText = t("CONVERSATION_NOT_PINNABLE") ?? "This conversation can't be pinned yet.";
441
+ } else if (isConversationCapError(error)) {
442
+ // Cap is 5 here, not the messages' 100 — and the server usually does not
443
+ // send the number, so the no-count copy is the expected path.
444
+ // errorParams first, then app settings (SDK getter, ENG-37790).
445
+ const limit = await resolveConversationCapLimit(error);
446
+ messageText =
447
+ limit !== null
448
+ ? (t("PIN_CONVERSATION_LIMIT_REACHED") ??
449
+ "You can only pin {limit} chats. Unpin one to pin another.")
450
+ .replace("{limit}", String(limit))
451
+ : (t("PIN_CONVERSATION_LIMIT_REACHED_NO_COUNT") ??
452
+ "You've reached your pinned chats limit. Unpin one to pin another.");
453
+ } else {
454
+ messageText = t("PIN_SAVE_GENERIC_ERROR") ?? "Something went wrong. Please try again.";
455
+ }
456
+ showToast(messageText);
457
+ });
458
+ };
303
459
  // Store the logged in user for comparison and event handling.
304
460
  const loggedInUser = React.useRef<CometChat.User>(undefined);
305
461
  // Buffer receipts by messageId to handle race conditions where receipts arrive
@@ -307,6 +463,14 @@ export const CometChatConversations = (props: ConversationInterface) => {
307
463
  const pendingReceiptsMap = React.useRef<Map<string, { readAt?: number; deliveredAt?: number }>>(new Map());
308
464
  // State to control the confirmation dialog for deleting a conversation.
309
465
  const [confirmDelete, setConfirmDelete] = React.useState<string | undefined>(undefined);
466
+ /**
467
+ * The conversation awaiting unpin confirmation, or undefined. Holds the whole
468
+ * conversation rather than an id because togglePinConversation needs the object,
469
+ * and `longPressedConversation` has already moved on by the time the user answers.
470
+ */
471
+ const [confirmUnpin, setConfirmUnpin] = React.useState<CometChat.Conversation | undefined>(
472
+ undefined
473
+ );
310
474
  // State to control selection mode for conversation items.
311
475
  const [selecting, setSelecting] = React.useState(selectionMode === "none" ? false : true);
312
476
  const [selectedConversation, setSelectedConversations] = React.useState<
@@ -620,7 +784,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
620
784
  loggedInUser.current?.getUid()
621
785
  )
622
786
  newConversation.setUnreadMessageCount(1);
623
- conversationListRef.current?.addItemToList(newConversation, 0);
787
+ placeConversation(newConversation);
624
788
  })
625
789
  .catch((err) => onError && onError(err));
626
790
  return;
@@ -652,7 +816,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
652
816
  oldConversation.setLastMessage(newMessage);
653
817
  if (newMessage.getSender().getUid() != loggedInUser.current?.getUid())
654
818
  oldConversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1);
655
- conversationListRef.current?.updateAndMoveToFirst(CommonUtils.clone(oldConversation));
819
+ placeConversation(CommonUtils.clone(oldConversation));
656
820
  })
657
821
  .catch((err) => {
658
822
  console.log("Error", err);
@@ -851,7 +1015,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
851
1015
  if (existingConv) {
852
1016
  groupHandler(message, otherDetails, _depth + 1);
853
1017
  } else {
854
- conversationListRef.current?.addItemToList(newConversation, 0);
1018
+ placeConversation(newConversation);
855
1019
  }
856
1020
  }).catch(() => {
857
1021
  // Silently ignore — conversation won't appear until next refresh
@@ -941,7 +1105,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
941
1105
  if (!lastMessage) return null;
942
1106
  let messageText: string | JSX.Element = "";
943
1107
  messageText = ChatConfigurator.getDataSource().getLastConversationMessage(conversations, theme);
944
-
1108
+
1109
+ // Rewrite a consumer's own wire token first: block detection and markdown stripping below
1110
+ // would otherwise flatten it away before the formatter ever sees the message.
1111
+ if (typeof messageText === "string") {
1112
+ messageText = applyRawFormatters(messageText, textFormatters);
1113
+ }
1114
+
945
1115
  // Detect block-level elements in text messages before stripMarkdown flattens them
946
1116
  let blockType: 'blockquote' | 'codeBlock' | 'list' | null = null;
947
1117
  let codeBlockLine = '';
@@ -1194,11 +1364,48 @@ export const CometChatConversations = (props: ConversationInterface) => {
1194
1364
  * @param conversation - The conversation object.
1195
1365
  * @returns A JSX.Element for the trailing view.
1196
1366
  */
1367
+ /**
1368
+ * The pin glyph on its own, for the rows that render no date and no badge.
1369
+ *
1370
+ * A pin is state the user set deliberately, so it has to be visible wherever a pinned row
1371
+ * is — it is the only thing on screen telling them the row is pinned rather than merely
1372
+ * near the top. Two rows used to lose it (ENG, agent rows): an AGENT conversation, whose
1373
+ * trailing view is blanked on purpose so it shows no preview or timestamp, and any
1374
+ * conversation with NO last message, where the date-driven trailing view bailed out early.
1375
+ * Both kept the pin working everywhere except on screen.
1376
+ *
1377
+ * Deliberately NOT the full trailing view: the date and unread badge stay hidden on those
1378
+ * rows, because hiding them was a design decision and only the pin was collateral.
1379
+ */
1380
+ const getPinOnlyTrailingView = useCallback(
1381
+ (conversation: CometChat.Conversation) => {
1382
+ if (!isConversationPinned(conversation)) return <></>;
1383
+ return (
1384
+ <View
1385
+ style={[
1386
+ conversationPreviewStyles.trailingContainer,
1387
+ mergedStyles.itemStyle.trailingViewContainerStyle,
1388
+ ]}
1389
+ >
1390
+ <View
1391
+ accessible={true}
1392
+ accessibilityLabel={t("PINNED") ?? "Pinned"}
1393
+ style={{ marginRight: theme.spacing.margin.m1 }}
1394
+ >
1395
+ <Icon name='keep-fill' color={theme.color.iconSecondary} height={14} width={14} />
1396
+ </View>
1397
+ </View>
1398
+ );
1399
+ },
1400
+ [mergedStyles, theme, t]
1401
+ );
1402
+
1197
1403
  const getTrailingView = useCallback(
1198
1404
  (conversation: CometChat.Conversation) => {
1199
1405
  const customPattern = () => datePattern?.(conversation);
1200
1406
  const timestamp = conversation.getLastMessage()?.getSentAt();
1201
- if (!timestamp) return <></>;
1407
+ // No last message — nothing to date-stamp, but a pin still has to show.
1408
+ if (!timestamp) return getPinOnlyTrailingView(conversation);
1202
1409
  return (
1203
1410
  <View
1204
1411
  style={[
@@ -1212,14 +1419,27 @@ export const CometChatConversations = (props: ConversationInterface) => {
1212
1419
  pattern={"conversationDate"}
1213
1420
  style={mergedStyles?.itemStyle?.dateStyle}
1214
1421
  />
1215
- <CometChatBadge
1216
- count={conversation.getUnreadMessageCount()}
1217
- style={mergedStyles?.itemStyle?.badgeStyle}
1218
- />
1422
+ <View style={{ flexDirection: "row", alignItems: "center" }}>
1423
+ {/* Pin indicator. Sits with the badge rather than in the title so it
1424
+ cannot push a long conversation name into truncation. */}
1425
+ {isConversationPinned(conversation) ? (
1426
+ <View
1427
+ accessible={true}
1428
+ accessibilityLabel={t("PINNED") ?? "Pinned"}
1429
+ style={{ marginRight: theme.spacing.margin.m1 }}
1430
+ >
1431
+ <Icon name='keep-fill' color={theme.color.iconSecondary} height={14} width={14} />
1432
+ </View>
1433
+ ) : null}
1434
+ <CometChatBadge
1435
+ count={conversation.getUnreadMessageCount()}
1436
+ style={mergedStyles?.itemStyle?.badgeStyle}
1437
+ />
1438
+ </View>
1219
1439
  </View>
1220
1440
  );
1221
1441
  },
1222
- [mergedStyles, datePattern]
1442
+ [mergedStyles, datePattern, theme, t, getPinOnlyTrailingView]
1223
1443
  );
1224
1444
 
1225
1445
  /**
@@ -1239,7 +1459,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1239
1459
  conversation = CommonUtils.clone(conversation);
1240
1460
  conversation.setLastMessage(message);
1241
1461
  conversation.setConversationWith(group);
1242
- conversationListRef.current?.updateAndMoveToFirst(conversation);
1462
+ placeConversation(conversation);
1243
1463
  } else {
1244
1464
  CometChat.CometChatHelper.getConversationFromMessage(message)
1245
1465
  .then((newConversation) => {
@@ -1248,7 +1468,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1248
1468
  loggedInUser.current?.getUid()
1249
1469
  )
1250
1470
  newConversation.setUnreadMessageCount(1);
1251
- conversationListRef.current?.addItemToList(newConversation, 0);
1471
+ placeConversation(newConversation);
1252
1472
  })
1253
1473
  .catch((err) => onError && onError(err));
1254
1474
  }
@@ -1578,7 +1798,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1578
1798
  group.getGuid(),
1579
1799
  CometChatUiKitConstants.ConversationTypeConstants.group
1580
1800
  ).then((conversation) => {
1581
- conversationListRef.current?.addItemToList(conversation, 0);
1801
+ placeConversation(conversation);
1582
1802
  });
1583
1803
  },
1584
1804
  ccGroupDeleted: ({ group }: { group: CometChat.Group }) => {
@@ -1849,10 +2069,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
1849
2069
  const TrailingViewRaw = useCallback((conv: CometChat.Conversation) => {
1850
2070
  const conversationWith = conv.getConversationWith();
1851
2071
  if (conversationWith instanceof CometChat.User && conversationWith.getRole() === "@agentic") {
1852
- return <></>;
2072
+ // An agent row shows no preview, date or unread count — but it can be pinned like any
2073
+ // other conversation, and a pinned row with no pin is indistinguishable from an
2074
+ // unpinned one that happens to be sorted high.
2075
+ return getPinOnlyTrailingView(conv);
1853
2076
  }
1854
2077
  return getTrailingView(conv);
1855
- }, [getTrailingView]);
2078
+ }, [getTrailingView, getPinOnlyTrailingView]);
1856
2079
 
1857
2080
  return (
1858
2081
  <View style={mergedStyles.containerStyle}>
@@ -1927,6 +2150,47 @@ export const CometChatConversations = (props: ConversationInterface) => {
1927
2150
  ? options(longPressedConversation.current!)
1928
2151
  : [
1929
2152
  ...[
2153
+ // Pin sits ABOVE Delete: non-destructive actions should not be
2154
+ // below the one the user must not hit by accident.
2155
+ ...(PinConversationConfig.isEnabled() &&
2156
+ pinConversationOptionVisibility &&
2157
+ longPressedConversation.current &&
2158
+ // A user cannot unpin an admin/global pin, so offer nothing rather
2159
+ // than an option the server will refuse.
2160
+ !isSystemPinnedConversation(longPressedConversation.current)
2161
+ ? [
2162
+ {
2163
+ text: isConversationPinned(longPressedConversation.current)
2164
+ ? (t("UNPIN_CONVERSATION") ?? "Unpin")
2165
+ : (t("PIN_CONVERSATION") ?? "Pin"),
2166
+ onPress: () => {
2167
+ const target = longPressedConversation.current!;
2168
+ setTooltipVisible(false);
2169
+ // Unpin asks, pin does not — the same asymmetry the message
2170
+ // list applies (Jitvar, 2026-08-04): pinning is additive and
2171
+ // undoable in one tap, unpinning discards a deliberate act
2172
+ // with nothing on screen offering it back.
2173
+ if (isConversationPinned(target)) {
2174
+ setConfirmUnpin(target);
2175
+ return;
2176
+ }
2177
+ togglePinConversation(target);
2178
+ },
2179
+ icon: (
2180
+ <Icon
2181
+ name={
2182
+ isConversationPinned(longPressedConversation.current)
2183
+ ? "keep-off"
2184
+ : "keep"
2185
+ }
2186
+ color={theme.color.iconSecondary}
2187
+ height={theme.spacing.spacing.s6}
2188
+ width={theme.spacing.spacing.s6}
2189
+ />
2190
+ ),
2191
+ },
2192
+ ]
2193
+ : []),
1930
2194
  ...(deleteConversationOptionVisibility
1931
2195
  ? [
1932
2196
  {
@@ -1965,6 +2229,26 @@ export const CometChatConversations = (props: ConversationInterface) => {
1965
2229
  }}
1966
2230
  {...mergedStyles.confirmDialogStyle}
1967
2231
  />
2232
+ <CometChatConfirmDialog
2233
+ titleText={t("UNPIN_CONVERSATION_TITLE") ?? "Unpin Conversation"}
2234
+ icon={<Icon name='keep-off' size={theme.spacing.spacing.s12} color={theme.color.error} />}
2235
+ cancelButtonText={t("CANCEL")}
2236
+ confirmButtonText={t("UNPIN_CONVERSATION") ?? "Unpin"}
2237
+ messageText={
2238
+ t("UNPIN_CONVERSATION_CONFIRM") ??
2239
+ "Do you want to unpin this conversation from the top of your list?"
2240
+ }
2241
+ isOpen={confirmUnpin != undefined}
2242
+ onCancel={() => setConfirmUnpin(undefined)}
2243
+ onConfirm={() => {
2244
+ togglePinConversation(confirmUnpin!);
2245
+ setConfirmUnpin(undefined);
2246
+ }}
2247
+ {...mergedStyles.confirmDialogStyle}
2248
+ />
2249
+ {/* Without this the useToast hook runs but nothing ever appears — the
2250
+ conversation pin/unpin toasts and every error message are invisible. */}
2251
+ {ToastElement}
1968
2252
  </View>
1969
2253
  );
1970
2254
  };
@@ -185,9 +185,9 @@ export interface CometChatGroupMembersInterface
185
185
  */
186
186
  hideHeader?: boolean;
187
187
  /**
188
- * Hide the Submit Button.
188
+ * Callback when an error occurs.
189
189
  */
190
- onError?: () => void;
190
+ onError?: (e: CometChat.CometChatException) => void;
191
191
  /**
192
192
  * search Keyword
193
193
  */
@@ -57,6 +57,7 @@ import {
57
57
  messageStatus,
58
58
  } from "../shared/utils/CometChatMessageHelper";
59
59
  import { CommonUtils } from "../shared/utils/CommonUtils";
60
+ import { applyRawFormatters } from "../shared/formatters/applyRawFormatters";
60
61
  import { isCursorWithinMentionRange, getMentionRangeAtCursor } from "../shared/utils/MentionUtils";
61
62
  import { permissionUtil } from "../shared/utils/PermissionUtil";
62
63
  import { CometChatMediaRecorder } from "../shared/views/CometChatMediaRecorder";
@@ -1921,10 +1922,15 @@ export const CometChatMessageComposer = React.forwardRef(
1921
1922
  if (user) formatter.setUser(user);
1922
1923
  if (group) formatter.setGroup(group);
1923
1924
  let trackingCharacter = formatter.getTrackingCharacter();
1924
- trackingCharacters.current.push(trackingCharacter);
1925
+ if (trackingCharacter) trackingCharacters.current.push(trackingCharacter);
1925
1926
 
1926
1927
  let newFormatter = CommonUtils.clone(formatter);
1927
- allFormatters.current.set(trackingCharacter, newFormatter);
1928
+ // A formatter with no tracking character has no suggestion list, but it still takes part in
1929
+ // the send and edit-preview lifecycle — so key it by id instead of letting an empty key
1930
+ // collapse them all into one entry. The prefix keeps it clear of tracking-character lookups.
1931
+ const formatterKey =
1932
+ trackingCharacter || `formatter:${formatter.getId?.() ?? allFormatters.current.size}`;
1933
+ allFormatters.current.set(formatterKey, newFormatter);
1928
1934
  });
1929
1935
  }, []);
1930
1936
 
@@ -2857,12 +2863,17 @@ export const CometChatMessageComposer = React.forwardRef(
2857
2863
  <CometChatMessagePreview
2858
2864
  messagePreviewTitle={t("EDIT_MESSAGE")}
2859
2865
  message={messagePreview?.message}
2866
+ textFormatters={textFormatters}
2860
2867
  // Editing a media caption: caption text is the editable subtitle; a muted overline
2861
2868
  // (media-type icon + attachment count) restores the context the hidden thumbnail gave.
2862
2869
  {...(typeof messagePreview?.message?.getCaption === "function"
2863
2870
  ? {
2864
- messagePreviewSubtitle:
2871
+ // A caption arrives as a plain string, so a consumer's token is rewritten
2872
+ // here — `textFormatters` above only covers the message-text path.
2873
+ messagePreviewSubtitle: applyRawFormatters(
2865
2874
  messagePreview.message.getCaption() ?? "",
2875
+ textFormatters
2876
+ ),
2866
2877
  hideSubtitleIcon: true,
2867
2878
  overlineText: attachmentCountLabel(messagePreview.message.getType?.(), messagePreview.message.getAttachments?.()?.length ?? 1),
2868
2879
  }
@@ -2888,6 +2899,7 @@ export const CometChatMessageComposer = React.forwardRef(
2888
2899
  {replyMessage && replyMessage.message && (
2889
2900
  <CometChatMessagePreview
2890
2901
  message={replyMessage.message}
2902
+ textFormatters={textFormatters}
2891
2903
  showCloseIcon={true}
2892
2904
  closeIconURL={ICONS.CLOSE}
2893
2905
  onCloseClick={() => {