@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
|
@@ -10,6 +10,10 @@ import {
|
|
|
10
10
|
} from 'react-native';
|
|
11
11
|
import { CometChat } from '@cometchat/chat-sdk-react-native';
|
|
12
12
|
import { CometChatTheme } from '../../../theme/type';
|
|
13
|
+
import { cachedPathOf, isMediaOutOfReach, requestMediaDownload, shouldUseCachedMedia } from '../../offline/media';
|
|
14
|
+
import { sdkConnected } from '../../offline/gate';
|
|
15
|
+
import { MediaOutOfReachNote } from '../../offline/OfflineMediaBubble';
|
|
16
|
+
import { OFFLINE_STRING_KEYS } from '../../offline/notices';
|
|
13
17
|
import { deepMerge } from '../../helper/helperFunctions';
|
|
14
18
|
import { useCompTheme } from '../../../theme/hook';
|
|
15
19
|
import { Icon } from '../../icons/Icon';
|
|
@@ -33,7 +37,7 @@ const fileEventEmitter = new NativeEventEmitter(FileManager);
|
|
|
33
37
|
// now-retired multi-section gallery bubble.)
|
|
34
38
|
// ---------------------------------------------------------------------------
|
|
35
39
|
|
|
36
|
-
type DownloadState = 'IDLE' | 'DOWNLOADING' | 'DONE' | 'FAILED';
|
|
40
|
+
type DownloadState = 'IDLE' | 'DOWNLOADING' | 'DONE' | 'FAILED' | 'OUT_OF_REACH';
|
|
37
41
|
|
|
38
42
|
function formatFileSize(bytes?: number): string {
|
|
39
43
|
// Missing/invalid size (e.g. an attachment reconstructed without a size field) → no label,
|
|
@@ -79,7 +83,7 @@ export function CometChatFilesBubble({
|
|
|
79
83
|
const [expanded, setExpanded] = useState(false);
|
|
80
84
|
const [downloadStates, setDownloadStates] = useState<Record<string, DownloadState>>({});
|
|
81
85
|
// Android's DownloadManager is async — map each downloadId to the file to OPEN once its
|
|
82
|
-
// `downloadComplete` event fires (iOS
|
|
86
|
+
// `downloadComplete` event fires (iOS downloads and opens in one native openFile call).
|
|
83
87
|
const pendingOpensRef = useRef<Record<string, { url: string; name: string; key: string }>>({});
|
|
84
88
|
useEffect(() => {
|
|
85
89
|
if (Platform.OS !== 'android') return;
|
|
@@ -119,12 +123,50 @@ export function CometChatFilesBubble({
|
|
|
119
123
|
const hiddenCount = files.length - ATTACHMENT_COLLAPSED_LIMIT;
|
|
120
124
|
const showExpandButton = files.length > ATTACHMENT_COLLAPSED_LIMIT;
|
|
121
125
|
|
|
126
|
+
/**
|
|
127
|
+
* A copy this kit downloaded earlier opens as usual. The SDK's own copy opens on iOS, where the
|
|
128
|
+
* native module takes a file URL; Android's needs a content URI and the kit has no native code for
|
|
129
|
+
* one, so there it waits for a connection. Nothing to open: "Available when online".
|
|
130
|
+
*/
|
|
131
|
+
const openFileOffline = (file: CometChat.Attachment, key: string) => {
|
|
132
|
+
const name = file.getName();
|
|
133
|
+
const cached = cachedPathOf(file);
|
|
134
|
+
const outOfReach = () => setDownloadStates(prev => ({ ...prev, [key]: 'OUT_OF_REACH' }));
|
|
135
|
+
const opened = () => setDownloadStates(prev => ({ ...prev, [key]: 'DONE' }));
|
|
136
|
+
FileManager?.doesFileExist?.(name, (existResult: string) => {
|
|
137
|
+
let exists = false;
|
|
138
|
+
try { exists = !!JSON.parse(existResult)?.exists; } catch {}
|
|
139
|
+
if (exists) {
|
|
140
|
+
if (Platform.OS === 'android') FileManager?.openFileWithOption?.(name, () => {});
|
|
141
|
+
else FileManager?.openFile?.(file.getUrl(), name, () => {});
|
|
142
|
+
opened();
|
|
143
|
+
} else if (cached && Platform.OS === 'ios') {
|
|
144
|
+
FileManager?.openFile?.(cached, name, (result: string) => {
|
|
145
|
+
let ok = false;
|
|
146
|
+
try { ok = !!JSON.parse(result)?.success; } catch {}
|
|
147
|
+
if (ok) opened();
|
|
148
|
+
else outOfReach();
|
|
149
|
+
});
|
|
150
|
+
} else {
|
|
151
|
+
outOfReach();
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
};
|
|
155
|
+
|
|
122
156
|
const handleDownload = (file: CometChat.Attachment) => {
|
|
123
157
|
const url = file.getUrl();
|
|
124
158
|
const name = file.getName();
|
|
125
159
|
const key = url;
|
|
126
160
|
if ((downloadStates[key] ?? 'IDLE') === 'DOWNLOADING') return;
|
|
127
161
|
|
|
162
|
+
// Offline ON, online, no copy on the device: the SDK caches one too, for later (AC-12.3).
|
|
163
|
+
requestMediaDownload(file);
|
|
164
|
+
// Offline ON, no connection: only what is on the device can open (README §3.8).
|
|
165
|
+
if (shouldUseCachedMedia() && sdkConnected() === false) {
|
|
166
|
+
openFileOffline(file, key);
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
|
|
128
170
|
// Tap = OPEN the document (mirror CometChatFileBubble — the multi bubble previously only
|
|
129
171
|
// downloaded and never opened, so multi-doc messages "didn't open" after sending). If a local
|
|
130
172
|
// copy already exists, open it immediately; otherwise download first, then open on completion.
|
|
@@ -138,18 +180,19 @@ export function CometChatFilesBubble({
|
|
|
138
180
|
}
|
|
139
181
|
|
|
140
182
|
setDownloadStates(prev => ({ ...prev, [key]: 'DOWNLOADING' }));
|
|
183
|
+
if (Platform.OS === 'ios') {
|
|
184
|
+
// native openFile downloads without the share sheet that checkAndDownload shows
|
|
185
|
+
FileManager?.openFile?.(url, name, (result: string) => {
|
|
186
|
+
let ok = false;
|
|
187
|
+
try { ok = !!JSON.parse(result)?.success; } catch {}
|
|
188
|
+
setDownloadStates(prev => ({ ...prev, [key]: ok ? 'DONE' : 'FAILED' }));
|
|
189
|
+
});
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
141
192
|
FileManager?.checkAndDownload?.(url, name, (result: string) => {
|
|
142
193
|
try {
|
|
143
194
|
const parsed = JSON.parse(result);
|
|
144
|
-
if (
|
|
145
|
-
// iOS resolves the download in this callback — open on success.
|
|
146
|
-
if (parsed.success) {
|
|
147
|
-
FileManager?.openFile?.(url, name, () => {});
|
|
148
|
-
setDownloadStates(prev => ({ ...prev, [key]: 'DONE' }));
|
|
149
|
-
} else {
|
|
150
|
-
setDownloadStates(prev => ({ ...prev, [key]: 'FAILED' }));
|
|
151
|
-
}
|
|
152
|
-
} else if (parsed.downloadId != null) {
|
|
195
|
+
if (parsed.downloadId != null) {
|
|
153
196
|
// Android: DownloadManager is async — the downloadComplete listener opens it.
|
|
154
197
|
pendingOpensRef.current[String(parsed.downloadId)] = { url, name, key };
|
|
155
198
|
} else {
|
|
@@ -220,6 +263,12 @@ export function CometChatFilesBubble({
|
|
|
220
263
|
>
|
|
221
264
|
{sizeLabel}
|
|
222
265
|
</Text>
|
|
266
|
+
{dlState === 'OUT_OF_REACH' && !isMediaOutOfReach(file) ? (
|
|
267
|
+
<Text style={{ ...theme.typography.caption2.regular, color: subtextColor, marginTop: S.margin.m0_5 }}>
|
|
268
|
+
{t(OFFLINE_STRING_KEYS.mediaAvailableWhenOnline)}
|
|
269
|
+
</Text>
|
|
270
|
+
) : null}
|
|
271
|
+
<MediaOutOfReachNote attachment={file} color={subtextColor} />
|
|
223
272
|
{dlState === 'FAILED' && (
|
|
224
273
|
<Text
|
|
225
274
|
style={{ ...theme.typography.caption2.regular, color: theme.color.error, marginTop: S.margin.m0_5 }}
|
|
@@ -2,6 +2,10 @@ import React, { useEffect, useMemo, useState } from 'react';
|
|
|
2
2
|
import { Image, StyleProp, StyleSheet, Text, TextStyle, TouchableOpacity, View, ViewStyle } from 'react-native';
|
|
3
3
|
import { CometChat } from '@cometchat/chat-sdk-react-native';
|
|
4
4
|
import { CometChatTheme } from '../../../theme/type';
|
|
5
|
+
import { useMediaOutOfReach, useOfflineMediaUri } from '../../offline/useOfflineMediaUri';
|
|
6
|
+
import { isMediaOutOfReach, requestMediaDownload, shouldUseCachedMedia } from '../../offline/media';
|
|
7
|
+
import { MediaOutOfReachLabel } from '../../offline/OfflineViews';
|
|
8
|
+
import { t as translate } from '../../resources/CometChatLocalizeNew/LocalizationManager';
|
|
5
9
|
import { useTheme } from '../../../theme';
|
|
6
10
|
import { useCompTheme } from '../../../theme/hook';
|
|
7
11
|
import { deepMerge } from '../../helper/helperFunctions';
|
|
@@ -51,10 +55,24 @@ const ImageCell = ({
|
|
|
51
55
|
overflowTextStyle,
|
|
52
56
|
}: ImageCellProps) => {
|
|
53
57
|
const theme = useTheme();
|
|
58
|
+
// Offline ON: the SDK's cached copy when it has one, else the URL (exactly today's with offline off).
|
|
59
|
+
const imageUri = useOfflineMediaUri(attachment);
|
|
54
60
|
// An IMAGE bubble previews images only. A non-image attachment (video/audio/file) OR an image that
|
|
55
61
|
// can't be decoded (unsupported format / dead URL → onError) shows a "no preview" placeholder cell
|
|
56
62
|
// instead of a broken/blank tile.
|
|
57
63
|
const [failed, setFailed] = useState(false);
|
|
64
|
+
// Offline ON: a reconnect or a finished download gets another try at the image.
|
|
65
|
+
const outOfReach = useMediaOutOfReach(attachment);
|
|
66
|
+
useEffect(() => {
|
|
67
|
+
if (!outOfReach && shouldUseCachedMedia()) setFailed(false);
|
|
68
|
+
}, [outOfReach, imageUri]);
|
|
69
|
+
const handlePress = () => {
|
|
70
|
+
// Offline ON: no copy on the device and no connection, so the viewer would only show an error.
|
|
71
|
+
if (isMediaOutOfReach(attachment)) return;
|
|
72
|
+
// Offline ON, online, no copy on the device: ask the SDK for one (AC-12.3).
|
|
73
|
+
if (requestMediaDownload(attachment)) setFailed(false);
|
|
74
|
+
onPress?.();
|
|
75
|
+
};
|
|
58
76
|
const mime = attachment.getMimeType?.() ?? '';
|
|
59
77
|
// Placeholder only for a KNOWN non-image kind (a proper "type/subtype" mime that isn't image/*) or a
|
|
60
78
|
// genuine decode failure (onError). An empty / bare-extension mime — e.g. an optimistic OUTGOING
|
|
@@ -71,7 +89,7 @@ const ImageCell = ({
|
|
|
71
89
|
return (
|
|
72
90
|
<TouchableOpacity
|
|
73
91
|
testID={testID}
|
|
74
|
-
onPress={
|
|
92
|
+
onPress={handlePress}
|
|
75
93
|
activeOpacity={0.85}
|
|
76
94
|
style={[{ flex: 1, aspectRatio, overflow: 'hidden' }, borderStyle, cellStyle]}
|
|
77
95
|
accessibilityRole="button"
|
|
@@ -83,10 +101,17 @@ const ImageCell = ({
|
|
|
83
101
|
style={[StyleSheet.absoluteFill, borderStyle, { backgroundColor: theme.color.neutral200, justifyContent: 'center', alignItems: 'center' }]}
|
|
84
102
|
>
|
|
85
103
|
<Icon name="unknown-file-type" size={theme.spacing.spacing.s12} />
|
|
104
|
+
{failed && shouldUseCachedMedia() ? (
|
|
105
|
+
// Offline ON: never downloaded and not reachable now (AC-12.3).
|
|
106
|
+
<MediaOutOfReachLabel
|
|
107
|
+
t={translate}
|
|
108
|
+
textStyle={{ color: theme.color.textSecondary }}
|
|
109
|
+
/>
|
|
110
|
+
) : null}
|
|
86
111
|
</View>
|
|
87
112
|
) : (
|
|
88
113
|
<Image
|
|
89
|
-
source={{ uri:
|
|
114
|
+
source={{ uri: imageUri }}
|
|
90
115
|
style={[StyleSheet.absoluteFill, borderStyle]}
|
|
91
116
|
resizeMode="cover"
|
|
92
117
|
onError={() => setFailed(true)}
|