@cometchat/chat-uikit-react-native 5.3.2 → 5.3.4
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/src/main/java/com/reactnativecometchatuikit/CometChatWebView.java +9 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +16 -10
- package/ios/RichTextEditorView.swift +49 -2
- package/ios/WebViewManager.m +13 -2
- package/package.json +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +50 -30
- package/src/CometChatConversations/CometChatConversations.tsx +23 -42
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +3 -3
- package/src/CometChatMessageList/CometChatMessageList.tsx +53 -11
- package/src/shared/constants/UIKitConstants.ts +1 -1
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +6 -4
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +93 -27
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +8 -2
- package/src/shared/framework/MessageDataSource.tsx +10 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +2 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +2 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +26 -23
- package/src/shared/utils/MarkdownUtils.ts +6 -1
- package/src/shared/utils/MessageUtils.tsx +66 -1
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +1 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +26 -10
- package/src/theme/CometChatThemeHelper.ts +9 -0
- package/src/theme/default/color/dark.ts +13 -0
- package/src/theme/default/color/light.ts +13 -1
|
@@ -29,7 +29,7 @@ const LINK_REGEX = /\[([^\]]+)\]\(([^)]+)\)/;
|
|
|
29
29
|
const URL_PROTOCOL_REGEX = /^(https?|mailto|tel):/i;
|
|
30
30
|
// Patterns for detecting list items inside blockquote content (ENG-31998)
|
|
31
31
|
const QUOTE_BULLET_REGEX = /^- (.*)$/;
|
|
32
|
-
const QUOTE_ORDERED_REGEX = /^(\d+)\.\s(.*)$/;
|
|
32
|
+
const QUOTE_ORDERED_REGEX = /^(\s*)(\d+)\.\s(.*)$/;
|
|
33
33
|
// Mention pattern — used to exclude mention UIDs from markdown marker detection
|
|
34
34
|
const MENTION_PATTERN_REGEX = /<@(?:uid|all):[^>]*>/g;
|
|
35
35
|
|
|
@@ -38,6 +38,49 @@ const LIST_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const }
|
|
|
38
38
|
const BULLET_MARKER_STYLE = { width: 18 };
|
|
39
39
|
const ORDERED_MARKER_STYLE = { width: 24 };
|
|
40
40
|
const LIST_CONTENT_STYLE = { flexShrink: 1, flexGrow: 1 };
|
|
41
|
+
|
|
42
|
+
/** Converts a number to lowercase alpha (1→a, 2→b, ..., 26→z, 27→aa) */
|
|
43
|
+
function toAlpha(n: number): string {
|
|
44
|
+
let result = '';
|
|
45
|
+
while (n > 0) {
|
|
46
|
+
n--;
|
|
47
|
+
result = String.fromCharCode(97 + (n % 26)) + result;
|
|
48
|
+
n = Math.floor(n / 26);
|
|
49
|
+
}
|
|
50
|
+
return result;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/** Converts a number to lowercase roman numerals */
|
|
54
|
+
function toRoman(n: number): string {
|
|
55
|
+
const vals = [1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1];
|
|
56
|
+
const syms = ['m', 'cm', 'd', 'cd', 'c', 'xc', 'l', 'xl', 'x', 'ix', 'v', 'iv', 'i'];
|
|
57
|
+
let result = '';
|
|
58
|
+
for (let i = 0; i < vals.length; i++) {
|
|
59
|
+
while (n >= vals[i]) {
|
|
60
|
+
result += syms[i];
|
|
61
|
+
n -= vals[i];
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
return result;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Formats a list counter based on nesting level (0→decimal, 1→alpha, 2+→roman) */
|
|
68
|
+
function formatListMarker(count: number, level: number): string {
|
|
69
|
+
if (level === 0) return `${count}. `;
|
|
70
|
+
if (level === 1) return `${toAlpha(count)}. `;
|
|
71
|
+
return `${toRoman(count)}. `;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Indentation width per nesting level for nested lists */
|
|
75
|
+
const NESTED_LIST_INDENT = 20;
|
|
76
|
+
|
|
77
|
+
/** Detect indentation level from leading spaces (4 spaces = 1 level) */
|
|
78
|
+
function getIndentLevel(line: string): number {
|
|
79
|
+
const match = line.match(/^(\s*)/);
|
|
80
|
+
if (!match) return 0;
|
|
81
|
+
return Math.floor(match[1].length / 4);
|
|
82
|
+
}
|
|
83
|
+
|
|
41
84
|
const BQ_TEXT_ROW_STYLE = { flexDirection: 'row' as const, flexShrink: 1 as const };
|
|
42
85
|
|
|
43
86
|
// Blockquote container styles — matches Figma spec (node 14736:1573987)
|
|
@@ -93,10 +136,12 @@ const defaultRichTextStyle: RichTextStyle = {
|
|
|
93
136
|
color: "#6852D6",
|
|
94
137
|
},
|
|
95
138
|
inlineCodeContainerStyle: {
|
|
96
|
-
backgroundColor: "
|
|
97
|
-
borderRadius:
|
|
98
|
-
|
|
99
|
-
|
|
139
|
+
backgroundColor: "rgba(120, 120, 128, 0.22)",
|
|
140
|
+
borderRadius: 4,
|
|
141
|
+
borderWidth: 0.5,
|
|
142
|
+
borderColor: "rgba(120, 120, 128, 0.35)",
|
|
143
|
+
paddingHorizontal: 4,
|
|
144
|
+
paddingVertical: 1,
|
|
100
145
|
},
|
|
101
146
|
codeBlockStyle: {
|
|
102
147
|
fontFamily: Platform.OS === "ios" ? "Menlo" : "monospace",
|
|
@@ -296,14 +341,14 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
296
341
|
}
|
|
297
342
|
// Render blockquote content — detect list items (ENG-31998)
|
|
298
343
|
const quoteContent: JSX.Element[] = [];
|
|
299
|
-
|
|
344
|
+
const quoteLevelCounters: Map<number, number> = new Map();
|
|
300
345
|
for (let i = 0; i < quoteLines.length; i++) {
|
|
301
346
|
const ql = quoteLines[i];
|
|
302
347
|
const bulletMatch = ql.match(QUOTE_BULLET_REGEX);
|
|
303
348
|
const orderedMatch = ql.match(QUOTE_ORDERED_REGEX);
|
|
304
349
|
if (bulletMatch) {
|
|
305
350
|
// Bullet items inside blockquote: render with marker + flex row
|
|
306
|
-
// Don't reset
|
|
351
|
+
// Don't reset quoteLevelCounters — numbering continues across bullet interruptions (Slack behavior)
|
|
307
352
|
quoteContent.push(
|
|
308
353
|
<View key={`ql-${i}`} style={LIST_ROW_STYLE}>
|
|
309
354
|
<Text style={BULLET_MARKER_STYLE}>{"‧ "}</Text>
|
|
@@ -313,20 +358,27 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
313
358
|
</View>
|
|
314
359
|
);
|
|
315
360
|
} else if (orderedMatch) {
|
|
316
|
-
// Numbered item inside blockquote:
|
|
317
|
-
|
|
361
|
+
// Numbered item inside blockquote: supports nested numbering (1. → a. → i.)
|
|
362
|
+
const level = Math.floor(orderedMatch[1].length / 4);
|
|
363
|
+
// Reset counters for deeper levels when returning to a shallower level
|
|
364
|
+
for (const [k] of quoteLevelCounters) {
|
|
365
|
+
if (k > level) quoteLevelCounters.delete(k);
|
|
366
|
+
}
|
|
367
|
+
const currentCount = (quoteLevelCounters.get(level) ?? 0) + 1;
|
|
368
|
+
quoteLevelCounters.set(level, currentCount);
|
|
369
|
+
const indent = level * NESTED_LIST_INDENT;
|
|
318
370
|
quoteContent.push(
|
|
319
|
-
<View key={`ql-${i}`} style={LIST_ROW_STYLE}>
|
|
320
|
-
<Text style={ORDERED_MARKER_STYLE}>{
|
|
371
|
+
<View key={`ql-${i}`} style={[LIST_ROW_STYLE, indent > 0 ? { marginLeft: indent } : undefined]}>
|
|
372
|
+
<Text style={ORDERED_MARKER_STYLE}>{formatListMarker(currentCount, level)}</Text>
|
|
321
373
|
<Text style={LIST_CONTENT_STYLE}>
|
|
322
|
-
{orderedMatch[
|
|
374
|
+
{orderedMatch[3].trim() === '' ? ' ' : this.parseInlineFormats(orderedMatch[3])}
|
|
323
375
|
</Text>
|
|
324
376
|
</View>
|
|
325
377
|
);
|
|
326
378
|
} else {
|
|
327
379
|
// Plain blockquote text — inline formats supported (Req 15.3)
|
|
328
380
|
// Wrap in View with flex:1 so long text wraps within blockquote bounds
|
|
329
|
-
|
|
381
|
+
quoteLevelCounters.clear();
|
|
330
382
|
quoteContent.push(
|
|
331
383
|
<View key={`ql-${i}`} style={BQ_TEXT_ROW_STYLE}>
|
|
332
384
|
<Text style={LIST_CONTENT_STYLE}>
|
|
@@ -360,24 +412,26 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
360
412
|
continue;
|
|
361
413
|
}
|
|
362
414
|
|
|
363
|
-
// Bullet lists (- ) —
|
|
415
|
+
// Bullet lists (- ) — supports nested lists via indentation (4 spaces per level)
|
|
364
416
|
if (isBulletLine(line)) {
|
|
365
417
|
hasViewChildren = true;
|
|
366
|
-
const listItems: string
|
|
418
|
+
const listItems: Array<{ text: string; level: number }> = [];
|
|
367
419
|
while (lineIndex < lines.length && isBulletLine(lines[lineIndex])) {
|
|
368
420
|
const raw = lines[lineIndex];
|
|
369
|
-
|
|
421
|
+
const level = getIndentLevel(raw);
|
|
370
422
|
const trimmed = raw.trim();
|
|
371
423
|
const itemText = trimmed.startsWith("- ") ? trimmed.substring(2) : "";
|
|
372
|
-
listItems.push(itemText);
|
|
424
|
+
listItems.push({ text: itemText, level });
|
|
373
425
|
lineIndex++;
|
|
374
426
|
}
|
|
375
427
|
for (let i = 0; i < listItems.length; i++) {
|
|
428
|
+
const { text: itemText, level } = listItems[i];
|
|
429
|
+
const indent = level * NESTED_LIST_INDENT;
|
|
376
430
|
elements.push(
|
|
377
|
-
<View key={`bullet-${elements.length}`} style={LIST_ROW_STYLE}>
|
|
431
|
+
<View key={`bullet-${elements.length}`} style={[LIST_ROW_STYLE, indent > 0 ? { marginLeft: indent } : undefined]}>
|
|
378
432
|
<Text style={BULLET_MARKER_STYLE}>{"‧ "}</Text>
|
|
379
433
|
<Text style={LIST_CONTENT_STYLE}>
|
|
380
|
-
{
|
|
434
|
+
{itemText.trim() === '' ? ' ' : this.parseInlineFormats(itemText)}
|
|
381
435
|
</Text>
|
|
382
436
|
</View>
|
|
383
437
|
);
|
|
@@ -387,27 +441,39 @@ export class CometChatRichTextFormatter extends CometChatTextFormatter {
|
|
|
387
441
|
continue;
|
|
388
442
|
}
|
|
389
443
|
|
|
390
|
-
// Ordered lists (1. ) —
|
|
444
|
+
// Ordered lists (1. ) — supports nested lists via indentation (4 spaces per level)
|
|
391
445
|
const orderedMatch = trimmedLine.match(ORDERED_LIST_REGEX);
|
|
392
446
|
if (orderedMatch) {
|
|
393
447
|
hasViewChildren = true;
|
|
394
|
-
|
|
448
|
+
// Collect all consecutive ordered list lines with their indentation levels
|
|
449
|
+
const listItems: Array<{ text: string; level: number }> = [];
|
|
395
450
|
while (lineIndex < lines.length) {
|
|
396
|
-
const
|
|
451
|
+
const rawLine = lines[lineIndex];
|
|
452
|
+
const itemMatch = rawLine.trim().match(ORDERED_LIST_REGEX);
|
|
397
453
|
if (itemMatch) {
|
|
398
|
-
|
|
454
|
+
const level = getIndentLevel(rawLine);
|
|
455
|
+
listItems.push({ text: itemMatch[2] ?? '', level });
|
|
399
456
|
lineIndex++;
|
|
400
457
|
} else {
|
|
401
458
|
break;
|
|
402
459
|
}
|
|
403
460
|
}
|
|
461
|
+
// Track counters per nesting level
|
|
462
|
+
const levelCounters: Map<number, number> = new Map();
|
|
404
463
|
for (let i = 0; i < listItems.length; i++) {
|
|
405
|
-
|
|
464
|
+
const { text: itemText, level } = listItems[i];
|
|
465
|
+
// Reset counters for deeper levels when we go back to a shallower level
|
|
466
|
+
for (const [k] of levelCounters) {
|
|
467
|
+
if (k > level) levelCounters.delete(k);
|
|
468
|
+
}
|
|
469
|
+
const currentCount = (levelCounters.get(level) ?? 0) + 1;
|
|
470
|
+
levelCounters.set(level, currentCount);
|
|
471
|
+
const indent = level * NESTED_LIST_INDENT;
|
|
406
472
|
elements.push(
|
|
407
|
-
<View key={`ordered-${elements.length}`} style={LIST_ROW_STYLE}>
|
|
408
|
-
<Text style={ORDERED_MARKER_STYLE}>{
|
|
473
|
+
<View key={`ordered-${elements.length}`} style={[LIST_ROW_STYLE, indent > 0 ? { marginLeft: indent } : undefined]}>
|
|
474
|
+
<Text style={ORDERED_MARKER_STYLE}>{formatListMarker(currentCount, level)}</Text>
|
|
409
475
|
<Text style={LIST_CONTENT_STYLE}>
|
|
410
|
-
{
|
|
476
|
+
{itemText.trim() === '' ? ' ' : this.parseInlineFormats(itemText)}
|
|
411
477
|
</Text>
|
|
412
478
|
</View>
|
|
413
479
|
);
|
|
@@ -75,8 +75,14 @@ export class CometChatUrlsFormatter extends CometChatTextFormatter {
|
|
|
75
75
|
if (!inputText) {
|
|
76
76
|
return null;
|
|
77
77
|
}
|
|
78
|
-
|
|
79
|
-
|
|
78
|
+
try {
|
|
79
|
+
let formattedText = this.getFormatTextForLinks({ str: inputText, style: this.style });
|
|
80
|
+
return formattedText;
|
|
81
|
+
} catch {
|
|
82
|
+
// Gracefully handle regex stack overflow on Android Hermes for very long messages.
|
|
83
|
+
// Return the input as-is rather than crashing the app.
|
|
84
|
+
return inputText;
|
|
85
|
+
}
|
|
80
86
|
}
|
|
81
87
|
|
|
82
88
|
getFormatTextForLinks = ({ str, style }: any): any => {
|
|
@@ -1054,6 +1054,15 @@ export class MessageDataSource implements DataSource {
|
|
|
1054
1054
|
}
|
|
1055
1055
|
};
|
|
1056
1056
|
|
|
1057
|
+
// Mentions style for reply preview — derived from theme tokens so customers can
|
|
1058
|
+
// override via CometChatThemeProvider. Uses same tokens as outgoing bubble mentions.
|
|
1059
|
+
const replyMentionsStyle = isOutgoingMessage
|
|
1060
|
+
? {
|
|
1061
|
+
textStyle: { color: theme.color.sendBubbleTextHighlight },
|
|
1062
|
+
backgroundColor: 'rgba(255, 255, 255, 0.25)',
|
|
1063
|
+
}
|
|
1064
|
+
: undefined;
|
|
1065
|
+
|
|
1057
1066
|
const previewComponent = (
|
|
1058
1067
|
<CometChatMessagePreview
|
|
1059
1068
|
message={hasQuotedMessage}
|
|
@@ -1069,6 +1078,7 @@ export class MessageDataSource implements DataSource {
|
|
|
1069
1078
|
}}
|
|
1070
1079
|
showCloseIcon={false}
|
|
1071
1080
|
isDeletedMessage={isQuotedMessageDeleted}
|
|
1081
|
+
mentionsStyle={replyMentionsStyle}
|
|
1072
1082
|
/>
|
|
1073
1083
|
);
|
|
1074
1084
|
|
|
@@ -509,5 +509,6 @@
|
|
|
509
509
|
"SEARCH_NO_MESSAGES": "No messages",
|
|
510
510
|
"MESSAGE_REPORTED": "Message reported",
|
|
511
511
|
"MARK_AS_UNREAD": "Mark Unread",
|
|
512
|
-
"NEW": "New"
|
|
512
|
+
"NEW": "New",
|
|
513
|
+
"GROUP_NO_LONGER_MEMBER": "You can't send message to this group because you're no longer a member."
|
|
513
514
|
}
|
|
@@ -509,5 +509,6 @@
|
|
|
509
509
|
"EDIT_LINK": "Редактировать ссылку",
|
|
510
510
|
"LINK_TEXT": "Текст ссылки",
|
|
511
511
|
"URL": "URL",
|
|
512
|
-
"INSERT": "Вставить"
|
|
512
|
+
"INSERT": "Вставить",
|
|
513
|
+
"GROUP_NO_LONGER_MEMBER": "Вы не можете отправить сообщение в эту группу, так как вы больше не являетесь участником."
|
|
513
514
|
}
|
|
@@ -7,6 +7,7 @@ import { getCometChatTranslation } from "../../resources/CometChatLocalizeNew/Lo
|
|
|
7
7
|
import { Icon } from "../../icons/Icon";
|
|
8
8
|
import { stripMarkdown, preparePreviewText } from "../MarkdownUtils";
|
|
9
9
|
import { CometChatRichTextFormatter } from "../../formatters/CometChatRichTextFormatter";
|
|
10
|
+
import { applyMentionsFormatting } from "../MessageUtils";
|
|
10
11
|
|
|
11
12
|
const t = getCometChatTranslation();
|
|
12
13
|
|
|
@@ -37,6 +38,9 @@ interface CometChatMessagePreviewProps {
|
|
|
37
38
|
|
|
38
39
|
// Deleted message indicator
|
|
39
40
|
isDeletedMessage?: boolean;
|
|
41
|
+
|
|
42
|
+
// Mentions style override for reply preview context
|
|
43
|
+
mentionsStyle?: any;
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
/**
|
|
@@ -56,7 +60,8 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
56
60
|
style,
|
|
57
61
|
subtitleIcon,
|
|
58
62
|
titleStyle,
|
|
59
|
-
isDeletedMessage = false
|
|
63
|
+
isDeletedMessage = false,
|
|
64
|
+
mentionsStyle,
|
|
60
65
|
} = props;
|
|
61
66
|
|
|
62
67
|
const theme = useTheme();
|
|
@@ -105,31 +110,25 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
105
110
|
case CometChat.MESSAGE_TYPE.TEXT:
|
|
106
111
|
const textMessage = message as CometChat.TextMessage;
|
|
107
112
|
let text = (typeof textMessage.getText === 'function' ? textMessage.getText() : (textMessage as any).text) || "";
|
|
108
|
-
try {
|
|
109
|
-
if (textMessage.getMentionedUsers && textMessage.getMentionedUsers().length > 0) {
|
|
110
|
-
const mentionedUsers = textMessage.getMentionedUsers();
|
|
111
|
-
const uidMap = new Map();
|
|
112
|
-
mentionedUsers.forEach(user => {
|
|
113
|
-
uidMap.set(user.getUid(), user.getName());
|
|
114
|
-
});
|
|
115
|
-
text = text.replace(/<@uid:(.*?)>/g, (match: string, uid: string): string => {
|
|
116
|
-
if (uidMap.has(uid)) {
|
|
117
|
-
return `@${uidMap.get(uid)}`;
|
|
118
|
-
}
|
|
119
|
-
return match;
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
text = text.replace(/<@all:(.*?)>/g, (match: string, alias: string): string => {
|
|
123
|
-
return `@${alias}`;
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
} catch (e) {
|
|
127
|
-
console.warn("Error formatting mentions in preview:", e);
|
|
128
|
-
}
|
|
129
113
|
|
|
130
114
|
// Prepare text for preview: collapse code blocks, strip block markers, flatten to single line
|
|
131
115
|
const previewResult = preparePreviewText(text);
|
|
132
116
|
const cleanText = previewResult.text;
|
|
117
|
+
// Set inline code styles for the preview context — uses theme's textPrimary
|
|
118
|
+
// which is white for outgoing (set by getReplyView) and dark for composer tray.
|
|
119
|
+
previewFormatter.setStyle({
|
|
120
|
+
inlineCodeStyle: {
|
|
121
|
+
fontSize: 14,
|
|
122
|
+
fontWeight: '400',
|
|
123
|
+
color: finalTheme?.color?.textPrimary as string || '#141414',
|
|
124
|
+
},
|
|
125
|
+
inlineCodeContainerStyle: {
|
|
126
|
+
backgroundColor: finalTheme?.color?.previewInlineCodeBackground ?? finalTheme?.color?.background3 ?? 'rgba(120, 120, 128, 0.18)',
|
|
127
|
+
borderRadius: 4,
|
|
128
|
+
borderWidth: 0.5,
|
|
129
|
+
borderColor: finalTheme?.color?.borderDefault ?? 'rgba(120, 120, 128, 0.3)',
|
|
130
|
+
},
|
|
131
|
+
});
|
|
133
132
|
const formatted = previewFormatter.getFormattedText(cleanText || null);
|
|
134
133
|
|
|
135
134
|
// Resolve subtitle content
|
|
@@ -140,6 +139,10 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
140
139
|
subtitleContent = (formatted as string) || stripMarkdown(text);
|
|
141
140
|
}
|
|
142
141
|
|
|
142
|
+
// Apply mentions formatter using shared helper (DRY — same as conversation list)
|
|
143
|
+
// mentionsStyle prop is passed from the caller (e.g., getReplyView in MessageDataSource)
|
|
144
|
+
subtitleContent = applyMentionsFormatting(textMessage, subtitleContent, text, mentionsStyle);
|
|
145
|
+
|
|
143
146
|
// For code blocks (first rich block): render compact code block container
|
|
144
147
|
if (previewResult.codeBlockFirstLine !== null) {
|
|
145
148
|
isCodeBlockPreview = true;
|
|
@@ -330,7 +333,7 @@ const CometChatMessagePreview = (props: CometChatMessagePreviewProps) => {
|
|
|
330
333
|
{iconToShow && <View>{iconToShow}</View>}
|
|
331
334
|
{isCodeBlockPreview ? (
|
|
332
335
|
<View style={previewBlockStyles.codeBlockRow}>
|
|
333
|
-
<View style={[previewBlockStyles.codeBlockBadge, { backgroundColor: finalTheme?.color?.background2 as string || '#FAFAFA', borderColor: finalTheme?.color?.borderDefault as string || '#E8E8E8' }]}>
|
|
336
|
+
<View style={[previewBlockStyles.codeBlockBadge, { backgroundColor: (finalTheme?.color?.previewCodeBlockBackground ?? finalTheme?.color?.background2) as string || '#FAFAFA', borderColor: (finalTheme?.color?.previewCodeBlockBorder ?? finalTheme?.color?.borderDefault) as string || '#E8E8E8' }]}>
|
|
334
337
|
<Text numberOfLines={1} ellipsizeMode='tail' style={[previewBlockStyles.codeBlockText, { color: finalTheme?.color?.textPrimary as string || '#141414' }]}>
|
|
335
338
|
{codeBlockLine + '..'}
|
|
336
339
|
</Text>
|
|
@@ -60,7 +60,12 @@ export function stripMarkdown(text: string): string {
|
|
|
60
60
|
// 9. Remove numbered list markers at start of lines
|
|
61
61
|
result = result.replace(/^\d+\.\s/gm, '');
|
|
62
62
|
|
|
63
|
-
// 10.
|
|
63
|
+
// 10. Strip HTML tags (e.g., <u>, <b>, <i>, <s>, <em>, <strong>, <del>, <br>, etc.)
|
|
64
|
+
// Preserve CometChat mention tokens <@uid:xxx> and <@all:xxx> which look like HTML tags
|
|
65
|
+
result = result.replace(/<br\s*\/?>/gi, '\n');
|
|
66
|
+
result = result.replace(/<(?!@(?:uid|all):)[^>]+>/g, '');
|
|
67
|
+
|
|
68
|
+
// 11. Remove any remaining backslash escapes (e.g., \* \_ \` \~)
|
|
64
69
|
result = result.replace(/\\([*_`~>\\])/g, '$1');
|
|
65
70
|
|
|
66
71
|
return result;
|
|
@@ -5,6 +5,7 @@ import { MessageBubbleAlignmentType } from "../base";
|
|
|
5
5
|
import {
|
|
6
6
|
CometChatCustomMessageTypes,
|
|
7
7
|
MessageCategoryConstants,
|
|
8
|
+
MentionsTargetElement,
|
|
8
9
|
MessageReceipt,
|
|
9
10
|
MessageTypeConstants,
|
|
10
11
|
} from "../constants/UIKitConstants";
|
|
@@ -13,7 +14,9 @@ import { Icon, IconName } from "../icons/Icon";
|
|
|
13
14
|
import { CometChatMessageTemplate } from "../modals";
|
|
14
15
|
import { CometChatMessageBubble } from "../views/CometChatMessageBubble";
|
|
15
16
|
import { BubbleStyles, CometChatTheme, OutgoingBubbleStyles } from "../../theme/type";
|
|
16
|
-
import { CometChatUIKit } from "../CometChatUiKit";
|
|
17
|
+
import { CometChatUIKit } from "../CometChatUiKit/CometChatUIKit";
|
|
18
|
+
import { SuggestionItem } from "../views/CometChatSuggestionList/SuggestionItem";
|
|
19
|
+
import { CommonUtils } from "./CommonUtils";
|
|
17
20
|
import { deepMerge } from "../helper/helperFunctions";
|
|
18
21
|
import { CometChatDate } from "../views/CometChatDate";
|
|
19
22
|
import { CometChatAvatar, CometChatReceipt } from "../views";
|
|
@@ -376,6 +379,68 @@ export const getMessagePreviewInternal = (
|
|
|
376
379
|
);
|
|
377
380
|
};
|
|
378
381
|
|
|
382
|
+
/**
|
|
383
|
+
* Applies mentions formatting to message content.
|
|
384
|
+
* Shared helper used by CometChatConversations subtitle and CometChatMessagePreview
|
|
385
|
+
* to ensure consistent @mention styling across the UI.
|
|
386
|
+
*
|
|
387
|
+
* @param message - The message containing mentioned users
|
|
388
|
+
* @param content - The current formatted content (string or JSX)
|
|
389
|
+
* @param rawText - The raw message text (for detecting @all alias tokens)
|
|
390
|
+
* @param mentionsStyle - Optional style overrides for mentions
|
|
391
|
+
* @returns The content with styled mentions applied
|
|
392
|
+
*/
|
|
393
|
+
export const applyMentionsFormatting = (
|
|
394
|
+
message: CometChat.BaseMessage,
|
|
395
|
+
content: string | JSX.Element,
|
|
396
|
+
rawText: string,
|
|
397
|
+
mentionsStyle?: any,
|
|
398
|
+
): string | JSX.Element => {
|
|
399
|
+
const containsAllAlias = /<@all:(.*?)>/.test(rawText);
|
|
400
|
+
if (!message.getMentionedUsers?.().length && !containsAllAlias) {
|
|
401
|
+
return content;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
try {
|
|
405
|
+
let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
|
|
406
|
+
mentionsFormatter.setContext("conversation");
|
|
407
|
+
mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
|
|
408
|
+
mentionsFormatter.setTargetElement(MentionsTargetElement.conversation);
|
|
409
|
+
mentionsFormatter.setMessage(message);
|
|
410
|
+
if (mentionsStyle) {
|
|
411
|
+
mentionsFormatter.setMentionsStyle(mentionsStyle);
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
if (containsAllAlias) {
|
|
415
|
+
const match = rawText.match(/<@all:(.*?)>/);
|
|
416
|
+
const aliasLabel = match && match[1] ? match[1] : "all";
|
|
417
|
+
let existing = mentionsFormatter.getSuggestionItems();
|
|
418
|
+
const underlyingText = `<@all:${aliasLabel}>`;
|
|
419
|
+
const already = existing.find((it: any) => it.underlyingText === underlyingText);
|
|
420
|
+
if (!already) {
|
|
421
|
+
const aliasItem = new SuggestionItem({
|
|
422
|
+
id: aliasLabel,
|
|
423
|
+
name: aliasLabel,
|
|
424
|
+
promptText: aliasLabel,
|
|
425
|
+
trackingCharacter: "@",
|
|
426
|
+
underlyingText,
|
|
427
|
+
hideLeadingIcon: true,
|
|
428
|
+
});
|
|
429
|
+
mentionsFormatter.setSuggestionItems([...existing, aliasItem]);
|
|
430
|
+
}
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
let suggestionUsers = mentionsFormatter.getSuggestionItems();
|
|
434
|
+
mentionsFormatter.setMessage(message);
|
|
435
|
+
if (suggestionUsers.length > 0) mentionsFormatter.setSuggestionItems(suggestionUsers);
|
|
436
|
+
let _formatter = CommonUtils.clone(mentionsFormatter);
|
|
437
|
+
return _formatter.getFormattedText(content, mentionsStyle);
|
|
438
|
+
} catch (e) {
|
|
439
|
+
console.warn("Error applying mentions formatting:", e);
|
|
440
|
+
return content;
|
|
441
|
+
}
|
|
442
|
+
};
|
|
443
|
+
|
|
379
444
|
export const getModerationStatus = (message: CometChat.BaseMessage | any): string => {
|
|
380
445
|
if (message?.getModerationStatus) {
|
|
381
446
|
try {
|
|
@@ -94,6 +94,7 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
|
|
|
94
94
|
<FlatList
|
|
95
95
|
data={data}
|
|
96
96
|
renderItem={_render}
|
|
97
|
+
keyExtractor={(item, index) => `${item.id}_${index}`}
|
|
97
98
|
onMomentumScrollEnd={(event) => {
|
|
98
99
|
const contentOffsetY = event.nativeEvent.contentOffset.y; // The current scroll position
|
|
99
100
|
const contentHeight = event.nativeEvent.contentSize.height; // Total height of the content
|