@cometchat/chat-uikit-react-native 5.5.0 → 5.5.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/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +20 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +9 -1
- package/ios/RichTextEditorView.swift +43 -0
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/RichTextEditorViewManager.swift +8 -0
- package/package.json +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +38 -9
- package/src/CometChatConversations/CometChatConversations.tsx +8 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +2 -2
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +15 -3
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +10 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +5 -2
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +7 -8
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +43 -19
- package/src/CometChatRichTextEditor/index.tsx +4 -0
- package/src/CometChatRichTextEditor/types.ts +2 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +251 -14
- package/src/CometChatSearch/CometChatSearch.tsx +29 -6
- package/src/shared/CometChatUiKit/CometChatUIKit.changes.md +76 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +2 -1
- package/src/shared/CometChatUiKit/checkAuthSettings-review.md +211 -0
- package/src/shared/constants/UIKitConstants.ts +3 -17
- package/src/shared/constants/textPatterns.ts +27 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +25 -259
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +31 -19
- package/src/shared/formatters/CometChatTextFormatter.ts +22 -0
- package/src/shared/formatters/applyRawFormatters.ts +31 -0
- package/src/shared/framework/MessageDataSource.tsx +14 -8
- package/src/shared/resources/CometChatLocalizeNew/CometChatI18nProvider.tsx +15 -30
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +138 -19
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +0 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +54 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +54 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +11 -0
- package/src/shared/utils/MarkdownUtils.ts +34 -4
- package/src/shared/utils/PinnedMessagesHelper.ts +65 -0
- package/src/shared/utils/SavedMessagesHelper.ts +42 -6
- package/src/shared/utils/__testUtils__/messagesRequestBuilderMock.ts +37 -0
- package/src/shared/utils/cloneRequestBuilder.ts +25 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +15 -4
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +5 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +4 -1
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +8 -1
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +5 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +5 -0
- package/src/shared/views/CometChatList/Header.tsx +8 -2
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +5 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +5 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +0 -154
|
@@ -17,8 +17,23 @@
|
|
|
17
17
|
* @module CometChatSavedMessages
|
|
18
18
|
*/
|
|
19
19
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
20
|
+
import { CometChatRichTextFormatter } from "../shared/formatters/CometChatRichTextFormatter";
|
|
21
|
+
import { preparePreviewText, stripMarkdown } from "../shared/utils/MarkdownUtils";
|
|
22
|
+
import {
|
|
23
|
+
applyMentionsFormatting,
|
|
24
|
+
getMessagePreviewInternal,
|
|
25
|
+
} from "../shared/utils/MessageUtils";
|
|
26
|
+
import { MessageCategoryConstants } from "../shared/constants/UIKitConstants";
|
|
20
27
|
import React, { JSX, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
21
|
-
import {
|
|
28
|
+
import {
|
|
29
|
+
FlatList,
|
|
30
|
+
GestureResponderEvent,
|
|
31
|
+
Platform,
|
|
32
|
+
Pressable,
|
|
33
|
+
StyleSheet,
|
|
34
|
+
Text,
|
|
35
|
+
View,
|
|
36
|
+
} from "react-native";
|
|
22
37
|
import { useCompTheme, useTheme } from "../theme/hook";
|
|
23
38
|
import { deepMerge } from "../shared/helper/helperFunctions";
|
|
24
39
|
import { DeepPartial } from "../shared/helper/types";
|
|
@@ -50,10 +65,34 @@ import {
|
|
|
50
65
|
} from "../shared/utils/PinSaveHelper";
|
|
51
66
|
import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
|
|
52
67
|
import { MessageEvents } from "../shared/events/messages";
|
|
68
|
+
import { CometChatTextFormatter } from "../shared/formatters/CometChatTextFormatter";
|
|
69
|
+
import { applyRawFormatters } from "../shared/formatters/applyRawFormatters";
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Module-level rich text formatter — reused across renders (no GC churn), mirroring
|
|
73
|
+
* CometChatConversations. A saved row shows the same preview a conversation row does,
|
|
74
|
+
* so it renders inline formatting rather than stripping it.
|
|
75
|
+
*/
|
|
76
|
+
const savedRichTextFormatter = new CometChatRichTextFormatter();
|
|
53
77
|
|
|
54
78
|
export interface CometChatSavedMessagesInterface {
|
|
55
79
|
/** Page size. Defaults to 30; the server caps the whole set at 100. */
|
|
56
80
|
limit?: number;
|
|
81
|
+
/**
|
|
82
|
+
* Your own request builder, for anything `limit` alone cannot express — a search
|
|
83
|
+
* term, a category or type filter, a different page size.
|
|
84
|
+
*
|
|
85
|
+
* `setSavedOnly(true)` is re-asserted on whatever you pass, so a builder that
|
|
86
|
+
* forgets it still returns saved messages rather than ordinary history. Set it
|
|
87
|
+
* anyway to keep the intent readable.
|
|
88
|
+
*
|
|
89
|
+
* Do NOT scope it to a conversation: saved is account-wide, and a uid/guid would
|
|
90
|
+
* turn this cross-conversation list into a per-chat one.
|
|
91
|
+
*
|
|
92
|
+
* The `limit` prop wins: `limit={10}` with a builder that calls `setLimit(50)` pages
|
|
93
|
+
* in tens. Without the prop the builder's own limit is used, and with neither, 30.
|
|
94
|
+
*/
|
|
95
|
+
messagesRequestBuilder?: CometChat.MessagesRequestBuilder;
|
|
57
96
|
/** Closes the surface — rendered as the ✕ in the header. */
|
|
58
97
|
onBack?: () => void;
|
|
59
98
|
/**
|
|
@@ -69,6 +108,12 @@ export interface CometChatSavedMessagesInterface {
|
|
|
69
108
|
hideUnsaveMessageOption?: boolean;
|
|
70
109
|
/** Replace the whole row body. */
|
|
71
110
|
ItemView?: (message: CometChat.BaseMessage) => JSX.Element;
|
|
111
|
+
/**
|
|
112
|
+
* Text formatters, same array the host passes to CometChatMessageList. Without them a consumer's
|
|
113
|
+
* own wire token is not UI Kit markup yet, so the formatter below has nothing to recognise and
|
|
114
|
+
* the row prints the token verbatim.
|
|
115
|
+
*/
|
|
116
|
+
textFormatters?: Array<CometChatTextFormatter>;
|
|
72
117
|
title?: string;
|
|
73
118
|
/** Per-instance style overrides, merged over the theme's savedMessagesStyles. */
|
|
74
119
|
style?: DeepPartial<SavedMessagesStyle>;
|
|
@@ -77,9 +122,34 @@ export interface CometChatSavedMessagesInterface {
|
|
|
77
122
|
type ListState = "loading" | "loaded" | "error" | "empty";
|
|
78
123
|
|
|
79
124
|
export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) => {
|
|
80
|
-
const {
|
|
125
|
+
const {
|
|
126
|
+
limit,
|
|
127
|
+
messagesRequestBuilder,
|
|
128
|
+
onBack,
|
|
129
|
+
onItemPress,
|
|
130
|
+
hideUnsaveMessageOption = false,
|
|
131
|
+
ItemView,
|
|
132
|
+
textFormatters,
|
|
133
|
+
title,
|
|
134
|
+
style,
|
|
135
|
+
} = props;
|
|
81
136
|
|
|
82
137
|
const theme = useTheme() as CometChatTheme;
|
|
138
|
+
|
|
139
|
+
// Same inline-code treatment the conversation list gives its subtitle.
|
|
140
|
+
useMemo(() => {
|
|
141
|
+
savedRichTextFormatter.setStyle({
|
|
142
|
+
inlineCodeStyle: { color: theme.color.primary as string },
|
|
143
|
+
inlineCodeContainerStyle: {
|
|
144
|
+
backgroundColor: "rgba(120, 120, 128, 0.22)",
|
|
145
|
+
borderRadius: 4,
|
|
146
|
+
borderWidth: 0.5,
|
|
147
|
+
borderColor: "rgba(120, 120, 128, 0.35)",
|
|
148
|
+
paddingHorizontal: 4,
|
|
149
|
+
paddingVertical: 1,
|
|
150
|
+
},
|
|
151
|
+
});
|
|
152
|
+
}, [theme]);
|
|
83
153
|
const compTheme = useCompTheme();
|
|
84
154
|
const { t } = useCometChatTranslation();
|
|
85
155
|
|
|
@@ -126,8 +196,11 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
126
196
|
/**
|
|
127
197
|
* The request is single-use and accumulates its own paging state, so it lives in
|
|
128
198
|
* a ref for the lifetime of the screen. Refreshing means building a NEW one.
|
|
199
|
+
*
|
|
200
|
+
* Built lazily below: a useRef ARGUMENT runs on every render and all but the first
|
|
201
|
+
* result is discarded, so the inline form built a request per render.
|
|
129
202
|
*/
|
|
130
|
-
const request = useRef(
|
|
203
|
+
const request = useRef<CometChat.MessagesRequest | null>(null);
|
|
131
204
|
const fetching = useRef(false);
|
|
132
205
|
/**
|
|
133
206
|
* The end of a cursor-paged list is an empty page — there is nothing to ask the request
|
|
@@ -136,8 +209,12 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
136
209
|
*/
|
|
137
210
|
const exhausted = useRef(false);
|
|
138
211
|
|
|
212
|
+
if (request.current === null) {
|
|
213
|
+
request.current = buildSavedMessagesRequest(limit, messagesRequestBuilder);
|
|
214
|
+
}
|
|
215
|
+
|
|
139
216
|
const loadNext = useCallback(async () => {
|
|
140
|
-
if (fetching.current || exhausted.current) return;
|
|
217
|
+
if (fetching.current || exhausted.current || !request.current) return;
|
|
141
218
|
fetching.current = true;
|
|
142
219
|
try {
|
|
143
220
|
// fetchPrevious(), not fetchNext() — "previous" is older, which is the direction
|
|
@@ -194,13 +271,15 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
194
271
|
* a retried request must start from the top of the list, not from a half-walked cursor.
|
|
195
272
|
*/
|
|
196
273
|
const reload = useCallback(() => {
|
|
197
|
-
request.current = buildSavedMessagesRequest(limit);
|
|
274
|
+
request.current = buildSavedMessagesRequest(limit, messagesRequestBuilder);
|
|
198
275
|
exhausted.current = false;
|
|
199
276
|
fetching.current = false;
|
|
200
277
|
setMessages([]);
|
|
201
278
|
setState("loading");
|
|
202
279
|
loadNext();
|
|
203
|
-
|
|
280
|
+
// messagesRequestBuilder included: without it a retry after the prop changes rebuilds
|
|
281
|
+
// the request from the builder captured at mount.
|
|
282
|
+
}, [limit, messagesRequestBuilder, loadNext]);
|
|
204
283
|
|
|
205
284
|
useEffect(() => {
|
|
206
285
|
CometChat.getLoggedinUser()
|
|
@@ -412,7 +491,116 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
412
491
|
);
|
|
413
492
|
const prefix = prefixName ? `${prefixName}: ` : "";
|
|
414
493
|
|
|
415
|
-
const
|
|
494
|
+
const rawLabel = preview.text ?? (preview.labelKey ? (t(preview.labelKey) ?? "") : "");
|
|
495
|
+
|
|
496
|
+
// Render inline formatting rather than printing the wire format. preparePreviewText
|
|
497
|
+
// reduces a multi-line or block message to one line — the formatter must not meet
|
|
498
|
+
// block-level markers — and reports which KIND of block it found. The four cases get
|
|
499
|
+
// the same treatment the conversation list gives them, so a saved row reads like the
|
|
500
|
+
// chat it came from.
|
|
501
|
+
//
|
|
502
|
+
// `prepared.text` is EMPTY for a code block: its content arrives in
|
|
503
|
+
// `codeBlockFirstLine`. Reading only `.text` rendered an empty subtitle for any
|
|
504
|
+
// message that was just a code block.
|
|
505
|
+
// The consumer's own token becomes UI Kit markup BEFORE any of the preparation below: run it
|
|
506
|
+
// after preparePreviewText or the rich formatter and the token has already been flattened into
|
|
507
|
+
// plain characters, with nothing left to colour.
|
|
508
|
+
const prepared = preparePreviewText(applyRawFormatters(rawLabel, textFormatters));
|
|
509
|
+
// The conversation list's pipeline, step for step, so the same message reads the
|
|
510
|
+
// same in Chats and in Saved Messages:
|
|
511
|
+
// text message -> rich formatter (colour, bold, italic, inline code)
|
|
512
|
+
// anything else -> stripMarkdown, as markers would render as literal characters
|
|
513
|
+
// then -> mentions resolved from "@uid" to the user's name
|
|
514
|
+
const format = (value: string): string | JSX.Element => {
|
|
515
|
+
const trimmed = value.trim();
|
|
516
|
+
const isPlainTextMessage =
|
|
517
|
+
message instanceof CometChat.TextMessage &&
|
|
518
|
+
message.getCategory() === MessageCategoryConstants.message;
|
|
519
|
+
|
|
520
|
+
let content: string | JSX.Element = isPlainTextMessage
|
|
521
|
+
? (savedRichTextFormatter.getFormattedText(trimmed) ?? trimmed)
|
|
522
|
+
: stripMarkdown(trimmed);
|
|
523
|
+
|
|
524
|
+
content = applyMentionsFormatting(message, content, trimmed, undefined);
|
|
525
|
+
return content;
|
|
526
|
+
};
|
|
527
|
+
|
|
528
|
+
// A message that leads with a URL previews as a link chip rather than the raw
|
|
529
|
+
// address, matching the conversation list. Checked on the first 50 characters, as
|
|
530
|
+
// the list does, so a link mentioned late in a long message is not treated as one.
|
|
531
|
+
const leadsWithLink =
|
|
532
|
+
message instanceof CometChat.TextMessage &&
|
|
533
|
+
message.getCategory() === MessageCategoryConstants.message &&
|
|
534
|
+
(() => {
|
|
535
|
+
const raw = typeof message.getText === "function" ? message.getText() : undefined;
|
|
536
|
+
return typeof raw === "string" && !!raw.slice(0, 50).match(/https?:\/\//);
|
|
537
|
+
})();
|
|
538
|
+
|
|
539
|
+
// Whether `label` already brings its own wrapper element. The block branches below return a
|
|
540
|
+
// <View>, and a <View> nested inside a <Text> lays out on iOS but COLLAPSES on Android — the
|
|
541
|
+
// saved row showed a bare "…" for every code block and blockquote. CometChatConversations
|
|
542
|
+
// renders its equivalent bare for exactly this reason.
|
|
543
|
+
let labelIsSelfWrapped = false;
|
|
544
|
+
let label: string | JSX.Element;
|
|
545
|
+
if (leadsWithLink) {
|
|
546
|
+
label = getMessagePreviewInternal("link-fill", t("LINK") ?? "Link", { theme });
|
|
547
|
+
labelIsSelfWrapped = true;
|
|
548
|
+
} else if (prepared.codeBlockFirstLine !== null) {
|
|
549
|
+
label = (
|
|
550
|
+
<View style={localStyles.codeBlockRow}>
|
|
551
|
+
<View
|
|
552
|
+
style={[
|
|
553
|
+
localStyles.codeBlockBadge,
|
|
554
|
+
{
|
|
555
|
+
backgroundColor: (theme?.color?.background2 as string) || "#FAFAFA",
|
|
556
|
+
borderColor: (theme?.color?.borderDefault as string) || "#E8E8E8",
|
|
557
|
+
},
|
|
558
|
+
]}
|
|
559
|
+
>
|
|
560
|
+
<Text
|
|
561
|
+
numberOfLines={1}
|
|
562
|
+
ellipsizeMode='tail'
|
|
563
|
+
style={[
|
|
564
|
+
localStyles.codeBlockText,
|
|
565
|
+
{ color: (theme?.color?.textPrimary as string) || "#141414" },
|
|
566
|
+
]}
|
|
567
|
+
>
|
|
568
|
+
{prepared.codeBlockFirstLine + ".."}
|
|
569
|
+
</Text>
|
|
570
|
+
</View>
|
|
571
|
+
</View>
|
|
572
|
+
);
|
|
573
|
+
labelIsSelfWrapped = true;
|
|
574
|
+
} else if (prepared.isBlockquote) {
|
|
575
|
+
label = (
|
|
576
|
+
<View style={localStyles.blockquoteRow}>
|
|
577
|
+
<View
|
|
578
|
+
style={[
|
|
579
|
+
localStyles.blockquoteBar,
|
|
580
|
+
{ backgroundColor: theme?.color?.primary as string },
|
|
581
|
+
]}
|
|
582
|
+
/>
|
|
583
|
+
<Text
|
|
584
|
+
numberOfLines={1}
|
|
585
|
+
ellipsizeMode='tail'
|
|
586
|
+
style={[itemStyle?.subtitleStyle, localStyles.blockquoteText]}
|
|
587
|
+
>
|
|
588
|
+
{format(prepared.text)}
|
|
589
|
+
</Text>
|
|
590
|
+
</View>
|
|
591
|
+
);
|
|
592
|
+
labelIsSelfWrapped = true;
|
|
593
|
+
} else if (prepared.listPrefix) {
|
|
594
|
+
label = (
|
|
595
|
+
<Text numberOfLines={1} ellipsizeMode='tail' style={itemStyle?.subtitleStyle}>
|
|
596
|
+
{prepared.listPrefix}
|
|
597
|
+
{format(prepared.text)}
|
|
598
|
+
</Text>
|
|
599
|
+
);
|
|
600
|
+
labelIsSelfWrapped = true;
|
|
601
|
+
} else {
|
|
602
|
+
label = format(prepared.text);
|
|
603
|
+
}
|
|
416
604
|
|
|
417
605
|
return (
|
|
418
606
|
<View style={localStyles.subtitleRow}>
|
|
@@ -433,13 +621,17 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
433
621
|
containerStyle={styles.previewIconContainerStyle}
|
|
434
622
|
/>
|
|
435
623
|
) : null}
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
624
|
+
{labelIsSelfWrapped ? (
|
|
625
|
+
label
|
|
626
|
+
) : (
|
|
627
|
+
<Text
|
|
628
|
+
numberOfLines={1}
|
|
629
|
+
ellipsizeMode='tail'
|
|
630
|
+
style={[itemStyle?.subtitleStyle, localStyles.subtitleText]}
|
|
631
|
+
>
|
|
632
|
+
{label}
|
|
633
|
+
</Text>
|
|
634
|
+
)}
|
|
443
635
|
</View>
|
|
444
636
|
);
|
|
445
637
|
};
|
|
@@ -620,10 +812,55 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
620
812
|
* lives in ./style.ts (or conversationStyles, for the row chrome) and is merged in.
|
|
621
813
|
*/
|
|
622
814
|
const localStyles = StyleSheet.create({
|
|
815
|
+
// Block-preview styling, matching CometChatConversations so a saved row and a
|
|
816
|
+
// conversation row render the same message identically.
|
|
817
|
+
codeBlockRow: {
|
|
818
|
+
flexDirection: "row",
|
|
819
|
+
alignItems: "center",
|
|
820
|
+
flexShrink: 2,
|
|
821
|
+
},
|
|
822
|
+
codeBlockBadge: {
|
|
823
|
+
borderRadius: 4,
|
|
824
|
+
borderWidth: 1,
|
|
825
|
+
paddingHorizontal: 6,
|
|
826
|
+
paddingVertical: 2,
|
|
827
|
+
flexShrink: 1,
|
|
828
|
+
},
|
|
829
|
+
codeBlockText: {
|
|
830
|
+
fontFamily: Platform.OS === "ios" ? "Menlo" : "monospace",
|
|
831
|
+
fontSize: 11,
|
|
832
|
+
},
|
|
833
|
+
blockquoteRow: {
|
|
834
|
+
flexDirection: "row",
|
|
835
|
+
alignItems: "stretch",
|
|
836
|
+
backgroundColor: "rgba(104, 81, 214, 0.08)",
|
|
837
|
+
borderRadius: 6,
|
|
838
|
+
flexShrink: 2,
|
|
839
|
+
minHeight: 22,
|
|
840
|
+
paddingVertical: 1,
|
|
841
|
+
},
|
|
842
|
+
blockquoteBar: {
|
|
843
|
+
width: 3,
|
|
844
|
+
borderRadius: 1.5,
|
|
845
|
+
marginVertical: 3,
|
|
846
|
+
marginLeft: 4,
|
|
847
|
+
},
|
|
848
|
+
blockquoteText: {
|
|
849
|
+
flex: 1,
|
|
850
|
+
paddingHorizontal: 5,
|
|
851
|
+
lineHeight: 18,
|
|
852
|
+
},
|
|
623
853
|
subtitleRow: {
|
|
624
854
|
flexDirection: "row",
|
|
625
855
|
alignItems: "center",
|
|
626
856
|
flexShrink: 1,
|
|
857
|
+
// flex:1 so the row actually FILLS the list item's subtitle slot. Without it the row is
|
|
858
|
+
// content-sized, and the block children inside (the code-block badge, the blockquote bar +
|
|
859
|
+
// text) size from a Text whose `flex: 1` gives it a flex-basis of 0 — contributing nothing to
|
|
860
|
+
// the content width. On Android that collapses to zero and the row renders a bare "…".
|
|
861
|
+
// CometChatConversations avoids this by returning a FRAGMENT, so its children sit directly in
|
|
862
|
+
// the list item's subtitle container rather than inside an extra content-sized View.
|
|
863
|
+
flex: 1,
|
|
627
864
|
},
|
|
628
865
|
subtitleText: {
|
|
629
866
|
flexShrink: 1,
|
|
@@ -20,6 +20,8 @@ import { getCometChatTranslation } from '../shared/resources/CometChatLocalizeNe
|
|
|
20
20
|
import { CommonUtils } from '../shared/utils/CommonUtils';
|
|
21
21
|
import { stripMarkdown } from '../shared/utils/MarkdownUtils';
|
|
22
22
|
import { CometChatRichTextFormatter } from '../shared/formatters/CometChatRichTextFormatter';
|
|
23
|
+
import { CometChatTextFormatter } from '../shared/formatters/CometChatTextFormatter';
|
|
24
|
+
import { applyRawFormatters } from '../shared/formatters/applyRawFormatters';
|
|
23
25
|
import { ExtensionConstants } from '../extensions/ExtensionConstants';
|
|
24
26
|
import { getExtensionData } from '../extensions/ExtensionModerator';
|
|
25
27
|
|
|
@@ -34,10 +36,16 @@ const searchRichTextFormatter = new CometChatRichTextFormatter();
|
|
|
34
36
|
* so only colour runs remain — the result is always inline `<Text>`, never a block-level `View`.
|
|
35
37
|
* Returns a JSX element when the text carries colour, a plain string otherwise.
|
|
36
38
|
*/
|
|
37
|
-
const formatPreviewText = (
|
|
39
|
+
const formatPreviewText = (
|
|
40
|
+
rawText: any,
|
|
41
|
+
message?: CometChat.BaseMessage,
|
|
42
|
+
textFormatters?: Array<CometChatTextFormatter>
|
|
43
|
+
): string | JSX.Element => {
|
|
38
44
|
if (typeof rawText !== 'string') return rawText;
|
|
39
45
|
|
|
40
|
-
|
|
46
|
+
// A consumer's own wire token becomes UI Kit markup first; `stripMarkdown` below removes
|
|
47
|
+
// anything it does not recognise, so nothing left until later would survive.
|
|
48
|
+
let text = stripMarkdown(applyRawFormatters(rawText, textFormatters), true).replace(/<@all:(.*?)>/g, '@$1');
|
|
41
49
|
|
|
42
50
|
try {
|
|
43
51
|
const mentionedUsers: CometChat.User[] = (message && (message).getMentionedUsers && (message).getMentionedUsers()) || [];
|
|
@@ -328,6 +336,15 @@ interface CometChatSearchProps {
|
|
|
328
336
|
*/
|
|
329
337
|
conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
|
|
330
338
|
|
|
339
|
+
/**
|
|
340
|
+
* Text formatters, the same instances passed to the message list and the composer.
|
|
341
|
+
*
|
|
342
|
+
* A search row renders the message's own text, so a consumer's wire token has to be rewritten
|
|
343
|
+
* here too — otherwise a message reads coloured in the chat and raw in the search results.
|
|
344
|
+
* Only `formatRawText` is used: rows are flattened to a single line.
|
|
345
|
+
*/
|
|
346
|
+
textFormatters?: Array<CometChatTextFormatter>;
|
|
347
|
+
|
|
331
348
|
/**
|
|
332
349
|
* Custom view component for text message items
|
|
333
350
|
* @param message - The text message object to render
|
|
@@ -606,10 +623,11 @@ interface ConversationItemProps {
|
|
|
606
623
|
mergedStyles: any;
|
|
607
624
|
theme: any;
|
|
608
625
|
conversationItemView?: (conversation: CometChat.Conversation, searchKeyword?: string) => React.ReactElement;
|
|
626
|
+
textFormatters?: Array<CometChatTextFormatter>;
|
|
609
627
|
}
|
|
610
628
|
|
|
611
629
|
const ConversationItem = React.memo<ConversationItemProps>((
|
|
612
|
-
{ conversation, searchText, onPress, mergedStyles, theme, conversationItemView }
|
|
630
|
+
{ conversation, searchText, onPress, mergedStyles, theme, conversationItemView, textFormatters }
|
|
613
631
|
) => {
|
|
614
632
|
const getStatusIndicator = () => {
|
|
615
633
|
const withObj = conversation.getConversationWith();
|
|
@@ -684,7 +702,7 @@ const ConversationItem = React.memo<ConversationItemProps>((
|
|
|
684
702
|
{conversation.getConversationWith().getName()}
|
|
685
703
|
</Text>
|
|
686
704
|
<Text style={mergedStyles.conversationItemStyle?.subtitleStyle} numberOfLines={2}>
|
|
687
|
-
{formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage())}
|
|
705
|
+
{formatPreviewText((conversation.getLastMessage())?.getText?.(), conversation.getLastMessage(), textFormatters)}
|
|
688
706
|
</Text>
|
|
689
707
|
</View>
|
|
690
708
|
{renderTrailingView()}
|
|
@@ -728,6 +746,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
728
746
|
emptyView,
|
|
729
747
|
errorView,
|
|
730
748
|
conversationItemView,
|
|
749
|
+
textFormatters,
|
|
731
750
|
textMessageItemView,
|
|
732
751
|
imageMessageItemView,
|
|
733
752
|
audioMessageItemView,
|
|
@@ -1468,7 +1487,10 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1468
1487
|
// The caption carries wire markup since ENG-38258, and it is concatenated with the count
|
|
1469
1488
|
// label below — so it is flattened here, exactly as the conversation row flattens it.
|
|
1470
1489
|
const caption = stripMarkdown(
|
|
1471
|
-
(
|
|
1490
|
+
applyRawFormatters(
|
|
1491
|
+
(typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "") || "",
|
|
1492
|
+
textFormatters
|
|
1493
|
+
)
|
|
1472
1494
|
);
|
|
1473
1495
|
const firstName =
|
|
1474
1496
|
atts[0]?.getName?.() || (message.getAttachment?.() as any)?.getName?.() || "";
|
|
@@ -1517,7 +1539,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1517
1539
|
return getMediaSearchSubtitle(message as CometChat.MediaMessage);
|
|
1518
1540
|
}
|
|
1519
1541
|
if (messageType === "text") {
|
|
1520
|
-
return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message)
|
|
1542
|
+
return formatPreviewText((message as CometChat.TextMessage).getText?.() ?? "", message, textFormatters)
|
|
1521
1543
|
|| messageType || "Message";
|
|
1522
1544
|
}
|
|
1523
1545
|
if (message.getCategory() === MessageCategoryConstants.card) {
|
|
@@ -1865,6 +1887,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
1865
1887
|
mergedStyles={mergedStyles}
|
|
1866
1888
|
theme={theme}
|
|
1867
1889
|
conversationItemView={conversationItemView}
|
|
1890
|
+
textFormatters={textFormatters}
|
|
1868
1891
|
/>
|
|
1869
1892
|
);
|
|
1870
1893
|
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
# CometChatUIKit.ts — Auth-check refactor
|
|
2
|
+
|
|
3
|
+
## What changed
|
|
4
|
+
|
|
5
|
+
The `checkAuthSettings()` helper and its call sites were refactored. The single
|
|
6
|
+
function that did three jobs (predicate + error construction + error
|
|
7
|
+
dispatch via a callback) was split into three small, single-purpose pieces:
|
|
8
|
+
|
|
9
|
+
| Member | Kind | Responsibility |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| `checkAuthSettings()` | public, pure predicate | Returns `true` when the UIKit is configured well enough to make authenticated calls (`uiKitSettings != null && uiKitSettings.appId` set). No side effects. |
|
|
12
|
+
| `authError()` | private factory | Single source of truth for the "not initialized" exception. Returns the correct `CometChatException` (`code: "ERR"` when settings are null, `code: "appIdErr"` when only `appId` is missing). |
|
|
13
|
+
| `assertInitialized()` | private guard | Throws `authError()` when unconfigured. Safe in both `async` methods (the throw becomes a rejected promise) and sync methods that are caught. |
|
|
14
|
+
|
|
15
|
+
Call sites updated:
|
|
16
|
+
|
|
17
|
+
- `getLoggedInUser()` / `login()` → `CometChatUIKit.assertInitialized();`
|
|
18
|
+
- `logout()` / `createUser()` / `updateUser()` → `if (!this.checkAuthSettings()) return Promise.reject(this.authError());`
|
|
19
|
+
|
|
20
|
+
## Why it was necessary
|
|
21
|
+
|
|
22
|
+
The old `checkAuthSettings(onError)` took an error callback and returned a
|
|
23
|
+
boolean, and **every call site was using it incorrectly** — the guard either
|
|
24
|
+
did nothing or did the opposite of what was intended:
|
|
25
|
+
|
|
26
|
+
1. **No-op guards (`getLoggedInUser`, `login`)**
|
|
27
|
+
|
|
28
|
+
```ts
|
|
29
|
+
if (CometChatUIKit.checkAuthSettings(Promise.reject)) null;
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
`Promise.reject` was passed as the `onError` callback, but its return value
|
|
33
|
+
was discarded and the `if` body was just `null`. When settings were missing
|
|
34
|
+
the method continued anyway instead of stopping — so the guard provided **no
|
|
35
|
+
protection at all**.
|
|
36
|
+
|
|
37
|
+
2. **Inverted logic (`logout`)**
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
if (this.checkAuthSettings(Promise.reject)) {
|
|
41
|
+
return Promise.reject(/* not initialized */);
|
|
42
|
+
}
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
`checkAuthSettings` returned `true` when the UIKit **was** properly
|
|
46
|
+
configured. So this rejected with "UIKit not initialized" exactly when it
|
|
47
|
+
*was* initialized, and proceeded when it was not — **backwards**.
|
|
48
|
+
|
|
49
|
+
3. **Empty guards (`createUser`, `updateUser`)**
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
if (this.checkAuthSettings(Promise.reject)) {
|
|
53
|
+
}
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
Empty body. The only effect was the `Promise.reject` callback firing as a
|
|
57
|
+
side effect, creating an unhandled rejection while the method continued.
|
|
58
|
+
|
|
59
|
+
The root cause was a function that mixed a **predicate** with **error
|
|
60
|
+
dispatch**, which made every call site ambiguous and easy to get wrong. After
|
|
61
|
+
the split:
|
|
62
|
+
|
|
63
|
+
- `checkAuthSettings()` reads as a plain question — `if (!checkAuthSettings())`
|
|
64
|
+
is unambiguous.
|
|
65
|
+
- Async methods `assertInitialized()` (throw → rejected promise).
|
|
66
|
+
- The exception text/codes live in one place (`authError()`), so the
|
|
67
|
+
"call `init()` first" message is consistent everywhere.
|
|
68
|
+
|
|
69
|
+
## Behavioral result
|
|
70
|
+
|
|
71
|
+
Every public entry point now **actually fails fast** with the correct
|
|
72
|
+
`CometChatException` when the UIKit has not been initialized, instead of
|
|
73
|
+
silently continuing or rejecting on the wrong condition.
|
|
74
|
+
|
|
75
|
+
The accompanying test file `__tests__/CometChatUIKit.test.ts` was updated to
|
|
76
|
+
cover these guards.
|