@cometchat/chat-uikit-react-native 5.5.3 → 5.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (100) hide show
  1. package/android/build.gradle +5 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +47 -4
  4. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  5. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +209 -119
  6. package/ios/CCLocalFileGuard.h +19 -0
  7. package/ios/CCLocalFileGuard.m +34 -0
  8. package/ios/FileManager.m +70 -6
  9. package/ios/RichTextEditorView.swift +96 -1
  10. package/ios/SoundPlayer.m +152 -6
  11. package/ios/VideoManager.m +1 -1
  12. package/package.json +18 -3
  13. package/react-native-cometchat-ui-kit.podspec +1 -1
  14. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +167 -79
  15. package/src/CometChatConversations/CometChatConversations.tsx +240 -117
  16. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
  17. package/src/CometChatGroups/CometChatGroups.tsx +61 -52
  18. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +173 -85
  19. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
  20. package/src/CometChatMessageHeader/listners.ts +76 -56
  21. package/src/CometChatMessageList/CometChatMessageList.tsx +1423 -205
  22. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
  23. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
  24. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
  25. package/src/CometChatSearch/CometChatSearch.tsx +353 -101
  26. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
  27. package/src/CometChatUsers/CometChatUsers.tsx +2 -0
  28. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
  29. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +48 -47
  30. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
  31. package/src/index.ts +6 -0
  32. package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
  33. package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
  34. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  35. package/src/shared/events/index.ts +4 -0
  36. package/src/shared/events/offline.ts +28 -0
  37. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
  38. package/src/shared/framework/MessageDataSource.tsx +34 -14
  39. package/src/shared/index.ts +2 -0
  40. package/src/shared/offline/OfflineHub.ts +651 -0
  41. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  42. package/src/shared/offline/OfflineViews.tsx +218 -0
  43. package/src/shared/offline/conversationPins.ts +137 -0
  44. package/src/shared/offline/conversations.ts +325 -0
  45. package/src/shared/offline/frameProbe.ts +24 -0
  46. package/src/shared/offline/gate.ts +94 -0
  47. package/src/shared/offline/groupActions.ts +81 -0
  48. package/src/shared/offline/identity.ts +162 -0
  49. package/src/shared/offline/index.ts +76 -0
  50. package/src/shared/offline/media.ts +247 -0
  51. package/src/shared/offline/notices.ts +90 -0
  52. package/src/shared/offline/reconcile.ts +296 -0
  53. package/src/shared/offline/searchOutcome.ts +62 -0
  54. package/src/shared/offline/send.ts +430 -0
  55. package/src/shared/offline/stateContract.ts +85 -0
  56. package/src/shared/offline/threadReplies.ts +125 -0
  57. package/src/shared/offline/twoPhase.ts +372 -0
  58. package/src/shared/offline/unsentActions.ts +168 -0
  59. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  60. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  61. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  62. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  63. package/src/shared/offline/usePresenceHidden.ts +33 -0
  64. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
  72. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
  73. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
  74. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
  75. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
  76. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
  77. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
  78. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
  79. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
  80. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
  81. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
  82. package/src/shared/services/UploadQueueService.ts +106 -1
  83. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  84. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  85. package/src/shared/utils/catchUpCursor.ts +36 -0
  86. package/src/shared/utils/failedMessageRetry.ts +73 -0
  87. package/src/shared/utils/messageIdentity.ts +38 -0
  88. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
  89. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
  90. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  91. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
  92. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
  93. package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
  94. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
  95. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
  96. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
  97. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  98. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
  99. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  100. package/src/theme/type.ts +17 -0
@@ -510,7 +510,9 @@ export const CometChatUsers = React.forwardRef<
510
510
  : () => <Skeleton style={mergedStyle.skeletonStyle} />
511
511
  }
512
512
  EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
513
+ customEmptyView={!!EmptyView}
513
514
  ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
515
+ customErrorView={!!ErrorView}
514
516
  statusIndicatorType={(user: CometChat.User) =>
515
517
  usersStatusVisibility
516
518
  ? user?.getBlockedByMe()
@@ -24,6 +24,8 @@ import { CometChatOutgoingCall, OutgoingCallConfiguration } from "../CometChatOu
24
24
  import { CallButtonStyle } from "./style";
25
25
  import { DeepPartial } from "../../shared/helper/types";
26
26
  import { CallingPackage } from "../CallingPackage";
27
+ import { isQuietRejection } from "../../shared/offline/send";
28
+ import { isOfflineOn, sdkConnected } from "../../shared/offline/gate";
27
29
  import { JSX } from "react";
28
30
 
29
31
  const CometChatCalls = CallingPackage.CometChatCalls;
@@ -142,6 +144,22 @@ export const CometChatCallButtons = (props: CometChatCallButtonsInterface): JSX.
142
144
  var callType = type;
143
145
  // For group calls, send a custom meeting message.
144
146
  if (group) {
147
+ // A call invite is worth nothing once it is late, so it never joins the offline queue.
148
+ // Queued, the send stays unanswered until the connection returns, and the `.then` below
149
+ // would then open the outgoing-call screen and invite the whole group minutes after the
150
+ // tap, with a push, without the user asking. Refuse it now instead, the way a refused
151
+ // `initiateCall` is refused. (Android 6.3.0 queues it - parity gap recorded on purpose.)
152
+ if (isOfflineOn() && sdkConnected() === false) {
153
+ const offlineError = new CometChat.CometChatException({
154
+ code: "ERROR_NO_INTERNET",
155
+ name: "ERROR_NO_INTERNET",
156
+ message: "A call cannot be started without a connection.",
157
+ });
158
+ // `{ error }`, the shape the kit's own `ccCallFailed` listener takes (CometChatOutgoingCall.tsx:198).
159
+ CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccCallFailed, { error: offlineError });
160
+ onError && onError(offlineError);
161
+ return;
162
+ }
145
163
  let customData = {
146
164
  callType: callType,
147
165
  sessionId: receiverID,
@@ -171,6 +189,7 @@ export const CometChatCallButtons = (props: CometChatCallButtonsInterface): JSX.
171
189
  CometChatUIEventHandler.emitCallEvent(CallUIEvents.ccOutgoingCall, { call: res });
172
190
  })
173
191
  .catch((rej) => {
192
+ if (isQuietRejection(rej)) return; // the session ended or the cache was reset: nothing to report
174
193
  console.log("custom msg error", rej);
175
194
  onError && onError(rej);
176
195
  });
@@ -160,56 +160,57 @@ export const LinkPreviewBubble = (props: LinkPreviewBubbleInterface) => {
160
160
  );
161
161
 
162
162
  return (
163
- <View
164
- onLayout={onLayoutHandler}
165
- onTouchStart={handleTouchStart}
166
- onTouchEnd={handleTouchEnd}
167
- onTouchMove={onTouchMove}
168
- >
169
- {imageSource ? (
170
- <View
171
- style={style?.headerImageContainerStyle}
172
- onTouchStart={handleTouchStart}
173
- onTouchEnd={handleTouchEnd}
174
- onTouchMove={onTouchMove}
175
- >
176
- <Image
177
- source={imageSource}
178
- style={[{ height: imageHeight, width: imageWidth }, style?.headerImageStyle]}
179
- onError={(err) => {
180
- setImageSource(DefaultLinkPreview);
181
- }}
182
- />
183
- </View>
184
- ) : null}
163
+ <View onLayout={onLayoutHandler}>
164
+ {/* Only the preview card (image, title, description, link) opens the link. Raw touch
165
+ events reach every ancestor of the touched view, whichever child handles the press, so
166
+ these handlers on the outer view also fired for taps on the message text and its
167
+ "Read more" below, and the image container's second copy made an image tap open the
168
+ link twice (ENG-41080). */}
169
+ <View
170
+ onTouchStart={handleTouchStart}
171
+ onTouchEnd={handleTouchEnd}
172
+ onTouchMove={onTouchMove}
173
+ >
174
+ {imageSource ? (
175
+ <View style={style?.headerImageContainerStyle}>
176
+ <Image
177
+ source={imageSource}
178
+ style={[{ height: imageHeight, width: imageWidth }, style?.headerImageStyle]}
179
+ onError={() => {
180
+ setImageSource(DefaultLinkPreview);
181
+ }}
182
+ />
183
+ </View>
184
+ ) : null}
185
+
186
+ <View style={style?.bodyStyle?.containerStyle}>
187
+ <View style={{ flexDirection: "row" }}>
188
+ <View style={style?.bodyStyle?.titleContainerStyle}>
189
+ <Text style={style?.bodyStyle?.titleStyle} ellipsizeMode='tail'>
190
+ {title}
191
+ </Text>
192
+ </View>
185
193
 
186
- <View style={style?.bodyStyle?.containerStyle}>
187
- <View style={{ flexDirection: "row" }}>
188
- <View style={style?.bodyStyle?.titleContainerStyle}>
189
- <Text style={style?.bodyStyle?.titleStyle} ellipsizeMode='tail'>
190
- {title}
194
+ {!imageSource && !faviconError && (
195
+ <View style={style?.bodyStyle?.faviconContainerStyle}>
196
+ <Image
197
+ source={faviconSource}
198
+ style={style?.bodyStyle?.faviconStyle}
199
+ onError={() => {
200
+ setFaviconError(true);
201
+ }}
202
+ />
203
+ </View>
204
+ )}
205
+ </View>
206
+ <View style={style?.bodyStyle?.subtitleContainerStyle}>
207
+ <Text style={style?.bodyStyle?.subtitleTitle} numberOfLines={2} ellipsizeMode='tail'>
208
+ {description}
209
+ </Text>
210
+ <Text style={style?.bodyStyle?.subtitleTitle} numberOfLines={2} ellipsizeMode='tail'>
211
+ {link}
191
212
  </Text>
192
213
  </View>
193
-
194
- {!imageSource && !faviconError && (
195
- <View style={style?.bodyStyle?.faviconContainerStyle}>
196
- <Image
197
- source={faviconSource}
198
- style={style?.bodyStyle?.faviconStyle}
199
- onError={(err) => {
200
- setFaviconError(true);
201
- }}
202
- />
203
- </View>
204
- )}
205
- </View>
206
- <View style={style?.bodyStyle?.subtitleContainerStyle}>
207
- <Text style={style?.bodyStyle?.subtitleTitle} numberOfLines={2} ellipsizeMode='tail'>
208
- {description}
209
- </Text>
210
- <Text style={style?.bodyStyle?.subtitleTitle} numberOfLines={2} ellipsizeMode='tail'>
211
- {link}
212
- </Text>
213
214
  </View>
214
215
  </View>
215
216
  {/* Only the card that carries the message text gets this padded row; the others would show an empty band. */}
@@ -23,6 +23,7 @@ import { CometChatStickerKeyboard } from "./CometChatStickerKeyboard";
23
23
  import { CometChatStickerBubble } from "./StickersBubble";
24
24
  import { StickerConfigurationInterface } from "./StickerConfiguration";
25
25
  import { AdditionalAuxiliaryOptionsParams } from "../../shared/base/Types";
26
+ import { isQuietRejection } from "../../shared/offline/send";
26
27
  import { getCometChatTranslation } from "../../shared/resources/CometChatLocalizeNew/LocalizationManager"
27
28
 
28
29
  const t = getCometChatTranslation();
@@ -161,6 +162,7 @@ const StickerButton = ({ user, group, id, stickerIconStyle, stickerIcon, replyTo
161
162
  }
162
163
  })
163
164
  .catch((err) => {
165
+ if (isQuietRejection(err)) return; // the session ended or the cache was reset: nothing to report
164
166
  console.error("Failed to send sticker:", err);
165
167
  });
166
168
  };
package/src/index.ts CHANGED
@@ -78,6 +78,7 @@ import {
78
78
  MessageBubbleAlignmentType,
79
79
  MessageDataSource,
80
80
  MessageEvents,
81
+ OfflineMessageEvents,
81
82
  MessageListAlignmentType,
82
83
  MessageTimeAlignmentType,
83
84
  RecorderState,
@@ -326,6 +327,7 @@ export {
326
327
  MentionTextStyle,
327
328
  MessageDataSource,
328
329
  MessageEvents,
330
+ OfflineMessageEvents,
329
331
  MessageTranslationBubble,
330
332
  MessageTranslationExtension,
331
333
  PollsExtension,
@@ -483,6 +485,10 @@ export type {
483
485
 
484
486
  // Rich Text Editor
485
487
  export { default as RichTextEditor } from './CometChatRichTextEditor';
488
+ // Offline support (additive): event payload and settings types.
489
+ export type { MessageSendState, MessageSendStateChangedEvent, OfflineCacheResetEvent } from "./shared/events";
490
+ export type { UIKitOfflineSettings } from "./shared/CometChatUiKit/UIKitSettings";
491
+
486
492
  export type {
487
493
  RichTextEditorRef,
488
494
  ContentChangeEvent,
@@ -20,6 +20,9 @@ import { CometChatSoundManager } from "../resources";
20
20
  import { getUnixTimestampInMilliseconds, messageStatus } from "../utils/CometChatMessageHelper";
21
21
  import { permissionUtil } from "../utils/PermissionUtil";
22
22
  import { CometChatUIKitHelper } from "./CometChatUIKitHelper";
23
+ import { applyOfflineSetting, prepareOfflineSupport, startOfflineSupport } from "../offline";
24
+ import { isOfflineOn } from "../offline/gate";
25
+ import { sendWithStatePromise } from "../offline/send";
23
26
  import { UIKitSettings } from "./UIKitSettings";
24
27
 
25
28
  export class CometChatUIKit {
@@ -57,14 +60,21 @@ export class CometChatUIKit {
57
60
  appSetting.roles = uiKitSettings.roles;
58
61
  }
59
62
 
63
+ // Offline: pass-through only (absent ⇒ no call; SDK without offline ⇒ no call).
64
+ applyOfflineSetting(appSetting, uiKitSettings.offline);
65
+
60
66
  CometChatUIKit.attachListener();
67
+ prepareOfflineSupport();
61
68
 
62
69
  return CometChat.init(uiKitSettings.appId, appSetting.build()).then(
63
70
  async() => {
64
71
  CometChat.setSource("uikit-v5", Platform.OS, "react-native");
65
72
  ListenerInitializer.attachListeners();
73
+ // After the SDK's own init: register the offline hub once (inert while offline is off).
74
+ startOfflineSupport();
66
75
  try {
67
76
  const user = await CometChat.getLoggedinUser();
77
+ if (user) startOfflineSupport(user);
68
78
  CometChatUIKit.setLoggedInUser(user);
69
79
  if (user) {
70
80
  this.enableExtensions();
@@ -92,8 +102,25 @@ export class CometChatUIKit {
92
102
  * File-based init for AI agent skills.
93
103
  * Calls CometChat.initFromSettings(settings) which writes
94
104
  * integrationSource = "ai-agent" to persistent storage.
105
+ *
106
+ * Offline works the same as on init(): pass `offline` (the value `UIKitSettings.offline`
107
+ * takes — `true`, an options object, or an SDK `OfflineConfig`) and it reaches the SDK as
108
+ * `chatSDK.offline`, replacing any value in the settings file. Without it, the file's
109
+ * `chatSDK.offline` reaches the SDK unchanged.
110
+ *
111
+ * @param settings The parsed cometchat-settings.json object.
112
+ * @param offline Optional offline messaging settings for the Chat SDK.
95
113
  */
96
- static initFromSettings(settings: CometChat.CometChatSettings) {
114
+ static initFromSettings(settings: CometChat.CometChatSettings, offline?: UIKitSettings["offline"]) {
115
+ // Offline: a code-level setting wins over the file's; the caller's object is left as is.
116
+ // Read and written untyped: an SDK before offline support has no `chatSDK.offline` in its typings.
117
+ if (offline !== undefined && offline !== null) {
118
+ settings = {
119
+ ...settings,
120
+ chatSDK: { ...settings.chatSDK, offline } as CometChat.CometChatSettings["chatSDK"],
121
+ };
122
+ }
123
+
97
124
  // Extract authKey from credentials (UIKit uses this for login — SDK ignores it)
98
125
  const authKey = settings.credentials?.authKey;
99
126
 
@@ -110,20 +137,26 @@ export class CometChatUIKit {
110
137
  subscriptionType: subscribePresence
111
138
  ? CometChat.AppSettings.SUBSCRIPTION_TYPE_ALL_USERS as UIKitSettings["subscriptionType"]
112
139
  : undefined,
140
+ // Same as init(): the kit's settings carry the offline setting the SDK was given.
141
+ offline: (settings.chatSDK as { offline?: UIKitSettings["offline"] } | undefined)?.offline,
113
142
  };
114
143
 
115
144
  // Capture raw settings so the Calls SDK routes through initFromSettings (ai-agent).
116
145
  CometChatUIKit.callsInitSettings = settings;
117
146
 
118
147
  CometChatUIKit.attachListener();
148
+ prepareOfflineSupport();
119
149
 
120
150
  // CRITICAL: Call initFromSettings — NOT init(). Only initFromSettings writes "ai-agent".
151
+ // `settings.chatSDK.offline` (from the file or `offline`) reaches the SDK: initFromSettings reads it itself.
121
152
  return CometChat.initFromSettings(settings).then(
122
153
  async () => {
123
154
  CometChat.setSource("uikit-v5", Platform.OS, "react-native");
124
155
  ListenerInitializer.attachListeners();
156
+ startOfflineSupport();
125
157
  await CometChat.getLoggedinUser()
126
- .then((user: any) => {
158
+ .then(async (user: any) => {
159
+ if (user) startOfflineSupport(user);
127
160
  CometChatUIKit.setLoggedInUser(user);
128
161
  if (user) {
129
162
  this.enableExtensions();
@@ -377,6 +410,8 @@ export class CometChatUIKit {
377
410
  static sendCustomMessage(
378
411
  message: CometChat.CustomMessage
379
412
  ): Promise<CometChat.CustomMessage | CometChat.BaseMessage> {
413
+ // Gate read once per send. OFF: today's code below, unchanged.
414
+ if (isOfflineOn()) return CometChatUIKit.sendOnOfflinePath(message, "custom");
380
415
  return new Promise((resolve, reject) => {
381
416
  if (!message.getMuid()) {
382
417
  message.setMuid(String(getUnixTimestampInMilliseconds()));
@@ -406,6 +441,7 @@ export class CometChatUIKit {
406
441
  static sendMediaMessage(
407
442
  message: CometChat.MediaMessage
408
443
  ): Promise<CometChat.MediaMessage | CometChat.BaseMessage> {
444
+ if (isOfflineOn()) return CometChatUIKit.sendOnOfflinePath(message, "media");
409
445
  return new Promise((resolve, reject) => {
410
446
  if (!message.getMuid()) {
411
447
  message.setMuid(String(getUnixTimestampInMilliseconds()));
@@ -461,6 +497,7 @@ export class CometChatUIKit {
461
497
  static sendTextMessage(
462
498
  message: CometChat.TextMessage
463
499
  ): Promise<CometChat.TextMessage | CometChat.BaseMessage> {
500
+ if (isOfflineOn()) return CometChatUIKit.sendOnOfflinePath(message, "text");
464
501
  return new Promise((resolve, reject) => {
465
502
  if (!message?.getMuid()) {
466
503
  message.setMuid(String(getUnixTimestampInMilliseconds()));
@@ -486,6 +523,52 @@ export class CometChatUIKit {
486
523
  });
487
524
  }
488
525
 
526
+ /**
527
+ * The statics on the offline (ON) path (README §3.4): the same compose-time preparation and
528
+ * `inprogress` announcement as today, then the kit's one send helper. Resolves on the server's
529
+ * ack (also after the message was queued), rejects on a final failure, a direct error or a
530
+ * discard, and never because the message was queued. When the session ends (logout, user
531
+ * switch) or a cache reset loses the queued send, it rejects once, quietly, with
532
+ * `ERROR_OFFLINE_MESSAGE_DISCARDED`, as Android does: no error event, no toast. The SDK's state
533
+ * comes from callbacks; the kit never stamps `metadata.error` here.
534
+ */
535
+ private static sendOnOfflinePath(message: any, kind: "text" | "media" | "custom"): Promise<any> {
536
+ try {
537
+ if (!message?.getMuid?.()) message.setMuid(String(getUnixTimestampInMilliseconds()));
538
+ if (!message?.getSender?.() && this.loggedInUser) message.setSender(this.loggedInUser);
539
+ if (kind === "media") {
540
+ let hasAttachment;
541
+ try {
542
+ hasAttachment = message.getAttachment();
543
+ } catch (error) {
544
+ hasAttachment = undefined;
545
+ }
546
+ if (hasAttachment == undefined) {
547
+ const file = message["files"]?.[0];
548
+ if (file == undefined) {
549
+ return Promise.reject(
550
+ new CometChat.CometChatException({
551
+ code: "Invalid Media message object",
552
+ message: "file object not found.",
553
+ })
554
+ );
555
+ }
556
+ const attachmentObject: CometChat.Attachment = new CometChat.Attachment(file);
557
+ attachmentObject.setName(file["name"]);
558
+ attachmentObject.setExtension((file["name"].lastIndexOf(".") + 1).toString());
559
+ attachmentObject.setMimeType(file["type"]);
560
+ attachmentObject.setSize(0);
561
+ attachmentObject.setUrl(file["uri"]);
562
+ message.setAttachment(attachmentObject);
563
+ }
564
+ }
565
+ } catch (error) {
566
+ return Promise.reject(error);
567
+ }
568
+ CometChatUIKitHelper.onMessageSent(message, messageStatus.inprogress);
569
+ return sendWithStatePromise(message, kind);
570
+ }
571
+
489
572
  static getDataSource() {
490
573
  return ChatConfigurator.getDataSource();
491
574
  }
@@ -1,6 +1,18 @@
1
1
  import { CallingExtension } from "../../calls";
2
2
  import { ExtensionsDataSource } from "../framework";
3
3
 
4
+ /**
5
+ * Offline settings handed through to the Chat SDK's `OfflineConfig` (README §4). The kit's own
6
+ * structural type, so it never names an SDK type an older SDK lacks; an SDK `OfflineConfig`
7
+ * instance is accepted as is. The kit never reads it back: it asks the SDK
8
+ * (`CometChat.isOfflineEnabled()`) at each decision instead.
9
+ */
10
+ export interface UIKitOfflineSettings {
11
+ /** Turn offline messaging on. Default `false`. */
12
+ enabled?: boolean;
13
+ [option: string]: unknown;
14
+ }
15
+
4
16
  export type UIKitSettings = {
5
17
  appId: string;
6
18
  region: string;
@@ -15,6 +27,12 @@ export type UIKitSettings = {
15
27
  extensions?: ExtensionsDataSource[];
16
28
  roles?: string[];
17
29
  callingExtension?: CallingExtension;
30
+ /**
31
+ * Offline messaging (Chat SDK 4.2.1 or later). `true`, an options object, or an SDK
32
+ * `OfflineConfig`. Absent ⇒ offline off and the kit behaves exactly as before. Ignored by an
33
+ * SDK below 4.2.1, which the kit runs online only.
34
+ */
35
+ offline?: boolean | UIKitOfflineSettings | object;
18
36
  };
19
37
 
20
38
  export function UIKitSettings({
@@ -31,6 +49,7 @@ export function UIKitSettings({
31
49
  extensions,
32
50
  roles,
33
51
  callingExtension,
52
+ offline,
34
53
  }: UIKitSettings): UIKitSettings {
35
54
  return {
36
55
  appId,
@@ -46,5 +65,6 @@ export function UIKitSettings({
46
65
  extensions,
47
66
  roles,
48
67
  callingExtension,
68
+ offline,
49
69
  };
50
70
  }
@@ -51,6 +51,16 @@ type MessageUIEvents = {
51
51
  };
52
52
  export class MessageUIEventListener {
53
53
  ccMessageSent?: Function = undefined;
54
+ /**
55
+ * Offline (additive): an own message's send state changed — `{ message, state, reason? }` with
56
+ * `state` one of "sending" | "sent" | "failed" | "discarded". Never emitted with offline off.
57
+ */
58
+ ccMessageSendStateChanged?: Function = undefined;
59
+ /**
60
+ * Offline (additive): the SDK rebuilt its offline cache — `{ reason, pendingMessagesLost }`
61
+ * (`null` when the count is unknown). Never emitted with offline off.
62
+ */
63
+ ccOfflineCacheReset?: Function = undefined;
54
64
  ccMessageEdited?: Function = undefined;
55
65
  ccMessageDeleted?: Function = undefined;
56
66
  ccMessageRead?: Function = undefined;
@@ -3,6 +3,8 @@ import { CometChatUIEvents } from "./CometChatUIEvents";
3
3
  import { CometChatConversationEvents } from "./conversations";
4
4
  import { CometChatGroupsEvents } from "./groups";
5
5
  import { MessageEvents } from "./messages";
6
+ import { OfflineMessageEvents } from "./offline";
7
+ import type { MessageSendState, MessageSendStateChangedEvent, OfflineCacheResetEvent } from "./offline";
6
8
 
7
9
  export {
8
10
  CometChatConversationEvents,
@@ -10,4 +12,6 @@ export {
10
12
  CometChatUIEventHandler,
11
13
  CometChatUIEvents,
12
14
  MessageEvents,
15
+ OfflineMessageEvents,
13
16
  };
17
+ export type { MessageSendState, MessageSendStateChangedEvent, OfflineCacheResetEvent };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Public offline events (README §4, additive). Emitted on the existing message event bus
3
+ * (`CometChatUIEventHandler.addMessageListener`) next to `ccMessageSent`, which keeps its meaning
4
+ * and fires once per transition. Never emitted with offline off. `MessageEvents` is not extended,
5
+ * so an exhaustive switch over it keeps compiling.
6
+ */
7
+ export const OfflineMessageEvents = Object.freeze({
8
+ ccMessageSendStateChanged: "ccMessageSendStateChanged",
9
+ ccOfflineCacheReset: "ccOfflineCacheReset",
10
+ } as const);
11
+
12
+ /** An own message's send state on the offline path. */
13
+ export type MessageSendState = "sending" | "sent" | "failed" | "discarded";
14
+
15
+ export interface MessageSendStateChangedEvent {
16
+ /** The SDK message (read `getMessageStatus()` / `getLocalMessageId()` on it for details). */
17
+ message: object;
18
+ state: MessageSendState;
19
+ /** The SDK's `MessageFailureReason` for "failed" / "discarded". */
20
+ reason?: string;
21
+ }
22
+
23
+ export interface OfflineCacheResetEvent {
24
+ /** The SDK's `OfflineCacheResetReason`. */
25
+ reason: string;
26
+ /** Unsent messages lost, or `null` when the SDK could not count them. */
27
+ pendingMessagesLost: number | null;
28
+ }
@@ -14,6 +14,7 @@ import { CometChatTheme } from "../../../theme/type";
14
14
  import { deepMerge } from "../../helper/helperFunctions";
15
15
  import { unescapeTypedMentionTokensInTree } from "../../utils/mentionTokens";
16
16
  import { getCometChatTranslation } from "../../resources/CometChatLocalizeNew/LocalizationManager";
17
+ import { readListPage } from "../../offline/twoPhase";
17
18
 
18
19
  const t = getCometChatTranslation();
19
20
 
@@ -395,10 +396,11 @@ export class CometChatMentionsFormatter extends CometChatTextFormatter {
395
396
 
396
397
  fetchNext(freshCall?: boolean): void | null {
397
398
  if (this.getUniqueUsersList().size >= this.limit) return;
399
+ // Offline ON: two-phase (cached people without a keyword; a keyword has no cache, so offline
400
+ // it answers empty, never an error). Offline OFF: today's Promise fetch.
398
401
  this.searchRequest?.fetchNext &&
399
- this.searchRequest
400
- ?.fetchNext()
401
- .then((users: CometChat.User[]) => {
402
+ readListPage<CometChat.User>(this.searchRequest, "next")
403
+ .then(({ rows: users }) => {
402
404
  let structuredData = this.convertCCUsersToSuggestionsItem(users);
403
405
  // Deduplicate: only add items whose id is not already present
404
406
  const existingIds = new Set(this.searchData.map((item) => item.id));
@@ -37,6 +37,8 @@ import {
37
37
  import { CometChatMessageOption } from "../modals/CometChatMessageOption";
38
38
  import { CometChatMessageTemplate } from "../modals/CometChatMessageTemplate";
39
39
  import { CometChatConversationUtils, attachmentCountLabel } from "../utils/conversationUtils";
40
+ import { downloadAttachments, shouldUseCachedMedia } from "../offline/media";
41
+ import { OfflineMediaBubble } from "../offline/OfflineMediaBubble";
40
42
  import { CometChatAudioBubble } from "../views/CometChatAudioBubble";
41
43
  import { CometChatDeletedBubble } from "../views/CometChatDeletedBubble";
42
44
  import { CometChatFileBubble } from "../views/CometChatFileBubble";
@@ -828,9 +830,7 @@ export class MessageDataSource implements DataSource {
828
830
  onPress: (message: CometChat.BaseMessage) => {
829
831
  const mediaMsg = message as CometChat.MediaMessage;
830
832
  const attachments = mediaMsg.getAttachments?.() ?? [];
831
- attachments.forEach((att) => {
832
- FileManager?.checkAndDownload(att.getUrl(), att.getName(), () => {});
833
- });
833
+ downloadAttachments(attachments, (uri, name) => FileManager?.checkAndDownload(uri, name, () => {}));
834
834
  },
835
835
  };
836
836
  }
@@ -1923,9 +1923,12 @@ export class MessageDataSource implements DataSource {
1923
1923
  // DD §9 — enableMultipleAttachments=false on the message list → deprecated single-attachment bubble.
1924
1924
  if (additionalParams?.enableMultipleAttachments === false) {
1925
1925
  const attachment = message.getAttachment();
1926
- return ChatConfigurator.dataSource.getAudioMessageBubble(
1927
- attachment.getUrl(), attachment.getName(), {}, message, theme
1926
+ const bubble = (url: string) => ChatConfigurator.dataSource.getAudioMessageBubble(
1927
+ url, attachment?.getName() ?? "", {}, message, theme
1928
1928
  );
1929
+ return shouldUseCachedMedia() && attachment
1930
+ ? <OfflineMediaBubble attachment={attachment} playable>{bubble}</OfflineMediaBubble>
1931
+ : bubble(attachment?.getUrl());
1929
1932
  }
1930
1933
  // §8.1a — audio rendering matches WhatsApp:
1931
1934
  // • SHARED / picked audio file (no audioType) → the headphone-chip + filename player
@@ -1946,13 +1949,20 @@ export class MessageDataSource implements DataSource {
1946
1949
  return <CometChatVoiceNoteBubble message={message} theme={theme} additionalParams={additionalParams} />;
1947
1950
  }
1948
1951
  const attachment = message.getAttachment();
1949
- return ChatConfigurator.dataSource.getAudioMessageBubble(
1950
- attachment.getUrl(),
1951
- attachment.getName(),
1952
+ const bubble = (url: string) => ChatConfigurator.dataSource.getAudioMessageBubble(
1953
+ url,
1954
+ attachment?.getName() ?? "",
1952
1955
  {},
1953
1956
  message,
1954
1957
  theme
1955
1958
  );
1959
+ // A message just sent with offline support on is the SDK's pending copy of the composed message,
1960
+ // which has no attachment until the upload is acknowledged (getAttachment() is null). Draw it as
1961
+ // the optimistic bubble is drawn with offline off (no source yet), not through the offline media
1962
+ // wrapper; the acknowledged message replaces it. Same guard on every single-attachment bubble.
1963
+ return shouldUseCachedMedia() && attachment
1964
+ ? <OfflineMediaBubble attachment={attachment} playable>{bubble}</OfflineMediaBubble>
1965
+ : bubble(attachment?.getUrl());
1956
1966
  }
1957
1967
  getVideoMessageContentView(
1958
1968
  message: CometChat.MediaMessage,
@@ -1963,9 +1973,12 @@ export class MessageDataSource implements DataSource {
1963
1973
  // DD §9 — enableMultipleAttachments=false → deprecated single-attachment video bubble.
1964
1974
  if (additionalParams?.enableMultipleAttachments === false) {
1965
1975
  const attachment = message.getAttachment();
1966
- return ChatConfigurator.dataSource.getVideoMessageBubble(
1967
- attachment.getUrl(), attachment.getUrl(), message, theme
1976
+ const bubble = (url: string) => ChatConfigurator.dataSource.getVideoMessageBubble(
1977
+ url, attachment?.getUrl(), message, theme
1968
1978
  );
1979
+ return shouldUseCachedMedia() && attachment
1980
+ ? <OfflineMediaBubble attachment={attachment} playable>{bubble}</OfflineMediaBubble>
1981
+ : bubble(attachment?.getUrl());
1969
1982
  }
1970
1983
  // A VIDEO message ALWAYS renders the video grid — no fallback to a file list. Any attachment that
1971
1984
  // isn't a video (image / audio / file) shows a "no preview" placeholder cell inside the grid, and
@@ -1982,9 +1995,12 @@ export class MessageDataSource implements DataSource {
1982
1995
  // DD §9 — enableMultipleAttachments=false → deprecated single-attachment image bubble.
1983
1996
  if (additionalParams?.enableMultipleAttachments === false) {
1984
1997
  const attachment = message.getAttachment();
1985
- return ChatConfigurator.dataSource.getImageMessageBubble(
1986
- attachment.getUrl(), caption, message, theme
1998
+ const bubble = (url: string) => ChatConfigurator.dataSource.getImageMessageBubble(
1999
+ url, caption, message, theme
1987
2000
  );
2001
+ return shouldUseCachedMedia() && attachment
2002
+ ? <OfflineMediaBubble attachment={attachment}>{bubble}</OfflineMediaBubble>
2003
+ : bubble(attachment?.getUrl());
1988
2004
  }
1989
2005
  // An IMAGE message ALWAYS renders the image grid — no fallback to a file list. Any attachment that
1990
2006
  // can't be previewed (unsupported format / load error) shows a "no preview" placeholder cell inside
@@ -2000,9 +2016,13 @@ export class MessageDataSource implements DataSource {
2000
2016
  // DD §9 — enableMultipleAttachments=false → deprecated single-attachment file bubble.
2001
2017
  if (additionalParams?.enableMultipleAttachments === false) {
2002
2018
  const attachment = message.getAttachment();
2003
- return ChatConfigurator.dataSource.getFileMessageBubble(
2004
- attachment.getUrl(), attachment.getName(), {}, message, theme
2019
+ const bubble = (url: string) => ChatConfigurator.dataSource.getFileMessageBubble(
2020
+ url, attachment?.getName() ?? "", {}, message, theme
2005
2021
  );
2022
+ // The file bubble names its download after the URL, so it keeps the URL (no cached source).
2023
+ return shouldUseCachedMedia() && attachment
2024
+ ? <OfflineMediaBubble attachment={attachment}>{() => bubble(attachment.getUrl())}</OfflineMediaBubble>
2025
+ : bubble(attachment?.getUrl());
2006
2026
  }
2007
2027
  // DD §9 (flag=true, default): the new FilesBubble renders 1..N — including a single file.
2008
2028
  return <CometChatFilesBubble message={message} theme={theme} additionalParams={additionalParams} />;
@@ -18,7 +18,9 @@ export {
18
18
  CometChatUIEventHandler,
19
19
  CometChatUIEvents,
20
20
  MessageEvents,
21
+ OfflineMessageEvents,
21
22
  } from "./events";
23
+ export type { MessageSendState, MessageSendStateChangedEvent, OfflineCacheResetEvent } from "./events";
22
24
 
23
25
  export type { DataSource } from "./framework";
24
26