@cometchat/chat-uikit-react-native 5.5.4 → 5.7.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/CometChatKeyboardModule.kt +101 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
- 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/CometChatKeyboardModule.m +9 -0
- package/ios/CometChatKeyboardModule.swift +71 -0
- package/ios/FileManager.m +70 -6
- package/ios/KeyboardLanguageDirection.swift +24 -0
- package/ios/RichTextEditorView.swift +253 -51
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
- package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
- package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +145 -63
- package/src/CometChatCompactMessageComposer/styles.ts +7 -7
- package/src/CometChatConversations/CometChatConversations.tsx +276 -147
- package/src/CometChatConversations/Skeleton.tsx +4 -1
- package/src/CometChatConversations/style.ts +1 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +39 -18
- package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
- package/src/CometChatGroupMembers/style.ts +6 -4
- package/src/CometChatGroups/CometChatGroups.tsx +74 -58
- package/src/CometChatGroups/GroupsStyle.ts +1 -1
- package/src/CometChatGroups/Skeleton.tsx +4 -1
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +190 -96
- package/src/CometChatMessageComposer/styles.tsx +1 -1
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +28 -15
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
- package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +1465 -313
- package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
- package/src/CometChatMessageList/style.ts +32 -32
- package/src/CometChatMessageList/swipeToReply.ts +25 -0
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +81 -10
- package/src/CometChatNotificationFeed/style.ts +1 -1
- package/src/CometChatNotificationFeed/utils.ts +17 -18
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +82 -3
- package/src/CometChatPinnedMessages/style.ts +5 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
- package/src/CometChatRichTextEditor/index.tsx +3 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +83 -15
- package/src/CometChatSavedMessages/style.ts +3 -3
- package/src/CometChatSearch/CometChatSearch.tsx +391 -136
- package/src/CometChatSearch/Skeleton.tsx +4 -1
- package/src/CometChatSearch/searchLabels.ts +26 -0
- package/src/CometChatSearch/style.ts +7 -7
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +34 -8
- package/src/CometChatThreadHeader/Header.tsx +2 -2
- package/src/CometChatUsers/CometChatUsers.tsx +10 -1
- package/src/CometChatUsers/Skeleton.tsx +4 -1
- package/src/CometChatUsers/style.ts +1 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +27 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
- package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
- package/src/extensions/CollaborativeBubble/style.ts +4 -4
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
- package/src/extensions/LinkPreview/style.ts +6 -6
- package/src/extensions/Polls/Header.tsx +1 -1
- package/src/extensions/Polls/Polls.tsx +25 -12
- package/src/extensions/Polls/PollsBubble.tsx +10 -6
- package/src/extensions/Polls/style.ts +4 -4
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
- package/src/index.ts +11 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +102 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +28 -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 +18 -13
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
- package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
- package/src/shared/framework/MessageDataSource.tsx +51 -108
- package/src/shared/helper/LocalizedDateHelper.ts +64 -4
- package/src/shared/helper/helperFunctions.ts +71 -4
- package/src/shared/helper/keyboardDirection.ts +54 -0
- package/src/shared/helper/layoutDirection.ts +205 -0
- package/src/shared/helper/pluralRules.ts +67 -0
- package/src/shared/helper/textDirection.ts +118 -0
- package/src/shared/icons/Icon.tsx +37 -2
- package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
- 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 +222 -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 +84 -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/CometChatLocalizationHelper.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +82 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +90 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +74 -3
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/MessageUtils.tsx +14 -14
- package/src/shared/utils/PermissionUtil.ts +16 -5
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/attachmentLimits.ts +3 -2
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/conversationUtils.ts +3 -5
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/fileIconFontSize.ts +10 -0
- package/src/shared/utils/fileSizeLabel.ts +16 -0
- package/src/shared/utils/groupActionText.ts +75 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +45 -12
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +20 -8
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
- package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
- package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
- package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +65 -15
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +56 -25
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
- package/src/shared/views/CometChatList/CometChatList.tsx +478 -21
- package/src/shared/views/CometChatList/Header.tsx +5 -2
- package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
- package/src/shared/views/CometChatList/styles.ts +7 -7
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
- package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +43 -16
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +19 -2
- package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +59 -12
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
- package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
- package/src/shared/views/CometChatReportDialog/style.ts +1 -1
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
- package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
- package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
- package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +58 -24
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/shared/views/SenderLabel.tsx +41 -0
- package/src/theme/default/default.ts +1 -1
- 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
|
@@ -0,0 +1,296 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pure list operations for the offline (ON) path (README §3.3): sorted upsert by identity, the
|
|
3
|
+
* windowed reconcile of a server page against the cached page it replaces, and the held-receipt
|
|
4
|
+
* map. Nothing here runs with offline off.
|
|
5
|
+
*
|
|
6
|
+
* Order (ascending): sent rows by `(sentAt, id)`; own rows without a server id last, by compose
|
|
7
|
+
* order (BEH-READ-10). A row without a server id is never removed by a read (BEH-READ-30). The RN
|
|
8
|
+
* message list keeps its rows newest-first; the `*Desc` wrappers adapt to that orientation.
|
|
9
|
+
*
|
|
10
|
+
* Stream rows (agent replies being streamed) borrow their user message's id, so they are never
|
|
11
|
+
* matched, moved or removed by these operations.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
import { categoryOf, localIdOf, muidOf, rowKey, serverIdOf } from "./identity";
|
|
16
|
+
|
|
17
|
+
/** The not-connected terminal of an offline read or send (RN: `FAILED_TO_FETCH`). */
|
|
18
|
+
export function isNotConnectedError(error: unknown): boolean {
|
|
19
|
+
const code = (error as any)?.code ?? (error as any)?.name;
|
|
20
|
+
return (
|
|
21
|
+
code === "FAILED_TO_FETCH" ||
|
|
22
|
+
code === "ERROR_INTERNET_UNAVAILABLE" ||
|
|
23
|
+
code === "NO_WEBSOCKET_CONNECTION" ||
|
|
24
|
+
code === "NOT_CONNECTED"
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function isStream(message: any): boolean {
|
|
29
|
+
return !!message?.isStreamMessage || categoryOf(message) === "stream";
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
function numberOf(value: unknown): number {
|
|
33
|
+
const n = Number(value);
|
|
34
|
+
return Number.isFinite(n) ? n : 0;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
function sentAtOf(message: any): number {
|
|
38
|
+
return numberOf(message?.getSentAt?.() ?? message?.sentAt);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function updatedAtOf(message: any): number {
|
|
42
|
+
return numberOf(message?.getUpdatedAt?.() ?? message?.updatedAt);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/** Rows that sort after every sent row: own messages the server has not acked. */
|
|
46
|
+
function inUnsentBucket(message: any): boolean {
|
|
47
|
+
if (serverIdOf(message) > 0 || isStream(message)) return false;
|
|
48
|
+
const category = categoryOf(message);
|
|
49
|
+
return category !== "action" && category !== "call";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/** Ascending comparator: sent rows by (sentAt, id), then unsent rows by compose time. */
|
|
53
|
+
export function compareRows(a: any, b: any): number {
|
|
54
|
+
const aUnsent = inUnsentBucket(a);
|
|
55
|
+
const bUnsent = inUnsentBucket(b);
|
|
56
|
+
if (aUnsent !== bUnsent) return aUnsent ? 1 : -1;
|
|
57
|
+
const bySentAt = sentAtOf(a) - sentAtOf(b);
|
|
58
|
+
if (bySentAt !== 0) return bySentAt;
|
|
59
|
+
return serverIdOf(a) - serverIdOf(b);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/** Index of the row that is the same message: server id, then local handle, then own muid. */
|
|
63
|
+
export function findRowIndex(rows: readonly any[], message: any): number {
|
|
64
|
+
if (!message || isStream(message)) return -1;
|
|
65
|
+
const id = serverIdOf(message);
|
|
66
|
+
if (id > 0) {
|
|
67
|
+
const byId = rows.findIndex((row) => !isStream(row) && serverIdOf(row) === id);
|
|
68
|
+
if (byId !== -1) return byId;
|
|
69
|
+
}
|
|
70
|
+
const local = localIdOf(message);
|
|
71
|
+
if (local) {
|
|
72
|
+
const byLocal = rows.findIndex((row) => !isStream(row) && localIdOf(row) === local);
|
|
73
|
+
if (byLocal !== -1) return byLocal;
|
|
74
|
+
}
|
|
75
|
+
const muid = muidOf(message);
|
|
76
|
+
if (muid) {
|
|
77
|
+
const byMuid = rows.findIndex(
|
|
78
|
+
(row) =>
|
|
79
|
+
!isStream(row) &&
|
|
80
|
+
muidOf(row) === muid &&
|
|
81
|
+
(serverIdOf(row) === 0 || id === 0 || serverIdOf(row) === id)
|
|
82
|
+
);
|
|
83
|
+
if (byMuid !== -1) return byMuid;
|
|
84
|
+
}
|
|
85
|
+
return -1;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function sortedIndex(rows: readonly any[], message: any): number {
|
|
89
|
+
let low = 0;
|
|
90
|
+
let high = rows.length;
|
|
91
|
+
while (low < high) {
|
|
92
|
+
const mid = (low + high) >> 1;
|
|
93
|
+
if (compareRows(rows[mid], message) <= 0) low = mid + 1;
|
|
94
|
+
else high = mid;
|
|
95
|
+
}
|
|
96
|
+
return low;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
export interface UpsertResult {
|
|
100
|
+
rows: any[];
|
|
101
|
+
changed: boolean;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
/**
|
|
105
|
+
* Upsert `incoming` into ascending `rows` by identity, each into its sorted place. For the same
|
|
106
|
+
* server id the copy with the newer `updatedAt` wins, so a read never reverts a live edit.
|
|
107
|
+
* Returns a new array when anything changed; untouched rows keep their objects.
|
|
108
|
+
*/
|
|
109
|
+
export function upsertSorted(rows: readonly any[], incoming: readonly any[]): UpsertResult {
|
|
110
|
+
const next = rows.slice();
|
|
111
|
+
let changed = false;
|
|
112
|
+
for (const message of incoming) {
|
|
113
|
+
if (!message || isStream(message)) continue;
|
|
114
|
+
const index = findRowIndex(next, message);
|
|
115
|
+
if (index !== -1) {
|
|
116
|
+
const existing = next[index];
|
|
117
|
+
if (existing === message) continue;
|
|
118
|
+
const sameServerRow = serverIdOf(existing) > 0 && serverIdOf(existing) === serverIdOf(message);
|
|
119
|
+
if (sameServerRow && updatedAtOf(existing) > updatedAtOf(message)) continue;
|
|
120
|
+
next.splice(index, 1);
|
|
121
|
+
next.splice(sortedIndex(next, message), 0, message);
|
|
122
|
+
changed = true;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
next.splice(sortedIndex(next, message), 0, message);
|
|
126
|
+
changed = true;
|
|
127
|
+
}
|
|
128
|
+
return { rows: changed ? next : (rows as any[]), changed };
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The part of `incoming` that is already a row of `rows`. A window anchored on an older message
|
|
133
|
+
* (a jump, start-from-unread) must take a sweep's copies of the rows it shows and nothing else:
|
|
134
|
+
* a newer message inserted past the window's end would leave a hole, and the "load newer" read
|
|
135
|
+
* anchors on the newest row shown, so it would skip everything inside the hole.
|
|
136
|
+
*/
|
|
137
|
+
export function onlyShownRows(rows: readonly any[], incoming: readonly any[]): any[] {
|
|
138
|
+
return incoming.filter((message) => findRowIndex(rows, message) !== -1);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/** Server-id keys of the rows a cached page showed. */
|
|
142
|
+
export function cachedKeysOf(messages: readonly any[]): Set<string> {
|
|
143
|
+
const keys = new Set<string>();
|
|
144
|
+
for (const message of messages) if (serverIdOf(message) > 0) keys.add(rowKey(message));
|
|
145
|
+
return keys;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Apply a server page: upsert it, then remove rows its cached page showed that the server no
|
|
150
|
+
* longer has, but only inside the server page's id range (a proven omission). Rows without a
|
|
151
|
+
* server id, and stream rows, are never removed.
|
|
152
|
+
*/
|
|
153
|
+
export function reconcileServerPage(rows: readonly any[], cachedKeys: ReadonlySet<string>, serverPage: readonly any[]): UpsertResult {
|
|
154
|
+
const upserted = upsertSorted(rows, serverPage);
|
|
155
|
+
const serverIds = serverPage.map(serverIdOf).filter((id) => id > 0);
|
|
156
|
+
if (serverIds.length === 0 || cachedKeys.size === 0) return upserted;
|
|
157
|
+
const minId = Math.min(...serverIds);
|
|
158
|
+
const maxId = Math.max(...serverIds);
|
|
159
|
+
const serverKeys = new Set(serverPage.map(rowKey));
|
|
160
|
+
const kept = upserted.rows.filter((row) => {
|
|
161
|
+
const id = serverIdOf(row);
|
|
162
|
+
if (id === 0 || isStream(row)) return true;
|
|
163
|
+
const key = rowKey(row);
|
|
164
|
+
if (!cachedKeys.has(key) || serverKeys.has(key)) return true;
|
|
165
|
+
return id < minId || id > maxId;
|
|
166
|
+
});
|
|
167
|
+
if (kept.length === upserted.rows.length) return upserted;
|
|
168
|
+
return { rows: kept, changed: true };
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* D13-R2: a cached page is kept only when it joins the server page that answered the same read
|
|
173
|
+
* (the two share a server id). One that does not join is stale: more arrived than one page holds.
|
|
174
|
+
* The rows it painted beyond the server page's far end (older for `previous`, newer for `next`)
|
|
175
|
+
* are dropped, not stitched to it over a hidden gap; the next page reads them again from the
|
|
176
|
+
* server page's edge. Rows listed before the cached page, rows without a server id, stream rows,
|
|
177
|
+
* and everything when the server page is empty, are never removed. Order-agnostic; returns `rows`
|
|
178
|
+
* itself when nothing is dropped.
|
|
179
|
+
*/
|
|
180
|
+
export function dropUnjoinedCachedPage(
|
|
181
|
+
rows: readonly any[],
|
|
182
|
+
paintedKeys: readonly string[],
|
|
183
|
+
rawCachedKeys: readonly string[],
|
|
184
|
+
serverPage: readonly any[],
|
|
185
|
+
direction: "previous" | "next"
|
|
186
|
+
): any[] {
|
|
187
|
+
const serverIds = serverPage.map(serverIdOf).filter((id) => id > 0);
|
|
188
|
+
if (serverIds.length === 0 || paintedKeys.length === 0) return rows as any[];
|
|
189
|
+
const serverKeys = cachedKeysOf(serverPage);
|
|
190
|
+
if (rawCachedKeys.some((key) => serverKeys.has(key))) return rows as any[];
|
|
191
|
+
const edge = direction === "previous" ? Math.min(...serverIds) : Math.max(...serverIds);
|
|
192
|
+
const painted = new Set(paintedKeys);
|
|
193
|
+
const kept = rows.filter((row) => {
|
|
194
|
+
const id = serverIdOf(row);
|
|
195
|
+
if (id < 1 || isStream(row) || !painted.has(rowKey(row))) return true;
|
|
196
|
+
return direction === "previous" ? id > edge : id < edge;
|
|
197
|
+
});
|
|
198
|
+
return kept.length === rows.length ? (rows as any[]) : kept;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/** Remove the row that is `message`, by identity. */
|
|
202
|
+
export function removeRow(rows: readonly any[], message: any): UpsertResult {
|
|
203
|
+
const index = findRowIndex(rows, message);
|
|
204
|
+
if (index === -1) return { rows: rows as any[], changed: false };
|
|
205
|
+
const next = rows.slice();
|
|
206
|
+
next.splice(index, 1);
|
|
207
|
+
return { rows: next, changed: true };
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
/** Newest server id among `rows` (any order): the newer-direction cursor anchor. */
|
|
211
|
+
export function newestServerId(rows: readonly any[]): number {
|
|
212
|
+
let newest = 0;
|
|
213
|
+
for (const row of rows) if (!isStream(row)) newest = Math.max(newest, serverIdOf(row));
|
|
214
|
+
return newest;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/** Oldest server id among `rows` (any order): the older-direction cursor anchor. */
|
|
218
|
+
export function oldestServerId(rows: readonly any[]): number {
|
|
219
|
+
let oldest = 0;
|
|
220
|
+
for (const row of rows) {
|
|
221
|
+
if (isStream(row)) continue;
|
|
222
|
+
const id = serverIdOf(row);
|
|
223
|
+
if (id > 0 && (oldest === 0 || id < oldest)) oldest = id;
|
|
224
|
+
}
|
|
225
|
+
return oldest;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
// ── Newest-first adapters for the RN message list ───────────────────────────
|
|
229
|
+
|
|
230
|
+
function reversed(rows: readonly any[]): any[] {
|
|
231
|
+
return rows.slice().reverse();
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
function adaptDesc(result: UpsertResult, original: readonly any[]): UpsertResult {
|
|
235
|
+
return result.changed ? { rows: reversed(result.rows), changed: true } : { rows: original as any[], changed: false };
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
export function upsertSortedDesc(rowsDesc: readonly any[], incoming: readonly any[]): UpsertResult {
|
|
239
|
+
return adaptDesc(upsertSorted(reversed(rowsDesc), incoming), rowsDesc);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
export function reconcileServerPageDesc(rowsDesc: readonly any[], cachedKeys: ReadonlySet<string>, serverPage: readonly any[]): UpsertResult {
|
|
243
|
+
return adaptDesc(reconcileServerPage(reversed(rowsDesc), cachedKeys, serverPage), rowsDesc);
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
/** `dropUnjoinedCachedPage` over a reconcile result (either orientation; the order is kept). */
|
|
247
|
+
export function dropUnjoinedCachedPageDesc(
|
|
248
|
+
result: UpsertResult,
|
|
249
|
+
paintedKeys: readonly string[],
|
|
250
|
+
rawCachedKeys: readonly string[],
|
|
251
|
+
serverPage: readonly any[],
|
|
252
|
+
direction: "previous" | "next"
|
|
253
|
+
): UpsertResult {
|
|
254
|
+
const rows = dropUnjoinedCachedPage(result.rows, paintedKeys, rawCachedKeys, serverPage, direction);
|
|
255
|
+
return rows === result.rows ? result : { rows, changed: true };
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
export function removeRowDesc(rowsDesc: readonly any[], message: any): UpsertResult {
|
|
259
|
+
return removeRow(rowsDesc, message);
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
// ── Held receipts (README §3.6) ─────────────────────────────────────────────
|
|
263
|
+
|
|
264
|
+
const MAX_HELD_RECEIPTS = 200;
|
|
265
|
+
|
|
266
|
+
/**
|
|
267
|
+
* Receipts for server ids the list does not show yet (their ack has not landed) are held here and
|
|
268
|
+
* applied when a row acquires that id (BEH-SEND-32). Cleared on `gen` change and after a sweep.
|
|
269
|
+
*/
|
|
270
|
+
export class HeldReceipts {
|
|
271
|
+
private readonly held = new Map<number, any>();
|
|
272
|
+
|
|
273
|
+
hold(messageId: number, receipt: any): void {
|
|
274
|
+
if (!(messageId > 0)) return;
|
|
275
|
+
this.held.delete(messageId);
|
|
276
|
+
this.held.set(messageId, receipt);
|
|
277
|
+
if (this.held.size > MAX_HELD_RECEIPTS) {
|
|
278
|
+
const oldest = this.held.keys().next().value;
|
|
279
|
+
if (oldest !== undefined) this.held.delete(oldest);
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
take(messageId: number): any {
|
|
284
|
+
const receipt = this.held.get(messageId);
|
|
285
|
+
if (receipt) this.held.delete(messageId);
|
|
286
|
+
return receipt;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
clear(): void {
|
|
290
|
+
this.held.clear();
|
|
291
|
+
}
|
|
292
|
+
|
|
293
|
+
get size(): number {
|
|
294
|
+
return this.held.size;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* What the offline (ON) search screen shows when a search ended with nothing on screen and at least one
|
|
3
|
+
* request failed (D84). Mirrors Android's `CometChatSearchViewModel.updateFinalStateIfCompleted`
|
|
4
|
+
* (CometChatSearchViewModel.kt:569-603) and its failure bookkeeping (:880-905):
|
|
5
|
+
*
|
|
6
|
+
* - "Connect to search" when offline is on, nothing is shown, no request failed with a real error
|
|
7
|
+
* (an error other than not-connected), AND (a keyword request failed not-connected, OR both the
|
|
8
|
+
* conversation and the message requests failed).
|
|
9
|
+
* - A filter-only search where only one scope failed is the plain empty state (Android:
|
|
10
|
+
* `SearchUIState.Empty` with `showConnectToSearch` false): no "Connect to search", no `onError`, and
|
|
11
|
+
* no read again on reconnect.
|
|
12
|
+
* - A real failure of ONE scope only (nothing on screen) is the same plain empty state: Android's
|
|
13
|
+
* `bothFailed` is false, so it ends in `SearchUIState.Empty` with no `onError`. Both scopes failing
|
|
14
|
+
* (at least one with a real error) is the error view plus `onError` (the kit's `rule 4`).
|
|
15
|
+
*
|
|
16
|
+
* A request "failed" with not-connected when it ended not-connected past the cache AND (it carried a
|
|
17
|
+
* keyword, which has no cache, OR the SDK gave no cached phase before the error). A filter-only read that
|
|
18
|
+
* got its cached phase first was answered from the device: nothing found, not a failure.
|
|
19
|
+
*
|
|
20
|
+
* @internal
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
/** One scope of the current search (conversations or messages). */
|
|
24
|
+
export interface SearchRead {
|
|
25
|
+
/** The scope took part in this search (it is rendered for the current keyword/filters). */
|
|
26
|
+
ran: boolean;
|
|
27
|
+
/** How its request failed; `null` when it did not fail. */
|
|
28
|
+
failure: null | "notConnected" | "error";
|
|
29
|
+
/** The request carried a keyword (a keyword has no cache). */
|
|
30
|
+
keyword: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export type SearchOfflineOutcome =
|
|
34
|
+
/** The screen's usual states apply (rows, results, loading, no results). */
|
|
35
|
+
| "none"
|
|
36
|
+
/** "Connect to search" (the app's own empty view wins), no `onError`. */
|
|
37
|
+
| "connectToSearch"
|
|
38
|
+
/** The plain empty state (the app's own empty view wins), no `onError`. */
|
|
39
|
+
| "empty"
|
|
40
|
+
/** The error view (the app's own error view wins). */
|
|
41
|
+
| "error";
|
|
42
|
+
|
|
43
|
+
export function searchOfflineOutcome(input: {
|
|
44
|
+
offlineOn: boolean;
|
|
45
|
+
nothingShown: boolean;
|
|
46
|
+
conversations: SearchRead;
|
|
47
|
+
messages: SearchRead;
|
|
48
|
+
}): SearchOfflineOutcome {
|
|
49
|
+
const { offlineOn, nothingShown, conversations, messages } = input;
|
|
50
|
+
if (!offlineOn || !nothingShown) return "none";
|
|
51
|
+
const ran = [conversations, messages].filter((read) => read.ran);
|
|
52
|
+
const failed = ran.filter((read) => read.failure !== null);
|
|
53
|
+
if (failed.length === 0) return "none";
|
|
54
|
+
const bothFailed = conversations.ran && messages.ran && failed.length === 2;
|
|
55
|
+
if (failed.some((read) => read.failure === "error")) {
|
|
56
|
+
// Android: a real failure of one scope only leaves `bothFailed` false and nothing shown: the plain
|
|
57
|
+
// empty state (no onError). Both scopes failing is the error view.
|
|
58
|
+
return bothFailed ? "error" : "empty";
|
|
59
|
+
}
|
|
60
|
+
const keywordFailed = failed.some((read) => read.keyword);
|
|
61
|
+
return keywordFailed || bothFailed ? "connectToSearch" : "empty";
|
|
62
|
+
}
|