@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.
Files changed (98) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  2. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  3. package/ios/CCLocalFileGuard.h +19 -0
  4. package/ios/CCLocalFileGuard.m +34 -0
  5. package/ios/FileManager.m +70 -6
  6. package/ios/VideoManager.m +1 -1
  7. package/package.json +18 -3
  8. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +124 -55
  9. package/src/CometChatConversations/CometChatConversations.tsx +240 -117
  10. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
  11. package/src/CometChatGroups/CometChatGroups.tsx +61 -52
  12. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +146 -66
  13. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
  14. package/src/CometChatMessageHeader/listners.ts +76 -56
  15. package/src/CometChatMessageList/CometChatMessageList.tsx +1371 -188
  16. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
  17. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
  18. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
  19. package/src/CometChatSearch/CometChatSearch.tsx +353 -101
  20. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
  21. package/src/CometChatUsers/CometChatUsers.tsx +2 -0
  22. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
  23. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
  24. package/src/index.ts +6 -0
  25. package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
  26. package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
  27. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  28. package/src/shared/events/index.ts +4 -0
  29. package/src/shared/events/offline.ts +28 -0
  30. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
  31. package/src/shared/framework/MessageDataSource.tsx +34 -14
  32. package/src/shared/index.ts +2 -0
  33. package/src/shared/offline/OfflineHub.ts +651 -0
  34. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  35. package/src/shared/offline/OfflineViews.tsx +218 -0
  36. package/src/shared/offline/conversationPins.ts +137 -0
  37. package/src/shared/offline/conversations.ts +325 -0
  38. package/src/shared/offline/frameProbe.ts +24 -0
  39. package/src/shared/offline/gate.ts +94 -0
  40. package/src/shared/offline/groupActions.ts +81 -0
  41. package/src/shared/offline/identity.ts +162 -0
  42. package/src/shared/offline/index.ts +76 -0
  43. package/src/shared/offline/media.ts +247 -0
  44. package/src/shared/offline/notices.ts +90 -0
  45. package/src/shared/offline/reconcile.ts +296 -0
  46. package/src/shared/offline/searchOutcome.ts +62 -0
  47. package/src/shared/offline/send.ts +430 -0
  48. package/src/shared/offline/stateContract.ts +85 -0
  49. package/src/shared/offline/threadReplies.ts +125 -0
  50. package/src/shared/offline/twoPhase.ts +372 -0
  51. package/src/shared/offline/unsentActions.ts +168 -0
  52. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  53. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  54. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  55. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  56. package/src/shared/offline/usePresenceHidden.ts +33 -0
  57. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
  72. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
  73. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
  74. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
  75. package/src/shared/services/UploadQueueService.ts +106 -1
  76. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  77. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  78. package/src/shared/utils/catchUpCursor.ts +36 -0
  79. package/src/shared/utils/failedMessageRetry.ts +73 -0
  80. package/src/shared/utils/messageIdentity.ts +38 -0
  81. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
  82. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
  83. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  84. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
  85. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
  86. package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
  87. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
  88. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
  89. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
  90. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  91. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
  92. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  93. package/src/theme/type.ts +17 -0
  94. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  95. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  96. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  97. package/android/.gradle/7.4/gc.properties +0 -0
  98. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -27,6 +27,9 @@ import { CometChat } from '@cometchat/chat-sdk-react-native';
27
27
  import Video from 'react-native-video';
28
28
  import { Icon } from '../../icons/Icon';
29
29
  import { useTheme } from '../../../theme';
30
+ import { useMediaOutOfReach, useOfflineMediaUri } from '../../offline/useOfflineMediaUri';
31
+ import { mediaActionSource } from '../../offline/media';
32
+ import { MediaOutOfReachLabel } from '../../offline/OfflineViews';
30
33
  import { useCometChatTranslation } from '../../resources/CometChatLocalizeNew';
31
34
  import { ReactNativeZoomableView } from '../../libs/ImageZoom';
32
35
  import { clampIndex, isImageMime, isVideoMime, nextIndexForSwipe } from './mediaViewerUtils';
@@ -52,7 +55,7 @@ export interface CometChatMediaViewerProps {
52
55
  canPreview?: (att: CometChat.Attachment) => boolean;
53
56
  }
54
57
 
55
- type DownloadState = 'IDLE' | 'DOWNLOADING' | 'DONE' | 'FAILED';
58
+ type DownloadState = 'IDLE' | 'DOWNLOADING' | 'DONE' | 'FAILED' | 'OUT_OF_REACH';
56
59
 
57
60
  const { FileManager } = NativeModules;
58
61
  const { width: SCREEN_W } = Dimensions.get('window');
@@ -102,6 +105,11 @@ export const CometChatMediaViewer = ({
102
105
  // previewable → they render the "No preview available" page instead of the image/video.
103
106
  const previewable = current ? canPreview(current) : false;
104
107
  const isVideo = previewable && current ? isVideoMime(current.getMimeType?.() ?? '') : false;
108
+ // Offline ON: the SDK's cached copy (a playable copy for video), else the URL as today.
109
+ const currentUri = useOfflineMediaUri(current, { playable: isVideo });
110
+ // Offline ON, no saved copy, no connection: nothing to show or download (BEH-MEDIA-18).
111
+ const outOfReachRaw = useMediaOutOfReach(current);
112
+ const outOfReach = !!current && outOfReachRaw;
105
113
 
106
114
  const mediaItemsRef = useRef(mediaItems);
107
115
  // Keep the ref in sync outside render (not during it) so the PanResponder closure reads the latest list.
@@ -147,8 +155,14 @@ export const CometChatMediaViewer = ({
147
155
 
148
156
  const handleDownload = () => {
149
157
  if (!current || downloadState === 'DOWNLOADING' || downloadState === 'DONE') return;
158
+ // Offline ON: the saved file, never the URL; offline with no copy there is nothing to download.
159
+ const source = mediaActionSource(current);
160
+ if (source.kind === 'unavailable') {
161
+ setDownloadState('OUT_OF_REACH');
162
+ return;
163
+ }
150
164
  setDownloadState('DOWNLOADING');
151
- FileManager?.checkAndDownload(current.getUrl(), current.getName(), (result: string) => {
165
+ FileManager?.checkAndDownload(source.uri, current.getName(), (result: string) => {
152
166
  try {
153
167
  const parsed = JSON.parse(result);
154
168
  setDownloadState(parsed.success ? 'DONE' : 'FAILED');
@@ -214,7 +228,7 @@ export const CometChatMediaViewer = ({
214
228
 
215
229
  {/* Media area — swipeable */}
216
230
  <View style={styles.mediaArea} {...panResponder.panHandlers}>
217
- {previewable && !mediaLoaded && !mediaError && (
231
+ {previewable && !mediaLoaded && !mediaError && !outOfReach && (
218
232
  <ActivityIndicator
219
233
  color="#fff"
220
234
  size="large"
@@ -259,6 +273,14 @@ export const CometChatMediaViewer = ({
259
273
  : t('DOWNLOAD') || 'Download'}
260
274
  </Text>
261
275
  </TouchableOpacity>
276
+ {downloadState === 'OUT_OF_REACH' ? (
277
+ <MediaOutOfReachLabel t={t} textStyle={styles.errorText} />
278
+ ) : null}
279
+ </View>
280
+ ) : outOfReach ? (
281
+ // "Available when online": the file is not on the device and there is no connection.
282
+ <View style={styles.errorBox}>
283
+ <MediaOutOfReachLabel t={t} textStyle={styles.errorText} />
262
284
  </View>
263
285
  ) : mediaError ? (
264
286
  <View style={styles.errorBox}>
@@ -272,7 +294,7 @@ export const CometChatMediaViewer = ({
272
294
  // fight the control taps (B3).
273
295
  <View style={styles.videoWrapper}>
274
296
  <Video
275
- source={{ uri: current.getUrl() }}
297
+ source={{ uri: currentUri }}
276
298
  controls={true}
277
299
  // The <Modal> keeps its children mounted when hidden, so without this the video would
278
300
  // keep playing (audio too) after the viewer closes. Pause whenever the viewer isn't visible.
@@ -308,7 +330,7 @@ export const CometChatMediaViewer = ({
308
330
  onPanResponderTerminationRequest={() => !zoomedRef.current}
309
331
  >
310
332
  <Image
311
- source={{ uri: current.getUrl() }}
333
+ source={{ uri: currentUri }}
312
334
  style={styles.fullMedia}
313
335
  resizeMode="contain"
314
336
  onLoad={() => setMediaLoaded(true)}
@@ -123,6 +123,7 @@ export const CometChatMessageInput = (props: CometChatMessageInputInterface) =>
123
123
  return (
124
124
  <View style={style?.containerStyle as ViewStyle}>
125
125
  <TextInput
126
+ testID="cc-composer-input"
126
127
  ref={messageInputRef}
127
128
  style={style?.textStyle as TextStyle}
128
129
  onChangeText={onChangeText}
@@ -18,6 +18,11 @@ import { Icon } from "../../icons/Icon";
18
18
  import { CometChatUIEventHandler, MessageEvents } from "../../events";
19
19
  import { messageStatus } from "../../utils/CometChatMessageHelper";
20
20
  import { useCometChatTranslation } from "../../resources/CometChatLocalizeNew";
21
+ import { readListPage } from "../../offline/twoPhase";
22
+ import { useOfflineReconnect } from "../../offline/useOfflineReconnect";
23
+ import { ConnectStateView } from "../../offline/OfflineViews";
24
+ import { OFFLINE_STRING_KEYS } from "../../offline/notices";
25
+ import { CONTRACT_IDS } from "../../offline/stateContract";
21
26
 
22
27
  /**
23
28
  * Props for the CometChatReactionList component.
@@ -84,6 +89,11 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
84
89
  const [currentSelectedReaction, setCurrentSelectedReaction] = useState(selectedReaction || "All");
85
90
  const [reactionList, setReactionList] = useState<CometChat.Reaction[]>();
86
91
  const [state, setState] = useState<"loading" | "error" | "done" | "fetchNextOnScroll">("loading");
92
+ // Offline ON (D84): the device was not connected and has no saved reactions: "Connect to load
93
+ // reactions" shows (the app's own error view instead, if it passed one) and the reactions load
94
+ // again once, by themselves, when the connection is back. Any other error is not loaded again.
95
+ const reloadOnConnectRef = useRef(false);
96
+ const [offlineMiss, setOfflineMiss] = useState(false);
87
97
  const loggedInUser = useRef<CometChat.User | null>(undefined);
88
98
  const newMessageObj = useRef<CometChat.BaseMessage>(CommonUtils.clone(message));
89
99
 
@@ -108,6 +118,13 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
108
118
  showReactions();
109
119
  }, [currentSelectedReaction]);
110
120
 
121
+ // D84 rule 8: the one reload of the offline state.
122
+ useOfflineReconnect(() => {
123
+ if (!reloadOnConnectRef.current) return;
124
+ reloadOnConnectRef.current = false;
125
+ void showReactions();
126
+ });
127
+
111
128
  const _setAllReactions = (_messageReactions: any) => {
112
129
  let totalCount = _messageReactions.reduce((acc: any, curr: any) => acc + curr.count, 0);
113
130
  const allReactionCountObject = new CometChat.ReactionCount("All", totalCount, false);
@@ -152,13 +169,26 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
152
169
  }
153
170
 
154
171
  try {
155
- const list = await requestBuilder.fetchNext();
172
+ // Offline ON: two-phase; offline past the cache the device's reactions show (U6).
173
+ const page = await readListPage<any>(requestBuilder, "next");
174
+ if (page.offline && page.rows.length === 0) {
175
+ // Nothing on the device and not connected: the offline state, loaded again on reconnect (D84 rule 3).
176
+ reloadOnConnectRef.current = true;
177
+ setOfflineMiss(true);
178
+ setState("error");
179
+ return [];
180
+ }
181
+ reloadOnConnectRef.current = false;
182
+ setOfflineMiss(false);
183
+ const list = page.rows;
156
184
  reactionListMap.current[reaction] = list;
157
185
  setState("done");
158
186
  return list;
159
187
  } catch (error: any) {
160
188
  //console.log("error while fetching reactions", error);
161
189
  if (error?.code === "REQUEST_IN_PROGRESS") return null;
190
+ reloadOnConnectRef.current = false;
191
+ setOfflineMiss(false);
162
192
  setState("error");
163
193
  return [];
164
194
  }
@@ -170,11 +200,12 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
170
200
  if (reactionListMap.current[currentSelectedReaction]?.length === 0) {
171
201
  return;
172
202
  } else {
173
- const newList = await requestBuilder.fetchNext();
174
- reactionListMap.current[currentSelectedReaction] = [
175
- ...(reactionListMap.current?.[currentSelectedReaction] || []),
176
- ...newList,
177
- ];
203
+ const page = await readListPage<any>(requestBuilder, "next");
204
+ // A cached page can repeat rows past the last page (SDK known issue): dedupe by id.
205
+ const shown = reactionListMap.current?.[currentSelectedReaction] || [];
206
+ const seen = new Set(shown.map((r: any) => String(r?.getReactionId?.() ?? r?.id ?? "")));
207
+ const newList = page.rows.filter((r: any) => !seen.has(String(r?.getReactionId?.() ?? r?.id ?? "")));
208
+ reactionListMap.current[currentSelectedReaction] = [...shown, ...newList];
178
209
  setReactionList(reactionListMap.current[currentSelectedReaction]);
179
210
  }
180
211
  setState("done");
@@ -189,6 +220,9 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
189
220
  (emoji: string) => {
190
221
  const msgObj = CommonUtils.clone(messageObject);
191
222
 
223
+ // The untouched copy a failed write rolls back to (UIK-MUT-01). The optimistic update below
224
+ // mutates msgObj's own reaction objects, so rolling back to msgObj left the change on screen.
225
+ const rollbackMessage = CommonUtils.clone(msgObj);
192
226
  const messageId = msgObj?.getId();
193
227
  const reactions = msgObj?.getReactions() || [];
194
228
  const emojiObject = reactions?.find((reaction: any) => {
@@ -221,7 +255,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
221
255
  .then((message: any) => {})
222
256
  .catch((error: any) => {
223
257
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
224
- message: msgObj,
258
+ message: rollbackMessage,
225
259
  status: messageStatus.success,
226
260
  });
227
261
  //console.log(error);
@@ -259,7 +293,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
259
293
  .catch((error: any) => {
260
294
  //console.log(error);
261
295
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
262
- message: msgObj,
296
+ message: rollbackMessage,
263
297
  status: messageStatus.success,
264
298
  });
265
299
  });
@@ -375,6 +409,17 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
375
409
 
376
410
  const ErrorView = () => {
377
411
  if (ErrorStateView) return <ErrorStateView />;
412
+ if (offlineMiss) {
413
+ return (
414
+ <ConnectStateView
415
+ testID={CONTRACT_IDS.emptyConnectToLoad}
416
+ title={t(OFFLINE_STRING_KEYS.connectToLoadReactions)}
417
+ containerStyle={theme.reactionListStyles.errorStateStyle?.containerStyle}
418
+ titleStyle={theme.reactionListStyles.errorStateStyle?.titleStyle}
419
+ subtitleStyle={theme.reactionListStyles.errorStateStyle?.subtitleStyle}
420
+ />
421
+ );
422
+ }
378
423
  return (
379
424
  <ErrorEmptyView
380
425
  title={errorStateText ?? "Oops!"}
@@ -413,8 +458,9 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
413
458
 
414
459
  return (
415
460
  <View style={{ flex: 1 }}>
416
- {/* Slider for reactions */}
417
- {state != "error" && (
461
+ {/* Slider for reactions. Offline with nothing loaded (D84), the tabs stay with the message's
462
+ own counts above "Connect to load reactions", as on Android; other errors hide them. */}
463
+ {(state != "error" || offlineMiss) && (
418
464
  <View>
419
465
  <ScrollView
420
466
  showsHorizontalScrollIndicator={false}
@@ -4,6 +4,7 @@ import { Image, View } from "react-native";
4
4
  import { useTheme } from "../../../theme";
5
5
  import { useCompTheme } from "../../../theme/hook";
6
6
  import { deepMerge } from "../../helper/helperFunctions";
7
+ import { usePresenceHidden } from "../../offline/usePresenceHidden";
7
8
  import { StatusIndicatorStyles } from "./styles";
8
9
 
9
10
  /**
@@ -34,11 +35,14 @@ export const CometChatStatusIndicator = ({
34
35
  }: CometChatStatusIndicatorInterface) => {
35
36
  const theme = useTheme();
36
37
  const compTheme = useCompTheme();
38
+ // Offline ON, SDK not connected: no presence anywhere (groups' private / protected badges stay).
39
+ const presenceHidden = usePresenceHidden();
37
40
  const statusIndicatorStyles = useMemo(() => {
38
41
  return deepMerge(theme.statusIndicatorStyle, compTheme.statusIndicatorStyle ?? {}, style ?? {});
39
42
  }, [theme, compTheme, style]);
40
43
 
41
44
  if (type === CometChat.USER_STATUS.ONLINE) {
45
+ if (presenceHidden) return null;
42
46
  return (
43
47
  <View
44
48
  style={[ statusIndicatorStyles.containerStyleOnline]}
@@ -2,6 +2,10 @@ import React, { useEffect, useMemo, useRef, useState } from 'react';
2
2
  import { Image, ImageStyle, 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 { isOfflineUnsent } from '../../offline/identity';
6
+ import { isMediaOutOfReach, requestMediaDownload } from '../../offline/media';
7
+ import { MediaOutOfReachNote } from '../../offline/OfflineMediaBubble';
8
+ import { useMediaOutOfReach } from '../../offline/useOfflineMediaUri';
5
9
  import { useTheme } from '../../../theme';
6
10
  import { useCompTheme } from '../../../theme/hook';
7
11
  import { deepMerge } from '../../helper/helperFunctions';
@@ -54,6 +58,8 @@ interface VideoCellProps {
54
58
  testID?: string;
55
59
  overflowCount?: number;
56
60
  thumbnailUrl?: string;
61
+ /** Own message the server has not acked (offline queue): no server thumbnail can exist yet. */
62
+ unsent?: boolean;
57
63
  /** Retry a failed server thumbnail — only for a just-sent message, whose thumbnail may not exist yet. */
58
64
  retryThumbnail?: boolean;
59
65
  cellStyle?: StyleProp<ViewStyle>;
@@ -73,6 +79,8 @@ interface VideoCellProps {
73
79
  const THUMBNAIL_RETRY_DELAYS_MS = [1000, 2000, 4000, 8000, 15000];
74
80
  const THUMBNAIL_RETRY_WINDOW_SECS = 120;
75
81
 
82
+ const isRemoteUrl = (url?: string) => /^https?:\/\//i.test(url ?? '');
83
+
76
84
  const VideoCell = ({
77
85
  attachment,
78
86
  aspectRatio = 1,
@@ -81,6 +89,7 @@ const VideoCell = ({
81
89
  testID,
82
90
  overflowCount,
83
91
  thumbnailUrl,
92
+ unsent,
84
93
  retryThumbnail,
85
94
  cellStyle,
86
95
  playButtonStyle,
@@ -94,7 +103,14 @@ const VideoCell = ({
94
103
  const duration = getDuration(attachment);
95
104
  // Only stand in for a server thumbnail that is on its way: no `thumbnailUrl` means the Thumbnail
96
105
  // Generation extension is off in the dashboard (or failed for this file), and then no thumbnail shows.
97
- const localThumbnail = useLocalVideoThumbnail({ remoteUrl: thumbnailUrl ? attachment.getUrl?.() : undefined });
106
+ // The exception is an own message still queued/sending (offline): it has no `thumbnailUrl` yet, and
107
+ // its video is a local file (or an upload this device linked), so the local frame stands in until it is acked.
108
+ const attachmentUrl = attachment.getUrl?.();
109
+ const localThumbnail = useLocalVideoThumbnail(
110
+ unsent
111
+ ? { localUri: isRemoteUrl(attachmentUrl) ? undefined : attachmentUrl || undefined, remoteUrl: attachmentUrl }
112
+ : { remoteUrl: thumbnailUrl ? attachmentUrl : undefined }
113
+ );
98
114
  // Bumped once a retried thumbnail is fetched, to remount the <Image> onto the now-cached file.
99
115
  const [thumbnailKey, setThumbnailKey] = useState(0);
100
116
  const retry = useRef<{ attempt: number; timer?: ReturnType<typeof setTimeout> }>({ attempt: 0 });
@@ -129,6 +145,14 @@ const VideoCell = ({
129
145
  borderBottomLeftRadius: radii.bottomLeft ?? 0,
130
146
  borderBottomRightRadius: radii.bottomRight ?? 0,
131
147
  };
148
+ const outOfReach = useMediaOutOfReach(attachment);
149
+ const handlePress = () => {
150
+ // Offline ON: no copy on the device and no connection, so the player has nothing to play.
151
+ if (isMediaOutOfReach(attachment)) return;
152
+ // Online with no copy: ask the SDK for one; the viewer streams the URL meanwhile (AC-12.3).
153
+ requestMediaDownload(attachment);
154
+ onPress?.();
155
+ };
132
156
 
133
157
  if (unsupported) {
134
158
  return (
@@ -162,7 +186,7 @@ const VideoCell = ({
162
186
  return (
163
187
  <TouchableOpacity
164
188
  testID={testID}
165
- onPress={onPress}
189
+ onPress={handlePress}
166
190
  activeOpacity={0.85}
167
191
  style={[{ flex: 1, aspectRatio, overflow: 'hidden' }, borderStyle, cellStyle]}
168
192
  accessibilityRole="button"
@@ -205,6 +229,12 @@ const VideoCell = ({
205
229
  </View>
206
230
  )}
207
231
 
232
+ {outOfReach && !overflowCount ? (
233
+ <View pointerEvents="none" style={{ position: 'absolute', top: theme.spacing.spacing.s2, left: theme.spacing.spacing.s2, right: theme.spacing.spacing.s2 }}>
234
+ <MediaOutOfReachNote attachment={attachment} color={theme.color.staticWhite} />
235
+ </View>
236
+ ) : null}
237
+
208
238
  {!overflowCount && duration && (
209
239
  <View
210
240
  pointerEvents="none"
@@ -241,6 +271,7 @@ const VideoCell = ({
241
271
  const VideoGrid = ({
242
272
  attachments,
243
273
  thumbnailUrls,
274
+ unsent,
244
275
  retryThumbnail,
245
276
  onAttachmentPress,
246
277
  containerStyle,
@@ -254,6 +285,7 @@ const VideoGrid = ({
254
285
  }: {
255
286
  attachments: CometChat.Attachment[];
256
287
  thumbnailUrls?: string[];
288
+ unsent?: boolean;
257
289
  retryThumbnail?: boolean;
258
290
  onAttachmentPress: (attachment: CometChat.Attachment, index: number) => void;
259
291
  containerStyle?: StyleProp<ViewStyle>;
@@ -279,6 +311,7 @@ const VideoGrid = ({
279
311
  radii={radii}
280
312
  overflowCount={overflowCount}
281
313
  thumbnailUrl={thumbnailUrls?.[i]}
314
+ unsent={unsent}
282
315
  retryThumbnail={retryThumbnail}
283
316
  onPress={() => onAttachmentPress(attachments[i], i)}
284
317
  cellStyle={cellStyle}
@@ -413,6 +446,7 @@ export function CometChatVideosBubble({
413
446
  <VideoGrid
414
447
  attachments={allAttachments}
415
448
  thumbnailUrls={thumbnailUrls}
449
+ unsent={isOfflineUnsent(message)}
416
450
  retryThumbnail={Date.now() / 1000 - (message.getSentAt?.() ?? 0) < THUMBNAIL_RETRY_WINDOW_SECS}
417
451
  containerStyle={s.containerStyle}
418
452
  cellStyle={s.cellStyle}
@@ -1,3 +1,5 @@
1
+ import { shouldUseCachedMedia } from '../../offline/media';
2
+ import { OfflineMediaBubble } from '../../offline/OfflineMediaBubble';
1
3
  import React from 'react';
2
4
  import { View } from 'react-native';
3
5
  import { CometChat } from '@cometchat/chat-sdk-react-native';
@@ -48,18 +50,28 @@ export function CometChatVoiceNoteBubble({
48
50
 
49
51
  return (
50
52
  <View style={[{ width: '100%' }, s.containerStyle]}>
51
- {audioAttachments.map((att, i) => (
52
- <CometChatAudioBubble
53
- key={att.getUrl() ?? String(i)}
54
- audioUrl={att.getUrl()}
55
- playViewContainerStyle={s.playViewContainerStyle}
56
- playIconStyle={s.playIconStyle}
57
- playIconContainerStyle={s.playIconContainerStyle}
58
- waveStyle={s.waveStyle}
59
- waveContainerStyle={s.waveContainerStyle}
60
- playProgressTextStyle={s.playProgressTextStyle}
61
- />
62
- ))}
53
+ {audioAttachments.map((att, i) => {
54
+ const bubble = (audioUrl: string) => (
55
+ <CometChatAudioBubble
56
+ key={att.getUrl() ?? String(i)}
57
+ audioUrl={audioUrl}
58
+ playViewContainerStyle={s.playViewContainerStyle}
59
+ playIconStyle={s.playIconStyle}
60
+ playIconContainerStyle={s.playIconContainerStyle}
61
+ waveStyle={s.waveStyle}
62
+ waveContainerStyle={s.waveContainerStyle}
63
+ playProgressTextStyle={s.playProgressTextStyle}
64
+ />
65
+ );
66
+ // Offline ON: the SDK's cached copy when it has one. OFF: today's bubble with the URL.
67
+ return shouldUseCachedMedia() ? (
68
+ <OfflineMediaBubble key={att.getUrl() ?? String(i)} attachment={att} playable>
69
+ {bubble}
70
+ </OfflineMediaBubble>
71
+ ) : (
72
+ bubble(att.getUrl())
73
+ );
74
+ })}
63
75
  {/* §7 — caption rides on the (last) message of the batch */}
64
76
  {Boolean(caption) && (
65
77
  <CometChatCaptionText
package/src/theme/type.ts CHANGED
@@ -538,6 +538,23 @@ export interface CometChatTheme {
538
538
  callActionBubbleStyles: DeepPartial<CallActionBubbleStyles>;
539
539
  messageInformationStyles: DeepPartial<CometChatTheme["messageInformationStyles"]>;
540
540
  messageOptionsStyles: DeepPartial<ActionSheetStyle>;
541
+ /**
542
+ * Offline states (message list, conversation list and media bubbles). Only drawn with the
543
+ * SDK's offline on. Optional: anything left out derives from today's error and date tokens.
544
+ */
545
+ offlineStyles?: {
546
+ /** The tappable "Not sent. Tap to retry" row of a failed message; no tint by default. */
547
+ failedRowStyle?: ViewStyle;
548
+ failedIconStyle?: ImageStyle;
549
+ retryTextStyle?: TextStyle;
550
+ notSentYetTextStyle?: TextStyle;
551
+ /** The "Available when online" stand-in for media the device never downloaded. */
552
+ mediaPlaceholderStyle?: { containerStyle?: ViewStyle; textStyle?: TextStyle };
553
+ /** The "Connect to load more" list footer. */
554
+ footerStyle?: { containerStyle?: ViewStyle; textStyle?: TextStyle };
555
+ /** The one-line notice ("1 unsent message was removed"). */
556
+ noticeStyle?: { containerStyle?: ViewStyle; textStyle?: TextStyle; actionTextStyle?: TextStyle };
557
+ };
541
558
  };
542
559
  avatarStyle: Partial<AvatarStyle>;
543
560
  statusIndicatorStyle: StatusIndicatorStyles;
File without changes
File without changes