@cometchat/chat-uikit-react-native 5.5.3 → 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/build.gradle +5 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +47 -4
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +209 -119
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/FileManager.m +70 -6
- package/ios/RichTextEditorView.swift +96 -1
- package/ios/SoundPlayer.m +152 -6
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/react-native-cometchat-ui-kit.podspec +1 -1
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +167 -79
- 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 +173 -85
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageList/CometChatMessageList.tsx +1423 -205
- 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/LinkPreview/LinkPreviewBubble.tsx +48 -47
- 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
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
ImageSourcePropType,
|
|
9
9
|
ImageStyle,
|
|
10
10
|
Platform,
|
|
11
|
+
RefreshControl,
|
|
11
12
|
StyleProp,
|
|
12
13
|
Text,
|
|
13
14
|
TextStyle,
|
|
@@ -30,6 +31,21 @@ import {
|
|
|
30
31
|
import Header from "./Header";
|
|
31
32
|
import styles from "./styles";
|
|
32
33
|
import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
|
|
34
|
+
import { isOfflineOn, offlineSdk, sdkConnected } from "../../offline/gate";
|
|
35
|
+
import { OfflineHub } from "../../offline/OfflineHub";
|
|
36
|
+
import { appendUnique, fetchTwoPhase, mergeSnapshotPage } from "../../offline/twoPhase";
|
|
37
|
+
import {
|
|
38
|
+
applyFirstServerPage,
|
|
39
|
+
mergeCachedFirstPage,
|
|
40
|
+
mergeFirstServerPage,
|
|
41
|
+
isFilteredConversationRequest,
|
|
42
|
+
keepUnsentPreviews,
|
|
43
|
+
reconcileSyncPage,
|
|
44
|
+
} from "../../offline/conversations";
|
|
45
|
+
import { ConnectStateView, ConnectToLoadMore } from "../../offline/OfflineViews";
|
|
46
|
+
import { OFFLINE_STRING_KEYS } from "../../offline/notices";
|
|
47
|
+
import { CONTRACT_IDS } from "../../offline/stateContract";
|
|
48
|
+
import { probeFrame } from "../../offline/frameProbe";
|
|
33
49
|
|
|
34
50
|
export interface CometChatListActionsInterface {
|
|
35
51
|
updateList: (prop: any) => void;
|
|
@@ -117,9 +133,22 @@ export interface CometChatListProps {
|
|
|
117
133
|
hideHeader?: boolean;
|
|
118
134
|
title?: string;
|
|
119
135
|
EmptyView?: React.FC;
|
|
136
|
+
/**
|
|
137
|
+
* Offline ON only: whether `EmptyView` is the integrator's own. A list wrapper that always
|
|
138
|
+
* passes a default empty view sets this so the kit's "Connect to search" state is not hidden by
|
|
139
|
+
* the wrapper's default but is by the integrator's. Defaults to `!!EmptyView`.
|
|
140
|
+
*/
|
|
141
|
+
customEmptyView?: boolean;
|
|
120
142
|
emptyStateText?: string;
|
|
121
143
|
errorStateText?: string;
|
|
122
144
|
ErrorView?: React.FC;
|
|
145
|
+
/**
|
|
146
|
+
* Offline ON only: whether `ErrorView` is the integrator's own, which then shows instead of the
|
|
147
|
+
* kit's "Connect to load ..." state (D84 rule 3). Defaults to `!!ErrorView`.
|
|
148
|
+
*/
|
|
149
|
+
customErrorView?: boolean;
|
|
150
|
+
/** Offline ON only: localization key of the "Connect to load ..." text (default from `listItemKey`). */
|
|
151
|
+
connectToLoadKey?: string;
|
|
123
152
|
LoadingView?: React.FC;
|
|
124
153
|
requestBuilder?: any;
|
|
125
154
|
searchRequestBuilder?: any;
|
|
@@ -129,6 +158,8 @@ export interface CometChatListProps {
|
|
|
129
158
|
onError?: (error: CometChat.CometChatException) => void;
|
|
130
159
|
onBack?: (() => void) | undefined;
|
|
131
160
|
listItemKey: "uid" | "guid" | "conversationId";
|
|
161
|
+
/** Automation identifier for each row (`testID`), e.g. the state contract's conversation row. */
|
|
162
|
+
itemTestID?: (item: any) => string | undefined;
|
|
132
163
|
listStyle?: DeepPartial<CometChatListStylesInterface>;
|
|
133
164
|
hideSubmitButton?: boolean;
|
|
134
165
|
statusIndicatorType?: (item: any) => CometChatStatusIndicatorInterface["type"] | null;
|
|
@@ -148,6 +179,13 @@ export interface CometChatListProps {
|
|
|
148
179
|
onSearchBarClicked?: () => void;
|
|
149
180
|
}
|
|
150
181
|
|
|
182
|
+
/** The "Connect to load ..." text of a list that could not load offline with nothing on screen. */
|
|
183
|
+
function connectToLoadKeyFor(listItemKey: "uid" | "guid" | "conversationId"): string {
|
|
184
|
+
if (listItemKey === "conversationId") return OFFLINE_STRING_KEYS.connectToLoadChats;
|
|
185
|
+
if (listItemKey === "guid") return OFFLINE_STRING_KEYS.connectToLoadGroups;
|
|
186
|
+
return OFFLINE_STRING_KEYS.connectToLoadUsers;
|
|
187
|
+
}
|
|
188
|
+
|
|
151
189
|
let lastCall: any;
|
|
152
190
|
let lastReject: Function;
|
|
153
191
|
|
|
@@ -183,9 +221,12 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
183
221
|
hideSearch = false,
|
|
184
222
|
title = "Title",
|
|
185
223
|
EmptyView,
|
|
224
|
+
customEmptyView,
|
|
186
225
|
emptyStateText = t("NO_USERS_FOUND"),
|
|
187
226
|
errorStateText = t("SOMETHING_WRONG"),
|
|
188
227
|
ErrorView,
|
|
228
|
+
customErrorView,
|
|
229
|
+
connectToLoadKey,
|
|
189
230
|
LoadingView,
|
|
190
231
|
requestBuilder,
|
|
191
232
|
hideHeader,
|
|
@@ -196,6 +237,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
196
237
|
onError,
|
|
197
238
|
onBack,
|
|
198
239
|
listItemKey = "uid",
|
|
240
|
+
itemTestID,
|
|
199
241
|
listStyle,
|
|
200
242
|
hideSubmitButton,
|
|
201
243
|
statusIndicatorType,
|
|
@@ -252,7 +294,41 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
252
294
|
const selectionEffectDidMountRef = useRef(false);
|
|
253
295
|
|
|
254
296
|
const [list, setList] = useState<any[]>([]);
|
|
297
|
+
// Dev and sample builds only: the row list of every committed frame (TEST-PLAN §3.3).
|
|
298
|
+
useEffect(() => {
|
|
299
|
+
probeFrame(`list:${listItemKey}`, () =>
|
|
300
|
+
list.map((item: any) => ({ key: String(item?.[listItemKey] ?? ""), id: 0, state: "", item }))
|
|
301
|
+
);
|
|
302
|
+
}, [list, listItemKey]);
|
|
255
303
|
const listRef = useRef<any[]>([]);
|
|
304
|
+
// Offline (ON path) state; untouched while offline is off.
|
|
305
|
+
const offlinePathUsedRef = useRef(false);
|
|
306
|
+
const offlineListRef = useRef<any[]>([]);
|
|
307
|
+
const offlineOpGenRef = useRef(0);
|
|
308
|
+
const offlineSearchTimer = useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
309
|
+
// A read past the cache failed offline and closed paging (conversations): the reconnect
|
|
310
|
+
// reopens it and loads that page once. Count of offline reads (and read-on loops) in flight.
|
|
311
|
+
const pagingClosedOfflineRef = useRef(false);
|
|
312
|
+
const offlineReadsInFlightRef = useRef(0);
|
|
313
|
+
/** A filtered chat list's re-read after a sync page is in flight: later sync pages start no second one. */
|
|
314
|
+
const syncRereadRef = useRef(false);
|
|
315
|
+
// D84 (offline ON): the error view, or the offline state, is up because a load failed with
|
|
316
|
+
// nothing on screen. "offline" = the device was not connected: a reconnect loads it again,
|
|
317
|
+
// once. "other" = any other error: never loaded again by itself. null = neither is up.
|
|
318
|
+
const errorViewRef = useRef<"offline" | "other" | null>(null);
|
|
319
|
+
// Which offline state shows over an empty list (D84 rule 3 and 7), if any: "load" = "Connect to
|
|
320
|
+
// load ..." (a plain list, error view slot), "search" = "Connect to search" (a keyword, empty
|
|
321
|
+
// view slot). Never set with offline off.
|
|
322
|
+
const [offlineState, setOfflineState] = useState<"none" | "load" | "search">("none");
|
|
323
|
+
// A reload the kit starts by itself (cache reset) goes through `reload()`: this makes it quiet
|
|
324
|
+
// while rows are shown, as the other kit-started re-reads are. Read once, synchronously.
|
|
325
|
+
const automaticReloadRef = useRef(false);
|
|
326
|
+
// A load-more asked for while an offline read was in flight: run once when the reads settle,
|
|
327
|
+
// so paging never waits for a second scroll (UIK-READ-03). Offline ON only; OFF keeps today's drop.
|
|
328
|
+
const deferredLoadMoreRef = useRef(false);
|
|
329
|
+
const [deferredLoadMoreTick, setDeferredLoadMoreTick] = useState(0);
|
|
330
|
+
const [offlineFooter, setOfflineFooter] = useState<"none" | "connect">("none");
|
|
331
|
+
const [refreshing, setRefreshing] = useState(false);
|
|
256
332
|
const [dataLoadingStatus, setDataLoadingStatus] = useState<string>(LOADING);
|
|
257
333
|
|
|
258
334
|
// Keep listRef in sync with list state for use in imperative methods
|
|
@@ -305,6 +381,15 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
305
381
|
};
|
|
306
382
|
|
|
307
383
|
const getSearch = (builtReq: any) => {
|
|
384
|
+
if (isOfflineOn()) {
|
|
385
|
+
// A keyword has no cache (BEH-SNAP-04): server only; offline with nothing saved is the error view (D83).
|
|
386
|
+
if (offlineSearchTimer.current) clearTimeout(offlineSearchTimer.current);
|
|
387
|
+
offlineSearchTimer.current = setTimeout(() => {
|
|
388
|
+
offlineSearchTimer.current = null;
|
|
389
|
+
void fetchListOffline(builtReq, true);
|
|
390
|
+
}, 500);
|
|
391
|
+
return;
|
|
392
|
+
}
|
|
308
393
|
getList(builtReq)
|
|
309
394
|
.then((newlist: any) => {
|
|
310
395
|
setDataLoadingStatus(NO_DATA_FOUND);
|
|
@@ -329,24 +414,65 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
329
414
|
return markedItems;
|
|
330
415
|
};
|
|
331
416
|
|
|
417
|
+
// D5: the connection listener below is registered once, so it reads the integrator's
|
|
418
|
+
// CURRENT request builder (and onListFetched) through refs instead of the first render's.
|
|
419
|
+
const requestBuilderRef = useRef(requestBuilder);
|
|
420
|
+
requestBuilderRef.current = requestBuilder;
|
|
421
|
+
const onListFetchedRef = useRef(props.onListFetched);
|
|
422
|
+
onListFetchedRef.current = props.onListFetched;
|
|
423
|
+
|
|
332
424
|
useEffect(() => {
|
|
333
425
|
CometChat.addConnectionListener(
|
|
334
426
|
connectionListenerId,
|
|
335
427
|
new CometChat.ConnectionListener({
|
|
336
428
|
onConnected: () => {
|
|
337
|
-
|
|
429
|
+
const offlineOn = isOfflineOn(); // gate read once for this reconnect
|
|
430
|
+
// Offline ON: conversations wait for the SDK's sync page (no fetch, UIK-SYNC-01).
|
|
431
|
+
if (offlineOn && listItemKey === "conversationId") {
|
|
432
|
+
// Paging a read past the cache closed offline opens again, and the load the user
|
|
433
|
+
// asked for runs now, once: its scroll trigger is spent (R5).
|
|
434
|
+
// D83 rule 4: so does an error view shown because the device was offline (not any other error).
|
|
435
|
+
if (pagingClosedOfflineRef.current || errorViewRef.current === "offline") {
|
|
436
|
+
const errorViewUp = errorViewRef.current === "offline" && listRef.current.length === 0;
|
|
437
|
+
pagingClosedOfflineRef.current = false;
|
|
438
|
+
errorViewRef.current = null;
|
|
439
|
+
setOfflineState("none");
|
|
440
|
+
setOfflineFooter("none");
|
|
441
|
+
setHasMoreData(true);
|
|
442
|
+
if (offlineReadsInFlightRef.current === 0) {
|
|
443
|
+
if (errorViewUp) setDataLoadingStatus(LOADING);
|
|
444
|
+
void readNextOfflineRef.current(listHandlerRef.current, listRef.current.length === 0);
|
|
445
|
+
}
|
|
446
|
+
}
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
// D83 rule 4: an error view shown for any other error is not loaded again by itself.
|
|
450
|
+
if (offlineOn && errorViewRef.current === "other") return;
|
|
451
|
+
const currentBuilder = requestBuilderRef.current;
|
|
452
|
+
if (currentBuilder) {
|
|
338
453
|
if (searchInputRef.current)
|
|
339
|
-
listHandlerRef.current =
|
|
454
|
+
listHandlerRef.current = currentBuilder
|
|
340
455
|
.setSearchKeyword(searchInputRef.current)
|
|
341
456
|
.build();
|
|
342
|
-
else listHandlerRef.current =
|
|
457
|
+
else listHandlerRef.current = currentBuilder.build();
|
|
458
|
+
}
|
|
459
|
+
if (offlineOn) {
|
|
460
|
+
// Today's trigger, two-phase so the list never blanks. Over an error view it is the
|
|
461
|
+
// one reload of rule 4: it shows loading, and fails loudly again if it must.
|
|
462
|
+
if (errorViewRef.current === "offline" && listRef.current.length === 0) {
|
|
463
|
+
errorViewRef.current = null;
|
|
464
|
+
setOfflineState("none");
|
|
465
|
+
setDataLoadingStatus(LOADING);
|
|
466
|
+
}
|
|
467
|
+
void fetchListOffline(listHandlerRef.current, true, true);
|
|
468
|
+
return;
|
|
343
469
|
}
|
|
344
470
|
getList(listHandlerRef.current)
|
|
345
471
|
.then((newlist: any[]) => {
|
|
346
472
|
setDataLoadingStatus(NO_DATA_FOUND);
|
|
347
473
|
setList(newlist);
|
|
348
474
|
setHasMoreData(true); // Reset pagination since we rebuilt the request
|
|
349
|
-
|
|
475
|
+
onListFetchedRef.current?.(newlist);
|
|
350
476
|
})
|
|
351
477
|
.catch((error) => {
|
|
352
478
|
if (error && error["message"] === "Promise cancelled") {
|
|
@@ -465,6 +591,11 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
465
591
|
* @param {boolean} throughKeyword - Pass true if wants to set only new users.
|
|
466
592
|
*/
|
|
467
593
|
const handleList = (throughKeyword?: boolean) => {
|
|
594
|
+
// Offline ON: a load-more asked for during an offline read waits for it, then runs (not dropped).
|
|
595
|
+
if (!throughKeyword && offlineReadsInFlightRef.current > 0 && isOfflineOn()) {
|
|
596
|
+
if (hasMoreData) deferredLoadMoreRef.current = true;
|
|
597
|
+
return;
|
|
598
|
+
}
|
|
468
599
|
// Prevent multiple fetches
|
|
469
600
|
if (isLoadingMore || (!throughKeyword && !hasMoreData)) return;
|
|
470
601
|
setIsLoadingMore(true);
|
|
@@ -487,6 +618,13 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
487
618
|
setHasMoreData(true);
|
|
488
619
|
}
|
|
489
620
|
|
|
621
|
+
if (isOfflineOn()) {
|
|
622
|
+
const firstPage = !!throughKeyword || list.length === 0;
|
|
623
|
+
if (listItemKey === "conversationId" && !firstPage) void readNextOffline(listHandlerRef.current, false);
|
|
624
|
+
else void fetchListOffline(listHandlerRef.current, firstPage, automaticReloadRef.current);
|
|
625
|
+
return;
|
|
626
|
+
}
|
|
627
|
+
|
|
490
628
|
getList(listHandlerRef.current)
|
|
491
629
|
.then((newlist: any[] = []) => {
|
|
492
630
|
let finalList: any[] = [];
|
|
@@ -531,6 +669,273 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
531
669
|
});
|
|
532
670
|
};
|
|
533
671
|
|
|
672
|
+
const offlineKeyOf = (item: any) => String(item?.[listItemKey] ?? "");
|
|
673
|
+
|
|
674
|
+
/**
|
|
675
|
+
* One page, two-phase (README §3.3, offline ON only): the cached page paints first, the
|
|
676
|
+
* server page replaces the same slice; an offline read past the cache keeps what is shown
|
|
677
|
+
* ("Connect to load more"). Only an empty online server page ends pagination.
|
|
678
|
+
*
|
|
679
|
+
* A failure (D84):
|
|
680
|
+
* - rows on screen, not connected: the rows stay, no error view, no `onError` (rule 2); a
|
|
681
|
+
* load-more page shows its "Connect to load more" footer;
|
|
682
|
+
* - rows on screen, a real error: the rows stay and `onError` fires once (rule 5), unless the
|
|
683
|
+
* kit started the read itself (`automatic`: reconnect, sync page, cache reset);
|
|
684
|
+
* - nothing on screen, not connected: "Connect to search" for a keyword (rule 7, no `onError`),
|
|
685
|
+
* otherwise the kit's "Connect to load ..." state in the error view's place (rule 3, `onError`
|
|
686
|
+
* once; the app's own error view shows instead if it passed one);
|
|
687
|
+
* - nothing on screen, a real error: the error view and `onError` (rule 4).
|
|
688
|
+
*
|
|
689
|
+
* `merge` (a conversations first page the kit re-reads itself after a sync page): the pages
|
|
690
|
+
* merge into the rows shown instead of replacing them, so rows paged in below page 1 stay.
|
|
691
|
+
*/
|
|
692
|
+
const fetchListOffline = (
|
|
693
|
+
request: any,
|
|
694
|
+
firstPage: boolean,
|
|
695
|
+
automatic = false,
|
|
696
|
+
merge = false
|
|
697
|
+
): Promise<any[] | undefined> => {
|
|
698
|
+
offlinePathUsedRef.current = true;
|
|
699
|
+
// A re-read the kit starts by itself (reconnect, sync page) that fails while rows are on
|
|
700
|
+
// screen stays quiet: rows stay, no footer, no error view, no onError. The next one retries.
|
|
701
|
+
const quietOnFailure = automatic && listRef.current.length > 0;
|
|
702
|
+
const opGen = ++offlineOpGenRef.current;
|
|
703
|
+
if (firstPage) deferredLoadMoreRef.current = false; // a fresh first page supersedes a waiting load-more
|
|
704
|
+
const hubGen = OfflineHub.getInstance().gen;
|
|
705
|
+
const stale = () => opGen !== offlineOpGenRef.current || hubGen !== OfflineHub.getInstance().gen;
|
|
706
|
+
const isConversations = listItemKey === "conversationId";
|
|
707
|
+
const keyword = searchInputRef.current;
|
|
708
|
+
let current = firstPage && !merge ? [] : listRef.current;
|
|
709
|
+
let cachedKeys = new Set<string>();
|
|
710
|
+
let shownCached = false;
|
|
711
|
+
let serverPage: any[] | undefined;
|
|
712
|
+
offlineReadsInFlightRef.current++;
|
|
713
|
+
setIsLoadingMore(true);
|
|
714
|
+
const publish = (next: any[]) => {
|
|
715
|
+
current = next;
|
|
716
|
+
offlineListRef.current = next;
|
|
717
|
+
listRef.current = next; // a read on right after this one starts from these rows
|
|
718
|
+
setList(next);
|
|
719
|
+
};
|
|
720
|
+
return fetchTwoPhase<any>(
|
|
721
|
+
request,
|
|
722
|
+
"next",
|
|
723
|
+
{
|
|
724
|
+
onCached: (page) => {
|
|
725
|
+
cachedKeys = new Set(page.map(offlineKeyOf));
|
|
726
|
+
if (page.length === 0) return;
|
|
727
|
+
shownCached = true;
|
|
728
|
+
publish(merge ? mergeCachedFirstPage(current, page) : firstPage ? page : appendUnique(current, page, offlineKeyOf));
|
|
729
|
+
setDataLoadingStatus("");
|
|
730
|
+
},
|
|
731
|
+
onServer: (page) => {
|
|
732
|
+
serverPage = page;
|
|
733
|
+
pagingClosedOfflineRef.current = false;
|
|
734
|
+
errorViewRef.current = null;
|
|
735
|
+
setOfflineState("none");
|
|
736
|
+
const base = firstPage && !shownCached && !merge ? [] : current;
|
|
737
|
+
const merged = mergeSnapshotPage(base, cachedKeys, page, offlineKeyOf);
|
|
738
|
+
const next = merge
|
|
739
|
+
? mergeFirstServerPage(base, cachedKeys, page)
|
|
740
|
+
: firstPage && isConversations
|
|
741
|
+
? applyFirstServerPage(base, page)
|
|
742
|
+
: isConversations
|
|
743
|
+
? keepUnsentPreviews(base, merged)
|
|
744
|
+
: merged;
|
|
745
|
+
publish(next);
|
|
746
|
+
setOfflineFooter("none");
|
|
747
|
+
// A merge over rows shown resets paging; an empty answer proves nothing (D17).
|
|
748
|
+
if (!merge || page.length > 0 || base.length === 0) setHasMoreData(page.length > 0);
|
|
749
|
+
setDataLoadingStatus(next.length === 0 ? NO_DATA_FOUND : "");
|
|
750
|
+
onListFetchedRef.current?.(next);
|
|
751
|
+
},
|
|
752
|
+
onError: (error, failedOffline) => {
|
|
753
|
+
if (quietOnFailure) return;
|
|
754
|
+
// Not connected: the SDK said so, or it reports no connection.
|
|
755
|
+
const notConnected = failedOffline || sdkConnected() === false;
|
|
756
|
+
if (notConnected && keyword && firstPage) {
|
|
757
|
+
// A keyword has no cache: the rows of the last search are not its answer (AC-10.2).
|
|
758
|
+
publish([]);
|
|
759
|
+
setHasMoreData(false);
|
|
760
|
+
}
|
|
761
|
+
if (listRef.current.length > 0) {
|
|
762
|
+
// Rows on screen stay (BEH-READ-06), no error view over them.
|
|
763
|
+
if (notConnected) {
|
|
764
|
+
// D84 rule 2: not connected over rows is not an error: no onError. A load-more page
|
|
765
|
+
// offers "Connect to load more" at its edge.
|
|
766
|
+
if (!keyword) {
|
|
767
|
+
setOfflineFooter("connect");
|
|
768
|
+
if (isConversations) pagingClosedOfflineRef.current = true;
|
|
769
|
+
}
|
|
770
|
+
return;
|
|
771
|
+
}
|
|
772
|
+
// D84 rule 5: a real error over rows, in a load the user or app started: onError once.
|
|
773
|
+
errorHandler(error);
|
|
774
|
+
return;
|
|
775
|
+
}
|
|
776
|
+
errorViewRef.current = notConnected ? "offline" : "other"; // only a not-connected one reloads on reconnect
|
|
777
|
+
if (notConnected && keyword) {
|
|
778
|
+
// D84 rule 7: an offline keyword search with nothing saved is an offline state, not an
|
|
779
|
+
// error: "Connect to search", no onError. It runs again once on reconnect.
|
|
780
|
+
setOfflineState("search");
|
|
781
|
+
setDataLoadingStatus(NO_DATA_FOUND);
|
|
782
|
+
return;
|
|
783
|
+
}
|
|
784
|
+
// D84 rule 3 and 4: nothing on screen. Offline: the kit's "Connect to load ..." state (the
|
|
785
|
+
// app's error view shows instead if it passed one); a real error: the error view. onError once.
|
|
786
|
+
setOfflineState(notConnected ? "load" : "none");
|
|
787
|
+
setDataLoadingStatus(SOMETHING_WRONG);
|
|
788
|
+
errorHandler(error);
|
|
789
|
+
},
|
|
790
|
+
},
|
|
791
|
+
stale
|
|
792
|
+
)
|
|
793
|
+
.finally(() => {
|
|
794
|
+
offlineReadsInFlightRef.current--;
|
|
795
|
+
setIsLoadingMore(false);
|
|
796
|
+
releaseDeferredLoadMore();
|
|
797
|
+
})
|
|
798
|
+
.then(() => serverPage);
|
|
799
|
+
};
|
|
800
|
+
|
|
801
|
+
/** The offline reads have settled: run the load-more that waited for them, once, from a fresh render. */
|
|
802
|
+
const releaseDeferredLoadMore = () => {
|
|
803
|
+
if (offlineReadsInFlightRef.current === 0 && deferredLoadMoreRef.current) setDeferredLoadMoreTick((t) => t + 1);
|
|
804
|
+
};
|
|
805
|
+
useEffect(() => {
|
|
806
|
+
if (deferredLoadMoreTick === 0 || !deferredLoadMoreRef.current) return;
|
|
807
|
+
deferredLoadMoreRef.current = false;
|
|
808
|
+
if (isOfflineOn()) handleList();
|
|
809
|
+
}, [deferredLoadMoreTick]);
|
|
810
|
+
|
|
811
|
+
/** Most pages one offline conversations read goes on while its pages list no new chat. */
|
|
812
|
+
const MAX_OFFLINE_READ_ON = 10;
|
|
813
|
+
|
|
814
|
+
/**
|
|
815
|
+
* Offline path of a conversations load-more. A server page that lists no new chat (the SDK's
|
|
816
|
+
* reconnect sync page already listed them) is not the end: the read goes on, up to
|
|
817
|
+
* MAX_OFFLINE_READ_ON pages, until a page brings a new chat. A stale read (list re-fetched,
|
|
818
|
+
* search changed, unmounted) or an empty / failed page stops it.
|
|
819
|
+
*/
|
|
820
|
+
const readNextOffline = async (request: any, firstPage: boolean): Promise<void> => {
|
|
821
|
+
const keyword = searchInputRef.current;
|
|
822
|
+
const listed = new Set(listRef.current.map(offlineKeyOf));
|
|
823
|
+
offlineReadsInFlightRef.current++; // held across the pages: no other read starts between them
|
|
824
|
+
try {
|
|
825
|
+
for (let reads = 0; reads < MAX_OFFLINE_READ_ON; reads++) {
|
|
826
|
+
const read = fetchListOffline(request, firstPage && reads === 0);
|
|
827
|
+
const gen = offlineOpGenRef.current;
|
|
828
|
+
const page = await read;
|
|
829
|
+
if (gen !== offlineOpGenRef.current || searchInputRef.current !== keyword) return;
|
|
830
|
+
if (!page?.length) return;
|
|
831
|
+
if (page.some((item: any) => !listed.has(offlineKeyOf(item)))) return;
|
|
832
|
+
}
|
|
833
|
+
} finally {
|
|
834
|
+
offlineReadsInFlightRef.current--;
|
|
835
|
+
releaseDeferredLoadMore();
|
|
836
|
+
}
|
|
837
|
+
};
|
|
838
|
+
const readNextOfflineRef = useRef(readNextOffline);
|
|
839
|
+
readNextOfflineRef.current = readNextOffline;
|
|
840
|
+
|
|
841
|
+
/** "Connect to load more" tapped: try the next page again. */
|
|
842
|
+
const retryOfflinePage = () => {
|
|
843
|
+
pagingClosedOfflineRef.current = false;
|
|
844
|
+
setOfflineFooter("none");
|
|
845
|
+
setHasMoreData(true);
|
|
846
|
+
void fetchListOffline(listHandlerRef.current, list.length === 0);
|
|
847
|
+
};
|
|
848
|
+
|
|
849
|
+
/** Pull-to-refresh, offline ON only (UIK-SYNC-05): ask the SDK for a catch-up sweep. */
|
|
850
|
+
const onPullToRefresh = () => {
|
|
851
|
+
setRefreshing(true);
|
|
852
|
+
const done = () => setRefreshing(false);
|
|
853
|
+
try {
|
|
854
|
+
const result: any = offlineSdk().forceSyncNow?.({
|
|
855
|
+
onSuccess: done,
|
|
856
|
+
onError: (error: any) => {
|
|
857
|
+
done();
|
|
858
|
+
// Sweep in progress or cooling down: end silently (AC-8.6). Offline off: today's refresh.
|
|
859
|
+
if (error?.code === "ERROR_OFFLINE_DISABLED") reload();
|
|
860
|
+
},
|
|
861
|
+
});
|
|
862
|
+
if (result && typeof result.then === "function") result.then(undefined, () => {});
|
|
863
|
+
else if (!result) done();
|
|
864
|
+
} catch {
|
|
865
|
+
done();
|
|
866
|
+
}
|
|
867
|
+
};
|
|
868
|
+
|
|
869
|
+
const offlineHandlers = {
|
|
870
|
+
onConversationSync: (conversations: any[], gen: number) => {
|
|
871
|
+
if (listItemKey !== "conversationId" || gen !== OfflineHub.getInstance().gen) return;
|
|
872
|
+
if (!offlinePathUsedRef.current && !isOfflineOn()) return;
|
|
873
|
+
const builder = requestBuilderRef.current;
|
|
874
|
+
if (searchInputRef.current || isFilteredConversationRequest(builder)) {
|
|
875
|
+
// A filtered list does not reconcile the plain sync page: it re-reads its own request
|
|
876
|
+
// once, merged into the rows shown, one at a time however many sync pages arrive.
|
|
877
|
+
if (syncRereadRef.current) return;
|
|
878
|
+
syncRereadRef.current = true;
|
|
879
|
+
if (builder) listHandlerRef.current = builder.build();
|
|
880
|
+
void fetchListOffline(listHandlerRef.current, true, true, true).finally(() => {
|
|
881
|
+
syncRereadRef.current = false;
|
|
882
|
+
});
|
|
883
|
+
return;
|
|
884
|
+
}
|
|
885
|
+
// The plain list reconciles the slice the page covers; the request cursor is untouched.
|
|
886
|
+
const next = reconcileSyncPage(listRef.current, conversations);
|
|
887
|
+
offlineListRef.current = next;
|
|
888
|
+
setList(next);
|
|
889
|
+
if (next.length > 0) setDataLoadingStatus("");
|
|
890
|
+
// The sync page is the server's answer: it replaces an error view (an empty page: the empty view).
|
|
891
|
+
else if (errorViewRef.current !== null) setDataLoadingStatus(NO_DATA_FOUND);
|
|
892
|
+
errorViewRef.current = null;
|
|
893
|
+
setOfflineState("none");
|
|
894
|
+
onListFetchedRef.current?.(next);
|
|
895
|
+
},
|
|
896
|
+
onSessionEnded: () => {
|
|
897
|
+
if (!offlinePathUsedRef.current) return;
|
|
898
|
+
offlineOpGenRef.current++;
|
|
899
|
+
deferredLoadMoreRef.current = false;
|
|
900
|
+
pagingClosedOfflineRef.current = false;
|
|
901
|
+
offlineListRef.current = [];
|
|
902
|
+
errorViewRef.current = null;
|
|
903
|
+
setOfflineState("none");
|
|
904
|
+
setList([]);
|
|
905
|
+
setOfflineFooter("none");
|
|
906
|
+
},
|
|
907
|
+
onCacheReset: () => {
|
|
908
|
+
if (!offlinePathUsedRef.current && !isOfflineOn()) return;
|
|
909
|
+
// The kit reloads by itself: quiet while rows are shown (D83 rule 3).
|
|
910
|
+
automaticReloadRef.current = true;
|
|
911
|
+
try {
|
|
912
|
+
reload();
|
|
913
|
+
} finally {
|
|
914
|
+
automaticReloadRef.current = false;
|
|
915
|
+
}
|
|
916
|
+
},
|
|
917
|
+
};
|
|
918
|
+
const offlineHandlersRef = useRef(offlineHandlers);
|
|
919
|
+
offlineHandlersRef.current = offlineHandlers;
|
|
920
|
+
|
|
921
|
+
const stopOfflineReads = () => {
|
|
922
|
+
offlineOpGenRef.current++;
|
|
923
|
+
};
|
|
924
|
+
useEffect(() => {
|
|
925
|
+
// Private hub channel; inert while offline is off.
|
|
926
|
+
const hub = OfflineHub.getInstance();
|
|
927
|
+
const subscriptions = [
|
|
928
|
+
hub.conversationSync$.subscribe((e) => offlineHandlersRef.current.onConversationSync(e.conversations, e.gen)),
|
|
929
|
+
hub.session$.subscribe(() => offlineHandlersRef.current.onSessionEnded()),
|
|
930
|
+
hub.cacheReset$.subscribe(() => offlineHandlersRef.current.onCacheReset()),
|
|
931
|
+
];
|
|
932
|
+
return () => {
|
|
933
|
+
subscriptions.forEach((s) => s.unsubscribe());
|
|
934
|
+
stopOfflineReads(); // an offline read-on loop in flight stops at unmount
|
|
935
|
+
if (offlineSearchTimer.current) clearTimeout(offlineSearchTimer.current);
|
|
936
|
+
};
|
|
937
|
+
}, []);
|
|
938
|
+
|
|
534
939
|
/**
|
|
535
940
|
* Reloads the list by fetching fresh data (matches Calls tab behavior)
|
|
536
941
|
*/
|
|
@@ -539,6 +944,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
539
944
|
if (isLoadingMore) return;
|
|
540
945
|
|
|
541
946
|
setDataLoadingStatus(LOADING);
|
|
947
|
+
errorViewRef.current = null;
|
|
948
|
+
setOfflineState("none");
|
|
542
949
|
setHasMoreData(true);
|
|
543
950
|
if (requestBuilder) {
|
|
544
951
|
if (searchInputRef.current)
|
|
@@ -644,6 +1051,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
644
1051
|
}
|
|
645
1052
|
return (
|
|
646
1053
|
<CometChatListItem
|
|
1054
|
+
testID={itemTestID?.(item.value)}
|
|
647
1055
|
statusIndicatorType={statusIndicatorType ? statusIndicatorType(item.value) : null}
|
|
648
1056
|
id={item.value[listItemKey]}
|
|
649
1057
|
avatarName={item.value.name}
|
|
@@ -687,6 +1095,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
687
1095
|
},
|
|
688
1096
|
[
|
|
689
1097
|
listItemKey,
|
|
1098
|
+
itemTestID,
|
|
690
1099
|
selectedItems,
|
|
691
1100
|
shouldSelect,
|
|
692
1101
|
listStyle,
|
|
@@ -735,7 +1144,30 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
735
1144
|
*/
|
|
736
1145
|
const getMessageContainer = useCallback(() => {
|
|
737
1146
|
let messageContainer: JSX.Element = <></>;
|
|
738
|
-
|
|
1147
|
+
// D84: the kit's offline states sit in the error / empty view's place, in the host list's error-state style.
|
|
1148
|
+
const connectState = (title: string, testID: string, subtitle?: string) => (
|
|
1149
|
+
<ConnectStateView
|
|
1150
|
+
testID={testID}
|
|
1151
|
+
title={title}
|
|
1152
|
+
subtitle={subtitle}
|
|
1153
|
+
containerStyle={listStyle?.errorStateStyle?.containerStyle}
|
|
1154
|
+
titleStyle={listStyle?.errorStateStyle?.titleStyle}
|
|
1155
|
+
subtitleStyle={listStyle?.errorStateStyle?.subTitleStyle}
|
|
1156
|
+
/>
|
|
1157
|
+
);
|
|
1158
|
+
if (
|
|
1159
|
+
list.length === 0 &&
|
|
1160
|
+
dataLoadingStatus.toLowerCase() === NO_DATA_FOUND &&
|
|
1161
|
+
offlineState === "search" &&
|
|
1162
|
+
!(customEmptyView ?? !!EmptyView)
|
|
1163
|
+
) {
|
|
1164
|
+
// D84 rule 7 + addition A: an offline keyword search with nothing saved.
|
|
1165
|
+
messageContainer = connectState(
|
|
1166
|
+
t(OFFLINE_STRING_KEYS.connectToSearch),
|
|
1167
|
+
CONTRACT_IDS.emptyConnectToSearch,
|
|
1168
|
+
t(OFFLINE_STRING_KEYS.connectToSearchSubtitle)
|
|
1169
|
+
);
|
|
1170
|
+
} else if (list.length === 0 && dataLoadingStatus.toLowerCase() === NO_DATA_FOUND) {
|
|
739
1171
|
messageContainer = EmptyView ? (
|
|
740
1172
|
<EmptyView />
|
|
741
1173
|
) : (
|
|
@@ -745,6 +1177,17 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
745
1177
|
</Text>
|
|
746
1178
|
</View>
|
|
747
1179
|
);
|
|
1180
|
+
} else if (
|
|
1181
|
+
!hideError &&
|
|
1182
|
+
dataLoadingStatus.toLowerCase() === SOMETHING_WRONG &&
|
|
1183
|
+
offlineState === "load" &&
|
|
1184
|
+
!(customErrorView ?? !!ErrorView)
|
|
1185
|
+
) {
|
|
1186
|
+
// D84 rule 3: offline with nothing on screen: "Connect to load ...", no Retry.
|
|
1187
|
+
messageContainer = connectState(
|
|
1188
|
+
t(connectToLoadKey ?? connectToLoadKeyFor(listItemKey)),
|
|
1189
|
+
CONTRACT_IDS.emptyConnectToLoad
|
|
1190
|
+
);
|
|
748
1191
|
} else if (!hideError && dataLoadingStatus.toLowerCase() === SOMETHING_WRONG) {
|
|
749
1192
|
messageContainer = ErrorView ? (
|
|
750
1193
|
<ErrorView />
|
|
@@ -807,7 +1250,25 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
807
1250
|
}
|
|
808
1251
|
}}
|
|
809
1252
|
showsVerticalScrollIndicator={false}
|
|
810
|
-
ListFooterComponent={
|
|
1253
|
+
ListFooterComponent={
|
|
1254
|
+
offlineFooter === "connect"
|
|
1255
|
+
? () => (
|
|
1256
|
+
<ConnectToLoadMore
|
|
1257
|
+
t={t}
|
|
1258
|
+
onRetry={retryOfflinePage}
|
|
1259
|
+
textColor={theme.color.textSecondary as string}
|
|
1260
|
+
containerStyle={theme.messageListStyles?.offlineStyles?.footerStyle?.containerStyle}
|
|
1261
|
+
textStyle={theme.messageListStyles?.offlineStyles?.footerStyle?.textStyle}
|
|
1262
|
+
/>
|
|
1263
|
+
)
|
|
1264
|
+
: renderFooter
|
|
1265
|
+
}
|
|
1266
|
+
refreshControl={
|
|
1267
|
+
// Offline ON only: pull-to-refresh asks the SDK for a sweep (conversations).
|
|
1268
|
+
listItemKey === "conversationId" && isOfflineOn() ? (
|
|
1269
|
+
<RefreshControl refreshing={refreshing} onRefresh={onPullToRefresh} />
|
|
1270
|
+
) : undefined
|
|
1271
|
+
}
|
|
811
1272
|
keyboardShouldPersistTaps='always'
|
|
812
1273
|
keyboardDismissMode={Platform.OS === 'ios' ? 'on-drag' : 'none'}
|
|
813
1274
|
/>
|
|
@@ -817,7 +1278,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
817
1278
|
}
|
|
818
1279
|
|
|
819
1280
|
return messageContainer;
|
|
820
|
-
}, [list, selectedItems, theme, dataLoadingStatus, isLoadingMore, hasMoreData, shouldSelect]);
|
|
1281
|
+
}, [list, selectedItems, theme, dataLoadingStatus, isLoadingMore, hasMoreData, shouldSelect, offlineFooter, offlineState, refreshing]);
|
|
821
1282
|
|
|
822
1283
|
|
|
823
1284
|
return (
|