@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.
- package/android/src/main/java/com/reactnativecometchatuikit/CometChatClipboardModule.kt +52 -0
- package/android/src/main/java/com/reactnativecometchatuikit/CometchatUiKitPackage.java +1 -0
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +95 -8
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +300 -7
- package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorViewManager.kt +2 -1
- package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +85 -47
- package/ios/CometChatClipboardModule.m +11 -0
- package/ios/CometChatClipboardModule.swift +41 -0
- package/ios/FileManager.m +201 -39
- package/ios/RichTextEditorView.swift +367 -8
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/SoundPlayer.m +18 -6
- package/package.json +10 -7
- package/react-native-cometchat-ui-kit.podspec +1 -0
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
- package/src/CometChatConversations/CometChatConversations.tsx +19 -6
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
- package/src/CometChatMessageList/CometChatMessageList.tsx +463 -54
- package/src/CometChatMessageList/SEARCH_NAV_SLOWNESS_FINDINGS_AND_FIX.md +313 -0
- package/src/CometChatMessageList/components/MessageListItem.tsx +30 -17
- package/src/CometChatMessageList/style.ts +33 -5
- package/src/CometChatRichTextEditor/RichTextEditorViewNativeComponent.ts +13 -0
- package/src/CometChatRichTextEditor/index.tsx +25 -0
- package/src/CometChatSearch/CometChatSearch.tsx +296 -154
- package/src/calls/CallingExtension.tsx +19 -13
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +20 -1
- package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +20 -9
- package/src/index.ts +39 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +40 -34
- package/src/shared/base/Types.ts +3 -0
- package/src/shared/constants/UIKitConstants.ts +15 -1
- package/src/shared/formatters/CometChatRichTextFormatter/index.tsx +3 -2
- package/src/shared/framework/DataSource.ts +14 -4
- package/src/shared/framework/DataSourceDecorator.tsx +17 -8
- package/src/shared/framework/MessageDataSource.tsx +307 -60
- package/src/shared/helper/useToast.tsx +29 -0
- package/src/shared/icons/components/audio-file-type.tsx +11 -22
- package/src/shared/icons/components/document-file-type.tsx +11 -24
- package/src/shared/icons/components/image-file-type.tsx +12 -21
- package/src/shared/icons/components/link-file-type.tsx +25 -0
- package/src/shared/icons/components/pdf-file-type.tsx +11 -22
- package/src/shared/icons/components/presentation-file-type.tsx +11 -24
- package/src/shared/icons/components/spreadsheet-file-type.tsx +11 -24
- package/src/shared/icons/components/text-file-type.tsx +11 -21
- package/src/shared/icons/components/unknown-file-type.tsx +21 -25
- package/src/shared/icons/components/video-file-type.tsx +11 -24
- package/src/shared/icons/components/zip-file-type.tsx +11 -24
- package/src/shared/icons/icon-mapping.tsx +2 -0
- package/src/shared/index.ts +28 -0
- package/src/shared/modals/AttachmentPickerConfiguration.ts +13 -0
- package/src/shared/modals/SelectedAttachment.ts +65 -0
- package/src/shared/modals/UploadState.ts +10 -0
- package/src/shared/modals/index.ts +4 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +42 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +42 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +43 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +43 -2
- package/src/shared/services/UploadQueueService.ts +145 -0
- package/src/shared/services/index.ts +2 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +44 -19
- package/src/shared/utils/MessageUtils.tsx +13 -4
- package/src/shared/utils/attachmentLimits.ts +156 -0
- package/src/shared/utils/audioPlaybackCoordinator.ts +28 -0
- package/src/shared/utils/batchMediaContext.tsx +30 -0
- package/src/shared/utils/conversationUtils.ts +26 -4
- package/src/shared/utils/elementType.tsx +38 -0
- package/src/shared/utils/groupAttachments.ts +93 -0
- package/src/shared/utils/index.ts +8 -0
- package/src/shared/utils/openMultiFileChooser.ts +123 -0
- package/src/shared/utils/partitionAttachmentsByKind.ts +44 -0
- package/src/shared/views/ClipboardPasteHandler/ClipboardPasteHandler.ts +28 -0
- package/src/shared/views/ClipboardPasteHandler/NativeCometChatClipboardModule.ts +16 -0
- package/src/shared/views/ClipboardPasteHandler/index.ts +2 -0
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +1 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.style.ts +32 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreview.tsx +90 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentPreviewItem.tsx +276 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTile.tsx +827 -0
- package/src/shared/views/CometChatAttachmentPreview/CometChatAttachmentTray.tsx +110 -0
- package/src/shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe.tsx +53 -0
- package/src/shared/views/CometChatAttachmentPreview/index.ts +8 -0
- package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +305 -0
- package/src/shared/views/CometChatAttachmentViewer/index.ts +2 -0
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +71 -74
- package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +587 -0
- package/src/shared/views/CometChatAudiosBubble/index.ts +2 -0
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +31 -20
- package/src/shared/views/CometChatCaptionText/CometChatCaptionText.tsx +182 -0
- package/src/shared/views/CometChatCaptionText/index.ts +2 -0
- package/src/shared/views/CometChatComposerErrorBanner.tsx +83 -0
- package/src/shared/views/CometChatConversationStarter/CometChatConversationStarter.tsx +141 -0
- package/src/shared/views/CometChatConversationStarter/index.ts +2 -0
- package/src/shared/views/CometChatConversationSummary/CometChatConversationSummary.tsx +155 -0
- package/src/shared/views/CometChatConversationSummary/index.ts +2 -0
- package/src/shared/views/CometChatFileBubble/style.ts +6 -4
- package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +316 -0
- package/src/shared/views/CometChatFilesBubble/index.ts +2 -0
- package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +323 -0
- package/src/shared/views/CometChatImagesBubble/index.ts +2 -0
- package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +425 -0
- package/src/shared/views/CometChatMediaViewer/index.ts +2 -0
- package/src/shared/views/CometChatMediaViewer/mediaViewerUtils.ts +30 -0
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +1 -0
- package/src/shared/views/CometChatSmartReplies/CometChatSmartReplies.tsx +172 -0
- package/src/shared/views/CometChatSmartReplies/index.ts +2 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +4 -3
- package/src/shared/views/CometChatVideoBubble/style.ts +3 -3
- package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +441 -0
- package/src/shared/views/CometChatVideosBubble/index.ts +2 -0
- package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +78 -0
- package/src/shared/views/CometChatVoiceNoteBubble/index.ts +2 -0
- package/src/shared/views/index.ts +37 -1
- package/src/theme/CometChatThemeHelper.ts +8 -0
- package/src/theme/default/color/dark.ts +9 -0
- package/src/theme/default/color/light.ts +10 -0
- package/src/theme/type.ts +73 -0
|
@@ -30,6 +30,7 @@ import RichTextEditor, {
|
|
|
30
30
|
type RichTextEditorRef,
|
|
31
31
|
type ContentChangeEvent,
|
|
32
32
|
type ActiveStylesState,
|
|
33
|
+
type PasteMediaItem,
|
|
33
34
|
} from '../CometChatRichTextEditor';
|
|
34
35
|
|
|
35
36
|
/**
|
|
@@ -94,7 +95,7 @@ import {
|
|
|
94
95
|
getUnixTimestampInMilliseconds,
|
|
95
96
|
messageStatus,
|
|
96
97
|
} from '../shared/utils/CometChatMessageHelper';
|
|
97
|
-
import { MessageTypeConstants, ReceiverTypeConstants, ConversationOptionConstants, MentionsVisibility, MentionsTargetElement, ViewAlignment, EnterKeyBehavior } from '../shared/constants/UIKitConstants';
|
|
98
|
+
import { MessageTypeConstants, ReceiverTypeConstants, ConversationOptionConstants, MentionsVisibility, MentionsTargetElement, ViewAlignment, EnterKeyBehavior, DISABLED_BUTTON_OPACITY } from '../shared/constants/UIKitConstants';
|
|
98
99
|
import { MessageEvents } from '../shared/events';
|
|
99
100
|
import { CometChatUIEventHandler } from '../shared/events/CometChatUIEventHandler/CometChatUIEventHandler';
|
|
100
101
|
import { CometChatMessageEvents } from '../shared/events/CometChatMessageEvents';
|
|
@@ -107,6 +108,17 @@ import { permissionUtil } from '../shared/utils/PermissionUtil';
|
|
|
107
108
|
import { CheckPropertyExists } from '../shared/helper/functions';
|
|
108
109
|
import { CometChatStickerKeyboard } from '../extensions/Stickers/CometChatStickerKeyboard';
|
|
109
110
|
import { ExtensionTypeConstants } from '../extensions/ExtensionConstants';
|
|
111
|
+
import { SelectedAttachment, toAttachmentFile } from '../shared/modals/SelectedAttachment';
|
|
112
|
+
import { UploadQueueService } from '../shared/services/UploadQueueService';
|
|
113
|
+
import { openMultiFileChooser } from '../shared/utils/openMultiFileChooser';
|
|
114
|
+
import { getFileUploadLimits, clampToServer, acceptPickedAttachments, toastAttachmentRejection } from '../shared/utils/attachmentLimits';
|
|
115
|
+
import { partitionAttachmentsByKind, AttachmentKindGroup } from '../shared/utils/partitionAttachmentsByKind';
|
|
116
|
+
import { attachmentCountLabel } from '../shared/utils/conversationUtils';
|
|
117
|
+
import { CometChatComposerErrorBanner } from '../shared/views/CometChatComposerErrorBanner';
|
|
118
|
+
// §5.0 — canonical DD name (CometChatAttachmentPreview is the back-compat alias)
|
|
119
|
+
import { CometChatAttachmentTray } from '../shared/views/CometChatAttachmentPreview';
|
|
120
|
+
import { CometChatMediaViewer } from '../shared/views/CometChatMediaViewer';
|
|
121
|
+
import { StagedVideoDurationProbe } from '../shared/views/CometChatAttachmentPreview/StagedVideoDurationProbe';
|
|
110
122
|
|
|
111
123
|
const { FileManager, CommonUtil } = NativeModules;
|
|
112
124
|
|
|
@@ -142,6 +154,10 @@ const richTextToolbarStyles = StyleSheet.create({
|
|
|
142
154
|
height: 20,
|
|
143
155
|
marginHorizontal: 4,
|
|
144
156
|
},
|
|
157
|
+
toolbarScrollContent: {
|
|
158
|
+
alignItems: 'center',
|
|
159
|
+
gap: 2,
|
|
160
|
+
},
|
|
145
161
|
});
|
|
146
162
|
|
|
147
163
|
/**
|
|
@@ -196,12 +212,13 @@ const richTextToolbarItems: ToolbarItem[] = [
|
|
|
196
212
|
* ActionSheetBoard component for displaying attachment options (v5 pattern)
|
|
197
213
|
*/
|
|
198
214
|
const ActionSheetBoard = (props: any) => {
|
|
199
|
-
const { shouldShow = false, onClose = () => {}, options = [], sheetRef, style } = props;
|
|
215
|
+
const { shouldShow = false, onClose = () => {}, onDismiss, options = [], sheetRef, style } = props;
|
|
200
216
|
return (
|
|
201
217
|
<CometChatBottomSheet
|
|
202
218
|
style={{ maxHeight: Dimensions.get("window").height * 0.49 }}
|
|
203
219
|
ref={sheetRef}
|
|
204
220
|
onClose={onClose}
|
|
221
|
+
onDismiss={onDismiss}
|
|
205
222
|
isOpen={shouldShow}
|
|
206
223
|
doNotOccupyEntireHeight={true}
|
|
207
224
|
>
|
|
@@ -251,11 +268,22 @@ const RecordAudio = (props: any) => {
|
|
|
251
268
|
*/
|
|
252
269
|
const MessagePreviewTray = (props: any) => {
|
|
253
270
|
const { shouldShow = false, message = null, onClose = () => {}, title = '' } = props;
|
|
271
|
+
const { t } = useCometChatTranslation();
|
|
254
272
|
if (!shouldShow) return null;
|
|
273
|
+
// Editing a media caption: caption text is the editable subtitle; a muted overline (media-type icon +
|
|
274
|
+
// attachment count) restores the context the hidden thumbnail gave.
|
|
275
|
+
const isMediaCaptionEdit = typeof message?.getCaption === 'function';
|
|
255
276
|
return (
|
|
256
277
|
<CometChatMessagePreview
|
|
257
278
|
messagePreviewTitle={title}
|
|
258
279
|
message={message}
|
|
280
|
+
{...(isMediaCaptionEdit
|
|
281
|
+
? {
|
|
282
|
+
messagePreviewSubtitle: message.getCaption() ?? '',
|
|
283
|
+
hideSubtitleIcon: true,
|
|
284
|
+
overlineText: attachmentCountLabel(message.getType?.(), message.getAttachments?.()?.length ?? 1),
|
|
285
|
+
}
|
|
286
|
+
: {})}
|
|
259
287
|
onCloseClick={onClose}
|
|
260
288
|
/>
|
|
261
289
|
);
|
|
@@ -373,7 +401,7 @@ const EmojiButton = ({ user, group, composerIdMap, replyToMessage, closeReplyPre
|
|
|
373
401
|
customMessage.setCategory(CometChat.CATEGORY_CUSTOM as CometChat.MessageCategory);
|
|
374
402
|
customMessage.setParentMessageId(parentId);
|
|
375
403
|
customMessage.setMuid(String(getUnixTimestampInMilliseconds()));
|
|
376
|
-
customMessage.setSender(loggedInUser.current);
|
|
404
|
+
if (loggedInUser.current) customMessage.setSender(loggedInUser.current as CometChat.User);
|
|
377
405
|
if (user || group) {
|
|
378
406
|
customMessage.setReceiver((user || group)!);
|
|
379
407
|
}
|
|
@@ -774,6 +802,14 @@ export interface CometChatCompactMessageComposerInterface {
|
|
|
774
802
|
*/
|
|
775
803
|
imageQuality?: number;
|
|
776
804
|
|
|
805
|
+
/**
|
|
806
|
+
* Enables the multiple-attachment workflow (staging tray + multi-upload; a send
|
|
807
|
+
* fans out into one message per kind). When `false`, attachments use the legacy
|
|
808
|
+
* single-select, send-immediately path (one picker → one message, no tray).
|
|
809
|
+
* @default true
|
|
810
|
+
*/
|
|
811
|
+
enableMultipleAttachments?: boolean;
|
|
812
|
+
|
|
777
813
|
/**
|
|
778
814
|
* If true, hides the camera option from the attachment options.
|
|
779
815
|
*/
|
|
@@ -1005,6 +1041,16 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1005
1041
|
(props: CometChatCompactMessageComposerInterface, ref) => {
|
|
1006
1042
|
const theme = useTheme();
|
|
1007
1043
|
const { t } = useCometChatTranslation();
|
|
1044
|
+
// Attachment error/info messages show as a red banner just above the tray (rendered below).
|
|
1045
|
+
const [attachmentBannerMessage, setAttachmentBannerMessage] = React.useState<string | null>(null);
|
|
1046
|
+
const [attachmentBannerHeight, setAttachmentBannerHeight] = React.useState(0);
|
|
1047
|
+
const attachmentBannerTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
1048
|
+
const showToast = useCallback((message: string) => {
|
|
1049
|
+
setAttachmentBannerMessage(message);
|
|
1050
|
+
if (attachmentBannerTimer.current) clearTimeout(attachmentBannerTimer.current);
|
|
1051
|
+
attachmentBannerTimer.current = setTimeout(() => setAttachmentBannerMessage(null), 4000);
|
|
1052
|
+
}, []);
|
|
1053
|
+
useEffect(() => () => { if (attachmentBannerTimer.current) clearTimeout(attachmentBannerTimer.current); }, []);
|
|
1008
1054
|
|
|
1009
1055
|
const {
|
|
1010
1056
|
id,
|
|
@@ -1085,6 +1131,9 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1085
1131
|
// Mention configuration props
|
|
1086
1132
|
disableMentionAll = false,
|
|
1087
1133
|
mentionAllLabel = "all",
|
|
1134
|
+
// §1 — when false, attachments fall back to the legacy single-select, send-immediately
|
|
1135
|
+
// path (no staging tray, no multi-upload/fan-out). Default true = multi-attachment.
|
|
1136
|
+
enableMultipleAttachments = true,
|
|
1088
1137
|
} = props;
|
|
1089
1138
|
|
|
1090
1139
|
// Auto-expand is always enabled (internal behavior)
|
|
@@ -1198,6 +1247,10 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1198
1247
|
const [showActionSheet, setShowActionSheet] = React.useState(false);
|
|
1199
1248
|
const [actionSheetItems, setActionSheetItems] = React.useState<CometChatMessageComposerAction[]>([]);
|
|
1200
1249
|
const [showInlineRecorder, setShowInlineRecorder] = React.useState(false);
|
|
1250
|
+
// iOS: holds a picker launch that must wait until the action sheet's modal has
|
|
1251
|
+
// fully dismissed — UIKit can't present the picker while the modal is dismissing.
|
|
1252
|
+
// Fired from the sheet's onDismiss. Unused on Android (picker launches inline).
|
|
1253
|
+
const pendingAttachmentActionRef = React.useRef<(() => void) | null>(null);
|
|
1201
1254
|
|
|
1202
1255
|
// Mic/sticker animation: single Animated.Value drives mic slide + fade
|
|
1203
1256
|
// 0 = idle (mic visible), 1 = typing (mic hidden)
|
|
@@ -1246,6 +1299,236 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1246
1299
|
// Focus tracking for floating toolbar visibility
|
|
1247
1300
|
const [isFocused, setIsFocused] = React.useState(false);
|
|
1248
1301
|
|
|
1302
|
+
// Multi-attachment state
|
|
1303
|
+
const [selectedAttachments, setSelectedAttachments] = React.useState<SelectedAttachment[]>([]);
|
|
1304
|
+
// §8.2 — full-screen preview of staged media (image/video) tiles; opened on tap when COMPLETED.
|
|
1305
|
+
const [trayViewerVisible, setTrayViewerVisible] = React.useState(false);
|
|
1306
|
+
const [trayViewerIndex, setTrayViewerIndex] = React.useState(0);
|
|
1307
|
+
// Live mirror of the staged count. The action-sheet items freeze an older handlePickFiles
|
|
1308
|
+
// closure (their effect deps don't include selectedAttachments), so reading
|
|
1309
|
+
// `selectedAttachments.length` inside the picker handler would be stale (stuck at the
|
|
1310
|
+
// count when the sheet was built) and the count guard would never see already-staged files.
|
|
1311
|
+
// Read the count from this ref instead so the limit is always enforced against the CURRENT tray.
|
|
1312
|
+
const selectedAttachmentsRef = React.useRef<SelectedAttachment[]>([]);
|
|
1313
|
+
React.useEffect(() => {
|
|
1314
|
+
selectedAttachmentsRef.current = selectedAttachments;
|
|
1315
|
+
}, [selectedAttachments]);
|
|
1316
|
+
|
|
1317
|
+
|
|
1318
|
+
// One UploadQueueService per composer mount
|
|
1319
|
+
const uploadQueue = useMemo(
|
|
1320
|
+
() =>
|
|
1321
|
+
new UploadQueueService({
|
|
1322
|
+
onProgress: (fileId, percent) => {
|
|
1323
|
+
setSelectedAttachments(prev =>
|
|
1324
|
+
prev.map(a =>
|
|
1325
|
+
a.fileId === fileId ? { ...a, uploadState: 'UPLOADING', uploadProgress: percent } : a
|
|
1326
|
+
)
|
|
1327
|
+
);
|
|
1328
|
+
},
|
|
1329
|
+
onFileComplete: (fileId, attachment) => {
|
|
1330
|
+
setSelectedAttachments(prev =>
|
|
1331
|
+
prev.map(a =>
|
|
1332
|
+
a.fileId === fileId
|
|
1333
|
+
? { ...a, uploadState: 'COMPLETED', uploadProgress: 100, uploadedAttachment: attachment }
|
|
1334
|
+
: a
|
|
1335
|
+
)
|
|
1336
|
+
);
|
|
1337
|
+
},
|
|
1338
|
+
onFileFailed: (fileId, _error) => {
|
|
1339
|
+
setSelectedAttachments(prev =>
|
|
1340
|
+
prev.map(a =>
|
|
1341
|
+
a.fileId === fileId ? { ...a, uploadState: 'FAILED', errorKey: 'UPLOAD_FAILED' } : a
|
|
1342
|
+
)
|
|
1343
|
+
);
|
|
1344
|
+
},
|
|
1345
|
+
onFileRejected: (fileId, error) => {
|
|
1346
|
+
// Store the SDK error code; the user sees WHY by tapping the errored tile (no auto-toast,
|
|
1347
|
+
// so several rejections can't spam). See handleTrayTilePress → toastAttachmentRejection.
|
|
1348
|
+
const code = error?.code ?? (error as any)?.getCode?.();
|
|
1349
|
+
setSelectedAttachments(prev =>
|
|
1350
|
+
prev.map(a =>
|
|
1351
|
+
a.fileId === fileId ? { ...a, uploadState: 'REJECTED', errorKey: 'UPLOAD_REJECTED', errorCode: code } : a
|
|
1352
|
+
)
|
|
1353
|
+
);
|
|
1354
|
+
},
|
|
1355
|
+
onAllComplete: () => {
|
|
1356
|
+
// Send is driven by the send button, not this callback.
|
|
1357
|
+
},
|
|
1358
|
+
}),
|
|
1359
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1360
|
+
[]
|
|
1361
|
+
);
|
|
1362
|
+
|
|
1363
|
+
// Cancel all in-flight uploads and discard the tray on unmount / conversation switch
|
|
1364
|
+
useEffect(() => {
|
|
1365
|
+
return () => {
|
|
1366
|
+
uploadQueue.cancelAll();
|
|
1367
|
+
setSelectedAttachments([]);
|
|
1368
|
+
};
|
|
1369
|
+
// uploadQueue is stable (useMemo with [] deps), so this only runs on unmount
|
|
1370
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
1371
|
+
}, []);
|
|
1372
|
+
|
|
1373
|
+
const handlePickFiles = useCallback(
|
|
1374
|
+
async (pickerType: 'media' | 'document' | 'camera' | 'audio') => {
|
|
1375
|
+
// Read the LIVE staged count (ref), not the possibly-stale closure value — see
|
|
1376
|
+
// selectedAttachmentsRef note. This is what makes the count limit hold across picks.
|
|
1377
|
+
const existingCount = selectedAttachmentsRef.current.length;
|
|
1378
|
+
|
|
1379
|
+
// Server-authoritative upload limits (file.count.max / per-file file.size.max),
|
|
1380
|
+
// clamped tighten-only against any developer override (§5.1 / §6.1).
|
|
1381
|
+
const serverLimits = await getFileUploadLimits();
|
|
1382
|
+
const maxCount = clampToServer(undefined, serverLimits.fileCountMax);
|
|
1383
|
+
|
|
1384
|
+
// Always open the picker (even at capacity) so the button never feels broken. Enforcement is
|
|
1385
|
+
// on selection: acceptPickedAttachments rejects the whole over-limit pick + shows the toast.
|
|
1386
|
+
const picked = await openMultiFileChooser(pickerType, existingCount, maxCount);
|
|
1387
|
+
|
|
1388
|
+
if (picked.length === 0) return;
|
|
1389
|
+
|
|
1390
|
+
// §6.3 — trim to the remaining count slots. Per-file SIZE is enforced by the SDK
|
|
1391
|
+
// (ERR_FILE_SIZE_EXCEEDED → onFileRejected), not here.
|
|
1392
|
+
const accepted = acceptPickedAttachments(picked, { maxCount, existingCount }, { showToast, t });
|
|
1393
|
+
if (accepted.length === 0) return;
|
|
1394
|
+
|
|
1395
|
+
const newAttachments: SelectedAttachment[] = accepted.map(f => ({
|
|
1396
|
+
fileId: '_' + Math.random().toString(36).substr(2, 9),
|
|
1397
|
+
file: toAttachmentFile(f),
|
|
1398
|
+
uploadState: 'NONE',
|
|
1399
|
+
uploadProgress: 0,
|
|
1400
|
+
}));
|
|
1401
|
+
|
|
1402
|
+
setSelectedAttachments(prev => {
|
|
1403
|
+
const next = [...prev, ...newAttachments];
|
|
1404
|
+
// Keep the count-guard ref exact SYNCHRONOUSLY. The useEffect mirror runs only after
|
|
1405
|
+
// paint, so a quick second pick could read a stale (lower) existingCount and let an
|
|
1406
|
+
// extra file past the max (e.g. staging 11 when the limit is 10). Mirroring here makes
|
|
1407
|
+
// the count correct on the very next pick.
|
|
1408
|
+
selectedAttachmentsRef.current = next;
|
|
1409
|
+
return next;
|
|
1410
|
+
});
|
|
1411
|
+
try {
|
|
1412
|
+
// Pass the target conversation so the SDK can hand receiver/receiverType to the server for
|
|
1413
|
+
// RBAC/SBAC presign authorization. Refs are read fresh (uploadQueue is memoized, refs are not).
|
|
1414
|
+
newAttachments.forEach(a =>
|
|
1415
|
+
uploadQueue.enqueue(a, { receiver: chatWithId.current, receiverType: chatWith.current })
|
|
1416
|
+
);
|
|
1417
|
+
} catch {
|
|
1418
|
+
// upload queue errors are surfaced per-file via onFileFailed
|
|
1419
|
+
}
|
|
1420
|
+
},
|
|
1421
|
+
[selectedAttachments.length, uploadQueue]
|
|
1422
|
+
);
|
|
1423
|
+
|
|
1424
|
+
// §5.0 — clipboard paste: the native editor extracts pasted image(s)/file(s) to temp files
|
|
1425
|
+
// and fires onPasteMedia. Stage them in the tray with the SAME count + per-file size guards
|
|
1426
|
+
// as the picker (using the live-count ref). Gated by enableMultipleAttachments.
|
|
1427
|
+
const handlePasteMedia = useCallback(
|
|
1428
|
+
async (items: PasteMediaItem[]) => {
|
|
1429
|
+
if (!enableMultipleAttachments || !items?.length) return;
|
|
1430
|
+
const existingCount = selectedAttachmentsRef.current.length;
|
|
1431
|
+
const serverLimits = await getFileUploadLimits();
|
|
1432
|
+
const maxCount = clampToServer(undefined, serverLimits.fileCountMax);
|
|
1433
|
+
|
|
1434
|
+
// Same count gate as the picker path; per-file SIZE is enforced by the SDK (see onFileRejected).
|
|
1435
|
+
const accepted = acceptPickedAttachments(items, { maxCount, existingCount }, { showToast, t });
|
|
1436
|
+
if (accepted.length === 0) return;
|
|
1437
|
+
|
|
1438
|
+
const newAttachments: SelectedAttachment[] = accepted.map(it => ({
|
|
1439
|
+
fileId: '_paste_' + Math.random().toString(36).substr(2, 9),
|
|
1440
|
+
file: toAttachmentFile(it),
|
|
1441
|
+
uploadState: 'NONE',
|
|
1442
|
+
uploadProgress: 0,
|
|
1443
|
+
}));
|
|
1444
|
+
setSelectedAttachments(prev => {
|
|
1445
|
+
const next = [...prev, ...newAttachments];
|
|
1446
|
+
// Keep the count-guard ref exact SYNCHRONOUSLY. The useEffect mirror runs only after
|
|
1447
|
+
// paint, so a quick second pick could read a stale (lower) existingCount and let an
|
|
1448
|
+
// extra file past the max (e.g. staging 11 when the limit is 10). Mirroring here makes
|
|
1449
|
+
// the count correct on the very next pick.
|
|
1450
|
+
selectedAttachmentsRef.current = next;
|
|
1451
|
+
return next;
|
|
1452
|
+
});
|
|
1453
|
+
try {
|
|
1454
|
+
// Pass the target conversation so the SDK can hand receiver/receiverType to the server for
|
|
1455
|
+
// RBAC/SBAC presign authorization. Refs are read fresh (uploadQueue is memoized, refs are not).
|
|
1456
|
+
newAttachments.forEach(a =>
|
|
1457
|
+
uploadQueue.enqueue(a, { receiver: chatWithId.current, receiverType: chatWith.current })
|
|
1458
|
+
);
|
|
1459
|
+
} catch {
|
|
1460
|
+
// upload queue errors are surfaced per-file via onFileFailed
|
|
1461
|
+
}
|
|
1462
|
+
},
|
|
1463
|
+
[enableMultipleAttachments, uploadQueue]
|
|
1464
|
+
);
|
|
1465
|
+
|
|
1466
|
+
// §8.2 — staged image/video items (LOCAL URIs) for the full-screen tray preview viewer — the
|
|
1467
|
+
// SAME CometChatMediaViewer used for sent media (see CometChatMediaGridBubble).
|
|
1468
|
+
const trayMediaItems = React.useMemo(() => {
|
|
1469
|
+
return selectedAttachments
|
|
1470
|
+
.filter(a => a.file.type.startsWith('image/') || a.file.type.startsWith('video/'))
|
|
1471
|
+
.map(a => ({
|
|
1472
|
+
getUrl: () => a.file.uri,
|
|
1473
|
+
getMimeType: () => a.file.type,
|
|
1474
|
+
getName: () => a.file.name,
|
|
1475
|
+
getSize: () => a.file.size || 0,
|
|
1476
|
+
} as unknown as CometChat.Attachment));
|
|
1477
|
+
}, [selectedAttachments]);
|
|
1478
|
+
|
|
1479
|
+
// Open the full-screen viewer at the tapped tile. Only COMPLETED media tiles are tappable
|
|
1480
|
+
// (gated by the tile's canPreview), so no upload-state check is needed here.
|
|
1481
|
+
const handleTrayTilePress = useCallback((fileId: string) => {
|
|
1482
|
+
const att = selectedAttachments.find(a => a.fileId === fileId);
|
|
1483
|
+
if (!att) return;
|
|
1484
|
+
// Rejected tile → tap reveals WHY it failed (size, etc.) as a toast.
|
|
1485
|
+
if (att.uploadState === 'REJECTED') {
|
|
1486
|
+
toastAttachmentRejection(att, { showToast, t });
|
|
1487
|
+
return;
|
|
1488
|
+
}
|
|
1489
|
+
const mediaOnly = selectedAttachments.filter(
|
|
1490
|
+
a => a.file.type.startsWith('image/') || a.file.type.startsWith('video/')
|
|
1491
|
+
);
|
|
1492
|
+
const idx = mediaOnly.findIndex(a => a.fileId === fileId);
|
|
1493
|
+
if (idx < 0) return;
|
|
1494
|
+
setTrayViewerIndex(idx);
|
|
1495
|
+
setTrayViewerVisible(true);
|
|
1496
|
+
}, [selectedAttachments, showToast, t]);
|
|
1497
|
+
|
|
1498
|
+
// Store a staged video's probed duration (seconds) so it can be written to metadata on send.
|
|
1499
|
+
const handleVideoDuration = useCallback((fileId: string, durationSeconds: number) => {
|
|
1500
|
+
setSelectedAttachments(prev =>
|
|
1501
|
+
prev.map(a => (a.fileId === fileId ? { ...a, durationSeconds } : a))
|
|
1502
|
+
);
|
|
1503
|
+
}, []);
|
|
1504
|
+
|
|
1505
|
+
const handleRemoveAttachment = useCallback(
|
|
1506
|
+
(fileId: string) => {
|
|
1507
|
+
uploadQueue.dequeue(fileId);
|
|
1508
|
+
setSelectedAttachments(prev => {
|
|
1509
|
+
const next = prev.filter(a => a.fileId !== fileId);
|
|
1510
|
+
// Sync the count-guard ref synchronously (see the add-path note) so removing then
|
|
1511
|
+
// immediately picking sees the freed slot instead of a stale, higher count.
|
|
1512
|
+
selectedAttachmentsRef.current = next;
|
|
1513
|
+
return next;
|
|
1514
|
+
});
|
|
1515
|
+
},
|
|
1516
|
+
[uploadQueue]
|
|
1517
|
+
);
|
|
1518
|
+
|
|
1519
|
+
const handleRetryAttachment = useCallback(
|
|
1520
|
+
(fileId: string) => {
|
|
1521
|
+
const attachment = selectedAttachments.find(a => a.fileId === fileId);
|
|
1522
|
+
if (!attachment) return;
|
|
1523
|
+
setSelectedAttachments(prev =>
|
|
1524
|
+
prev.map(a =>
|
|
1525
|
+
a.fileId === fileId ? { ...a, uploadState: 'NONE', uploadProgress: 0, errorKey: undefined } : a
|
|
1526
|
+
)
|
|
1527
|
+
);
|
|
1528
|
+
uploadQueue.retry(fileId, { ...attachment, uploadState: 'NONE', uploadProgress: 0 });
|
|
1529
|
+
},
|
|
1530
|
+
[selectedAttachments, uploadQueue]
|
|
1531
|
+
);
|
|
1249
1532
|
|
|
1250
1533
|
/**
|
|
1251
1534
|
* Tracks links inserted via the JS modal.
|
|
@@ -1955,62 +2238,209 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
1955
2238
|
};
|
|
1956
2239
|
|
|
1957
2240
|
/**
|
|
1958
|
-
* File input handler for different file types
|
|
1959
|
-
*
|
|
2241
|
+
* File input handler for different file types.
|
|
2242
|
+
* Image / video / file route through the multi-attachment upload flow.
|
|
2243
|
+
* Camera and legacy types (audio, etc.) fall through to the original single-send path.
|
|
1960
2244
|
*/
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
2245
|
+
// The actual picker presentation. Split out from fileInputHandler so it can be
|
|
2246
|
+
// launched inline (Android) or deferred to the sheet's onDismiss (iOS).
|
|
2247
|
+
const launchPicker = async (fileType: string) => {
|
|
2248
|
+
// §1 — MULTI (default): route image/video/file/camera into the staging tray.
|
|
2249
|
+
if (enableMultipleAttachments) {
|
|
2250
|
+
if (fileType === MessageTypeConstants.image || fileType === MessageTypeConstants.video) {
|
|
2251
|
+
await handlePickFiles('media');
|
|
1964
2252
|
return;
|
|
1965
2253
|
}
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
2254
|
+
if (fileType === MessageTypeConstants.file) {
|
|
2255
|
+
await handlePickFiles('document');
|
|
2256
|
+
return;
|
|
1969
2257
|
}
|
|
1970
|
-
if (
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
)
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
);
|
|
2258
|
+
if (fileType === MessageTypeConstants.audio) {
|
|
2259
|
+
await handlePickFiles('audio');
|
|
2260
|
+
return;
|
|
2261
|
+
}
|
|
2262
|
+
if (fileType === MessageTypeConstants.takePhoto) {
|
|
2263
|
+
if (!(await permissionUtil.startResourceBasedTask(['camera']))) {
|
|
2264
|
+
return;
|
|
2265
|
+
}
|
|
2266
|
+
await handlePickFiles('camera');
|
|
2267
|
+
return;
|
|
1981
2268
|
}
|
|
1982
|
-
}
|
|
2269
|
+
}
|
|
2270
|
+
|
|
2271
|
+
// §1 — LEGACY single-select, send-immediately (flag=false, or audio/other types):
|
|
2272
|
+
// one picker → one MediaMessage, no tray/multi-upload.
|
|
2273
|
+
if (fileType === MessageTypeConstants.takePhoto) {
|
|
2274
|
+
if (!(await permissionUtil.startResourceBasedTask(['camera']))) return;
|
|
2275
|
+
const onCapture = (result: any) => {
|
|
2276
|
+
if (result && !CheckPropertyExists(result, 'error') && result.uri) {
|
|
2277
|
+
sendMediaMessage(chatWithId.current, { name: result.name, type: result.type, uri: result.uri }, MessageTypeConstants.image, chatWith.current);
|
|
2278
|
+
}
|
|
2279
|
+
};
|
|
2280
|
+
if (Platform.OS === 'ios') FileManager.openCamera('image', onCapture);
|
|
2281
|
+
else FileManager.openCamera('image', 50, onCapture);
|
|
2282
|
+
return;
|
|
2283
|
+
}
|
|
2284
|
+
if (Platform.OS === 'ios' && fileType === MessageTypeConstants.video) {
|
|
1983
2285
|
NativeModules.VideoPickerModule.pickVideo((file: any) => {
|
|
1984
2286
|
if (file.uri) {
|
|
1985
|
-
sendMediaMessage(
|
|
1986
|
-
chatWithId.current,
|
|
1987
|
-
file,
|
|
1988
|
-
MessageTypeConstants.video,
|
|
1989
|
-
chatWith.current
|
|
1990
|
-
);
|
|
2287
|
+
sendMediaMessage(chatWithId.current, file, MessageTypeConstants.video, chatWith.current);
|
|
1991
2288
|
}
|
|
1992
2289
|
});
|
|
1993
2290
|
} else {
|
|
1994
2291
|
FileManager.openFileChooser(fileType, async (fileInfo: any) => {
|
|
1995
|
-
if (CheckPropertyExists(fileInfo, 'error'))
|
|
1996
|
-
return;
|
|
1997
|
-
}
|
|
2292
|
+
if (CheckPropertyExists(fileInfo, 'error')) return;
|
|
1998
2293
|
const { name, uri, type } = fileInfo;
|
|
1999
|
-
|
|
2000
|
-
name,
|
|
2001
|
-
type,
|
|
2002
|
-
uri,
|
|
2003
|
-
};
|
|
2004
|
-
sendMediaMessage(
|
|
2005
|
-
chatWithId.current,
|
|
2006
|
-
file,
|
|
2007
|
-
fileType,
|
|
2008
|
-
chatWith.current
|
|
2009
|
-
);
|
|
2294
|
+
sendMediaMessage(chatWithId.current, { name, type, uri }, fileType, chatWith.current);
|
|
2010
2295
|
});
|
|
2011
2296
|
}
|
|
2012
2297
|
};
|
|
2013
2298
|
|
|
2299
|
+
const fileInputHandler = (fileType: string) => {
|
|
2300
|
+
// Always close the attachment sheet first.
|
|
2301
|
+
// iOS: UIKit can't present the picker while the sheet's modal is still
|
|
2302
|
+
// dismissing, so stash the launch and fire it from the modal's onDismiss
|
|
2303
|
+
// (see the ActionSheetBoard below). Android has no such restriction, so launch
|
|
2304
|
+
// immediately as the sheet closes.
|
|
2305
|
+
if (Platform.OS === 'ios') {
|
|
2306
|
+
pendingAttachmentActionRef.current = () => {
|
|
2307
|
+
void launchPicker(fileType);
|
|
2308
|
+
};
|
|
2309
|
+
setShowActionSheet(false);
|
|
2310
|
+
return;
|
|
2311
|
+
}
|
|
2312
|
+
setShowActionSheet(false);
|
|
2313
|
+
void launchPicker(fileType);
|
|
2314
|
+
};
|
|
2315
|
+
|
|
2316
|
+
/**
|
|
2317
|
+
* Send all pre-uploaded attachments as a single multi-attachment media message.
|
|
2318
|
+
* Uses SDK-native setAttachments() so data.attachments survives the server round-trip
|
|
2319
|
+
* and groupAttachments() can render the grid correctly on receive.
|
|
2320
|
+
*/
|
|
2321
|
+
const sendMultiAttachmentMediaMessage = useCallback(() => {
|
|
2322
|
+
// Guard: never ship a partial batch. If any staged tile errored (FAILED/REJECTED), block
|
|
2323
|
+
// the send until the user removes it (the send button is also disabled in this state).
|
|
2324
|
+
if (selectedAttachmentsRef.current.some(a => a.uploadState === 'FAILED' || a.uploadState === 'REJECTED')) {
|
|
2325
|
+
return;
|
|
2326
|
+
}
|
|
2327
|
+
// Write each staged video/audio's probed duration into its uploaded attachment's metadata
|
|
2328
|
+
// BEFORE setAttachments() serializes it — uploadedAttachment is the SAME object that flows into
|
|
2329
|
+
// the outgoing message, so BOTH bubbles read duration from metadata immediately (no reliance on
|
|
2330
|
+
// the shared native SoundPlayer, which races to 00:00 when several audio cards mount at once).
|
|
2331
|
+
selectedAttachmentsRef.current.forEach(a => {
|
|
2332
|
+
if ((a.file.type.startsWith('video/') || a.file.type.startsWith('audio/')) && a.durationSeconds && a.durationSeconds > 0 && a.uploadedAttachment) {
|
|
2333
|
+
a.uploadedAttachment.setMetadata({
|
|
2334
|
+
...(a.uploadedAttachment.getMetadata?.() || {}),
|
|
2335
|
+
duration: a.durationSeconds,
|
|
2336
|
+
});
|
|
2337
|
+
}
|
|
2338
|
+
});
|
|
2339
|
+
const completed = uploadQueue.completedAttachments;
|
|
2340
|
+
|
|
2341
|
+
if (completed.length === 0) {
|
|
2342
|
+
return;
|
|
2343
|
+
}
|
|
2344
|
+
|
|
2345
|
+
// Prefer the SDK's upload batch id (DD §5.3) as the message batchId; captured BEFORE cancelAll
|
|
2346
|
+
// releases the request. Fall back to a client timestamp id when the SDK doesn't expose one.
|
|
2347
|
+
const sdkBatchId = uploadQueue.batchId;
|
|
2348
|
+
|
|
2349
|
+
// Reset the queue immediately after capturing this batch's attachments.
|
|
2350
|
+
// The completed Map accumulates across batches — without this reset the next
|
|
2351
|
+
// send would include all previous batches' attachments as well.
|
|
2352
|
+
uploadQueue.cancelAll();
|
|
2353
|
+
|
|
2354
|
+
// §7 — FAN OUT: partition the completed tiles by kind and send ONE MediaMessage per
|
|
2355
|
+
// non-empty kind (Images → Videos → Files; picker audio → file), all sharing one
|
|
2356
|
+
// batchId. Each message gets its own muid; the caption goes on the LAST message only.
|
|
2357
|
+
const groups = partitionAttachmentsByKind(completed);
|
|
2358
|
+
if (groups.length === 0) return;
|
|
2359
|
+
|
|
2360
|
+
const batchId = sdkBatchId ?? String(getUnixTimestampInMilliseconds());
|
|
2361
|
+
// §8.4 — total attachments across the whole batch, so the conversation-list preview can
|
|
2362
|
+
// aggregate ("N attachments") from just the last fanned-out message it receives.
|
|
2363
|
+
const batchTotalCount = groups.reduce((sum, g) => sum + g.attachments.length, 0);
|
|
2364
|
+
const caption = plainTextInputRef.current.trim();
|
|
2365
|
+
const currentReplyMessage = replyMessageRef.current;
|
|
2366
|
+
const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
|
|
2367
|
+
|
|
2368
|
+
// Fresh MediaMessage for a group — used for both the optimistic echo and the send.
|
|
2369
|
+
const buildMessage = (group: AttachmentKindGroup, index: number, muid: string) => {
|
|
2370
|
+
const m = new CometChat.MediaMessage(chatWithId.current, null, group.type, chatWith.current);
|
|
2371
|
+
if (loggedInUser.current) m.setSender(loggedInUser.current as CometChat.User);
|
|
2372
|
+
m.setMuid(muid);
|
|
2373
|
+
m.setAttachments(group.attachments);
|
|
2374
|
+
// §7/§8.3a batch contract — lets the message list group the fanned-out messages.
|
|
2375
|
+
m.setMetadata({ batchId, batchIndex: index, batchSize: groups.length, batchTotalCount });
|
|
2376
|
+
if (index === groups.length - 1 && caption) m.setCaption(caption); // caption on LAST only
|
|
2377
|
+
if (parentMessageId) m.setParentMessageId(parentMessageId as number); // thread parent on ALL
|
|
2378
|
+
// Quoted reply on the FIRST message of the batch only — otherwise every fanned-out bubble
|
|
2379
|
+
// shows the "replying to X" quote. (Thread parentMessageId above stays on all.)
|
|
2380
|
+
if (replyMessageId && currentReplyMessage?.message && index === 0 && typeof m.setQuotedMessage === 'function') {
|
|
2381
|
+
m.setQuotedMessage(currentReplyMessage.message);
|
|
2382
|
+
(m as any).quotedMessage = currentReplyMessage.message;
|
|
2383
|
+
(m as any).quotedMessageId = replyMessageId;
|
|
2384
|
+
}
|
|
2385
|
+
return m;
|
|
2386
|
+
};
|
|
2387
|
+
|
|
2388
|
+
// Flag a fanned message's optimistic echo as FAILED and push it back to the list. Mirrors the full
|
|
2389
|
+
// composer: the message list marks failures via `ccMessageSent` + status:error (it has no
|
|
2390
|
+
// `ccMessageError` handler), and the bubble's error icon reads `metaData.error` / `metadata.error`.
|
|
2391
|
+
// Without stamping BOTH here, a failed send would render as a blank/in-progress bubble with no
|
|
2392
|
+
// indication — and for a first/middle batch member, get collapsed away entirely (§12.1).
|
|
2393
|
+
const markSendFailed = (msg: CometChat.MediaMessage) => {
|
|
2394
|
+
const currentData = msg.getData?.() || {};
|
|
2395
|
+
msg.setData({ ...currentData, metaData: { ...((currentData as any).metaData || {}), error: true } });
|
|
2396
|
+
const md = (msg.getMetadata?.() as Record<string, unknown>) || {};
|
|
2397
|
+
msg.setMetadata({ ...md, error: true });
|
|
2398
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
2399
|
+
message: msg,
|
|
2400
|
+
status: messageStatus.error,
|
|
2401
|
+
});
|
|
2402
|
+
};
|
|
2403
|
+
|
|
2404
|
+
groups.forEach((group, index) => {
|
|
2405
|
+
const muid = `${batchId}_${index}`;
|
|
2406
|
+
|
|
2407
|
+
// Optimistic (in-progress) bubble for this kind's message, keyed by its muid.
|
|
2408
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
2409
|
+
message: buildMessage(group, index, muid),
|
|
2410
|
+
status: messageStatus.inprogress,
|
|
2411
|
+
});
|
|
2412
|
+
|
|
2413
|
+
// §7/§12.1 — independent per-message send: one kind can fail while others deliver.
|
|
2414
|
+
const outgoing = buildMessage(group, index, muid);
|
|
2415
|
+
CometChat.sendMediaMessage(outgoing)
|
|
2416
|
+
.then((msg: any) => {
|
|
2417
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
2418
|
+
message: msg,
|
|
2419
|
+
status: messageStatus.success,
|
|
2420
|
+
});
|
|
2421
|
+
})
|
|
2422
|
+
.catch(() => markSendFailed(outgoing));
|
|
2423
|
+
});
|
|
2424
|
+
|
|
2425
|
+
// ENG-36991 — clear the swipe-to-reply preview FIRST, before the teardown below. clearInputBox()
|
|
2426
|
+
// calls the native RichTextEditor clear(), which on some real Android devices can throw and skip
|
|
2427
|
+
// everything after it — leaving the reply preview stuck (worked on the emulator, not on device).
|
|
2428
|
+
setReplyMessage(null);
|
|
2429
|
+
replyMessageRef.current = null;
|
|
2430
|
+
|
|
2431
|
+
setSelectedAttachments([]);
|
|
2432
|
+
setShowActionSheet(false);
|
|
2433
|
+
clearInputBox();
|
|
2434
|
+
|
|
2435
|
+
if (!disableSoundForMessages) {
|
|
2436
|
+
CometChatSoundManager.play(
|
|
2437
|
+
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
2438
|
+
customSoundForMessage
|
|
2439
|
+
);
|
|
2440
|
+
}
|
|
2441
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
2442
|
+
}, [uploadQueue, parentMessageId, disableSoundForMessages, customSoundForMessage]);
|
|
2443
|
+
|
|
2014
2444
|
/**
|
|
2015
2445
|
* Send media message (image, video, audio, file)
|
|
2016
2446
|
* Includes reply message support for quoted messages.
|
|
@@ -2019,14 +2449,15 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2019
2449
|
receiverId: string,
|
|
2020
2450
|
messageInput: { name: string; type: string; uri: string },
|
|
2021
2451
|
messageType: string,
|
|
2022
|
-
receiverType: string
|
|
2452
|
+
receiverType: string,
|
|
2453
|
+
extraMetadata?: Record<string, any>
|
|
2023
2454
|
) => {
|
|
2024
2455
|
setShowActionSheet(false);
|
|
2025
2456
|
|
|
2026
2457
|
// Capture current reply message using ref to avoid stale closures
|
|
2027
2458
|
const currentReplyMessage = replyMessageRef.current;
|
|
2028
2459
|
const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
|
|
2029
|
-
|
|
2460
|
+
|
|
2030
2461
|
const mediaMessage = new CometChat.MediaMessage(
|
|
2031
2462
|
receiverId,
|
|
2032
2463
|
messageInput,
|
|
@@ -2034,10 +2465,20 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2034
2465
|
receiverType
|
|
2035
2466
|
);
|
|
2036
2467
|
|
|
2037
|
-
|
|
2468
|
+
// The optimistic echo (localMessage) and the message actually sent
|
|
2469
|
+
// (mediaMessage) MUST share ONE muid. CometChatMessageList reconciles the
|
|
2470
|
+
// in-progress bubble with the delivered message via messageEdited(), which
|
|
2471
|
+
// matches by muid — and when no match is found it does nothing, so the
|
|
2472
|
+
// delivered message is dropped and the optimistic bubble is orphaned (no
|
|
2473
|
+
// echo until a refetch). Two independent getUnixTimestampInMilliseconds()
|
|
2474
|
+
// calls can land in different milliseconds, so they must not be used
|
|
2475
|
+
// separately here. This mirrors the working multi-attachment path, which
|
|
2476
|
+
// builds both messages with the same `${batchId}_${index}` muid.
|
|
2477
|
+
const sharedMuid = String(getUnixTimestampInMilliseconds());
|
|
2478
|
+
if (loggedInUser.current) mediaMessage.setSender(loggedInUser.current as CometChat.User);
|
|
2038
2479
|
mediaMessage.setReceiver((user || group)!);
|
|
2039
2480
|
mediaMessage.setType(messageType);
|
|
2040
|
-
mediaMessage.setMuid(
|
|
2481
|
+
mediaMessage.setMuid(sharedMuid);
|
|
2041
2482
|
mediaMessage.setData({
|
|
2042
2483
|
type: messageType,
|
|
2043
2484
|
category: CometChat.CATEGORY_MESSAGE,
|
|
@@ -2046,7 +2487,13 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2046
2487
|
url: messageInput.uri,
|
|
2047
2488
|
sender: loggedInUser.current,
|
|
2048
2489
|
});
|
|
2049
|
-
|
|
2490
|
+
// setMetadata MUST run AFTER setData: the SDK stores metadata inside `data`, and
|
|
2491
|
+
// setData replaces `data` wholesale — so tagging before setData would be wiped from
|
|
2492
|
+
// the payload sent to the server (e.g. audioType:"voice_note" would never round-trip).
|
|
2493
|
+
if (extraMetadata) {
|
|
2494
|
+
mediaMessage.setMetadata({ ...(mediaMessage.getMetadata() || {}), ...extraMetadata });
|
|
2495
|
+
}
|
|
2496
|
+
|
|
2050
2497
|
if (parentMessageId) {
|
|
2051
2498
|
mediaMessage.setParentMessageId(parentMessageId as number);
|
|
2052
2499
|
}
|
|
@@ -2067,10 +2514,12 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2067
2514
|
receiverType
|
|
2068
2515
|
);
|
|
2069
2516
|
|
|
2070
|
-
localMessage.setSender(loggedInUser.current);
|
|
2517
|
+
if (loggedInUser.current) localMessage.setSender(loggedInUser.current as CometChat.User);
|
|
2071
2518
|
localMessage.setReceiver((user || group)!);
|
|
2072
2519
|
localMessage.setType(messageType);
|
|
2073
|
-
|
|
2520
|
+
// Same muid as the sent mediaMessage above — see note there. This is what
|
|
2521
|
+
// lets messageEdited() replace this optimistic bubble with the delivered one.
|
|
2522
|
+
localMessage.setMuid(sharedMuid);
|
|
2074
2523
|
localMessage.setData({
|
|
2075
2524
|
type: messageType,
|
|
2076
2525
|
category: CometChat.CATEGORY_MESSAGE,
|
|
@@ -2080,6 +2529,10 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2080
2529
|
sender: loggedInUser.current,
|
|
2081
2530
|
attachments: [messageInput],
|
|
2082
2531
|
});
|
|
2532
|
+
// setMetadata AFTER setData (see note above) so the optimistic bubble matches the sent one.
|
|
2533
|
+
if (extraMetadata) {
|
|
2534
|
+
localMessage.setMetadata({ ...(localMessage.getMetadata() || {}), ...extraMetadata });
|
|
2535
|
+
}
|
|
2083
2536
|
|
|
2084
2537
|
if (parentMessageId) {
|
|
2085
2538
|
localMessage.setParentMessageId(parentMessageId as number);
|
|
@@ -2154,12 +2607,17 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2154
2607
|
type: 'audio/mp4',
|
|
2155
2608
|
uri: recordedFile,
|
|
2156
2609
|
};
|
|
2157
|
-
|
|
2610
|
+
|
|
2611
|
+
// §8.1a — tag recorded audio as a voice note so it renders in the WAVEFORM bubble
|
|
2612
|
+
// (CometChatAudioBubble), distinct from picked/shared audio files which use the
|
|
2613
|
+
// headphone+filename bubble. Always tagged (independent of enableMultipleAttachments).
|
|
2614
|
+
const voiceNoteMeta = { audioType: 'voice_note' }; // always tag → recorded audio is ALWAYS the waveform bubble
|
|
2158
2615
|
sendMediaMessage(
|
|
2159
2616
|
chatWithId.current,
|
|
2160
2617
|
fileObj,
|
|
2161
2618
|
MessageTypeConstants.audio,
|
|
2162
|
-
chatWith.current
|
|
2619
|
+
chatWith.current,
|
|
2620
|
+
voiceNoteMeta
|
|
2163
2621
|
);
|
|
2164
2622
|
};
|
|
2165
2623
|
|
|
@@ -2173,9 +2631,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2173
2631
|
type: 'audio/mp4',
|
|
2174
2632
|
uri: recordedFile,
|
|
2175
2633
|
};
|
|
2176
|
-
|
|
2634
|
+
// §8.1a — tag recorded audio as a voice note (always → waveform bubble).
|
|
2635
|
+
const voiceNoteMeta = { audioType: 'voice_note' }; // always tag → recorded audio is ALWAYS the waveform bubble
|
|
2636
|
+
sendMediaMessage(chatWithId.current, fileObj, MessageTypeConstants.audio, chatWith.current, voiceNoteMeta);
|
|
2177
2637
|
setShowInlineRecorder(false);
|
|
2178
|
-
}, []);
|
|
2638
|
+
}, [enableMultipleAttachments]);
|
|
2179
2639
|
|
|
2180
2640
|
/**
|
|
2181
2641
|
* Handle inline audio recorder cancel.
|
|
@@ -2205,9 +2665,12 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2205
2665
|
blocksRef.current = [];
|
|
2206
2666
|
pendingLinksRef.current.clear();
|
|
2207
2667
|
setEditContentBlocks(undefined);
|
|
2208
|
-
// Clear the RichTextEditor content
|
|
2209
|
-
|
|
2210
|
-
|
|
2668
|
+
// Clear the RichTextEditor content. Guard the native call — on some real devices it can throw
|
|
2669
|
+
// if the view is mid-teardown, which would otherwise abort whatever runs after clearInputBox().
|
|
2670
|
+
try {
|
|
2671
|
+
inputRef.current?.clear();
|
|
2672
|
+
} catch {}
|
|
2673
|
+
|
|
2211
2674
|
// When autoExpand is enabled, reset height to minHeight
|
|
2212
2675
|
// This handles the edge case of clearing all text
|
|
2213
2676
|
if (autoExpand) {
|
|
@@ -2919,7 +3382,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
2919
3382
|
|
|
2920
3383
|
// Resolve mention tokens (<@uid:...>, <@all:...>) to display names
|
|
2921
3384
|
// and build mentionMap so the native editor can apply mention styling.
|
|
2922
|
-
|
|
3385
|
+
// Media messages carry their editable text in the caption, not `.text`.
|
|
3386
|
+
const rawText =
|
|
3387
|
+
typeof message?.getCaption === "function"
|
|
3388
|
+
? (message.getCaption() ?? '')
|
|
3389
|
+
: (message?.text ?? '');
|
|
2923
3390
|
const mentionFormatter = allFormatters.current.get('@');
|
|
2924
3391
|
let resolvedText = rawText;
|
|
2925
3392
|
const newMentionMap = new Map<string, SuggestionItem>();
|
|
@@ -3043,6 +3510,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3043
3510
|
previewMessageForEdit: previewMessage,
|
|
3044
3511
|
sendTextMessage,
|
|
3045
3512
|
getText: () => plainTextInputRef.current,
|
|
3513
|
+
setText: (text: string) => setInputTextProgrammatic(text),
|
|
3046
3514
|
clear: () => {
|
|
3047
3515
|
clearInputBox();
|
|
3048
3516
|
inputRef.current?.clear();
|
|
@@ -3724,7 +4192,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3724
4192
|
chatWith.current
|
|
3725
4193
|
);
|
|
3726
4194
|
|
|
3727
|
-
textMessage.setSender(loggedInUser.current);
|
|
4195
|
+
if (loggedInUser.current) textMessage.setSender(loggedInUser.current as CometChat.User);
|
|
3728
4196
|
textMessage.setReceiver((user || group)!);
|
|
3729
4197
|
textMessage.setMuid(String(getUnixTimestampInMilliseconds()));
|
|
3730
4198
|
|
|
@@ -3843,18 +4311,49 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3843
4311
|
: trimmedText;
|
|
3844
4312
|
textToSend = replaceMentionsWithTokens(textToSend);
|
|
3845
4313
|
|
|
3846
|
-
//
|
|
3847
|
-
|
|
3848
|
-
|
|
3849
|
-
|
|
3850
|
-
|
|
3851
|
-
|
|
4314
|
+
// Media caption edit — keep the media (attachments) and update only the caption,
|
|
4315
|
+
// instead of replacing the media message with a text message.
|
|
4316
|
+
const isMediaEdit =
|
|
4317
|
+
typeof originalMessage?.getCaption === "function" &&
|
|
4318
|
+
typeof originalMessage?.setCaption === "function";
|
|
4319
|
+
|
|
4320
|
+
let outgoing: any;
|
|
4321
|
+
if (isMediaEdit) {
|
|
4322
|
+
// Same approach as the text edit below: build a FRESH message rather than reusing the one
|
|
4323
|
+
// the server sent us (which carries stale metadata + the prior moderation verdict). A clean
|
|
4324
|
+
// payload is re-moderated by the server just like a fresh send. Attachments are carried over
|
|
4325
|
+
// so the media survives the caption edit.
|
|
4326
|
+
const mediaMessage = new CometChat.MediaMessage(
|
|
4327
|
+
chatWithId.current,
|
|
4328
|
+
undefined as any,
|
|
4329
|
+
originalMessage.getType(),
|
|
4330
|
+
chatWith.current
|
|
4331
|
+
);
|
|
4332
|
+
mediaMessage.setId(
|
|
4333
|
+
originalMessage.getId ? originalMessage.getId() : originalMessage.id
|
|
4334
|
+
);
|
|
4335
|
+
const existingAttachments = originalMessage.getAttachments?.() ?? [];
|
|
4336
|
+
if (existingAttachments.length) mediaMessage.setAttachments(existingAttachments);
|
|
4337
|
+
mediaMessage.setCaption(textToSend);
|
|
4338
|
+
if (parentMessageId) {
|
|
4339
|
+
mediaMessage.setParentMessageId(parentMessageId as number);
|
|
4340
|
+
}
|
|
4341
|
+
outgoing = mediaMessage;
|
|
4342
|
+
} else {
|
|
4343
|
+
// Create new text message with edited content
|
|
4344
|
+
const textMessage = new CometChat.TextMessage(
|
|
4345
|
+
chatWithId.current,
|
|
4346
|
+
textToSend,
|
|
4347
|
+
chatWith.current
|
|
4348
|
+
);
|
|
3852
4349
|
|
|
3853
|
-
|
|
3854
|
-
|
|
4350
|
+
// Set the message ID from the original message
|
|
4351
|
+
textMessage.setId(originalMessage.id);
|
|
3855
4352
|
|
|
3856
|
-
|
|
3857
|
-
|
|
4353
|
+
if (parentMessageId) {
|
|
4354
|
+
textMessage.setParentMessageId(parentMessageId as number);
|
|
4355
|
+
}
|
|
4356
|
+
outgoing = textMessage;
|
|
3858
4357
|
}
|
|
3859
4358
|
|
|
3860
4359
|
// Clear input and preview
|
|
@@ -3863,7 +4362,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3863
4362
|
|
|
3864
4363
|
// If custom send handler is provided, use it
|
|
3865
4364
|
if (onSendButtonPress) {
|
|
3866
|
-
onSendButtonPress(
|
|
4365
|
+
onSendButtonPress(outgoing);
|
|
3867
4366
|
return;
|
|
3868
4367
|
}
|
|
3869
4368
|
|
|
@@ -3873,7 +4372,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3873
4372
|
}
|
|
3874
4373
|
|
|
3875
4374
|
// Edit message via SDK
|
|
3876
|
-
CometChat.editMessage(
|
|
4375
|
+
CometChat.editMessage(outgoing)
|
|
3877
4376
|
.then((editedMessage: CometChat.BaseMessage) => {
|
|
3878
4377
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3879
4378
|
message: editedMessage,
|
|
@@ -3927,6 +4426,9 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3927
4426
|
* .start() on a new animation cancels the previous one.
|
|
3928
4427
|
*/
|
|
3929
4428
|
const hasContent = hasActualContent(inputText);
|
|
4429
|
+
// Hide the mic (→ show send) when there's text OR staged attachments — you can't record a voice
|
|
4430
|
+
// note on top of a media message, and the design shows only Send once media is attached.
|
|
4431
|
+
const micCollapsed = hasContent || selectedAttachments.length > 0;
|
|
3930
4432
|
useEffect(() => {
|
|
3931
4433
|
if (hideVoiceRecordingButton) return;
|
|
3932
4434
|
|
|
@@ -3934,18 +4436,18 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3934
4436
|
Animated.parallel([
|
|
3935
4437
|
// Visual: slide + fade (native driver for 60fps)
|
|
3936
4438
|
Animated.timing(micAnimValue, {
|
|
3937
|
-
toValue:
|
|
4439
|
+
toValue: micCollapsed ? 1 : 0,
|
|
3938
4440
|
duration: MIC_ANIM_DURATION,
|
|
3939
4441
|
useNativeDriver: true,
|
|
3940
4442
|
}),
|
|
3941
4443
|
// Layout: width collapse (JS driver, needed for layout props)
|
|
3942
4444
|
Animated.timing(micWidthAnim, {
|
|
3943
|
-
toValue:
|
|
4445
|
+
toValue: micCollapsed ? 0 : 1,
|
|
3944
4446
|
duration: MIC_ANIM_DURATION,
|
|
3945
4447
|
useNativeDriver: false,
|
|
3946
4448
|
}),
|
|
3947
4449
|
]).start();
|
|
3948
|
-
}, [
|
|
4450
|
+
}, [micCollapsed, hideVoiceRecordingButton]);
|
|
3949
4451
|
|
|
3950
4452
|
/**
|
|
3951
4453
|
* Check if send button should be disabled.
|
|
@@ -3953,7 +4455,20 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3953
4455
|
* - Streaming state (disabled while AI is responding)
|
|
3954
4456
|
* - Send button delay (disabled for 1 second after sending)
|
|
3955
4457
|
*/
|
|
3956
|
-
const
|
|
4458
|
+
const hasPendingUploads = selectedAttachments.some(
|
|
4459
|
+
a => a.uploadState === 'NONE' || a.uploadState === 'UPLOADING'
|
|
4460
|
+
);
|
|
4461
|
+
// Any errored (FAILED/REJECTED) staged attachment blocks send entirely — the user must
|
|
4462
|
+
// ✕-remove the errored file(s) first, so we never ship a partial batch.
|
|
4463
|
+
const hasErroredUploads = selectedAttachments.some(
|
|
4464
|
+
a => a.uploadState === 'FAILED' || a.uploadState === 'REJECTED'
|
|
4465
|
+
);
|
|
4466
|
+
const isSendDisabled =
|
|
4467
|
+
isStreaming ||
|
|
4468
|
+
isSendButtonDisabledForDelay ||
|
|
4469
|
+
hasPendingUploads ||
|
|
4470
|
+
hasErroredUploads ||
|
|
4471
|
+
(!hasActualContent(inputText) && selectedAttachments.length === 0);
|
|
3957
4472
|
|
|
3958
4473
|
/**
|
|
3959
4474
|
* Get send button tint color based on state
|
|
@@ -3983,37 +4498,45 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
3983
4498
|
return null;
|
|
3984
4499
|
}
|
|
3985
4500
|
|
|
4501
|
+
let content: JSX.Element;
|
|
3986
4502
|
if (SecondaryButtonView) {
|
|
3987
|
-
|
|
4503
|
+
content = (
|
|
3988
4504
|
<SecondaryButtonView
|
|
3989
4505
|
user={user}
|
|
3990
4506
|
group={group}
|
|
3991
4507
|
composerId={id || 'single-line-composer'}
|
|
3992
4508
|
/>
|
|
3993
4509
|
);
|
|
3994
|
-
}
|
|
4510
|
+
} else {
|
|
4511
|
+
// Default attachment button - opens action sheet. Always enabled (even at capacity) so it never
|
|
4512
|
+
// feels broken; an over-limit pick is rejected on selection (acceptPickedAttachments + count toast).
|
|
4513
|
+
const handleAttachmentClick = () => {
|
|
4514
|
+
if (onAttachmentClick) {
|
|
4515
|
+
onAttachmentClick();
|
|
4516
|
+
}
|
|
4517
|
+
setShowActionSheet(true);
|
|
4518
|
+
};
|
|
3995
4519
|
|
|
3996
|
-
|
|
3997
|
-
|
|
3998
|
-
|
|
3999
|
-
|
|
4000
|
-
|
|
4001
|
-
|
|
4002
|
-
|
|
4520
|
+
// Always show attachment button by default (per requirements doc)
|
|
4521
|
+
// The button opens the attachment action sheet with default options from ChatConfigurator
|
|
4522
|
+
// Use SVG icon name for proper tintColor support
|
|
4523
|
+
content = (
|
|
4524
|
+
<IconButton
|
|
4525
|
+
testID="CometChatComposer.attach"
|
|
4526
|
+
name={attachmentIcon ? undefined : 'add-circle'}
|
|
4527
|
+
icon={attachmentIcon}
|
|
4528
|
+
onClick={handleAttachmentClick}
|
|
4529
|
+
buttonStyle={Style.iconButton}
|
|
4530
|
+
iconStyle={Style.icon}
|
|
4531
|
+
tintColor={getAttachmentIconTint()}
|
|
4532
|
+
/>
|
|
4533
|
+
);
|
|
4534
|
+
}
|
|
4003
4535
|
|
|
4004
|
-
//
|
|
4005
|
-
|
|
4006
|
-
|
|
4007
|
-
|
|
4008
|
-
<IconButton
|
|
4009
|
-
name={attachmentIcon ? undefined : 'add-circle'}
|
|
4010
|
-
icon={attachmentIcon}
|
|
4011
|
-
onClick={handleAttachmentClick}
|
|
4012
|
-
buttonStyle={Style.iconButton}
|
|
4013
|
-
iconStyle={Style.icon}
|
|
4014
|
-
tintColor={getAttachmentIconTint()}
|
|
4015
|
-
/>
|
|
4016
|
-
);
|
|
4536
|
+
// Edit mode: attachments are disabled (greyed, non-interactive) — only Send and Sticker stay active.
|
|
4537
|
+
return messagePreview ? (
|
|
4538
|
+
<View pointerEvents="none" style={{ opacity: DISABLED_BUTTON_OPACITY }}>{content}</View>
|
|
4539
|
+
) : content;
|
|
4017
4540
|
};
|
|
4018
4541
|
|
|
4019
4542
|
/**
|
|
@@ -4132,10 +4655,11 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4132
4655
|
const sendIconColor = isSendDisabled
|
|
4133
4656
|
? (theme.color.iconSecondary as string)
|
|
4134
4657
|
: (theme.color.primaryButtonIcon as string);
|
|
4658
|
+
const handleSendPress = selectedAttachments.length > 0 ? sendMultiAttachmentMediaMessage : sendTextMessage;
|
|
4135
4659
|
return (
|
|
4136
4660
|
<TouchableOpacity
|
|
4137
4661
|
testID="send-button"
|
|
4138
|
-
onPress={
|
|
4662
|
+
onPress={handleSendPress}
|
|
4139
4663
|
disabled={isSendDisabled}
|
|
4140
4664
|
style={[{
|
|
4141
4665
|
width: theme.spacing.spacing.s8,
|
|
@@ -4196,7 +4720,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4196
4720
|
}}
|
|
4197
4721
|
>
|
|
4198
4722
|
<Animated.View
|
|
4199
|
-
pointerEvents={
|
|
4723
|
+
pointerEvents={micCollapsed || messagePreview ? 'none' : 'auto'}
|
|
4200
4724
|
style={{
|
|
4201
4725
|
opacity: micAnimValue.interpolate({ inputRange: [0, 1], outputRange: [1, 0] }),
|
|
4202
4726
|
transform: [{ translateX: micAnimValue.interpolate({ inputRange: [0, 1], outputRange: [0, MIC_SLIDE_DISTANCE] }) }],
|
|
@@ -4277,6 +4801,30 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4277
4801
|
>
|
|
4278
4802
|
{/* Outer wrapper with padding (matches Figma: Message Composer) */}
|
|
4279
4803
|
<View style={wrapperStyle}>
|
|
4804
|
+
{/* Error banner floats ABOVE the composer, over the message list. Anchored to the outer
|
|
4805
|
+
wrapper (bottom:100%), NOT the bordered container which clips via overflow:hidden. */}
|
|
4806
|
+
<View
|
|
4807
|
+
onLayout={(e) => {
|
|
4808
|
+
const h = e.nativeEvent.layout.height;
|
|
4809
|
+
if (h > 0 && h !== attachmentBannerHeight) setAttachmentBannerHeight(h);
|
|
4810
|
+
}}
|
|
4811
|
+
style={{
|
|
4812
|
+
position: 'absolute',
|
|
4813
|
+
left: 0,
|
|
4814
|
+
right: 0,
|
|
4815
|
+
// Sit fully ABOVE the composer with a gap: top = -(measured banner height + gap), so it
|
|
4816
|
+
// clears the composer regardless of text length. Hidden until measured (avoids a flash).
|
|
4817
|
+
top: -(attachmentBannerHeight + theme.spacing.spacing.s3),
|
|
4818
|
+
paddingHorizontal: theme.spacing.padding.p2, // match the composer's side inset
|
|
4819
|
+
opacity: attachmentBannerHeight > 0 ? 1 : 0,
|
|
4820
|
+
}}
|
|
4821
|
+
pointerEvents="box-none"
|
|
4822
|
+
>
|
|
4823
|
+
<CometChatComposerErrorBanner
|
|
4824
|
+
message={attachmentBannerMessage}
|
|
4825
|
+
onDismiss={() => setAttachmentBannerMessage(null)}
|
|
4826
|
+
/>
|
|
4827
|
+
</View>
|
|
4280
4828
|
{/* Inner container with border (matches Figma: Base_Message Composer) */}
|
|
4281
4829
|
<View style={containerStyle}>
|
|
4282
4830
|
{/* Action Sheet for attachments */}
|
|
@@ -4285,9 +4833,16 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4285
4833
|
options={actionSheetItems}
|
|
4286
4834
|
shouldShow={showActionSheet}
|
|
4287
4835
|
onClose={() => setShowActionSheet(false)}
|
|
4836
|
+
// iOS: launch the deferred picker only after the sheet's modal has
|
|
4837
|
+
// fully dismissed, so UIKit isn't asked to present while dismissing.
|
|
4838
|
+
onDismiss={() => {
|
|
4839
|
+
const action = pendingAttachmentActionRef.current;
|
|
4840
|
+
pendingAttachmentActionRef.current = null;
|
|
4841
|
+
action?.();
|
|
4842
|
+
}}
|
|
4288
4843
|
style={resolvedStyle?.attachmentOptionsStyles}
|
|
4289
4844
|
/>
|
|
4290
|
-
|
|
4845
|
+
|
|
4291
4846
|
{/* Voice Recording - removed bottom sheet, using inline recorder instead */}
|
|
4292
4847
|
|
|
4293
4848
|
{HeaderView ? (
|
|
@@ -4356,6 +4911,20 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4356
4911
|
/>
|
|
4357
4912
|
) : (
|
|
4358
4913
|
<>
|
|
4914
|
+
{trayMediaItems.length > 0 && (
|
|
4915
|
+
<CometChatMediaViewer
|
|
4916
|
+
mediaItems={trayMediaItems}
|
|
4917
|
+
startIndex={trayViewerIndex}
|
|
4918
|
+
visible={trayViewerVisible}
|
|
4919
|
+
onClose={() => setTrayViewerVisible(false)}
|
|
4920
|
+
/>
|
|
4921
|
+
)}
|
|
4922
|
+
{selectedAttachments.length > 0 && (
|
|
4923
|
+
<StagedVideoDurationProbe
|
|
4924
|
+
attachments={selectedAttachments}
|
|
4925
|
+
onDuration={handleVideoDuration}
|
|
4926
|
+
/>
|
|
4927
|
+
)}
|
|
4359
4928
|
{/* Top Field - Input row with icons (matches Figma: Top Field) */}
|
|
4360
4929
|
<View
|
|
4361
4930
|
style={[
|
|
@@ -4371,10 +4940,10 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4371
4940
|
{/* Secondary button (attachment) */}
|
|
4372
4941
|
{renderSecondaryButton()}
|
|
4373
4942
|
</View>
|
|
4374
|
-
|
|
4943
|
+
|
|
4375
4944
|
{/* Auxiliary button on left if alignment is 'left' */}
|
|
4376
4945
|
{resolvedAlignment === 'left' && renderAuxiliaryButton()}
|
|
4377
|
-
|
|
4946
|
+
|
|
4378
4947
|
{/* Rich Text Editor - replaces TextInput with same styling */}
|
|
4379
4948
|
<View
|
|
4380
4949
|
style={{ flex: 1, maxHeight: resolvedMaxHeight, overflow: 'hidden' }}
|
|
@@ -4465,12 +5034,17 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4465
5034
|
showTextSelectionMenuItems={showTextSelectionMenuItems}
|
|
4466
5035
|
onSendRequest={() => {
|
|
4467
5036
|
if (!isSendDisabled) {
|
|
4468
|
-
|
|
5037
|
+
if (selectedAttachments.length > 0) {
|
|
5038
|
+
sendMultiAttachmentMediaMessage();
|
|
5039
|
+
} else {
|
|
5040
|
+
sendTextMessage();
|
|
5041
|
+
}
|
|
4469
5042
|
}
|
|
4470
5043
|
}}
|
|
5044
|
+
onPasteMedia={handlePasteMedia}
|
|
4471
5045
|
/>
|
|
4472
5046
|
</View>
|
|
4473
|
-
|
|
5047
|
+
|
|
4474
5048
|
{/* Right icons container - dynamic alignment based on expansion state */}
|
|
4475
5049
|
<View style={[
|
|
4476
5050
|
Style.rightIconsContainer,
|
|
@@ -4481,15 +5055,26 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4481
5055
|
renderAuxiliaryButton()
|
|
4482
5056
|
)}
|
|
4483
5057
|
{resolvedAlignment === 'right' && hideVoiceRecordingButton && renderAuxiliaryButton()}
|
|
4484
|
-
|
|
5058
|
+
|
|
4485
5059
|
{/* Voice recording button - matches Figma design */}
|
|
4486
5060
|
{!hideVoiceRecordingButton && !isAgenticUser() && <RecordAudioButtonView />}
|
|
4487
|
-
|
|
5061
|
+
|
|
4488
5062
|
{/* Send button */}
|
|
4489
5063
|
{renderSendButton()}
|
|
4490
5064
|
</View>
|
|
4491
5065
|
</View>
|
|
4492
5066
|
|
|
5067
|
+
{/* Attachment preview strip — BELOW the input row (design: tray under the input,
|
|
5068
|
+
icons stay inline on the input row). Only shown when files are queued. */}
|
|
5069
|
+
{selectedAttachments.length > 0 && (
|
|
5070
|
+
<CometChatAttachmentTray
|
|
5071
|
+
attachments={selectedAttachments}
|
|
5072
|
+
onRemove={handleRemoveAttachment}
|
|
5073
|
+
onRetry={handleRetryAttachment}
|
|
5074
|
+
onPressTile={handleTrayTilePress}
|
|
5075
|
+
/>
|
|
5076
|
+
)}
|
|
5077
|
+
|
|
4493
5078
|
{/* Rich text toolbar — shown below input row */}
|
|
4494
5079
|
{enableRichTextEditor && !hideRichTextFormattingOptions && (
|
|
4495
5080
|
<View style={{
|
|
@@ -4504,7 +5089,7 @@ export const CometChatCompactMessageComposer = React.forwardRef(
|
|
|
4504
5089
|
testID="toolbar-scrollview"
|
|
4505
5090
|
horizontal
|
|
4506
5091
|
showsHorizontalScrollIndicator={false}
|
|
4507
|
-
contentContainerStyle={
|
|
5092
|
+
contentContainerStyle={richTextToolbarStyles.toolbarScrollContent}
|
|
4508
5093
|
>
|
|
4509
5094
|
{richTextToolbarItems.map((item, index) => {
|
|
4510
5095
|
if (item.type === 'separator') {
|