@cometchat/chat-uikit-react-native 5.5.4 → 5.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatKeyboardModule.kt +101 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardDirectionWatcher.kt +64 -0
- package/android/src/main/java/com/reactnativecometchatuikit/KeyboardLanguageDirection.kt +44 -0
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +287 -49
- package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
- package/ios/CCLocalFileGuard.h +19 -0
- package/ios/CCLocalFileGuard.m +34 -0
- package/ios/CometChatKeyboardModule.m +9 -0
- package/ios/CometChatKeyboardModule.swift +71 -0
- package/ios/FileManager.m +70 -6
- package/ios/KeyboardLanguageDirection.swift +24 -0
- package/ios/RichTextEditorView.swift +253 -51
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/VideoManager.m +1 -1
- package/package.json +18 -3
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +41 -57
- package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +4 -1
- package/src/CometChatAIAssistantChatHistory/style.ts +5 -2
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +145 -63
- package/src/CometChatCompactMessageComposer/styles.ts +7 -7
- package/src/CometChatConversations/CometChatConversations.tsx +276 -147
- package/src/CometChatConversations/Skeleton.tsx +4 -1
- package/src/CometChatConversations/style.ts +1 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +39 -18
- package/src/CometChatGroupMembers/Skeleton.tsx +4 -1
- package/src/CometChatGroupMembers/style.ts +6 -4
- package/src/CometChatGroups/CometChatGroups.tsx +74 -58
- package/src/CometChatGroups/GroupsStyle.ts +1 -1
- package/src/CometChatGroups/Skeleton.tsx +4 -1
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +190 -96
- package/src/CometChatMessageComposer/styles.tsx +1 -1
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +28 -15
- package/src/CometChatMessageHeader/listners.ts +76 -56
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +8 -1
- package/src/CometChatMessageInformation/Skeleton.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +1465 -313
- package/src/CometChatMessageList/SwipeToReplyView.tsx +61 -0
- package/src/CometChatMessageList/style.ts +32 -32
- package/src/CometChatMessageList/swipeToReply.ts +25 -0
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +81 -10
- package/src/CometChatNotificationFeed/style.ts +1 -1
- package/src/CometChatNotificationFeed/utils.ts +17 -18
- package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +82 -3
- package/src/CometChatPinnedMessages/style.ts +5 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +2 -0
- package/src/CometChatRichTextEditor/index.tsx +3 -0
- package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +83 -15
- package/src/CometChatSavedMessages/style.ts +3 -3
- package/src/CometChatSearch/CometChatSearch.tsx +391 -136
- package/src/CometChatSearch/Skeleton.tsx +4 -1
- package/src/CometChatSearch/searchLabels.ts +26 -0
- package/src/CometChatSearch/style.ts +7 -7
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +34 -8
- package/src/CometChatThreadHeader/Header.tsx +2 -2
- package/src/CometChatUsers/CometChatUsers.tsx +10 -1
- package/src/CometChatUsers/Skeleton.tsx +4 -1
- package/src/CometChatUsers/style.ts +1 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +27 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +16 -4
- package/src/calls/CometChatCallLogs/Skeleton.tsx +4 -1
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +11 -3
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +10 -2
- package/src/extensions/CollaborativeBubble/style.ts +4 -4
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +1 -1
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +1 -1
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +11 -6
- package/src/extensions/LinkPreview/style.ts +6 -6
- package/src/extensions/Polls/Header.tsx +1 -1
- package/src/extensions/Polls/Polls.tsx +25 -12
- package/src/extensions/Polls/PollsBubble.tsx +10 -6
- package/src/extensions/Polls/style.ts +4 -4
- package/src/extensions/Stickers/CometChatStickerKeyboard/CometChatStickerKeyboard.tsx +2 -2
- package/src/extensions/Stickers/CometChatStickerKeyboard/Skeleton.tsx +1 -1
- package/src/extensions/Stickers/CometChatStickerKeyboard/style.ts +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +4 -2
- package/src/index.ts +11 -1
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +102 -2
- package/src/shared/CometChatUiKit/UIKitSettings.ts +28 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
- package/src/shared/events/index.ts +4 -0
- package/src/shared/events/offline.ts +28 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +18 -13
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +15 -7
- package/src/shared/formatters/CometChatTextFormatter.ts +11 -0
- package/src/shared/formatters/CometChatUrlsFormatter/index.tsx +7 -4
- package/src/shared/framework/MessageDataSource.tsx +51 -108
- package/src/shared/helper/LocalizedDateHelper.ts +64 -4
- package/src/shared/helper/helperFunctions.ts +71 -4
- package/src/shared/helper/keyboardDirection.ts +54 -0
- package/src/shared/helper/layoutDirection.ts +205 -0
- package/src/shared/helper/pluralRules.ts +67 -0
- package/src/shared/helper/textDirection.ts +118 -0
- package/src/shared/icons/Icon.tsx +37 -2
- package/src/shared/icons/components/format-list-numbered-rtl.tsx +15 -0
- package/src/shared/index.ts +2 -0
- package/src/shared/offline/OfflineHub.ts +651 -0
- package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
- package/src/shared/offline/OfflineViews.tsx +222 -0
- package/src/shared/offline/conversationPins.ts +137 -0
- package/src/shared/offline/conversations.ts +325 -0
- package/src/shared/offline/frameProbe.ts +24 -0
- package/src/shared/offline/gate.ts +94 -0
- package/src/shared/offline/groupActions.ts +81 -0
- package/src/shared/offline/identity.ts +162 -0
- package/src/shared/offline/index.ts +76 -0
- package/src/shared/offline/media.ts +247 -0
- package/src/shared/offline/notices.ts +84 -0
- package/src/shared/offline/reconcile.ts +296 -0
- package/src/shared/offline/searchOutcome.ts +62 -0
- package/src/shared/offline/send.ts +430 -0
- package/src/shared/offline/stateContract.ts +85 -0
- package/src/shared/offline/threadReplies.ts +125 -0
- package/src/shared/offline/twoPhase.ts +372 -0
- package/src/shared/offline/unsentActions.ts +168 -0
- package/src/shared/offline/useOfflineMediaUri.ts +87 -0
- package/src/shared/offline/useOfflineReconnect.ts +25 -0
- package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
- package/src/shared/offline/useOfflineUploadTray.ts +76 -0
- package/src/shared/offline/usePresenceHidden.ts +33 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/ar/translation.json +720 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +75 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +82 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +90 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +74 -3
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +74 -3
- package/src/shared/services/UploadQueueService.ts +106 -1
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +13 -12
- package/src/shared/utils/CometChatMessagePreview/style.ts +1 -1
- package/src/shared/utils/MessageReceiptUtils.ts +8 -0
- package/src/shared/utils/MessageUtils.tsx +14 -14
- package/src/shared/utils/PermissionUtil.ts +16 -5
- package/src/shared/utils/SavedMessagesHelper.ts +18 -1
- package/src/shared/utils/attachmentLimits.ts +3 -2
- package/src/shared/utils/catchUpCursor.ts +36 -0
- package/src/shared/utils/conversationUtils.ts +3 -5
- package/src/shared/utils/failedMessageRetry.ts +73 -0
- package/src/shared/utils/fileIconFontSize.ts +10 -0
- package/src/shared/utils/fileSizeLabel.ts +16 -0
- package/src/shared/utils/groupActionText.ts +75 -0
- package/src/shared/utils/messageIdentity.ts +38 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +12 -8
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +1 -1
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +5 -3
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +22 -17
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +45 -12
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +16 -10
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +20 -8
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +8 -4
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +6 -2
- package/src/shared/views/CometChatComposerErrorBanner.tsx +3 -1
- package/src/shared/views/CometChatConfirmDialog/CometChatConfirmDialog.tsx +8 -3
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +2 -2
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -3
- package/src/shared/views/CometChatEmojiKeyboard/emojis.ts +8 -8
- package/src/shared/views/CometChatEmojiKeyboard/style.ts +2 -2
- package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +65 -15
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +7 -3
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +56 -25
- package/src/shared/views/CometChatInlineAudioRecorder/CometChatInlineAudioRecorder.tsx +41 -21
- package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +7 -3
- package/src/shared/views/CometChatLinkConfirmPopup/CometChatLinkConfirmPopup.tsx +7 -3
- package/src/shared/views/CometChatList/CometChatList.tsx +478 -21
- package/src/shared/views/CometChatList/Header.tsx +5 -2
- package/src/shared/views/CometChatList/sectionLetter.ts +44 -0
- package/src/shared/views/CometChatList/styles.ts +7 -7
- package/src/shared/views/CometChatListItem/CometChatListItem.tsx +6 -4
- package/src/shared/views/CometChatMediaRecorder/CometChatAudioPlayer.tsx +16 -10
- package/src/shared/views/CometChatMediaRecorder/Timer.tsx +5 -1
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +43 -16
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +24 -4
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +19 -2
- package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +3 -2
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +59 -12
- package/src/shared/views/CometChatReactionList/ReactionListStyle.tsx +2 -2
- package/src/shared/views/CometChatReactionList/Skeleton.tsx +4 -1
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +6 -2
- package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +7 -3
- package/src/shared/views/CometChatReportDialog/style.ts +1 -1
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +1 -1
- package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +20 -13
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -2
- package/src/shared/views/CometChatSuggestionList/Skeleton.tsx +1 -1
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +29 -3
- package/src/shared/views/CometChatTooltipMenu/CometChatTooltipMenu.tsx +20 -30
- package/src/shared/views/CometChatTooltipMenu/tooltipPosition.ts +43 -0
- package/src/shared/views/CometChatVideoBubble/style.ts +2 -2
- package/src/shared/views/CometChatVideoPlayer/CometChatVideoPlayer.tsx +4 -1
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +58 -24
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
- package/src/shared/views/SenderLabel.tsx +41 -0
- package/src/theme/default/default.ts +1 -1
- package/src/theme/type.ts +17 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Internal entry point of the kit's offline support. Not part of the public API: integrators get
|
|
3
|
+
* `UIKitSettings.offline`, the additive events and `hideOfflineNotices` only.
|
|
4
|
+
*
|
|
5
|
+
* @internal
|
|
6
|
+
*/
|
|
7
|
+
import { hasOfflineSdk, offlineSdk } from "./gate";
|
|
8
|
+
import { clearPlayableShims } from "./media";
|
|
9
|
+
import { OfflineHub } from "./OfflineHub";
|
|
10
|
+
|
|
11
|
+
let mediaCleanupWired = false;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Start the hub after the SDK's own init resolved (both init entry points call this). Idempotent.
|
|
15
|
+
* `user` is the restored session's user, if any, so a later user switch is recognised.
|
|
16
|
+
*/
|
|
17
|
+
export function startOfflineSupport(user?: any): void {
|
|
18
|
+
const hub = OfflineHub.getInstance();
|
|
19
|
+
hub.start();
|
|
20
|
+
if (!mediaCleanupWired) {
|
|
21
|
+
mediaCleanupWired = true;
|
|
22
|
+
// Playable copies are per session: gone on logout, user switch and cache reset.
|
|
23
|
+
hub.session$.subscribe(() => {
|
|
24
|
+
clearPlayableShims();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (user) hub.onLogin(user);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Hand `UIKitSettings.offline` to the SDK's AppSettingsBuilder, untouched in meaning: an SDK
|
|
32
|
+
* `OfflineConfig` instance as is, `true`/an options object through `OfflineConfig.fromJson`.
|
|
33
|
+
* Nothing happens when the setting is absent or the SDK has no offline support.
|
|
34
|
+
*/
|
|
35
|
+
export function applyOfflineSetting(appSettingsBuilder: any, setting: unknown): void {
|
|
36
|
+
if (setting === undefined || setting === null) return;
|
|
37
|
+
try {
|
|
38
|
+
// Below the kit's SDK floor the config must not reach the SDK: 4.2.0 has setOfflineConfig,
|
|
39
|
+
// so it would queue and cache while the kit's screens act online (the half-on state).
|
|
40
|
+
if (!hasOfflineSdk()) {
|
|
41
|
+
// The peer stays `"*"` on purpose (see `gate.ts`), so an app can pair this kit with an SDK
|
|
42
|
+
// that has no offline support and keep working online. Asking for offline on such an SDK
|
|
43
|
+
// then did nothing at all and said nothing, which reads as the kit ignoring the setting.
|
|
44
|
+
// `__DEV__` keeps this out of release bundles.
|
|
45
|
+
if (__DEV__) {
|
|
46
|
+
console.warn(
|
|
47
|
+
"[CometChatUIKit] `offline` was set, but offline support needs Chat SDK React Native " +
|
|
48
|
+
"4.2.1 or later. The kit is running online only. Upgrade " +
|
|
49
|
+
"@cometchat/chat-sdk-react-native to 4.2.1+ to enable it."
|
|
50
|
+
);
|
|
51
|
+
}
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (typeof appSettingsBuilder?.setOfflineConfig !== "function") return;
|
|
55
|
+
if (typeof setting === "object" && typeof (setting as any).isEnabled === "function") {
|
|
56
|
+
appSettingsBuilder.setOfflineConfig(setting);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
const OfflineConfig = offlineSdk().OfflineConfig;
|
|
60
|
+
if (typeof OfflineConfig?.fromJson === "function") {
|
|
61
|
+
appSettingsBuilder.setOfflineConfig(OfflineConfig.fromJson(setting));
|
|
62
|
+
} else if (typeof setting === "boolean" && typeof appSettingsBuilder.offline === "function") {
|
|
63
|
+
appSettingsBuilder.offline(setting);
|
|
64
|
+
}
|
|
65
|
+
} catch (e) {
|
|
66
|
+
console.warn("[CometChatUIKit] offline setting was not applied", e);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Before the SDK's init: only what must already be listening when the SDK starts (see the hub). */
|
|
71
|
+
export function prepareOfflineSupport(): void {
|
|
72
|
+
OfflineHub.getInstance().listenForStartAnnouncements();
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
export { OfflineHub } from "./OfflineHub";
|
|
76
|
+
export { isOfflineOn } from "./gate";
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Media on the offline (ON) path (README §3.8, UIK-MEDIA-01): an attachment's source is the
|
|
3
|
+
* SDK's cached copy (`attachment.getLocalPath()`, stamped by the SDK on cached messages) when it
|
|
4
|
+
* has one, else its URL, as today. With offline off, or the SDK's media caching OFF, the URL is
|
|
5
|
+
* returned untouched and nothing else runs: no lookup, no timer, no file.
|
|
6
|
+
*
|
|
7
|
+
* The kit keeps no media cache of its own. The single exception is the per-session "playable"
|
|
8
|
+
* shim: the SDK stores cached files without an extension and AVFoundation will not play a video
|
|
9
|
+
* or audio file without one, so the kit copies such a file once, with the right extension, into
|
|
10
|
+
* `Caches/cometchat-offline-playable/<uid>/`. The folder is wiped on the first shim of a process
|
|
11
|
+
* (so a previous session's copies never survive) and on logout, user switch and cache reset.
|
|
12
|
+
* `react-native-fs` is an optional peer; without it the cached path is used as is.
|
|
13
|
+
*
|
|
14
|
+
* @internal
|
|
15
|
+
*/
|
|
16
|
+
import { isOfflineOn, mediaCachingMode, offlineSdk, sdkConnected } from "./gate";
|
|
17
|
+
import { OfflineHub } from "./OfflineHub";
|
|
18
|
+
|
|
19
|
+
/** Whether media should come from the SDK's cache for this render. */
|
|
20
|
+
export function shouldUseCachedMedia(): boolean {
|
|
21
|
+
return isOfflineOn() && mediaCachingMode() !== "OFF";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
function toFileUri(path: string): string {
|
|
25
|
+
if (/^[a-z][a-z0-9+.-]*:\/\//i.test(path)) return path;
|
|
26
|
+
return path.startsWith("/") ? `file://${path}` : path;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** The SDK's cached file for an attachment, as a URI, or `""`. */
|
|
30
|
+
export function cachedPathOf(attachment: any): string {
|
|
31
|
+
try {
|
|
32
|
+
const local = attachment?.getLocalPath?.();
|
|
33
|
+
return typeof local === "string" && local ? toFileUri(local) : "";
|
|
34
|
+
} catch {
|
|
35
|
+
return "";
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The source for an attachment: with offline off this is exactly `attachment.getUrl()`; on the ON
|
|
41
|
+
* path the SDK's cached copy wins over the URL.
|
|
42
|
+
*/
|
|
43
|
+
export function offlineAttachmentUri(attachment: any): string {
|
|
44
|
+
if (!shouldUseCachedMedia()) return attachment?.getUrl?.();
|
|
45
|
+
return cachedPathOf(attachment) || attachment?.getUrl?.();
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Media the device has no copy of and cannot reach now (offline ON, not connected): the bubble
|
|
50
|
+
* shows "Available when online" (AC-12.3). `false` with offline off and with media caching off.
|
|
51
|
+
*/
|
|
52
|
+
export function isMediaOutOfReach(attachment: any): boolean {
|
|
53
|
+
return shouldUseCachedMedia() && !cachedPathOf(attachment) && sdkConnected() === false;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* What Download / Share / "Download all" act on (BEH-MEDIA-18). With offline off, or media caching
|
|
58
|
+
* off: the URL, exactly as before. On the ON path: the saved local file when there is one (never
|
|
59
|
+
* re-fetched), else the URL while connected, else `unavailable` (show "Available when online").
|
|
60
|
+
*/
|
|
61
|
+
export type MediaActionSource =
|
|
62
|
+
| { kind: "remote"; uri: string }
|
|
63
|
+
| { kind: "local"; uri: string }
|
|
64
|
+
| { kind: "unavailable" };
|
|
65
|
+
|
|
66
|
+
export function mediaActionSource(attachment: any): MediaActionSource {
|
|
67
|
+
if (!shouldUseCachedMedia()) return { kind: "remote", uri: attachment?.getUrl?.() };
|
|
68
|
+
const local = cachedPathOf(attachment);
|
|
69
|
+
if (local) return { kind: "local", uri: local };
|
|
70
|
+
if (sdkConnected() === false) return { kind: "unavailable" };
|
|
71
|
+
return { kind: "remote", uri: attachment?.getUrl?.() };
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** Raise the kit's "Available when online" notice for a Download / Share that cannot proceed. */
|
|
75
|
+
export function notifyMediaUnavailable(): void {
|
|
76
|
+
try {
|
|
77
|
+
OfflineHub.getInstance().notify({ kind: "media_available_when_online" });
|
|
78
|
+
} catch {
|
|
79
|
+
/* no hub: nothing to show */
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* "Download all": each attachment goes to `download` as its saved local file when offline support is
|
|
85
|
+
* on and it has one, else as its URL; one with neither (offline, no copy) is skipped and the
|
|
86
|
+
* "Available when online" notice is raised once. With offline off every URL is passed, as before.
|
|
87
|
+
*/
|
|
88
|
+
export function downloadAttachments(attachments: any[], download: (uri: string, name: string) => void): void {
|
|
89
|
+
let unavailable = false;
|
|
90
|
+
attachments.forEach((attachment) => {
|
|
91
|
+
const source = mediaActionSource(attachment);
|
|
92
|
+
if (source.kind === "unavailable") {
|
|
93
|
+
unavailable = true;
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
download(source.uri, attachment.getName());
|
|
97
|
+
});
|
|
98
|
+
if (unavailable) notifyMediaUnavailable();
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* A tap on media the device has no copy of, online: ask the SDK to download and cache it. Its media
|
|
103
|
+
* listener reports the file (the bubble re-resolves through `useOfflineMediaUri`). A no-op with
|
|
104
|
+
* offline off, media caching off, offline, or when a copy exists. Never throws or rejects.
|
|
105
|
+
*/
|
|
106
|
+
export function requestMediaDownload(attachment: any): boolean {
|
|
107
|
+
if (!shouldUseCachedMedia() || cachedPathOf(attachment) || sdkConnected() === false) return false;
|
|
108
|
+
const sdk = offlineSdk();
|
|
109
|
+
if (typeof sdk?.downloadMedia !== "function") return false;
|
|
110
|
+
// One download per item at a time: further touches while it runs do not ask again.
|
|
111
|
+
const key = downloadKeyOf(attachment);
|
|
112
|
+
if (downloadsInFlight.has(key)) return true;
|
|
113
|
+
try {
|
|
114
|
+
const result: any = sdk.downloadMedia(attachment);
|
|
115
|
+
if (result && typeof result.then === "function") {
|
|
116
|
+
downloadsInFlight.add(key);
|
|
117
|
+
const done = () => downloadsInFlight.delete(key);
|
|
118
|
+
result.then(done, done);
|
|
119
|
+
}
|
|
120
|
+
return true;
|
|
121
|
+
} catch {
|
|
122
|
+
return false;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
const downloadsInFlight = new Set<unknown>();
|
|
127
|
+
|
|
128
|
+
function downloadKeyOf(attachment: any): unknown {
|
|
129
|
+
let url: unknown;
|
|
130
|
+
try {
|
|
131
|
+
url = attachment?.getUrl?.() ?? attachment?.url;
|
|
132
|
+
} catch {
|
|
133
|
+
url = undefined;
|
|
134
|
+
}
|
|
135
|
+
return typeof url === "string" && url ? url : attachment;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
// ── Playable shim ───────────────────────────────────────────────────────────
|
|
139
|
+
|
|
140
|
+
const SHIM_FOLDER = "cometchat-offline-playable";
|
|
141
|
+
// The one-time wipe of stale copies, shared: every caller waits for it, so a copy made by one
|
|
142
|
+
// bubble is never deleted by another bubble's still-running wipe.
|
|
143
|
+
let shimRootClear: Promise<void> | null = null;
|
|
144
|
+
let shimsCreated = false;
|
|
145
|
+
|
|
146
|
+
const EXTENSION_BY_MIME: Record<string, string> = {
|
|
147
|
+
"video/mp4": "mp4",
|
|
148
|
+
"video/quicktime": "mov",
|
|
149
|
+
"video/x-m4v": "m4v",
|
|
150
|
+
"video/webm": "webm",
|
|
151
|
+
"video/3gpp": "3gp",
|
|
152
|
+
"audio/mpeg": "mp3",
|
|
153
|
+
"audio/mp3": "mp3",
|
|
154
|
+
"audio/mp4": "m4a",
|
|
155
|
+
"audio/x-m4a": "m4a",
|
|
156
|
+
"audio/m4a": "m4a",
|
|
157
|
+
"audio/aac": "aac",
|
|
158
|
+
"audio/wav": "wav",
|
|
159
|
+
"audio/x-wav": "wav",
|
|
160
|
+
"audio/ogg": "ogg",
|
|
161
|
+
};
|
|
162
|
+
|
|
163
|
+
function loadFs(): any {
|
|
164
|
+
try {
|
|
165
|
+
// Optional peer: Metro treats a try-wrapped require as an optional dependency.
|
|
166
|
+
const fs = require("react-native-fs");
|
|
167
|
+
return fs?.default ?? fs;
|
|
168
|
+
} catch {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
function hasExtension(path: string): boolean {
|
|
174
|
+
const last = path.split("?")[0].split("/").pop() ?? "";
|
|
175
|
+
return /\.[a-z0-9]{2,5}$/i.test(last);
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
function hashOf(text: string): string {
|
|
179
|
+
let h = 5381;
|
|
180
|
+
for (let i = 0; i < text.length; i++) h = ((h << 5) + h + text.charCodeAt(i)) | 0;
|
|
181
|
+
return (h >>> 0).toString(36);
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
function safeSegment(value: string): string {
|
|
185
|
+
return (value || "anonymous").replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/** Extension for a playable copy: from the attachment's own extension or mime type. */
|
|
189
|
+
export function playableExtensionOf(attachment: any): string {
|
|
190
|
+
const ext = String(attachment?.getExtension?.() ?? "").replace(/^\./, "").toLowerCase();
|
|
191
|
+
if (/^[a-z0-9]{2,5}$/.test(ext)) return ext;
|
|
192
|
+
const mime = String(attachment?.getMimeType?.() ?? "").toLowerCase();
|
|
193
|
+
return EXTENSION_BY_MIME[mime] ?? "";
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
/**
|
|
197
|
+
* A URI AVFoundation can play for the cached copy of `attachment`, or the cached URI as is when no
|
|
198
|
+
* copy is needed or possible. Only called on the ON path, with a cached path in hand.
|
|
199
|
+
*/
|
|
200
|
+
export async function playableUri(cachedUri: string, attachment: any, uid: string): Promise<string> {
|
|
201
|
+
if (!cachedUri.startsWith("file://") || hasExtension(cachedUri)) return cachedUri;
|
|
202
|
+
const ext = playableExtensionOf(attachment);
|
|
203
|
+
const fs = loadFs();
|
|
204
|
+
if (!ext || !fs?.CachesDirectoryPath) return cachedUri;
|
|
205
|
+
try {
|
|
206
|
+
const root = `${fs.CachesDirectoryPath}/${SHIM_FOLDER}`;
|
|
207
|
+
if (!shimRootClear) {
|
|
208
|
+
shimRootClear = (async () => {
|
|
209
|
+
if (await fs.exists(root)) await fs.unlink(root);
|
|
210
|
+
})().catch((e) => console.warn("[CometChatUIKit] could not remove stale playable copies", e));
|
|
211
|
+
}
|
|
212
|
+
await shimRootClear;
|
|
213
|
+
const dir = `${root}/${safeSegment(uid)}`;
|
|
214
|
+
const source = cachedUri.replace(/^file:\/\//, "");
|
|
215
|
+
const target = `${dir}/${hashOf(source)}.${ext}`;
|
|
216
|
+
if (!(await fs.exists(target))) {
|
|
217
|
+
await fs.mkdir(dir);
|
|
218
|
+
await fs.copyFile(source, target);
|
|
219
|
+
}
|
|
220
|
+
shimsCreated = true;
|
|
221
|
+
return `file://${target}`;
|
|
222
|
+
} catch (e) {
|
|
223
|
+
console.warn("[CometChatUIKit] playable copy failed; using the cached file", e);
|
|
224
|
+
return cachedUri;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/** Delete every playable copy (logout, user switch, cache reset). No-op if none was made. */
|
|
229
|
+
export async function clearPlayableShims(): Promise<void> {
|
|
230
|
+
if (!shimsCreated) return;
|
|
231
|
+
shimsCreated = false;
|
|
232
|
+
const fs = loadFs();
|
|
233
|
+
if (!fs?.CachesDirectoryPath) return;
|
|
234
|
+
try {
|
|
235
|
+
const root = `${fs.CachesDirectoryPath}/${SHIM_FOLDER}`;
|
|
236
|
+
if (await fs.exists(root)) await fs.unlink(root);
|
|
237
|
+
} catch (e) {
|
|
238
|
+
console.warn("[CometChatUIKit] could not remove playable copies", e);
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
/** Tests only. */
|
|
243
|
+
export function resetMediaShimStateForTests(): void {
|
|
244
|
+
shimRootClear = null;
|
|
245
|
+
shimsCreated = false;
|
|
246
|
+
downloadsInFlight.clear();
|
|
247
|
+
}
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Localized text for offline notices (README §4 strings). Keys with a count have a form per CLDR
|
|
3
|
+
* plural category (`_ONE` / `_OTHER` everywhere, plus `_ZERO` / `_TWO` / `_FEW` / `_MANY` where the
|
|
4
|
+
* language has them), picked by pluralCountLabel; `{count}` is replaced with the count in the
|
|
5
|
+
* language's digits.
|
|
6
|
+
*
|
|
7
|
+
* @internal
|
|
8
|
+
*/
|
|
9
|
+
import { pluralCountLabel } from "../helper/pluralRules";
|
|
10
|
+
import { Language } from "../resources/CometChatLocalizeNew/type";
|
|
11
|
+
import { OfflineNotice } from "./OfflineHub";
|
|
12
|
+
|
|
13
|
+
export type Translate = (key: string) => string;
|
|
14
|
+
|
|
15
|
+
export const OFFLINE_STRING_KEYS = Object.freeze({
|
|
16
|
+
notSentYet: "OFFLINE_MESSAGE_NOT_SENT_YET",
|
|
17
|
+
notSentTapToRetry: "OFFLINE_MESSAGE_NOT_SENT_TAP_TO_RETRY",
|
|
18
|
+
unsentMessageRemoved: "OFFLINE_UNSENT_MESSAGE_REMOVED",
|
|
19
|
+
messagesNotSent: "OFFLINE_MESSAGES_NOT_SENT",
|
|
20
|
+
unsentMessagesLost: "OFFLINE_UNSENT_MESSAGES_LOST",
|
|
21
|
+
unsentMessagesMaybeLost: "OFFLINE_UNSENT_MESSAGES_MAYBE_LOST",
|
|
22
|
+
queueFull: "OFFLINE_QUEUE_FULL",
|
|
23
|
+
fileTooLarge: "OFFLINE_FILE_TOO_LARGE",
|
|
24
|
+
connectToLoadMore: "OFFLINE_CONNECT_TO_LOAD_MORE",
|
|
25
|
+
connectToSearch: "OFFLINE_CONNECT_TO_SEARCH",
|
|
26
|
+
connectToSearchMessages: "OFFLINE_CONNECT_TO_SEARCH_MESSAGES",
|
|
27
|
+
connectToSearchSubtitle: "OFFLINE_CONNECT_TO_SEARCH_SUBTITLE",
|
|
28
|
+
connectToLoadUsers: "OFFLINE_CONNECT_TO_LOAD_USERS",
|
|
29
|
+
connectToLoadGroups: "OFFLINE_CONNECT_TO_LOAD_GROUPS",
|
|
30
|
+
connectToLoadChats: "OFFLINE_CONNECT_TO_LOAD_CHATS",
|
|
31
|
+
connectToLoadMembers: "OFFLINE_CONNECT_TO_LOAD_MEMBERS",
|
|
32
|
+
connectToLoadMessages: "OFFLINE_CONNECT_TO_LOAD_MESSAGES",
|
|
33
|
+
connectToLoadReactions: "OFFLINE_CONNECT_TO_LOAD_REACTIONS",
|
|
34
|
+
connectToLoadNotifications: "OFFLINE_CONNECT_TO_LOAD_NOTIFICATIONS",
|
|
35
|
+
mediaAvailableWhenOnline: "OFFLINE_MEDIA_AVAILABLE_WHEN_ONLINE",
|
|
36
|
+
sendInFlight: "OFFLINE_SEND_IN_FLIGHT",
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* `key` for `count` in `language`: pass the language `t` translates into (useCometChatTranslation's
|
|
41
|
+
* `language`); the default is the global language, which the provider sets a render later.
|
|
42
|
+
*/
|
|
43
|
+
export function localizedPlural(t: Translate, key: string, count: number, language?: Language): string {
|
|
44
|
+
return pluralCountLabel((k) => String(t(k) ?? ""), key, count, language);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function offlineNoticeText(notice: OfflineNotice, t: Translate, language?: Language): string {
|
|
48
|
+
switch (notice.kind) {
|
|
49
|
+
case "unsent_message_removed":
|
|
50
|
+
return t(OFFLINE_STRING_KEYS.unsentMessageRemoved);
|
|
51
|
+
case "queue_full":
|
|
52
|
+
return t(OFFLINE_STRING_KEYS.queueFull);
|
|
53
|
+
case "file_too_large_offline":
|
|
54
|
+
return t(OFFLINE_STRING_KEYS.fileTooLarge);
|
|
55
|
+
case "messages_not_sent":
|
|
56
|
+
return localizedPlural(t, OFFLINE_STRING_KEYS.messagesNotSent, notice.count ?? 1, language);
|
|
57
|
+
case "unsent_messages_lost":
|
|
58
|
+
return localizedPlural(t, OFFLINE_STRING_KEYS.unsentMessagesLost, notice.count ?? 1, language);
|
|
59
|
+
case "unsent_messages_maybe_lost":
|
|
60
|
+
return t(OFFLINE_STRING_KEYS.unsentMessagesMaybeLost);
|
|
61
|
+
case "send_in_flight":
|
|
62
|
+
return t(OFFLINE_STRING_KEYS.sendInFlight);
|
|
63
|
+
case "media_available_when_online":
|
|
64
|
+
return t(OFFLINE_STRING_KEYS.mediaAvailableWhenOnline);
|
|
65
|
+
default:
|
|
66
|
+
return "";
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Whether a notice offers Copy: a removed unsent TEXT message. */
|
|
71
|
+
export function noticeCopyText(notice: OfflineNotice): string | null {
|
|
72
|
+
if (notice.kind !== "unsent_message_removed") return null;
|
|
73
|
+
const text = notice.message?.getText?.() ?? notice.message?.text;
|
|
74
|
+
return typeof text === "string" && text.length > 0 ? text : null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* ENG-41199 (plan §3.10): an edit, delete or reaction on a sent message that failed on the offline
|
|
79
|
+
* (ON) path shows today's error notice, the kit's existing "Something went wrong" text. `null` with
|
|
80
|
+
* offline off: that failure stays today's (`onError` only).
|
|
81
|
+
*/
|
|
82
|
+
export function offlineMutationErrorText(offlineOn: boolean, t: Translate): string | null {
|
|
83
|
+
return offlineOn ? t("SOMETHING_WRONG") : null;
|
|
84
|
+
}
|