@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
|
@@ -39,6 +39,7 @@ import { ChatConfigurator, CometChatSoundManager } from "../shared";
|
|
|
39
39
|
import { commonVars } from "../shared/base/vars";
|
|
40
40
|
import {
|
|
41
41
|
ConversationOptionConstants,
|
|
42
|
+
DISABLED_BUTTON_OPACITY,
|
|
42
43
|
MentionsTargetElement,
|
|
43
44
|
MentionsVisibility,
|
|
44
45
|
MessageTypeConstants,
|
|
@@ -65,6 +66,17 @@ import { CometChatTheme } from "../theme/type";
|
|
|
65
66
|
import { deepMerge } from "../shared/helper/helperFunctions";
|
|
66
67
|
import { JSX } from "react";
|
|
67
68
|
import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
|
|
69
|
+
// Multiple Attachment Support — U8
|
|
70
|
+
// §5.0 — canonical DD name (CometChatAttachmentPreview is the back-compat alias)
|
|
71
|
+
import { CometChatAttachmentTray } from "../shared/views/CometChatAttachmentPreview";
|
|
72
|
+
import { CometChatMediaViewer } from "../shared/views/CometChatMediaViewer";
|
|
73
|
+
import { SelectedAttachment, toAttachmentFile } from "../shared/modals/SelectedAttachment";
|
|
74
|
+
import { UploadQueueService } from "../shared/services/UploadQueueService";
|
|
75
|
+
import { openMultiFileChooser } from "../shared/utils/openMultiFileChooser";
|
|
76
|
+
import { getFileUploadLimits, clampToServer, acceptPickedAttachments, toastAttachmentRejection } from "../shared/utils/attachmentLimits";
|
|
77
|
+
import { partitionAttachmentsByKind, AttachmentKindGroup } from "../shared/utils/partitionAttachmentsByKind";
|
|
78
|
+
import { attachmentCountLabel } from "../shared/utils/conversationUtils";
|
|
79
|
+
import { CometChatComposerErrorBanner } from "../shared/views/CometChatComposerErrorBanner";
|
|
68
80
|
|
|
69
81
|
type MentionOverlap = {
|
|
70
82
|
key: string;
|
|
@@ -78,15 +90,13 @@ const { FileManager, CommonUtil } = NativeModules;
|
|
|
78
90
|
const uiEventListenerShow = "uiEvent_show_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
79
91
|
const uiEventListenerHide = "uiEvent_hide_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
80
92
|
|
|
81
|
-
|
|
82
|
-
|
|
83
93
|
const AttachIconButton = (props: {
|
|
84
94
|
onPress: TouchableWithoutFeedbackProps["onPress"];
|
|
85
95
|
icon: ImageSourcePropType | JSX.Element;
|
|
86
96
|
iconStyle: ImageStyle;
|
|
87
97
|
}) => {
|
|
88
98
|
return (
|
|
89
|
-
<TouchableOpacity onPress={props.onPress}>
|
|
99
|
+
<TouchableOpacity testID="CometChatComposer.attach" onPress={props.onPress}>
|
|
90
100
|
<Icon
|
|
91
101
|
name='add-circle'
|
|
92
102
|
icon={props.icon}
|
|
@@ -100,12 +110,13 @@ const AttachIconButton = (props: {
|
|
|
100
110
|
};
|
|
101
111
|
|
|
102
112
|
const ActionSheetBoard = (props: any) => {
|
|
103
|
-
const { shouldShow = false, onClose = () => {}, options = [], sheetRef, style } = props;
|
|
113
|
+
const { shouldShow = false, onClose = () => {}, onDismiss, options = [], sheetRef, style } = props;
|
|
104
114
|
return (
|
|
105
115
|
<CometChatBottomSheet
|
|
106
116
|
style={{ maxHeight: Dimensions.get("window").height * 0.49 }}
|
|
107
117
|
ref={sheetRef}
|
|
108
118
|
onClose={onClose}
|
|
119
|
+
onDismiss={onDismiss}
|
|
109
120
|
isOpen={shouldShow}
|
|
110
121
|
doNotOccupyEntireHeight
|
|
111
122
|
>
|
|
@@ -359,6 +370,14 @@ export interface CometChatMessageComposerInterface {
|
|
|
359
370
|
*/
|
|
360
371
|
imageQuality?: IntRange<1, 100>;
|
|
361
372
|
|
|
373
|
+
/**
|
|
374
|
+
* Enables the multiple-attachment workflow (staging tray + multi-upload; a send
|
|
375
|
+
* fans out into one message per kind). When `false`, attachments use the legacy
|
|
376
|
+
* single-select, send-immediately path (one picker → one message, no tray).
|
|
377
|
+
* @default true
|
|
378
|
+
*/
|
|
379
|
+
enableMultipleAttachments?: boolean;
|
|
380
|
+
|
|
362
381
|
/**
|
|
363
382
|
* If true, hides the camera option from the attachment options.
|
|
364
383
|
*/
|
|
@@ -460,6 +479,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
460
479
|
|
|
461
480
|
const theme = useTheme();
|
|
462
481
|
const {t} = useCometChatTranslation()
|
|
482
|
+
// Attachment error/info messages show as a red banner just above the tray (rendered below).
|
|
483
|
+
const [attachmentBannerMessage, setAttachmentBannerMessage] = React.useState<string | null>(null);
|
|
484
|
+
const [attachmentBannerHeight, setAttachmentBannerHeight] = React.useState(0);
|
|
485
|
+
const attachmentBannerTimer = React.useRef<ReturnType<typeof setTimeout> | null>(null);
|
|
486
|
+
const showToast = useCallback((message: string) => {
|
|
487
|
+
setAttachmentBannerMessage(message);
|
|
488
|
+
if (attachmentBannerTimer.current) clearTimeout(attachmentBannerTimer.current);
|
|
489
|
+
attachmentBannerTimer.current = setTimeout(() => setAttachmentBannerMessage(null), 4000);
|
|
490
|
+
}, []);
|
|
491
|
+
useEffect(() => () => { if (attachmentBannerTimer.current) clearTimeout(attachmentBannerTimer.current); }, []);
|
|
463
492
|
const {
|
|
464
493
|
id,
|
|
465
494
|
user,
|
|
@@ -499,6 +528,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
499
528
|
addAttachmentOptions,
|
|
500
529
|
auxiliaryButtonsAlignment = "left",
|
|
501
530
|
AgentSendButtonView,
|
|
531
|
+
// §1 — false → legacy single-select, send-immediately attachments (no tray/fan-out).
|
|
532
|
+
enableMultipleAttachments = true,
|
|
502
533
|
} = props;
|
|
503
534
|
|
|
504
535
|
// Helper function to check if user is agentic
|
|
@@ -565,6 +596,10 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
565
596
|
const [showActionSheet, setShowActionSheet] = React.useState(false);
|
|
566
597
|
const [showRecordAudio, setShowRecordAudio] = React.useState(false);
|
|
567
598
|
const [actionSheetItems, setActionSheetItems] = React.useState<any[]>([]);
|
|
599
|
+
// iOS: holds a picker launch that must wait until the action sheet's modal has
|
|
600
|
+
// fully dismissed — UIKit can't present the picker while the modal is dismissing.
|
|
601
|
+
// Fired from the sheet's onDismiss. Unused on Android (picker launches inline).
|
|
602
|
+
const pendingAttachmentActionRef = React.useRef<(() => void) | null>(null);
|
|
568
603
|
const [messagePreview, setMessagePreview] = React.useState<any>();
|
|
569
604
|
const [replyMessage, setReplyMessage] = React.useState<any>();
|
|
570
605
|
// Ref to hold current replyMessage value to avoid stale closures in attachment handlers
|
|
@@ -582,6 +617,17 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
582
617
|
const [warningMessage, setWarningMessage] = React.useState("");
|
|
583
618
|
const [originalText, setOriginalText] = React.useState<string>("");
|
|
584
619
|
const [hasEdited, setHasEdited] = React.useState<boolean>(false);
|
|
620
|
+
const [selectedAttachments, setSelectedAttachments] = React.useState<SelectedAttachment[]>([]);
|
|
621
|
+
// Live mirror of the staged count — the picker/paste handlers can be invoked from
|
|
622
|
+
// memoized closures that captured an older count, so read the CURRENT tray size from
|
|
623
|
+
// this ref when enforcing the count limit (avoids letting picks slip past the max).
|
|
624
|
+
const selectedAttachmentsRef = React.useRef<SelectedAttachment[]>([]);
|
|
625
|
+
React.useEffect(() => {
|
|
626
|
+
selectedAttachmentsRef.current = selectedAttachments;
|
|
627
|
+
}, [selectedAttachments]);
|
|
628
|
+
|
|
629
|
+
const [trayViewerVisible, setTrayViewerVisible] = React.useState(false);
|
|
630
|
+
const [trayViewerIndex, setTrayViewerIndex] = React.useState(0);
|
|
585
631
|
const [plainText, setPlainText] = React.useState(initialComposertext ?? "");
|
|
586
632
|
const bottomSheetRef = React.useRef<any>(null);
|
|
587
633
|
const [showStopButton, setShowStopButton] = React.useState(false);
|
|
@@ -607,6 +653,158 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
607
653
|
});
|
|
608
654
|
}, [mergedComposerStyle, hideStickersButton, hideAuxiliaryButtons, replyMessage, closeReplyPreview]);
|
|
609
655
|
|
|
656
|
+
// Multi-attachment: one UploadQueueService per composer mount
|
|
657
|
+
const uploadQueue = useMemo(
|
|
658
|
+
() =>
|
|
659
|
+
new UploadQueueService({
|
|
660
|
+
onProgress: (fileId, percent) => {
|
|
661
|
+
setSelectedAttachments(prev =>
|
|
662
|
+
prev.map(a =>
|
|
663
|
+
a.fileId === fileId ? { ...a, uploadState: 'UPLOADING', uploadProgress: percent } : a
|
|
664
|
+
)
|
|
665
|
+
);
|
|
666
|
+
},
|
|
667
|
+
onFileComplete: (fileId, attachment) => {
|
|
668
|
+
setSelectedAttachments(prev =>
|
|
669
|
+
prev.map(a =>
|
|
670
|
+
a.fileId === fileId
|
|
671
|
+
? { ...a, uploadState: 'COMPLETED', uploadProgress: 100, uploadedAttachment: attachment }
|
|
672
|
+
: a
|
|
673
|
+
)
|
|
674
|
+
);
|
|
675
|
+
},
|
|
676
|
+
onFileFailed: (fileId, error) => {
|
|
677
|
+
// Retryable network/server failure — show ⚠ tap-to-retry affordance
|
|
678
|
+
setSelectedAttachments(prev =>
|
|
679
|
+
prev.map(a =>
|
|
680
|
+
a.fileId === fileId ? { ...a, uploadState: 'FAILED', errorKey: 'UPLOAD_FAILED', rawError: error } : a
|
|
681
|
+
)
|
|
682
|
+
);
|
|
683
|
+
},
|
|
684
|
+
onFileRejected: (fileId, error) => {
|
|
685
|
+
// Store the SDK error code; the user sees WHY by tapping the errored tile (no auto-toast,
|
|
686
|
+
// so several rejections can't spam). See handleTrayTilePress → toastAttachmentRejection.
|
|
687
|
+
const code = error?.code ?? (error as any)?.getCode?.();
|
|
688
|
+
setSelectedAttachments(prev =>
|
|
689
|
+
prev.map(a =>
|
|
690
|
+
a.fileId === fileId ? { ...a, uploadState: 'REJECTED', errorKey: 'ATTACHMENT_UPLOAD_UNAVAILABLE', errorCode: code, rawError: error } : a
|
|
691
|
+
)
|
|
692
|
+
);
|
|
693
|
+
},
|
|
694
|
+
onAllComplete: () => {
|
|
695
|
+
// Send is driven by the send button, not by this callback.
|
|
696
|
+
},
|
|
697
|
+
}),
|
|
698
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
699
|
+
[]
|
|
700
|
+
);
|
|
701
|
+
|
|
702
|
+
const updateAttachment = useCallback(
|
|
703
|
+
(fileId: string, patch: Partial<SelectedAttachment>) => {
|
|
704
|
+
setSelectedAttachments(prev =>
|
|
705
|
+
prev.map(a => (a.fileId === fileId ? { ...a, ...patch } : a))
|
|
706
|
+
);
|
|
707
|
+
},
|
|
708
|
+
[]
|
|
709
|
+
);
|
|
710
|
+
|
|
711
|
+
const handlePickFiles = useCallback(
|
|
712
|
+
async (pickerType: 'media' | 'document' | 'camera' | 'audio') => {
|
|
713
|
+
// Live staged count (ref), not the possibly-stale closure value.
|
|
714
|
+
const existingCount = selectedAttachmentsRef.current.length;
|
|
715
|
+
// Server-authoritative upload limits (file.count.max / per-file file.size.max),
|
|
716
|
+
// clamped tighten-only against any developer override (§5.1 / §6.1).
|
|
717
|
+
const serverLimits = await getFileUploadLimits();
|
|
718
|
+
const maxCount = clampToServer(undefined, serverLimits.fileCountMax);
|
|
719
|
+
|
|
720
|
+
// Always open the picker (even at capacity) so the button never feels broken. Enforcement is
|
|
721
|
+
// on selection: acceptPickedAttachments rejects the whole over-limit pick + shows the toast.
|
|
722
|
+
const picked = await openMultiFileChooser(pickerType, existingCount, maxCount);
|
|
723
|
+
if (picked.length === 0) return;
|
|
724
|
+
|
|
725
|
+
// §6.3 — over the count limit → reject the whole pick (see acceptPickedAttachments). Per-file
|
|
726
|
+
// SIZE is enforced by the SDK (ERR_FILE_SIZE_EXCEEDED → onFileRejected), not here.
|
|
727
|
+
const accepted = acceptPickedAttachments(picked, { maxCount, existingCount }, { showToast, t });
|
|
728
|
+
if (accepted.length === 0) return;
|
|
729
|
+
|
|
730
|
+
const newAttachments: SelectedAttachment[] = accepted.map(f => ({
|
|
731
|
+
fileId: '_' + Math.random().toString(36).substr(2, 9),
|
|
732
|
+
file: toAttachmentFile(f),
|
|
733
|
+
uploadState: 'NONE',
|
|
734
|
+
uploadProgress: 0,
|
|
735
|
+
}));
|
|
736
|
+
|
|
737
|
+
setSelectedAttachments(prev => {
|
|
738
|
+
const next = [...prev, ...newAttachments];
|
|
739
|
+
// Mirror the ref SYNCHRONOUSLY so a quick second pick reads the exact count (not the stale
|
|
740
|
+
// post-render useEffect value). Otherwise existingCount under-counts, the pick gate lets too
|
|
741
|
+
// many through, and the shared SDK upload group overflows file.count.max → ERR_FILE_COUNT_EXCEEDED
|
|
742
|
+
// even though the tray shows fewer than the limit.
|
|
743
|
+
selectedAttachmentsRef.current = next;
|
|
744
|
+
return next;
|
|
745
|
+
});
|
|
746
|
+
// Pass the target conversation so the SDK can hand receiver/receiverType to the server for
|
|
747
|
+
// RBAC/SBAC presign authorization. Read the refs fresh here (uploadQueue is memoized at mount,
|
|
748
|
+
// the refs are not) — constructor-time capture would be stale.
|
|
749
|
+
newAttachments.forEach(a =>
|
|
750
|
+
uploadQueue.enqueue(a, { receiver: chatWithId.current, receiverType: chatWith.current })
|
|
751
|
+
);
|
|
752
|
+
},
|
|
753
|
+
[selectedAttachments, uploadQueue]
|
|
754
|
+
);
|
|
755
|
+
|
|
756
|
+
const handleRemoveAttachment = useCallback(
|
|
757
|
+
(fileId: string) => {
|
|
758
|
+
uploadQueue.dequeue(fileId);
|
|
759
|
+
setSelectedAttachments(prev => {
|
|
760
|
+
const next = prev.filter(a => a.fileId !== fileId);
|
|
761
|
+
selectedAttachmentsRef.current = next; // keep the ref exact for the next pick's count gate
|
|
762
|
+
return next;
|
|
763
|
+
});
|
|
764
|
+
},
|
|
765
|
+
[uploadQueue]
|
|
766
|
+
);
|
|
767
|
+
|
|
768
|
+
const handleRetryAttachment = useCallback(
|
|
769
|
+
(fileId: string) => {
|
|
770
|
+
const attachment = selectedAttachments.find(a => a.fileId === fileId);
|
|
771
|
+
if (!attachment) return;
|
|
772
|
+
updateAttachment(fileId, { uploadState: 'NONE', uploadProgress: 0, errorKey: undefined });
|
|
773
|
+
uploadQueue.retry(fileId, { ...attachment, uploadState: 'NONE', uploadProgress: 0 });
|
|
774
|
+
},
|
|
775
|
+
[selectedAttachments, updateAttachment, uploadQueue]
|
|
776
|
+
);
|
|
777
|
+
|
|
778
|
+
// §8.2 — staged-attachment media items for tray preview viewer (local URIs)
|
|
779
|
+
const trayMediaItems = React.useMemo(() => {
|
|
780
|
+
return selectedAttachments
|
|
781
|
+
.filter(a => a.file.type.startsWith('image/') || a.file.type.startsWith('video/'))
|
|
782
|
+
.map(a => ({
|
|
783
|
+
getUrl: () => a.file.uri,
|
|
784
|
+
getMimeType: () => a.file.type,
|
|
785
|
+
getName: () => a.file.name,
|
|
786
|
+
getSize: () => a.file.size || 0,
|
|
787
|
+
} as unknown as CometChat.Attachment));
|
|
788
|
+
}, [selectedAttachments]);
|
|
789
|
+
|
|
790
|
+
const handleTrayTilePress = useCallback((fileId: string) => {
|
|
791
|
+
const att = selectedAttachments.find(a => a.fileId === fileId);
|
|
792
|
+
if (!att) return;
|
|
793
|
+
// DEBUG — dump the real SDK error for a tapped errored tile.
|
|
794
|
+
// Rejected tile → tap reveals WHY it failed (size, etc.) as a toast.
|
|
795
|
+
if (att.uploadState === 'REJECTED') {
|
|
796
|
+
toastAttachmentRejection(att, { showToast, t });
|
|
797
|
+
return;
|
|
798
|
+
}
|
|
799
|
+
const mediaOnly = selectedAttachments.filter(
|
|
800
|
+
a => a.file.type.startsWith('image/') || a.file.type.startsWith('video/')
|
|
801
|
+
);
|
|
802
|
+
const idx = mediaOnly.findIndex(a => a.fileId === fileId);
|
|
803
|
+
if (idx < 0) return;
|
|
804
|
+
setTrayViewerIndex(idx);
|
|
805
|
+
setTrayViewerVisible(true);
|
|
806
|
+
}, [selectedAttachments, showToast, t]);
|
|
807
|
+
|
|
610
808
|
useEffect(() => {
|
|
611
809
|
setShowStopButton(false);
|
|
612
810
|
setIsStreaming(false);
|
|
@@ -616,6 +814,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
616
814
|
if (sendButtonDelayTimer.current) {
|
|
617
815
|
clearTimeout(sendButtonDelayTimer.current);
|
|
618
816
|
}
|
|
817
|
+
uploadQueue.cancelAll();
|
|
619
818
|
};
|
|
620
819
|
}, []);
|
|
621
820
|
|
|
@@ -644,6 +843,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
644
843
|
previewMessageForEdit: previewMessage,
|
|
645
844
|
sendTextMessage,
|
|
646
845
|
getText: () => messageInputRef.current?.getText?.() ?? "",
|
|
846
|
+
setText: (text: string) => {
|
|
847
|
+
plainTextInput.current = text;
|
|
848
|
+
setPlainText(text);
|
|
849
|
+
messageInputRef.current?.setNativeProps?.({ text });
|
|
850
|
+
},
|
|
647
851
|
clear: () => messageInputRef.current?.clear?.(),
|
|
648
852
|
resetStreaming: () => {
|
|
649
853
|
setShowStopButton(false);
|
|
@@ -700,9 +904,14 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
700
904
|
// Don't clear reply preview here - it needs to remain available for sendMediaMessage
|
|
701
905
|
// The reply preview will be cleared after successful send in sendMediaMessage (line 1127)
|
|
702
906
|
|
|
703
|
-
|
|
907
|
+
// Media messages carry their editable text in the caption, not `.text`.
|
|
908
|
+
const editSourceText =
|
|
909
|
+
typeof message?.getCaption === "function"
|
|
910
|
+
? (message.getCaption() ?? "")
|
|
911
|
+
: (message?.text ?? "");
|
|
912
|
+
let textComponents = editSourceText;
|
|
704
913
|
|
|
705
|
-
let rawText =
|
|
914
|
+
let rawText = editSourceText;
|
|
706
915
|
|
|
707
916
|
let users: any = {};
|
|
708
917
|
let regexes: Array<RegExp> = [];
|
|
@@ -742,7 +951,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
742
951
|
// Sort edits by startIndex to apply them in order
|
|
743
952
|
edits.sort((a: any, b: any) => a.startIndex - b.startIndex);
|
|
744
953
|
|
|
745
|
-
plainTextInput.current = getPlainString(
|
|
954
|
+
plainTextInput.current = getPlainString(editSourceText, edits) ?? "";
|
|
746
955
|
setPlainText(plainTextInput.current);
|
|
747
956
|
setOriginalText(plainTextInput.current.trim());
|
|
748
957
|
setHasEdited(false);
|
|
@@ -806,21 +1015,49 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
806
1015
|
sendMediaMessage(chatWithId.current, file, MessageTypeConstants.image, chatWith.current);
|
|
807
1016
|
};
|
|
808
1017
|
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
1018
|
+
// The actual picker presentation. Split out from fileInputHandler so it can be
|
|
1019
|
+
// launched inline (Android) or deferred to the sheet's onDismiss (iOS).
|
|
1020
|
+
const launchPicker = async (fileType: string) => {
|
|
1021
|
+
// §1 — MULTI (default): route image/video/file/camera through the staging tray.
|
|
1022
|
+
if (enableMultipleAttachments) {
|
|
1023
|
+
if (
|
|
1024
|
+
fileType === MessageTypeConstants.image ||
|
|
1025
|
+
fileType === MessageTypeConstants.video
|
|
1026
|
+
) {
|
|
1027
|
+
await handlePickFiles('media');
|
|
812
1028
|
return;
|
|
813
1029
|
}
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
1030
|
+
if (fileType === MessageTypeConstants.file) {
|
|
1031
|
+
await handlePickFiles('document');
|
|
1032
|
+
return;
|
|
817
1033
|
}
|
|
818
|
-
if (
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
FileManager.openCamera(fileType, cameraCallback);
|
|
1034
|
+
if (fileType === MessageTypeConstants.audio) {
|
|
1035
|
+
await handlePickFiles('audio');
|
|
1036
|
+
return;
|
|
822
1037
|
}
|
|
823
|
-
|
|
1038
|
+
if (fileType === MessageTypeConstants.takePhoto) {
|
|
1039
|
+
if (!(await permissionUtil.startResourceBasedTask(["camera"]))) {
|
|
1040
|
+
return;
|
|
1041
|
+
}
|
|
1042
|
+
await handlePickFiles('camera');
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
// §1 — LEGACY single-select, send-immediately (flag=false, or audio/other types):
|
|
1048
|
+
// one picker → one MediaMessage, no tray/multi-upload.
|
|
1049
|
+
if (fileType === MessageTypeConstants.takePhoto) {
|
|
1050
|
+
if (!(await permissionUtil.startResourceBasedTask(["camera"]))) return;
|
|
1051
|
+
const onCapture = (result: any) => {
|
|
1052
|
+
if (result && !CheckPropertyExists(result, "error") && result.uri) {
|
|
1053
|
+
sendMediaMessage(chatWithId.current, { name: result.name, type: result.type, uri: result.uri }, MessageTypeConstants.image, chatWith.current);
|
|
1054
|
+
}
|
|
1055
|
+
};
|
|
1056
|
+
if (Platform.OS === "ios") FileManager.openCamera("image", onCapture);
|
|
1057
|
+
else FileManager.openCamera("image", 50, onCapture);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1060
|
+
if (Platform.OS === "ios" && fileType === MessageTypeConstants.video) {
|
|
824
1061
|
NativeModules.VideoPickerModule.pickVideo((file: any) => {
|
|
825
1062
|
if (file.uri)
|
|
826
1063
|
sendMediaMessage(
|
|
@@ -845,6 +1082,23 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
845
1082
|
});
|
|
846
1083
|
};
|
|
847
1084
|
|
|
1085
|
+
const fileInputHandler = (fileType: string) => {
|
|
1086
|
+
// Always close the attachment sheet first.
|
|
1087
|
+
// iOS: UIKit can't present the picker while the sheet's modal is still
|
|
1088
|
+
// dismissing, so stash the launch and fire it from the modal's onDismiss
|
|
1089
|
+
// (see the ActionSheetBoard below). Android has no such restriction, so launch
|
|
1090
|
+
// immediately as the sheet closes.
|
|
1091
|
+
if (Platform.OS === "ios") {
|
|
1092
|
+
pendingAttachmentActionRef.current = () => {
|
|
1093
|
+
void launchPicker(fileType);
|
|
1094
|
+
};
|
|
1095
|
+
setShowActionSheet(false);
|
|
1096
|
+
return;
|
|
1097
|
+
}
|
|
1098
|
+
setShowActionSheet(false);
|
|
1099
|
+
void launchPicker(fileType);
|
|
1100
|
+
};
|
|
1101
|
+
|
|
848
1102
|
const playAudio = () => {
|
|
849
1103
|
if (customSoundForOutgoingMessage) {
|
|
850
1104
|
CometChatSoundManager.play(
|
|
@@ -856,6 +1110,136 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
856
1110
|
}
|
|
857
1111
|
};
|
|
858
1112
|
|
|
1113
|
+
const sendMultiAttachmentMediaMessage = useCallback(() => {
|
|
1114
|
+
// Guard: never ship a partial batch. If any staged tile errored (FAILED/REJECTED), block
|
|
1115
|
+
// the send until the user removes it (the send button is also disabled in this state).
|
|
1116
|
+
if (selectedAttachmentsRef.current.some(a => a.uploadState === 'FAILED' || a.uploadState === 'REJECTED')) {
|
|
1117
|
+
return;
|
|
1118
|
+
}
|
|
1119
|
+
const completed = uploadQueue.completedAttachments;
|
|
1120
|
+
if (completed.length === 0) return;
|
|
1121
|
+
|
|
1122
|
+
// Prefer the SDK's upload batch id (DD §5.3) as the message batchId; captured BEFORE cancelAll
|
|
1123
|
+
// releases the request. Fall back to a client timestamp id when the SDK doesn't expose one.
|
|
1124
|
+
const sdkBatchId = uploadQueue.batchId;
|
|
1125
|
+
|
|
1126
|
+
// Release the SDK upload group + clear the queue's completed set so the NEXT pick starts a FRESH
|
|
1127
|
+
// group. Without this the already-sent attachments linger in `completed` and get re-included in
|
|
1128
|
+
// the next send (e.g. send 3 images, then add 1 → the next send ships all 4).
|
|
1129
|
+
uploadQueue.cancelAll();
|
|
1130
|
+
|
|
1131
|
+
// §7 — FAN OUT: partition the completed tiles by kind and send ONE MediaMessage per
|
|
1132
|
+
// non-empty kind (Images → Videos → Files; picker audio → file), all sharing one
|
|
1133
|
+
// batchId. Each message gets its own muid; the caption goes on the LAST message only.
|
|
1134
|
+
const groups = partitionAttachmentsByKind(completed);
|
|
1135
|
+
if (groups.length === 0) return;
|
|
1136
|
+
|
|
1137
|
+
const batchId = sdkBatchId ?? String(getUnixTimestampInMilliseconds());
|
|
1138
|
+
// §8.4 — total attachments across the whole batch, so the conversation-list preview can
|
|
1139
|
+
// aggregate ("N attachments") from just the last fanned-out message it receives.
|
|
1140
|
+
const batchTotalCount = groups.reduce((sum, g) => sum + g.attachments.length, 0);
|
|
1141
|
+
const caption = plainTextInput.current.trim();
|
|
1142
|
+
const currentReplyMessage = replyMessageRef.current;
|
|
1143
|
+
const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
|
|
1144
|
+
|
|
1145
|
+
// ENG-36991 — clear the swipe-to-reply preview UP-FRONT (the quote is captured above), so a
|
|
1146
|
+
// throw anywhere in the fan-out/teardown below can't leave the reply preview stuck on a real
|
|
1147
|
+
// device (it worked on the emulator, not on device). The reset block below is now redundant.
|
|
1148
|
+
setReplyMessage(null);
|
|
1149
|
+
replyMessageRef.current = null;
|
|
1150
|
+
|
|
1151
|
+
// Fresh MediaMessage for a group — used for both the optimistic echo and the send.
|
|
1152
|
+
const buildMessage = (group: AttachmentKindGroup, index: number, muid: string) => {
|
|
1153
|
+
const m = new CometChat.MediaMessage(chatWithId.current, null, group.type, chatWith.current);
|
|
1154
|
+
m.setSender(loggedInUser.current);
|
|
1155
|
+
m.setMuid(muid);
|
|
1156
|
+
// setAttachments() writes data.attachments (validateMessage + FormData read there).
|
|
1157
|
+
m.setAttachments(group.attachments);
|
|
1158
|
+
// §7/§8.3a batch contract — lets the message list group the fanned-out messages.
|
|
1159
|
+
m.setMetadata({ batchId, batchIndex: index, batchSize: groups.length, batchTotalCount });
|
|
1160
|
+
if (index === groups.length - 1 && caption) m.setCaption(caption); // caption on LAST only
|
|
1161
|
+
if (parentMessageId) m.setParentMessageId(parentMessageId as number); // thread parent on ALL
|
|
1162
|
+
// Quoted reply on the FIRST message of the batch only — otherwise every fanned-out bubble
|
|
1163
|
+
// shows the "replying to X" quote. (Thread parentMessageId above stays on all.)
|
|
1164
|
+
if (replyMessageId && currentReplyMessage?.message && index === 0) {
|
|
1165
|
+
if (typeof m.setQuotedMessage === 'function') m.setQuotedMessage(currentReplyMessage.message);
|
|
1166
|
+
if (typeof m.setQuotedMessageId === 'function') m.setQuotedMessageId(replyMessageId);
|
|
1167
|
+
(m as any).quotedMessage = currentReplyMessage.message;
|
|
1168
|
+
(m as any).quotedMessageId = replyMessageId;
|
|
1169
|
+
}
|
|
1170
|
+
return m;
|
|
1171
|
+
};
|
|
1172
|
+
|
|
1173
|
+
groups.forEach((group, index) => {
|
|
1174
|
+
const muid = `${batchId}_${index}`;
|
|
1175
|
+
const localMessage = buildMessage(group, index, muid);
|
|
1176
|
+
|
|
1177
|
+
// Optimistic (in-progress) bubble for this kind's message, keyed by its muid.
|
|
1178
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
1179
|
+
message: localMessage,
|
|
1180
|
+
status: messageStatus.inprogress,
|
|
1181
|
+
});
|
|
1182
|
+
|
|
1183
|
+
// §7/§12.1 — independent per-message send: one kind can fail while others deliver.
|
|
1184
|
+
const outgoing = buildMessage(group, index, muid);
|
|
1185
|
+
CometChat.sendMediaMessage(outgoing)
|
|
1186
|
+
.then((msg: any) => {
|
|
1187
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
1188
|
+
message: msg,
|
|
1189
|
+
status: messageStatus.success,
|
|
1190
|
+
});
|
|
1191
|
+
if (replyMessageId) {
|
|
1192
|
+
CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
|
|
1193
|
+
message: msg,
|
|
1194
|
+
status: messageStatus.success,
|
|
1195
|
+
});
|
|
1196
|
+
}
|
|
1197
|
+
})
|
|
1198
|
+
.catch((error: any) => {
|
|
1199
|
+
// Preserve the batch metadata; just flag this message's optimistic echo as failed.
|
|
1200
|
+
const currentData = localMessage.getData() || {};
|
|
1201
|
+
localMessage.setData({ ...currentData, metaData: { error: true } });
|
|
1202
|
+
const md = (localMessage.getMetadata?.() as Record<string, unknown>) || {};
|
|
1203
|
+
localMessage.setMetadata({ ...md, error: true });
|
|
1204
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
1205
|
+
message: localMessage,
|
|
1206
|
+
status: messageStatus.error,
|
|
1207
|
+
});
|
|
1208
|
+
onError && onError(error);
|
|
1209
|
+
});
|
|
1210
|
+
});
|
|
1211
|
+
|
|
1212
|
+
// Clear composer state immediately
|
|
1213
|
+
setSelectedAttachments([]);
|
|
1214
|
+
selectedAttachmentsRef.current = []; // keep the ref exact so a pick right after send isn't gated on a stale count
|
|
1215
|
+
plainTextInput.current = '';
|
|
1216
|
+
inputValueRef.current = '';
|
|
1217
|
+
setPlainText('');
|
|
1218
|
+
setInputMessage('');
|
|
1219
|
+
setReplyMessage(null);
|
|
1220
|
+
|
|
1221
|
+
if (!disableSoundForOutgoingMessages) {
|
|
1222
|
+
if (customSoundForOutgoingMessage) {
|
|
1223
|
+
CometChatSoundManager.play(
|
|
1224
|
+
CometChatSoundManager.SoundOutput.outgoingMessage,
|
|
1225
|
+
customSoundForOutgoingMessage
|
|
1226
|
+
);
|
|
1227
|
+
} else {
|
|
1228
|
+
CometChatSoundManager.play(CometChatSoundManager.SoundOutput.outgoingMessage);
|
|
1229
|
+
}
|
|
1230
|
+
}
|
|
1231
|
+
}, [
|
|
1232
|
+
uploadQueue,
|
|
1233
|
+
chatWithId,
|
|
1234
|
+
chatWith,
|
|
1235
|
+
loggedInUser,
|
|
1236
|
+
parentMessageId,
|
|
1237
|
+
replyMessageRef,
|
|
1238
|
+
disableSoundForOutgoingMessages,
|
|
1239
|
+
customSoundForOutgoingMessage,
|
|
1240
|
+
onError,
|
|
1241
|
+
]);
|
|
1242
|
+
|
|
859
1243
|
const clearInputBox = () => {
|
|
860
1244
|
inputValueRef.current = "";
|
|
861
1245
|
setPlainText("");
|
|
@@ -1025,13 +1409,41 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1025
1409
|
let finalTextInput = getRegexString(plainTextInput.current);
|
|
1026
1410
|
|
|
1027
1411
|
let messageText = finalTextInput.trim();
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1412
|
+
|
|
1413
|
+
// Media caption edit — keep the media (attachments) and update only the caption.
|
|
1414
|
+
// Mirrors the text path (fresh minimal message) so we don't PUT stale receipt/entity fields.
|
|
1415
|
+
const isMediaEdit =
|
|
1416
|
+
typeof message?.getCaption === "function" &&
|
|
1417
|
+
typeof message?.setCaption === "function";
|
|
1418
|
+
|
|
1419
|
+
let outgoing: any;
|
|
1420
|
+
if (isMediaEdit) {
|
|
1421
|
+
// Same approach as the text edit below: build a FRESH message rather than reusing the one
|
|
1422
|
+
// the server sent us (which carries stale metadata + the prior moderation verdict). A clean
|
|
1423
|
+
// payload is re-moderated by the server just like a fresh send. Attachments are carried over
|
|
1424
|
+
// so the media survives the caption edit.
|
|
1425
|
+
const mediaMessage = new CometChat.MediaMessage(
|
|
1426
|
+
chatWithId.current,
|
|
1427
|
+
undefined as any,
|
|
1428
|
+
message.getType(),
|
|
1429
|
+
chatWith.current
|
|
1430
|
+
);
|
|
1431
|
+
mediaMessage.setId(message.getId ? message.getId() : message.id);
|
|
1432
|
+
const existingAttachments = message.getAttachments?.() ?? [];
|
|
1433
|
+
if (existingAttachments.length) mediaMessage.setAttachments(existingAttachments);
|
|
1434
|
+
mediaMessage.setCaption(messageText);
|
|
1435
|
+
parentMessageId && mediaMessage.setParentMessageId(parentMessageId as number);
|
|
1436
|
+
outgoing = mediaMessage;
|
|
1437
|
+
} else {
|
|
1438
|
+
let textMessage = new CometChat.TextMessage(
|
|
1439
|
+
chatWithId.current,
|
|
1440
|
+
messageText,
|
|
1441
|
+
chatWith.current
|
|
1442
|
+
);
|
|
1443
|
+
textMessage.setId(message.id);
|
|
1444
|
+
parentMessageId && textMessage.setParentMessageId(parentMessageId as number);
|
|
1445
|
+
outgoing = textMessage;
|
|
1446
|
+
}
|
|
1035
1447
|
|
|
1036
1448
|
inputValueRef.current = "";
|
|
1037
1449
|
clearInputBox();
|
|
@@ -1040,13 +1452,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1040
1452
|
setMessagePreview(null);
|
|
1041
1453
|
|
|
1042
1454
|
if (onSendButtonPress) {
|
|
1043
|
-
onSendButtonPress(
|
|
1455
|
+
onSendButtonPress(outgoing);
|
|
1044
1456
|
return;
|
|
1045
1457
|
}
|
|
1046
1458
|
|
|
1047
1459
|
if (!disableSoundForOutgoingMessages) playAudio();
|
|
1048
1460
|
|
|
1049
|
-
CometChat.editMessage(
|
|
1461
|
+
CometChat.editMessage(outgoing)
|
|
1050
1462
|
.then((editedMessage: any) => {
|
|
1051
1463
|
inputValueRef.current = "";
|
|
1052
1464
|
setInputMessage("");
|
|
@@ -1065,7 +1477,8 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1065
1477
|
receiverId?: any,
|
|
1066
1478
|
messageInput?: any,
|
|
1067
1479
|
messageType?: any,
|
|
1068
|
-
receiverType?: any
|
|
1480
|
+
receiverType?: any,
|
|
1481
|
+
extraMetadata?: Record<string, any>
|
|
1069
1482
|
) => {
|
|
1070
1483
|
setShowActionSheet(false);
|
|
1071
1484
|
let mediaMessage = new CometChat.MediaMessage(
|
|
@@ -1075,10 +1488,19 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1075
1488
|
receiverType
|
|
1076
1489
|
);
|
|
1077
1490
|
|
|
1491
|
+
// The optimistic echo (localMessage) and the message actually sent
|
|
1492
|
+
// (mediaMessage) MUST share ONE muid. CometChatMessageList reconciles the
|
|
1493
|
+
// in-progress bubble with the delivered message via messageEdited(), which
|
|
1494
|
+
// matches by muid — and when no match is found it does nothing, so the
|
|
1495
|
+
// delivered message is dropped and the optimistic bubble is orphaned (no
|
|
1496
|
+
// echo until a refetch). Two independent getUnixTimestampInMilliseconds()
|
|
1497
|
+
// calls can land in different milliseconds, so they must not be used
|
|
1498
|
+
// separately here. This mirrors the working multi-attachment path.
|
|
1499
|
+
const sharedMuid = String(getUnixTimestampInMilliseconds());
|
|
1078
1500
|
mediaMessage.setSender(loggedInUser.current);
|
|
1079
1501
|
mediaMessage.setReceiver(receiverType);
|
|
1080
1502
|
mediaMessage.setType(messageType);
|
|
1081
|
-
mediaMessage.setMuid(
|
|
1503
|
+
mediaMessage.setMuid(sharedMuid);
|
|
1082
1504
|
mediaMessage.setData({
|
|
1083
1505
|
type: messageType,
|
|
1084
1506
|
category: CometChat.CATEGORY_MESSAGE,
|
|
@@ -1087,6 +1509,12 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1087
1509
|
url: messageInput["uri"],
|
|
1088
1510
|
sender: loggedInUser.current,
|
|
1089
1511
|
});
|
|
1512
|
+
// setMetadata MUST run AFTER setData: the SDK stores metadata inside `data`, and setData
|
|
1513
|
+
// replaces `data` wholesale — tagging before it would be wiped from the server payload
|
|
1514
|
+
// (e.g. audioType:"voice_note" would never round-trip, so recorded audio shows the wrong bubble).
|
|
1515
|
+
if (extraMetadata) {
|
|
1516
|
+
mediaMessage.setMetadata({ ...(mediaMessage.getMetadata() || {}), ...extraMetadata });
|
|
1517
|
+
}
|
|
1090
1518
|
// Use ref to get current replyMessage value (avoids stale closure)
|
|
1091
1519
|
const currentReplyMessage = replyMessageRef.current;
|
|
1092
1520
|
const replyMessageId = currentReplyMessage?.message?.getId?.() ?? null;
|
|
@@ -1118,7 +1546,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1118
1546
|
localMessage.setSender(loggedInUser.current);
|
|
1119
1547
|
localMessage.setReceiver(receiverType);
|
|
1120
1548
|
localMessage.setType(messageType);
|
|
1121
|
-
|
|
1549
|
+
// Same muid as the sent mediaMessage above — see note there. This is what
|
|
1550
|
+
// lets messageEdited() replace this optimistic bubble with the delivered one.
|
|
1551
|
+
localMessage.setMuid(sharedMuid);
|
|
1122
1552
|
localMessage.setData({
|
|
1123
1553
|
type: messageType,
|
|
1124
1554
|
category: CometChat.CATEGORY_MESSAGE,
|
|
@@ -1161,6 +1591,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1161
1591
|
},
|
|
1162
1592
|
},
|
|
1163
1593
|
});
|
|
1594
|
+
// setMetadata AFTER the final setData (SDK stores metadata inside `data`, which setData
|
|
1595
|
+
// replaces) so the optimistic bubble carries the tag and matches the sent message.
|
|
1596
|
+
if (extraMetadata) {
|
|
1597
|
+
localMessage.setMetadata({ ...(localMessage.getMetadata() || {}), ...extraMetadata });
|
|
1598
|
+
}
|
|
1164
1599
|
|
|
1165
1600
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
|
|
1166
1601
|
message: localMessage,
|
|
@@ -1265,7 +1700,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1265
1700
|
|
|
1266
1701
|
const SecondaryButtonViewElem = useMemo(() => {
|
|
1267
1702
|
if (hideAttachmentButton || !actionSheetItems.length) return <></>;
|
|
1268
|
-
|
|
1703
|
+
// Always open the action sheet (even at capacity) so the button never feels broken; an over-limit
|
|
1704
|
+
// pick is rejected on selection (acceptPickedAttachments + count toast).
|
|
1705
|
+
const attachBtn = (
|
|
1269
1706
|
<AttachIconButton
|
|
1270
1707
|
onPress={() => {
|
|
1271
1708
|
Keyboard.dismiss();
|
|
@@ -1275,7 +1712,9 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1275
1712
|
iconStyle={mergedComposerStyle.attachmentIconStyle as ImageStyle}
|
|
1276
1713
|
/>
|
|
1277
1714
|
);
|
|
1278
|
-
|
|
1715
|
+
// Edit mode: attachments are disabled (greyed, non-interactive) — only Send and Sticker stay active.
|
|
1716
|
+
return messagePreview ? <View pointerEvents="none" style={{ opacity: DISABLED_BUTTON_OPACITY }}>{attachBtn}</View> : attachBtn;
|
|
1717
|
+
}, [mergedComposerStyle, actionSheetItems, hideAttachmentButton, messagePreview]);
|
|
1279
1718
|
|
|
1280
1719
|
const RecordAudioButtonView = ({
|
|
1281
1720
|
icon,
|
|
@@ -1306,13 +1745,18 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1306
1745
|
const voiceRecoringButtonElem = useMemo(() => {
|
|
1307
1746
|
const isAgenticUser = user?.getRole?.() === '@agentic';
|
|
1308
1747
|
|
|
1309
|
-
|
|
1748
|
+
if (hideVoiceRecordingButton || isAgenticUser) return undefined;
|
|
1749
|
+
// Once attachments are staged, hide the mic — Send takes over (matches the compact composer).
|
|
1750
|
+
if (selectedAttachments.length > 0) return undefined;
|
|
1751
|
+
const micBtn = (
|
|
1310
1752
|
<RecordAudioButtonView
|
|
1311
1753
|
icon={mergedComposerStyle.voiceRecordingIcon as ImageSourcePropType | JSX.Element}
|
|
1312
1754
|
iconStyle={mergedComposerStyle.voiceRecordingIconStyle as ImageStyle}
|
|
1313
1755
|
/>
|
|
1314
1756
|
);
|
|
1315
|
-
|
|
1757
|
+
// Edit mode: voice recording is disabled — only Send and Sticker stay active.
|
|
1758
|
+
return messagePreview ? <View pointerEvents="none" style={{ opacity: DISABLED_BUTTON_OPACITY }}>{micBtn}</View> : micBtn;
|
|
1759
|
+
}, [hideVoiceRecordingButton, mergedComposerStyle, user, messagePreview, selectedAttachments.length]);
|
|
1316
1760
|
|
|
1317
1761
|
const AuxiliaryButtonViewElem = useCallback(() => {
|
|
1318
1762
|
const isAgenticUser = user?.getRole?.() === '@agentic';
|
|
@@ -1324,7 +1768,23 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1324
1768
|
return <></>;
|
|
1325
1769
|
}
|
|
1326
1770
|
|
|
1327
|
-
if (defaultAuxiliaryButtonOptions)
|
|
1771
|
+
if (defaultAuxiliaryButtonOptions) {
|
|
1772
|
+
// Edit mode: keep only the Sticker button active; disable (grey + non-interactive) the rest.
|
|
1773
|
+
const items = messagePreview
|
|
1774
|
+
? (defaultAuxiliaryButtonOptions as any[]).map((el, idx) =>
|
|
1775
|
+
el?.key === "sticker-button"
|
|
1776
|
+
? el
|
|
1777
|
+
: (
|
|
1778
|
+
<View
|
|
1779
|
+
key={el?.key ?? `aux-${idx}`}
|
|
1780
|
+
pointerEvents="none"
|
|
1781
|
+
style={{ opacity: DISABLED_BUTTON_OPACITY }}
|
|
1782
|
+
>
|
|
1783
|
+
{el}
|
|
1784
|
+
</View>
|
|
1785
|
+
)
|
|
1786
|
+
)
|
|
1787
|
+
: defaultAuxiliaryButtonOptions;
|
|
1328
1788
|
return (
|
|
1329
1789
|
<View
|
|
1330
1790
|
style={{
|
|
@@ -1333,12 +1793,13 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1333
1793
|
gap: theme.spacing.spacing.s2,
|
|
1334
1794
|
}}
|
|
1335
1795
|
>
|
|
1336
|
-
{
|
|
1796
|
+
{items}
|
|
1337
1797
|
</View>
|
|
1338
1798
|
);
|
|
1799
|
+
}
|
|
1339
1800
|
|
|
1340
1801
|
return <></>;
|
|
1341
|
-
}, [defaultAuxiliaryButtonOptions, user, AuxiliaryButtonView, group, id, theme]);
|
|
1802
|
+
}, [defaultAuxiliaryButtonOptions, user, AuxiliaryButtonView, group, id, theme, messagePreview]);
|
|
1342
1803
|
|
|
1343
1804
|
const DefaultAgentSendButtonView = useCallback(
|
|
1344
1805
|
({ isButtonDisabled, composerRef }: { isButtonDisabled: boolean; composerRef: any }) => (
|
|
@@ -1359,7 +1820,20 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1359
1820
|
const isAgenticUserCheck = isAgenticUser();
|
|
1360
1821
|
|
|
1361
1822
|
if (isAgenticUserCheck) {
|
|
1362
|
-
const
|
|
1823
|
+
const hasPendingUploadsAgentic = selectedAttachments.some(
|
|
1824
|
+
a => a.uploadState === 'NONE' || a.uploadState === 'UPLOADING'
|
|
1825
|
+
);
|
|
1826
|
+
// Errored (FAILED/REJECTED) tiles block send until the user removes them — no partial batch.
|
|
1827
|
+
const hasErroredUploadsAgentic = selectedAttachments.some(
|
|
1828
|
+
a => a.uploadState === 'FAILED' || a.uploadState === 'REJECTED'
|
|
1829
|
+
);
|
|
1830
|
+
const disabled =
|
|
1831
|
+
isStreaming ||
|
|
1832
|
+
(plainTextInput.current.trim().length === 0 && selectedAttachments.length === 0) ||
|
|
1833
|
+
(messagePreview && !hasEdited) ||
|
|
1834
|
+
isSendButtonDisabledForDelay ||
|
|
1835
|
+
hasPendingUploadsAgentic ||
|
|
1836
|
+
hasErroredUploadsAgentic;
|
|
1363
1837
|
const SendButtonComponent = DefaultAgentSendButtonView;
|
|
1364
1838
|
// Create a ref-like object that matches what CometChatSendButtonView expects
|
|
1365
1839
|
const composerRef = {
|
|
@@ -1375,10 +1849,25 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1375
1849
|
}
|
|
1376
1850
|
|
|
1377
1851
|
if (SendButtonView) return <SendButtonView user={user} group={group} composerId={id!} />;
|
|
1378
|
-
const
|
|
1852
|
+
const hasPendingUploads = selectedAttachments.some(
|
|
1853
|
+
a => a.uploadState === 'NONE' || a.uploadState === 'UPLOADING'
|
|
1854
|
+
);
|
|
1855
|
+
// Errored (FAILED/REJECTED) tiles block send until the user removes them — no partial batch.
|
|
1856
|
+
const hasErroredUploads = selectedAttachments.some(
|
|
1857
|
+
a => a.uploadState === 'FAILED' || a.uploadState === 'REJECTED'
|
|
1858
|
+
);
|
|
1859
|
+
const disabled =
|
|
1860
|
+
isStreaming ||
|
|
1861
|
+
(plainText.trim().length === 0 && selectedAttachments.length === 0) ||
|
|
1862
|
+
(messagePreview && !hasEdited) ||
|
|
1863
|
+
hasPendingUploads ||
|
|
1864
|
+
hasErroredUploads;
|
|
1865
|
+
const handleSendPress = selectedAttachments.length > 0
|
|
1866
|
+
? sendMultiAttachmentMediaMessage
|
|
1867
|
+
: sendTextMessage;
|
|
1379
1868
|
return (
|
|
1380
1869
|
<TouchableOpacity
|
|
1381
|
-
onPress={
|
|
1870
|
+
onPress={handleSendPress}
|
|
1382
1871
|
style={[
|
|
1383
1872
|
{
|
|
1384
1873
|
borderRadius: theme.spacing.radius.max,
|
|
@@ -1402,7 +1891,7 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1402
1891
|
/>
|
|
1403
1892
|
</TouchableOpacity>
|
|
1404
1893
|
);
|
|
1405
|
-
}, [mergedComposerStyle, inputMessage, plainText, messagePreview, hasEdited, isStreaming, DefaultAgentSendButtonView, user, isAgenticUser, sendTextMessage, hideSendButton, SendButtonView, isSendButtonDisabledForDelay]);
|
|
1894
|
+
}, [mergedComposerStyle, inputMessage, plainText, messagePreview, hasEdited, isStreaming, DefaultAgentSendButtonView, user, isAgenticUser, sendTextMessage, sendMultiAttachmentMediaMessage, hideSendButton, SendButtonView, isSendButtonDisabledForDelay, selectedAttachments]);
|
|
1406
1895
|
|
|
1407
1896
|
//fetch logged in user
|
|
1408
1897
|
useEffect(() => {
|
|
@@ -1440,6 +1929,23 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1440
1929
|
}, []);
|
|
1441
1930
|
|
|
1442
1931
|
useEffect(() => {
|
|
1932
|
+
const newChatWithId = user?.getUid()
|
|
1933
|
+
? user.getUid()
|
|
1934
|
+
: group?.getGuid()
|
|
1935
|
+
? group.getGuid()
|
|
1936
|
+
: chatWithId.current;
|
|
1937
|
+
|
|
1938
|
+
// Conversation switch guard: if the receiver IDENTITY changed, drop any staged / in-flight
|
|
1939
|
+
// attachments so they can't be sent to the new receiver (wrong-destination leak). Compare the
|
|
1940
|
+
// uid/guid — NOT the user/group object refs — so a parent re-render that passes fresh objects
|
|
1941
|
+
// for the SAME conversation doesn't wipe a tray the user is mid-staging. Skip the first
|
|
1942
|
+
// assignment (chatWithId.current === null → nothing staged yet).
|
|
1943
|
+
if (chatWithId.current != null && chatWithId.current !== newChatWithId) {
|
|
1944
|
+
uploadQueue.cancelAll();
|
|
1945
|
+
setSelectedAttachments([]);
|
|
1946
|
+
selectedAttachmentsRef.current = [];
|
|
1947
|
+
}
|
|
1948
|
+
|
|
1443
1949
|
//update receiver user
|
|
1444
1950
|
if (user && user.getUid()) {
|
|
1445
1951
|
chatRef.current = {
|
|
@@ -1672,9 +2178,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1672
2178
|
type: "audio/mp4",
|
|
1673
2179
|
uri: recordedFile,
|
|
1674
2180
|
};
|
|
1675
|
-
//
|
|
1676
|
-
|
|
1677
|
-
//
|
|
2181
|
+
// §8.1a — tag recorded audio as a voice note so it renders in the WAVEFORM bubble
|
|
2182
|
+
// (CometChatAudioBubble), distinct from picked/shared audio files which use the
|
|
2183
|
+
// headphone+filename bubble. Always tagged (independent of enableMultipleAttachments).
|
|
2184
|
+
const voiceNoteMeta = { audioType: "voice_note" }; // always tag → recorded audio is ALWAYS the waveform bubble
|
|
2185
|
+
sendMediaMessage(chatWithId.current, fileObj, MessageTypeConstants.audio, chatWith.current, voiceNoteMeta);
|
|
1678
2186
|
};
|
|
1679
2187
|
|
|
1680
2188
|
function shouldOpenList(
|
|
@@ -2245,13 +2753,44 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2245
2753
|
mergedComposerStyle.containerStyle as ViewStyle,
|
|
2246
2754
|
]}
|
|
2247
2755
|
>
|
|
2756
|
+
{/* Error banner floats ABOVE the composer, over the message list. */}
|
|
2757
|
+
<View
|
|
2758
|
+
onLayout={(e) => {
|
|
2759
|
+
const h = e.nativeEvent.layout.height;
|
|
2760
|
+
if (h > 0 && h !== attachmentBannerHeight) setAttachmentBannerHeight(h);
|
|
2761
|
+
}}
|
|
2762
|
+
style={{
|
|
2763
|
+
position: 'absolute',
|
|
2764
|
+
left: 0,
|
|
2765
|
+
right: 0,
|
|
2766
|
+
// Sit fully ABOVE the composer with a gap: top = -(measured banner height + gap), so it
|
|
2767
|
+
// clears the composer regardless of text length. Hidden until measured (avoids a flash).
|
|
2768
|
+
top: -(attachmentBannerHeight + theme.spacing.spacing.s3),
|
|
2769
|
+
paddingHorizontal: theme.spacing.padding.p2, // match the composer's side inset
|
|
2770
|
+
opacity: attachmentBannerHeight > 0 ? 1 : 0,
|
|
2771
|
+
}}
|
|
2772
|
+
pointerEvents="box-none"
|
|
2773
|
+
>
|
|
2774
|
+
<CometChatComposerErrorBanner
|
|
2775
|
+
message={attachmentBannerMessage}
|
|
2776
|
+
onDismiss={() => setAttachmentBannerMessage(null)}
|
|
2777
|
+
/>
|
|
2778
|
+
</View>
|
|
2248
2779
|
<ActionSheetBoard
|
|
2249
2780
|
sheetRef={bottomSheetRef}
|
|
2250
2781
|
options={actionSheetItems}
|
|
2251
2782
|
shouldShow={showActionSheet}
|
|
2252
2783
|
onClose={() => setShowActionSheet(false)}
|
|
2784
|
+
// iOS: launch the deferred picker only after the sheet's modal has
|
|
2785
|
+
// fully dismissed, so UIKit isn't asked to present while dismissing.
|
|
2786
|
+
onDismiss={() => {
|
|
2787
|
+
const action = pendingAttachmentActionRef.current;
|
|
2788
|
+
pendingAttachmentActionRef.current = null;
|
|
2789
|
+
action?.();
|
|
2790
|
+
}}
|
|
2253
2791
|
style={mergedComposerStyle.attachmentOptionsStyles}
|
|
2254
2792
|
/>
|
|
2793
|
+
|
|
2255
2794
|
<RecordAudio
|
|
2256
2795
|
sheetRef={bottomSheetRef}
|
|
2257
2796
|
options={actionSheetItems}
|
|
@@ -2288,12 +2827,20 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2288
2827
|
style={[
|
|
2289
2828
|
{
|
|
2290
2829
|
flexDirection: "column",
|
|
2830
|
+
// Give this "above-input" area the composer surface when there's an edit/reply
|
|
2831
|
+
// preview, with NO bottom edge so it joins the input below into ONE continuous,
|
|
2832
|
+
// bordered composer surface. (The attachment tray now uses a matching surface
|
|
2833
|
+
// BELOW the input instead.)
|
|
2291
2834
|
...(messagePreview || replyMessage ? {
|
|
2292
2835
|
backgroundColor: theme.color.background1,
|
|
2293
|
-
|
|
2294
|
-
|
|
2836
|
+
// radius.r2 + borderDefault + (s0_5 / 2) width — the SAME tokens the input's
|
|
2837
|
+
// messageInputStyles.containerStyle uses, so the tray joins it seamlessly.
|
|
2838
|
+
borderTopRightRadius: theme.spacing.radius.r2,
|
|
2839
|
+
borderTopLeftRadius: theme.spacing.radius.r2,
|
|
2295
2840
|
paddingHorizontal: theme.spacing.padding.p1,
|
|
2296
|
-
|
|
2841
|
+
borderWidth: theme.spacing.spacing.s0_5 / 2,
|
|
2842
|
+
borderColor: theme.color.borderDefault,
|
|
2843
|
+
borderBottomWidth: 0,
|
|
2297
2844
|
} : {}),
|
|
2298
2845
|
},
|
|
2299
2846
|
]}
|
|
@@ -2310,6 +2857,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2310
2857
|
<CometChatMessagePreview
|
|
2311
2858
|
messagePreviewTitle={t("EDIT_MESSAGE")}
|
|
2312
2859
|
message={messagePreview?.message}
|
|
2860
|
+
// Editing a media caption: caption text is the editable subtitle; a muted overline
|
|
2861
|
+
// (media-type icon + attachment count) restores the context the hidden thumbnail gave.
|
|
2862
|
+
{...(typeof messagePreview?.message?.getCaption === "function"
|
|
2863
|
+
? {
|
|
2864
|
+
messagePreviewSubtitle:
|
|
2865
|
+
messagePreview.message.getCaption() ?? "",
|
|
2866
|
+
hideSubtitleIcon: true,
|
|
2867
|
+
overlineText: attachmentCountLabel(messagePreview.message.getType?.(), messagePreview.message.getAttachments?.()?.length ?? 1),
|
|
2868
|
+
}
|
|
2869
|
+
: {})}
|
|
2313
2870
|
showCloseIcon={true}
|
|
2314
2871
|
closeIconURL={ICONS.CLOSE}
|
|
2315
2872
|
onCloseClick={() => {
|
|
@@ -2346,6 +2903,14 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2346
2903
|
/>
|
|
2347
2904
|
)}
|
|
2348
2905
|
</View>
|
|
2906
|
+
{trayMediaItems.length > 0 && (
|
|
2907
|
+
<CometChatMediaViewer
|
|
2908
|
+
mediaItems={trayMediaItems}
|
|
2909
|
+
startIndex={trayViewerIndex}
|
|
2910
|
+
visible={trayViewerVisible}
|
|
2911
|
+
onClose={() => setTrayViewerVisible(false)}
|
|
2912
|
+
/>
|
|
2913
|
+
)}
|
|
2349
2914
|
<CometChatMessageInput
|
|
2350
2915
|
messageInputRef={messageInputRef}
|
|
2351
2916
|
text={inputMessage as string}
|
|
@@ -2354,10 +2919,19 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2354
2919
|
...mergedComposerStyle.messageInputStyles,
|
|
2355
2920
|
containerStyle: {
|
|
2356
2921
|
...mergedComposerStyle.messageInputStyles?.containerStyle,
|
|
2922
|
+
// Square the TOP for previews above (edit/reply) and the BOTTOM for the tray below,
|
|
2923
|
+
// so the input joins whichever surface is attached into one continuous composer.
|
|
2357
2924
|
...(messagePreview || replyMessage ? {
|
|
2358
2925
|
borderTopLeftRadius: 0,
|
|
2359
2926
|
borderTopRightRadius: 0,
|
|
2360
2927
|
} : {}),
|
|
2928
|
+
...(selectedAttachments.length > 0 ? {
|
|
2929
|
+
borderBottomLeftRadius: 0,
|
|
2930
|
+
borderBottomRightRadius: 0,
|
|
2931
|
+
// No bottom edge either — the tray surface below closes the box, so input + tray
|
|
2932
|
+
// read as one seamless container (like the single-line composer), not two pieces.
|
|
2933
|
+
borderBottomWidth: 0,
|
|
2934
|
+
} : {}),
|
|
2361
2935
|
},
|
|
2362
2936
|
}}
|
|
2363
2937
|
onSelectionChange={({ nativeEvent: { selection } }) => {
|
|
@@ -2365,7 +2939,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2365
2939
|
const mentionRange = getMentionRangeAtCursor(mentionMap.current, cursorPos);
|
|
2366
2940
|
|
|
2367
2941
|
if (mentionRange) {
|
|
2368
|
-
console.log('Mention boundary positions:', mentionRange);
|
|
2369
2942
|
const distanceToStart = cursorPos - mentionRange.start;
|
|
2370
2943
|
const distanceToEnd = mentionRange.end - cursorPos;
|
|
2371
2944
|
let targetPosition: number;
|
|
@@ -2376,6 +2949,11 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2376
2949
|
}
|
|
2377
2950
|
if (targetPosition !== cursorPos) {
|
|
2378
2951
|
InteractionManager.runAfterInteractions(() => {
|
|
2952
|
+
// Move the cursor IMPERATIVELY — the input is uncontrolled (the `selection`
|
|
2953
|
+
// prop was removed). A controlled `selection` prop re-fires onSelectionChange
|
|
2954
|
+
// on every re-render, which hard-freezes iOS once the attachment tray adds
|
|
2955
|
+
// layout churn. This mirrors the compact composer's proven approach.
|
|
2956
|
+
messageInputRef.current?.setSelection?.(targetPosition, targetPosition);
|
|
2379
2957
|
setSelectionPosition({ start: targetPosition, end: targetPosition });
|
|
2380
2958
|
});
|
|
2381
2959
|
return;
|
|
@@ -2385,7 +2963,6 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2385
2963
|
setSelectionPosition(selection);
|
|
2386
2964
|
openList(selection);
|
|
2387
2965
|
}}
|
|
2388
|
-
selection={selectionPosition}
|
|
2389
2966
|
onChangeText={textChangeHandler}
|
|
2390
2967
|
VoiceRecordingButtonView={voiceRecoringButtonElem}
|
|
2391
2968
|
SecondaryButtonView={SecondaryButtonViewElem}
|
|
@@ -2393,6 +2970,29 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2393
2970
|
PrimaryButtonView={SendButtonViewElem}
|
|
2394
2971
|
auxiliaryButtonAlignment={auxiliaryButtonsAlignment}
|
|
2395
2972
|
/>
|
|
2973
|
+
{/* Staged attachment tray — BELOW the input, on a matching composer surface with NO top
|
|
2974
|
+
edge so it joins the input above into ONE continuous box (mirrors the above-input
|
|
2975
|
+
surface, just bottom-rounded instead of top-rounded — same tokens). */}
|
|
2976
|
+
{selectedAttachments.length > 0 && (
|
|
2977
|
+
<View
|
|
2978
|
+
style={{
|
|
2979
|
+
backgroundColor: theme.color.background1,
|
|
2980
|
+
borderBottomRightRadius: theme.spacing.radius.r2,
|
|
2981
|
+
borderBottomLeftRadius: theme.spacing.radius.r2,
|
|
2982
|
+
paddingHorizontal: theme.spacing.padding.p1,
|
|
2983
|
+
borderWidth: theme.spacing.spacing.s0_5 / 2,
|
|
2984
|
+
borderColor: theme.color.borderDefault,
|
|
2985
|
+
borderTopWidth: 0,
|
|
2986
|
+
}}
|
|
2987
|
+
>
|
|
2988
|
+
<CometChatAttachmentTray
|
|
2989
|
+
attachments={selectedAttachments}
|
|
2990
|
+
onRemove={handleRemoveAttachment}
|
|
2991
|
+
onRetry={handleRetryAttachment}
|
|
2992
|
+
onPressTile={handleTrayTilePress}
|
|
2993
|
+
/>
|
|
2994
|
+
</View>
|
|
2995
|
+
)}
|
|
2396
2996
|
</View>
|
|
2397
2997
|
</KeyboardAvoidingView>
|
|
2398
2998
|
{CustomViewFooter ? (
|