@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,634 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* CometChatSavedMessages — the USER-LEVEL saved messages surface (§6.4).
|
|
3
|
+
*
|
|
4
|
+
* Cross-conversation and private: this is the "star / bookmark" inbox, reached from
|
|
5
|
+
* app chrome (main nav, profile, settings), NOT from a conversation header. On RN it
|
|
6
|
+
* is a full-screen route, not a drawer (§6.9).
|
|
7
|
+
*
|
|
8
|
+
* Renders as a CONVERSATION-STYLE LIST — avatar, source name, preview subtitle,
|
|
9
|
+
* trailing date — not as full message bubbles. That is a deliberate divergence from
|
|
10
|
+
* CometChatPinnedMessages, which does show bubbles: a pinned list is scoped to one
|
|
11
|
+
* conversation where a bubble reads naturally, whereas this list spans every
|
|
12
|
+
* conversation and the question a reader asks first is "where is this from?".
|
|
13
|
+
*
|
|
14
|
+
* Read-only with respect to unread state (§7.7): nothing here calls markAsRead,
|
|
15
|
+
* emits receipts, or touches an unread count.
|
|
16
|
+
*
|
|
17
|
+
* @module CometChatSavedMessages
|
|
18
|
+
*/
|
|
19
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
20
|
+
import React, { JSX, useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
21
|
+
import { FlatList, GestureResponderEvent, Pressable, StyleSheet, Text, View } from "react-native";
|
|
22
|
+
import { useCompTheme, useTheme } from "../theme/hook";
|
|
23
|
+
import { deepMerge } from "../shared/helper/helperFunctions";
|
|
24
|
+
import { DeepPartial } from "../shared/helper/types";
|
|
25
|
+
import { SavedMessagesStyle } from "./style";
|
|
26
|
+
import { CometChatTheme } from "../theme/type";
|
|
27
|
+
import { Icon } from "../shared/icons/Icon";
|
|
28
|
+
import { IconName } from "../shared/icons/Icon";
|
|
29
|
+
import { CometChatDate } from "../shared/views/CometChatDate";
|
|
30
|
+
import { Skeleton } from "../CometChatConversations/Skeleton";
|
|
31
|
+
import { CometChatListItem } from "../shared/views/CometChatListItem";
|
|
32
|
+
import { CometChatTooltipMenu, MenuItemInterface } from "../shared/views/CometChatTooltipMenu";
|
|
33
|
+
import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
|
|
34
|
+
import { CometChatConfirmDialog } from "../shared/views/CometChatConfirmDialog";
|
|
35
|
+
import { CometChatRetryButton } from "../shared/views/CometChatRetryButton/CometChatRetryButton";
|
|
36
|
+
import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
|
|
37
|
+
import { useToast } from "../shared/helper/useToast";
|
|
38
|
+
import {
|
|
39
|
+
buildSavedMessagesRequest,
|
|
40
|
+
previewFor,
|
|
41
|
+
sourceLabelFor,
|
|
42
|
+
subtitlePrefixNameFor,
|
|
43
|
+
SavedMessageSource,
|
|
44
|
+
} from "../shared/utils/SavedMessagesHelper";
|
|
45
|
+
import {
|
|
46
|
+
carryPinSaveAttrs,
|
|
47
|
+
isMessageGoneError,
|
|
48
|
+
unsaveMessage,
|
|
49
|
+
sameMessageId,
|
|
50
|
+
} from "../shared/utils/PinSaveHelper";
|
|
51
|
+
import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
|
|
52
|
+
import { MessageEvents } from "../shared/events/messages";
|
|
53
|
+
|
|
54
|
+
export interface CometChatSavedMessagesInterface {
|
|
55
|
+
/** Page size. Defaults to 30; the server caps the whole set at 100. */
|
|
56
|
+
limit?: number;
|
|
57
|
+
/** Closes the surface — rendered as the ✕ in the header. */
|
|
58
|
+
onBack?: () => void;
|
|
59
|
+
/**
|
|
60
|
+
* Tapping a row. Receives the message and its resolved source so the host can
|
|
61
|
+
* open that conversation and jump to the message.
|
|
62
|
+
*/
|
|
63
|
+
onItemPress?: (message: CometChat.BaseMessage, source: SavedMessageSource | null) => void;
|
|
64
|
+
/**
|
|
65
|
+
* Hide the unsave option in the long-press menu. Named per design doc §6.7,
|
|
66
|
+
* which lists the same four flags for the action sheet — the panel mirrors that
|
|
67
|
+
* vocabulary rather than inventing a shorter one.
|
|
68
|
+
*/
|
|
69
|
+
hideUnsaveMessageOption?: boolean;
|
|
70
|
+
/** Replace the whole row body. */
|
|
71
|
+
ItemView?: (message: CometChat.BaseMessage) => JSX.Element;
|
|
72
|
+
title?: string;
|
|
73
|
+
/** Per-instance style overrides, merged over the theme's savedMessagesStyles. */
|
|
74
|
+
style?: DeepPartial<SavedMessagesStyle>;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
type ListState = "loading" | "loaded" | "error" | "empty";
|
|
78
|
+
|
|
79
|
+
export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) => {
|
|
80
|
+
const { limit, onBack, onItemPress, hideUnsaveMessageOption = false, ItemView, title, style } = props;
|
|
81
|
+
|
|
82
|
+
const theme = useTheme() as CometChatTheme;
|
|
83
|
+
const compTheme = useCompTheme();
|
|
84
|
+
const { t } = useCometChatTranslation();
|
|
85
|
+
|
|
86
|
+
/** theme → component-level override → per-instance prop, the kit's usual order. */
|
|
87
|
+
const styles = useMemo(
|
|
88
|
+
() => deepMerge(theme.savedMessagesStyles, compTheme.savedMessagesStyles ?? {}, style ?? {}),
|
|
89
|
+
[theme.savedMessagesStyles, compTheme.savedMessagesStyles, style]
|
|
90
|
+
);
|
|
91
|
+
const { showToast, ToastElement } = useToast();
|
|
92
|
+
|
|
93
|
+
const [messages, setMessagesRaw] = useState<CometChat.BaseMessage[]>([]);
|
|
94
|
+
const [state, setStateRaw] = useState<ListState>("loading");
|
|
95
|
+
const loggedInUser = useRef<CometChat.User | null>(null);
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* These panels are full-screen routes, so popping one while a fetch or a post-confirm
|
|
99
|
+
* write is still in flight lands a setState on an unmounted component — the React Native
|
|
100
|
+
* warning, plus work nobody will see. Guarding at the SETTER rather than at each of the
|
|
101
|
+
* async resolvers keeps every existing call site unchanged and cannot be forgotten at a
|
|
102
|
+
* new one.
|
|
103
|
+
*/
|
|
104
|
+
const mounted = useRef(true);
|
|
105
|
+
useEffect(() => () => { mounted.current = false; }, []);
|
|
106
|
+
const setMessages: typeof setMessagesRaw = useCallback(
|
|
107
|
+
value => { if (mounted.current) setMessagesRaw(value); },
|
|
108
|
+
[]
|
|
109
|
+
);
|
|
110
|
+
const setState: typeof setStateRaw = useCallback(
|
|
111
|
+
value => { if (mounted.current) setStateRaw(value); },
|
|
112
|
+
[]
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Long-press menu state. Anchored at the touch point via CometChatTooltipMenu —
|
|
117
|
+
* the SAME affordance the conversation list uses for its Pin/Delete menu, because
|
|
118
|
+
* these rows are conversation rows and should answer a long-press the same way.
|
|
119
|
+
*/
|
|
120
|
+
const [menuVisible, setMenuVisible] = useState(false);
|
|
121
|
+
/** The row awaiting unsave confirmation, or null. */
|
|
122
|
+
const [confirmUnsave, setConfirmUnsave] = useState<CometChat.BaseMessage | null>(null);
|
|
123
|
+
const menuAnchor = useRef({ pageX: 0, pageY: 0 });
|
|
124
|
+
const menuTarget = useRef<CometChat.BaseMessage | null>(null);
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* The request is single-use and accumulates its own paging state, so it lives in
|
|
128
|
+
* a ref for the lifetime of the screen. Refreshing means building a NEW one.
|
|
129
|
+
*/
|
|
130
|
+
const request = useRef(buildSavedMessagesRequest(limit));
|
|
131
|
+
const fetching = useRef(false);
|
|
132
|
+
/**
|
|
133
|
+
* The end of a cursor-paged list is an empty page — there is nothing to ask the request
|
|
134
|
+
* for beforehand. Latch it here, or every further scroll-to-end fires a round trip that
|
|
135
|
+
* can only come back empty again.
|
|
136
|
+
*/
|
|
137
|
+
const exhausted = useRef(false);
|
|
138
|
+
|
|
139
|
+
const loadNext = useCallback(async () => {
|
|
140
|
+
if (fetching.current || exhausted.current) return;
|
|
141
|
+
fetching.current = true;
|
|
142
|
+
try {
|
|
143
|
+
// fetchPrevious(), not fetchNext() — "previous" is older, which is the direction
|
|
144
|
+
// this list scrolls. Same call CometChatMessageList makes to load history.
|
|
145
|
+
const rows = await request.current.fetchPrevious();
|
|
146
|
+
if (rows.length > 0) {
|
|
147
|
+
// Dedupe on append (ENG-38891). A realtime pin/save PREPENDS its row the moment the
|
|
148
|
+
// event lands; the same message then comes back inside a later fetched page, and a
|
|
149
|
+
// plain concat lists it twice — which is how a five-pin cap rendered six rows.
|
|
150
|
+
setMessages(prev => {
|
|
151
|
+
const seen = new Set(prev.map(m => String(m.getId())));
|
|
152
|
+
return [...prev, ...rows.filter(r => !seen.has(String(r.getId())))];
|
|
153
|
+
});
|
|
154
|
+
setState("loaded");
|
|
155
|
+
} else {
|
|
156
|
+
exhausted.current = true;
|
|
157
|
+
setState(prev => (prev === "loading" ? "empty" : prev));
|
|
158
|
+
}
|
|
159
|
+
} catch (e) {
|
|
160
|
+
// Log it. A bare `catch {}` here cost hours once: the list showed a generic error
|
|
161
|
+
// screen with an empty network log, and the actual cause (SET_LIMIT_IS_COMPULSORY,
|
|
162
|
+
// rejected client-side before any request) was unreachable from outside a debugger.
|
|
163
|
+
console.error("CometChatSavedMessages: failed to fetch saved messages", e);
|
|
164
|
+
// An empty first page is "empty", not "error" — only a real rejection is.
|
|
165
|
+
setState(prev => (prev === "loading" ? "error" : prev));
|
|
166
|
+
} finally {
|
|
167
|
+
fetching.current = false;
|
|
168
|
+
}
|
|
169
|
+
}, []);
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Keep loading while the rows do not fill the viewport.
|
|
173
|
+
*
|
|
174
|
+
* onEndReached is the only paging trigger, and it needs a scroll to fire. When the first page
|
|
175
|
+
* is shorter than the screen there is nothing to scroll, so the list stops at page one and the
|
|
176
|
+
* rest is unreachable — verified with limit=2 against 4 pinned messages: `loadNext` ran once,
|
|
177
|
+
* returned 2 rows, and was never called again while the panel sat half empty.
|
|
178
|
+
*
|
|
179
|
+
* The default page size fills a phone screen, which is why this hid; `limit` is a public prop,
|
|
180
|
+
* so any integrator who lowers it hits a permanently incomplete list. loadNext already guards
|
|
181
|
+
* on `fetching`/`exhausted`, so this tops up at most one request at a time and stops on its own.
|
|
182
|
+
*/
|
|
183
|
+
const viewportHeight = useRef(0);
|
|
184
|
+
const contentHeight = useRef(0);
|
|
185
|
+
const fillViewport = useCallback(() => {
|
|
186
|
+
if (exhausted.current || fetching.current) return;
|
|
187
|
+
if (viewportHeight.current <= 0 || contentHeight.current <= 0) return;
|
|
188
|
+
if (contentHeight.current < viewportHeight.current) loadNext();
|
|
189
|
+
}, [loadNext]);
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Retry after an error. The request is single-use and has already consumed whatever
|
|
193
|
+
* paging state it got to, so this builds a fresh one rather than re-calling the old —
|
|
194
|
+
* a retried request must start from the top of the list, not from a half-walked cursor.
|
|
195
|
+
*/
|
|
196
|
+
const reload = useCallback(() => {
|
|
197
|
+
request.current = buildSavedMessagesRequest(limit);
|
|
198
|
+
exhausted.current = false;
|
|
199
|
+
fetching.current = false;
|
|
200
|
+
setMessages([]);
|
|
201
|
+
setState("loading");
|
|
202
|
+
loadNext();
|
|
203
|
+
}, [limit, loadNext]);
|
|
204
|
+
|
|
205
|
+
useEffect(() => {
|
|
206
|
+
CometChat.getLoggedinUser()
|
|
207
|
+
.then(user => {
|
|
208
|
+
loggedInUser.current = user ?? null;
|
|
209
|
+
})
|
|
210
|
+
.catch(() => {
|
|
211
|
+
// A missing logged-in user only costs 1-1 label precision, so carry on.
|
|
212
|
+
loggedInUser.current = null;
|
|
213
|
+
})
|
|
214
|
+
.finally(() => {
|
|
215
|
+
loadNext();
|
|
216
|
+
});
|
|
217
|
+
}, [loadNext]);
|
|
218
|
+
|
|
219
|
+
/**
|
|
220
|
+
* Keep the panel in step with saves made anywhere else — the message list next to it,
|
|
221
|
+
* or this user's other device. Without it the list is a snapshot taken on mount.
|
|
222
|
+
*
|
|
223
|
+
* No conversation filter here, unlike the pinned panel: saved is per-viewer and spans
|
|
224
|
+
* every conversation, so any save of this user's belongs on this screen.
|
|
225
|
+
*
|
|
226
|
+
* Both event families: cc* from the device that performed the action, on* from the
|
|
227
|
+
* socket echo to this user's other devices. Save/unsave is private, which is why the
|
|
228
|
+
* SDK exempts it from the self-session guard. Payload shapes differ, hence the unwrap.
|
|
229
|
+
*
|
|
230
|
+
* Keys written out literally — emitMessageEvent matches on each callback's inferred
|
|
231
|
+
* function name, which an anonymous arrow takes from its property key.
|
|
232
|
+
*/
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const id = "saved-messages-panel";
|
|
235
|
+
|
|
236
|
+
const unwrap = (payload: any): CometChat.BaseMessage | null =>
|
|
237
|
+
payload?.message ?? payload ?? null;
|
|
238
|
+
|
|
239
|
+
const added = (payload: any) => {
|
|
240
|
+
const message = unwrap(payload);
|
|
241
|
+
if (!message) return;
|
|
242
|
+
setMessages(prev => {
|
|
243
|
+
if (prev.some(m => sameMessageId(m.getId(), message.getId()))) return prev;
|
|
244
|
+
return [message, ...prev];
|
|
245
|
+
});
|
|
246
|
+
setState("loaded");
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const removed = (payload: any) => {
|
|
250
|
+
const message = unwrap(payload);
|
|
251
|
+
if (!message) return;
|
|
252
|
+
setMessages(prev => {
|
|
253
|
+
const next = prev.filter(m => !sameMessageId(m.getId(), message.getId()));
|
|
254
|
+
if (next.length === prev.length) return prev;
|
|
255
|
+
// Only claim empty once the first page has been read, or an event arriving
|
|
256
|
+
// mid-load would replace the spinner with "no saved messages".
|
|
257
|
+
if (next.length === 0 && exhausted.current) setState("empty");
|
|
258
|
+
return next;
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
|
|
262
|
+
/**
|
|
263
|
+
* ENG-38177/38181 were filed against the pinned panel; this list has the same shape and
|
|
264
|
+
* therefore the same two defects. An edited saved message must show its new text, and a
|
|
265
|
+
* deleted one must leave — otherwise the row survives its own message.
|
|
266
|
+
*
|
|
267
|
+
* carryPinSaveAttrs is what keeps `savedAt` alive across the edit: the edit response is
|
|
268
|
+
* minimal and omits it (verified on staging 2026-08-14), so a straight replace would
|
|
269
|
+
* strip the attribute this whole list is filtered on.
|
|
270
|
+
*/
|
|
271
|
+
const edited = (payload: any) => {
|
|
272
|
+
const message = unwrap(payload);
|
|
273
|
+
if (!message) return;
|
|
274
|
+
setMessages(prev => {
|
|
275
|
+
const index = prev.findIndex(m => sameMessageId(m.getId(), message.getId()));
|
|
276
|
+
if (index === -1) return prev;
|
|
277
|
+
const next = [...prev];
|
|
278
|
+
next[index] = carryPinSaveAttrs(message, prev[index]);
|
|
279
|
+
return next;
|
|
280
|
+
});
|
|
281
|
+
};
|
|
282
|
+
|
|
283
|
+
const deleted = (payload: any) => removed(payload);
|
|
284
|
+
|
|
285
|
+
CometChatUIEventHandler.addMessageListener(id, {
|
|
286
|
+
ccMessageSaved: (payload: any) => added(payload),
|
|
287
|
+
onMessageSaved: (payload: any) => added(payload),
|
|
288
|
+
ccMessageUnsaved: (payload: any) => removed(payload),
|
|
289
|
+
onMessageUnsaved: (payload: any) => removed(payload),
|
|
290
|
+
ccMessageEdited: (payload: any) => edited(payload),
|
|
291
|
+
onMessageEdited: (payload: any) => edited(payload),
|
|
292
|
+
ccMessageDeleted: (payload: any) => deleted(payload),
|
|
293
|
+
onMessageDeleted: (payload: any) => deleted(payload),
|
|
294
|
+
});
|
|
295
|
+
|
|
296
|
+
return () => CometChatUIEventHandler.removeMessageListener(id);
|
|
297
|
+
}, []);
|
|
298
|
+
|
|
299
|
+
/**
|
|
300
|
+
* Row chrome from the CONVERSATION list's own tokens, not this screen's.
|
|
301
|
+
*
|
|
302
|
+
* This surface is a conversation list in every visual respect — avatar, name,
|
|
303
|
+
* preview, date — so it must not grow a parallel set of row styles that drift.
|
|
304
|
+
* `containerStyle` in particular carries the `flexDirection: "row"` that makes a
|
|
305
|
+
* row a row; without it CometChatListItem stacks avatar, title and date
|
|
306
|
+
* vertically.
|
|
307
|
+
*/
|
|
308
|
+
const itemStyle = theme.conversationStyles?.itemStyle;
|
|
309
|
+
|
|
310
|
+
const closeMenu = useCallback(() => {
|
|
311
|
+
setMenuVisible(false);
|
|
312
|
+
menuTarget.current = null;
|
|
313
|
+
}, []);
|
|
314
|
+
|
|
315
|
+
const removeRow = (messageId: number) => {
|
|
316
|
+
setMessages(prev => {
|
|
317
|
+
const next = prev.filter(m => !sameMessageId(m.getId(), messageId));
|
|
318
|
+
if (next.length === 0) setState("empty");
|
|
319
|
+
return next;
|
|
320
|
+
});
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Unsave ASKS first (Jitvar, 2026-08-04): the removing half of each pair confirms,
|
|
325
|
+
* everywhere it appears. This panel used to act immediately — the message list already
|
|
326
|
+
* confirmed, so the same action asked or didn't depending on which screen you were on.
|
|
327
|
+
*/
|
|
328
|
+
const onUnsave = (message: CometChat.BaseMessage) => {
|
|
329
|
+
setConfirmUnsave(message);
|
|
330
|
+
};
|
|
331
|
+
|
|
332
|
+
const runUnsave = (message: CometChat.BaseMessage) => {
|
|
333
|
+
const id = message.getId();
|
|
334
|
+
// Optimistic once confirmed: re-adding on failure is trivially correct because the
|
|
335
|
+
// row object is still in hand — EXCEPT when the message is gone, see below.
|
|
336
|
+
removeRow(id);
|
|
337
|
+
unsaveMessage(id)
|
|
338
|
+
.then((updated) => {
|
|
339
|
+
// Same omission as the pinned panel (ENG-38884): this list writes to the server and
|
|
340
|
+
// drops its own row, but the message's bubble in its conversation holds a separate
|
|
341
|
+
// copy and kept showing the bookmark. The bus is the only channel between them.
|
|
342
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageUnsaved, {
|
|
343
|
+
message: updated ?? message,
|
|
344
|
+
});
|
|
345
|
+
showToast(t("MESSAGE_UNSAVED") ?? "Message unsaved");
|
|
346
|
+
})
|
|
347
|
+
.catch((error: any) => {
|
|
348
|
+
// A message that no longer exists must STAY removed, or the user taps Unsave
|
|
349
|
+
// forever on something the server will never accept. This panel is especially
|
|
350
|
+
// exposed: it spans every conversation, so clearing ANY chat can strand rows here.
|
|
351
|
+
if (isMessageGoneError(error)) {
|
|
352
|
+
showToast(t("MESSAGE_NO_LONGER_AVAILABLE") ?? "This message is no longer available.");
|
|
353
|
+
return;
|
|
354
|
+
}
|
|
355
|
+
setMessages(prev => [message, ...prev]);
|
|
356
|
+
setState("loaded");
|
|
357
|
+
showToast(t("PIN_SAVE_GENERIC_ERROR") ?? "Something went wrong. Please try again.");
|
|
358
|
+
});
|
|
359
|
+
};
|
|
360
|
+
|
|
361
|
+
/**
|
|
362
|
+
* The long-press menu: Unsave, and nothing else.
|
|
363
|
+
*
|
|
364
|
+
* A saved row is a pointer to a message, not the message itself, so the only
|
|
365
|
+
* action that belongs on it is the one that removes it from THIS list. Copy,
|
|
366
|
+
* share, info and unpin all act on the message and belong where the message
|
|
367
|
+
* actually is — its conversation, or the pinned panel.
|
|
368
|
+
*/
|
|
369
|
+
const menuItemsFor = (message: CometChat.BaseMessage): MenuItemInterface[] => {
|
|
370
|
+
if (hideUnsaveMessageOption) return [];
|
|
371
|
+
return [
|
|
372
|
+
{
|
|
373
|
+
text: t("UNSAVE_MESSAGE") ?? "Unsave message",
|
|
374
|
+
onPress: () => {
|
|
375
|
+
closeMenu();
|
|
376
|
+
onUnsave(message);
|
|
377
|
+
},
|
|
378
|
+
icon: (
|
|
379
|
+
// Same unsave glyph as the message action sheet — one action, one icon everywhere.
|
|
380
|
+
<Icon
|
|
381
|
+
name='unsave'
|
|
382
|
+
color={styles.menuIconStyle?.tintColor}
|
|
383
|
+
height={styles.menuIconStyle?.height}
|
|
384
|
+
width={styles.menuIconStyle?.width}
|
|
385
|
+
/>
|
|
386
|
+
),
|
|
387
|
+
},
|
|
388
|
+
];
|
|
389
|
+
};
|
|
390
|
+
|
|
391
|
+
const onLongPressRow = (message: CometChat.BaseMessage, e?: GestureResponderEvent) => {
|
|
392
|
+
if (!e || !("nativeEvent" in e)) return;
|
|
393
|
+
menuTarget.current = message;
|
|
394
|
+
menuAnchor.current = { pageX: e.nativeEvent.pageX, pageY: e.nativeEvent.pageY };
|
|
395
|
+
setMenuVisible(true);
|
|
396
|
+
};
|
|
397
|
+
|
|
398
|
+
/**
|
|
399
|
+
* Subtitle: an optional author prefix, then the preview. Mirrors the conversation
|
|
400
|
+
* list's vocabulary so a saved row reads the same as the chat it came from.
|
|
401
|
+
*
|
|
402
|
+
* The prefix rule lives in the helper — it is the only thing distinguishing an
|
|
403
|
+
* outgoing 1-1 row from an incoming one, since this list shows no receipts and both
|
|
404
|
+
* directions resolve to the same avatar and title.
|
|
405
|
+
*/
|
|
406
|
+
const renderSubtitle = (message: CometChat.BaseMessage) => {
|
|
407
|
+
const preview = previewFor(message);
|
|
408
|
+
const prefixName = subtitlePrefixNameFor(
|
|
409
|
+
message,
|
|
410
|
+
loggedInUser.current?.getUid() ?? null,
|
|
411
|
+
t("YOU") ?? "You"
|
|
412
|
+
);
|
|
413
|
+
const prefix = prefixName ? `${prefixName}: ` : "";
|
|
414
|
+
|
|
415
|
+
const label = preview.text ?? (preview.labelKey ? (t(preview.labelKey) ?? "") : "");
|
|
416
|
+
|
|
417
|
+
return (
|
|
418
|
+
<View style={localStyles.subtitleRow}>
|
|
419
|
+
{prefix ? (
|
|
420
|
+
<Text
|
|
421
|
+
numberOfLines={1}
|
|
422
|
+
style={itemStyle?.subtitleStyle}
|
|
423
|
+
>
|
|
424
|
+
{prefix}
|
|
425
|
+
</Text>
|
|
426
|
+
) : null}
|
|
427
|
+
{preview.icon ? (
|
|
428
|
+
<Icon
|
|
429
|
+
name={preview.icon as IconName}
|
|
430
|
+
color={styles.previewIconStyle?.tintColor}
|
|
431
|
+
height={styles.previewIconStyle?.height}
|
|
432
|
+
width={styles.previewIconStyle?.width}
|
|
433
|
+
containerStyle={styles.previewIconContainerStyle}
|
|
434
|
+
/>
|
|
435
|
+
) : null}
|
|
436
|
+
<Text
|
|
437
|
+
numberOfLines={1}
|
|
438
|
+
ellipsizeMode='tail'
|
|
439
|
+
style={[itemStyle?.subtitleStyle, localStyles.subtitleText]}
|
|
440
|
+
>
|
|
441
|
+
{label}
|
|
442
|
+
</Text>
|
|
443
|
+
</View>
|
|
444
|
+
);
|
|
445
|
+
};
|
|
446
|
+
|
|
447
|
+
const renderRow = ({ item, index }: { item: CometChat.BaseMessage; index: number }) => {
|
|
448
|
+
if (ItemView) return ItemView(item);
|
|
449
|
+
|
|
450
|
+
const source = sourceLabelFor(item, loggedInUser.current?.getUid() ?? null);
|
|
451
|
+
const name = source?.name ?? item.getSender()?.getName() ?? "";
|
|
452
|
+
const avatar = source?.avatar ?? item.getSender()?.getAvatar();
|
|
453
|
+
|
|
454
|
+
return (
|
|
455
|
+
<CometChatListItem
|
|
456
|
+
testID={`SavedMessages.row-${index}`}
|
|
457
|
+
id={item.getId()}
|
|
458
|
+
// A row whose source cannot be derived still renders (design doc §6.4 rule
|
|
459
|
+
// one) — it just falls back to the sender for identity.
|
|
460
|
+
avatarURL={avatar ? { uri: avatar } : undefined}
|
|
461
|
+
avatarName={name}
|
|
462
|
+
title={name}
|
|
463
|
+
// Row chrome comes from conversationStyles, the SAME source the conversation
|
|
464
|
+
// list uses, so a saved row is visually identical to the chat it came from.
|
|
465
|
+
// Without these the item has no flexDirection and the avatar, title and date
|
|
466
|
+
// stack vertically instead of forming a row.
|
|
467
|
+
containerStyle={itemStyle?.containerStyle}
|
|
468
|
+
titleStyle={itemStyle?.titleStyle}
|
|
469
|
+
avatarStyle={itemStyle?.avatarStyle}
|
|
470
|
+
headViewContainerStyle={localStyles.headViewContainer}
|
|
471
|
+
SubtitleView={renderSubtitle(item)}
|
|
472
|
+
// Date only. NO pin indicator: pinned is a property of a message within its
|
|
473
|
+
// conversation, and this list is not a conversation — surfacing it here just
|
|
474
|
+
// adds a signal the reader cannot act on and did not ask for. The pinned
|
|
475
|
+
// panel is where pin state belongs.
|
|
476
|
+
TrailingView={
|
|
477
|
+
<CometChatDate
|
|
478
|
+
timeStamp={item.getSentAt() * 1000}
|
|
479
|
+
pattern='conversationDate'
|
|
480
|
+
style={itemStyle?.dateStyle}
|
|
481
|
+
/>
|
|
482
|
+
}
|
|
483
|
+
onPress={() => onItemPress?.(item, source)}
|
|
484
|
+
onLongPress={(_id: string | number, e: GestureResponderEvent) => onLongPressRow(item, e)}
|
|
485
|
+
/>
|
|
486
|
+
);
|
|
487
|
+
};
|
|
488
|
+
|
|
489
|
+
return (
|
|
490
|
+
<View style={styles.containerStyle}>
|
|
491
|
+
{/* Back arrow LEADING the title, matching Group Info / User Info. This is a pushed
|
|
492
|
+
full-screen route, not a modal, so a leading back is the right affordance — a
|
|
493
|
+
trailing ✕ read as "dismiss a sheet". */}
|
|
494
|
+
<View style={styles.headerContainerStyle}>
|
|
495
|
+
{onBack ? (
|
|
496
|
+
<Pressable
|
|
497
|
+
testID='SavedMessages.back'
|
|
498
|
+
onPress={onBack}
|
|
499
|
+
accessibilityRole='button'
|
|
500
|
+
accessibilityLabel={t("BACK") ?? "Back"}
|
|
501
|
+
hitSlop={8}
|
|
502
|
+
>
|
|
503
|
+
<Icon
|
|
504
|
+
name='arrow-back'
|
|
505
|
+
icon={styles.closeButtonIcon}
|
|
506
|
+
color={styles.closeButtonIconStyle?.tintColor}
|
|
507
|
+
height={styles.closeButtonIconStyle?.height}
|
|
508
|
+
width={styles.closeButtonIconStyle?.width}
|
|
509
|
+
/>
|
|
510
|
+
</Pressable>
|
|
511
|
+
) : null}
|
|
512
|
+
<Text style={styles.titleStyle}>
|
|
513
|
+
{title ?? (t("SAVED_MESSAGES") ?? "Saved Messages")}
|
|
514
|
+
</Text>
|
|
515
|
+
</View>
|
|
516
|
+
|
|
517
|
+
{state === "loading" ? (
|
|
518
|
+
// The CONVERSATION skeleton, not a bespoke one: these rows are conversation
|
|
519
|
+
// rows, so the placeholder that matches them already exists and stays in step
|
|
520
|
+
// with them for free.
|
|
521
|
+
<Skeleton />
|
|
522
|
+
) : state === "empty" ? (
|
|
523
|
+
<ErrorEmptyView
|
|
524
|
+
testID='SavedMessages.empty'
|
|
525
|
+
// ErrorEmptyView is an unstyled shell — it renders a bare View with whatever
|
|
526
|
+
// containerStyle it is handed. Without these three the block sat top-left in the
|
|
527
|
+
// default text style instead of centred in the space the list would have filled.
|
|
528
|
+
containerStyle={styles.emptyStateStyle?.containerStyle}
|
|
529
|
+
title={t("NO_SAVED_MESSAGES") ?? "No saved messages yet"}
|
|
530
|
+
titleStyle={styles.emptyStateStyle?.titleStyle}
|
|
531
|
+
subTitle={
|
|
532
|
+
t("NO_SAVED_MESSAGES_SUBTITLE") ??
|
|
533
|
+
"Save messages to keep them handy whenever you need them."
|
|
534
|
+
}
|
|
535
|
+
subTitleStyle={styles.emptyStateStyle?.subTitleStyle}
|
|
536
|
+
Icon={
|
|
537
|
+
<Icon
|
|
538
|
+
name='bookmark-fill'
|
|
539
|
+
color={styles.emptyStateStyle?.iconStyle?.tintColor}
|
|
540
|
+
height={styles.emptyStateStyle?.iconStyle?.height}
|
|
541
|
+
width={styles.emptyStateStyle?.iconStyle?.width}
|
|
542
|
+
/>
|
|
543
|
+
}
|
|
544
|
+
/>
|
|
545
|
+
) : state === "error" ? (
|
|
546
|
+
// The house error state, same as the conversation list: error-state illustration,
|
|
547
|
+
// Oops! / went wrong / try again, and a Retry button. A bare sentence in the
|
|
548
|
+
// default text style was the only thing here before, which read as a broken
|
|
549
|
+
// screen rather than a recoverable one.
|
|
550
|
+
<ErrorEmptyView
|
|
551
|
+
testID='SavedMessages.error'
|
|
552
|
+
containerStyle={styles.errorStateStyle?.containerStyle}
|
|
553
|
+
title={t("OOPS") ?? "Oops!"}
|
|
554
|
+
titleStyle={styles.errorStateStyle?.titleStyle}
|
|
555
|
+
subTitle={t("SOMETHING_WENT_WRONG") ?? "Looks like something went wrong."}
|
|
556
|
+
tertiaryTitle={t("WRONG_TEXT_TRY_AGAIN") ?? "Please try again."}
|
|
557
|
+
subTitleStyle={styles.errorStateStyle?.subTitleStyle}
|
|
558
|
+
Icon={
|
|
559
|
+
<Icon
|
|
560
|
+
name='error-state'
|
|
561
|
+
height={styles.errorStateStyle?.iconStyle?.height}
|
|
562
|
+
width={styles.errorStateStyle?.iconStyle?.width}
|
|
563
|
+
containerStyle={{ marginBottom: styles.errorStateStyle?.iconStyle?.marginBottom }}
|
|
564
|
+
/>
|
|
565
|
+
}
|
|
566
|
+
RetryView={<CometChatRetryButton onPress={reload} />}
|
|
567
|
+
/>
|
|
568
|
+
) : (
|
|
569
|
+
<FlatList
|
|
570
|
+
testID='SavedMessages.list'
|
|
571
|
+
data={messages}
|
|
572
|
+
keyExtractor={item => String(item.getId())}
|
|
573
|
+
renderItem={renderRow}
|
|
574
|
+
onEndReachedThreshold={0.5}
|
|
575
|
+
onEndReached={loadNext}
|
|
576
|
+
onLayout={event => {
|
|
577
|
+
viewportHeight.current = event.nativeEvent.layout.height;
|
|
578
|
+
fillViewport();
|
|
579
|
+
}}
|
|
580
|
+
onContentSizeChange={(_width, height) => {
|
|
581
|
+
contentHeight.current = height;
|
|
582
|
+
fillViewport();
|
|
583
|
+
}}
|
|
584
|
+
/>
|
|
585
|
+
)}
|
|
586
|
+
|
|
587
|
+
<CometChatConfirmDialog
|
|
588
|
+
titleText={t("UNSAVE_MESSAGE_TITLE") ?? "Unsave Message"}
|
|
589
|
+
icon={<Icon name='unsave' size={theme.spacing.spacing.s12} color={theme.color.error} />}
|
|
590
|
+
cancelButtonText={t("CANCEL") ?? "Cancel"}
|
|
591
|
+
confirmButtonText={t("UNSAVE") ?? "Unsave"}
|
|
592
|
+
messageText={
|
|
593
|
+
t("UNSAVE_MESSAGE_CONFIRM") ??
|
|
594
|
+
"Do you want to remove this message from your saved messages?"
|
|
595
|
+
}
|
|
596
|
+
isOpen={confirmUnsave != null}
|
|
597
|
+
onCancel={() => setConfirmUnsave(null)}
|
|
598
|
+
onConfirm={() => {
|
|
599
|
+
if (confirmUnsave) runUnsave(confirmUnsave);
|
|
600
|
+
setConfirmUnsave(null);
|
|
601
|
+
}}
|
|
602
|
+
/>
|
|
603
|
+
|
|
604
|
+
{/* The conversation list's own long-press affordance, anchored at the touch
|
|
605
|
+
point — the same component and the same shape as its Pin/Delete menu. */}
|
|
606
|
+
<CometChatTooltipMenu
|
|
607
|
+
visible={menuVisible}
|
|
608
|
+
onClose={closeMenu}
|
|
609
|
+
event={{ nativeEvent: menuAnchor.current }}
|
|
610
|
+
menuItems={menuTarget.current ? menuItemsFor(menuTarget.current) : []}
|
|
611
|
+
/>
|
|
612
|
+
|
|
613
|
+
{ToastElement}
|
|
614
|
+
</View>
|
|
615
|
+
);
|
|
616
|
+
};
|
|
617
|
+
|
|
618
|
+
/**
|
|
619
|
+
* Static layout only — nothing here depends on the theme. Anything theme-derived
|
|
620
|
+
* lives in ./style.ts (or conversationStyles, for the row chrome) and is merged in.
|
|
621
|
+
*/
|
|
622
|
+
const localStyles = StyleSheet.create({
|
|
623
|
+
subtitleRow: {
|
|
624
|
+
flexDirection: "row",
|
|
625
|
+
alignItems: "center",
|
|
626
|
+
flexShrink: 1,
|
|
627
|
+
},
|
|
628
|
+
subtitleText: {
|
|
629
|
+
flexShrink: 1,
|
|
630
|
+
},
|
|
631
|
+
headViewContainer: {
|
|
632
|
+
marginHorizontal: 9,
|
|
633
|
+
},
|
|
634
|
+
});
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { CometChatSavedMessages } from "./CometChatSavedMessages";
|
|
2
|
+
export type { CometChatSavedMessagesInterface } from "./CometChatSavedMessages";
|
|
3
|
+
|
|
4
|
+
export { getSavedMessagesStyleLight, getSavedMessagesStyleDark } from "./style";
|
|
5
|
+
export type { SavedMessagesStyle } from "./style";
|