@cometchat/chat-uikit-react-native 5.3.10 → 5.4.1

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 (132) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +52 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
  3. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +95 -8
  4. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +300 -7
  5. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +2 -1
  6. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +85 -47
  7. package/ios/CometChatClipboardModule.m +11 -0
  8. package/ios/CometChatClipboardModule.swift +41 -0
  9. package/ios/FileManager.m +201 -39
  10. package/ios/RichTextEditorView.swift +367 -8
  11. package/ios/RichTextEditorViewManager.m +1 -0
  12. package/ios/SoundPlayer.m +18 -6
  13. package/package.json +10 -7
  14. package/react-native-cometchat-ui-kit.podspec +1 -0
  15. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
  16. package/src/CometChatConversations/CometChatConversations.tsx +19 -6
  17. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
  18. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
  19. package/src/CometChatMessageList/CometChatMessageList.tsx +463 -54
  20. package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
  21. package/src/CometChatMessageList/components/MessageListItem.tsx +30 -17
  22. package/src/CometChatMessageList/style.ts +33 -5
  23. package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +13 -0
  24. package/src/CometChatRichTextEditor/index.tsx +25 -0
  25. package/src/CometChatSearch/CometChatSearch.tsx +296 -154
  26. package/src/calls/CallingExtension.tsx +19 -13
  27. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +20 -1
  28. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +20 -9
  29. package/src/index.ts +39 -0
  30. package/src/shared/CometChatUiKit/CometChatUIKit.ts +40 -34
  31. package/src/shared/base/Types.ts +3 -0
  32. package/src/shared/constants/UIKitConstants.ts +15 -1
  33. package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +3 -2
  34. package/src/shared/framework/DataSource.ts +14 -4
  35. package/src/shared/framework/DataSourceDecorator.tsx +17 -8
  36. package/src/shared/framework/MessageDataSource.tsx +307 -60
  37. package/src/shared/helper/useToast.tsx +29 -0
  38. package/src/shared/icons/components/audio-file-type.tsx +11 -22
  39. package/src/shared/icons/components/document-file-type.tsx +11 -24
  40. package/src/shared/icons/components/image-file-type.tsx +12 -21
  41. package/src/shared/icons/components/link-file-type.tsx +25 -0
  42. package/src/shared/icons/components/pdf-file-type.tsx +11 -22
  43. package/src/shared/icons/components/presentation-file-type.tsx +11 -24
  44. package/src/shared/icons/components/spreadsheet-file-type.tsx +11 -24
  45. package/src/shared/icons/components/text-file-type.tsx +11 -21
  46. package/src/shared/icons/components/unknown-file-type.tsx +21 -25
  47. package/src/shared/icons/components/video-file-type.tsx +11 -24
  48. package/src/shared/icons/components/zip-file-type.tsx +11 -24
  49. package/src/shared/icons/icon-mapping.tsx +2 -0
  50. package/src/shared/index.ts +28 -0
  51. package/src/shared/modals/AttachmentPickerConfiguration.ts +13 -0
  52. package/src/shared/modals/SelectedAttachment.ts +65 -0
  53. package/src/shared/modals/UploadState.ts +10 -0
  54. package/src/shared/modals/index.ts +4 -0
  55. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +42 -1
  56. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +42 -1
  57. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +43 -2
  58. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +43 -2
  59. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +43 -2
  60. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +43 -2
  61. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -2
  62. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -2
  63. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -2
  64. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +43 -2
  65. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +43 -2
  66. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -2
  67. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +43 -2
  68. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +43 -2
  69. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -2
  70. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -2
  71. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +43 -2
  72. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +43 -2
  73. package/src/shared/services/UploadQueueService.ts +145 -0
  74. package/src/shared/services/index.ts +2 -0
  75. package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +44 -19
  76. package/src/shared/utils/MessageUtils.tsx +13 -4
  77. package/src/shared/utils/attachmentLimits.ts +156 -0
  78. package/src/shared/utils/audioPlaybackCoordinator.ts +28 -0
  79. package/src/shared/utils/batchMediaContext.tsx +30 -0
  80. package/src/shared/utils/conversationUtils.ts +26 -4
  81. package/src/shared/utils/elementType.tsx +38 -0
  82. package/src/shared/utils/groupAttachments.ts +93 -0
  83. package/src/shared/utils/index.ts +8 -0
  84. package/src/shared/utils/openMultiFileChooser.ts +123 -0
  85. package/src/shared/utils/partitionAttachmentsByKind.ts +44 -0
  86. package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +28 -0
  87. package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +16 -0
  88. package/src/shared/views/ClipboardPasteHandler/index.ts +2 -0
  89. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
  90. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +32 -0
  91. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.tsx +90 -0
  92. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +276 -0
  93. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +827 -0
  94. package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTray.tsx +110 -0
  95. package/src/shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe.tsx +53 -0
  96. package/src/shared/views/CometChatAttachmentPreview/index.ts +8 -0
  97. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +305 -0
  98. package/src/shared/views/CometChatAttachmentViewer/index.ts +2 -0
  99. package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +71 -74
  100. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +587 -0
  101. package/src/shared/views/CometChatAudiosBubble/index.ts +2 -0
  102. package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +31 -20
  103. package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +182 -0
  104. package/src/shared/views/CometChatCaptionText/index.ts +2 -0
  105. package/src/shared/views/CometChatComposerErrorBanner.tsx +83 -0
  106. package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +141 -0
  107. package/src/shared/views/CometChatConversationStarter/index.ts +2 -0
  108. package/src/shared/views/CometChatConversationSummary/CometChatConversationSummary.tsx +155 -0
  109. package/src/shared/views/CometChatConversationSummary/index.ts +2 -0
  110. package/src/shared/views/CometChatFileBubble/style.ts +6 -4
  111. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +316 -0
  112. package/src/shared/views/CometChatFilesBubble/index.ts +2 -0
  113. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +323 -0
  114. package/src/shared/views/CometChatImagesBubble/index.ts +2 -0
  115. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +425 -0
  116. package/src/shared/views/CometChatMediaViewer/index.ts +2 -0
  117. package/src/shared/views/CometChatMediaViewer/mediaViewerUtils.ts +30 -0
  118. package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
  119. package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +1 -0
  120. package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +172 -0
  121. package/src/shared/views/CometChatSmartReplies/index.ts +2 -0
  122. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
  123. package/src/shared/views/CometChatVideoBubble/style.ts +3 -3
  124. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +441 -0
  125. package/src/shared/views/CometChatVideosBubble/index.ts +2 -0
  126. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +78 -0
  127. package/src/shared/views/CometChatVoiceNoteBubble/index.ts +2 -0
  128. package/src/shared/views/index.ts +37 -1
  129. package/src/theme/CometChatThemeHelper.ts +8 -0
  130. package/src/theme/default/color/dark.ts +9 -0
  131. package/src/theme/default/color/light.ts +10 -0
  132. package/src/theme/type.ts +73 -0
@@ -0,0 +1,156 @@
1
+ import { useEffect, useState } from 'react';
2
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
3
+ import {
4
+ DEFAULT_MAX_ATTACHMENT_COUNT,
5
+ DEFAULT_MAX_FILE_SIZE,
6
+ } from '../modals/AttachmentPickerConfiguration';
7
+
8
+ export interface FileUploadLimits {
9
+ /** Max number of attachments per message (server `file.count.max`). */
10
+ fileCountMax: number;
11
+ /** Max size **PER FILE**, in bytes (server `file.size.max`). NOT a combined/batch
12
+ * total — size is validated per file (design doc §6.1). */
13
+ fileSizeMax: number;
14
+ }
15
+
16
+ /**
17
+ * Ultimate fallback when the SDK getter is unavailable (older SDK) or errors.
18
+ * Kept in parity with the SDK's own DEFAULT_VALUES (10 files / 100 MB per file).
19
+ */
20
+ const DEFAULTS: FileUploadLimits = {
21
+ fileCountMax: DEFAULT_MAX_ATTACHMENT_COUNT,
22
+ fileSizeMax: DEFAULT_MAX_FILE_SIZE,
23
+ };
24
+
25
+ // Server limits don't change mid-session, so memoize the single fetch.
26
+ let cached: Promise<FileUploadLimits> | null = null;
27
+
28
+ /**
29
+ * Server-authoritative upload limits. `fileCountMax` comes from the SDK's
30
+ * `CometChat.getMaxAttachmentCount()` (reads `file.count.max` from cached app settings — the
31
+ * same source the SDK's own validation uses, so UIKit and SDK can't disagree on count).
32
+ * `fileSizeMax` has NO public SDK getter — the SDK enforces `file.size.max` internally — so it
33
+ * stays on the DEFAULT here; it feeds only the "X MB" rejection toast, never enforcement.
34
+ * `fileSizeMax` is PER FILE. Never rejects — resolves to DEFAULTS if the getter is missing
35
+ * (older SDK) or fails. Memoized for the session.
36
+ */
37
+ export function getFileUploadLimits(): Promise<FileUploadLimits> {
38
+ if (!cached) {
39
+ const getCount = (CometChat as unknown as {
40
+ getMaxAttachmentCount?: () => Promise<number>;
41
+ }).getMaxAttachmentCount;
42
+ cached =
43
+ typeof getCount === 'function'
44
+ ? getCount()
45
+ .then((count) => ({
46
+ fileCountMax: count || DEFAULTS.fileCountMax,
47
+ fileSizeMax: DEFAULTS.fileSizeMax,
48
+ }))
49
+ .catch(() => DEFAULTS)
50
+ : Promise.resolve(DEFAULTS);
51
+ }
52
+ return cached;
53
+ }
54
+
55
+ /**
56
+ * React hook for render-time access to the upload limits (e.g. a "N / max"
57
+ * capacity hint). Returns DEFAULTS until the async fetch resolves.
58
+ */
59
+ export function useFileUploadLimits(): FileUploadLimits {
60
+ const [limits, setLimits] = useState<FileUploadLimits>(DEFAULTS);
61
+ useEffect(() => {
62
+ let alive = true;
63
+ getFileUploadLimits().then((l) => {
64
+ if (alive) setLimits(l);
65
+ });
66
+ return () => {
67
+ alive = false;
68
+ };
69
+ }, []);
70
+ return limits;
71
+ }
72
+
73
+ /**
74
+ * Effective limit = tighten-only: a developer override may only make the limit
75
+ * SMALLER than the server value, never larger (`min(dev, server)`).
76
+ */
77
+ export function clampToServer(devValue: number | undefined, serverValue: number): number {
78
+ return devValue == null ? serverValue : Math.min(devValue, serverValue);
79
+ }
80
+
81
+ /**
82
+ * Gate a freshly picked/pasted batch by COUNT: if the pick would exceed the remaining slots, REJECT
83
+ * THE WHOLE PICK (drop all of it) and toast; otherwise accept it in full. Reject-all (NOT trim-to-N)
84
+ * is deliberate — each pick is atomic, so we never silently keep some of the user's chosen files and
85
+ * drop others (which the user didn't choose). The media picker already hard-caps selection natively;
86
+ * this gate is the enforcement for the pickers the OS can't cap (documents/audio) and the paste path.
87
+ *
88
+ * Per-file SIZE is NOT checked here — the SDK is the single source of truth for it. An oversized file
89
+ * is staged, then the SDK rejects it with ERR_FILE_SIZE_EXCEEDED → the composer's onFileRejected marks
90
+ * the tile "Upload failed" and shows the size toast. Shared by the compact + full composers' picker AND
91
+ * paste paths so the count logic can't silently re-diverge (it had drifted into three copies).
92
+ *
93
+ * `t` returns the raw template (we interpolate with `.replace`); `showToast` shows one line.
94
+ */
95
+ export function acceptPickedAttachments<T>(
96
+ files: T[],
97
+ opts: { maxCount: number; existingCount: number },
98
+ notify: { showToast: (msg: string) => void; t: (key: string) => string }
99
+ ): T[] {
100
+ const { maxCount, existingCount } = opts;
101
+ const { showToast, t } = notify;
102
+
103
+ const remaining = Math.max(0, maxCount - existingCount);
104
+ if (files.length > remaining) {
105
+ // Over the limit → drop the ENTIRE pick (already-staged files are untouched).
106
+ showToast(t('ATTACHMENT_COUNT_EXCEEDED').replace('{max}', String(maxCount)));
107
+ return [];
108
+ }
109
+ return files;
110
+ }
111
+
112
+ /**
113
+ * Toast explaining WHY an attachment was rejected — shown when the user taps the errored tile (we
114
+ * don't auto-toast on rejection, to avoid spam when several files fail). Maps the SDK error code to a
115
+ * friendly, named message; size is the common case and gets the server's exact per-file max. Shared
116
+ * by both composers so the mapping stays in one place.
117
+ */
118
+ export async function toastAttachmentRejection(
119
+ att: { file: { name: string }; errorCode?: string },
120
+ notify: { showToast: (msg: string) => void; t: (key: string) => string }
121
+ ): Promise<void> {
122
+ const { showToast, t } = notify;
123
+ const code = att.errorCode;
124
+
125
+ // Too big — show the server's exact per-file size cap.
126
+ if (code === 'ERR_FILE_SIZE_EXCEEDED') {
127
+ const { fileSizeMax } = await getFileUploadLimits();
128
+ showToast(
129
+ t('ATTACHMENT_SIZE_EXCEEDED')
130
+ .replace('{max}', `${Math.round(fileSizeMax / 1024 / 1024)} MB`)
131
+ );
132
+ return;
133
+ }
134
+
135
+ // Server declined this specific file at presign — a disallowed content type (e.g. .md).
136
+ // The presign endpoint enforces the app's allowed-file-type policy per file, so both the generic
137
+ // rejection AND the permission/policy denial for a picked file mean "this file type isn't allowed".
138
+ if (code === 'ERR_PRESIGN_REJECTED' || code === 'ERR_PERMISSION_DENIED') {
139
+ showToast(t('UNSUPPORTED_FILE_TYPE'));
140
+ return;
141
+ }
142
+
143
+ // Account-level billing denial → uploads aren't available on this plan (not a per-file-type issue).
144
+ if (code === 'ERR_BILLING') {
145
+ showToast(t('ATTACHMENT_UPLOAD_UNAVAILABLE'));
146
+ return;
147
+ }
148
+
149
+ // Couldn't read the file / its size.
150
+ if (code === 'ERR_INVALID_FILE_OBJECT') {
151
+ showToast(t('ATTACHMENT_SIZE_UNKNOWN').replace('{name}', att.file.name));
152
+ return;
153
+ }
154
+
155
+ showToast(t('ATTACHMENT_UPLOAD_FAILED'));
156
+ }
@@ -0,0 +1,28 @@
1
+ /**
2
+ * Cross-bubble audio coordinator — makes audio playback behave like WhatsApp: only ONE clip
3
+ * plays at a time, and starting/resuming a clip pauses whatever else was playing AT ITS CURRENT
4
+ * POSITION (so it can be resumed from where it left off), across BOTH the recorded voice-note
5
+ * bubble and the shared/gallery audio bubble.
6
+ *
7
+ * The native SoundPlayer is a single instance, so it physically plays one clip; this coordinator
8
+ * keeps every bubble's UI in sync with that reality. A bubble that is about to (re)play announces
9
+ * its url; every other bubble reacts by pausing-in-place. Announce runs synchronously BEFORE the
10
+ * native play() call, so the others are already paused when the native stop/replace happens.
11
+ */
12
+ type Listener = (activeUrl: string) => void;
13
+
14
+ const listeners = new Set<Listener>();
15
+
16
+ export const audioPlaybackCoordinator = {
17
+ /** Subscribe a bubble; returns an unsubscribe fn. */
18
+ subscribe(fn: Listener): () => void {
19
+ listeners.add(fn);
20
+ return () => {
21
+ listeners.delete(fn);
22
+ };
23
+ },
24
+ /** Announce that `activeUrl` is (re)starting — every OTHER bubble pauses in place. */
25
+ announcePlay(activeUrl: string): void {
26
+ listeners.forEach((fn) => fn(activeUrl));
27
+ },
28
+ };
@@ -0,0 +1,30 @@
1
+ import { createContext } from 'react';
2
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
3
+
4
+ // ---------------------------------------------------------------------------
5
+ // §8.2 — Batch-spanning fullscreen viewer.
6
+ //
7
+ // After the §7 fan-out, a batch's images and videos live on SEPARATE messages
8
+ // (one Images message + one Videos message sharing metadata.batchId). Tapping a
9
+ // tile should open a pager over the WHOLE batch's image+video set, not just the
10
+ // tapped message's. The message list is the only layer that can see sibling
11
+ // messages, so it provides this lookup via context; a media bubble consumes it
12
+ // and falls back to its own attachments when no provider is present (e.g. threads).
13
+ // ---------------------------------------------------------------------------
14
+
15
+ export interface BatchMediaResult {
16
+ /** Union of image+video attachments across the batch, in batchIndex order. */
17
+ items: CometChat.Attachment[];
18
+ /** Index in `items` where the queried message's own media begins. */
19
+ offsetForMessage: number;
20
+ }
21
+
22
+ export interface BatchMediaContextValue {
23
+ /**
24
+ * Returns the batch-spanning image+video list for `message`, or null when the
25
+ * message is not part of a multi-message batch (caller should use its own media).
26
+ */
27
+ getBatchImageVideoItems: (message: CometChat.MediaMessage) => BatchMediaResult | null;
28
+ }
29
+
30
+ export const CometChatBatchMediaContext = createContext<BatchMediaContextValue | null>(null);
@@ -10,6 +10,28 @@ import { getCometChatTranslation } from "../resources/CometChatLocalizeNew/Local
10
10
 
11
11
  const t = getCometChatTranslation();
12
12
 
13
+ // "N Photos / Videos / Audios / Files" for a media message, keyed by its COARSE type (image/video/audio/
14
+ // file) — never a generic "N attachments". File is the default. One source of truth for the conversation
15
+ // list, the reply/edit preview and the composer overline, so they always read the same.
16
+ export function attachmentCountLabel(type: string, count: number): string {
17
+ const n = String(count);
18
+ switch (type) {
19
+ case "image": return t("PREVIEW_PHOTOS_COUNT").replace("{count}", n);
20
+ case "video": return t("PREVIEW_VIDEOS_COUNT").replace("{count}", n);
21
+ case "audio": return t("PREVIEW_AUDIOS_COUNT").replace("{count}", n);
22
+ default: return t("PREVIEW_FILES_COUNT").replace("{count}", n);
23
+ }
24
+ }
25
+
26
+ // A single media message can carry a caption (you typed one when sending one photo/video/file). Show it
27
+ // after the kind label — "Photo · <caption>" — mirroring the multi-attachment subtitle. Empty → nothing.
28
+ // (Multi-attachment messages are summarized upstream in getLastConversationMessage.)
29
+ function captionSuffix(message: CometChat.BaseMessage): string {
30
+ const raw = typeof (message as any).getCaption === "function" ? (message as any).getCaption() : "";
31
+ const caption = typeof raw === "string" ? raw.trim() : "";
32
+ return caption ? ` · ${caption}` : "";
33
+ }
34
+
13
35
  export class CometChatConversationUtils {
14
36
  static getLastMessage(conversation: CometChat.Conversation): CometChat.BaseMessage | undefined {
15
37
  let msg = conversation?.getLastMessage && conversation?.getLastMessage();
@@ -98,13 +120,13 @@ export class CometChatConversationUtils {
98
120
  msgText = (lastMessage as CometChat.TextMessage).getText();
99
121
  break;
100
122
  case "image":
101
- return getMessagePreviewInternal("photo-fill", t('PHOTOS'), {theme});
123
+ return getMessagePreviewInternal("photo-fill", t('PHOTOS') + captionSuffix(lastMessage), {theme});
102
124
  case "audio":
103
- return getMessagePreviewInternal("mic-fill", t('MESSAGE_AUDIO'), {theme});
125
+ return getMessagePreviewInternal("mic-fill", t('MESSAGE_AUDIO') + captionSuffix(lastMessage), {theme});
104
126
  case "video":
105
- return getMessagePreviewInternal("videocam-fill", t("MESSAGE_VIDEO"), {theme});
127
+ return getMessagePreviewInternal("videocam-fill", t("MESSAGE_VIDEO") + captionSuffix(lastMessage), {theme});
106
128
  case "file":
107
- return getMessagePreviewInternal("description-fill", t("MESSAGE_FILE"), {theme});
129
+ return getMessagePreviewInternal("description-fill", t("MESSAGE_FILE") + captionSuffix(lastMessage), {theme});
108
130
  }
109
131
  } else if (
110
132
  lastMessage.getCategory() == (CometChat.CATEGORY_CUSTOM as CometChat.MessageCategory)
@@ -0,0 +1,38 @@
1
+ import { Text, View } from "react-native";
2
+
3
+ /**
4
+ * Identity checks for react-native's `View` / `Text` that survive a wrapped JSX runtime.
5
+ *
6
+ * We ship raw `.tsx`, so the *consumer's* babel compiles our source. A build that
7
+ * substitutes the JSX runtime — NativeWind (`react-native-css-interop`) being the common
8
+ * case — swaps every element's type for an equivalent wrapper (`CssInterop.View`). A bare
9
+ * `element.type === View` then silently returns false, and rich-text bubbles lose their
10
+ * colour and truncation (ENG-38093).
11
+ *
12
+ * The fix is to stop assuming what a `View` element looks like and ask the runtime that is
13
+ * actually in effect. Because these probes are compiled by the same pipeline as the code
14
+ * whose elements we inspect, they resolve to whatever identity that pipeline produces.
15
+ *
16
+ * The probes must be written as JSX. `React.createElement` is deliberately NOT equivalent:
17
+ * css-interop wraps only the JSX runtime and re-exports `createElement` untouched, so
18
+ * building the probe that way would capture the unwrapped identity and defeat the purpose.
19
+ *
20
+ * With no wrapper present these constants are simply `View` / `Text`, so the checks behave
21
+ * exactly as the original strict comparison did — no behaviour change for consumers who
22
+ * don't transform our JSX.
23
+ */
24
+ const RUNTIME_VIEW = (<View />).type;
25
+ const RUNTIME_TEXT = (<Text />).type;
26
+
27
+ /**
28
+ * True when `el` is a react-native `View` element.
29
+ *
30
+ * The `=== View` arm is a fallback for elements built outside our own compilation unit —
31
+ * e.g. a consumer's custom `CometChatTextFormatter` returning a plain `<View>` tree.
32
+ */
33
+ export const isViewElement = (el: any): boolean =>
34
+ el?.type === RUNTIME_VIEW || el?.type === View;
35
+
36
+ /** True when `el` is a react-native `Text` element. Mirrors {@link isViewElement}. */
37
+ export const isTextElement = (el: any): boolean =>
38
+ el?.type === RUNTIME_TEXT || el?.type === Text;
@@ -0,0 +1,93 @@
1
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
2
+
3
+ export interface AttachmentGroups {
4
+ mediaAttachments: CometChat.Attachment[];
5
+ audioAttachments: CometChat.Attachment[];
6
+ fileAttachments: CometChat.Attachment[];
7
+ }
8
+
9
+ const EMPTY: AttachmentGroups = { mediaAttachments: [], audioAttachments: [], fileAttachments: [] };
10
+
11
+ /**
12
+ * True when a message carries MORE THAN ONE attachment. After the §7 fan-out a message
13
+ * is single-kind (all images / all videos / all audio / all files), so this is the
14
+ * dispatch predicate the content-view routers use to pick the per-type multi-attachment
15
+ * bubble (ImagesBubble / VideosBubble / AudiosBubble / FilesBubble) over the legacy
16
+ * single-attachment bubble. It is NOT a distinct wire/SDK type — the coarse message type
17
+ * stays `image` / `video` / `audio` / `file`.
18
+ */
19
+ export function isGalleryMessage(message: CometChat.MediaMessage): boolean {
20
+ const atts = message?.getAttachments?.() ?? [];
21
+ return Array.isArray(atts) && atts.length > 1;
22
+ }
23
+
24
+ function getAttachmentsFromMetadata(
25
+ message: CometChat.MediaMessage
26
+ ): CometChat.Attachment[] {
27
+ const meta = message.getMetadata?.() as Record<string, unknown> | null;
28
+ if (!meta || !Array.isArray(meta.attachments)) return [];
29
+
30
+ // Filter out any null/undefined/non-object entries before constructing Attachment instances
31
+ // (a deleted message's metadata may contain malformed attachment data)
32
+ const validItems = (meta.attachments as unknown[]).filter(
33
+ (a): a is Record<string, unknown> => a != null && typeof a === 'object'
34
+ );
35
+ if (validItems.length === 0) return [];
36
+
37
+ // Reconstruct Attachment objects from the plain-object fallback in metadata
38
+ const list = validItems.map((a) => new CometChat.Attachment(a));
39
+ return list;
40
+ }
41
+
42
+ export function groupAttachments(
43
+ message: CometChat.MediaMessage
44
+ ): AttachmentGroups {
45
+ // Guard: deleted messages or action messages may not have attachment data
46
+ if (!message || message.getDeletedBy?.()) return EMPTY;
47
+
48
+ try {
49
+ // Primary path: SDK-native data.attachments (set via setAttachments / server response)
50
+ let attachments: CometChat.Attachment[] = message.getAttachments?.() ?? [];
51
+
52
+ if (attachments.length === 0) {
53
+ const meta = message.getMetadata?.() as Record<string, unknown> | null;
54
+ const metaList =
55
+ meta?.attachments && Array.isArray(meta.attachments) && meta.attachments.length > 0
56
+ ? getAttachmentsFromMetadata(message)
57
+ : [];
58
+
59
+ if (metaList.length > 0) {
60
+ attachments = metaList;
61
+ } else {
62
+ // Last resort: single attachment from the primary message data slot
63
+ const single = message.getAttachment?.();
64
+ attachments = single ? [single] : [];
65
+ }
66
+ } else {
67
+ // Filter out any Attachment instances that have no URL (malformed SDK response)
68
+ attachments = attachments.filter(att => att != null && typeof att.getUrl === 'function');
69
+ }
70
+
71
+ const isVisual = (a: CometChat.Attachment) => {
72
+ const mime = a.getMimeType?.() ?? '';
73
+ return mime.startsWith('image/') || mime.startsWith('video/');
74
+ };
75
+
76
+ const isAudio = (a: CometChat.Attachment) =>
77
+ (a.getMimeType?.() ?? '').startsWith('audio/');
78
+
79
+ // Decision 4.5 — preserve pick/insertion order within the media grid (no videos-first
80
+ // sort). getAttachments() already reflects the order the attachments were added.
81
+ const mediaAttachments = attachments.filter(isVisual);
82
+ // TODO (decision 3.2/4.1, blocked by 8.6 audio-tile design): picked audio should live
83
+ // IN the media grid, not as a standalone section. Kept separate until the tile design lands.
84
+ const audioAttachments = attachments.filter(isAudio);
85
+ // Decision 4.8 — files are always their own section at the bottom, regardless of pick order.
86
+ const fileAttachments = attachments.filter((a) => !isVisual(a) && !isAudio(a));
87
+
88
+ return { mediaAttachments, audioAttachments, fileAttachments };
89
+ } catch {
90
+ // Never crash the conversation list or message list over attachment parsing
91
+ return EMPTY;
92
+ }
93
+ }
@@ -11,3 +11,11 @@ export {
11
11
  getMentionRangeAtCursor,
12
12
  stripMarkdown,
13
13
  };
14
+
15
+ // Multiple Attachment Support — U3
16
+ export { openMultiFileChooser } from './openMultiFileChooser';
17
+ export type { PickedFile } from './openMultiFileChooser';
18
+
19
+ // Multiple Attachment Support — U7
20
+ export { groupAttachments } from './groupAttachments';
21
+ export type { AttachmentGroups } from './groupAttachments';
@@ -0,0 +1,123 @@
1
+ import { NativeModules, Platform } from 'react-native';
2
+ import { DEFAULT_MAX_ATTACHMENT_COUNT } from '../modals/AttachmentPickerConfiguration';
3
+
4
+ const { FileManager } = NativeModules;
5
+
6
+ export type PickedFile = {
7
+ uri: string;
8
+ name: string;
9
+ type: string;
10
+ size: number;
11
+ };
12
+
13
+ export async function openMultiFileChooser(
14
+ pickerType: 'media' | 'document' | 'camera' | 'audio',
15
+ existingCount: number,
16
+ maxAttachmentCount?: number,
17
+ allowedMimeTypes?: string[],
18
+ allowMultipleSelection?: boolean
19
+ ): Promise<PickedFile[]> {
20
+ const max = maxAttachmentCount ?? DEFAULT_MAX_ATTACHMENT_COUNT;
21
+
22
+ // allowMultipleSelection === false → cap the pick at ONE file. Otherwise: how many MORE files this pick
23
+ // may add (server count limit − already staged), clamped to ≥ 1 so the native media picker always gets a
24
+ // valid cap even at capacity. Only the MEDIA picker honors the cap natively (iOS PHPicker.selectionLimit,
25
+ // Android 13+ EXTRA_PICK_IMAGES_MAX); doc/audio pickers ignore it, so mapAndFilter also trims to 1 below.
26
+ const singleSelect = allowMultipleSelection === false;
27
+ const remaining = singleSelect ? 1 : Math.max(1, max - existingCount);
28
+
29
+ // The picker ALWAYS opens (no at-capacity block, so the Attach button never feels broken). We return
30
+ // the FULL picked set — the composer's acceptPickedAttachments REJECTS the whole over-limit pick and
31
+ // shows the §6.3 count toast; that reject-all is the hard enforcement for pickers the OS can't cap.
32
+
33
+ try {
34
+ if (pickerType === 'camera') {
35
+ const file = await openCameraNative();
36
+ if (!file) return [];
37
+ return mapAndFilter([file], allowedMimeTypes, allowMultipleSelection);
38
+ }
39
+
40
+ if (pickerType === 'media') {
41
+ // Both platforms support multi-select: Android uses gallery picker, iOS uses PHPickerViewController
42
+ const files = await openFileChooserMultiNative('image', remaining);
43
+ return mapAndFilter(files, allowedMimeTypes, allowMultipleSelection);
44
+ }
45
+
46
+ if (pickerType === 'audio') {
47
+ // Multi-select audio: iOS document picker (public.audio), Android ACTION_OPEN_DOCUMENT (audio/*).
48
+ // Both already set allowsMultipleSelection / EXTRA_ALLOW_MULTIPLE natively.
49
+ const files = await openFileChooserMultiNative('audio', remaining);
50
+ return mapAndFilter(files, allowedMimeTypes, allowMultipleSelection);
51
+ }
52
+
53
+ // document — multi-select on both platforms via openFileChooserMulti
54
+ const files = await openFileChooserMultiNative('file', remaining);
55
+ return mapAndFilter(files, allowedMimeTypes, allowMultipleSelection);
56
+ } catch {
57
+ return [];
58
+ }
59
+ }
60
+
61
+ function openCameraNative(): Promise<PickedFile | null> {
62
+ return new Promise(resolve => {
63
+ if (Platform.OS === 'ios') {
64
+ FileManager.openCamera('image', (result: any) => {
65
+ resolve(toPickedFile(result));
66
+ });
67
+ } else {
68
+ FileManager.openCamera('image', 50, (result: any) => {
69
+ resolve(toPickedFile(result));
70
+ });
71
+ }
72
+ });
73
+ }
74
+
75
+ function openFileChooserMultiNative(fileType: string, maxSelection: number): Promise<PickedFile[]> {
76
+ return new Promise(resolve => {
77
+ FileManager.openFileChooserMulti(fileType, maxSelection, (result: any) => {
78
+ if (!result) { resolve([]); return; }
79
+ const items: any[] = Array.isArray(result) ? result : [result];
80
+ resolve(
81
+ items
82
+ .filter((f: any) => f && !f.error && f.uri)
83
+ .map((f: any) => toPickedFile(f)!)
84
+ );
85
+ });
86
+ });
87
+ }
88
+
89
+ function toPickedFile(f: any): PickedFile | null {
90
+ if (!f || f.error || !f.uri) return null;
91
+ // Prefer local file copy (fileCopyUri) over content URI so the SDK gets a stable file:// path
92
+ const uri = (f.fileCopyUri ?? f.uri) as string;
93
+ return {
94
+ uri,
95
+ name: f.name ?? 'file',
96
+ type: f.type ?? 'application/octet-stream',
97
+ size: f.size ?? 0,
98
+ };
99
+ }
100
+
101
+ function mapAndFilter(
102
+ files: PickedFile[],
103
+ allowedMimeTypes?: string[],
104
+ allowMultipleSelection?: boolean
105
+ ): PickedFile[] {
106
+ let out = files.filter(f => f.uri.length > 0);
107
+
108
+ if (allowedMimeTypes && allowedMimeTypes.length > 0) {
109
+ out = out.filter(f => allowedMimeTypes.includes(f.type));
110
+ }
111
+
112
+ // allowMultipleSelection === false → single-file pick. The media picker enforces this via its cap; the
113
+ // OS doc/audio pickers can't be capped to 1, so keep only the first file here.
114
+ if (allowMultipleSelection === false) {
115
+ out = out.slice(0, 1);
116
+ }
117
+
118
+ // §6.1 — NO size gate here. Per-file size is server-authoritative and enforced by the SDK
119
+ // (a file over file.size.max is rejected with ERR_FILE_SIZE_EXCEEDED → onFileRejected). There is
120
+ // NO combined/batch total cap — size is validated per file, never as a message total.
121
+
122
+ return out;
123
+ }
@@ -0,0 +1,44 @@
1
+ import { CometChat } from '@cometchat/chat-sdk-react-native';
2
+ import { MessageTypeConstants } from '../constants/UIKitConstants';
3
+
4
+ export interface AttachmentKindGroup {
5
+ /** The `MediaMessage` type for this group's fanned-out message. */
6
+ type: string;
7
+ attachments: CometChat.Attachment[];
8
+ }
9
+
10
+ /**
11
+ * Design doc §7 fan-out — partition completed attachments into per-kind groups in the
12
+ * fixed display order **Images → Videos → Audios → Files**, one group per non-empty kind.
13
+ * Each group becomes ONE `MediaMessage` on send.
14
+ *
15
+ * Audio routing (§7/§8.1a): **picker audio is its own `type=audio` group** (NO
16
+ * `audioType` metadata), so a picked/shared audio file renders with the WhatsApp-style
17
+ * headphone+filename bubble (`CometChatAudiosBubble`) — NOT a file card. Recorder voice
18
+ * notes are a separate send flow tagged `audioType="voice_note"` (rendered by the WAVEFORM
19
+ * bubble, `CometChatVoiceNoteBubble` / `CometChatAudioBubble`); they never appear in the
20
+ * tray, so no voice-note group is produced here.
21
+ */
22
+ export function partitionAttachmentsByKind(
23
+ attachments: CometChat.Attachment[]
24
+ ): AttachmentKindGroup[] {
25
+ const image: CometChat.Attachment[] = [];
26
+ const video: CometChat.Attachment[] = [];
27
+ const audio: CometChat.Attachment[] = [];
28
+ const file: CometChat.Attachment[] = [];
29
+
30
+ for (const a of attachments) {
31
+ const mime = a.getMimeType?.() ?? '';
32
+ if (mime.startsWith('image/')) image.push(a);
33
+ else if (mime.startsWith('video/')) video.push(a);
34
+ else if (mime.startsWith('audio/')) audio.push(a); // picker audio → audio player bubble
35
+ else file.push(a); // documents + everything else → files
36
+ }
37
+
38
+ return [
39
+ { type: MessageTypeConstants.image, attachments: image },
40
+ { type: MessageTypeConstants.video, attachments: video },
41
+ { type: MessageTypeConstants.audio, attachments: audio },
42
+ { type: MessageTypeConstants.file, attachments: file },
43
+ ].filter((g) => g.attachments.length > 0);
44
+ }
@@ -0,0 +1,28 @@
1
+ import NativeCometChatClipboardModule from './NativeCometChatClipboardModule';
2
+ import type { ClipboardImageResult } from './NativeCometChatClipboardModule';
3
+
4
+ export type { ClipboardImageResult };
5
+
6
+ export const ClipboardPasteHandler = {
7
+ isAvailable(): boolean {
8
+ return !!NativeCometChatClipboardModule;
9
+ },
10
+
11
+ async hasImage(): Promise<boolean> {
12
+ if (!NativeCometChatClipboardModule) return false;
13
+ try {
14
+ return await NativeCometChatClipboardModule.hasImageInClipboard();
15
+ } catch {
16
+ return false;
17
+ }
18
+ },
19
+
20
+ async getImage(): Promise<ClipboardImageResult | null> {
21
+ if (!NativeCometChatClipboardModule) return null;
22
+ try {
23
+ return await NativeCometChatClipboardModule.getClipboardImage();
24
+ } catch {
25
+ return null;
26
+ }
27
+ },
28
+ };
@@ -0,0 +1,16 @@
1
+ import { NativeModules } from 'react-native';
2
+
3
+ export interface ClipboardImageResult {
4
+ uri: string;
5
+ mimeType: string;
6
+ size: number;
7
+ name: string;
8
+ }
9
+
10
+ interface NativeCometChatClipboardModuleSpec {
11
+ hasImageInClipboard(): Promise<boolean>;
12
+ getClipboardImage(): Promise<ClipboardImageResult | null>;
13
+ }
14
+
15
+ const { CometChatClipboardModule } = NativeModules;
16
+ export default CometChatClipboardModule as NativeCometChatClipboardModuleSpec | undefined;
@@ -0,0 +1,2 @@
1
+ export { ClipboardPasteHandler } from './ClipboardPasteHandler';
2
+ export type { ClipboardImageResult } from './NativeCometChatClipboardModule';
@@ -46,6 +46,7 @@ const OptionListView = ({
46
46
  return (
47
47
  <Pressable
48
48
  key={id}
49
+ testID={`ActionSheet.${id}`}
49
50
  onPress={onPress}
50
51
  onPressIn={() => setIsPressed(true)}
51
52
  onPressOut={() => setIsPressed(false)}
@@ -0,0 +1,32 @@
1
+ import { CometChatTheme } from '../../../theme/type';
2
+
3
+ export const getAttachmentPreviewStyle = (
4
+ color: CometChatTheme['color'],
5
+ spacing: CometChatTheme['spacing']
6
+ ) => ({
7
+ container: {
8
+ paddingVertical: spacing.padding.p2,
9
+ borderTopWidth: 1,
10
+ borderTopColor: color.neutral200,
11
+ backgroundColor: color.background1,
12
+ },
13
+ itemContainer: {
14
+ width: 72,
15
+ height: 72,
16
+ borderRadius: spacing.radius.r2,
17
+ margin: spacing.margin.m1,
18
+ overflow: 'hidden' as const,
19
+ backgroundColor: color.neutral200,
20
+ },
21
+ removeButton: {
22
+ position: 'absolute' as const,
23
+ top: 4,
24
+ right: 4,
25
+ width: 18,
26
+ height: 18,
27
+ borderRadius: 9,
28
+ backgroundColor: 'rgba(0,0,0,0.55)',
29
+ justifyContent: 'center' as const,
30
+ alignItems: 'center' as const,
31
+ },
32
+ });