@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
@@ -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,44 @@ 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';
22
23
  import { ExtensionConstants } from '../extensions/ExtensionConstants';
23
24
  import { getExtensionData } from '../extensions/ExtensionModerator';
24
25
 
25
26
 
27
+ /** Module-level formatter for search previews — reused across renders (no GC churn). */
28
+ const searchRichTextFormatter = new CometChatRichTextFormatter();
29
+
30
+ /**
31
+ * Preview text for a search row: mention tokens resolved to @Name and markdown flattened, but the
32
+ * rich-text colour tokens are KEPT and painted, so a coloured message reads coloured in search
33
+ * exactly as it does in the conversation list row. Markdown is stripped before the formatter runs,
34
+ * so only colour runs remain — the result is always inline `<Text>`, never a block-level `View`.
35
+ * Returns a JSX element when the text carries colour, a plain string otherwise.
36
+ */
37
+ const formatPreviewText = (rawText: any, message?: CometChat.BaseMessage): string | JSX.Element => {
38
+ if (typeof rawText !== 'string') return rawText;
39
+
40
+ let text = stripMarkdown(rawText, true).replace(/<@all:(.*?)>/g, '@$1');
41
+
42
+ try {
43
+ const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
44
+ if (mentionedUsers && mentionedUsers.length > 0) {
45
+ mentionedUsers.forEach((u: CometChat.User) => {
46
+ const uid = u.getUid();
47
+ const name = u.getName();
48
+ if (uid && name) {
49
+ text = text.replace(new RegExp(`<@uid:${uid}>`, 'g'), `@${name}`);
50
+ }
51
+ });
52
+ }
53
+ } catch (e) {
54
+ console.log(e)
55
+ }
56
+
57
+ return searchRichTextFormatter.getFormattedText(text) ?? text;
58
+ };
59
+
26
60
  // ERROR HANDLER
27
61
  function useCometChatErrorHandler(onError?: (error: CometChat.CometChatException) => void) {
28
62
  return useCallback(
@@ -631,32 +665,6 @@ const ConversationItem = React.memo<ConversationItemProps>((
631
665
  );
632
666
  };
633
667
 
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
668
  if (conversationItemView) {
661
669
  return (
662
670
  <TouchableOpacity onPress={() => onPress(conversation, searchText)}>
@@ -676,7 +684,7 @@ const ConversationItem = React.memo<ConversationItemProps>((
676
684
  {conversation.getConversationWith().getName()}
677
685
  </Text>
678
686
  <Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
679
- {formatMentionsInText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
687
+ {formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
680
688
  </Text>
681
689
  </View>
682
690
  {renderTrailingView()}
@@ -1397,47 +1405,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1397
1405
  return undefined;
1398
1406
  };
1399
1407
 
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
1408
  // Get file type icon based on file extension
1442
1409
  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
1410
  if (!fileName) return 'unknown-file-type';
@@ -1488,34 +1455,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1488
1455
  return 'document-file-type';
1489
1456
  };
1490
1457
 
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
1458
  // Subtitle text for a media/file search result. Shows the message CAPTION when there is one,
1520
1459
  // otherwise a count summary ("N Videos" / "12 Files"). Photos/videos put their +N on the
1521
1460
  // thumbnail, so they show caption-or-count; files/audio have no thumbnail, so a caption is
@@ -1526,8 +1465,11 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1526
1465
  const atts =
1527
1466
  (typeof message.getAttachments === "function" ? message.getAttachments() : null) || [];
1528
1467
  const count = atts.length || 1;
1529
- const caption =
1530
- (typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || "";
1468
+ // The caption carries wire markup since ENG-38258, and it is concatenated with the count
1469
+ // label below — so it is flattened here, exactly as the conversation row flattens it.
1470
+ const caption = stripMarkdown(
1471
+ (typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || ""
1472
+ );
1531
1473
  const firstName =
1532
1474
  atts[0]?.getName?.() || (message.getAttachment?.() as any)?.getName?.() || "";
1533
1475
 
@@ -1566,16 +1508,17 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1566
1508
  return (sentByMe ? receiver?.getName?.() : message.getSender()?.getName?.()) || "";
1567
1509
  };
1568
1510
 
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 => {
1511
+ // Subtitle text for any message type (attachments delegate to the caption/count helper above;
1512
+ // everything else keeps the existing text/card/custom handling). Text messages come back as JSX
1513
+ // when they carry colour, so the row renders it instead of flattening it away.
1514
+ const getMessageSubtitleText = (message: CometChat.BaseMessage): string | JSX.Element => {
1572
1515
  const messageType = message.getType();
1573
1516
  if (["image", "video", "file", "audio"].includes(messageType)) {
1574
1517
  return getMediaSearchSubtitle(message as CometChat.MediaMessage);
1575
1518
  }
1576
1519
  if (messageType === "text") {
1577
- const raw = (message as CometChat.TextMessage).getText?.();
1578
- return formatMentionsInText(raw, message) || messageType || "Message";
1520
+ return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message)
1521
+ || messageType || "Message";
1579
1522
  }
1580
1523
  if (message.getCategory() === MessageCategoryConstants.card) {
1581
1524
  const cardText =
@@ -1792,247 +1735,11 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1792
1735
  (prev, next) => prev.message.getId() === next.message.getId()
1793
1736
  );
1794
1737
 
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
1738
  // Helper to format date for headers
1894
1739
  const getDateHeaderDate = useCallback((timestamp: number) => {
1895
1740
  return new Date(timestamp * 1000).toLocaleDateString('en-US', { month: 'long', year: 'numeric' });
1896
1741
  }, []);
1897
1742
 
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
1743
  const renderResults = () => {
2037
1744
  const conversationsRendered = shouldRenderConversations();
2038
1745
  const messagesRendered = shouldRenderMessages();
@@ -1,6 +1,6 @@
1
1
  let __listenerIdCounter = 0;
2
2
  import React, { useEffect, useState, useMemo, JSX } from "react";
3
- import { ScrollView, Text, View } from "react-native";
3
+ import { ScrollView, StyleSheet, Text, View } from "react-native";
4
4
  import {
5
5
  ChatConfigurator,
6
6
  CometChatMentionsFormatter,
@@ -96,6 +96,15 @@ export interface CometChatThreadHeaderInterface {
96
96
  textFormatters?: Array<
97
97
  CometChatMentionsFormatter | CometChatUrlsFormatter | CometChatTextFormatter
98
98
  >;
99
+ /**
100
+ * Replaces the trailing area of the reply-count bar entirely — the escape
101
+ * hatch for integrators who want their own control there.
102
+ *
103
+ * The follow/unfollow control is NOT here: on this platform the landed design
104
+ * places it in the message header's top bar, so it lives on
105
+ * CometChatMessageHeader (`parentMessage` + `threadSubscriptionVisibility`).
106
+ */
107
+ TrailingView?: (props: { parentMessage: CometChat.BaseMessage }) => JSX.Element;
99
108
  }
100
109
 
101
110
  /**
@@ -116,6 +125,7 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
116
125
  alignment,
117
126
  receiptsVisibility = true,
118
127
  avatarVisibility = true,
128
+ TrailingView,
119
129
  } = props;
120
130
  const [message, setMessage] = useState<CometChat.BaseMessage>(parentMessage);
121
131
  const [replyCount, setReplyCount] = useState<number>(parentMessage.getReplyCount() || 0);
@@ -283,7 +293,7 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
283
293
  </View>
284
294
  </ScrollView>
285
295
  {replyCountBarVisibility && (
286
- <View style={style?.replyCountBarStyle}>
296
+ <View style={[style?.replyCountBarStyle, staticStyles.replyCountBarRow]}>
287
297
  <Text style={style?.replyCountTextStyle}>
288
298
  {replyCountVisibility
289
299
  ? replyCount.toString() +
@@ -291,8 +301,18 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
291
301
  (replyCount == 1 ? t("REPLY") : t("REPLIES"))
292
302
  : ""}
293
303
  </Text>
304
+ {TrailingView && <TrailingView parentMessage={message} />}
294
305
  </View>
295
306
  )}
296
307
  </View>
297
308
  );
298
309
  };
310
+
311
+ const staticStyles = StyleSheet.create({
312
+ // Text on the leading edge, whatever TrailingView supplies on the trailing one.
313
+ replyCountBarRow: {
314
+ flexDirection: "row",
315
+ alignItems: "center",
316
+ justifyContent: "space-between",
317
+ },
318
+ });