@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,5 @@
1
+ export { CometChatSavedMessages } from "./CometChatSavedMessages";
2
+ export type { CometChatSavedMessagesInterface } from "./CometChatSavedMessages";
3
+
4
+ export { getSavedMessagesStyleLight, getSavedMessagesStyleDark } from "./style";
5
+ export type { SavedMessagesStyle } from "./style";
@@ -0,0 +1,159 @@
1
+ import { ImageSourcePropType, ImageStyle, TextStyle, ViewStyle } from "react-native";
2
+ import { JSX } from "react";
3
+ import { CometChatTheme } from "../theme/type";
4
+
5
+ /**
6
+ * Style type for the CometChatSavedMessages component (design doc §6.7).
7
+ *
8
+ * Every value maps to a SEMANTIC theme token rather than a literal, so light and
9
+ * dark are two calls to the same builder and an integrator retheming the kit gets
10
+ * this surface for free.
11
+ *
12
+ * `itemStyle` is intentionally ABSENT. These rows are conversation rows and take
13
+ * their chrome from `theme.conversationStyles.itemStyle` — the same tokens the
14
+ * conversation list uses — so that the two surfaces cannot drift apart. Giving this
15
+ * component its own copy would guarantee they eventually do.
16
+ */
17
+ export type SavedMessagesStyle = {
18
+ /** Root container. */
19
+ containerStyle: ViewStyle;
20
+
21
+ /** Header: title on the left, close affordance on the right. */
22
+ headerContainerStyle: ViewStyle;
23
+ titleStyle: TextStyle;
24
+ closeButtonIconStyle: ImageStyle;
25
+ closeButtonIcon?: ImageSourcePropType | JSX.Element;
26
+
27
+ /** Type glyph in the row subtitle (image / video / audio / file / sticker …). */
28
+ previewIconStyle: ImageStyle;
29
+ previewIconContainerStyle: ViewStyle;
30
+
31
+ /** Glyph in the long-press menu (Unsave). */
32
+ menuIconStyle: ImageStyle;
33
+
34
+ /** Empty and error states. */
35
+ emptyStateStyle: {
36
+ /** Centres the whole block in the space the list would have filled. */
37
+ containerStyle: ViewStyle;
38
+ titleStyle: TextStyle;
39
+ subTitleStyle: TextStyle;
40
+ iconStyle: ImageStyle;
41
+ };
42
+ errorStateStyle: {
43
+ containerStyle: ViewStyle;
44
+ titleStyle: TextStyle;
45
+ subTitleStyle: TextStyle;
46
+ iconStyle: ImageStyle;
47
+ };
48
+ };
49
+
50
+ export const getSavedMessagesStyleLight = (
51
+ color: CometChatTheme["color"],
52
+ spacing: CometChatTheme["spacing"],
53
+ typography: CometChatTheme["typography"]
54
+ ): SavedMessagesStyle => ({
55
+ containerStyle: {
56
+ flex: 1,
57
+ backgroundColor: color.background1,
58
+ },
59
+ // Mirrors the Group Info / User Info header: a leading back arrow, then the title. Those
60
+ // screens are the reference for every full-screen view in the app, so the paddings and the
61
+ // heading1.bold title are copied rather than re-invented.
62
+ headerContainerStyle: {
63
+ flexDirection: "row",
64
+ alignItems: "center",
65
+ paddingTop: spacing.padding.p4,
66
+ paddingLeft: spacing.padding.p2,
67
+ paddingBottom: spacing.padding.p2,
68
+ },
69
+ titleStyle: {
70
+ ...typography.heading1.bold,
71
+ color: color.textPrimary,
72
+ paddingLeft: spacing.padding.p1,
73
+ },
74
+ closeButtonIconStyle: {
75
+ tintColor: color.iconPrimary,
76
+ height: spacing.spacing.s6,
77
+ width: spacing.spacing.s6,
78
+ },
79
+ previewIconStyle: {
80
+ tintColor: color.iconSecondary,
81
+ height: spacing.spacing.s4,
82
+ width: spacing.spacing.s4,
83
+ },
84
+ previewIconContainerStyle: {
85
+ marginRight: spacing.margin.m1,
86
+ },
87
+ menuIconStyle: {
88
+ tintColor: color.iconSecondary,
89
+ height: spacing.spacing.s6,
90
+ width: spacing.spacing.s6,
91
+ },
92
+ emptyStateStyle: {
93
+ containerStyle: {
94
+ flex: 1,
95
+ alignItems: "center",
96
+ justifyContent: "center",
97
+ paddingHorizontal: spacing.padding.p8,
98
+ gap: spacing.spacing.s2,
99
+ },
100
+ titleStyle: {
101
+ ...typography.heading4.bold,
102
+ color: color.textPrimary,
103
+ textAlign: "center",
104
+ },
105
+ subTitleStyle: {
106
+ ...typography.body.regular,
107
+ color: color.textSecondary,
108
+ textAlign: "center",
109
+ },
110
+ iconStyle: {
111
+ tintColor: color.iconSecondary,
112
+ // 120, not a spacing token: these glyphs sit in a 24x24 viewBox but only fill ~54% of its
113
+ // width, so the BOX has to be far larger than the mark you want to see. The design's
114
+ // bookmark measures 66x80 against a 16px title, and 66 / 0.54 ≈ 120. Using s14 (56) drew
115
+ // a 30x37 mark — less than half the intended size.
116
+ height: 120,
117
+ width: 120,
118
+ marginBottom: spacing.margin.m3,
119
+ },
120
+ },
121
+ // Same layout as the empty state, because it fills the same hole. The icon needs no
122
+ // size compensation: `error-state` is a purpose-built 120x120 illustration that fills
123
+ // its viewBox, unlike the glyphs above. 120 is also what the conversation list asks
124
+ // for (`margin.m15 << 1`), so the two error screens come out identical.
125
+ errorStateStyle: {
126
+ containerStyle: {
127
+ flex: 1,
128
+ alignItems: "center",
129
+ justifyContent: "center",
130
+ paddingHorizontal: spacing.padding.p8,
131
+ },
132
+ titleStyle: {
133
+ ...typography.heading4.bold,
134
+ color: color.textPrimary,
135
+ textAlign: "center",
136
+ },
137
+ subTitleStyle: {
138
+ ...typography.body.regular,
139
+ color: color.textSecondary,
140
+ textAlign: "center",
141
+ },
142
+ iconStyle: {
143
+ height: 120,
144
+ width: 120,
145
+ marginBottom: spacing.margin.m3,
146
+ },
147
+ },
148
+ });
149
+
150
+ /**
151
+ * Dark delegates to light — see the note in CometChatPinnedMessages/style.ts. Every
152
+ * value here resolves from a semantic token and `color` is already the dark palette,
153
+ * so there is no dark-only override to apply.
154
+ */
155
+ export const getSavedMessagesStyleDark = (
156
+ color: CometChatTheme["color"],
157
+ spacing: CometChatTheme["spacing"],
158
+ typography: CometChatTheme["typography"]
159
+ ): SavedMessagesStyle => getSavedMessagesStyleLight(color, spacing, typography);
@@ -1,4 +1,4 @@
1
- import React, { useCallback, useEffect, useReducer, useRef, useState, useMemo } from 'react';
1
+ import React, { useCallback, useEffect, useReducer, useRef, useState, useMemo, JSX } from 'react';
2
2
  import { View, TextInput, TouchableOpacity, Text, Image, ImageBackground, FlatList, ImageSourcePropType, StyleSheet } from 'react-native';
3
3
  import { CometChat } from '@cometchat/chat-sdk-react-native';
4
4
  import {
@@ -19,10 +19,52 @@ import { DeepPartial } from '../shared/helper/types';
19
19
  import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNew/LocalizationManager';
20
20
  import { CommonUtils } from '../shared/utils/CommonUtils';
21
21
  import { stripMarkdown } from '../shared/utils/MarkdownUtils';
22
+ import { CometChatRichTextFormatter } from '../shared/formatters/CometChatRichTextFormatter';
23
+ import { CometChatTextFormatter } from '../shared/formatters/CometChatTextFormatter';
24
+ import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
22
25
  import { ExtensionConstants } from '../extensions/ExtensionConstants';
23
26
  import { getExtensionData } from '../extensions/ExtensionModerator';
24
27
 
25
28
 
29
+ /** Module-level formatter for search previews — reused across renders (no GC churn). */
30
+ const searchRichTextFormatter = new CometChatRichTextFormatter();
31
+
32
+ /**
33
+ * Preview text for a search row: mention tokens resolved to @Name and markdown flattened, but the
34
+ * rich-text colour tokens are KEPT and painted, so a coloured message reads coloured in search
35
+ * exactly as it does in the conversation list row. Markdown is stripped before the formatter runs,
36
+ * so only colour runs remain — the result is always inline `<Text>`, never a block-level `View`.
37
+ * Returns a JSX element when the text carries colour, a plain string otherwise.
38
+ */
39
+ const formatPreviewText = (
40
+ rawText: any,
41
+ message?: CometChat.BaseMessage,
42
+ textFormatters?: Array<CometChatTextFormatter>
43
+ ): string | JSX.Element => {
44
+ if (typeof rawText !== 'string') return rawText;
45
+
46
+ // A consumer's own wire token becomes UI Kit markup first; `stripMarkdown` below removes
47
+ // anything it does not recognise, so nothing left until later would survive.
48
+ let text = stripMarkdown(applyRawFormatters(rawText, textFormatters), true).replace(/<@all:(.*?)>/g, '@$1');
49
+
50
+ try {
51
+ const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
52
+ if (mentionedUsers && mentionedUsers.length > 0) {
53
+ mentionedUsers.forEach((u: CometChat.User) => {
54
+ const uid = u.getUid();
55
+ const name = u.getName();
56
+ if (uid && name) {
57
+ text = text.replace(new RegExp(`<@uid:${uid}>`, 'g'), `@${name}`);
58
+ }
59
+ });
60
+ }
61
+ } catch (e) {
62
+ console.log(e)
63
+ }
64
+
65
+ return searchRichTextFormatter.getFormattedText(text) ?? text;
66
+ };
67
+
26
68
  // ERROR HANDLER
27
69
  function useCometChatErrorHandler(onError?: (error: CometChat.CometChatException) => void) {
28
70
  return useCallback(
@@ -294,6 +336,15 @@ interface CometChatSearchProps {
294
336
  */
295
337
  conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
296
338
 
339
+ /**
340
+ * Text formatters, the same instances passed to the message list and the composer.
341
+ *
342
+ * A search row renders the message's own text, so a consumer's wire token has to be rewritten
343
+ * here too — otherwise a message reads coloured in the chat and raw in the search results.
344
+ * Only `formatRawText` is used: rows are flattened to a single line.
345
+ */
346
+ textFormatters?: Array<CometChatTextFormatter>;
347
+
297
348
  /**
298
349
  * Custom view component for text message items
299
350
  * @param message - The text message object to render
@@ -572,10 +623,11 @@ interface ConversationItemProps {
572
623
  mergedStyles: any;
573
624
  theme: any;
574
625
  conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
626
+ textFormatters?: Array<CometChatTextFormatter>;
575
627
  }
576
628
 
577
629
  const ConversationItem = React.memo<ConversationItemProps>((
578
- { conversation, searchText, onPress, mergedStyles, theme, conversationItemView }
630
+ { conversation, searchText, onPress, mergedStyles, theme, conversationItemView, textFormatters }
579
631
  ) => {
580
632
  const getStatusIndicator = () => {
581
633
  const withObj = conversation.getConversationWith();
@@ -631,32 +683,6 @@ const ConversationItem = React.memo<ConversationItemProps>((
631
683
  );
632
684
  };
633
685
 
634
- const formatMentionsInText = (rawText: any, message?: CometChat.BaseMessage) => {
635
- if (typeof rawText !== 'string') return rawText;
636
-
637
- // Strip markdown syntax for clean search result preview while
638
- // preserving mention tokens for processing below.
639
- let text = stripMarkdown(rawText).replace(/<@all:(.*?)>/g, '@$1');
640
-
641
- try {
642
- const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
643
- if (mentionedUsers && mentionedUsers.length > 0) {
644
- mentionedUsers.forEach((u: CometChat.User) => {
645
- const uid = u.getUid();
646
- const name = u.getName();
647
- if (uid && name) {
648
- const uidRegex = new RegExp(`<@uid:${uid}>`, 'g');
649
- text = text.replace(uidRegex, `@${name}`);
650
- }
651
- });
652
- }
653
- } catch (e) {
654
- console.log(e)
655
- }
656
-
657
- return text;
658
- };
659
-
660
686
  if (conversationItemView) {
661
687
  return (
662
688
  <TouchableOpacity onPress={() => onPress(conversation, searchText)}>
@@ -676,7 +702,7 @@ const ConversationItem = React.memo<ConversationItemProps>((
676
702
  {conversation.getConversationWith().getName()}
677
703
  </Text>
678
704
  <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
679
- {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
705
+ {formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage(), textFormatters)}
680
706
  </Text>
681
707
  </View>
682
708
  {renderTrailingView()}
@@ -720,6 +746,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
720
746
  emptyView,
721
747
  errorView,
722
748
  conversationItemView,
749
+ textFormatters,
723
750
  textMessageItemView,
724
751
  imageMessageItemView,
725
752
  audioMessageItemView,
@@ -1397,47 +1424,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1397
1424
  return undefined;
1398
1425
  };
1399
1426
 
1400
- // Render conversation avatar
1401
- const renderConversationLeadingView = (conversation: CometChat.Conversation) => {
1402
- const withObj = conversation.getConversationWith();
1403
- const avatarURL = withObj instanceof CometChat.User ? withObj.getAvatar() : withObj.getIcon();
1404
- const name = withObj.getName();
1405
-
1406
- return (
1407
- <View style={styles.avatarWrap}>
1408
- <View style={styles.avatar}>
1409
- <CometChatAvatar
1410
- image={{ uri: avatarURL }}
1411
- name={name}
1412
- />
1413
- <View style={styles.statusBadge}>
1414
- <CometChatStatusIndicator
1415
- type={getStatusIndicator(conversation)}
1416
- />
1417
- </View>
1418
- </View>
1419
- </View>
1420
- );
1421
- };
1422
-
1423
- // Render conversation trailing view (date and badge)
1424
- const renderConversationTrailingView = (conversation: CometChat.Conversation) => {
1425
- const timestamp = conversation.getLastMessage()?.getSentAt();
1426
- if (!timestamp) return null;
1427
-
1428
- return (
1429
- <View style={mergedStyles.conversationItemStyle?.trailingContainerStyle}>
1430
- <CometChatDate
1431
- timeStamp={timestamp * 1000}
1432
- pattern={"conversationDate"}
1433
- />
1434
- <CometChatBadge
1435
- count={conversation.getUnreadMessageCount()}
1436
- />
1437
- </View>
1438
- );
1439
- };
1440
-
1441
1427
  // Get file type icon based on file extension
1442
1428
  const getFileTypeIcon = (fileName: string): 'audio-file-type' | 'image-file-type' | 'video-file-type' | 'pdf-file-type' | 'presentation-file-type' | 'spreadsheet-file-type' | 'text-file-type' | 'zip-file-type' | 'document-file-type' | 'unknown-file-type' => {
1443
1429
  if (!fileName) return 'unknown-file-type';
@@ -1488,34 +1474,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1488
1474
  return 'document-file-type';
1489
1475
  };
1490
1476
 
1491
- // Format mentions in raw message text: convert <@all:alias> to @alias
1492
- // and <@uid:UID> to @Name when message provides mentioned users.
1493
- // Also strips markdown syntax for clean search result previews.
1494
- const formatMentionsInText = (rawText: any, message?: CometChat.BaseMessage) => {
1495
- if (typeof rawText !== 'string') return rawText;
1496
-
1497
- // Strip markdown syntax while preserving mention tokens for processing below.
1498
- let text = stripMarkdown(rawText).replace(/<@all:(.*?)>/g, '@$1');
1499
-
1500
- try {
1501
- const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
1502
- if (mentionedUsers && mentionedUsers.length > 0) {
1503
- mentionedUsers.forEach((u: CometChat.User) => {
1504
- const uid = u.getUid();
1505
- const name = u.getName();
1506
- if (uid && name) {
1507
- const uidRegex = new RegExp(`<@uid:${uid}>`, 'g');
1508
- text = text.replace(uidRegex, `@${name}`);
1509
- }
1510
- });
1511
- }
1512
- } catch (e) {
1513
- console.log(e)
1514
- }
1515
-
1516
- return text;
1517
- };
1518
-
1519
1477
  // Subtitle text for a media/file search result. Shows the message CAPTION when there is one,
1520
1478
  // otherwise a count summary ("N Videos" / "12 Files"). Photos/videos put their +N on the
1521
1479
  // thumbnail, so they show caption-or-count; files/audio have no thumbnail, so a caption is
@@ -1526,8 +1484,14 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1526
1484
  const atts =
1527
1485
  (typeof message.getAttachments === "function" ? message.getAttachments() : null) || [];
1528
1486
  const count = atts.length || 1;
1529
- const caption =
1530
- (typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || "";
1487
+ // The caption carries wire markup since ENG-38258, and it is concatenated with the count
1488
+ // label below — so it is flattened here, exactly as the conversation row flattens it.
1489
+ const caption = stripMarkdown(
1490
+ applyRawFormatters(
1491
+ (typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || "",
1492
+ textFormatters
1493
+ )
1494
+ );
1531
1495
  const firstName =
1532
1496
  atts[0]?.getName?.() || (message.getAttachment?.() as any)?.getName?.() || "";
1533
1497
 
@@ -1566,16 +1530,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1566
1530
  return (sentByMe ? receiver?.getName?.() : message.getSender()?.getName?.()) || "";
1567
1531
  };
1568
1532
 
1569
- // Plain-string subtitle text for any message type (attachments delegate to the caption/count
1570
- // helper above; everything else keeps the existing text/card/custom handling).
1571
- const getMessageSubtitleText = (message: CometChat.BaseMessage): string => {
1533
+ // Subtitle text for any message type (attachments delegate to the caption/count helper above;
1534
+ // everything else keeps the existing text/card/custom handling). Text messages come back as JSX
1535
+ // when they carry colour, so the row renders it instead of flattening it away.
1536
+ const getMessageSubtitleText = (message: CometChat.BaseMessage): string | JSX.Element => {
1572
1537
  const messageType = message.getType();
1573
1538
  if (["image", "video", "file", "audio"].includes(messageType)) {
1574
1539
  return getMediaSearchSubtitle(message as CometChat.MediaMessage);
1575
1540
  }
1576
1541
  if (messageType === "text") {
1577
- const raw = (message as CometChat.TextMessage).getText?.();
1578
- return formatMentionsInText(raw, message) || messageType || "Message";
1542
+ return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message, textFormatters)
1543
+ || messageType || "Message";
1579
1544
  }
1580
1545
  if (message.getCategory() === MessageCategoryConstants.card) {
1581
1546
  const cardText =
@@ -1792,247 +1757,11 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1792
1757
  (prev, next) => prev.message.getId() === next.message.getId()
1793
1758
  );
1794
1759
 
1795
- // Render conversations section
1796
- const renderConversationsSection = () => {
1797
- const { conversationList, fetchState } = conversationState;
1798
-
1799
- if (fetchState === States.loading && conversationList.length === 0) {
1800
- return loadingView ? loadingView() : <Skeleton />;
1801
- }
1802
-
1803
- if (fetchState === States.empty || conversationList.length === 0) {
1804
- return null; // Don't show empty conversations section
1805
- }
1806
-
1807
- if (fetchState === States.error) {
1808
- if (errorView) {
1809
- return errorView();
1810
- }
1811
-
1812
- return (
1813
- <View style={[mergedStyles.errorStateStyle?.containerStyle]}>
1814
- <Icon
1815
- name="empty-search"
1816
- size={120}
1817
- height={120}
1818
- width={120}
1819
- imageStyle={mergedStyles.errorStateStyle?.iconStyle}
1820
- containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
1821
- />
1822
- <Text style={[mergedStyles.errorStateStyle?.titleStyle]}>
1823
- {t("SEARCH_ERROR_LOADING_CONVERSATIONS") || "Error Loading Conversations"}
1824
- </Text>
1825
- <Text style={[mergedStyles.errorStateStyle?.subtitleStyle]}>
1826
- {t("SEARCH_TRY_AGAIN") || "Please try again later"}
1827
- </Text>
1828
- </View>
1829
- );
1830
- }
1831
-
1832
- return (
1833
- <View>
1834
- <Text style={mergedStyles.sectionTitleStyle}>{t("CHATS") || "Chats"}</Text>
1835
- <FlatList
1836
- data={conversationList}
1837
- keyExtractor={(item) => item.getConversationId()}
1838
- scrollEnabled={false}
1839
- initialNumToRender={10}
1840
- maxToRenderPerBatch={5}
1841
- windowSize={5}
1842
- removeClippedSubviews={true}
1843
- updateCellsBatchingPeriod={50}
1844
- renderItem={({ item: conversation }) => {
1845
- // Use custom conversation item view if provided
1846
- if (conversationItemView) {
1847
- return (
1848
- <TouchableOpacity
1849
- onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1850
- >
1851
- {conversationItemView(conversation, searchState.searchText)}
1852
- </TouchableOpacity>
1853
- );
1854
- }
1855
-
1856
- // Default conversation item rendering
1857
- return (
1858
- <TouchableOpacity
1859
- style={mergedStyles.conversationItemStyle?.containerStyle}
1860
- onPress={() => onConversationClicked?.(conversation, searchState.searchText)}
1861
- >
1862
- {renderConversationLeadingView(conversation)}
1863
- <View style={mergedStyles.conversationItemStyle?.contentStyle}>
1864
- <Text style={mergedStyles.conversationItemStyle?.titleStyle} numberOfLines={1}>
1865
- {conversation.getConversationWith().getName()}
1866
- </Text>
1867
- <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
1868
- {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
1869
- </Text>
1870
- </View>
1871
- {renderConversationTrailingView(conversation)}
1872
- </TouchableOpacity>
1873
- );
1874
- }}
1875
- ListFooterComponent={
1876
- conversationState.hasMoreResults ? (
1877
- <TouchableOpacity
1878
- style={mergedStyles.seeMoreButtonStyle}
1879
- onPress={loadMoreConversations}
1880
- disabled={isConversationMoreResultsLoading.current}
1881
- >
1882
- <Text style={mergedStyles.seeMoreTextStyle}>
1883
- {isConversationMoreResultsLoading.current ? t("SEARCH_LOADING") || 'Loading...' : t("SEARCH_SEE_MORE") || 'See More'}
1884
- </Text>
1885
- </TouchableOpacity>
1886
- ) : null
1887
- }
1888
- />
1889
- </View>
1890
- );
1891
- };
1892
-
1893
1760
  // Helper to format date for headers
1894
1761
  const getDateHeaderDate = useCallback((timestamp: number) => {
1895
1762
  return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
1896
1763
  }, []);
1897
1764
 
1898
- // Render messages section
1899
- const renderMessagesSection = () => {
1900
- const { messageList, fetchState } = messageState;
1901
-
1902
- if (fetchState === States.loading && messageList.length === 0) {
1903
- return loadingView ? loadingView() : <Skeleton />;
1904
- }
1905
-
1906
- if (fetchState === States.empty || messageList.length === 0) {
1907
- return null; // Don't show empty messages section
1908
- }
1909
-
1910
- if (fetchState === States.error) {
1911
- if (errorView) {
1912
- return errorView();
1913
- }
1914
-
1915
- return (
1916
- <View style={[mergedStyles.errorStateStyle?.containerStyle]}>
1917
- <Icon
1918
- name="empty-search"
1919
- size={120}
1920
- height={120}
1921
- width={120}
1922
- imageStyle={mergedStyles.errorStateStyle?.iconStyle}
1923
- containerStyle={mergedStyles.errorStateStyle?.iconContainerStyle}
1924
- />
1925
- <Text style={[mergedStyles.errorStateStyle?.titleStyle]}>
1926
- {t("SEARCH_ERROR_LOADING_MESSAGES") || "Error Loading M essages"}
1927
- </Text>
1928
- <Text style={[mergedStyles.errorStateStyle?.subtitleStyle]}>
1929
- {t("SEARCH_TRY_AGAIN") || "Please try again later"}
1930
- </Text>
1931
- </View>
1932
- );
1933
- }
1934
-
1935
- return (
1936
- <View>
1937
- <Text style={mergedStyles.sectionTitleStyle}>{t("MESSAGES") || "Messages"}</Text>
1938
- <FlatList
1939
- data={messageList}
1940
- keyExtractor={(item, index) => `${item.getId()}-${index}`}
1941
- initialNumToRender={10}
1942
- maxToRenderPerBatch={5}
1943
- windowSize={5}
1944
- removeClippedSubviews={true}
1945
- updateCellsBatchingPeriod={50}
1946
- renderItem={({ item: message, index }) => {
1947
- const messageType = message.getType();
1948
-
1949
- // Date header logic for media items
1950
- let dateHeader: React.ReactNode = null;
1951
- if (['image', 'video'].includes(messageType)) {
1952
- const sentAt = message.getSentAt();
1953
- const currentDateStr = getDateHeaderDate(sentAt);
1954
- const prevMessage = index > 0 ? messageList[index - 1] : null;
1955
- const prevDateStr = prevMessage ? getDateHeaderDate(prevMessage.getSentAt()) : null;
1956
-
1957
- if (currentDateStr !== prevDateStr) {
1958
- dateHeader = (
1959
- <CometChatDate
1960
- timeStamp={sentAt * 1000}
1961
- customDateString={currentDateStr}
1962
- style={{
1963
- textStyle: mergedStyles.sectionTitleStyle
1964
- }}
1965
- />
1966
- );
1967
- }
1968
- }
1969
-
1970
- // Check if message is a text message with link preview
1971
- const isLinkMessage = messageType === 'text' && (() => {
1972
- const textMessage = message as CometChat.TextMessage;
1973
- const metadata = textMessage.getMetadata();
1974
- return metadata && (metadata as any)['@injected'] && (metadata as any)['@injected']['extensions'] && (metadata as any)['@injected']['extensions']['link-preview'];
1975
- })();
1976
-
1977
- // Determine which custom view to use based on message type
1978
- let customView: (() => React.ReactElement) | undefined;
1979
-
1980
- if (isLinkMessage && linkMessageItemView) {
1981
- customView = () => linkMessageItemView(message, searchState.searchText);
1982
- } else if (messageType === 'text' && textMessageItemView) {
1983
- customView = () => textMessageItemView(message, searchState.searchText);
1984
- } else if (messageType === 'image' && imageMessageItemView) {
1985
- customView = () => imageMessageItemView(message, searchState.searchText);
1986
- } else if (messageType === 'video' && videoMessageItemView) {
1987
- customView = () => videoMessageItemView(message, searchState.searchText);
1988
- } else if (messageType === 'audio' && audioMessageItemView) {
1989
- customView = () => audioMessageItemView(message, searchState.searchText);
1990
- } else if (messageType === 'file' && documentMessageItemView) {
1991
- customView = () => documentMessageItemView(message, searchState.searchText);
1992
- }
1993
-
1994
- // Use custom view if available
1995
- if (customView) {
1996
- return (
1997
- <View>
1998
- {dateHeader}
1999
- <TouchableOpacity
2000
- onPress={() => onMessageClicked?.(message, searchState.searchText)}
2001
- >
2002
- {customView()}
2003
- </TouchableOpacity>
2004
- </View>
2005
- );
2006
- }
2007
-
2008
- // Default message item rendering
2009
- return (
2010
- <View>
2011
- {dateHeader}
2012
- <TouchableOpacity
2013
- style={mergedStyles.messageItemStyle?.containerStyle}
2014
- onPress={() => onMessageClicked?.(message, searchState.searchText)}
2015
- >
2016
- {renderMessageLeadingView(message)}
2017
- <View style={[
2018
- mergedStyles.messageItemStyle?.contentStyle,
2019
- (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
2020
- ]}>
2021
- <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
2022
- {getMessageChatTitle(message)}
2023
- </Text>
2024
- {renderMessageSubtitle(message)}
2025
- </View>
2026
- <MemoizedTrailingView message={message} />
2027
- </TouchableOpacity>
2028
- </View>
2029
- );
2030
- }}
2031
- />
2032
- </View>
2033
- );
2034
- };
2035
-
2036
1765
  const renderResults = () => {
2037
1766
  const conversationsRendered = shouldRenderConversations();
2038
1767
  const messagesRendered = shouldRenderMessages();
@@ -2158,6 +1887,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
2158
1887
  mergedStyles={mergedStyles}
2159
1888
  theme={theme}
2160
1889
  conversationItemView={conversationItemView}
1890
+ textFormatters={textFormatters}
2161
1891
  />
2162
1892
  );
2163
1893