@cometchat/chat-uikit-react-native 5.2.11 → 5.3.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 (93) hide show
  1. package/android/build.gradle +3 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +4 -1
  3. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +909 -10
  4. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorPackage.kt +24 -0
  5. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +5382 -0
  6. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +452 -0
  7. package/ios/FileManager.m +430 -3
  8. package/ios/RichTextEditorView.swift +5504 -0
  9. package/ios/RichTextEditorViewManager.m +66 -0
  10. package/ios/RichTextEditorViewManager.swift +291 -0
  11. package/ios/ToolbarIcons.swift +736 -0
  12. package/package.json +1 -1
  13. package/react-native-cometchat-ui-kit.podspec +1 -1
  14. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +4602 -0
  15. package/src/CometChatCompactMessageComposer/SingleLineTextComposerConfiguration.tsx +568 -0
  16. package/src/CometChatCompactMessageComposer/heightUtils.ts +204 -0
  17. package/src/CometChatCompactMessageComposer/index.ts +56 -0
  18. package/src/CometChatCompactMessageComposer/resources/index.ts +5 -0
  19. package/src/CometChatCompactMessageComposer/styles.ts +291 -0
  20. package/src/CometChatConversations/CometChatConversations.tsx +141 -14
  21. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +6 -0
  22. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +1 -20
  23. package/src/CometChatMessageComposer/styles.tsx +0 -1
  24. package/src/CometChatMessageList/CometChatMessageList.tsx +76 -30
  25. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +105 -0
  26. package/src/CometChatRichTextEditor/index.tsx +385 -0
  27. package/src/CometChatRichTextEditor/types.ts +162 -0
  28. package/src/CometChatSearch/CometChatSearch.tsx +35 -29
  29. package/src/calls/CallUtils.ts +4 -4
  30. package/src/index.ts +48 -1
  31. package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -0
  32. package/src/shared/constants/UIKitConstants.ts +12 -1
  33. package/src/shared/events/ListenerInitializer.ts +6 -0
  34. package/src/shared/events/messages.ts +2 -0
  35. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -5
  36. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +768 -0
  37. package/src/shared/formatters/index.ts +3 -0
  38. package/src/shared/framework/MessageDataSource.tsx +93 -2
  39. package/src/shared/helper/composerHelpers.ts +553 -0
  40. package/src/shared/helper/useKeyboard.tsx +7 -17
  41. package/src/shared/icons/components/code-blocks.tsx +13 -0
  42. package/src/shared/icons/components/code.tsx +11 -0
  43. package/src/shared/icons/components/format-bold.tsx +11 -0
  44. package/src/shared/icons/components/format-italic.tsx +11 -0
  45. package/src/shared/icons/components/format-list-bulleted.tsx +11 -0
  46. package/src/shared/icons/components/format-list-numbered.tsx +11 -0
  47. package/src/shared/icons/components/format-quote.tsx +13 -0
  48. package/src/shared/icons/components/format-strikethrough.tsx +13 -0
  49. package/src/shared/icons/components/format-underlined.tsx +11 -0
  50. package/src/shared/icons/components/smileys-&-people.tsx +1 -1
  51. package/src/shared/icons/icon-mapping.tsx +18 -0
  52. package/src/shared/index.ts +54 -2
  53. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +37 -32
  54. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +5 -0
  55. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +17 -12
  56. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -500
  57. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +18 -13
  58. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +17 -12
  59. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -499
  60. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -499
  61. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -499
  62. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +18 -13
  63. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +17 -12
  64. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -500
  65. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +17 -12
  66. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +17 -12
  67. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +18 -13
  68. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -500
  69. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +17 -12
  70. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +18 -13
  71. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
  72. package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
  73. package/src/shared/utils/CommonUtils.ts +18 -1
  74. package/src/shared/utils/MarkdownUtils.ts +143 -0
  75. package/src/shared/utils/MentionUtils.ts +37 -0
  76. package/src/shared/utils/MessageReceiptUtils.ts +5 -4
  77. package/src/shared/utils/MessageUtils.tsx +5 -3
  78. package/src/shared/utils/index.ts +5 -0
  79. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +1 -1
  80. package/src/shared/views/CometChatInlineAudioRecorder/AudioWaveformVisualizer.tsx +417 -0
  81. package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +537 -0
  82. package/src/shared/views/CometChatInlineAudioRecorder/index.ts +34 -0
  83. package/src/shared/views/CometChatInlineAudioRecorder/style.ts +155 -0
  84. package/src/shared/views/CometChatInlineAudioRecorder/types.ts +303 -0
  85. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +1336 -0
  86. package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +183 -0
  87. package/src/shared/views/CometChatLinkConfirmPopup/index.ts +13 -0
  88. package/src/shared/views/CometChatLinkConfirmPopup/style.ts +128 -0
  89. package/src/shared/views/CometChatList/Header.tsx +2 -1
  90. package/src/shared/views/CometChatListItem/style.ts +1 -0
  91. package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
  92. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +64 -16
  93. package/src/shared/views/index.ts +39 -0
@@ -11,7 +11,7 @@
11
11
  */
12
12
  import { CometChat } from "@cometchat/chat-sdk-react-native";
13
13
  import React, { useCallback, useMemo } from "react";
14
- import { Text, View, GestureResponderEvent } from "react-native";
14
+ import { Text, View, GestureResponderEvent, Platform, StyleSheet } from "react-native";
15
15
  import {
16
16
  ChatConfigurator,
17
17
  CometChatAvatar,
@@ -41,6 +41,8 @@ import {
41
41
  import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
42
42
  import { Icon } from "../shared/icons/Icon";
43
43
  import { CommonUtils } from "../shared/utils/CommonUtils";
44
+ import { stripMarkdown, preparePreviewText } from "../shared/utils/MarkdownUtils";
45
+ import { CometChatRichTextFormatter } from "../shared/formatters/CometChatRichTextFormatter";
44
46
  import { getMessagePreviewInternal } from "../shared/utils/MessageUtils";
45
47
  import { CometChatBadge } from "../shared/views/CometChatBadge";
46
48
  import { CometChatConfirmDialog } from "../shared/views/CometChatConfirmDialog";
@@ -68,6 +70,9 @@ const groupListenerId = "chatlist_group_" + new Date().getTime();
68
70
  const messageListenerId = "chatlist_message_" + new Date().getTime();
69
71
  const callListenerId = "call_" + new Date().getTime();
70
72
 
73
+ /** Module-level rich text formatter — reused across renders (no GC churn) */
74
+ const conversationRichTextFormatter = new CometChatRichTextFormatter();
75
+
71
76
  /**
72
77
  * Interface defining props for the CometChatConversations component.
73
78
  */
@@ -322,6 +327,22 @@ export const CometChatConversations = (props: ConversationInterface) => {
322
327
  // Merge theme styles with provided style overrides.
323
328
  const theme = useTheme();
324
329
  const { t } = useCometChatTranslation()
330
+
331
+ // Configure conversation subtitle formatter with theme-aware inline code colors
332
+ useMemo(() => {
333
+ conversationRichTextFormatter.setStyle({
334
+ inlineCodeStyle: {
335
+ color: theme.color.primary as string,
336
+ },
337
+ inlineCodeContainerStyle: {
338
+ backgroundColor: theme.color.background3 as string,
339
+ borderRadius: 2,
340
+ paddingHorizontal: 2,
341
+ paddingVertical: 0,
342
+ },
343
+ });
344
+ }, [theme]);
345
+
325
346
  const mergedStyles = useMemo(() => {
326
347
  const baseStyles = deepMerge(theme.conversationStyles, style ?? {});
327
348
  // Add search styling for CometChatList component
@@ -647,8 +668,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
647
668
  if (
648
669
  conv &&
649
670
  conv?.getLastMessage &&
650
- (conv.getLastMessage().id == receipt.getMessageId() ||
651
- conv.getLastMessage().messageId == receipt.getMessageId())
671
+ (String(typeof conv.getLastMessage().getId === 'function' ? conv.getLastMessage().getId() : conv.getLastMessage().id) === String(receipt.getMessageId()))
652
672
  ) {
653
673
  let newConversation = CommonUtils.clone(conv);
654
674
  if (receipt.getReadAt()) {
@@ -815,20 +835,74 @@ export const CometChatConversations = (props: ConversationInterface) => {
815
835
  let messageText: string | JSX.Element = "";
816
836
  messageText = ChatConfigurator.getDataSource().getLastConversationMessage(conversations, theme);
817
837
 
818
- if (lastMessage && typeof messageText === "string") {
838
+ // Detect block-level elements in text messages before stripMarkdown flattens them
839
+ let blockType: 'blockquote' | 'codeBlock' | 'list' | null = null;
840
+ let codeBlockLine = '';
841
+ let listPrefix = '';
842
+ if (
843
+ lastMessage instanceof CometChat.TextMessage &&
844
+ lastMessage.getCategory() === MessageCategoryConstants.message &&
845
+ typeof messageText === "string"
846
+ ) {
847
+ const rawText = messageText;
848
+ const preview = preparePreviewText(rawText);
849
+ if (preview.isBlockquote) {
850
+ blockType = 'blockquote';
851
+ // Run formatter on content only (no `> ` prefix) so it won't re-parse as block
852
+ messageText = getFormattedText(lastMessage, preview.text.trim());
853
+ } else if (preview.codeBlockFirstLine !== null) {
854
+ blockType = 'codeBlock';
855
+ codeBlockLine = preview.codeBlockFirstLine;
856
+ } else if (preview.listPrefix) {
857
+ blockType = 'list';
858
+ listPrefix = preview.listPrefix;
859
+ messageText = getFormattedText(lastMessage, preview.text.trim());
860
+ } else {
861
+ messageText = getFormattedText(lastMessage, preview.text.trim());
862
+ }
863
+ } else if (lastMessage && typeof messageText === "string") {
819
864
  messageText = getFormattedText(lastMessage, messageText?.trim());
820
865
  }
866
+
821
867
  if (
822
868
  lastMessage instanceof CometChat.TextMessage &&
823
- lastMessage.getCategory() === "message" &&
869
+ lastMessage.getCategory() === MessageCategoryConstants.message &&
824
870
  (() => {
825
- // Guard against undefined text or non-string values.
826
871
  const text = typeof lastMessage.getText === "function" ? lastMessage.getText() : undefined;
827
872
  return typeof text === "string" && text.slice(0, 50).match(/https?:\/\//);
828
873
  })()
829
874
  ) {
830
875
  messageText = getMessagePreviewInternal("link-fill", t("LINK"), { theme });
831
- } else if (messageText) {
876
+ } else if (blockType === 'codeBlock') {
877
+ messageText = (
878
+ <View style={conversationPreviewStyles.codeBlockRow}>
879
+ <View style={[conversationPreviewStyles.codeBlockBadge, { backgroundColor: theme?.color?.background2 as string || '#FAFAFA', borderColor: theme?.color?.borderDefault as string || '#E8E8E8' }]}>
880
+ <Text numberOfLines={1} ellipsizeMode='tail' style={[conversationPreviewStyles.codeBlockText, { color: theme?.color?.textPrimary as string || '#141414' }]}>
881
+ {codeBlockLine + '..'}
882
+ </Text>
883
+ </View>
884
+ </View>
885
+ );
886
+ } else if (blockType === 'blockquote') {
887
+ messageText = (
888
+ <View style={conversationPreviewStyles.blockquoteRow}>
889
+ <View style={[conversationPreviewStyles.blockquoteBar, { backgroundColor: theme?.color?.primary as string }]} />
890
+ <Text numberOfLines={1} ellipsizeMode='tail' style={[mergedStyles.itemStyle.subtitleStyle, conversationPreviewStyles.blockquoteText]}>
891
+ {messageText}
892
+ </Text>
893
+ </View>
894
+ );
895
+ } else if (blockType === 'list') {
896
+ messageText = (
897
+ <Text
898
+ style={[mergedStyles.itemStyle.subtitleStyle, { flexShrink: 2 }]}
899
+ numberOfLines={1}
900
+ ellipsizeMode='tail'
901
+ >
902
+ {listPrefix}{messageText}{'...'}
903
+ </Text>
904
+ );
905
+ } else if (messageText && typeof messageText === 'string') {
832
906
  messageText = (
833
907
  <Text
834
908
  style={[mergedStyles.itemStyle.subtitleStyle, { flexShrink: 2 }]}
@@ -874,11 +948,24 @@ export const CometChatConversations = (props: ConversationInterface) => {
874
948
  * @returns The formatted text.
875
949
  */
876
950
  function getFormattedText(message: CometChat.BaseMessage, subtitle: string) {
877
- let messageTextTmp: string | JSX.Element = subtitle;
951
+ // For text messages, use the rich text formatter to preserve inline styles
952
+ // (bold, italic, underline, strikethrough, inline code). The subtitle has
953
+ // already been processed by preparePreviewText which strips block-level
954
+ // markers, so the formatter will only encounter inline formatting.
955
+ let messageTextTmp: string | JSX.Element;
956
+ if (
957
+ message instanceof CometChat.TextMessage &&
958
+ message.getCategory() === MessageCategoryConstants.message
959
+ ) {
960
+ const formatted = conversationRichTextFormatter.getFormattedText(subtitle);
961
+ messageTextTmp = formatted ?? subtitle;
962
+ } else {
963
+ // Non-text messages: strip markdown as before
964
+ messageTextTmp = stripMarkdown(subtitle);
965
+ }
878
966
  let allFormatters = [...(textFormatters || [])];
879
- // Detect presence of @all alias token in raw string
880
- const containsAllAlias =
881
- typeof messageTextTmp === "string" && /<@all:(.*?)>/.test(messageTextTmp);
967
+ // Detect presence of @all alias token in raw subtitle string (before formatting)
968
+ const containsAllAlias = /<@all:(.*?)>/.test(subtitle);
882
969
 
883
970
  if (message.getMentionedUsers().length || containsAllAlias) {
884
971
  let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
@@ -890,7 +977,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
890
977
 
891
978
  // Inject alias suggestion item if needed so formatter can render styled @All
892
979
  if (containsAllAlias) {
893
- const match = (messageTextTmp as string).match(/<@all:(.*?)>/);
980
+ const match = subtitle.match(/<@all:(.*?)>/);
894
981
  const aliasLabel = match && match[1] ? match[1] : "all";
895
982
  let existing = mentionsFormatter.getSuggestionItems();
896
983
  const underlyingText = `<@all:${aliasLabel}>`;
@@ -913,7 +1000,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
913
1000
 
914
1001
  if (
915
1002
  message instanceof CometChat.TextMessage &&
916
- message.getCategory() === "message" &&
1003
+ message.getCategory() === MessageCategoryConstants.message &&
917
1004
  (() => {
918
1005
  const text = typeof message.getText === "function" ? message.getText() : undefined;
919
1006
  return typeof text === "string" && text.slice(0, 50).match(/https?:\/\//);
@@ -1617,7 +1704,6 @@ export const CometChatConversations = (props: ConversationInterface) => {
1617
1704
 
1618
1705
  return (
1619
1706
  <View style={[
1620
- { flex: 1 },
1621
1707
  isAgentic ? { justifyContent: 'center' } : null
1622
1708
  ]}>
1623
1709
  <Text
@@ -1765,3 +1851,44 @@ export const CometChatConversations = (props: ConversationInterface) => {
1765
1851
  </View>
1766
1852
  );
1767
1853
  };
1854
+
1855
+ // Static styles for conversation preview block-level elements (code block, blockquote, list).
1856
+ // Theme-dependent values (colors) are applied inline via style array merging.
1857
+ const conversationPreviewStyles = StyleSheet.create({
1858
+ codeBlockRow: {
1859
+ flexDirection: 'row',
1860
+ alignItems: 'center',
1861
+ flexShrink: 2,
1862
+ },
1863
+ codeBlockBadge: {
1864
+ borderRadius: 4,
1865
+ borderWidth: 1,
1866
+ paddingHorizontal: 6,
1867
+ paddingVertical: 2,
1868
+ flexShrink: 1,
1869
+ },
1870
+ codeBlockText: {
1871
+ fontFamily: Platform.OS === 'ios' ? 'Menlo' : 'monospace',
1872
+ fontSize: 11,
1873
+ },
1874
+ blockquoteRow: {
1875
+ flexDirection: 'row',
1876
+ alignItems: 'stretch',
1877
+ backgroundColor: 'rgba(104, 81, 214, 0.08)',
1878
+ borderRadius: 6,
1879
+ flexShrink: 2,
1880
+ minHeight: 22,
1881
+ paddingVertical: 1,
1882
+ },
1883
+ blockquoteBar: {
1884
+ width: 3,
1885
+ borderRadius: 1.5,
1886
+ marginVertical: 3,
1887
+ marginLeft: 4,
1888
+ },
1889
+ blockquoteText: {
1890
+ flex: 1,
1891
+ paddingHorizontal: 5,
1892
+ lineHeight: 18,
1893
+ },
1894
+ });
@@ -454,6 +454,8 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
454
454
  action.setSender(loggedInUser.current);
455
455
  action.setReceiver(group);
456
456
  action.setConversationId("group_" + group.getGuid());
457
+ // Initialize data to prevent crash when SDK accesses getData().metadata during render
458
+ action.setData({ metadata: {} });
457
459
 
458
460
  // Emit the group event for a kicked member.
459
461
  CometChatUIEventHandler.emitGroupEvent(CometChatGroupsEvents.ccGroupMemberKicked, {
@@ -496,6 +498,8 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
496
498
  action.setMuid(String(getUnixTimestampInMilliseconds()));
497
499
  action.setSender(loggedInUser.current);
498
500
  action.setReceiver(group);
501
+ // Initialize data to prevent crash when SDK accesses getData().metadata during render
502
+ action.setData({ metadata: {} });
499
503
  group.setMembersCount(group.getMembersCount() - 1);
500
504
 
501
505
  // Emit the group event for a banned member.
@@ -928,6 +932,8 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
928
932
  action.setMuid(String(getUnixTimestampInMilliseconds()));
929
933
  action.setSender(loggedInUser.current);
930
934
  action.setReceiver(group);
935
+ // Initialize data to prevent crash when SDK accesses getData().metadata during render
936
+ action.setData({ metadata: {} });
931
937
 
932
938
  // Emit the group event for a scope change.
933
939
  CometChatUIEventHandler.emitGroupEvent(
@@ -55,6 +55,7 @@ import {
55
55
  messageStatus,
56
56
  } from "../shared/utils/CometChatMessageHelper";
57
57
  import { CommonUtils } from "../shared/utils/CommonUtils";
58
+ import { isCursorWithinMentionRange, getMentionRangeAtCursor } from "../shared/utils/MentionUtils";
58
59
  import { permissionUtil } from "../shared/utils/PermissionUtil";
59
60
  import { CometChatMediaRecorder } from "../shared/views/CometChatMediaRecorder";
60
61
  import { useTheme } from "../theme";
@@ -1673,26 +1674,6 @@ export const CometChatMessageComposer = React.forwardRef(
1673
1674
  // console.log("Send Audio"); // Removed debug log
1674
1675
  };
1675
1676
 
1676
- function isCursorWithinMentionRange(mentionRanges: any, cursorPosition: number) {
1677
- for (let [range, mention] of mentionRanges) {
1678
- const [start, end] = range.split("_").map(Number);
1679
- if (cursorPosition >= start && cursorPosition <= end) {
1680
- return true; // Cursor is within the range of a mention
1681
- }
1682
- }
1683
- return false; // No mention found at the cursor position
1684
- }
1685
-
1686
- function getMentionRangeAtCursor(mentionRanges: any, cursorPosition: number): { start: number; end: number } | null {
1687
- for (let [range] of mentionRanges) {
1688
- const [start, end] = range.split("_").map(Number);
1689
- if (cursorPosition >= start && cursorPosition <= end) {
1690
- return { start, end }; // Return the boundary positions
1691
- }
1692
- }
1693
- return null; // No mention found at the cursor position
1694
- }
1695
-
1696
1677
  function shouldOpenList(
1697
1678
  selection: {
1698
1679
  start: number;
@@ -7,7 +7,6 @@ import {
7
7
  ViewStyle,
8
8
  } from "react-native";
9
9
  import { ActionSheetStyle, CometChatTheme } from "../theme/type";
10
- import { Icon } from "../shared/icons/Icon";
11
10
  import { DeepPartial } from "../shared/helper/types";
12
11
  import { JSX } from "react";
13
12
 
@@ -936,11 +936,17 @@ export const CometChatMessageList = memo(
936
936
  const [itemPositions, setItemPositions] = useState<Map<string, { y: number; height: number }>>(new Map());
937
937
  const markUnreadMessageAsRead = (message?: CometChat.BaseMessage) => {
938
938
  const messageToMark = message || messagesContentListRef.current[0];
939
- if (messageToMark) {
939
+ if (
940
+ messageToMark &&
941
+ messageToMark.getSender?.()?.getUid() !== loggedInUser.current?.getUid()
942
+ ) {
940
943
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
941
944
  message: messageToMark,
942
945
  });
943
- CometChat.markAsRead(messageToMark);
946
+ CometChat.markAsRead(messageToMark).catch((error: any) => {
947
+ console.log("Error marking unread message as read", error);
948
+ onError && onError(error);
949
+ });
944
950
  setUnreadCount(0);
945
951
  }
946
952
  };
@@ -1107,7 +1113,9 @@ export const CometChatMessageList = memo(
1107
1113
 
1108
1114
  } else {
1109
1115
  for (let index = 0; index < previousMessagesFetched.length; index++) {
1110
- const message: CometChat.BaseMessage = previousMessagesFetched[index];
1116
+ CometChat.markAsRead(message).catch((error: any) => {
1117
+ console.log("Error marking message as read", error);
1118
+ });sage = previousMessagesFetched[index];
1111
1119
  if (
1112
1120
  message &&
1113
1121
  !message.hasOwnProperty("readAt") &&
@@ -1697,7 +1705,10 @@ export const CometChatMessageList = memo(
1697
1705
  }, []);
1698
1706
 
1699
1707
  const markMessageAsRead = (message: any) => {
1700
- if (!message?.readAt) {
1708
+ if (
1709
+ !message?.readAt &&
1710
+ message?.getSender?.()?.getUid() !== loggedInUser.current?.getUid()
1711
+ ) {
1701
1712
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, { message });
1702
1713
  CometChat.markAsRead(message).catch((error: any) => {
1703
1714
  console.log("Error", error);
@@ -1952,6 +1963,7 @@ export const CometChatMessageList = memo(
1952
1963
  addToMessageList(newMessage);
1953
1964
  }
1954
1965
  scrollToBottom();
1966
+
1955
1967
  markMessageAsRead(newMessage);
1956
1968
  latestMessageRef.current = newMessage;
1957
1969
  } else {
@@ -2202,9 +2214,13 @@ export const CometChatMessageList = memo(
2202
2214
  ) {
2203
2215
  return;
2204
2216
  }
2217
+ // Use getter method for messageId (SDK receipt objects expose it via getMessageId())
2218
+ let receiptMessageId = typeof receipt.getMessageId === 'function' ? receipt.getMessageId() : receipt["messageId"];
2205
2219
  let index = messagesContentListRef.current.findIndex(
2206
- (msg, index) =>
2207
- msg["id"] == receipt["messageId"] || msg["messageId"] == receipt["messageId"]
2220
+ (msg) => {
2221
+ const msgId = typeof msg.getId === 'function' ? msg.getId() : msg["id"];
2222
+ return String(msgId) === String(receiptMessageId);
2223
+ }
2208
2224
  );
2209
2225
 
2210
2226
  if (index == -1) return;
@@ -2786,15 +2802,16 @@ export const CometChatMessageList = memo(
2786
2802
  inConnecting: () => { },
2787
2803
  onDisconnected: () => {
2788
2804
  streamOnDisconnected();
2789
- if (!messagesList[0].id) {
2790
- for (let i = 0; i < messagesList.length; i++) {
2791
- if (messagesList[i].id) {
2792
- lastID.current = messagesList[i].id;
2805
+ const currentMessages = messagesContentListRef.current;
2806
+ if (currentMessages.length > 0 && !currentMessages[0].id) {
2807
+ for (let i = 0; i < currentMessages.length; i++) {
2808
+ if (currentMessages[i].id) {
2809
+ lastID.current = currentMessages[i].id;
2793
2810
  break;
2794
2811
  }
2795
2812
  }
2796
- } else {
2797
- lastID.current = messagesList[0].id;
2813
+ } else if (currentMessages.length > 0) {
2814
+ lastID.current = currentMessages[0].id;
2798
2815
  }
2799
2816
  },
2800
2817
  })
@@ -2816,7 +2833,7 @@ export const CometChatMessageList = memo(
2816
2833
  }
2817
2834
  }
2818
2835
  };
2819
- }, [unreadCount, user, group, isAgenticUser, messagesList]);
2836
+ }, [unreadCount, user, group, isAgenticUser]);
2820
2837
 
2821
2838
  useEffect(() => {
2822
2839
  if (aiAssistantTools) {
@@ -2934,7 +2951,7 @@ export const CometChatMessageList = memo(
2934
2951
  return item.getType();
2935
2952
  })();
2936
2953
 
2937
- if (item.getSender().getUid() != loggedInUser.current.getUid()) {
2954
+ if (item.getSender()?.getUid() != loggedInUser.current?.getUid()) {
2938
2955
  return (
2939
2956
  overridenBubbleStyles.get(type)?.incoming ??
2940
2957
  mergedTheme.messageListStyles.incomingMessageBubbleStyles
@@ -3329,7 +3346,12 @@ export const CometChatMessageList = memo(
3329
3346
  const copyMessage = (item: any) => {
3330
3347
  let copyMessage = getPlainString(item["text"], item);
3331
3348
  Clipboard.setString(copyMessage);
3332
- setShowMessageOptions([]);
3349
+ // Defer modal dismiss to next frame to avoid Fabric race condition
3350
+ // where unmounting the Modal while Clipboard is still accessing views
3351
+ // causes EXC_BAD_ACCESS (SIGSEGV) at null pointer in mount phase.
3352
+ requestAnimationFrame(() => {
3353
+ setShowMessageOptions([]);
3354
+ });
3333
3355
  };
3334
3356
 
3335
3357
  const getThreadView = useCallback(
@@ -3513,19 +3535,43 @@ export const CometChatMessageList = memo(
3513
3535
  isThreaded?: boolean;
3514
3536
  currentIndex?: number;
3515
3537
  }) => {
3516
- const { message, showOptions = true, isThreaded = false, currentIndex } = params;
3517
- const hasTemplate = useMemo(() => {
3518
- const defaultTemplate = templatesMap.get(
3519
- `${message.getCategory()}_${message.getType()}`
3520
- );
3521
-
3522
- if (templates?.length > 0) {
3523
- const customTemplate = templates.find(
3524
- (template) =>
3525
- template.type === message.getType() && template.category === message.getCategory()
3526
- );
3527
- return customTemplate ?? defaultTemplate;
3528
- }
3538
+ const { message, showOptions = true, isThreaded = false, currentIndex } = params
3539
+
3540
+           const hasTemplate = useMemo(() => {
3541
+             // Detect InteractiveMessage instances where Object.assign
3542
+             // (from mergeObjects during history fetch dedup) overwrote `category` and `type`
3543
+             let lookupCategory: string = message.getCategory();
3544
+             let lookupType: string = message.getType();
3545
+
3546
+             const hasInteractiveData =
3547
+               typeof (message as any).getInteractiveData === 'function' &&
3548
+               (message as any).getInteractiveData() != null;
3549
+
3550
+             if (hasInteractiveData && lookupCategory !== MessageCategoryConstants.interactive) {
3551
+               lookupCategory = MessageCategoryConstants.interactive;
3552
+               const interactiveData = (message as any).getInteractiveData();
3553
+               if (interactiveData?.formFields) {
3554
+                 lookupType = MessageTypeConstants.form;
3555
+               } else if (interactiveData?.scheduleElement || interactiveData?.timezoneCode) {
3556
+                 lookupType = MessageTypeConstants.scheduler;
3557
+               } else if (interactiveData?.cardActions) {
3558
+                 lookupType = MessageTypeConstants.card;
3559
+               }
3560
+               (message as any).category = lookupCategory;
3561
+               (message as any).type = lookupType;
3562
+             }
3563
+
3564
+             const defaultTemplate = templatesMap.get(
3565
+               `${lookupCategory}_${lookupType}`
3566
+             );
3567
+
3568
+             if (templates?.length > 0) {
3569
+               const customTemplate = templates.find(
3570
+                 (template) =>
3571
+                   template.type === lookupType && template.category === lookupCategory
3572
+               );
3573
+               return customTemplate ?? defaultTemplate;
3574
+             }
3529
3575
 
3530
3576
  return defaultTemplate;
3531
3577
  }, [message, templatesMap, templates]);
@@ -3572,10 +3618,10 @@ export const CometChatMessageList = memo(
3572
3618
 
3573
3619
  const BottomView = useMemo(() => {
3574
3620
  const moderationStatus = getModerationStatus(message);
3575
- const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
3621
+ const isOutgoing = message?.getSender?.()?.getUid() === loggedInUser.current?.getUid();
3576
3622
 
3577
3623
  // Check for MIME type error (ERR_PERMISSION_DENIED)
3578
- const hasErrorMetadata = (message as any)?.getData?.()?.metaData?.error;
3624
+ const hasErrorMetadata = message?.getData?.()?.metaData?.error;
3579
3625
  const hasErrorInMetadata = (message as any)?.getMetadata?.()?.error;
3580
3626
  if (isOutgoing && (hasErrorMetadata || hasErrorInMetadata) && !isAgenticUser) {
3581
3627
  return (
@@ -0,0 +1,105 @@
1
+ import type { ViewProps, HostComponent } from 'react-native';
2
+ import { requireNativeComponent } from 'react-native';
3
+
4
+ type Double = number;
5
+ type Int32 = number;
6
+ type DirectEventHandler<T> = (event: { nativeEvent: T }) => void;
7
+
8
+ // New prop types for CometChat integration
9
+ type SelectionProp = Readonly<{
10
+ start: Int32;
11
+ end: Int32;
12
+ }>;
13
+
14
+ type TextStyleProp = Readonly<{
15
+ fontSize?: Double;
16
+ color?: string;
17
+ fontFamily?: string;
18
+ }>;
19
+
20
+ export type StyleRange = Readonly<{
21
+ style: string;
22
+ start: Int32;
23
+ end: Int32;
24
+ url?: string;
25
+ highlightColor?: string;
26
+ }>;
27
+
28
+ export type Block = Readonly<{
29
+ type: string;
30
+ text: string;
31
+ styles: ReadonlyArray<StyleRange>;
32
+ alignment?: string;
33
+ checked?: boolean;
34
+ indentLevel?: Int32;
35
+ }>;
36
+
37
+ type ContentChangeEventData = Readonly<{
38
+ text: string;
39
+ blocksJson: string;
40
+ }>;
41
+
42
+ type SelectionChangeEventData = Readonly<{
43
+ start: Int32;
44
+ end: Int32;
45
+ }>;
46
+
47
+ type SizeChangeEventData = Readonly<{
48
+ height: Double;
49
+ }>;
50
+
51
+ type ActiveStylesEventData = Readonly<{
52
+ bold: boolean;
53
+ italic: boolean;
54
+ underline: boolean;
55
+ strikethrough: boolean;
56
+ code: boolean;
57
+ codeBlock: boolean;
58
+ highlight: boolean;
59
+ blockType: string;
60
+ alignment: string;
61
+ }>;
62
+
63
+ type LinkTapEventData = Readonly<{
64
+ url: string;
65
+ text: string;
66
+ location: Int32;
67
+ length: Int32;
68
+ }>;
69
+
70
+ export interface NativeProps extends ViewProps {
71
+ placeholder?: string;
72
+ editable?: boolean;
73
+ maxHeight?: Double;
74
+ numberOfLines?: Int32;
75
+ showToolbar?: boolean;
76
+ toolbarOptions?: ReadonlyArray<string>;
77
+ variant?: string;
78
+ initialContentJson?: string;
79
+ toolbarMode?: string;
80
+ enterKeyBehavior?: string;
81
+
82
+ // New props for CometChat integration
83
+ selection?: SelectionProp;
84
+ textStyle?: TextStyleProp;
85
+ placeholderTextColor?: string;
86
+ text?: string;
87
+ showTextSelectionMenuItems?: boolean;
88
+ codeBackgroundColor?: string;
89
+ codeBorderColor?: string;
90
+ codeTextColor?: string;
91
+ codeFontSize?: Double;
92
+
93
+ onContentChange?: DirectEventHandler<ContentChangeEventData>;
94
+ onSelectionChange?: DirectEventHandler<SelectionChangeEventData>;
95
+ onEditorFocus?: DirectEventHandler<Readonly<{}>>;
96
+ onEditorBlur?: DirectEventHandler<Readonly<{}>>;
97
+ onSizeChange?: DirectEventHandler<SizeChangeEventData>;
98
+ onActiveStylesChange?: DirectEventHandler<ActiveStylesEventData>;
99
+ onLinkTap?: DirectEventHandler<LinkTapEventData>;
100
+ onSendRequest?: DirectEventHandler<Readonly<{}>>;
101
+ }
102
+
103
+ export default requireNativeComponent<NativeProps>(
104
+ 'RichTextEditorView',
105
+ ) as HostComponent<NativeProps>;