@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
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The conversation list's offline (ON) path (README §3.7, UIK-SYNC-04): the reconcile of the
|
|
3
|
+
* SDK's catch-up sync page instead of a refetch on reconnect, and the rows a read never drops.
|
|
4
|
+
* Nothing here runs with offline off.
|
|
5
|
+
*
|
|
6
|
+
* @internal
|
|
7
|
+
*/
|
|
8
|
+
import { isOfflineUnsent, isSyncDelivered, localIdOf, muidOf } from "./identity";
|
|
9
|
+
import { isConversationPinned, tierOf, TIER } from "../utils/PinConversationHelper";
|
|
10
|
+
import { OfflineHub } from "./OfflineHub";
|
|
11
|
+
import { unsentRowInfo } from "./unsentActions";
|
|
12
|
+
|
|
13
|
+
function conversationKey(conversation: any): string {
|
|
14
|
+
const id = conversation?.getConversationId?.() ?? conversation?.conversationId;
|
|
15
|
+
return typeof id === "string" ? id : String(id ?? "");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/** A row whose preview is an own message the server has not acked (BEH-CONV-06). */
|
|
19
|
+
export function hasUnsentPreview(conversation: any): boolean {
|
|
20
|
+
const last = conversation?.getLastMessage?.();
|
|
21
|
+
return !!last && isOfflineUnsent(last);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function updatedAtOf(conversation: any): number {
|
|
25
|
+
const value = Number(
|
|
26
|
+
conversation?.getUpdatedAt?.() ?? conversation?.getLastMessage?.()?.getSentAt?.() ?? 0
|
|
27
|
+
);
|
|
28
|
+
return Number.isFinite(value) ? value : 0;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function previewSentAt(conversation: any): number {
|
|
32
|
+
const value = Number(conversation?.getLastMessage?.()?.getSentAt?.() ?? 0);
|
|
33
|
+
return Number.isFinite(value) ? value : 0;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function pinnedAtOf(conversation: any): number {
|
|
37
|
+
const value = Number(conversation?.getPinnedAt?.());
|
|
38
|
+
return Number.isFinite(value) ? value : -1;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* The list's one ordering rule (the same as `conversationInsertIndex`): system pins, then the
|
|
43
|
+
* user's pins, newest pin first, then every other chat by recency. A sync page carries the pins
|
|
44
|
+
* the sweep learned (another device, an admin), so its reconcile must keep the pinned block on top.
|
|
45
|
+
*/
|
|
46
|
+
function compareRows(a: any, b: any): number {
|
|
47
|
+
const tierA = tierOf(a);
|
|
48
|
+
const tierB = tierOf(b);
|
|
49
|
+
if (tierA !== tierB) return tierA - tierB;
|
|
50
|
+
if (tierA !== TIER.UNPINNED) return pinnedAtOf(b) - pinnedAtOf(a);
|
|
51
|
+
return updatedAtOf(b) - updatedAtOf(a);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
function dedupe(list: any[]): any[] {
|
|
55
|
+
const seen = new Set<string>();
|
|
56
|
+
return list.filter((c) => {
|
|
57
|
+
const key = conversationKey(c);
|
|
58
|
+
if (seen.has(key)) return false;
|
|
59
|
+
seen.add(key);
|
|
60
|
+
return true;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Nothing moves backwards: a server copy older than the row's own unsent preview does not replace
|
|
66
|
+
* it. The row's own timestamp does not move for a pending preview, so the messages decide too.
|
|
67
|
+
*/
|
|
68
|
+
function keepsUnsentPreview(existing: any, incoming: any): boolean {
|
|
69
|
+
if (!hasUnsentPreview(existing)) return false;
|
|
70
|
+
// A preview restored from the store has no sent time until its ack: it is the newest there is.
|
|
71
|
+
const sentAt = previewSentAt(existing);
|
|
72
|
+
return !sentAt || updatedAtOf(existing) >= updatedAtOf(incoming) || sentAt >= previewSentAt(incoming);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Reconcile the slice one sync page covers on the plain, unfiltered list: rows in the page are
|
|
77
|
+
* replaced or added; rows inside the page's range that the page no longer has are removed, unless
|
|
78
|
+
* their preview is an own unsent message; rows below the page are kept; nothing moves backwards
|
|
79
|
+
* (an own unsent preview newer than the server's copy wins).
|
|
80
|
+
*/
|
|
81
|
+
export function reconcileSyncPage(current: readonly any[], page: readonly any[]): any[] {
|
|
82
|
+
if (page.length === 0) return current as any[];
|
|
83
|
+
const pageIds = new Set(page.map(conversationKey));
|
|
84
|
+
// The server floats pinned rows to the top of the page whatever their age, so they never set
|
|
85
|
+
// the page's floor (BEH-SYNC-15); a page of pins only reconciles nothing below them.
|
|
86
|
+
const ranked = page.filter((c) => !isConversationPinned(c));
|
|
87
|
+
const oldestInPage = ranked.length > 0 ? Math.min(...ranked.map(updatedAtOf)) : Infinity;
|
|
88
|
+
const byId = new Map(current.map((c) => [conversationKey(c), c] as const));
|
|
89
|
+
const merged = page.map((incoming) => {
|
|
90
|
+
const existing = byId.get(conversationKey(incoming));
|
|
91
|
+
return existing && keepsUnsentPreview(existing, incoming) ? existing : incoming;
|
|
92
|
+
});
|
|
93
|
+
const rest = current.filter((c) => {
|
|
94
|
+
if (pageIds.has(conversationKey(c))) return false;
|
|
95
|
+
if (hasUnsentPreview(c)) return true;
|
|
96
|
+
return updatedAtOf(c) < oldestInPage;
|
|
97
|
+
});
|
|
98
|
+
return dedupe([...merged, ...rest].sort(compareRows));
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The first server page of a two-phase conversation read replaces the cached first page; a row
|
|
103
|
+
* the page no longer has is dropped, except one whose preview is an own unsent message, and such a
|
|
104
|
+
* preview is not replaced by an older server copy.
|
|
105
|
+
*/
|
|
106
|
+
export function applyFirstServerPage(current: readonly any[], page: readonly any[]): any[] {
|
|
107
|
+
const pageIds = new Set(page.map(conversationKey));
|
|
108
|
+
const keptUnsent = current.filter((c) => !pageIds.has(conversationKey(c)) && hasUnsentPreview(c));
|
|
109
|
+
const byId = new Map(current.map((c) => [conversationKey(c), c] as const));
|
|
110
|
+
const merged = page.map((incoming) => {
|
|
111
|
+
const existing = byId.get(conversationKey(incoming));
|
|
112
|
+
return existing && keepsUnsentPreview(existing, incoming) ? existing : incoming;
|
|
113
|
+
});
|
|
114
|
+
return dedupe([...keptUnsent, ...merged]);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
/** Oldest-to-newest order of two rows by (when it last changed, id). */
|
|
118
|
+
function compareByRange(a: any, b: any): number {
|
|
119
|
+
const byTime = updatedAtOf(a) - updatedAtOf(b);
|
|
120
|
+
if (byTime !== 0) return byTime;
|
|
121
|
+
const x = conversationKey(a);
|
|
122
|
+
const y = conversationKey(b);
|
|
123
|
+
return x < y ? -1 : x > y ? 1 : 0;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/** The cached page of a merging first-page read: new rows join the rows shown, shown copies stay. */
|
|
127
|
+
export function mergeCachedFirstPage(current: readonly any[], page: readonly any[]): any[] {
|
|
128
|
+
return dedupe([...current, ...page].sort(compareRows));
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* The server page of a narrowed list's re-read (the kit's own resync after a sync page), merged
|
|
133
|
+
* into the rows shown: the page's rows are upserted; a row is dropped only if this read's cached
|
|
134
|
+
* phase delivered it, it lies inside the page's (last change, id) range and the page lacks it
|
|
135
|
+
* (and its preview is not an own unsent message). Rows the user paged in below stay. A page with
|
|
136
|
+
* no rows proves nothing gone and changes nothing (D17).
|
|
137
|
+
*/
|
|
138
|
+
export function mergeFirstServerPage(
|
|
139
|
+
current: readonly any[],
|
|
140
|
+
cachedIds: ReadonlySet<string>,
|
|
141
|
+
page: readonly any[]
|
|
142
|
+
): any[] {
|
|
143
|
+
if (page.length === 0) return current as any[];
|
|
144
|
+
const pageIds = new Set(page.map(conversationKey));
|
|
145
|
+
// Pinned rows float to the top of the page whatever their age: they never set its range.
|
|
146
|
+
const ranked = page.filter((c) => !isConversationPinned(c));
|
|
147
|
+
let low: any = ranked[0];
|
|
148
|
+
let high: any = ranked[0];
|
|
149
|
+
for (const row of ranked) {
|
|
150
|
+
if (compareByRange(row, low) < 0) low = row;
|
|
151
|
+
if (compareByRange(row, high) > 0) high = row;
|
|
152
|
+
}
|
|
153
|
+
const byId = new Map(current.map((c) => [conversationKey(c), c] as const));
|
|
154
|
+
const upserted = page.map((incoming) => {
|
|
155
|
+
const existing = byId.get(conversationKey(incoming));
|
|
156
|
+
return existing && keepsUnsentPreview(existing, incoming) ? existing : incoming;
|
|
157
|
+
});
|
|
158
|
+
const kept = current.filter((row) => {
|
|
159
|
+
if (pageIds.has(conversationKey(row))) return false;
|
|
160
|
+
if (!cachedIds.has(conversationKey(row)) || hasUnsentPreview(row)) return true;
|
|
161
|
+
// A page of pins only has no range: nothing is proven gone.
|
|
162
|
+
if (!low) return true;
|
|
163
|
+
return compareByRange(row, low) < 0 || compareByRange(row, high) > 0;
|
|
164
|
+
});
|
|
165
|
+
return dedupe([...upserted, ...kept].sort(compareRows));
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
/** A later page, merged by key: as above, an older server copy does not replace an unsent preview. */
|
|
169
|
+
export function keepUnsentPreviews(current: readonly any[], next: any[]): any[] {
|
|
170
|
+
const byId = new Map(current.map((c) => [conversationKey(c), c] as const));
|
|
171
|
+
return next.map((row) => {
|
|
172
|
+
const existing = byId.get(conversationKey(row));
|
|
173
|
+
return existing && keepsUnsentPreview(existing, row) ? existing : row;
|
|
174
|
+
});
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export { conversationKey };
|
|
178
|
+
|
|
179
|
+
const FILTER_FIELDS = [
|
|
180
|
+
"conversationType",
|
|
181
|
+
"searchKeyword",
|
|
182
|
+
"tags",
|
|
183
|
+
"groupTags",
|
|
184
|
+
"userTags",
|
|
185
|
+
"unreadOnly",
|
|
186
|
+
"unread",
|
|
187
|
+
"pinnedBy",
|
|
188
|
+
"onlyAgentic",
|
|
189
|
+
"hideAgentic",
|
|
190
|
+
];
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Whether a conversations request (or its builder) narrows the list (type, tags, search,
|
|
194
|
+
* unread-only, pinnedBy, agentic). Such a list does not reconcile the sync page, which covers the
|
|
195
|
+
* plain list (Android finding F2); it re-runs its own request once instead.
|
|
196
|
+
*/
|
|
197
|
+
export function isFilteredConversationRequest(requestOrBuilder: any): boolean {
|
|
198
|
+
if (!requestOrBuilder) return false;
|
|
199
|
+
for (const field of FILTER_FIELDS) {
|
|
200
|
+
const value = requestOrBuilder[field];
|
|
201
|
+
if (Array.isArray(value) ? value.length > 0 : value !== undefined && value !== null && value !== false && value !== "") {
|
|
202
|
+
return true;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
export interface IncomingMessageRoute {
|
|
209
|
+
/** The list's own filter (`shouldUpdateLastMessageAndUnreadCount`). */
|
|
210
|
+
accepts(message: any): boolean;
|
|
211
|
+
/** Swept (SYNC) message: preview only, no sound, no unread +1, no delivered receipt. */
|
|
212
|
+
previewOnly(message: any): void;
|
|
213
|
+
/** Live message: today's handling (receipt, preview, unread +1, sound). */
|
|
214
|
+
live(message: any): void;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* One incoming message on the conversation list, whatever its category (text, media, custom,
|
|
219
|
+
* form, card, scheduler, custom-interactive, AI assistant). A message the SDK's catch-up sweep
|
|
220
|
+
* delivered (`getSource() === "SYNC"`, offline ON only) is already counted in the synced
|
|
221
|
+
* conversation's unread count, so it updates the preview only (UIK-SYNC-02, UIT-CONV-09). With
|
|
222
|
+
* offline off no message is SYNC, so every message takes today's live path.
|
|
223
|
+
*/
|
|
224
|
+
export function routeIncomingMessage(message: any, route: IncomingMessageRoute): void {
|
|
225
|
+
if (!route.accepts(message)) return;
|
|
226
|
+
if (isSyncDelivered(message)) {
|
|
227
|
+
route.previewOnly(message);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
route.live(message);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
export interface DiscardPreviewDeps {
|
|
234
|
+
rows(): readonly any[];
|
|
235
|
+
/** Two-phase single read (cached copy offline). Resolves `null` when the chat is gone. */
|
|
236
|
+
fetchConversation(conversationWith: string, type: string): Promise<any | null>;
|
|
237
|
+
update(row: any): void;
|
|
238
|
+
remove(conversationId: string): void;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
function sameOwnMessage(a: any, b: any): boolean {
|
|
242
|
+
const localA = localIdOf(a);
|
|
243
|
+
if (localA && localA === localIdOf(b)) return true;
|
|
244
|
+
const muidA = muidOf(a);
|
|
245
|
+
return !!muidA && muidA === muidOf(b);
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
function withOf(conversation: any): { id: string; type: string } | null {
|
|
249
|
+
const type = conversation?.getConversationType?.() ?? conversation?.conversationType;
|
|
250
|
+
const entity = conversation?.getConversationWith?.();
|
|
251
|
+
const id = type === "group" ? entity?.getGuid?.() : entity?.getUid?.();
|
|
252
|
+
return typeof id === "string" && id && typeof type === "string" ? { id, type } : null;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
/**
|
|
256
|
+
* A user deleted an unsent message (BEH-SEND-36): the SDK moved that chat's preview back to its
|
|
257
|
+
* newest remaining message, or removed a chat that only existed because of local sends. When the
|
|
258
|
+
* row on screen shows the deleted message as its preview, re-read the chat (two-phase, so it works
|
|
259
|
+
* offline) and show the SDK's answer; a chat that is gone is removed. Other rows are untouched.
|
|
260
|
+
*/
|
|
261
|
+
export async function refreshPreviewAfterDiscard(message: any, deps: DiscardPreviewDeps): Promise<void> {
|
|
262
|
+
if (!message) return;
|
|
263
|
+
const row = deps.rows().find((c) => {
|
|
264
|
+
const last = c?.getLastMessage?.();
|
|
265
|
+
return !!last && sameOwnMessage(last, message);
|
|
266
|
+
});
|
|
267
|
+
if (!row) return;
|
|
268
|
+
const target = withOf(row);
|
|
269
|
+
if (!target) return;
|
|
270
|
+
let fresh: any | null = null;
|
|
271
|
+
try {
|
|
272
|
+
fresh = await deps.fetchConversation(target.id, target.type);
|
|
273
|
+
} catch {
|
|
274
|
+
return; // not answerable now: keep the row; the next sync heals it
|
|
275
|
+
}
|
|
276
|
+
if (fresh) deps.update(fresh);
|
|
277
|
+
else deps.remove(conversationKey(row));
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Kill switch (UIK-LIFE-03): offline turned off with own unsent previews on the chat list, and no
|
|
282
|
+
* open chat may be there to find them. They turn failed (direct), as the open chat's rows do, and
|
|
283
|
+
* are remembered in `stranded`: a reconnect with offline off refetches the list, and the server has
|
|
284
|
+
* never heard of them. Returns how many this call turned failed; a preview an open chat already
|
|
285
|
+
* reported is not counted again.
|
|
286
|
+
*/
|
|
287
|
+
export function failStrandedPreviews(rows: readonly any[], stranded: Map<string, any>, hub: OfflineHub = OfflineHub.getInstance()): number {
|
|
288
|
+
let count = 0;
|
|
289
|
+
for (const row of rows) {
|
|
290
|
+
const last = row?.getLastMessage?.();
|
|
291
|
+
const info = last ? unsentRowInfo(last, hub) : null;
|
|
292
|
+
if (!info) continue;
|
|
293
|
+
const key = conversationKey(row);
|
|
294
|
+
if (info.direct || info.state === "failed") {
|
|
295
|
+
if (info.direct) stranded.set(key, last);
|
|
296
|
+
continue;
|
|
297
|
+
}
|
|
298
|
+
stranded.set(key, last);
|
|
299
|
+
if (hub.reportFailure(last, "", { direct: true })) count++;
|
|
300
|
+
}
|
|
301
|
+
return count;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/** Forget a stranded preview once it was sent or deleted. */
|
|
305
|
+
export function forgetStrandedPreview(stranded: Map<string, any>, message: any): void {
|
|
306
|
+
for (const [key, last] of stranded) {
|
|
307
|
+
if (sameOwnMessage(last, message)) stranded.delete(key);
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
/**
|
|
312
|
+
* The stranded previews a fresh list page no longer shows: a chat the page has with an older last
|
|
313
|
+
* message, or does not have at all (a chat started offline). Newer messages keep their row.
|
|
314
|
+
*/
|
|
315
|
+
export function strandedPreviewsToRestore(rows: readonly any[], stranded: Map<string, any>): any[] {
|
|
316
|
+
const out: any[] = [];
|
|
317
|
+
for (const [key, message] of stranded) {
|
|
318
|
+
const row = rows.find((c) => conversationKey(c) === key);
|
|
319
|
+
const last = row?.getLastMessage?.();
|
|
320
|
+
if (last && sameOwnMessage(last, message)) continue;
|
|
321
|
+
if (last && Number(last.getSentAt?.() ?? 0) > Number(message?.getSentAt?.() ?? 0)) continue;
|
|
322
|
+
out.push(message);
|
|
323
|
+
}
|
|
324
|
+
return out;
|
|
325
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Frame probe (TEST-PLAN §3.3): on every committed render of a list, hand the row list to a probe
|
|
3
|
+
* the sample app installed (`globalThis.__ccFrameProbe`), so a runner can assert "no duplicate key,
|
|
4
|
+
* no flash, no blank" across frames, not just on the final screen.
|
|
5
|
+
*
|
|
6
|
+
* Dev and sample builds only. `__DEV__` is a constant in release bundles, so the body and the global
|
|
7
|
+
* name are folded out of them (`scripts/probe-strip-check.sh` proves it). Nothing here runs unless a
|
|
8
|
+
* probe was installed, and nothing is installed by the kit.
|
|
9
|
+
*
|
|
10
|
+
* @internal
|
|
11
|
+
*/
|
|
12
|
+
export interface FrameRow {
|
|
13
|
+
key: string;
|
|
14
|
+
id: number;
|
|
15
|
+
state: string;
|
|
16
|
+
/** The row's own object, for a runner that needs to label it. Never logged or stored by the kit. */
|
|
17
|
+
item: unknown;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function probeFrame(list: string, rows: () => FrameRow[]): void {
|
|
21
|
+
if (!__DEV__) return;
|
|
22
|
+
const probe = (globalThis as any).__ccFrameProbe;
|
|
23
|
+
if (typeof probe === "function") probe(list, rows());
|
|
24
|
+
}
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OfflineGate: the one place the kit asks the Chat SDK whether offline support is on
|
|
3
|
+
* (README §3.1, UIK-GATE-01).
|
|
4
|
+
*
|
|
5
|
+
* Every offline-dependent decision calls {@link isOfflineOn} once, at the moment of the decision
|
|
6
|
+
* (one fetch, one send, one reconnect event, one Retry tap), and passes the answer down that
|
|
7
|
+
* operation. Nothing stores it: the SDK can switch offline off mid-session (kill switch) or on at
|
|
8
|
+
* the next login, and the next operation must see the new value.
|
|
9
|
+
*
|
|
10
|
+
* The kit ships TypeScript source that customers type-check against whatever SDK they pinned
|
|
11
|
+
* (`"main": "src/index"`, SDK peer `"*"`), and SDKs before the offline release have none of these
|
|
12
|
+
* members. So every offline SDK member is reached through the untyped {@link offlineSdk} accessor
|
|
13
|
+
* and feature-detected; on an SDK without them `isOfflineOn()` answers `false` and the kit runs
|
|
14
|
+
* today's code.
|
|
15
|
+
*
|
|
16
|
+
* @internal
|
|
17
|
+
*/
|
|
18
|
+
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
19
|
+
|
|
20
|
+
/** Untyped view of the SDK's static surface (never name an offline SDK type in kit source). */
|
|
21
|
+
export function offlineSdk(): any {
|
|
22
|
+
return CometChat as any;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Whether the installed SDK has a static function called `name`. */
|
|
26
|
+
export function hasSdkFunction(name: string): boolean {
|
|
27
|
+
try {
|
|
28
|
+
return typeof offlineSdk()?.[name] === "function";
|
|
29
|
+
} catch {
|
|
30
|
+
return false;
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* Whether the installed SDK is one the kit runs offline on: Chat SDK 4.2.1 or later.
|
|
36
|
+
*
|
|
37
|
+
* Published 4.2.0 already has `isOfflineEnabled` and the rest of the offline surface, so
|
|
38
|
+
* feature-detecting that alone would run offline fully on against it, without the 4.2.1 fixes
|
|
39
|
+
* the kit relies on. The floor therefore also needs `OfflineCacheResetReason.SCHEMA_RESET`,
|
|
40
|
+
* which first ships in 4.2.1. On an older SDK the kit runs online only, as with 4.1.x.
|
|
41
|
+
*/
|
|
42
|
+
export function hasOfflineSdk(): boolean {
|
|
43
|
+
try {
|
|
44
|
+
const sdk = offlineSdk();
|
|
45
|
+
return (
|
|
46
|
+
typeof sdk?.isOfflineEnabled === "function" &&
|
|
47
|
+
sdk?.OfflineCacheResetReason?.SCHEMA_RESET === "SCHEMA_RESET"
|
|
48
|
+
);
|
|
49
|
+
} catch {
|
|
50
|
+
return false;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* `CometChat.isOfflineEnabled()`; `false` when the SDK is older than the offline floor
|
|
56
|
+
* ({@link hasOfflineSdk}), has no such method, or the call throws.
|
|
57
|
+
*/
|
|
58
|
+
export function isOfflineOn(): boolean {
|
|
59
|
+
try {
|
|
60
|
+
if (!hasOfflineSdk()) return false;
|
|
61
|
+
return offlineSdk().isOfflineEnabled() === true;
|
|
62
|
+
} catch {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** `CometChat.getMediaCachingMode()`, or `"OFF"` when unknown. */
|
|
68
|
+
export function mediaCachingMode(): string {
|
|
69
|
+
try {
|
|
70
|
+
const sdk = offlineSdk();
|
|
71
|
+
if (typeof sdk?.getMediaCachingMode !== "function") return "OFF";
|
|
72
|
+
const mode = sdk.getMediaCachingMode();
|
|
73
|
+
return typeof mode === "string" ? mode : "OFF";
|
|
74
|
+
} catch {
|
|
75
|
+
return "OFF";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
/**
|
|
80
|
+
* Whether the SDK's realtime connection is up: `true` / `false` from
|
|
81
|
+
* `CometChat.getConnectionStatus()` (`"connected"` or not), `undefined` when the SDK does not say.
|
|
82
|
+
* Used only on the offline path, to know a pending callback is the only answer a send will get
|
|
83
|
+
* for now (a send queued behind an earlier unsent message in its chat, SDK R77).
|
|
84
|
+
*/
|
|
85
|
+
export function sdkConnected(): boolean | undefined {
|
|
86
|
+
try {
|
|
87
|
+
const sdk = offlineSdk();
|
|
88
|
+
if (typeof sdk?.getConnectionStatus !== "function") return undefined;
|
|
89
|
+
const status = sdk.getConnectionStatus();
|
|
90
|
+
return typeof status === "string" ? status === "connected" : undefined;
|
|
91
|
+
} catch {
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Swept group actions (README §3.7 row `onMessageSyncCompleted`, UIT-SYNC-13).
|
|
3
|
+
*
|
|
4
|
+
* Action rows come on neither MessageListener channel during the SDK's catch-up sweep
|
|
5
|
+
* (BEH-SYNC-25), and the SDK fires no `GroupListener` callback for them. So a member kicked,
|
|
6
|
+
* banned, left or whose scope changed while the device was offline would update the open chat's
|
|
7
|
+
* rows but nothing else. The hub hands each swept group-member action to the screens, and each
|
|
8
|
+
* screen runs the very `GroupListener` handlers it registered for the live event, called with the
|
|
9
|
+
* SDK's own argument order (`WSConnectionHelper.publishActionMessage`).
|
|
10
|
+
*
|
|
11
|
+
* Only on the offline (ON) path: the sync listener never fires with offline off.
|
|
12
|
+
*
|
|
13
|
+
* @internal
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/** The `GroupListener` callbacks a screen registers (any subset). */
|
|
17
|
+
export interface GroupListenerHandlers {
|
|
18
|
+
onGroupMemberJoined?: (message: any, joinedUser: any, joinedGroup: any) => void;
|
|
19
|
+
onGroupMemberLeft?: (message: any, leavingUser: any, group: any) => void;
|
|
20
|
+
onGroupMemberKicked?: (message: any, kickedUser: any, kickedBy: any, kickedFrom: any) => void;
|
|
21
|
+
onGroupMemberBanned?: (message: any, bannedUser: any, bannedBy: any, bannedFrom: any) => void;
|
|
22
|
+
onGroupMemberUnbanned?: (message: any, unbannedUser: any, unbannedBy: any, unbannedFrom: any) => void;
|
|
23
|
+
onGroupMemberScopeChanged?: (message: any, changedUser: any, newScope: any, oldScope: any, changedGroup: any) => void;
|
|
24
|
+
onMemberAddedToGroup?: (message: any, userAdded: any, userAddedBy: any, userAddedIn: any) => void;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function call(target: any, name: string): any {
|
|
28
|
+
try {
|
|
29
|
+
const fn = target?.[name];
|
|
30
|
+
return typeof fn === "function" ? fn.call(target) : undefined;
|
|
31
|
+
} catch {
|
|
32
|
+
return undefined;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** A group-member action message (`category: action`, `type: groupMember`). */
|
|
37
|
+
export function isGroupMemberAction(message: any): boolean {
|
|
38
|
+
const category = call(message, "getCategory") ?? message?.category;
|
|
39
|
+
const type = call(message, "getType") ?? message?.type;
|
|
40
|
+
return category === "action" && type === "groupMember";
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Run the screen's live `GroupListener` handler for one swept group-member action. Returns
|
|
45
|
+
* whether a handler ran. A handler that throws is logged, never rethrown (one screen must not
|
|
46
|
+
* stop the others).
|
|
47
|
+
*/
|
|
48
|
+
export function dispatchSweptGroupAction(message: any, handlers: GroupListenerHandlers | null | undefined): boolean {
|
|
49
|
+
if (!handlers || !isGroupMemberAction(message)) return false;
|
|
50
|
+
const action = call(message, "getAction") ?? message?.action;
|
|
51
|
+
const on = call(message, "getActionOn");
|
|
52
|
+
const by = call(message, "getActionBy");
|
|
53
|
+
const group = call(message, "getActionFor");
|
|
54
|
+
const run = (fn: Function | undefined, ...args: unknown[]): boolean => {
|
|
55
|
+
if (typeof fn !== "function") return false;
|
|
56
|
+
try {
|
|
57
|
+
fn(...args);
|
|
58
|
+
} catch (e) {
|
|
59
|
+
console.warn("[CometChatUIKit] a group listener threw on a swept action", e);
|
|
60
|
+
}
|
|
61
|
+
return true;
|
|
62
|
+
};
|
|
63
|
+
switch (action) {
|
|
64
|
+
case "joined":
|
|
65
|
+
return run(handlers.onGroupMemberJoined, message, by, group);
|
|
66
|
+
case "left":
|
|
67
|
+
return run(handlers.onGroupMemberLeft, message, by, group);
|
|
68
|
+
case "kicked":
|
|
69
|
+
return run(handlers.onGroupMemberKicked, message, on, by, group);
|
|
70
|
+
case "banned":
|
|
71
|
+
return run(handlers.onGroupMemberBanned, message, on, by, group);
|
|
72
|
+
case "unbanned":
|
|
73
|
+
return run(handlers.onGroupMemberUnbanned, message, on, by, group);
|
|
74
|
+
case "scopeChanged":
|
|
75
|
+
return run(handlers.onGroupMemberScopeChanged, message, on, call(message, "getNewScope"), call(message, "getOldScope"), group);
|
|
76
|
+
case "added":
|
|
77
|
+
return run(handlers.onMemberAddedToGroup, message, on, by, group);
|
|
78
|
+
default:
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row identity and send state for the offline (ON) path (README §3.2).
|
|
3
|
+
*
|
|
4
|
+
* With offline off none of these helpers decides anything: the OFF path keeps today's id/muid
|
|
5
|
+
* matching and keys exactly. Every SDK accessor is feature-detected, because the kit runs against
|
|
6
|
+
* SDKs that predate the offline release. On RN the derived offline status is
|
|
7
|
+
* `getMessageStatus()`; `getStatus()` is the pre-existing call status and is never read here.
|
|
8
|
+
*
|
|
9
|
+
* @internal
|
|
10
|
+
*/
|
|
11
|
+
import { isOfflineOn } from "./gate";
|
|
12
|
+
|
|
13
|
+
/** Message states the offline SDK reports through `getMessageStatus()`. */
|
|
14
|
+
export const OfflineMessageStatus = Object.freeze({
|
|
15
|
+
pending: "PENDING",
|
|
16
|
+
sending: "SENDING",
|
|
17
|
+
sent: "SENT",
|
|
18
|
+
delivered: "DELIVERED",
|
|
19
|
+
read: "READ",
|
|
20
|
+
failed: "FAILED",
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
/** Why a send failed (`MessageFailureReason`); identical on every SDK. */
|
|
24
|
+
export const OfflineFailureReason = Object.freeze({
|
|
25
|
+
transient: "TRANSIENT",
|
|
26
|
+
permanent: "PERMANENT",
|
|
27
|
+
queueOverflow: "QUEUE_OVERFLOW",
|
|
28
|
+
queueFull: "QUEUE_FULL",
|
|
29
|
+
byteOverflow: "BYTE_OVERFLOW",
|
|
30
|
+
discarded: "DISCARDED",
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
const NON_SENDABLE_CATEGORIES = new Set(["action", "call", "stream"]);
|
|
34
|
+
|
|
35
|
+
function callIfFunction(target: any, name: string): any {
|
|
36
|
+
try {
|
|
37
|
+
const fn = target?.[name];
|
|
38
|
+
return typeof fn === "function" ? fn.call(target) : undefined;
|
|
39
|
+
} catch {
|
|
40
|
+
return undefined;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The message's server id as a number; `0` until the server has acked it. */
|
|
45
|
+
export function serverIdOf(message: any): number {
|
|
46
|
+
if (!message) return 0;
|
|
47
|
+
const raw = callIfFunction(message, "getId") ?? message.id;
|
|
48
|
+
const id = typeof raw === "string" ? parseInt(raw, 10) : Number(raw);
|
|
49
|
+
return Number.isFinite(id) && id > 0 ? id : 0;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The SDK's own local handle, from `getLocalMessageId()` only. Used for render keys, so a message
|
|
54
|
+
* that an older offline session stamped (`data.localMessageId`) keeps today's key with offline off.
|
|
55
|
+
*/
|
|
56
|
+
export function sdkLocalIdOf(message: any): string {
|
|
57
|
+
const local = callIfFunction(message, "getLocalMessageId");
|
|
58
|
+
return typeof local === "string" ? local : "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
/**
|
|
62
|
+
* The SDK's local handle for an own message. RN parses `localMessageId` only on messages it
|
|
63
|
+
* created; a server-parsed copy carries it in `data.localMessageId` (SDK ask A4), so fall back.
|
|
64
|
+
*/
|
|
65
|
+
export function localIdOf(message: any): string {
|
|
66
|
+
if (!message) return "";
|
|
67
|
+
const local = sdkLocalIdOf(message);
|
|
68
|
+
if (local) return local;
|
|
69
|
+
const data = callIfFunction(message, "getData") ?? message.data;
|
|
70
|
+
const fromData = data && typeof data === "object" ? data.localMessageId : undefined;
|
|
71
|
+
return typeof fromData === "string" && fromData ? fromData : "";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
export function muidOf(message: any): string {
|
|
75
|
+
if (!message) return "";
|
|
76
|
+
const muid = message.muid ?? callIfFunction(message, "getMuid");
|
|
77
|
+
return typeof muid === "string" || typeof muid === "number" ? String(muid) : "";
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
export function categoryOf(message: any): string {
|
|
81
|
+
const category = callIfFunction(message, "getCategory") ?? message?.category;
|
|
82
|
+
return typeof category === "string" ? category : "";
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
/** The offline send state (`getMessageStatus()`), or `""`. Never read for calls. */
|
|
86
|
+
export function statusOf(message: any): string {
|
|
87
|
+
if (!message || categoryOf(message) === "call") return "";
|
|
88
|
+
const status = callIfFunction(message, "getMessageStatus");
|
|
89
|
+
return typeof status === "string" ? status : "";
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/** The `MessageFailureReason` stamped on a FAILED message, or `""`. */
|
|
93
|
+
export function failureReasonOf(message: any): string {
|
|
94
|
+
const reason = callIfFunction(message, "getFailureReason");
|
|
95
|
+
return typeof reason === "string" ? reason : "";
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** Delivered by the SDK's catch-up sweep (`getSource() === "SYNC"`). */
|
|
99
|
+
export function isSyncDelivered(message: any): boolean {
|
|
100
|
+
return callIfFunction(message, "getSource") === "SYNC";
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
/** PENDING or SENDING: on its way, shown with the clock. */
|
|
104
|
+
export function isSending(message: any): boolean {
|
|
105
|
+
const status = statusOf(message);
|
|
106
|
+
return status === OfflineMessageStatus.pending || status === OfflineMessageStatus.sending;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/** FAILED in the outbox (derived from status, so it survives a restart). */
|
|
110
|
+
export function isOutboxFailed(message: any): boolean {
|
|
111
|
+
return statusOf(message) === OfflineMessageStatus.failed;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* An own message the server has not acked that the offline SDK knows about: PENDING, SENDING or
|
|
116
|
+
* FAILED, or a local id without a server id. Action, call and stream rows never are. With offline
|
|
117
|
+
* off nothing has a local id or an offline status, so this is always false there.
|
|
118
|
+
*/
|
|
119
|
+
export function isOfflineUnsent(message: any): boolean {
|
|
120
|
+
if (!message || NON_SENDABLE_CATEGORIES.has(categoryOf(message)) || message.isStreamMessage) return false;
|
|
121
|
+
const status = statusOf(message);
|
|
122
|
+
if (status === OfflineMessageStatus.pending || status === OfflineMessageStatus.sending || status === OfflineMessageStatus.failed) {
|
|
123
|
+
return true;
|
|
124
|
+
}
|
|
125
|
+
return serverIdOf(message) === 0 && localIdOf(message) !== "";
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/** The list key on the ON path: server id once there is one, then the local handle, then the muid. */
|
|
129
|
+
export function rowKey(message: any): string {
|
|
130
|
+
const id = serverIdOf(message);
|
|
131
|
+
if (id > 0) return `s:${id}`;
|
|
132
|
+
const local = localIdOf(message);
|
|
133
|
+
if (local) return `l:${local}`;
|
|
134
|
+
return `m:${muidOf(message)}`;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* A render key that stays the same from compose to ack for an own message on the offline path, or
|
|
139
|
+
* `null` to keep today's key. The composer's optimistic row is keyed `muid_<muid>` today, and every
|
|
140
|
+
* later copy keeps it: the pending one the SDK stamps, and the sent one, which is server-parsed and
|
|
141
|
+
* carries its local id only in `data.localMessageId` (SDK ask A4). So the bubble does not remount
|
|
142
|
+
* on ack (UIK-SEND-08). Other senders keep today's key: their muids can collide, and the server
|
|
143
|
+
* echoes their `data.localMessageId` too. With offline off nothing changes: only the offline SDK
|
|
144
|
+
* stamps `getLocalMessageId()`, and an own row stamped by an older session keeps today's key.
|
|
145
|
+
*/
|
|
146
|
+
export function offlineRenderKey(message: any, loggedInUid?: string): string | null {
|
|
147
|
+
if (!message || message.isStreamMessage) return null;
|
|
148
|
+
const muid = muidOf(message);
|
|
149
|
+
const sdkLocal = sdkLocalIdOf(message);
|
|
150
|
+
if (sdkLocal) return muid ? `muid_${muid}` : `local_${sdkLocal}`;
|
|
151
|
+
if (!loggedInUid || callIfFunction(callIfFunction(message, "getSender"), "getUid") !== loggedInUid) return null;
|
|
152
|
+
if (!isOfflineOn()) return null;
|
|
153
|
+
if (muid) return `muid_${muid}`;
|
|
154
|
+
const local = localIdOf(message);
|
|
155
|
+
return local ? `local_${local}` : null;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
/** The conversation id a message belongs to, when the SDK has stamped it. */
|
|
159
|
+
export function conversationIdOf(message: any): string {
|
|
160
|
+
const id = callIfFunction(message, "getConversationId");
|
|
161
|
+
return typeof id === "string" ? id : "";
|
|
162
|
+
}
|