@cometchat/chat-uikit-react-native 5.5.4 → 5.6.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/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/FileManager.m +70 -6
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +124 -55
- package/src/CometChatConversations/CometChatConversations.tsx +240 -117
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
- package/src/CometChatGroups/CometChatGroups.tsx +61 -52
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +146 -66
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageList/CometChatMessageList.tsx +1371 -188
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
- package/src/CometChatSearch/CometChatSearch.tsx +353 -101
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
- package/src/CometChatUsers/CometChatUsers.tsx +2 -0
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
- package/src/index.ts +6 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
- package/src/shared/framework/MessageDataSource.tsx +34 -14
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +218 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +90 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/theme/type.ts +17 -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
|
@@ -38,6 +38,14 @@ import { Skeleton } from "./Skeleton";
|
|
|
38
38
|
import Header from "../shared/views/CometChatList/Header";
|
|
39
39
|
import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
|
|
40
40
|
import NotificationEmptyIcon from "../shared/icons/components/notification-empty";
|
|
41
|
+
import { readListPage } from "../shared/offline/twoPhase";
|
|
42
|
+
import { useOfflineSessionEnded } from "../shared/offline/useOfflineSessionEnded";
|
|
43
|
+
import { useOfflineReconnect } from "../shared/offline/useOfflineReconnect";
|
|
44
|
+
import { isOfflineOn, sdkConnected } from "../shared/offline/gate";
|
|
45
|
+
import { isNotConnectedError } from "../shared/offline/reconcile";
|
|
46
|
+
import { ConnectStateView } from "../shared/offline/OfflineViews";
|
|
47
|
+
import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
|
|
48
|
+
import { CONTRACT_IDS } from "../shared/offline/stateContract";
|
|
41
49
|
|
|
42
50
|
// ───────────────────────────────────────────────────────────────
|
|
43
51
|
// Module-level constants (hoisted — no GC churn)
|
|
@@ -148,6 +156,16 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
148
156
|
// ─── State ───────────────────────────────────────────────────
|
|
149
157
|
const [screenState, setScreenState] = useState<ScreenState>("loading");
|
|
150
158
|
const [feedItems, setFeedItems] = useState<NotificationFeedItem[]>([]);
|
|
159
|
+
// Offline ON: nothing of the old session stays on screen (UIK-LIFE-01).
|
|
160
|
+
useOfflineSessionEnded(() => {
|
|
161
|
+
setFeedItems([]);
|
|
162
|
+
setScreenState("empty");
|
|
163
|
+
});
|
|
164
|
+
// Offline ON (D84): the device was not connected and has nothing saved: "Connect to load
|
|
165
|
+
// notifications" shows (the app's own ErrorView instead, if it passed one) and the feed loads
|
|
166
|
+
// again once, by itself, when the connection is back. Any other error is not loaded again.
|
|
167
|
+
const [offlineMiss, setOfflineMiss] = useState(false);
|
|
168
|
+
const reloadOnConnectRef = useRef(false);
|
|
151
169
|
const [categories, setCategories] = useState<NotificationCategory[]>([]);
|
|
152
170
|
const [activeCategory, setActiveCategory] = useState<string | null>(null);
|
|
153
171
|
const [totalUnreadCount, setTotalUnreadCount] = useState<number>(0);
|
|
@@ -243,8 +261,22 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
243
261
|
feedRequestRef.current = builder;
|
|
244
262
|
|
|
245
263
|
try {
|
|
246
|
-
|
|
247
|
-
|
|
264
|
+
// Offline ON: two-phase; offline past the cache the device's feed shows (U6).
|
|
265
|
+
const page = await readListPage<any>(builder, "next");
|
|
266
|
+
const items = page.rows;
|
|
267
|
+
if (page.offline && items.length === 0) {
|
|
268
|
+
// Nothing on the device and not connected: the offline state and onError once (D84 rule 3),
|
|
269
|
+
// not an empty feed; it loads again once on reconnect.
|
|
270
|
+
reloadOnConnectRef.current = true;
|
|
271
|
+
setOfflineMiss(true);
|
|
272
|
+
setScreenState("error");
|
|
273
|
+
onError?.(page.error as CometChat.CometChatException);
|
|
274
|
+
return;
|
|
275
|
+
}
|
|
276
|
+
reloadOnConnectRef.current = false;
|
|
277
|
+
setOfflineMiss(false);
|
|
278
|
+
// The device's rows are shown and the server read could not be reached: the rows stay and
|
|
279
|
+
// nothing is reported (D84 rule 2).
|
|
248
280
|
if (!items || items.length === 0) {
|
|
249
281
|
setScreenState("empty");
|
|
250
282
|
setFeedItems([]);
|
|
@@ -273,6 +305,8 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
273
305
|
}
|
|
274
306
|
}
|
|
275
307
|
} catch (err: any) {
|
|
308
|
+
reloadOnConnectRef.current = false;
|
|
309
|
+
setOfflineMiss(false);
|
|
276
310
|
setScreenState("error");
|
|
277
311
|
onError?.(err);
|
|
278
312
|
} finally {
|
|
@@ -290,13 +324,20 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
290
324
|
setIsLoadingMore(true);
|
|
291
325
|
setLoadMoreError(false);
|
|
292
326
|
try {
|
|
293
|
-
const
|
|
294
|
-
|
|
295
|
-
if (
|
|
327
|
+
const page = await readListPage<any>(feedRequestRef.current, "next");
|
|
328
|
+
const items = page.rows;
|
|
329
|
+
if (page.offline && items.length === 0) {
|
|
330
|
+
// A cached page never ends the feed (BEH-READ-09b): "load more" errors, retry reads on.
|
|
331
|
+
setLoadMoreError(true);
|
|
332
|
+
} else if (!items || items.length === 0) {
|
|
296
333
|
setHasMorePages(false);
|
|
297
334
|
hasMorePagesRef.current = false;
|
|
298
335
|
} else {
|
|
299
|
-
|
|
336
|
+
// Reading past the last page can repeat items (SDK known issue): dedupe by id.
|
|
337
|
+
setFeedItems((prev) => {
|
|
338
|
+
const seen = new Set(prev.map((i: any) => String(i?.id ?? i?.getId?.() ?? "")));
|
|
339
|
+
return [...prev, ...items.filter((i: any) => !seen.has(String(i?.id ?? i?.getId?.() ?? "")))];
|
|
340
|
+
});
|
|
300
341
|
markItemsAsDelivered(items);
|
|
301
342
|
}
|
|
302
343
|
} catch (err: any) {
|
|
@@ -327,7 +368,8 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
327
368
|
markItemsAsDelivered(items);
|
|
328
369
|
}
|
|
329
370
|
} catch (err: any) {
|
|
330
|
-
|
|
371
|
+
// D84 rule 2: not connected over the rows on screen is not an error. A real one is reported (rule 5).
|
|
372
|
+
if (!(isOfflineOn() && (isNotConnectedError(err) || sdkConnected() === false))) onError?.(err);
|
|
331
373
|
} finally {
|
|
332
374
|
setIsRefreshing(false);
|
|
333
375
|
}
|
|
@@ -469,6 +511,13 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
469
511
|
fetchInitialItems();
|
|
470
512
|
}, [activeCategory]);
|
|
471
513
|
|
|
514
|
+
// D84 rule 8: the one load again of the offline state.
|
|
515
|
+
useOfflineReconnect(() => {
|
|
516
|
+
if (!reloadOnConnectRef.current) return;
|
|
517
|
+
reloadOnConnectRef.current = false;
|
|
518
|
+
void fetchInitialItems();
|
|
519
|
+
});
|
|
520
|
+
|
|
472
521
|
// ─── Lifecycle: WebSocket Listener ───────────────────────────
|
|
473
522
|
useEffect(() => {
|
|
474
523
|
const listenerId = listenerIdRef.current;
|
|
@@ -751,6 +800,21 @@ export const CometChatNotificationFeed = (props: CometChatNotificationFeedInterf
|
|
|
751
800
|
</View>
|
|
752
801
|
);
|
|
753
802
|
}
|
|
803
|
+
if (offlineMiss) {
|
|
804
|
+
// D84 rule 3: offline with nothing saved: the offline state, no Retry.
|
|
805
|
+
return (
|
|
806
|
+
<View style={mergedStyles.containerStyle}>
|
|
807
|
+
{renderHeader()}
|
|
808
|
+
<ConnectStateView
|
|
809
|
+
testID={CONTRACT_IDS.emptyConnectToLoad}
|
|
810
|
+
title={t(OFFLINE_STRING_KEYS.connectToLoadNotifications)}
|
|
811
|
+
containerStyle={mergedStyles.errorStateStyle?.containerStyle}
|
|
812
|
+
titleStyle={mergedStyles.errorStateStyle?.titleStyle}
|
|
813
|
+
subtitleStyle={mergedStyles.errorStateStyle?.subTitleStyle}
|
|
814
|
+
/>
|
|
815
|
+
</View>
|
|
816
|
+
);
|
|
817
|
+
}
|
|
754
818
|
return (
|
|
755
819
|
<View style={mergedStyles.containerStyle}>
|
|
756
820
|
{renderHeader()}
|
|
@@ -60,6 +60,13 @@ import { MessageEvents } from "../shared/events/messages";
|
|
|
60
60
|
import { CometChatTextFormatter } from "../shared/formatters/CometChatTextFormatter";
|
|
61
61
|
import { applyRawFormatters } from "../shared/formatters/applyRawFormatters";
|
|
62
62
|
import { buildPinnedMessagesRequest } from "../shared/utils/PinnedMessagesHelper";
|
|
63
|
+
import { readListPage } from "../shared/offline/twoPhase";
|
|
64
|
+
import { mediaActionSource, notifyMediaUnavailable } from "../shared/offline/media";
|
|
65
|
+
import { useOfflineSessionEnded } from "../shared/offline/useOfflineSessionEnded";
|
|
66
|
+
import { useOfflineReconnect } from "../shared/offline/useOfflineReconnect";
|
|
67
|
+
import { ConnectStateView } from "../shared/offline/OfflineViews";
|
|
68
|
+
import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
|
|
69
|
+
import { CONTRACT_IDS } from "../shared/offline/stateContract";
|
|
63
70
|
|
|
64
71
|
/**
|
|
65
72
|
* The options this panel is willing to show, as an ALLOW-LIST.
|
|
@@ -209,6 +216,11 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
209
216
|
value => { if (mounted.current) setStateRaw(value); },
|
|
210
217
|
[]
|
|
211
218
|
);
|
|
219
|
+
// Offline ON: nothing of the old session stays on screen (UIK-LIFE-01).
|
|
220
|
+
useOfflineSessionEnded(() => {
|
|
221
|
+
setMessages([]);
|
|
222
|
+
setState("empty");
|
|
223
|
+
});
|
|
212
224
|
|
|
213
225
|
/** Long-press sheet state, mirroring what CometChatMessageList keeps. */
|
|
214
226
|
const [sheetOptions, setSheetOptions] = useState<CometChatMessageOption[]>([]);
|
|
@@ -239,6 +251,14 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
239
251
|
* can only come back empty again.
|
|
240
252
|
*/
|
|
241
253
|
const exhausted = useRef(false);
|
|
254
|
+
/**
|
|
255
|
+
* Offline ON (D84): "Connect to load messages" is up because the device was not connected and nothing is
|
|
256
|
+
* saved: the panel reads again once, by itself, when the connection is back. Any other error
|
|
257
|
+
* is not read again.
|
|
258
|
+
*/
|
|
259
|
+
const reloadOnConnect = useRef(false);
|
|
260
|
+
/** Offline ON (D84 rule 3): the error state is "Connect to load messages" (not the error view) while this is set. */
|
|
261
|
+
const [offlineMiss, setOfflineMiss] = useState(false);
|
|
242
262
|
|
|
243
263
|
/**
|
|
244
264
|
* The ordinary messages request, filtered to pinned rows. Paging is the ordinary
|
|
@@ -261,7 +281,32 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
261
281
|
try {
|
|
262
282
|
// fetchPrevious(), not fetchNext() — "previous" is older, which is the direction
|
|
263
283
|
// this list scrolls. Same call CometChatMessageList makes to load history.
|
|
264
|
-
|
|
284
|
+
// Offline ON: the SDK's two-phase read; offline past the cache it answers with the
|
|
285
|
+
// device's page instead of an error (U6). Offline OFF: today's Promise fetch.
|
|
286
|
+
const { rows, offline } = await readListPage<CometChat.BaseMessage>(request.current, "previous");
|
|
287
|
+
if (offline) {
|
|
288
|
+
// A cached page never ends the list (BEH-READ-09b, BEH-PIN-02); a retry reads on.
|
|
289
|
+
if (rows.length > 0) {
|
|
290
|
+
setMessages(prev => {
|
|
291
|
+
const seen = new Set(prev.map(m => String(m.getId())));
|
|
292
|
+
return [...prev, ...rows.filter(r => !seen.has(String(r.getId())))];
|
|
293
|
+
});
|
|
294
|
+
setState("loaded");
|
|
295
|
+
reloadOnConnect.current = false;
|
|
296
|
+
setOfflineMiss(false);
|
|
297
|
+
} else {
|
|
298
|
+
// Nothing on the device and not connected: the offline state (D84), not an empty panel.
|
|
299
|
+
setState(prev => {
|
|
300
|
+
if (prev !== "loading") return prev;
|
|
301
|
+
reloadOnConnect.current = true;
|
|
302
|
+
return "error";
|
|
303
|
+
});
|
|
304
|
+
setOfflineMiss(true);
|
|
305
|
+
}
|
|
306
|
+
return;
|
|
307
|
+
}
|
|
308
|
+
reloadOnConnect.current = false;
|
|
309
|
+
setOfflineMiss(false);
|
|
265
310
|
if (rows.length > 0) {
|
|
266
311
|
// Dedupe on append (ENG-38891). A realtime pin/save PREPENDS its row the moment the
|
|
267
312
|
// event lands; the same message then comes back inside a later fetched page, and a
|
|
@@ -279,6 +324,8 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
279
324
|
// Log it — a bare `catch {}` hides client-side rejections that never reach the
|
|
280
325
|
// network, leaving a generic error screen and an empty network log to debug from.
|
|
281
326
|
console.error("CometChatPinnedMessages: failed to fetch pinned messages", e);
|
|
327
|
+
reloadOnConnect.current = false;
|
|
328
|
+
setOfflineMiss(false);
|
|
282
329
|
setState(prev => (prev === "loading" ? "error" : prev));
|
|
283
330
|
} finally {
|
|
284
331
|
fetching.current = false;
|
|
@@ -319,6 +366,13 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
319
366
|
loadNext();
|
|
320
367
|
}, [buildRequest, loadNext]);
|
|
321
368
|
|
|
369
|
+
// D84 rule 8: the one read again of the offline state.
|
|
370
|
+
useOfflineReconnect(() => {
|
|
371
|
+
if (!reloadOnConnect.current) return;
|
|
372
|
+
reloadOnConnect.current = false;
|
|
373
|
+
reload();
|
|
374
|
+
});
|
|
375
|
+
|
|
322
376
|
useEffect(() => {
|
|
323
377
|
CometChat.getLoggedinUser()
|
|
324
378
|
.then(u => {
|
|
@@ -618,7 +672,15 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
618
672
|
const onShare = (message: CometChat.BaseMessage) => {
|
|
619
673
|
const attachment =
|
|
620
674
|
message instanceof CometChat.MediaMessage ? message.getAttachment() : undefined;
|
|
621
|
-
|
|
675
|
+
let fileUrl = attachment?.getUrl() ?? "";
|
|
676
|
+
// Offline ON: share the saved file, never re-fetch the URL (BEH-MEDIA-18).
|
|
677
|
+
const source = attachment ? mediaActionSource(attachment) : null;
|
|
678
|
+
if (source?.kind === "unavailable") {
|
|
679
|
+
closeSheet();
|
|
680
|
+
notifyMediaUnavailable();
|
|
681
|
+
return;
|
|
682
|
+
}
|
|
683
|
+
if (source?.kind === "local") fileUrl = source.uri;
|
|
622
684
|
const shareObj = {
|
|
623
685
|
// Plain text: the share target is another app, which cannot read our wire format.
|
|
624
686
|
message: stripRichText(applyRawFormatters(textOf(message), textFormatters)),
|
|
@@ -858,6 +920,16 @@ export const CometChatPinnedMessages = (props: CometChatPinnedMessagesInterface)
|
|
|
858
920
|
}
|
|
859
921
|
/>
|
|
860
922
|
) : state === "error" ? (
|
|
923
|
+
offlineMiss ? (
|
|
924
|
+
// D84 rule 3: offline with nothing saved: the offline state, no Retry; it loads by itself on reconnect.
|
|
925
|
+
<ConnectStateView
|
|
926
|
+
testID={CONTRACT_IDS.emptyConnectToLoad}
|
|
927
|
+
title={t(OFFLINE_STRING_KEYS.connectToLoadMessages)}
|
|
928
|
+
containerStyle={styles.errorStateStyle?.containerStyle}
|
|
929
|
+
titleStyle={styles.errorStateStyle?.titleStyle}
|
|
930
|
+
subtitleStyle={styles.errorStateStyle?.subTitleStyle}
|
|
931
|
+
/>
|
|
932
|
+
) :
|
|
861
933
|
// The house error state, same as the conversation list: error-state illustration,
|
|
862
934
|
// Oops! / went wrong / try again, and a Retry button. A bare sentence in the
|
|
863
935
|
// default text style was the only thing here before, which read as a broken
|
|
@@ -56,6 +56,7 @@ import {
|
|
|
56
56
|
sourceLabelFor,
|
|
57
57
|
subtitlePrefixNameFor,
|
|
58
58
|
SavedMessageSource,
|
|
59
|
+
sentAtDesc,
|
|
59
60
|
} from "../shared/utils/SavedMessagesHelper";
|
|
60
61
|
import {
|
|
61
62
|
carryPinSaveAttrs,
|
|
@@ -67,6 +68,12 @@ import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandle
|
|
|
67
68
|
import { MessageEvents } from "../shared/events/messages";
|
|
68
69
|
import { CometChatTextFormatter } from "../shared/formatters/CometChatTextFormatter";
|
|
69
70
|
import { applyRawFormatters } from "../shared/formatters/applyRawFormatters";
|
|
71
|
+
import { readListPage } from "../shared/offline/twoPhase";
|
|
72
|
+
import { useOfflineSessionEnded } from "../shared/offline/useOfflineSessionEnded";
|
|
73
|
+
import { useOfflineReconnect } from "../shared/offline/useOfflineReconnect";
|
|
74
|
+
import { ConnectStateView } from "../shared/offline/OfflineViews";
|
|
75
|
+
import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
|
|
76
|
+
import { CONTRACT_IDS } from "../shared/offline/stateContract";
|
|
70
77
|
|
|
71
78
|
/**
|
|
72
79
|
* Module-level rich text formatter — reused across renders (no GC churn), mirroring
|
|
@@ -181,6 +188,11 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
181
188
|
value => { if (mounted.current) setStateRaw(value); },
|
|
182
189
|
[]
|
|
183
190
|
);
|
|
191
|
+
// Offline ON: nothing of the old session stays on screen (UIK-LIFE-01).
|
|
192
|
+
useOfflineSessionEnded(() => {
|
|
193
|
+
setMessages([]);
|
|
194
|
+
setState("empty");
|
|
195
|
+
});
|
|
184
196
|
|
|
185
197
|
/**
|
|
186
198
|
* Long-press menu state. Anchored at the touch point via CometChatTooltipMenu —
|
|
@@ -208,6 +220,14 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
208
220
|
* can only come back empty again.
|
|
209
221
|
*/
|
|
210
222
|
const exhausted = useRef(false);
|
|
223
|
+
/**
|
|
224
|
+
* Offline ON (D84): "Connect to load messages" is up because the device was not connected and nothing is
|
|
225
|
+
* saved: the panel reads again once, by itself, when the connection is back. Any other error
|
|
226
|
+
* is not read again.
|
|
227
|
+
*/
|
|
228
|
+
const reloadOnConnect = useRef(false);
|
|
229
|
+
/** Offline ON (D84 rule 3): the error state is "Connect to load messages" (not the error view) while this is set. */
|
|
230
|
+
const [offlineMiss, setOfflineMiss] = useState(false);
|
|
211
231
|
|
|
212
232
|
if (request.current === null) {
|
|
213
233
|
request.current = buildSavedMessagesRequest(limit, messagesRequestBuilder);
|
|
@@ -219,14 +239,39 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
219
239
|
try {
|
|
220
240
|
// fetchPrevious(), not fetchNext() — "previous" is older, which is the direction
|
|
221
241
|
// this list scrolls. Same call CometChatMessageList makes to load history.
|
|
222
|
-
|
|
242
|
+
// Offline ON: the SDK's two-phase read; offline past the cache it answers with the
|
|
243
|
+
// device's page instead of an error (U6). Offline OFF: today's Promise fetch.
|
|
244
|
+
const { rows, offline } = await readListPage<CometChat.BaseMessage>(request.current, "previous");
|
|
245
|
+
if (offline) {
|
|
246
|
+
// A cached page never ends the list (BEH-READ-09b, BEH-PIN-02); a retry reads on.
|
|
247
|
+
if (rows.length > 0) {
|
|
248
|
+
setMessages(prev => {
|
|
249
|
+
const seen = new Set(prev.map(m => String(m.getId())));
|
|
250
|
+
return [...prev, ...rows.filter(r => !seen.has(String(r.getId())))].sort(sentAtDesc);
|
|
251
|
+
});
|
|
252
|
+
setState("loaded");
|
|
253
|
+
reloadOnConnect.current = false;
|
|
254
|
+
setOfflineMiss(false);
|
|
255
|
+
} else {
|
|
256
|
+
// Nothing on the device and not connected: the offline state (D84), not an empty panel.
|
|
257
|
+
setState(prev => {
|
|
258
|
+
if (prev !== "loading") return prev;
|
|
259
|
+
reloadOnConnect.current = true;
|
|
260
|
+
return "error";
|
|
261
|
+
});
|
|
262
|
+
setOfflineMiss(true);
|
|
263
|
+
}
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
reloadOnConnect.current = false;
|
|
267
|
+
setOfflineMiss(false);
|
|
223
268
|
if (rows.length > 0) {
|
|
224
269
|
// Dedupe on append (ENG-38891). A realtime pin/save PREPENDS its row the moment the
|
|
225
270
|
// event lands; the same message then comes back inside a later fetched page, and a
|
|
226
271
|
// plain concat lists it twice — which is how a five-pin cap rendered six rows.
|
|
227
272
|
setMessages(prev => {
|
|
228
273
|
const seen = new Set(prev.map(m => String(m.getId())));
|
|
229
|
-
return [...prev, ...rows.filter(r => !seen.has(String(r.getId())))];
|
|
274
|
+
return [...prev, ...rows.filter(r => !seen.has(String(r.getId())))].sort(sentAtDesc);
|
|
230
275
|
});
|
|
231
276
|
setState("loaded");
|
|
232
277
|
} else {
|
|
@@ -239,6 +284,8 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
239
284
|
// rejected client-side before any request) was unreachable from outside a debugger.
|
|
240
285
|
console.error("CometChatSavedMessages: failed to fetch saved messages", e);
|
|
241
286
|
// An empty first page is "empty", not "error" — only a real rejection is.
|
|
287
|
+
reloadOnConnect.current = false;
|
|
288
|
+
setOfflineMiss(false);
|
|
242
289
|
setState(prev => (prev === "loading" ? "error" : prev));
|
|
243
290
|
} finally {
|
|
244
291
|
fetching.current = false;
|
|
@@ -281,6 +328,13 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
281
328
|
// the request from the builder captured at mount.
|
|
282
329
|
}, [limit, messagesRequestBuilder, loadNext]);
|
|
283
330
|
|
|
331
|
+
// D84 rule 8: the one read again of the offline state.
|
|
332
|
+
useOfflineReconnect(() => {
|
|
333
|
+
if (!reloadOnConnect.current) return;
|
|
334
|
+
reloadOnConnect.current = false;
|
|
335
|
+
reload();
|
|
336
|
+
});
|
|
337
|
+
|
|
284
338
|
useEffect(() => {
|
|
285
339
|
CometChat.getLoggedinUser()
|
|
286
340
|
.then(user => {
|
|
@@ -320,7 +374,8 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
320
374
|
if (!message) return;
|
|
321
375
|
setMessages(prev => {
|
|
322
376
|
if (prev.some(m => sameMessageId(m.getId(), message.getId()))) return prev;
|
|
323
|
-
|
|
377
|
+
// By sentAt, not at the top: saving an old message must not make it look newest.
|
|
378
|
+
return [message, ...prev].sort(sentAtDesc);
|
|
324
379
|
});
|
|
325
380
|
setState("loaded");
|
|
326
381
|
};
|
|
@@ -431,7 +486,7 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
431
486
|
showToast(t("MESSAGE_NO_LONGER_AVAILABLE") ?? "This message is no longer available.");
|
|
432
487
|
return;
|
|
433
488
|
}
|
|
434
|
-
setMessages(prev => [message, ...prev]);
|
|
489
|
+
setMessages(prev => [message, ...prev].sort(sentAtDesc));
|
|
435
490
|
setState("loaded");
|
|
436
491
|
showToast(t("PIN_SAVE_GENERIC_ERROR") ?? "Something went wrong. Please try again.");
|
|
437
492
|
});
|
|
@@ -735,6 +790,16 @@ export const CometChatSavedMessages = (props: CometChatSavedMessagesInterface) =
|
|
|
735
790
|
}
|
|
736
791
|
/>
|
|
737
792
|
) : state === "error" ? (
|
|
793
|
+
offlineMiss ? (
|
|
794
|
+
// D84 rule 3: offline with nothing saved: the offline state, no Retry; it loads by itself on reconnect.
|
|
795
|
+
<ConnectStateView
|
|
796
|
+
testID={CONTRACT_IDS.emptyConnectToLoad}
|
|
797
|
+
title={t(OFFLINE_STRING_KEYS.connectToLoadMessages)}
|
|
798
|
+
containerStyle={styles.errorStateStyle?.containerStyle}
|
|
799
|
+
titleStyle={styles.errorStateStyle?.titleStyle}
|
|
800
|
+
subtitleStyle={styles.errorStateStyle?.subTitleStyle}
|
|
801
|
+
/>
|
|
802
|
+
) :
|
|
738
803
|
// The house error state, same as the conversation list: error-state illustration,
|
|
739
804
|
// Oops! / went wrong / try again, and a Retry button. A bare sentence in the
|
|
740
805
|
// default text style was the only thing here before, which read as a broken
|