@cometchat/chat-uikit-react-native 5.4.0 → 5.5.0
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/CometChatClipboardModule.kt +34 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +605 -6
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +20 -1
- package/ios/CometChatClipboardModule.m +5 -0
- package/ios/CometChatClipboardModule.swift +22 -0
- package/ios/RichTextEditorView.swift +648 -35
- package/ios/RichTextEditorViewManager.m +2 -0
- package/ios/RichTextEditorViewManager.swift +16 -0
- package/package.json +2 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +245 -55
- package/src/CometChatCompactMessageComposer/index.ts +2 -0
- package/src/CometChatConversations/CometChatConversations.tsx +291 -14
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +181 -12
- package/src/CometChatMessageList/CometChatMessageList.tsx +568 -15
- package/src/CometChatMessageList/components/MessageModals.tsx +30 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +14 -1
- package/src/CometChatMessageList/components/MessageQuickActions.tsx +162 -0
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +940 -0
- package/src/CometChatPinnedMessages/index.ts +5 -0
- package/src/CometChatPinnedMessages/style.ts +216 -0
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +5 -0
- package/src/CometChatRichTextEditor/index.tsx +27 -1
- package/src/CometChatRichTextEditor/types.ts +19 -1
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +634 -0
- package/src/CometChatSavedMessages/index.ts +5 -0
- package/src/CometChatSavedMessages/style.ts +159 -0
- package/src/CometChatSearch/CometChatSearch.tsx +47 -340
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +22 -2
- package/src/index.ts +60 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +16 -0
- package/src/shared/base/Types.ts +5 -0
- package/src/shared/constants/UIKitConstants.ts +13 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +34 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +37 -0
- package/src/shared/events/ListenerInitializer.ts +20 -1
- package/src/shared/events/messages.ts +18 -0
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +95 -8
- package/src/shared/formatters/index.ts +14 -0
- package/src/shared/formatters/richTextWireFormat.ts +165 -0
- package/src/shared/framework/MessageDataSource.tsx +296 -3
- package/src/shared/icons/components/thread-follow.tsx +13 -0
- package/src/shared/icons/components/thread-unfollow.tsx +13 -0
- package/src/shared/icons/components/unsave.tsx +13 -0
- package/src/shared/icons/icon-mapping.tsx +6 -0
- package/src/shared/index.ts +37 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +54 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +2 -1
- package/src/shared/utils/MarkdownUtils.ts +25 -4
- package/src/shared/utils/MessageUtils.tsx +80 -5
- package/src/shared/utils/PinConversationHelper.ts +245 -0
- package/src/shared/utils/PinSaveFeatureGates.ts +178 -0
- package/src/shared/utils/PinSaveHelper.ts +549 -0
- package/src/shared/utils/SavedMessagesHelper.ts +231 -0
- package/src/shared/utils/ThreadSubscriptionHelper.ts +427 -0
- package/src/shared/utils/conversationUtils.ts +8 -1
- package/src/shared/utils/elementType.tsx +38 -0
- package/src/shared/utils/stripRichText.ts +7 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +21 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +6 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +4 -0
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +17 -5
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +28 -14
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +2 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +91 -20
- package/src/shared/views/CometChatList/CometChatList.tsx +6 -1
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +4 -0
- package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +1 -0
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +4 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
- package/src/shared/views/ErrorEmptyView/ErrorEmptyView.tsx +4 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/type.ts +4 -0
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { Text, View } from "react-native";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Identity checks for react-native's `View` / `Text` that survive a wrapped JSX runtime.
|
|
5
|
+
*
|
|
6
|
+
* We ship raw `.tsx`, so the *consumer's* babel compiles our source. A build that
|
|
7
|
+
* substitutes the JSX runtime — NativeWind (`react-native-css-interop`) being the common
|
|
8
|
+
* case — swaps every element's type for an equivalent wrapper (`CssInterop.View`). A bare
|
|
9
|
+
* `element.type === View` then silently returns false, and rich-text bubbles lose their
|
|
10
|
+
* colour and truncation (ENG-38093).
|
|
11
|
+
*
|
|
12
|
+
* The fix is to stop assuming what a `View` element looks like and ask the runtime that is
|
|
13
|
+
* actually in effect. Because these probes are compiled by the same pipeline as the code
|
|
14
|
+
* whose elements we inspect, they resolve to whatever identity that pipeline produces.
|
|
15
|
+
*
|
|
16
|
+
* The probes must be written as JSX. `React.createElement` is deliberately NOT equivalent:
|
|
17
|
+
* css-interop wraps only the JSX runtime and re-exports `createElement` untouched, so
|
|
18
|
+
* building the probe that way would capture the unwrapped identity and defeat the purpose.
|
|
19
|
+
*
|
|
20
|
+
* With no wrapper present these constants are simply `View` / `Text`, so the checks behave
|
|
21
|
+
* exactly as the original strict comparison did — no behaviour change for consumers who
|
|
22
|
+
* don't transform our JSX.
|
|
23
|
+
*/
|
|
24
|
+
const RUNTIME_VIEW = (<View />).type;
|
|
25
|
+
const RUNTIME_TEXT = (<Text />).type;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* True when `el` is a react-native `View` element.
|
|
29
|
+
*
|
|
30
|
+
* The `=== View` arm is a fallback for elements built outside our own compilation unit —
|
|
31
|
+
* e.g. a consumer's custom `CometChatTextFormatter` returning a plain `<View>` tree.
|
|
32
|
+
*/
|
|
33
|
+
export const isViewElement = (el: any): boolean =>
|
|
34
|
+
el?.type === RUNTIME_VIEW || el?.type === View;
|
|
35
|
+
|
|
36
|
+
/** True when `el` is a react-native `Text` element. Mirrors {@link isViewElement}. */
|
|
37
|
+
export const isTextElement = (el: any): boolean =>
|
|
38
|
+
el?.type === RUNTIME_TEXT || el?.type === Text;
|
|
@@ -6,10 +6,17 @@
|
|
|
6
6
|
* Only a whitelist of known formatting tags is removed, so legitimate text such
|
|
7
7
|
* as "make a <product>" or "5 < 10" is preserved.
|
|
8
8
|
*/
|
|
9
|
+
import { stripColorTags } from "../formatters/richTextWireFormat";
|
|
10
|
+
|
|
9
11
|
export const stripRichText = (input?: string | null): string => {
|
|
10
12
|
if (!input) return "";
|
|
11
13
|
let text = input;
|
|
12
14
|
|
|
15
|
+
// 0. Remove the rich-text wire format's colour tokens. These are NOT HTML, so the
|
|
16
|
+
// whitelist in step 1 does not (and must not) match them — `<color=#ff0000>` would
|
|
17
|
+
// otherwise reach users verbatim in plain-text previews.
|
|
18
|
+
text = stripColorTags(text);
|
|
19
|
+
|
|
13
20
|
// 1. Remove the HTML formatting tags the compact composer can emit — bold, italic,
|
|
14
21
|
// underline, strikethrough, link, ordered/unordered lists, blockquote, inline code
|
|
15
22
|
// and code-block, plus the structural wrappers these produce. Whitelisted (not a
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import Clipboard from '@react-native-clipboard/clipboard';
|
|
1
2
|
import NativeCometChatClipboardModule from './NativeCometChatClipboardModule';
|
|
2
3
|
import type { ClipboardImageResult } from './NativeCometChatClipboardModule';
|
|
4
|
+
import { stripColorTags } from '../../formatters/richTextWireFormat';
|
|
3
5
|
|
|
4
6
|
export type { ClipboardImageResult };
|
|
5
7
|
|
|
@@ -25,4 +27,23 @@ export const ClipboardPasteHandler = {
|
|
|
25
27
|
return null;
|
|
26
28
|
}
|
|
27
29
|
},
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Copies message text, preserving inline colour for a paste back into our own composer.
|
|
33
|
+
*
|
|
34
|
+
* Every app gets the plain text with the wire format stripped; only our editor reads the
|
|
35
|
+
* private representation, so `<color=…>` markup can never leak into Notes, mail or another
|
|
36
|
+
* chat app. Falls back to a plain copy when the native module is unavailable — the text
|
|
37
|
+
* still lands on the clipboard, just without colour.
|
|
38
|
+
*/
|
|
39
|
+
copyMessageText(raw: string): void {
|
|
40
|
+
const plain = stripColorTags(raw);
|
|
41
|
+
if (!NativeCometChatClipboardModule?.setRichText) {
|
|
42
|
+
Clipboard.setString(plain);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
NativeCometChatClipboardModule.setRichText(plain, raw).catch(() => {
|
|
46
|
+
Clipboard.setString(plain);
|
|
47
|
+
});
|
|
48
|
+
},
|
|
28
49
|
};
|
|
@@ -10,6 +10,12 @@ export interface ClipboardImageResult {
|
|
|
10
10
|
interface NativeCometChatClipboardModuleSpec {
|
|
11
11
|
hasImageInClipboard(): Promise<boolean>;
|
|
12
12
|
getClipboardImage(): Promise<ClipboardImageResult | null>;
|
|
13
|
+
/**
|
|
14
|
+
* Copies `plain` to the system clipboard for every app, and `wire` under a private
|
|
15
|
+
* representation only our composer reads back — so inline colour survives a copy/paste
|
|
16
|
+
* inside CometChat without leaking `<color=…>` markup to anywhere else.
|
|
17
|
+
*/
|
|
18
|
+
setRichText(plain: string, wire: string): Promise<boolean>;
|
|
13
19
|
}
|
|
14
20
|
|
|
15
21
|
const { CometChatClipboardModule } = NativeModules;
|
|
@@ -90,6 +90,10 @@ export const CometChatActionSheet = (props: CometChatActionSheetInterface) => {
|
|
|
90
90
|
return (
|
|
91
91
|
<FlatList
|
|
92
92
|
key={"list"}
|
|
93
|
+
// The option list scrolls when there are more options than fit — Delete in particular
|
|
94
|
+
// sits below the fold on a long sheet. Without an id there is nothing for a test (or an
|
|
95
|
+
// integrator's own automation) to scroll, so the option exists but can never be tapped.
|
|
96
|
+
testID='ActionSheet.list'
|
|
93
97
|
keyExtractor={(item) => item.id}
|
|
94
98
|
data={actionList}
|
|
95
99
|
numColumns={1}
|
|
@@ -54,11 +54,23 @@ export const CometChatAvatar = (props: CometChatAvatarProps) => {
|
|
|
54
54
|
const initials = [...(name || "")].slice(0, 2).join("").toUpperCase();
|
|
55
55
|
|
|
56
56
|
return (
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
// NO adjustsFontSizeToFit (ENG-38886).
|
|
58
|
+
//
|
|
59
|
+
// On iOS that prop shrinks the text to fit the Text's frame — and on the FIRST row a list
|
|
60
|
+
// renders, the frame is not known yet. iOS shrinks to its minimum against that unknown,
|
|
61
|
+
// never recomputes, and the initials end up a few pixels tall in the corner of the circle
|
|
62
|
+
// while every later row in the same list is perfect. Measured 2026-09-04: identical
|
|
63
|
+
// resolved style (20px font, 48px circle) on every row, only the first one broken.
|
|
64
|
+
//
|
|
65
|
+
// It was never earning its keep. Initials are at most two characters and the theme sizes
|
|
66
|
+
// them for its own circle, so there is nothing to shrink in the normal case; it only ever
|
|
67
|
+
// fired when a consumer shrank the container WITHOUT bringing the font down with it. That
|
|
68
|
+
// is a styling mistake and it should look like one, rather than being silently papered
|
|
69
|
+
// over on Android and mangled on iOS — see CometChatPinnedMessages/style.ts, which sizes
|
|
70
|
+
// its own text for its 32px avatar.
|
|
71
|
+
//
|
|
72
|
+
// numberOfLines stays: it keeps a stray long value on one line instead of wrapping.
|
|
73
|
+
<Text style={[avatarStyle.textStyle]} numberOfLines={1}>
|
|
62
74
|
{initials}
|
|
63
75
|
</Text>
|
|
64
76
|
);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React, {
|
|
2
2
|
forwardRef,
|
|
3
|
+
useContext,
|
|
3
4
|
useEffect,
|
|
4
5
|
useImperativeHandle,
|
|
5
6
|
useRef,
|
|
@@ -16,6 +17,7 @@ import {
|
|
|
16
17
|
Platform,
|
|
17
18
|
ScrollView,
|
|
18
19
|
} from "react-native";
|
|
20
|
+
import { SafeAreaInsetsContext } from "react-native-safe-area-context";
|
|
19
21
|
import { useTheme } from "../../../theme";
|
|
20
22
|
|
|
21
23
|
/**
|
|
@@ -93,6 +95,10 @@ const CometChatBottomSheet = forwardRef(
|
|
|
93
95
|
// All hooks called unconditionally at top level
|
|
94
96
|
const overlayAnim = useRef(new Animated.Value(0)).current;
|
|
95
97
|
|
|
98
|
+
const safeAreaInsets = useContext(SafeAreaInsetsContext);
|
|
99
|
+
const bottomInset =
|
|
100
|
+
Platform.OS === "android" ? safeAreaInsets?.bottom ?? 0 : 0;
|
|
101
|
+
|
|
96
102
|
// Fade in/out the overlay when isOpen changes
|
|
97
103
|
useEffect(() => {
|
|
98
104
|
if (isOpen) {
|
|
@@ -163,6 +169,7 @@ const CometChatBottomSheet = forwardRef(
|
|
|
163
169
|
>
|
|
164
170
|
{/* Animated overlay that fades in from transparent to a semi-transparent black */}
|
|
165
171
|
<Animated.View
|
|
172
|
+
testID='BottomSheet.overlay'
|
|
166
173
|
style={{
|
|
167
174
|
flex: 1,
|
|
168
175
|
backgroundColor: overlayAnim.interpolate({
|
|
@@ -184,7 +191,7 @@ const CometChatBottomSheet = forwardRef(
|
|
|
184
191
|
backgroundColor: theme.color.background1,
|
|
185
192
|
paddingTop: 25,
|
|
186
193
|
position: "absolute",
|
|
187
|
-
bottom:
|
|
194
|
+
bottom: bottomInset,
|
|
188
195
|
left: 0,
|
|
189
196
|
right: 0,
|
|
190
197
|
borderTopLeftRadius: 24,
|
|
@@ -199,19 +206,26 @@ const CometChatBottomSheet = forwardRef(
|
|
|
199
206
|
...(doNotOccupyEntireHeight ? {} : { height: "100%" }),
|
|
200
207
|
}}
|
|
201
208
|
>
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
<View
|
|
210
|
+
style={{
|
|
211
|
+
...(doNotOccupyEntireHeight ? {} : { flex: 1 }),
|
|
212
|
+
paddingBottom: style.paddingBottom ?? 0,
|
|
213
|
+
}}
|
|
214
|
+
>
|
|
215
|
+
{scrollEnabled ? (
|
|
216
|
+
<ScrollView
|
|
217
|
+
scrollEnabled={scrollEnabled}
|
|
218
|
+
keyboardShouldPersistTaps="always"
|
|
219
|
+
style={{ flex: 1 }}
|
|
220
|
+
>
|
|
221
|
+
{typeof children === "function" ? children() : children}
|
|
222
|
+
</ScrollView>
|
|
223
|
+
) : typeof children === "function" ? (
|
|
224
|
+
children()
|
|
225
|
+
) : (
|
|
226
|
+
children
|
|
227
|
+
)}
|
|
228
|
+
</View>
|
|
215
229
|
</KeyboardAvoidingView>
|
|
216
230
|
</Modal>
|
|
217
231
|
);
|
|
@@ -154,6 +154,7 @@ export const CometChatConfirmDialog = (props: CometChatConfirmDialogInterface) =
|
|
|
154
154
|
)}
|
|
155
155
|
<View style={styles.buttonContainer}>
|
|
156
156
|
<TouchableOpacity
|
|
157
|
+
testID='ConfirmDialog.cancel'
|
|
157
158
|
style={[theme.confirmDialogStyles.cancelButtonStyle, cancelButtonStyle]}
|
|
158
159
|
onPress={(e) => {
|
|
159
160
|
e.stopPropagation();
|
|
@@ -165,6 +166,7 @@ export const CometChatConfirmDialog = (props: CometChatConfirmDialogInterface) =
|
|
|
165
166
|
</Text>
|
|
166
167
|
</TouchableOpacity>
|
|
167
168
|
<TouchableOpacity
|
|
169
|
+
testID='ConfirmDialog.confirm'
|
|
168
170
|
style={[theme.confirmDialogStyles.confirmButtonStyle, confirmButtonStyle]}
|
|
169
171
|
onPress={(e) => {
|
|
170
172
|
e.stopPropagation();
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react';
|
|
1
|
+
import React, { Component, ReactNode, useEffect, useRef, useState } from 'react';
|
|
2
2
|
import {
|
|
3
3
|
Animated,
|
|
4
4
|
ScrollView,
|
|
@@ -8,21 +8,39 @@ import {
|
|
|
8
8
|
View,
|
|
9
9
|
} from 'react-native';
|
|
10
10
|
import { useTheme } from '../../../theme';
|
|
11
|
-
import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
|
|
12
11
|
|
|
13
12
|
export interface CometChatConversationStarterProps {
|
|
14
13
|
getConversationStarters: () => Promise<string[]>;
|
|
15
14
|
onSuggestionClicked?: (reply: string) => void;
|
|
16
15
|
}
|
|
17
16
|
|
|
18
|
-
|
|
17
|
+
// No 'error' member: a failure is indistinguishable from 'nothing to suggest', and both
|
|
18
|
+
// render null. See the catch below for why an error must never reach the screen.
|
|
19
|
+
type State = 'loading' | 'loaded' | 'empty';
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Is this rejection "your plan does not include AI", rather than something a retry could fix?
|
|
23
|
+
*
|
|
24
|
+
* Matched on the code first; the message is a fallback because the same refusal reaches
|
|
25
|
+
* different SDK surfaces with the code sometimes nested on the response rather than the
|
|
26
|
+
* exception.
|
|
27
|
+
*/
|
|
28
|
+
export const isFeatureUnavailable = (error: any): boolean => {
|
|
29
|
+
try {
|
|
30
|
+
const code = error?.code ?? error?.error?.code ?? '';
|
|
31
|
+
if (code === 'ERR_FEATURE_NOT_ACCESSIBLE') return true;
|
|
32
|
+
const message = String(error?.message ?? error?.error?.message ?? '');
|
|
33
|
+
return /feature is not available|upgrade your plan/i.test(message);
|
|
34
|
+
} catch {
|
|
35
|
+
return false;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
19
38
|
|
|
20
39
|
const CometChatConversationStarter: React.FC<CometChatConversationStarterProps> = ({
|
|
21
40
|
getConversationStarters,
|
|
22
41
|
onSuggestionClicked,
|
|
23
42
|
}) => {
|
|
24
43
|
const theme = useTheme();
|
|
25
|
-
const { t } = useCometChatTranslation();
|
|
26
44
|
const [state, setState] = useState<State>('loading');
|
|
27
45
|
const [starters, setStarters] = useState<string[]>([]);
|
|
28
46
|
const shimmer = useRef(new Animated.Value(0.4)).current;
|
|
@@ -45,7 +63,30 @@ const CometChatConversationStarter: React.FC<CometChatConversationStarterProps>
|
|
|
45
63
|
setState('empty');
|
|
46
64
|
}
|
|
47
65
|
})
|
|
48
|
-
.catch(() =>
|
|
66
|
+
.catch((error: any) => {
|
|
67
|
+
// Starters are SUGGESTIONS. They are not the conversation, and nothing about the
|
|
68
|
+
// conversation depends on them, so a failure here must never put anything on screen —
|
|
69
|
+
// it renders nothing and the chat is left exactly as it would have been.
|
|
70
|
+
//
|
|
71
|
+
// It used to render "Could not load conversation starters. Please try again.", which was
|
|
72
|
+
// wrong twice over: on an app without the AI add-on the call returns the same 403 for
|
|
73
|
+
// ever, so the retry is a instruction that can never be satisfied; and because this view
|
|
74
|
+
// stood in for the whole empty state, that one line was the only thing on an empty
|
|
75
|
+
// conversation — it read as "the chat failed to load".
|
|
76
|
+
//
|
|
77
|
+
// Logged rather than swallowed, so a genuine outage is still diagnosable from the
|
|
78
|
+
// console. The two cases are logged differently on purpose: a missing add-on is expected
|
|
79
|
+
// and should not look like a defect to an integrator reading their logs.
|
|
80
|
+
if (isFeatureUnavailable(error)) {
|
|
81
|
+
console.warn(
|
|
82
|
+
'[CometChatConversationStarter] AI conversation starters are not enabled for this app; ' +
|
|
83
|
+
'no starters will be shown. This is a plan setting, not an error.'
|
|
84
|
+
);
|
|
85
|
+
} else {
|
|
86
|
+
console.error('[CometChatConversationStarter] Failed to load conversation starters', error);
|
|
87
|
+
}
|
|
88
|
+
setState('empty');
|
|
89
|
+
})
|
|
49
90
|
.finally(() => loop.stop());
|
|
50
91
|
|
|
51
92
|
return () => loop.stop();
|
|
@@ -63,14 +104,6 @@ const CometChatConversationStarter: React.FC<CometChatConversationStarterProps>
|
|
|
63
104
|
);
|
|
64
105
|
}
|
|
65
106
|
|
|
66
|
-
if (state === 'error') {
|
|
67
|
-
return (
|
|
68
|
-
<View style={s.container}>
|
|
69
|
-
<Text style={s.stateText}>{t('ai_conversation_starter_error')}</Text>
|
|
70
|
-
</View>
|
|
71
|
-
);
|
|
72
|
-
}
|
|
73
|
-
|
|
74
107
|
if (state === 'empty') {
|
|
75
108
|
return null;
|
|
76
109
|
}
|
|
@@ -130,12 +163,50 @@ const styles = (theme: ReturnType<typeof useTheme>) =>
|
|
|
130
163
|
fontSize: theme.typography.body.regular.fontSize,
|
|
131
164
|
fontFamily: theme.typography.body.regular.fontFamily,
|
|
132
165
|
},
|
|
133
|
-
stateText: {
|
|
134
|
-
color: theme.color.textSecondary,
|
|
135
|
-
fontSize: theme.typography.caption1.regular.fontSize,
|
|
136
|
-
fontFamily: theme.typography.caption1.regular.fontFamily,
|
|
137
|
-
paddingHorizontal: 4,
|
|
138
|
-
},
|
|
139
166
|
});
|
|
140
167
|
|
|
141
|
-
|
|
168
|
+
/**
|
|
169
|
+
* A crash in the suggestions must never take the conversation with it.
|
|
170
|
+
*
|
|
171
|
+
* The promise path is already handled — a rejected fetch logs and renders nothing. This covers
|
|
172
|
+
* the other half: an exception thrown while RENDERING. React unmounts the nearest tree when a
|
|
173
|
+
* render throws, and this component is mounted INSIDE the message list, so without a boundary a
|
|
174
|
+
* fault in an optional AI add-on would blank the whole conversation. That is the wrong failure
|
|
175
|
+
* for a feature whose entire job is to suggest an opening line.
|
|
176
|
+
*
|
|
177
|
+
* Renders null on failure, exactly like having no suggestions, so the chat is left as if the
|
|
178
|
+
* feature were not enabled at all.
|
|
179
|
+
*/
|
|
180
|
+
class ConversationStarterBoundary extends Component<
|
|
181
|
+
{ children: ReactNode },
|
|
182
|
+
{ failed: boolean }
|
|
183
|
+
> {
|
|
184
|
+
state = { failed: false };
|
|
185
|
+
|
|
186
|
+
static getDerivedStateFromError() {
|
|
187
|
+
return { failed: true };
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
componentDidCatch(error: Error) {
|
|
191
|
+
console.error(
|
|
192
|
+
'[CometChatConversationStarter] Suggestions crashed and were dropped; the conversation is unaffected',
|
|
193
|
+
error
|
|
194
|
+
);
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
render() {
|
|
198
|
+
return this.state.failed ? null : this.props.children;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/**
|
|
203
|
+
* Exported already wrapped, so every call site is protected by construction rather than by each
|
|
204
|
+
* one remembering to add a boundary.
|
|
205
|
+
*/
|
|
206
|
+
const SafeCometChatConversationStarter: React.FC<CometChatConversationStarterProps> = (props) => (
|
|
207
|
+
<ConversationStarterBoundary>
|
|
208
|
+
<CometChatConversationStarter {...props} />
|
|
209
|
+
</ConversationStarterBoundary>
|
|
210
|
+
);
|
|
211
|
+
|
|
212
|
+
export default SafeCometChatConversationStarter;
|
|
@@ -423,7 +423,12 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
423
423
|
if (position !== undefined) {
|
|
424
424
|
if (position === 0) return [item, ...prev];
|
|
425
425
|
if (position >= prev.length) return [...prev, item];
|
|
426
|
-
|
|
426
|
+
// slice(0, position), NOT position - 1. The old form dropped the element
|
|
427
|
+
// immediately before the insert point: inserting at 2 in a 5-item list
|
|
428
|
+
// produced [0, item, 2, 3, 4] — index 1 silently deleted. Every other
|
|
429
|
+
// caller passes 0, which takes the branch above, so this went unnoticed
|
|
430
|
+
// until the conversation-pin reordering became the first middle insert.
|
|
431
|
+
return [...prev.slice(0, position), item, ...prev.slice(position)];
|
|
427
432
|
}
|
|
428
433
|
return [...prev, item];
|
|
429
434
|
});
|
|
@@ -21,6 +21,8 @@ import { Style } from "./style";
|
|
|
21
21
|
import { DeepPartial } from "../../helper/types";
|
|
22
22
|
|
|
23
23
|
export interface CometChatListItemInterface {
|
|
24
|
+
/** Forwarded to the row's root node so a caller can address a specific row. */
|
|
25
|
+
testID?: string;
|
|
24
26
|
/**
|
|
25
27
|
* Unique identifier for the list item.
|
|
26
28
|
*/
|
|
@@ -116,6 +118,7 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
116
118
|
const theme = useTheme();
|
|
117
119
|
|
|
118
120
|
const {
|
|
121
|
+
testID,
|
|
119
122
|
id,
|
|
120
123
|
avatarURL,
|
|
121
124
|
avatarName,
|
|
@@ -269,6 +272,7 @@ export const CometChatListItem = React.memo((props: CometChatListItemInterface)
|
|
|
269
272
|
return (
|
|
270
273
|
<ListComponent
|
|
271
274
|
{...listComponentProps}
|
|
275
|
+
testID={testID}
|
|
272
276
|
style={[containerStyle, selected && { backgroundColor: theme.color.background4 }]}
|
|
273
277
|
>
|
|
274
278
|
{getLeadingView()}
|
|
@@ -68,6 +68,10 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
|
|
|
68
68
|
return (
|
|
69
69
|
<CometChatListItem
|
|
70
70
|
key={index}
|
|
71
|
+
// Derived from the suggestion's own id so a test can pick ONE row out of a list that
|
|
72
|
+
// is virtualized and reorders as you type. A plain shared id would force atIndex(),
|
|
73
|
+
// which picks an unpredictable row.
|
|
74
|
+
testID={`SuggestionList.item-${item.id}`}
|
|
71
75
|
id={item.id}
|
|
72
76
|
title={isAllAlias ? undefined : item.name}
|
|
73
77
|
TitleView={TitleView}
|
|
@@ -16,6 +16,7 @@ import {
|
|
|
16
16
|
CometChatUrlsFormatter,
|
|
17
17
|
} from "../../formatters";
|
|
18
18
|
import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
|
|
19
|
+
import { isTextElement, isViewElement } from "../../utils/elementType";
|
|
19
20
|
|
|
20
21
|
// Pre-allocated style for view-based content wrapper (blockquotes, lists).
|
|
21
22
|
const VIEW_BASED_WRAPPER_STYLE = { flexShrink: 1 as const };
|
|
@@ -56,12 +57,12 @@ function applyTextStyleDeep(
|
|
|
56
57
|
el: React.ReactElement<any>,
|
|
57
58
|
textStyle: StyleProp<TextStyle> | undefined
|
|
58
59
|
): React.ReactElement<any> {
|
|
59
|
-
if (el
|
|
60
|
+
if (isTextElement(el)) {
|
|
60
61
|
return React.cloneElement(el, {
|
|
61
62
|
style: [textStyle, el.props?.style],
|
|
62
63
|
});
|
|
63
64
|
}
|
|
64
|
-
if (el
|
|
65
|
+
if (isViewElement(el) && el.props.children) {
|
|
65
66
|
const newChildren = React.Children.map(el.props.children, (child) => {
|
|
66
67
|
if (!React.isValidElement(child)) return child;
|
|
67
68
|
return applyTextStyleDeep(child as React.ReactElement<any>, textStyle);
|
|
@@ -171,7 +172,7 @@ export const CometChatTextBubbleText = (
|
|
|
171
172
|
// Check if formattedText is a View-based element (e.g. blockquote with View wrapper).
|
|
172
173
|
// View elements cannot be nested inside Text, so render them directly.
|
|
173
174
|
const isViewBased = React.isValidElement(formattedText) &&
|
|
174
|
-
(formattedText
|
|
175
|
+
isViewElement(formattedText);
|
|
175
176
|
|
|
176
177
|
// For View-based content, count children to determine truncatability and slice when collapsed.
|
|
177
178
|
// This avoids pixel-based clipping that cuts through the middle of list items.
|
|
@@ -37,6 +37,8 @@ type ErrorEmptyViewProps = {
|
|
|
37
37
|
* A custom JSX element to render for a retry action.
|
|
38
38
|
*/
|
|
39
39
|
RetryView?: JSX.Element;
|
|
40
|
+
/** Forwarded to the container so a caller can identify which state rendered. */
|
|
41
|
+
testID?: string;
|
|
40
42
|
};
|
|
41
43
|
|
|
42
44
|
|
|
@@ -50,9 +52,10 @@ export const ErrorEmptyView = (props: ErrorEmptyViewProps) => {
|
|
|
50
52
|
titleStyle = {},
|
|
51
53
|
subTitleStyle = {},
|
|
52
54
|
RetryView = null,
|
|
55
|
+
testID,
|
|
53
56
|
} = props;
|
|
54
57
|
return (
|
|
55
|
-
<View style={[containerStyle]}>
|
|
58
|
+
<View testID={testID} style={[containerStyle]}>
|
|
56
59
|
{Icon}
|
|
57
60
|
{title && <Text style={titleStyle}>{title}</Text>}
|
|
58
61
|
{subTitle && <Text style={subTitleStyle}>{subTitle}</Text>}
|
|
@@ -6,6 +6,8 @@ import {
|
|
|
6
6
|
getConversationStyleDark,
|
|
7
7
|
getConversationStyleLight,
|
|
8
8
|
} from "../../CometChatConversations/style";
|
|
9
|
+
import { getPinnedMessagesStyleDark, getPinnedMessagesStyleLight } from "../../CometChatPinnedMessages/style";
|
|
10
|
+
import { getSavedMessagesStyleDark, getSavedMessagesStyleLight } from "../../CometChatSavedMessages/style";
|
|
9
11
|
import {
|
|
10
12
|
getNotificationFeedStyleDark,
|
|
11
13
|
getNotificationFeedStyleLight,
|
|
@@ -135,6 +137,8 @@ export const lightThemeMaker = (
|
|
|
135
137
|
dateSeparatorStyles: getDateSeparatorStyleLight(color, spacing, typography),
|
|
136
138
|
conversationStyles: getConversationStyleLight(color, spacing, typography),
|
|
137
139
|
notificationFeedStyles: getNotificationFeedStyleLight(color, spacing, typography),
|
|
140
|
+
pinnedMessagesStyles: getPinnedMessagesStyleLight(color, spacing, typography),
|
|
141
|
+
savedMessagesStyles: getSavedMessagesStyleLight(color, spacing, typography),
|
|
138
142
|
confirmDialogStyles: getConfirmDialogStyleLight(color, spacing, typography),
|
|
139
143
|
reportDialogStyles: getReportDialogStyleLight(color, spacing, typography),
|
|
140
144
|
messageHeaderStyles: getMessageHeaderStyle(color, spacing, typography),
|
|
@@ -177,6 +181,8 @@ export const darkThemeMaker = (
|
|
|
177
181
|
dateSeparatorStyles: getDateSeparatorStyleDark(color, spacing, typography),
|
|
178
182
|
conversationStyles: getConversationStyleDark(color, spacing, typography),
|
|
179
183
|
notificationFeedStyles: getNotificationFeedStyleDark(color, spacing, typography),
|
|
184
|
+
pinnedMessagesStyles: getPinnedMessagesStyleDark(color, spacing, typography),
|
|
185
|
+
savedMessagesStyles: getSavedMessagesStyleDark(color, spacing, typography),
|
|
180
186
|
confirmDialogStyles: getConfirmDialogStyleDark(color, spacing, typography),
|
|
181
187
|
reportDialogStyles: getReportDialogStyleDark(color, spacing, typography),
|
|
182
188
|
messageHeaderStyles: getMessageHeaderStyle(color, spacing, typography),
|
package/src/theme/type.ts
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ColorValue, ImageSourcePropType, ImageStyle, TextStyle, ViewStyle } from "react-native";
|
|
2
2
|
import { CallButtonStyle } from "../calls/CometChatCallButtons";
|
|
3
3
|
import { ConversationStyle } from "../CometChatConversations/style";
|
|
4
|
+
import { PinnedMessagesStyle } from "../CometChatPinnedMessages/style";
|
|
5
|
+
import { SavedMessagesStyle } from "../CometChatSavedMessages/style";
|
|
4
6
|
import { GroupMemberStyle } from "../CometChatGroupMembers/style";
|
|
5
7
|
import { GroupStyle } from "../CometChatGroups/GroupsStyle";
|
|
6
8
|
import { MessageComposerStyle } from "../CometChatMessageComposer/styles";
|
|
@@ -543,6 +545,8 @@ export interface CometChatTheme {
|
|
|
543
545
|
callLogsStyles: CallLogsStyle;
|
|
544
546
|
conversationStyles: ConversationStyle;
|
|
545
547
|
notificationFeedStyles: NotificationFeedStyle;
|
|
548
|
+
pinnedMessagesStyles: PinnedMessagesStyle;
|
|
549
|
+
savedMessagesStyles: SavedMessagesStyle;
|
|
546
550
|
confirmDialogStyles: ConfirmDialogStyle;
|
|
547
551
|
reportDialogStyles: ReportDialogStyle;
|
|
548
552
|
quickReactionStyle: {
|