@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.
- package/android/build.gradle +3 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +4 -1
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +909 -10
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorPackage.kt +24 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +5382 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +452 -0
- package/ios/FileManager.m +430 -3
- package/ios/RichTextEditorView.swift +5504 -0
- package/ios/RichTextEditorViewManager.m +66 -0
- package/ios/RichTextEditorViewManager.swift +291 -0
- package/ios/ToolbarIcons.swift +736 -0
- package/package.json +1 -1
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +4602 -0
- package/src/CometChatCompactMessageComposer/SingleLineTextComposerConfiguration.tsx +568 -0
- package/src/CometChatCompactMessageComposer/heightUtils.ts +204 -0
- package/src/CometChatCompactMessageComposer/index.ts +56 -0
- package/src/CometChatCompactMessageComposer/resources/index.ts +5 -0
- package/src/CometChatCompactMessageComposer/styles.ts +291 -0
- package/src/CometChatConversations/CometChatConversations.tsx +141 -14
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +6 -0
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +1 -20
- package/src/CometChatMessageComposer/styles.tsx +0 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +76 -30
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +105 -0
- package/src/CometChatRichTextEditor/index.tsx +385 -0
- package/src/CometChatRichTextEditor/types.ts +162 -0
- package/src/CometChatSearch/CometChatSearch.tsx +35 -29
- package/src/calls/CallUtils.ts +4 -4
- package/src/index.ts +48 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -0
- package/src/shared/constants/UIKitConstants.ts +12 -1
- package/src/shared/events/ListenerInitializer.ts +6 -0
- package/src/shared/events/messages.ts +2 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -5
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +768 -0
- package/src/shared/formatters/index.ts +3 -0
- package/src/shared/framework/MessageDataSource.tsx +93 -2
- package/src/shared/helper/composerHelpers.ts +553 -0
- package/src/shared/helper/useKeyboard.tsx +7 -17
- package/src/shared/icons/components/code-blocks.tsx +13 -0
- package/src/shared/icons/components/code.tsx +11 -0
- package/src/shared/icons/components/format-bold.tsx +11 -0
- package/src/shared/icons/components/format-italic.tsx +11 -0
- package/src/shared/icons/components/format-list-bulleted.tsx +11 -0
- package/src/shared/icons/components/format-list-numbered.tsx +11 -0
- package/src/shared/icons/components/format-quote.tsx +13 -0
- package/src/shared/icons/components/format-strikethrough.tsx +13 -0
- package/src/shared/icons/components/format-underlined.tsx +11 -0
- package/src/shared/icons/components/smileys-&-people.tsx +1 -1
- package/src/shared/icons/icon-mapping.tsx +18 -0
- package/src/shared/index.ts +54 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +37 -32
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +5 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +504 -499
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +18 -13
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +505 -500
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +17 -12
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +18 -13
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +132 -11
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -3
- package/src/shared/utils/CommonUtils.ts +18 -1
- package/src/shared/utils/MarkdownUtils.ts +143 -0
- package/src/shared/utils/MentionUtils.ts +37 -0
- package/src/shared/utils/MessageReceiptUtils.ts +5 -4
- package/src/shared/utils/MessageUtils.tsx +5 -3
- package/src/shared/utils/index.ts +5 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +1 -1
- package/src/shared/views/CometChatInlineAudioRecorder/AudioWaveformVisualizer.tsx +417 -0
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +537 -0
- package/src/shared/views/CometChatInlineAudioRecorder/index.ts +34 -0
- package/src/shared/views/CometChatInlineAudioRecorder/style.ts +155 -0
- package/src/shared/views/CometChatInlineAudioRecorder/types.ts +303 -0
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +1336 -0
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +183 -0
- package/src/shared/views/CometChatLinkConfirmPopup/index.ts +13 -0
- package/src/shared/views/CometChatLinkConfirmPopup/style.ts +128 -0
- package/src/shared/views/CometChatList/Header.tsx +2 -1
- package/src/shared/views/CometChatListItem/style.ts +1 -0
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +32 -29
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +64 -16
- package/src/shared/views/index.ts +39 -0
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"AI": "AI",
|
|
19
19
|
"ALL": "全部",
|
|
20
20
|
"MESSAGE_COMPOSER_MENTION_ALL": "全部",
|
|
21
|
-
|
|
21
|
+
"MESSAGE_COMPOSER_MENTION_NOTIFY_EVERYONE_LABEL": "通知此群组中的所有人",
|
|
22
22
|
"AND": "一个",
|
|
23
23
|
"ANIMALES_NATURE": "动物与自然",
|
|
24
24
|
"ANSWER": "回答",
|
|
@@ -458,16 +458,16 @@
|
|
|
458
458
|
"YOU_INITIATED_GROUP_VIDEO_CALL": "你发起了视频通话",
|
|
459
459
|
"meeting": "会议",
|
|
460
460
|
"Flag_Message_Title": "举报消息",
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
461
|
+
"Flag_Message_Subtitle": "如果此聊天违反我们的社区标准,请举报。我们不会告诉对方您已举报他们。",
|
|
462
|
+
"Flag_Message_Remark_Label": "原因",
|
|
463
|
+
"Flag_Message_Remark_Optional": "可选",
|
|
464
|
+
"Flag_Message_Remark_Placeholder": "为您的举报提供额外说明…",
|
|
465
|
+
"Flag_Message_Confirm_Yes": "举报",
|
|
466
|
+
"Flag_Message_Confirm_No": "取消",
|
|
467
|
+
"Flag_Message_Reason_Id_Spam": "垃圾邮件/不想要的内容",
|
|
468
|
+
"Flag_Message_Reason_Id_Sexual": "露骨或不当内容",
|
|
469
|
+
"Flag_Message_Reason_Id_Harassment": "侮辱或威胁行为",
|
|
470
|
+
"Message_List_Option_Flag_Message": "举报",
|
|
471
471
|
"Flag_Error_Text":"出现错误。请检查后重试。",
|
|
472
472
|
"Flag_Empty_Submit_Text":"无法提交。请在举报此消息前选择一个原因。",
|
|
473
473
|
"START_REPORTING": "开始报告",
|
|
@@ -504,5 +504,10 @@
|
|
|
504
504
|
"SEARCH_NO_MESSAGES": "没有消息",
|
|
505
505
|
"MESSAGE_REPORTED": "消息已举报",
|
|
506
506
|
"MARK_AS_UNREAD": "标记未读",
|
|
507
|
-
"NEW": "新"
|
|
507
|
+
"NEW": "新",
|
|
508
|
+
"INSERT_LINK": "插入链接",
|
|
509
|
+
"EDIT_LINK": "编辑链接",
|
|
510
|
+
"LINK_TEXT": "链接文本",
|
|
511
|
+
"URL": "URL",
|
|
512
|
+
"INSERT": "插入"
|
|
508
513
|
}
|
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
"AI": "艾",
|
|
19
19
|
"ALL": "全部",
|
|
20
20
|
"MESSAGE_COMPOSER_MENTION_ALL": "全部",
|
|
21
|
-
|
|
21
|
+
"MESSAGE_COMPOSER_MENTION_NOTIFY_EVERYONE_LABEL": "通知此群組中的所有人",
|
|
22
22
|
"AND": "一個",
|
|
23
23
|
"ANIMALES_NATURE": "動物與自然",
|
|
24
24
|
"ANSWER": "答案",
|
|
@@ -458,16 +458,16 @@
|
|
|
458
458
|
"YOU_INITIATED_GROUP_VIDEO_CALL": "您已啟動視訊通話",
|
|
459
459
|
"meeting": "會議",
|
|
460
460
|
"Flag_Message_Title": "檢舉訊息",
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
461
|
+
"Flag_Message_Subtitle": "若此對話違反我們的社群規範,請檢舉。我們不會告知該帳戶您已檢舉他們。",
|
|
462
|
+
"Flag_Message_Remark_Label": "理由",
|
|
463
|
+
"Flag_Message_Remark_Optional": "選填",
|
|
464
|
+
"Flag_Message_Remark_Placeholder": "為您的檢舉提供更多說明…",
|
|
465
|
+
"Flag_Message_Confirm_Yes": "檢舉",
|
|
466
|
+
"Flag_Message_Confirm_No": "取消",
|
|
467
|
+
"Flag_Message_Reason_Id_Spam": "垃圾訊息/不想要的內容",
|
|
468
|
+
"Flag_Message_Reason_Id_Sexual": "露骨或不當內容",
|
|
469
|
+
"Flag_Message_Reason_Id_Harassment": "侮辱或威脅行為",
|
|
470
|
+
"Message_List_Option_Flag_Message": "檢舉",
|
|
471
471
|
"Flag_Error_Text":"發生錯誤。請檢查後再試一次。",
|
|
472
472
|
"Flag_Empty_Submit_Text":"無法提交。請在回報此訊息前選擇一個原因。",
|
|
473
473
|
"START_REPORTING": "開始報告",
|
|
@@ -504,5 +504,10 @@
|
|
|
504
504
|
"SEARCH_NO_MESSAGES": "沒有訊息",
|
|
505
505
|
"MESSAGE_REPORTED": "訊息已檢舉",
|
|
506
506
|
"MARK_AS_UNREAD": "標記未讀",
|
|
507
|
-
"NEW": "新"
|
|
508
|
-
|
|
507
|
+
"NEW": "新",
|
|
508
|
+
"INSERT_LINK": "插入連結",
|
|
509
|
+
"EDIT_LINK": "編輯連結",
|
|
510
|
+
"LINK_TEXT": "連結文字",
|
|
511
|
+
"URL": "URL",
|
|
512
|
+
"INSERT": "插入"
|
|
513
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import React, { JSX } from "react";
|
|
2
|
-
import { View, Text, TouchableOpacity,
|
|
2
|
+
import { View, Text, TouchableOpacity, StyleProp, ViewStyle, Platform, StyleSheet } from "react-native";
|
|
3
3
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
4
|
-
import closeIcon from "./resources/close.png";
|
|
5
4
|
import { useTheme } from "../../../theme";
|
|
6
5
|
import { Styles } from "./style";
|
|
7
6
|
import { getCometChatTranslation } from "../../resources/CometChatLocalizeNew/LocalizationManager";
|
|
8
7
|
import { Icon } from "../../icons/Icon";
|
|
9
|
-
import {
|
|
8
|
+
import { stripMarkdown, preparePreviewText } from "../MarkdownUtils";
|
|
9
|
+
import { CometChatRichTextFormatter } from "../../formatters/CometChatRichTextFormatter";
|
|
10
10
|
|
|
11
11
|
const t = getCometChatTranslation();
|
|
12
12
|
|
|
13
|
+
/** Module-level formatter instance — reused across renders (SRP, no GC churn) */
|
|
14
|
+
const previewFormatter = new CometChatRichTextFormatter();
|
|
15
|
+
|
|
13
16
|
/**
|
|
14
17
|
* Props for CometChatMessagePreview component
|
|
15
18
|
*/
|
|
@@ -83,7 +86,7 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
83
86
|
};
|
|
84
87
|
|
|
85
88
|
// Helper function to get message preview subtitle/content
|
|
86
|
-
const getMessagePreviewSubtitle = (): string => {
|
|
89
|
+
const getMessagePreviewSubtitle = (): string | JSX.Element => {
|
|
87
90
|
if (messagePreviewSubtitle) return messagePreviewSubtitle;
|
|
88
91
|
|
|
89
92
|
if (!message) return "";
|
|
@@ -124,8 +127,37 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
124
127
|
console.warn("Error formatting mentions in preview:", e);
|
|
125
128
|
}
|
|
126
129
|
|
|
127
|
-
//
|
|
128
|
-
|
|
130
|
+
// Prepare text for preview: collapse code blocks, strip block markers, flatten to single line
|
|
131
|
+
const previewResult = preparePreviewText(text);
|
|
132
|
+
const cleanText = previewResult.text;
|
|
133
|
+
const formatted = previewFormatter.getFormattedText(cleanText || null);
|
|
134
|
+
|
|
135
|
+
// Resolve subtitle content
|
|
136
|
+
let subtitleContent: string | JSX.Element;
|
|
137
|
+
if (formatted && typeof formatted !== 'string') {
|
|
138
|
+
subtitleContent = formatted;
|
|
139
|
+
} else {
|
|
140
|
+
subtitleContent = (formatted as string) || stripMarkdown(text);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
// For code blocks (first rich block): render compact code block container
|
|
144
|
+
if (previewResult.codeBlockFirstLine !== null) {
|
|
145
|
+
isCodeBlockPreview = true;
|
|
146
|
+
codeBlockLine = previewResult.codeBlockFirstLine;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
// For blockquotes: set flag for render section to add container styling
|
|
150
|
+
if (previewResult.isBlockquote) {
|
|
151
|
+
isBlockquotePreview = true;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
// For list items: set flag so render shows prefix + content with ellipsis
|
|
155
|
+
if (previewResult.listPrefix) {
|
|
156
|
+
isListPreview = true;
|
|
157
|
+
listPrefix = previewResult.listPrefix;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
return subtitleContent;
|
|
129
161
|
|
|
130
162
|
case CometChat.MESSAGE_TYPE.IMAGE:
|
|
131
163
|
const imageMessage = message as CometChat.MediaMessage;
|
|
@@ -258,7 +290,14 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
258
290
|
return null;
|
|
259
291
|
};
|
|
260
292
|
|
|
261
|
-
|
|
293
|
+
// Mutable flags set by getMessagePreviewSubtitle when block types are detected
|
|
294
|
+
let isBlockquotePreview = false;
|
|
295
|
+
let isCodeBlockPreview = false;
|
|
296
|
+
let isListPreview = false;
|
|
297
|
+
let listPrefix = '';
|
|
298
|
+
let codeBlockLine = '';
|
|
299
|
+
|
|
300
|
+
let messageText: string | JSX.Element = getMessagePreviewSubtitle();
|
|
262
301
|
let title = getMessagePreviewTitle();
|
|
263
302
|
let autoIcon = getAutoIcon();
|
|
264
303
|
|
|
@@ -266,6 +305,13 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
266
305
|
const containerStyle = style ? [Styles(finalTheme).editPreviewContainerStyle, style] : Styles(finalTheme).editPreviewContainerStyle;
|
|
267
306
|
const iconToShow = subtitleIcon || autoIcon;
|
|
268
307
|
|
|
308
|
+
// Determine if subtitle is rich (JSX) or plain string
|
|
309
|
+
const isRichSubtitle = typeof messageText !== 'string';
|
|
310
|
+
// Detect if the formatter returned a View root (block-level content that
|
|
311
|
+
// slipped through preparePreviewText). View can't nest inside Text, so we
|
|
312
|
+
// render it in a height-constrained View wrapper instead.
|
|
313
|
+
const isViewRoot = isRichSubtitle && React.isValidElement(messageText) && (messageText as React.ReactElement<any>).type === View;
|
|
314
|
+
|
|
269
315
|
return (
|
|
270
316
|
<View style={containerStyle}>
|
|
271
317
|
{/* <View style={Styles(finalTheme).leftBar} /> */}
|
|
@@ -280,14 +326,89 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
280
326
|
</TouchableOpacity>
|
|
281
327
|
)}
|
|
282
328
|
</View>
|
|
283
|
-
<View style={{ flexDirection: 'row', alignItems: 'flex-start', gap: finalTheme?.spacing?.padding?.p1}}>
|
|
329
|
+
<View style={[{ flexDirection: 'row', alignItems: 'flex-start', gap: finalTheme?.spacing?.padding?.p1 }]}>
|
|
284
330
|
{iconToShow && <View>{iconToShow}</View>}
|
|
285
|
-
|
|
286
|
-
{
|
|
287
|
-
|
|
331
|
+
{isCodeBlockPreview ? (
|
|
332
|
+
<View style={previewBlockStyles.codeBlockRow}>
|
|
333
|
+
<View style={[previewBlockStyles.codeBlockBadge, { backgroundColor: finalTheme?.color?.background2 as string || '#FAFAFA', borderColor: finalTheme?.color?.borderDefault as string || '#E8E8E8' }]}>
|
|
334
|
+
<Text numberOfLines={1} ellipsizeMode='tail' style={[previewBlockStyles.codeBlockText, { color: finalTheme?.color?.textPrimary as string || '#141414' }]}>
|
|
335
|
+
{codeBlockLine + '..'}
|
|
336
|
+
</Text>
|
|
337
|
+
</View>
|
|
338
|
+
</View>
|
|
339
|
+
) : isBlockquotePreview ? (
|
|
340
|
+
<View style={previewBlockStyles.blockquoteRow}>
|
|
341
|
+
<View style={[previewBlockStyles.blockquoteBar, { backgroundColor: finalTheme.color.primaryColor as string }]} />
|
|
342
|
+
<Text numberOfLines={1} ellipsizeMode='tail' style={[Styles(finalTheme).previewSubTitleStyle, previewBlockStyles.blockquoteText]}>
|
|
343
|
+
{messageText}
|
|
344
|
+
</Text>
|
|
345
|
+
</View>
|
|
346
|
+
) : isListPreview ? (
|
|
347
|
+
<Text numberOfLines={1} ellipsizeMode='tail' style={[Styles(finalTheme).previewSubTitleStyle, previewBlockStyles.flexOne]}>
|
|
348
|
+
{listPrefix}{messageText}{'...'}
|
|
349
|
+
</Text>
|
|
350
|
+
) : isViewRoot ? (
|
|
351
|
+
<View style={previewBlockStyles.viewRootContainer}>
|
|
352
|
+
{messageText}
|
|
353
|
+
</View>
|
|
354
|
+
) : (
|
|
355
|
+
<Text numberOfLines={1} ellipsizeMode='tail' style={[Styles(finalTheme).previewSubTitleStyle, previewBlockStyles.flexOne]}>
|
|
356
|
+
{messageText}
|
|
357
|
+
</Text>
|
|
358
|
+
)}
|
|
288
359
|
</View>
|
|
289
360
|
</View>
|
|
290
361
|
);
|
|
291
362
|
};
|
|
292
363
|
|
|
293
364
|
export { CometChatMessagePreview };
|
|
365
|
+
|
|
366
|
+
// Static styles for message preview block-level elements.
|
|
367
|
+
// Theme-dependent values (colors) are applied inline via style array merging.
|
|
368
|
+
const previewBlockStyles = StyleSheet.create({
|
|
369
|
+
codeBlockRow: {
|
|
370
|
+
flex: 1,
|
|
371
|
+
flexDirection: 'row',
|
|
372
|
+
alignItems: 'center',
|
|
373
|
+
},
|
|
374
|
+
codeBlockBadge: {
|
|
375
|
+
borderRadius: 4,
|
|
376
|
+
borderWidth: 1,
|
|
377
|
+
paddingHorizontal: 8,
|
|
378
|
+
paddingVertical: 3,
|
|
379
|
+
flexShrink: 1,
|
|
380
|
+
},
|
|
381
|
+
codeBlockText: {
|
|
382
|
+
fontFamily: Platform.OS === 'ios' ? 'Menlo' : 'monospace',
|
|
383
|
+
fontSize: 12,
|
|
384
|
+
},
|
|
385
|
+
blockquoteRow: {
|
|
386
|
+
flex: 1,
|
|
387
|
+
flexDirection: 'row',
|
|
388
|
+
alignItems: 'stretch',
|
|
389
|
+
backgroundColor: 'rgba(104, 81, 214, 0.08)',
|
|
390
|
+
borderRadius: 8,
|
|
391
|
+
minHeight: 26,
|
|
392
|
+
paddingVertical: 2,
|
|
393
|
+
},
|
|
394
|
+
blockquoteBar: {
|
|
395
|
+
width: 4,
|
|
396
|
+
borderRadius: 2,
|
|
397
|
+
marginVertical: 4,
|
|
398
|
+
marginLeft: 4,
|
|
399
|
+
},
|
|
400
|
+
blockquoteText: {
|
|
401
|
+
flex: 1,
|
|
402
|
+
marginBottom: 0,
|
|
403
|
+
paddingHorizontal: 6,
|
|
404
|
+
lineHeight: 22,
|
|
405
|
+
},
|
|
406
|
+
flexOne: {
|
|
407
|
+
flex: 1,
|
|
408
|
+
},
|
|
409
|
+
viewRootContainer: {
|
|
410
|
+
flex: 1,
|
|
411
|
+
overflow: 'hidden',
|
|
412
|
+
maxHeight: 28,
|
|
413
|
+
},
|
|
414
|
+
});
|
|
@@ -4,14 +4,12 @@ import { CometChatTheme } from "../../../theme/type";
|
|
|
4
4
|
export const Styles = (theme: CometChatTheme) => {
|
|
5
5
|
return StyleSheet.create({
|
|
6
6
|
editPreviewContainerStyle: {
|
|
7
|
-
alignSelf: "center",
|
|
8
7
|
borderRadius: theme.spacing.radius.r2,
|
|
9
8
|
padding: theme.spacing.padding.p2,
|
|
10
9
|
marginBottom: theme.spacing.margin.m1,
|
|
11
10
|
backgroundColor: theme.color.background3,
|
|
12
|
-
width: '100%',
|
|
13
11
|
borderWidth: theme.spacing.spacing.s0_5 / 2,
|
|
14
|
-
borderColor: theme.color.borderDefault
|
|
12
|
+
borderColor: theme.color.borderDefault,
|
|
15
13
|
},
|
|
16
14
|
previewHeadingStyle: {
|
|
17
15
|
marginBottom: 5,
|
|
@@ -54,7 +54,24 @@ export class CommonUtils {
|
|
|
54
54
|
// Copy properties from obj2 to the new instance
|
|
55
55
|
Object.assign(merged, obj2);
|
|
56
56
|
|
|
57
|
-
|
|
57
|
+
// Preserve SDK message class identity after merge.
|
|
58
|
+
// When obj2 is a raw JSON object from the REST API history fetch,
|
|
59
|
+
// it contains flat `category` and `type` own properties (e.g. "message"/"text")
|
|
60
|
+
const protectedProps = ['category', 'type'];
|
|
61
|
+
for (const prop of protectedProps) {
|
|
62
|
+
const getterName = `get${prop.charAt(0).toUpperCase() + prop.slice(1)}`;
|
|
63
|
+
if (
|
|
64
|
+
typeof (obj1 as any)[getterName] === 'function' &&
|
|
65
|
+
typeof (obj2 as any)[getterName] !== 'function'
|
|
66
|
+
) {
|
|
67
|
+
const correctValue = (obj1 as any)[getterName]();
|
|
68
|
+
if (correctValue !== undefined && (merged as any)[prop] !== correctValue) {
|
|
69
|
+
(merged as any)[prop] = correctValue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
return merged;
|
|
58
75
|
}
|
|
59
76
|
|
|
60
77
|
/**
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Utility functions for markdown text processing.
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Strips markdown syntax characters from text, returning clean readable content.
|
|
7
|
+
*
|
|
8
|
+
* Handles:
|
|
9
|
+
* - Code blocks: ```code``` → code
|
|
10
|
+
* - Inline code: `code` → code
|
|
11
|
+
* - Bold: **text** → text
|
|
12
|
+
* - Underline: __text__ → text
|
|
13
|
+
* - Strikethrough: ~~text~~ → text
|
|
14
|
+
* - Italic: _text_ → text
|
|
15
|
+
* - Blockquotes: > text → text
|
|
16
|
+
* - Bullet lists: - text → text
|
|
17
|
+
* - Numbered lists: 1. text → text
|
|
18
|
+
*
|
|
19
|
+
* @param text - The markdown text to strip
|
|
20
|
+
* @returns Clean text without markdown syntax characters
|
|
21
|
+
*/
|
|
22
|
+
export function stripMarkdown(text: string): string {
|
|
23
|
+
if (!text) return text;
|
|
24
|
+
|
|
25
|
+
let result = text;
|
|
26
|
+
|
|
27
|
+
// 1. Remove code block fences (``` on their own lines or inline ```)
|
|
28
|
+
result = result.replace(/```[\s\S]*?```/g, (match) => {
|
|
29
|
+
return match.slice(3, -3).trim();
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// 1.5. Convert markdown links [text](url) → text
|
|
33
|
+
result = result.replace(/\[([^\]]+)\]\([^)]+\)/g, '$1');
|
|
34
|
+
|
|
35
|
+
// 2. Remove inline code backticks (normal and escaped)
|
|
36
|
+
result = result.replace(/\\`([^`]*?)\\`/g, '$1'); // escaped \`code\`
|
|
37
|
+
result = result.replace(/`([^`]*)`/g, '$1'); // normal `code`
|
|
38
|
+
|
|
39
|
+
// 3. Remove bold **text** (normal and escaped)
|
|
40
|
+
result = result.replace(/\\\*\\\*(.+?)\\\*\\\*/g, '$1'); // escaped \*\*bold\*\*
|
|
41
|
+
result = result.replace(/\*\*(.+?)\*\*/g, '$1'); // normal **bold**
|
|
42
|
+
|
|
43
|
+
// 4. Remove underline __text__ (must come before italic _ handling)
|
|
44
|
+
result = result.replace(/\\__(.+?)\\__/g, '$1'); // escaped
|
|
45
|
+
result = result.replace(/__(.+?)__/g, '$1'); // normal
|
|
46
|
+
|
|
47
|
+
// 5. Remove strikethrough ~~text~~
|
|
48
|
+
result = result.replace(/\\~~(.+?)\\~~/g, '$1'); // escaped
|
|
49
|
+
result = result.replace(/~~(.+?)~~/g, '$1'); // normal
|
|
50
|
+
|
|
51
|
+
// 6. Remove italic _text_
|
|
52
|
+
result = result.replace(/(?<![a-zA-Z0-9])_(.+?)_(?![a-zA-Z0-9])/g, '$1');
|
|
53
|
+
|
|
54
|
+
// 7. Remove blockquote markers at start of lines
|
|
55
|
+
result = result.replace(/^>\s?/gm, '');
|
|
56
|
+
|
|
57
|
+
// 8. Remove bullet list markers at start of lines
|
|
58
|
+
result = result.replace(/^-\s/gm, '');
|
|
59
|
+
|
|
60
|
+
// 9. Remove numbered list markers at start of lines
|
|
61
|
+
result = result.replace(/^\d+\.\s/gm, '');
|
|
62
|
+
|
|
63
|
+
// 10. Remove any remaining backslash escapes (e.g., \* \_ \` \~)
|
|
64
|
+
result = result.replace(/\\([*_`~>\\])/g, '$1');
|
|
65
|
+
|
|
66
|
+
return result;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Result from preparePreviewText with metadata about detected block types.
|
|
72
|
+
*/
|
|
73
|
+
export interface PreviewTextResult {
|
|
74
|
+
text: string;
|
|
75
|
+
isBlockquote: boolean;
|
|
76
|
+
/** First line of a fenced code block (if the first rich block is a code block) */
|
|
77
|
+
codeBlockFirstLine: string | null;
|
|
78
|
+
/** Display prefix for list items (e.g. "1. " or "- ") — kept separate so the
|
|
79
|
+
* formatter won't re-parse the text as a block element. */
|
|
80
|
+
listPrefix: string | null;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Prepare message text for compact single-line preview display.
|
|
85
|
+
* Detects the FIRST block-level element and returns only its first line.
|
|
86
|
+
* Priority: blockquote > code block > ordered list > bullet list > plain text
|
|
87
|
+
* Everything after the first block element is discarded.
|
|
88
|
+
*
|
|
89
|
+
* For list items and blockquotes, the returned `text` contains ONLY the item
|
|
90
|
+
* content (no `> `, `- `, or `1. ` prefix) so the formatter won't re-parse
|
|
91
|
+
* it as a block element. The `listPrefix` field carries the display prefix.
|
|
92
|
+
*/
|
|
93
|
+
export function preparePreviewText(text: string): PreviewTextResult {
|
|
94
|
+
const lines = text.split('\n');
|
|
95
|
+
|
|
96
|
+
for (let i = 0; i < lines.length; i++) {
|
|
97
|
+
const trimmed = lines[i].trim();
|
|
98
|
+
if (trimmed.length === 0) continue;
|
|
99
|
+
|
|
100
|
+
// Blockquote
|
|
101
|
+
if (trimmed.startsWith('> ') || trimmed.startsWith('▎ ')) {
|
|
102
|
+
return { text: trimmed.substring(2), isBlockquote: true, codeBlockFirstLine: null, listPrefix: null };
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
// Fenced code block
|
|
106
|
+
if (trimmed.startsWith('```')) {
|
|
107
|
+
const afterOpen = trimmed.substring(3);
|
|
108
|
+
const closeIdx = afterOpen.indexOf('```');
|
|
109
|
+
let firstLine: string;
|
|
110
|
+
if (closeIdx > 0) {
|
|
111
|
+
firstLine = afterOpen.substring(0, closeIdx).trim();
|
|
112
|
+
} else {
|
|
113
|
+
firstLine = '';
|
|
114
|
+
for (let j = i + 1; j < lines.length; j++) {
|
|
115
|
+
if (lines[j].trim().startsWith('```')) break;
|
|
116
|
+
if (lines[j].trim().length > 0) { firstLine = lines[j].trim(); break; }
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
return { text: '', isBlockquote: false, codeBlockFirstLine: firstLine, listPrefix: null };
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Ordered list — content only, prefix in listPrefix
|
|
123
|
+
const orderedMatch = trimmed.match(/^(\d+)\.\s(.*)$/);
|
|
124
|
+
if (orderedMatch) {
|
|
125
|
+
return { text: orderedMatch[2].trim(), isBlockquote: false, codeBlockFirstLine: null, listPrefix: `${orderedMatch[1]}. ` };
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// Bullet list — content only, prefix in listPrefix
|
|
129
|
+
if (trimmed.startsWith('- ')) {
|
|
130
|
+
return { text: trimmed.substring(2).trim(), isBlockquote: false, codeBlockFirstLine: null, listPrefix: '- ' };
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
// Plain text — collapse any inline code blocks
|
|
134
|
+
let result = lines[i];
|
|
135
|
+
result = result.replace(/```\n?([\s\S]*?)```/g, (_m, c: string) => {
|
|
136
|
+
const fl = c.split('\n')[0].trim();
|
|
137
|
+
return fl ? '`' + fl + '..' + '`' : '';
|
|
138
|
+
});
|
|
139
|
+
return { text: result.trim(), isBlockquote: false, codeBlockFirstLine: null, listPrefix: null };
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return { text: text.trim(), isBlockquote: false, codeBlockFirstLine: null, listPrefix: null };
|
|
143
|
+
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared mention utility functions used by both CometChatMessageComposer
|
|
3
|
+
* and CometChatSingleLineMessageComposer for cursor positioning around mentions.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Check if cursor is within a mention range.
|
|
8
|
+
*/
|
|
9
|
+
export function isCursorWithinMentionRange(
|
|
10
|
+
mentionRanges: Map<string, any>,
|
|
11
|
+
cursorPosition: number
|
|
12
|
+
): boolean {
|
|
13
|
+
for (const [range] of mentionRanges) {
|
|
14
|
+
const [start, end] = range.split('_').map(Number);
|
|
15
|
+
if (cursorPosition >= start && cursorPosition <= end) {
|
|
16
|
+
return true;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
return false;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* Get the mention range boundaries if cursor is within a mention.
|
|
24
|
+
* Used to snap cursor to the nearest edge (WhatsApp-style behavior).
|
|
25
|
+
*/
|
|
26
|
+
export function getMentionRangeAtCursor(
|
|
27
|
+
mentionRanges: Map<string, any>,
|
|
28
|
+
cursorPosition: number
|
|
29
|
+
): { start: number; end: number } | null {
|
|
30
|
+
for (const [range] of mentionRanges) {
|
|
31
|
+
const [start, end] = range.split('_').map(Number);
|
|
32
|
+
if (cursorPosition >= start && cursorPosition <= end) {
|
|
33
|
+
return { start, end };
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
@@ -19,11 +19,12 @@ export const MessageReceiptUtils = {
|
|
|
19
19
|
if (hasError) return MessageReceipt.ERROR;
|
|
20
20
|
|
|
21
21
|
// Deleted messages treated as error for receipts
|
|
22
|
-
if (
|
|
22
|
+
if (message.getDeletedAt?.()) return MessageReceipt.ERROR;
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
if (
|
|
26
|
-
if (
|
|
24
|
+
// Use getter methods for receipt state (SDK objects expose these via getters)
|
|
25
|
+
if (message.getReadAt?.()) return MessageReceipt.READ;
|
|
26
|
+
if (message.getDeliveredAt?.()) return MessageReceipt.DELIVERED;
|
|
27
|
+
if (message.getSentAt?.()) return MessageReceipt.SENT;
|
|
27
28
|
|
|
28
29
|
return MessageReceipt.WAIT;
|
|
29
30
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
2
|
import React, { JSX } from "react";
|
|
3
|
-
import { ColorValue, Text, View } from "react-native";
|
|
3
|
+
import { ColorValue, PixelRatio, Text, View } from "react-native";
|
|
4
4
|
import { MessageBubbleAlignmentType } from "../base";
|
|
5
5
|
import {
|
|
6
6
|
CometChatCustomMessageTypes,
|
|
@@ -174,7 +174,7 @@ const getHeaderView = (
|
|
|
174
174
|
) {
|
|
175
175
|
const senderName = (item.getSender()?.getName() || "").trim();
|
|
176
176
|
return (
|
|
177
|
-
<View style={{
|
|
177
|
+
<View style={{flexDirection: "row" }}>
|
|
178
178
|
{Boolean(senderName) && (
|
|
179
179
|
<Text style={_style.senderNameTextStyles} numberOfLines={1} ellipsizeMode={"tail"}>
|
|
180
180
|
{senderName}
|
|
@@ -349,12 +349,14 @@ export const getMessagePreviewInternal = (
|
|
|
349
349
|
text: string,
|
|
350
350
|
{ iconColor, theme }: { iconColor?: ColorValue; theme?: CometChatTheme }
|
|
351
351
|
) => {
|
|
352
|
+
const fontScale = PixelRatio.getFontScale();
|
|
353
|
+
const iconSize = (theme?.spacing?.spacing?.s4 ?? 16) * fontScale;
|
|
352
354
|
return (
|
|
353
355
|
<>
|
|
354
356
|
{iconName && (
|
|
355
357
|
<Icon
|
|
356
358
|
name={iconName}
|
|
357
|
-
size={
|
|
359
|
+
size={iconSize}
|
|
358
360
|
color={iconColor || theme?.color?.textSecondary}
|
|
359
361
|
containerStyle={{ marginRight: theme?.spacing?.spacing?.s0_5 }}
|
|
360
362
|
/>
|
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
import { CometChatSoundManager } from "../resources/CometChatSoundManager";
|
|
2
2
|
import { CometChatMessagePreview } from "./CometChatMessagePreview";
|
|
3
3
|
import { CometChatConversationUtils } from "./conversationUtils";
|
|
4
|
+
import { isCursorWithinMentionRange, getMentionRangeAtCursor } from "./MentionUtils";
|
|
5
|
+
import { stripMarkdown } from "./MarkdownUtils";
|
|
4
6
|
export {
|
|
5
7
|
CometChatConversationUtils,
|
|
6
8
|
CometChatMessagePreview,
|
|
7
9
|
CometChatSoundManager,
|
|
10
|
+
isCursorWithinMentionRange,
|
|
11
|
+
getMentionRangeAtCursor,
|
|
12
|
+
stripMarkdown,
|
|
8
13
|
};
|
|
@@ -199,7 +199,7 @@ export const CometChatAudioBubble = ({
|
|
|
199
199
|
|
|
200
200
|
const displayDuration = useCallback(
|
|
201
201
|
() => (
|
|
202
|
-
<Text style={playProgressTextStyle}>
|
|
202
|
+
<Text allowFontScaling={false} style={playProgressTextStyle}>
|
|
203
203
|
{`${String(Math.floor((currentTime || 0) / 60)).padStart(2, "0")}:${String(
|
|
204
204
|
Math.floor((currentTime || 0) % 60)
|
|
205
205
|
).padStart(2, "0")}`}
|