@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
@@ -1,10 +1,13 @@
1
1
  import { CometChatMentionsFormatter, MentionTextStyle } from "./CometChatMentionsFormatter";
2
2
  import { CometChatTextFormatter } from "./CometChatTextFormatter";
3
3
  import { CometChatUrlsFormatter } from "./CometChatUrlsFormatter";
4
+ import { CometChatRichTextFormatter, RichTextStyle } from "./CometChatRichTextFormatter";
4
5
 
5
6
  export {
6
7
  CometChatMentionsFormatter,
7
8
  CometChatTextFormatter,
8
9
  CometChatUrlsFormatter,
10
+ CometChatRichTextFormatter,
9
11
  MentionTextStyle,
12
+ RichTextStyle,
10
13
  };
@@ -5,6 +5,7 @@ import {
5
5
  CometChatTextFormatter,
6
6
  CometChatUIKit,
7
7
  CometChatUrlsFormatter,
8
+ CometChatRichTextFormatter,
8
9
  } from "../..";
9
10
  import { CometChatTheme } from "../../theme/type";
10
11
  import {
@@ -40,7 +41,7 @@ import CometChatStreamMessageBubble from '../views/CometChatStreamMessageBubble/
40
41
  import { ChatConfigurator } from "./ChatConfigurator";
41
42
  import { DataSource } from "./DataSource";
42
43
  import { CommonUtils } from "../utils/CommonUtils";
43
- import { DimensionValue, TouchableOpacity, ViewStyle, View, Text } from "react-native";
44
+ import { DimensionValue, TouchableOpacity, ViewStyle, View, Text, Platform } from "react-native";
44
45
  import Clipboard from "@react-native-clipboard/clipboard";
45
46
  import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/LocalizationManager";
46
47
  import { CometChatMessageEvents } from "../events/CometChatMessageEvents";
@@ -1143,6 +1144,86 @@ export class MessageDataSource implements DataSource {
1143
1144
  loggedInUser!,
1144
1145
  theme
1145
1146
  );
1147
+
1148
+ // Create rich text formatter for markdown parsing
1149
+ let richTextFormatter = new CometChatRichTextFormatter(loggedInUser!);
1150
+ richTextFormatter.setMessage(message);
1151
+ richTextFormatter.setId("ccDefaultRichTextFormatterId");
1152
+ // Use same link color as CometChatUrlsFormatter for consistency
1153
+ // Inline code styles differ for sent vs received bubbles per Figma spec
1154
+ richTextFormatter.setStyle({
1155
+ linkStyle: {
1156
+ color: isMessageSentByLoggedInUser ? theme.color.sendBubbleLink : theme.color.receiveBubbleLink,
1157
+ textDecorationLine: 'underline',
1158
+ },
1159
+ inlineCodeStyle: isMessageSentByLoggedInUser
1160
+ ? {
1161
+ fontSize: theme.typography.body.regular.fontSize,
1162
+ fontWeight: '400',
1163
+ lineHeight: ((theme.typography.body.regular.fontSize as number) ?? 14) * 1.2,
1164
+ color: theme.color.sendBubbleTextHighlight,
1165
+ }
1166
+ : {
1167
+ fontSize: theme.typography.body.regular.fontSize,
1168
+ fontWeight: '400',
1169
+ lineHeight: ((theme.typography.body.regular.fontSize as number) ?? 14) * 1.2,
1170
+ color: theme.color.receiveBubbleTextHighlight,
1171
+ },
1172
+ inlineCodeContainerStyle: isMessageSentByLoggedInUser
1173
+ ? {
1174
+ backgroundColor: `${String(theme.color.extendedPrimary50)}33`, // 20% opacity
1175
+ borderRadius: 2,
1176
+ paddingHorizontal: 2,
1177
+ paddingVertical: 0,
1178
+ }
1179
+ : {
1180
+ backgroundColor: theme.color.background3,
1181
+ borderRadius: 2,
1182
+ paddingHorizontal: 2,
1183
+ paddingVertical: 0,
1184
+ },
1185
+ // Code block styles per Figma spec — monospace font in a rounded container
1186
+ codeBlockStyle: {
1187
+ fontFamily: Platform.OS === "ios" ? "Menlo" : "monospace",
1188
+ fontSize: 13,
1189
+ color: isMessageSentByLoggedInUser
1190
+ ? theme.color.sendBubbleText
1191
+ : theme.color.receiveBubbleText,
1192
+ },
1193
+ codeBlockContainerStyle: isMessageSentByLoggedInUser
1194
+ ? {
1195
+ backgroundColor: 'rgba(255,255,255,0.1)',
1196
+ borderRadius: 4,
1197
+ borderWidth: 1,
1198
+ borderColor: 'rgba(255,255,255,0.2)',
1199
+ padding: 12,
1200
+ }
1201
+ : {
1202
+ backgroundColor: theme.color.background2,
1203
+ borderRadius: 4,
1204
+ borderWidth: 1,
1205
+ borderColor: theme.color.borderDefault,
1206
+ padding: 12,
1207
+ },
1208
+ // Blockquote styles per Figma spec — rounded container with left bar
1209
+ blockquoteContainerStyle: isMessageSentByLoggedInUser
1210
+ ? {
1211
+ backgroundColor: 'rgba(255,255,255,0.2)',
1212
+ borderRadius: theme.spacing.radius.r2,
1213
+ }
1214
+ : {
1215
+ backgroundColor: theme.color.background3,
1216
+ borderRadius: theme.spacing.radius.r2,
1217
+ },
1218
+ blockquoteBarStyle: isMessageSentByLoggedInUser
1219
+ ? {
1220
+ backgroundColor: 'rgba(255,255,255,0.6)',
1221
+ }
1222
+ : {
1223
+ backgroundColor: theme.color.primary,
1224
+ },
1225
+ });
1226
+
1146
1227
  mentionsTextFormatter.setContext(isMessageSentByLoggedInUser ? MentionContext.Outgoing : MentionContext.Incoming);
1147
1228
  linksTextFormatter.setMessage(message);
1148
1229
  linksTextFormatter.setId("ccDefaultUrlsFormatterId");
@@ -1161,6 +1242,7 @@ export class MessageDataSource implements DataSource {
1161
1242
 
1162
1243
  let urlFormatterExists = false;
1163
1244
  let mentionsFormatterExists = false;
1245
+ let richTextFormatterExists = false;
1164
1246
 
1165
1247
  for (const formatter of textFormatters) {
1166
1248
  if (formatter instanceof CometChatUrlsFormatter) {
@@ -1175,13 +1257,22 @@ export class MessageDataSource implements DataSource {
1175
1257
  formatter.setContext(isMessageSentByLoggedInUser ? "outgoing" : "incoming");
1176
1258
  }
1177
1259
 
1260
+ if (formatter instanceof CometChatRichTextFormatter) {
1261
+ richTextFormatterExists = true;
1262
+ }
1263
+
1178
1264
  formatter.setMessage(message);
1179
1265
  finalFormatters.push(CommonUtils.clone(formatter));
1180
- if (urlFormatterExists && mentionsFormatterExists) {
1266
+ if (urlFormatterExists && mentionsFormatterExists && richTextFormatterExists) {
1181
1267
  break;
1182
1268
  }
1183
1269
  }
1184
1270
 
1271
+ // Add rich text formatter first (to parse markdown before other formatters)
1272
+ if (!richTextFormatterExists) {
1273
+ finalFormatters.unshift(richTextFormatter);
1274
+ }
1275
+
1185
1276
  if (!urlFormatterExists) {
1186
1277
  finalFormatters.push(linksTextFormatter);
1187
1278
  }
@@ -0,0 +1,553 @@
1
+ /**
2
+ * Shared helper functions for CometChat message composers.
3
+ * These utilities are used by both CometChatMessageComposer and CometChatSingleLineMessageComposer
4
+ * to ensure consistent behavior and maintainability.
5
+ *
6
+ * DESIGN PRINCIPLE: All composer functionality should be extracted into reusable helpers
7
+ * to ensure feature parity and plug-and-play compatibility between composers.
8
+ *
9
+ * @module composerHelpers
10
+ */
11
+
12
+ //@ts-ignore
13
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
14
+
15
+ // ============================================================================
16
+ // AGENTIC USER HELPERS
17
+ // ============================================================================
18
+
19
+ /**
20
+ * Check if a user is an agentic user (AI agent).
21
+ * Agentic users have the role '@agentic' and require special handling:
22
+ * - Auto-hide certain buttons (attachment, stickers, voice recording)
23
+ * - Disable typing events and mentions
24
+ * - Apply send button delay
25
+ * - Track parent message ID for threaded conversations
26
+ *
27
+ * @param user - The CometChat user object to check
28
+ * @returns True if the user has role '@agentic'
29
+ */
30
+ export const isAgenticUser = (user?: CometChat.User): boolean => {
31
+ return user?.getRole?.() === '@agentic';
32
+ };
33
+
34
+ /**
35
+ * Derive button visibility based on agentic user status and prop value.
36
+ * When user is agentic, buttons are automatically hidden regardless of prop values.
37
+ *
38
+ * @param isAgentic - Whether the user is an agentic user
39
+ * @param propValue - The prop value for hiding the button
40
+ * @returns True if the button should be hidden
41
+ */
42
+ export const deriveHideButton = (isAgentic: boolean, propValue?: boolean): boolean => {
43
+ return isAgentic ? true : (propValue ?? false);
44
+ };
45
+
46
+ /**
47
+ * Derive feature disabled state based on agentic user status and prop value.
48
+ * When user is agentic, features are automatically disabled regardless of prop values.
49
+ *
50
+ * @param isAgentic - Whether the user is an agentic user
51
+ * @param propValue - The prop value for disabling the feature
52
+ * @returns True if the feature should be disabled
53
+ */
54
+ export const deriveDisableFeature = (isAgentic: boolean, propValue?: boolean): boolean => {
55
+ return isAgentic ? true : (propValue ?? false);
56
+ };
57
+
58
+ /**
59
+ * Configuration for agentic user send button delay.
60
+ */
61
+ export interface AgenticSendDelayConfig {
62
+ /** Whether the user is agentic */
63
+ isAgentic: boolean;
64
+ /** Current delay state setter */
65
+ setDelayState: (value: boolean) => void;
66
+ /** Timer ref for cleanup */
67
+ timerRef: React.MutableRefObject<NodeJS.Timeout | null>;
68
+ /** Delay duration in milliseconds (default: 1000) */
69
+ delayMs?: number;
70
+ }
71
+
72
+ /**
73
+ * Apply send button delay for agentic users.
74
+ * Prevents rapid-fire messages to AI agents by disabling send button for 1 second.
75
+ *
76
+ * @param config - Configuration for the delay
77
+ */
78
+ export const applyAgenticSendDelay = (config: AgenticSendDelayConfig): void => {
79
+ const { isAgentic, setDelayState, timerRef, delayMs = 1000 } = config;
80
+
81
+ if (!isAgentic) return;
82
+
83
+ setDelayState(true);
84
+
85
+ if (timerRef.current) {
86
+ clearTimeout(timerRef.current);
87
+ }
88
+
89
+ timerRef.current = setTimeout(() => {
90
+ setDelayState(false);
91
+ }, delayMs);
92
+ };
93
+
94
+ /**
95
+ * Configuration for tracking parent message ID for agentic users.
96
+ */
97
+ export interface AgenticParentMessageConfig {
98
+ /** Whether the user is agentic */
99
+ isAgentic: boolean;
100
+ /** Parent message ID from props (if provided) */
101
+ parentMessageIdProp?: number;
102
+ /** Ref to store tracked parent message ID */
103
+ parentMessageIdRef: React.MutableRefObject<number | null>;
104
+ /** The sent message object */
105
+ message: any;
106
+ }
107
+
108
+ /**
109
+ * Track parent message ID for agentic users.
110
+ * For the first message sent to an agentic user without a parentMessageId prop,
111
+ * stores the message ID as the parent for subsequent messages.
112
+ *
113
+ * @param config - Configuration for parent message tracking
114
+ * @returns The message ID if it was stored, null otherwise
115
+ */
116
+ export const trackAgenticParentMessageId = (config: AgenticParentMessageConfig): number | null => {
117
+ const { isAgentic, parentMessageIdProp, parentMessageIdRef, message } = config;
118
+
119
+ if (!isAgentic || parentMessageIdProp || !message?.getId) {
120
+ return null;
121
+ }
122
+
123
+ const messageId = typeof message.getId() === 'string'
124
+ ? Number(message.getId())
125
+ : message.getId();
126
+
127
+ if (!isNaN(messageId) && !parentMessageIdRef.current) {
128
+ parentMessageIdRef.current = messageId;
129
+ return messageId;
130
+ }
131
+
132
+ return null;
133
+ };
134
+
135
+ /**
136
+ * Get the parent message ID to use for a message.
137
+ * Prioritizes prop value, then tracked value for agentic users.
138
+ *
139
+ * @param parentMessageIdProp - Parent message ID from props
140
+ * @param isAgentic - Whether the user is agentic
141
+ * @param parentMessageIdRef - Ref containing tracked parent message ID
142
+ * @returns The parent message ID to use, or null if none
143
+ */
144
+ export const getParentMessageId = (
145
+ parentMessageIdProp?: number,
146
+ isAgentic?: boolean,
147
+ parentMessageIdRef?: React.MutableRefObject<number | null>
148
+ ): number | null => {
149
+ if (parentMessageIdProp) {
150
+ return parentMessageIdProp;
151
+ }
152
+ if (isAgentic && parentMessageIdRef?.current) {
153
+ return parentMessageIdRef.current;
154
+ }
155
+ return null;
156
+ };
157
+
158
+ // ============================================================================
159
+ // REPLY MESSAGE HELPERS
160
+ // ============================================================================
161
+
162
+ /**
163
+ * Interface for reply message state used by composers.
164
+ */
165
+ export interface ReplyMessageState {
166
+ message: any;
167
+ mode: string;
168
+ }
169
+
170
+ /**
171
+ * Interface for message preview state used by composers (edit mode).
172
+ */
173
+ export interface MessagePreviewState {
174
+ message: any;
175
+ mode: string;
176
+ }
177
+
178
+ /**
179
+ * Get the reply message ID from a reply message state.
180
+ *
181
+ * @param replyMessage - The reply message state
182
+ * @returns The message ID or null if not available
183
+ */
184
+ export const getReplyMessageId = (replyMessage: ReplyMessageState | null): number | null => {
185
+ return replyMessage?.message?.getId?.() ?? null;
186
+ };
187
+
188
+ /**
189
+ * Check if a reply message is active.
190
+ *
191
+ * @param replyMessage - The reply message state
192
+ * @returns True if there is an active reply message
193
+ */
194
+ export const hasActiveReply = (replyMessage: ReplyMessageState | null): boolean => {
195
+ return replyMessage !== null && replyMessage.message !== null;
196
+ };
197
+
198
+ /**
199
+ * Set quoted message on a CometChat message for reply functionality.
200
+ * Uses SDK's built-in quoted message functionality with error handling.
201
+ *
202
+ * @param message - The message to set the quoted message on (TextMessage or MediaMessage)
203
+ * @param replyMessage - The original message being replied to
204
+ * @param replyMessageId - The ID of the original message
205
+ * @returns True if quoted message was set successfully, false otherwise
206
+ */
207
+ export const setQuotedMessageSafe = (
208
+ message: CometChat.TextMessage | CometChat.MediaMessage,
209
+ replyMessage: any,
210
+ replyMessageId: number | string
211
+ ): boolean => {
212
+ try {
213
+ if (typeof (message as any).setQuotedMessage === 'function') {
214
+ (message as any).setQuotedMessage(replyMessage);
215
+ }
216
+ if (typeof (message as any).setQuotedMessageId === 'function') {
217
+ (message as any).setQuotedMessageId(replyMessageId);
218
+ }
219
+ return true;
220
+ } catch (error) {
221
+ // Silently handle errors - quoted message is optional
222
+ return false;
223
+ }
224
+ };
225
+
226
+ /**
227
+ * Configuration for handling reply message on send.
228
+ */
229
+ export interface ReplyMessageSendConfig {
230
+ /** The message being sent */
231
+ message: CometChat.TextMessage | CometChat.MediaMessage;
232
+ /** Current reply message state */
233
+ replyMessage: ReplyMessageState | null;
234
+ /** Callback to clear reply state after handling */
235
+ clearReplyState?: () => void;
236
+ }
237
+
238
+ /**
239
+ * Handle reply message when sending a message.
240
+ * Sets quoted message if reply is active and optionally clears reply state.
241
+ *
242
+ * @param config - Configuration for reply handling
243
+ * @returns True if quoted message was set, false otherwise
244
+ */
245
+ export const handleReplyOnSend = (config: ReplyMessageSendConfig): boolean => {
246
+ const { message, replyMessage, clearReplyState } = config;
247
+
248
+ const replyMessageId = getReplyMessageId(replyMessage);
249
+
250
+ if (replyMessageId && replyMessage?.message) {
251
+ const success = setQuotedMessageSafe(message, replyMessage.message, replyMessageId);
252
+
253
+ if (clearReplyState) {
254
+ clearReplyState();
255
+ }
256
+
257
+ return success;
258
+ }
259
+
260
+ return false;
261
+ };
262
+
263
+ // ============================================================================
264
+ // SEND BUTTON STATE HELPERS
265
+ // ============================================================================
266
+
267
+ /**
268
+ * Configuration for determining send button disabled state.
269
+ */
270
+ export interface SendButtonStateConfig {
271
+ /** Current input text */
272
+ inputText: string;
273
+ /** Whether streaming is active (for agentic users) */
274
+ isStreaming?: boolean;
275
+ /** Whether send button delay is active (for agentic users) */
276
+ isSendButtonDelayed?: boolean;
277
+ /** Whether in edit mode */
278
+ isEditMode?: boolean;
279
+ }
280
+
281
+ /**
282
+ * Determine if send button should be disabled.
283
+ * Considers input text, streaming state, and delay state.
284
+ *
285
+ * @param config - Configuration for send button state
286
+ * @returns True if send button should be disabled
287
+ */
288
+ export const isSendButtonDisabled = (config: SendButtonStateConfig): boolean => {
289
+ const { inputText, isStreaming = false, isSendButtonDelayed = false, isEditMode = false } = config;
290
+
291
+ // In edit mode, only check if text is empty
292
+ if (isEditMode) {
293
+ return inputText.trim().length === 0;
294
+ }
295
+
296
+ return isStreaming || inputText.trim().length === 0 || isSendButtonDelayed;
297
+ };
298
+
299
+ /**
300
+ * Get send button tint color based on disabled state.
301
+ *
302
+ * @param isDisabled - Whether the button is disabled
303
+ * @param activeTint - Tint color when active
304
+ * @param inactiveTint - Tint color when inactive
305
+ * @returns The appropriate tint color
306
+ */
307
+ export const getSendButtonTint = (
308
+ isDisabled: boolean,
309
+ activeTint: string,
310
+ inactiveTint: string
311
+ ): string => {
312
+ return isDisabled ? inactiveTint : activeTint;
313
+ };
314
+
315
+ // ============================================================================
316
+ // MESSAGE CREATION HELPERS
317
+ // ============================================================================
318
+
319
+ /**
320
+ * Configuration for creating a text message.
321
+ */
322
+ export interface CreateTextMessageConfig {
323
+ /** Receiver ID (user UID or group GUID) */
324
+ receiverId: string;
325
+ /** Message text */
326
+ text: string;
327
+ /** Receiver type ('user' or 'group') */
328
+ receiverType: string;
329
+ /** Logged in user */
330
+ sender: CometChat.User;
331
+ /** Receiver (user or group) */
332
+ receiver: CometChat.User | CometChat.Group;
333
+ /** Message unique ID */
334
+ muid: string;
335
+ /** Parent message ID for threaded messages */
336
+ parentMessageId?: number | null;
337
+ }
338
+
339
+ /**
340
+ * Create a text message with common configuration.
341
+ *
342
+ * @param config - Configuration for the text message
343
+ * @returns Configured TextMessage object
344
+ */
345
+ export const createTextMessage = (config: CreateTextMessageConfig): CometChat.TextMessage => {
346
+ const { receiverId, text, receiverType, sender, receiver, muid, parentMessageId } = config;
347
+
348
+ const textMessage = new CometChat.TextMessage(receiverId, text, receiverType);
349
+
350
+ textMessage.setSender(sender);
351
+ textMessage.setReceiver(receiver);
352
+ textMessage.setMuid(muid);
353
+
354
+ if (parentMessageId) {
355
+ textMessage.setParentMessageId(parentMessageId);
356
+ }
357
+
358
+ return textMessage;
359
+ };
360
+
361
+ /**
362
+ * Configuration for creating a media message.
363
+ */
364
+ export interface CreateMediaMessageConfig {
365
+ /** Receiver ID (user UID or group GUID) */
366
+ receiverId: string;
367
+ /** Media file */
368
+ file: any;
369
+ /** Media type (image, video, audio, file) */
370
+ mediaType: string;
371
+ /** Receiver type ('user' or 'group') */
372
+ receiverType: string;
373
+ /** Logged in user */
374
+ sender: CometChat.User;
375
+ /** Receiver (user or group) */
376
+ receiver: CometChat.User | CometChat.Group;
377
+ /** Message unique ID */
378
+ muid: string;
379
+ /** Parent message ID for threaded messages */
380
+ parentMessageId?: number | null;
381
+ }
382
+
383
+ /**
384
+ * Create a media message with common configuration.
385
+ *
386
+ * @param config - Configuration for the media message
387
+ * @returns Configured MediaMessage object
388
+ */
389
+ export const createMediaMessage = (config: CreateMediaMessageConfig): CometChat.MediaMessage => {
390
+ const { receiverId, file, mediaType, receiverType, sender, receiver, muid, parentMessageId } = config;
391
+
392
+ const mediaMessage = new CometChat.MediaMessage(receiverId, file, mediaType, receiverType);
393
+
394
+ mediaMessage.setSender(sender);
395
+ mediaMessage.setReceiver(receiver);
396
+ mediaMessage.setMuid(muid);
397
+
398
+ if (parentMessageId) {
399
+ mediaMessage.setParentMessageId(parentMessageId);
400
+ }
401
+
402
+ return mediaMessage;
403
+ };
404
+
405
+ // ============================================================================
406
+ // MENTION HELPERS
407
+ // ============================================================================
408
+
409
+ /**
410
+ * Interface for mention overlap detection.
411
+ */
412
+ export interface MentionOverlap {
413
+ key: string;
414
+ value: any;
415
+ start: number;
416
+ end: number;
417
+ }
418
+
419
+ /**
420
+ * Parse a mention key string into start/end positions.
421
+ * Mention keys are in format "start_end".
422
+ *
423
+ * @param key - The mention key string
424
+ * @returns Object with start and end positions, or undefined if invalid
425
+ */
426
+ export const parseMentionKey = (key: string): { start: number; end: number } | undefined => {
427
+ const [startStr, endStr] = key.split('_');
428
+ const start = Number(startStr);
429
+ const end = Number(endStr);
430
+
431
+ const isValid = Number.isFinite(start) && Number.isFinite(end);
432
+
433
+ if (!isValid && __DEV__) {
434
+ console.warn(`Invalid mention key: "${key}" (expected "start_end")`);
435
+ }
436
+
437
+ return isValid ? { start, end } : undefined;
438
+ };
439
+
440
+ /**
441
+ * Calculate the deletion range based on selection and deletion length.
442
+ *
443
+ * @param selection - Current selection with start and end positions
444
+ * @param deletionLength - Number of characters being deleted
445
+ * @returns The range of text being deleted
446
+ */
447
+ export const calcDeletionRange = (
448
+ selection: { start: number; end: number },
449
+ deletionLength: number
450
+ ): { start: number; end: number } => {
451
+ return selection.start === selection.end
452
+ ? { start: Math.max(0, selection.start - deletionLength), end: selection.start }
453
+ : { start: selection.start, end: selection.end };
454
+ };
455
+
456
+ /**
457
+ * Collect all mentions that overlap with a deletion range.
458
+ *
459
+ * @param range - The deletion range
460
+ * @param mentionMap - Map of mention keys to mention data
461
+ * @returns Array of overlapping mentions sorted by start position
462
+ */
463
+ export const collectOverlappingMentions = <T>(
464
+ range: { start: number; end: number },
465
+ mentionMap: Map<string, T>
466
+ ): MentionOverlap[] => {
467
+ const overlaps: MentionOverlap[] = [];
468
+
469
+ mentionMap.forEach((value, key) => {
470
+ const mentionRange = parseMentionKey(key);
471
+ if (!mentionRange) return;
472
+
473
+ const { start, end } = mentionRange;
474
+ if (range.start < end && range.end > start) {
475
+ overlaps.push({ key, value, start, end });
476
+ }
477
+ });
478
+
479
+ overlaps.sort((a, b) => a.start - b.start);
480
+ return overlaps;
481
+ };
482
+
483
+ /**
484
+ * Shift remaining mention keys after deletion.
485
+ * Updates mention positions to account for removed text.
486
+ *
487
+ * @param map - The mention map to update
488
+ * @param shiftStart - Position after which to shift
489
+ * @param delta - Amount to shift (negative for deletion)
490
+ */
491
+ export const shiftRemainingMentionKeys = <T>(
492
+ map: Map<string, T>,
493
+ shiftStart: number,
494
+ delta: number
495
+ ): void => {
496
+ if (delta === 0) return;
497
+
498
+ const shifted = new Map<string, T>();
499
+
500
+ map.forEach((val, key) => {
501
+ const range = parseMentionKey(key);
502
+ if (!range) return;
503
+
504
+ const { start, end } = range;
505
+ if (start > shiftStart) {
506
+ shifted.set(`${start + delta}_${end + delta}`, val);
507
+ } else {
508
+ shifted.set(key, val);
509
+ }
510
+ });
511
+
512
+ map.clear();
513
+ shifted.forEach((v, k) => map.set(k, v));
514
+ };
515
+
516
+ // ============================================================================
517
+ // UTILITY HELPERS
518
+ // ============================================================================
519
+
520
+ /**
521
+ * Generate a unique message ID using Unix timestamp in milliseconds.
522
+ *
523
+ * @returns Unique message ID string
524
+ */
525
+ export const generateMessageMuid = (): string => {
526
+ return String(Date.now());
527
+ };
528
+
529
+ /**
530
+ * Check if text is empty or contains only whitespace.
531
+ *
532
+ * @param text - The text to check
533
+ * @returns True if text is empty or whitespace only
534
+ */
535
+ export const isTextEmpty = (text: string): boolean => {
536
+ return text.trim().length === 0;
537
+ };
538
+
539
+ /**
540
+ * Safely get message ID from a message object.
541
+ * Handles both string and number ID types.
542
+ *
543
+ * @param message - The message object
544
+ * @returns The message ID as a number, or null if not available
545
+ */
546
+ export const getMessageIdSafe = (message: any): number | null => {
547
+ if (!message?.getId) return null;
548
+
549
+ const id = message.getId();
550
+ const numId = typeof id === 'string' ? Number(id) : id;
551
+
552
+ return isNaN(numId) ? null : numId;
553
+ };