@cometchat/chat-uikit-react-native 5.3.9 → 5.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
- 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 +237 -6
- 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 +312 -4
- package/ios/RichTextEditorViewManager.m +1 -0
- package/ios/SoundPlayer.m +18 -6
- package/package.json +9 -7
- package/react-native-cometchat-ui-kit.podspec +1 -0
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +692 -107
- package/src/CometChatConversations/CometChatConversations.tsx +28 -6
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +649 -49
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +23 -4
- package/src/CometChatMessageList/CometChatMessageList.tsx +530 -58
- package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -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/framework/DataSource.ts +14 -4
- package/src/shared/framework/DataSourceDecorator.tsx +17 -8
- package/src/shared/framework/MessageDataSource.tsx +321 -62
- 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 +43 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +43 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +44 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +44 -2
- package/src/shared/services/UploadQueueService.ts +145 -0
- package/src/shared/services/index.ts +2 -0
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +42 -18
- 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 +44 -4
- 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 +5 -7
- 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/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
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +0 -478
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +0 -613
|
@@ -71,6 +71,8 @@ import { Icon } from "../shared/icons/Icon";
|
|
|
71
71
|
import { CometChatMessageTemplate } from "../shared/modals/CometChatMessageTemplate";
|
|
72
72
|
import { getUnixTimestamp, messageStatus } from "../shared/utils/CometChatMessageHelper";
|
|
73
73
|
import { CommonUtils } from "../shared/utils/CommonUtils";
|
|
74
|
+
import { CometChatBatchMediaContext, BatchMediaResult } from "../shared/utils/batchMediaContext";
|
|
75
|
+
import { CometChatUIKit } from "../shared/CometChatUiKit/CometChatUIKit";
|
|
74
76
|
import { CometChatNewMessageIndicator, CometChatReceipt, NewMessageIndicatorStyle } from "../shared/views";
|
|
75
77
|
import { CometChatAvatar } from "../shared/views/CometChatAvatar";
|
|
76
78
|
import { CometChatBadge } from "../shared/views/CometChatBadge";
|
|
@@ -105,9 +107,10 @@ import { MessageModals } from "./components/MessageModals";
|
|
|
105
107
|
import { ReactionModals } from "./components/ReactionModals";
|
|
106
108
|
import { MessageOptionsSheet } from "./components/MessageOptionsSheet";
|
|
107
109
|
import { MessageListItem } from "./components/MessageListItem";
|
|
110
|
+
import CometChatConversationStarter from "../shared/views/CometChatConversationStarter/CometChatConversationStarter";
|
|
111
|
+
import CometChatSmartReplies from "../shared/views/CometChatSmartReplies/CometChatSmartReplies";
|
|
108
112
|
|
|
109
113
|
let _defaultRequestBuilder: CometChat.MessagesRequestBuilder;
|
|
110
|
-
const SEPARATOR_HEIGHT = 40;
|
|
111
114
|
const AVERAGE_ITEM_LENGTH = 120;
|
|
112
115
|
const SMALL_LIST_THRESHOLD = 30;
|
|
113
116
|
|
|
@@ -415,6 +418,12 @@ export interface CometChatMessageListProps {
|
|
|
415
418
|
* Flag to hide the reply option
|
|
416
419
|
*/
|
|
417
420
|
hideReplyOption?: boolean;
|
|
421
|
+
/**
|
|
422
|
+
* DD §9 — message-list attachment rendering. `true` (default): new per-type bubbles that render
|
|
423
|
+
* 1..N attachments (including a single one). `false`: the deprecated single-attachment bubbles
|
|
424
|
+
* (set this only to keep legacy single-bubble styling for messages that carry one attachment).
|
|
425
|
+
*/
|
|
426
|
+
enableMultipleAttachments?: boolean;
|
|
418
427
|
/**
|
|
419
428
|
* Flag to hide the reply in thread option
|
|
420
429
|
*/
|
|
@@ -491,6 +500,14 @@ export interface CometChatMessageListProps {
|
|
|
491
500
|
* Callback when suggested message is clicked (only applies to @agentic users)
|
|
492
501
|
*/
|
|
493
502
|
onSuggestedMessageClick?: (suggestion: string) => void;
|
|
503
|
+
/**
|
|
504
|
+
* When true, shows AI-generated conversation starters when the message list is empty.
|
|
505
|
+
*/
|
|
506
|
+
showConversationStarters?: boolean;
|
|
507
|
+
/**
|
|
508
|
+
* When true, shows AI-generated smart reply chips above the composer after a new message arrives.
|
|
509
|
+
*/
|
|
510
|
+
showSmartReplies?: boolean;
|
|
494
511
|
/**
|
|
495
512
|
* Custom AI assistant tools with action functions (only applies to @agentic users)
|
|
496
513
|
*/
|
|
@@ -584,6 +601,81 @@ export interface CometChatMessageListActionsInterface {
|
|
|
584
601
|
updateMessageReceipt: (message: CometChat.BaseMessage) => void;
|
|
585
602
|
}
|
|
586
603
|
|
|
604
|
+
// ---------------------------------------------------------------------------
|
|
605
|
+
// §8.3a — Batch grouping helpers. After the §7 fan-out, one user "send" becomes
|
|
606
|
+
// N single-kind messages sharing metadata.batchId. Consecutive messages from the
|
|
607
|
+
// same sender that share a batchId render as ONE visual group: a single avatar on
|
|
608
|
+
// the group's first (top/oldest) member and a single receipt+timestamp on the last
|
|
609
|
+
// (bottom/newest) member. Pure functions (no closures) — safe to reuse anywhere.
|
|
610
|
+
// ---------------------------------------------------------------------------
|
|
611
|
+
function getMessageBatchId(m: any): string | number | null {
|
|
612
|
+
try {
|
|
613
|
+
const md = m?.getMetadata?.();
|
|
614
|
+
const id = md?.batchId;
|
|
615
|
+
return id === undefined || id === null || id === "" ? null : id;
|
|
616
|
+
} catch {
|
|
617
|
+
return null;
|
|
618
|
+
}
|
|
619
|
+
}
|
|
620
|
+
|
|
621
|
+
/** True when both messages belong to the SAME batch (same non-empty batchId) AND the same sender. */
|
|
622
|
+
function isSameBatchGroup(a: any, b: any): boolean {
|
|
623
|
+
if (!a || !b) return false;
|
|
624
|
+
const ba = getMessageBatchId(a);
|
|
625
|
+
const bb = getMessageBatchId(b);
|
|
626
|
+
if (ba == null || bb == null || ba !== bb) return false;
|
|
627
|
+
const ua = a.getSender?.()?.getUid?.();
|
|
628
|
+
const ub = b.getSender?.()?.getUid?.();
|
|
629
|
+
return !!ua && ua === ub;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
function getMessageBatchIndex(m: any): number {
|
|
633
|
+
try {
|
|
634
|
+
const bi = m?.getMetadata?.()?.batchIndex;
|
|
635
|
+
return typeof bi === "number" ? bi : 0;
|
|
636
|
+
} catch {
|
|
637
|
+
return 0;
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
|
|
641
|
+
/**
|
|
642
|
+
* §8.3a — enforce the sender's order within a batch on the RECEIVE side. Each kind fans out
|
|
643
|
+
* into an INDEPENDENT async upload, so a small file can arrive (and be stored by the server)
|
|
644
|
+
* before a large image — which would show Files above Images. We reorder each CONTIGUOUS run
|
|
645
|
+
* of same-batch messages by `batchIndex` from metadata. The list is inverted (index 0 = newest
|
|
646
|
+
* / bottom) and a higher batchIndex was sent later, so a run is ordered DESCENDING by batchIndex
|
|
647
|
+
* (last-sent at the bottom). Non-batch messages and the overall message order are untouched.
|
|
648
|
+
* Returns the SAME array reference when nothing needed reordering (keeps the memo stable).
|
|
649
|
+
*/
|
|
650
|
+
function orderBatchRuns(messages: any[]): any[] {
|
|
651
|
+
if (!Array.isArray(messages) || messages.length < 2) return messages;
|
|
652
|
+
const result = messages.slice();
|
|
653
|
+
let changed = false;
|
|
654
|
+
let i = 0;
|
|
655
|
+
while (i < result.length) {
|
|
656
|
+
if (getMessageBatchId(result[i]) == null) {
|
|
657
|
+
i++;
|
|
658
|
+
continue;
|
|
659
|
+
}
|
|
660
|
+
let j = i;
|
|
661
|
+
while (j + 1 < result.length && isSameBatchGroup(result[j + 1], result[i])) j++;
|
|
662
|
+
if (j > i) {
|
|
663
|
+
const run = result.slice(i, j + 1);
|
|
664
|
+
const sorted = run.slice().sort((a, b) => getMessageBatchIndex(b) - getMessageBatchIndex(a));
|
|
665
|
+
let runChanged = false;
|
|
666
|
+
for (let k = 0; k < run.length; k++) {
|
|
667
|
+
if (run[k] !== sorted[k]) { runChanged = true; break; }
|
|
668
|
+
}
|
|
669
|
+
if (runChanged) {
|
|
670
|
+
result.splice(i, run.length, ...sorted);
|
|
671
|
+
changed = true;
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
i = j + 1;
|
|
675
|
+
}
|
|
676
|
+
return changed ? result : messages;
|
|
677
|
+
}
|
|
678
|
+
|
|
587
679
|
export const CometChatMessageList = memo(
|
|
588
680
|
forwardRef<CometChatMessageListActionsInterface, CometChatMessageListProps>(
|
|
589
681
|
(props: CometChatMessageListProps, ref) => {
|
|
@@ -622,6 +714,7 @@ export const CometChatMessageList = memo(
|
|
|
622
714
|
addTemplates = [],
|
|
623
715
|
onLoad,
|
|
624
716
|
onEmpty,
|
|
717
|
+
enableMultipleAttachments = true,
|
|
625
718
|
hideReplyOption: propHideReplyOption = false,
|
|
626
719
|
hideReplyInThreadOption: propHideReplyInThreadOption = false,
|
|
627
720
|
hideShareMessageOption: propHideShareMessageOption = false,
|
|
@@ -640,6 +733,8 @@ export const CometChatMessageList = memo(
|
|
|
640
733
|
emptyChatIntroMessageView,
|
|
641
734
|
emptyChatImageView,
|
|
642
735
|
onSuggestedMessageClick,
|
|
736
|
+
showConversationStarters = false,
|
|
737
|
+
showSmartReplies = false,
|
|
643
738
|
aiAssistantTools,
|
|
644
739
|
streamingSpeed = 30,
|
|
645
740
|
goToMessageId,
|
|
@@ -950,6 +1045,9 @@ export const CometChatMessageList = memo(
|
|
|
950
1045
|
// State for showing bottom loading indicator when fetching next messages
|
|
951
1046
|
const [bottomLoading, setBottomLoading] = useState(false);
|
|
952
1047
|
const [unreadCount, setUnreadCount] = useState<number>(0);
|
|
1048
|
+
const [showSmartRepliesView, setShowSmartRepliesView] = useState(false);
|
|
1049
|
+
const [smartRepliesKey, setSmartRepliesKey] = useState('');
|
|
1050
|
+
const latestReceivedMessageRef = useRef<CometChat.BaseMessage | null>(null);
|
|
953
1051
|
const [showMessageOptions, setShowMessageOptions] = useState<any[]>([]);
|
|
954
1052
|
const [ExtensionsComponent, setExtensionsComponent] = useState<JSX.Element | null>(null);
|
|
955
1053
|
const [CustomListHeader, setCustomListHeader] = useState<any>(null);
|
|
@@ -1642,6 +1740,7 @@ export const CometChatMessageList = memo(
|
|
|
1642
1740
|
const isAgenticUserCheck = isAgenticUser;
|
|
1643
1741
|
const options = {
|
|
1644
1742
|
textFormatters: textFormatters || [],
|
|
1743
|
+
enableMultipleAttachments,
|
|
1645
1744
|
hideReplyOption: isAgenticUserCheck || hideReplyOption,
|
|
1646
1745
|
hideReplyInThreadOption: isAgenticUserCheck || hideReplyInThreadOption,
|
|
1647
1746
|
hideShareMessageOption: isAgenticUserCheck || hideShareMessageOption,
|
|
@@ -1963,9 +2062,23 @@ export const CometChatMessageList = memo(
|
|
|
1963
2062
|
}
|
|
1964
2063
|
|
|
1965
2064
|
if (isAgenticUser) {
|
|
2065
|
+
// A 1:1 agent conversation only ever contains user-receiver messages. Reject
|
|
2066
|
+
// anything addressed to a group (e.g. a group agent reply that reached this
|
|
2067
|
+
// listener) — otherwise a top-level group message matches the parent-id check
|
|
2068
|
+
// below (String(undefined) === String(undefined)) and leaks into the 1:1 chat.
|
|
2069
|
+
//
|
|
2070
|
+
// In a 1:1 agent chat the `parentMessageId` prop is undefined, but messages
|
|
2071
|
+
// from the 2nd onward are stamped with the first message's id (the thread
|
|
2072
|
+
// root), tracked in agenticParentMessageIdRef. Accept those too, otherwise
|
|
2073
|
+
// every message after the first is filtered out until a remount refetch.
|
|
2074
|
+
const agenticParentId = agenticParentMessageIdRef.current;
|
|
1966
2075
|
if (
|
|
1967
|
-
|
|
1968
|
-
String(baseMessage.
|
|
2076
|
+
baseMessage.getReceiverType?.() === ReceiverTypeConstants.user &&
|
|
2077
|
+
(String(baseMessage.getParentMessageId()) === String(parentMessageId) ||
|
|
2078
|
+
String(baseMessage.getId()) === String(parentMessageId) ||
|
|
2079
|
+
(agenticParentId !== undefined &&
|
|
2080
|
+
(String(baseMessage.getParentMessageId()) === String(agenticParentId) ||
|
|
2081
|
+
String(baseMessage.getId()) === String(agenticParentId))))
|
|
1969
2082
|
) {
|
|
1970
2083
|
CometChat.markAsDelivered(newMessage);
|
|
1971
2084
|
bottomHandler(newMessage, isReceived);
|
|
@@ -1973,11 +2086,11 @@ export const CometChatMessageList = memo(
|
|
|
1973
2086
|
return;
|
|
1974
2087
|
}
|
|
1975
2088
|
} else {
|
|
1976
|
-
|
|
2089
|
+
const inSameConversation =
|
|
1977
2090
|
checkSameConversation(baseMessage) ||
|
|
1978
2091
|
checkMessageInSameConversation(baseMessage) ||
|
|
1979
|
-
messageToSameConversation(baseMessage)
|
|
1980
|
-
) {
|
|
2092
|
+
messageToSameConversation(baseMessage);
|
|
2093
|
+
if (inSameConversation) {
|
|
1981
2094
|
if (user) {
|
|
1982
2095
|
CometChat.markConversationAsDelivered(user.getUid(), CometChat.RECEIVER_TYPE.USER);
|
|
1983
2096
|
} else if (group) {
|
|
@@ -2035,8 +2148,22 @@ export const CometChatMessageList = memo(
|
|
|
2035
2148
|
// Thread mismatch check — must run BEFORE the sender check to prevent
|
|
2036
2149
|
// messages from appearing in the wrong context (main list vs thread)
|
|
2037
2150
|
// when the same user is logged in on multiple devices.
|
|
2151
|
+
//
|
|
2152
|
+
// Exception: in a 1:1 agent chat the `parentMessageId` prop is undefined,
|
|
2153
|
+
// but messages from the 2nd onward carry the agent thread-root id (tracked
|
|
2154
|
+
// in agenticParentMessageIdRef). Those belong in this list, so don't treat
|
|
2155
|
+
// them as a thread mismatch — otherwise every message after the first is
|
|
2156
|
+
// dropped here until a remount refetch.
|
|
2157
|
+
const isAgenticThreadRootMessage =
|
|
2158
|
+
isAgenticUser &&
|
|
2159
|
+
!parentMessageId &&
|
|
2160
|
+
agenticParentMessageIdRef.current !== undefined &&
|
|
2161
|
+
String(newMessage.getParentMessageId()) ===
|
|
2162
|
+
String(agenticParentMessageIdRef.current);
|
|
2038
2163
|
if (
|
|
2039
|
-
(!parentMessageId &&
|
|
2164
|
+
(!parentMessageId &&
|
|
2165
|
+
newMessage.getParentMessageId() &&
|
|
2166
|
+
!isAgenticThreadRootMessage) ||
|
|
2040
2167
|
(parentMessageId && !newMessage.getParentMessageId()) ||
|
|
2041
2168
|
(parentMessageId &&
|
|
2042
2169
|
newMessage.getParentMessageId() &&
|
|
@@ -2250,10 +2377,14 @@ export const CometChatMessageList = memo(
|
|
|
2250
2377
|
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
2251
2378
|
}
|
|
2252
2379
|
|
|
2253
|
-
|
|
2254
|
-
|
|
2380
|
+
// Capture the snapshot synchronously — see note on the own-message append
|
|
2381
|
+
// below: the deferred (rAF) setMessagesList must not re-read the ref, which
|
|
2382
|
+
// an intervening render can clobber back to the pre-append state.
|
|
2383
|
+
const gapNextList = messagesContentListRef.current;
|
|
2384
|
+
latestMessageRef.current = gapNextList[0] ?? newMessage;
|
|
2385
|
+
onLoad && onLoad([...gapNextList].reverse());
|
|
2255
2386
|
batchStateUpdates(() => {
|
|
2256
|
-
setMessagesList([...
|
|
2387
|
+
setMessagesList([...gapNextList]);
|
|
2257
2388
|
if (hideScrollToBottomButton === false && unreadCount < 1 && !hasTargetMessageId) {
|
|
2258
2389
|
setHideScrollToBottomButton(true);
|
|
2259
2390
|
}
|
|
@@ -2262,14 +2393,21 @@ export const CometChatMessageList = memo(
|
|
|
2262
2393
|
return;
|
|
2263
2394
|
}
|
|
2264
2395
|
}
|
|
2265
|
-
|
|
2266
|
-
|
|
2396
|
+
const nextList = [newMessage, ...messagesContentListRef.current];
|
|
2397
|
+
messagesContentListRef.current = nextList;
|
|
2398
|
+
onLoad && onLoad([...nextList].reverse());
|
|
2267
2399
|
// Update latestMessageRef for gap detection
|
|
2268
2400
|
latestMessageRef.current = newMessage;
|
|
2269
2401
|
|
|
2270
|
-
// Batch state updates for better performance
|
|
2402
|
+
// Batch state updates for better performance.
|
|
2403
|
+
// NOTE: batchStateUpdates defers to the next animation frame. Capture the list
|
|
2404
|
+
// in `nextList` and commit THAT — do not re-read messagesContentListRef.current
|
|
2405
|
+
// inside the rAF. An intervening render (e.g. the composer clearing its reply
|
|
2406
|
+
// preview after sending a quoted reply) re-syncs the ref from state via the
|
|
2407
|
+
// `messagesContentListRef.current = orderedMessagesList` line below, which would
|
|
2408
|
+
// drop this just-appended message before the deferred setMessagesList runs.
|
|
2271
2409
|
batchStateUpdates(() => {
|
|
2272
|
-
setMessagesList([...
|
|
2410
|
+
setMessagesList([...nextList]);
|
|
2273
2411
|
if (hideScrollToBottomButton === false && unreadCount < 1 && !hasTargetMessageId) {
|
|
2274
2412
|
setHideScrollToBottomButton(true);
|
|
2275
2413
|
}
|
|
@@ -2863,6 +3001,12 @@ export const CometChatMessageList = memo(
|
|
|
2863
3001
|
} else {
|
|
2864
3002
|
newMessage(textMessage);
|
|
2865
3003
|
}
|
|
3004
|
+
if (showSmartReplies && textMessage.getSender?.()?.getUid() !== loggedInUser.current?.getUid()) {
|
|
3005
|
+
latestReceivedMessageRef.current = textMessage;
|
|
3006
|
+
// keys CometChatSmartReplies below so back-to-back messages force a refetch
|
|
3007
|
+
setSmartRepliesKey(String(textMessage.getId?.() ?? Date.now()));
|
|
3008
|
+
setShowSmartRepliesView(true);
|
|
3009
|
+
}
|
|
2866
3010
|
},
|
|
2867
3011
|
onMediaMessageReceived: (mediaMessage: any) => {
|
|
2868
3012
|
if (isAgenticUser) {
|
|
@@ -2910,7 +3054,16 @@ export const CometChatMessageList = memo(
|
|
|
2910
3054
|
messageEdited(editedMessage);
|
|
2911
3055
|
},
|
|
2912
3056
|
onMessageModerated: (moderatedMessage: any) => {
|
|
2913
|
-
|
|
3057
|
+
if (isAgenticUser) return;
|
|
3058
|
+
// A moderation verdict can arrive BEFORE the optimistic message has reconciled to its
|
|
3059
|
+
// server id — common when sending 3+ images at once, where the last sends are still
|
|
3060
|
+
// keyed by muid in the list. messageEdited() matches by id XOR muid, so when the id
|
|
3061
|
+
// isn't present in the list yet, fall back to muid matching (the event carries the
|
|
3062
|
+
// muid and the optimistic bubble has it). Otherwise the block silently misses that
|
|
3063
|
+
// bubble until a refetch (navigate away + back).
|
|
3064
|
+
const mid = moderatedMessage?.getId?.() ?? (moderatedMessage as any)?.id;
|
|
3065
|
+
const foundById = mid != null && messagesContentListRef.current.some((m: any) => m?.getId?.() == mid);
|
|
3066
|
+
messageEdited(moderatedMessage, !foundById && !!(moderatedMessage as any)?.muid);
|
|
2914
3067
|
},
|
|
2915
3068
|
onFormMessageReceived: (formMessage: any) => {
|
|
2916
3069
|
newMessage(formMessage);
|
|
@@ -2951,6 +3104,26 @@ export const CometChatMessageList = memo(
|
|
|
2951
3104
|
) {
|
|
2952
3105
|
return;
|
|
2953
3106
|
}
|
|
3107
|
+
// Group agent reply belongs ONLY to its own group conversation. In a 1:1
|
|
3108
|
+
// agent chat `group` is undefined, and a different group won't match the
|
|
3109
|
+
// guid — so the reply can never leak outside its own group list.
|
|
3110
|
+
if (
|
|
3111
|
+
aiAssistantMessage.getReceiverType?.() === ReceiverTypeConstants.group
|
|
3112
|
+
) {
|
|
3113
|
+
if (group && aiAssistantMessage.getReceiverId?.() === group.getGuid()) {
|
|
3114
|
+
newMessage(aiAssistantMessage);
|
|
3115
|
+
}
|
|
3116
|
+
return;
|
|
3117
|
+
}
|
|
3118
|
+
// 1:1 agent reply belongs ONLY to the matching 1:1 agent conversation — its
|
|
3119
|
+
// sender is the agent represented by `user`. Anything else (a group list, or
|
|
3120
|
+
// a different agent's chat) ignores it so it can't leak across conversations.
|
|
3121
|
+
if (
|
|
3122
|
+
!user ||
|
|
3123
|
+
aiAssistantMessage.getSender?.()?.getUid?.() !== user.getUid()
|
|
3124
|
+
) {
|
|
3125
|
+
return;
|
|
3126
|
+
}
|
|
2954
3127
|
if (runId) {
|
|
2955
3128
|
storeAIAssistantMessage(String(runId), aiAssistantMessage);
|
|
2956
3129
|
}
|
|
@@ -3245,6 +3418,12 @@ export const CometChatMessageList = memo(
|
|
|
3245
3418
|
})();
|
|
3246
3419
|
|
|
3247
3420
|
if (item.getSender()?.getUid() != loggedInUser.current?.getUid()) {
|
|
3421
|
+
// Agent (assistant) replies use the normal incoming bubble — which has a
|
|
3422
|
+
// background container and no negative top margin — so the reply is visually
|
|
3423
|
+
// contained like other messages. Applies to both group and 1:1 AI chat.
|
|
3424
|
+
if (type === MessageTypeConstants.assistant) {
|
|
3425
|
+
return mergedTheme.messageListStyles.incomingMessageBubbleStyles as BubbleStyles;
|
|
3426
|
+
}
|
|
3248
3427
|
return (
|
|
3249
3428
|
overridenBubbleStyles.get(type)?.incoming ??
|
|
3250
3429
|
mergedTheme.messageListStyles.incomingMessageBubbleStyles
|
|
@@ -3260,7 +3439,7 @@ export const CometChatMessageList = memo(
|
|
|
3260
3439
|
);
|
|
3261
3440
|
|
|
3262
3441
|
// functions returning view
|
|
3263
|
-
const getLeadingView = useCallback((item: CometChat.BaseMessage): JSX.Element | undefined => {
|
|
3442
|
+
const getLeadingView = useCallback((item: CometChat.BaseMessage, currentIndex?: number): JSX.Element | undefined => {
|
|
3264
3443
|
let _style = getCurrentBubbleStyle(item);
|
|
3265
3444
|
|
|
3266
3445
|
if (
|
|
@@ -3278,6 +3457,20 @@ export const CometChatMessageList = memo(
|
|
|
3278
3457
|
(isAgenticUser && isIncomingMessage));
|
|
3279
3458
|
|
|
3280
3459
|
if (shouldShowAvatar) {
|
|
3460
|
+
// §8.3a — within a batch, show the avatar only on the FIRST (top/oldest) member.
|
|
3461
|
+
// The list is inverted (index 0 = newest), so the older neighbour is at index+1.
|
|
3462
|
+
// For the rest of the batch, render a same-width spacer so the stack stays aligned.
|
|
3463
|
+
const list = messagesContentListRef.current || [];
|
|
3464
|
+
const older = typeof currentIndex === "number" ? list[currentIndex + 1] : undefined;
|
|
3465
|
+
const newer = typeof currentIndex === "number" ? list[currentIndex - 1] : undefined;
|
|
3466
|
+
const isBatchMember =
|
|
3467
|
+
getMessageBatchId(item) != null &&
|
|
3468
|
+
(isSameBatchGroup(item, older) || isSameBatchGroup(item, newer));
|
|
3469
|
+
const isBatchFirst = !isSameBatchGroup(item, older);
|
|
3470
|
+
if (isBatchMember && !isBatchFirst) {
|
|
3471
|
+
const avatarWidth = (_style?.avatarStyle?.containerStyle?.width as number) ?? 32;
|
|
3472
|
+
return <View style={{ width: avatarWidth }} />;
|
|
3473
|
+
}
|
|
3281
3474
|
return (
|
|
3282
3475
|
<CometChatAvatar
|
|
3283
3476
|
image={
|
|
@@ -3298,8 +3491,19 @@ export const CometChatMessageList = memo(
|
|
|
3298
3491
|
}, []);
|
|
3299
3492
|
|
|
3300
3493
|
const getHeaderView = useCallback(
|
|
3301
|
-
(item: CometChat.BaseMessage | any): JSX.Element | undefined => {
|
|
3494
|
+
(item: CometChat.BaseMessage | any, currentIndex?: number): JSX.Element | undefined => {
|
|
3302
3495
|
const _style = getCurrentBubbleStyle(item);
|
|
3496
|
+
// §8.3a — within a batch, the sender name shows only on the first (top/oldest) member.
|
|
3497
|
+
const _list = messagesContentListRef.current || [];
|
|
3498
|
+
const _older = typeof currentIndex === "number" ? _list[currentIndex + 1] : undefined;
|
|
3499
|
+
const _newer = typeof currentIndex === "number" ? _list[currentIndex - 1] : undefined;
|
|
3500
|
+
const _isBatchMember =
|
|
3501
|
+
getMessageBatchId(item) != null &&
|
|
3502
|
+
(isSameBatchGroup(item, _older) || isSameBatchGroup(item, _newer));
|
|
3503
|
+
if (_isBatchMember && isSameBatchGroup(item, _older)) {
|
|
3504
|
+
// not the first of the batch → suppress the duplicate sender name
|
|
3505
|
+
return undefined;
|
|
3506
|
+
}
|
|
3303
3507
|
if (
|
|
3304
3508
|
(alignment === "leftAligned" ||
|
|
3305
3509
|
(item.getSender()?.getUid() != loggedInUser.current?.getUid() && !user)) &&
|
|
@@ -3343,6 +3547,35 @@ export const CometChatMessageList = memo(
|
|
|
3343
3547
|
if ((item as CometChat.BaseMessage).getCategory() === MessageCategoryConstants.action)
|
|
3344
3548
|
return undefined;
|
|
3345
3549
|
|
|
3550
|
+
// §8.3a — within a batch, the receipt+timestamp shows only on the LAST (bottom/newest)
|
|
3551
|
+
// member. List is inverted (index 0 = newest) → the newer neighbour is at index-1.
|
|
3552
|
+
// Hide the row on any batch member that still has a same-batch neighbour below it.
|
|
3553
|
+
// EXCEPTION (§12.1): a FAILED member must always show its own status so its error
|
|
3554
|
+
// (and any retry affordance) is never hidden by the group collapse.
|
|
3555
|
+
const _batchList = messagesContentListRef.current || [];
|
|
3556
|
+
const _newerNeighbour =
|
|
3557
|
+
typeof currentIndex === "number" ? _batchList[currentIndex - 1] : undefined;
|
|
3558
|
+
// A batch member with a same-batch neighbour BELOW it (newer) is not the last one — its
|
|
3559
|
+
// receipt/timestamp is normally collapsed onto the last member of the group.
|
|
3560
|
+
const _isCollapsibleBatchMember =
|
|
3561
|
+
getMessageBatchId(item) != null && isSameBatchGroup(item, _newerNeighbour);
|
|
3562
|
+
// EXCEPTION (§12.1): a FAILED or moderation-BLOCKED member must always show its own error
|
|
3563
|
+
// icon, so a blocked/failed first/middle attachment isn't left with NO indication. A
|
|
3564
|
+
// moderation block is NOT stamped as metadata.error, so check the moderation status here too.
|
|
3565
|
+
const _hasError =
|
|
3566
|
+
item?.getData?.()?.metaData?.error ||
|
|
3567
|
+
item?.getMetadata?.()?.error ||
|
|
3568
|
+
(item as any)?.error ||
|
|
3569
|
+
getModerationStatus(item) === "disapproved";
|
|
3570
|
+
if (!_hasError && _isCollapsibleBatchMember) {
|
|
3571
|
+
// Non-last, non-failed batch member: the receipt/timestamp shows only on the LAST member,
|
|
3572
|
+
// but that row is what gives the bubble its bottom footprint. Returning `undefined` leaves
|
|
3573
|
+
// the content flush to the edge, so the rounded bottom corner doesn't render like the top.
|
|
3574
|
+
// Keep a small spacer so the bottom matches the top. Scoped to this branch — the default
|
|
3575
|
+
// (non-batch) bubble is untouched.
|
|
3576
|
+
return <View style={{ height: theme.spacing.spacing.s2 }} />;
|
|
3577
|
+
}
|
|
3578
|
+
|
|
3346
3579
|
let isOutgoingMessage = item.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
3347
3580
|
let _style = getCurrentBubbleStyle(item);
|
|
3348
3581
|
|
|
@@ -3373,13 +3606,25 @@ export const CometChatMessageList = memo(
|
|
|
3373
3606
|
if (moderationStatus === "disapproved") {
|
|
3374
3607
|
messageState = MessageReceipt.ERROR;
|
|
3375
3608
|
}
|
|
3376
|
-
// Determine if message has been edited.
|
|
3377
|
-
//
|
|
3609
|
+
// Determine if message has been edited. Text edits always qualify; media messages qualify
|
|
3610
|
+
// only when they carry a caption (that's the only thing you can edit on media) — the caption
|
|
3611
|
+
// guard also keeps async server edits like thumbnail generation from falsely tagging images.
|
|
3612
|
+
const editedType = (item as CometChat.BaseMessage).getType();
|
|
3613
|
+
const isEditedMedia =
|
|
3614
|
+
(editedType === MessageTypeConstants.image ||
|
|
3615
|
+
editedType === MessageTypeConstants.video ||
|
|
3616
|
+
editedType === MessageTypeConstants.audio ||
|
|
3617
|
+
editedType === MessageTypeConstants.file) &&
|
|
3618
|
+
!!(item as CometChat.MediaMessage).getCaption?.()?.trim();
|
|
3378
3619
|
const isEdited =
|
|
3379
|
-
item.getEditedAt?.() &&
|
|
3380
|
-
(
|
|
3381
|
-
|
|
3382
|
-
|
|
3620
|
+
!!item.getEditedAt?.() &&
|
|
3621
|
+
(editedType === MessageTypeConstants.text || isEditedMedia);
|
|
3622
|
+
|
|
3623
|
+
// A first/middle failed/blocked batch member shows JUST the error icon (below) — hide its
|
|
3624
|
+
// timestamp so only the last member of the group carries the timestamp.
|
|
3625
|
+
const shouldShowTimestamp =
|
|
3626
|
+
(isAgenticUser ? isOutgoingMessage : !hideTimestamp) &&
|
|
3627
|
+
!(_isCollapsibleBatchMember && messageState === MessageReceipt.ERROR);
|
|
3383
3628
|
return (
|
|
3384
3629
|
<View>
|
|
3385
3630
|
<View
|
|
@@ -3422,23 +3667,52 @@ export const CometChatMessageList = memo(
|
|
|
3422
3667
|
alignment !== "leftAligned" &&
|
|
3423
3668
|
isOutgoingMessage &&
|
|
3424
3669
|
!item.getDeletedAt?.() ? (
|
|
3425
|
-
|
|
3426
|
-
|
|
3427
|
-
|
|
3428
|
-
|
|
3429
|
-
|
|
3430
|
-
|
|
3431
|
-
|
|
3432
|
-
|
|
3433
|
-
|
|
3434
|
-
|
|
3435
|
-
|
|
3436
|
-
|
|
3437
|
-
|
|
3438
|
-
|
|
3439
|
-
|
|
3440
|
-
|
|
3441
|
-
|
|
3670
|
+
(() => {
|
|
3671
|
+
const receiptEl = (
|
|
3672
|
+
<CometChatReceipt
|
|
3673
|
+
receipt={messageState}
|
|
3674
|
+
style={{
|
|
3675
|
+
deliveredIcon: _style.receiptStyles.deliveredIcon,
|
|
3676
|
+
readIcon: _style.receiptStyles.readIcon,
|
|
3677
|
+
sentIcon: _style.receiptStyles.sentIcon,
|
|
3678
|
+
waitIcon: _style.receiptStyles.waitIcon,
|
|
3679
|
+
errorIcon: _style.receiptStyles.errorIcon,
|
|
3680
|
+
sentIconStyle: _style.receiptStyles.sentIconStyle,
|
|
3681
|
+
readIconStyle: _style.receiptStyles.readIconStyle,
|
|
3682
|
+
waitIconStyle: _style.receiptStyles.waitIconStyle,
|
|
3683
|
+
errorIconStyle: _style.receiptStyles.errorIconStyle,
|
|
3684
|
+
deliveredIconStyle: _style.receiptStyles.deliveredIconStyle,
|
|
3685
|
+
}}
|
|
3686
|
+
/>
|
|
3687
|
+
);
|
|
3688
|
+
// A first/middle failed/blocked batch member shows JUST the error icon (no
|
|
3689
|
+
// timestamp, no Retry label) so the group collapse never hides the failure.
|
|
3690
|
+
if (messageState === MessageReceipt.ERROR && _isCollapsibleBatchMember) {
|
|
3691
|
+
return <View testID="batch-error-icon" style={staticStyles.receiptContainer}>{receiptEl}</View>;
|
|
3692
|
+
}
|
|
3693
|
+
// §12.1 — a failed send becomes a tappable "Retry" (re-sends this message).
|
|
3694
|
+
return messageState === MessageReceipt.ERROR ? (
|
|
3695
|
+
<TouchableOpacity
|
|
3696
|
+
style={[staticStyles.receiptContainer, staticStyles.receiptRow]}
|
|
3697
|
+
onPress={() => resendMediaMessage(item)}
|
|
3698
|
+
accessibilityRole="button"
|
|
3699
|
+
accessibilityLabel={t("RETRY") ?? "Retry"}
|
|
3700
|
+
hitSlop={{ top: 6, bottom: 6, left: 6, right: 6 }}
|
|
3701
|
+
>
|
|
3702
|
+
{receiptEl}
|
|
3703
|
+
<Text
|
|
3704
|
+
style={[
|
|
3705
|
+
_style.dateStyles.textStyle,
|
|
3706
|
+
{ textTransform: "none", marginLeft: 4, color: mergedTheme.color.error },
|
|
3707
|
+
]}
|
|
3708
|
+
>
|
|
3709
|
+
{t("RETRY") ?? "Retry"}
|
|
3710
|
+
</Text>
|
|
3711
|
+
</TouchableOpacity>
|
|
3712
|
+
) : (
|
|
3713
|
+
<View style={staticStyles.receiptContainer}>{receiptEl}</View>
|
|
3714
|
+
);
|
|
3715
|
+
})()
|
|
3442
3716
|
) : null}
|
|
3443
3717
|
</View>
|
|
3444
3718
|
</View>
|
|
@@ -3447,6 +3721,75 @@ export const CometChatMessageList = memo(
|
|
|
3447
3721
|
[mergedTheme, isAgenticUser, hideTimestamp]
|
|
3448
3722
|
);
|
|
3449
3723
|
|
|
3724
|
+
// §8.2 — batch-spanning viewer source: the union of image+video attachments
|
|
3725
|
+
// across all messages of this message's batch (in batchIndex order), plus the
|
|
3726
|
+
// offset where the queried message's own media begins. Null when not a real batch.
|
|
3727
|
+
const getBatchImageVideoItems = useCallback(
|
|
3728
|
+
(message: CometChat.MediaMessage): BatchMediaResult | null => {
|
|
3729
|
+
const batchId = getMessageBatchId(message);
|
|
3730
|
+
if (batchId == null) return null;
|
|
3731
|
+
const list = messagesContentListRef.current || [];
|
|
3732
|
+
const siblings = list.filter((m) => isSameBatchGroup(m, message));
|
|
3733
|
+
if (siblings.length <= 1) return null;
|
|
3734
|
+
const idxOf = (m: any) => {
|
|
3735
|
+
const bi = m?.getMetadata?.()?.batchIndex;
|
|
3736
|
+
return typeof bi === "number" ? bi : 0;
|
|
3737
|
+
};
|
|
3738
|
+
siblings.sort((a, b) => idxOf(a) - idxOf(b));
|
|
3739
|
+
const isVisual = (a: any) => {
|
|
3740
|
+
const mime = a?.getMimeType?.() ?? "";
|
|
3741
|
+
return mime.startsWith("image/") || mime.startsWith("video/");
|
|
3742
|
+
};
|
|
3743
|
+
const sameMsg = (a: any, b: any) => {
|
|
3744
|
+
const ai = a?.getId?.();
|
|
3745
|
+
const bi = b?.getId?.();
|
|
3746
|
+
if (ai && bi) return ai === bi;
|
|
3747
|
+
const am = a?.getMuid?.();
|
|
3748
|
+
const bm = b?.getMuid?.();
|
|
3749
|
+
return !!am && am === bm;
|
|
3750
|
+
};
|
|
3751
|
+
let items: CometChat.Attachment[] = [];
|
|
3752
|
+
let offsetForMessage = 0;
|
|
3753
|
+
for (const sib of siblings) {
|
|
3754
|
+
const media = ((sib as CometChat.MediaMessage).getAttachments?.() ?? []).filter(isVisual);
|
|
3755
|
+
if (sameMsg(sib, message)) offsetForMessage = items.length;
|
|
3756
|
+
items = items.concat(media);
|
|
3757
|
+
}
|
|
3758
|
+
if (items.length === 0) return null;
|
|
3759
|
+
return { items, offsetForMessage };
|
|
3760
|
+
},
|
|
3761
|
+
[]
|
|
3762
|
+
);
|
|
3763
|
+
|
|
3764
|
+
const batchMediaContextValue = useMemo(
|
|
3765
|
+
() => ({ getBatchImageVideoItems }),
|
|
3766
|
+
[getBatchImageVideoItems]
|
|
3767
|
+
);
|
|
3768
|
+
|
|
3769
|
+
// §12.1 — retry a FAILED outgoing media message (e.g. one member of a partial batch).
|
|
3770
|
+
// Clears the error flag, then re-sends via the canonical CometChatUIKit path which
|
|
3771
|
+
// re-emits ccMessageSent inprogress→success/error; this list reconciles by muid in place.
|
|
3772
|
+
const resendMediaMessage = useCallback((message: CometChat.BaseMessage) => {
|
|
3773
|
+
try {
|
|
3774
|
+
if (!(message instanceof CometChat.MediaMessage)) return;
|
|
3775
|
+
const data: any = (message as any).getData?.() || {};
|
|
3776
|
+
if (data?.metaData?.error) {
|
|
3777
|
+
delete data.metaData.error;
|
|
3778
|
+
(message as any).setData?.(data);
|
|
3779
|
+
}
|
|
3780
|
+
const md: any = (message as any).getMetadata?.();
|
|
3781
|
+
if (md?.error) {
|
|
3782
|
+
delete md.error;
|
|
3783
|
+
(message as any).setMetadata?.(md);
|
|
3784
|
+
}
|
|
3785
|
+
(message as any).error = undefined;
|
|
3786
|
+
// On failure CometChatUIKit.sendMediaMessage re-applies the error flag + emits error.
|
|
3787
|
+
CometChatUIKit.sendMediaMessage(message as CometChat.MediaMessage).catch(() => {});
|
|
3788
|
+
} catch (e) {
|
|
3789
|
+
// best-effort retry
|
|
3790
|
+
}
|
|
3791
|
+
}, []);
|
|
3792
|
+
|
|
3450
3793
|
const reactToMessage = (emoji: string, messageObj?: CometChat.BaseMessage) => {
|
|
3451
3794
|
const originalMessage = messageObj || selectedMessage;
|
|
3452
3795
|
const msgObj = CommonUtils.clone(originalMessage);
|
|
@@ -3892,9 +4235,9 @@ export const CometChatMessageList = memo(
|
|
|
3892
4235
|
return hasTemplate?.HeaderView
|
|
3893
4236
|
? hasTemplate?.HeaderView(message, bubbleAlignment)
|
|
3894
4237
|
: !isThreaded
|
|
3895
|
-
? getHeaderView(message)
|
|
4238
|
+
? getHeaderView(message, currentIndex)
|
|
3896
4239
|
: undefined;
|
|
3897
|
-
}, [message, bubbleAlignment, hasTemplate, getHeaderView]);
|
|
4240
|
+
}, [message, bubbleAlignment, hasTemplate, getHeaderView, currentIndex]);
|
|
3898
4241
|
|
|
3899
4242
|
const FooterView = useMemo(() => {
|
|
3900
4243
|
return hasTemplate?.FooterView
|
|
@@ -3917,8 +4260,8 @@ export const CometChatMessageList = memo(
|
|
|
3917
4260
|
if (hasTemplate?.LeadingView) {
|
|
3918
4261
|
return hasTemplate.LeadingView(message, bubbleAlignment);
|
|
3919
4262
|
}
|
|
3920
|
-
return !isThreaded ? getLeadingView(message) : undefined;
|
|
3921
|
-
}, [isThreaded, message, getLeadingView, hasTemplate, bubbleAlignment]);
|
|
4263
|
+
return !isThreaded ? getLeadingView(message, currentIndex) : undefined;
|
|
4264
|
+
}, [isThreaded, message, getLeadingView, hasTemplate, bubbleAlignment, currentIndex]);
|
|
3922
4265
|
|
|
3923
4266
|
const BottomView = useMemo(() => {
|
|
3924
4267
|
const moderationStatus = getModerationStatus(message);
|
|
@@ -4055,8 +4398,17 @@ export const CometChatMessageList = memo(
|
|
|
4055
4398
|
}
|
|
4056
4399
|
}, [onReply, message]);
|
|
4057
4400
|
|
|
4401
|
+
// Disable swipe-to-reply for agent ("@agentic") messages. Covers both the
|
|
4402
|
+
// 1:1 AI chat (isAgenticUser, whole conversation) and agent messages inside a
|
|
4403
|
+
// group — where the reply context-menu option is already removed, so the swipe
|
|
4404
|
+
// gesture is suppressed to match (otherwise mobile users could still swipe-reply).
|
|
4405
|
+
const isAgenticMessage =
|
|
4406
|
+
isAgenticUser ||
|
|
4407
|
+
message.getSender?.()?.getRole?.() === "@agentic" ||
|
|
4408
|
+
message.getCategory?.() === MessageCategoryConstants.agentic;
|
|
4409
|
+
|
|
4058
4410
|
return (
|
|
4059
|
-
message.getCategory() === MessageCategoryConstants.action ||
|
|
4411
|
+
message.getCategory() === MessageCategoryConstants.action || isAgenticMessage ? (
|
|
4060
4412
|
<View style={staticStyles.positionRelative}>
|
|
4061
4413
|
<TouchableOpacity
|
|
4062
4414
|
activeOpacity={1}
|
|
@@ -4271,7 +4623,14 @@ export const CometChatMessageList = memo(
|
|
|
4271
4623
|
return `index_${index}`;
|
|
4272
4624
|
}, []);
|
|
4273
4625
|
|
|
4274
|
-
|
|
4626
|
+
// `tight` collapses the gap between two consecutive messages of the SAME batch so a
|
|
4627
|
+
// fanned-out mixed batch (images + files + audio…) reads as one grouped message.
|
|
4628
|
+
const itemSeparator = useCallback(
|
|
4629
|
+
(tight?: boolean) => (
|
|
4630
|
+
<View style={tight ? staticStyles.itemSeparatorTight : staticStyles.itemSeparator} />
|
|
4631
|
+
),
|
|
4632
|
+
[staticStyles]
|
|
4633
|
+
);
|
|
4275
4634
|
|
|
4276
4635
|
const getAgentEmptyView = useCallback(() => {
|
|
4277
4636
|
if (!user) return <></>;
|
|
@@ -4345,15 +4704,7 @@ export const CometChatMessageList = memo(
|
|
|
4345
4704
|
)}
|
|
4346
4705
|
|
|
4347
4706
|
{!hideSuggestedMessages && displaySuggestions?.length > 0 && (
|
|
4348
|
-
<View
|
|
4349
|
-
style={{
|
|
4350
|
-
flexDirection: "row",
|
|
4351
|
-
flexWrap: "wrap",
|
|
4352
|
-
justifyContent: "center",
|
|
4353
|
-
paddingHorizontal: 0,
|
|
4354
|
-
maxWidth: "100%",
|
|
4355
|
-
}}
|
|
4356
|
-
>
|
|
4707
|
+
<View style={staticStyles.suggestionsWrap}>
|
|
4357
4708
|
{displaySuggestions.map((suggestion, idx) => (
|
|
4358
4709
|
<TouchableOpacity
|
|
4359
4710
|
key={idx}
|
|
@@ -4411,12 +4762,52 @@ export const CometChatMessageList = memo(
|
|
|
4411
4762
|
mergedTheme,
|
|
4412
4763
|
]);
|
|
4413
4764
|
|
|
4765
|
+
const fetchConversationStarters = (): Promise<string[]> => {
|
|
4766
|
+
const receiverId = user?.getUid() ?? group?.getGuid() ?? '';
|
|
4767
|
+
const receiverType = user
|
|
4768
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
4769
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
4770
|
+
return CometChat.getConversationStarter(receiverId, receiverType);
|
|
4771
|
+
};
|
|
4772
|
+
|
|
4773
|
+
const fetchSmartReplies = (): Promise<string[]> => {
|
|
4774
|
+
const msg = latestReceivedMessageRef.current;
|
|
4775
|
+
if (!msg) return Promise.resolve([]);
|
|
4776
|
+
const receiverId = user?.getUid() ?? group?.getGuid() ?? '';
|
|
4777
|
+
const receiverType = user
|
|
4778
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
4779
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
4780
|
+
return CometChat.getSmartReplies(receiverId, receiverType)
|
|
4781
|
+
.then((res) => Object.values(res) as string[]);
|
|
4782
|
+
};
|
|
4783
|
+
|
|
4784
|
+
// ponytail: group action messages (e.g. "X joined the group") aren't real
|
|
4785
|
+
// conversation messages, so they shouldn't hide the conversation starter chips (ENG-36769).
|
|
4786
|
+
const hasOnlyActionMessages = useMemo(
|
|
4787
|
+
() =>
|
|
4788
|
+
messagesList.length > 0 &&
|
|
4789
|
+
messagesList.every(
|
|
4790
|
+
(m) => m?.getCategory?.() === MessageCategoryConstants.action
|
|
4791
|
+
),
|
|
4792
|
+
[messagesList]
|
|
4793
|
+
);
|
|
4794
|
+
|
|
4414
4795
|
const getEmptyStateView = useCallback(() => {
|
|
4415
4796
|
const isAgenticUserCheck = user?.getRole?.() === "@agentic";
|
|
4416
4797
|
|
|
4417
4798
|
if (isAgenticUserCheck) {
|
|
4418
4799
|
return getAgentEmptyView();
|
|
4419
4800
|
}
|
|
4801
|
+
if (showConversationStarters) {
|
|
4802
|
+
return (
|
|
4803
|
+
<View style={{ flex: 1, justifyContent: 'flex-end' }}>
|
|
4804
|
+
<CometChatConversationStarter
|
|
4805
|
+
getConversationStarters={fetchConversationStarters}
|
|
4806
|
+
onSuggestionClicked={(text) => onSuggestedMessageClick?.(text)}
|
|
4807
|
+
/>
|
|
4808
|
+
</View>
|
|
4809
|
+
);
|
|
4810
|
+
}
|
|
4420
4811
|
if (EmptyView)
|
|
4421
4812
|
return (
|
|
4422
4813
|
<>
|
|
@@ -4432,7 +4823,7 @@ export const CometChatMessageList = memo(
|
|
|
4432
4823
|
titleStyle={mergedTheme.messageListStyles.emptyStateStyle?.textStyle as TextStyle}
|
|
4433
4824
|
/>
|
|
4434
4825
|
);
|
|
4435
|
-
}, [mergedTheme, EmptyView, getAgentEmptyView, user]);
|
|
4826
|
+
}, [mergedTheme, EmptyView, getAgentEmptyView, user, group, showConversationStarters]);
|
|
4436
4827
|
|
|
4437
4828
|
const getErrorStateView = useCallback(() => {
|
|
4438
4829
|
if (hideError) return null;
|
|
@@ -4737,6 +5128,17 @@ export const CometChatMessageList = memo(
|
|
|
4737
5128
|
const memoizedRenderItem = useCallback(
|
|
4738
5129
|
({ item, index }: any) => {
|
|
4739
5130
|
const nextItem = messagesContentListRef.current[index + 1];
|
|
5131
|
+
const prevItem = messagesContentListRef.current[index - 1];
|
|
5132
|
+
// Collapse this row's vertical padding (and the separator) toward a neighbour that belongs
|
|
5133
|
+
// to the SAME fan-out batch, so a mixed batch (images + files + audio…) reads as one grouped
|
|
5134
|
+
// message. Gated on a shared batchId + sender on the NEIGHBOUR alone — that already proves a
|
|
5135
|
+
// real multi-message batch, so we do NOT also require the `batchSize > 1` metadata field,
|
|
5136
|
+
// which can be absent on reloaded messages and silently left the batch un-clubbed (the big
|
|
5137
|
+
// gap). A lone batchId (single-attachment send) has no same-batch neighbour → never tightened.
|
|
5138
|
+
// List is inverted: index+1 = older (above), index-1 = newer (below); tightTop shrinks toward
|
|
5139
|
+
// the older member, tightBottom toward the newer.
|
|
5140
|
+
const tightTop = isSameBatchGroup(item, nextItem);
|
|
5141
|
+
const tightBottom = isSameBatchGroup(item, prevItem);
|
|
4740
5142
|
const currentItemMs = sentAtToMs(item);
|
|
4741
5143
|
const nextItemMs = sentAtToMs(nextItem);
|
|
4742
5144
|
const showSeparator = shouldShowSeparator(index, currentItemMs, nextItemMs);
|
|
@@ -4766,6 +5168,8 @@ export const CometChatMessageList = memo(
|
|
|
4766
5168
|
dayHeaderString={dayHeaderString}
|
|
4767
5169
|
RenderMessageItem={RenderMessageItem}
|
|
4768
5170
|
itemSeparator={itemSeparator}
|
|
5171
|
+
tightTop={tightTop}
|
|
5172
|
+
tightBottom={tightBottom}
|
|
4769
5173
|
staticStyles={staticStyles}
|
|
4770
5174
|
onLayout={handleItemLayout}
|
|
4771
5175
|
showNewMessageIndicator={showNewMessageIndicator}
|
|
@@ -4799,7 +5203,15 @@ export const CometChatMessageList = memo(
|
|
|
4799
5203
|
);
|
|
4800
5204
|
|
|
4801
5205
|
|
|
5206
|
+
// §8.3a — reorder each batch's messages by batchIndex for display, so a batch always
|
|
5207
|
+
// shows in the sender's order even if the kinds arrived out of order (independent uploads).
|
|
5208
|
+
// Keep the neighbour-lookup ref pointing at the SAME ordered list the FlatList renders,
|
|
5209
|
+
// so batch grouping (avatar-first / receipt-last) and the pager stay index-consistent.
|
|
5210
|
+
const orderedMessagesList = useMemo(() => orderBatchRuns(messagesList), [messagesList]);
|
|
5211
|
+
messagesContentListRef.current = orderedMessagesList;
|
|
5212
|
+
|
|
4802
5213
|
return (
|
|
5214
|
+
<CometChatBatchMediaContext.Provider value={batchMediaContextValue}>
|
|
4803
5215
|
<View style={mergedTheme.messageListStyles.containerStyle}>
|
|
4804
5216
|
{listState == "loading" && messagesList.length == 0 ? (
|
|
4805
5217
|
getLoadingStateView()
|
|
@@ -4832,6 +5244,7 @@ export const CometChatMessageList = memo(
|
|
|
4832
5244
|
{/* Navigation loading for far message fetching and scroll operations */}
|
|
4833
5245
|
{navigationLoading && (getLoadingStateView())}
|
|
4834
5246
|
<FlatList
|
|
5247
|
+
testID="message-list"
|
|
4835
5248
|
showsVerticalScrollIndicator={false}
|
|
4836
5249
|
ref={messageListRef}
|
|
4837
5250
|
onMomentumScrollEnd={handleScrollInternal}
|
|
@@ -4846,7 +5259,7 @@ export const CometChatMessageList = memo(
|
|
|
4846
5259
|
onStartReachedThreshold={0.5}
|
|
4847
5260
|
scrollEventThrottle={16}
|
|
4848
5261
|
keyboardShouldPersistTaps={(Platform.OS === "ios" ? "handled" : "always") as "handled" | "always"}
|
|
4849
|
-
data={
|
|
5262
|
+
data={orderedMessagesList}
|
|
4850
5263
|
extraData={themeMode}
|
|
4851
5264
|
keyExtractor={keyExtractor}
|
|
4852
5265
|
renderItem={memoizedRenderItem}
|
|
@@ -4863,10 +5276,29 @@ export const CometChatMessageList = memo(
|
|
|
4863
5276
|
/>
|
|
4864
5277
|
|
|
4865
5278
|
|
|
5279
|
+
{/* ENG-36769: keep conversation starters visible when the group only
|
|
5280
|
+
has action messages (e.g. "X joined the group") and no real messages yet */}
|
|
5281
|
+
{showConversationStarters && hasOnlyActionMessages && (
|
|
5282
|
+
<CometChatConversationStarter
|
|
5283
|
+
getConversationStarters={fetchConversationStarters}
|
|
5284
|
+
onSuggestionClicked={(text) => onSuggestedMessageClick?.(text)}
|
|
5285
|
+
/>
|
|
5286
|
+
)}
|
|
4866
5287
|
{CustomListHeader && <CustomListHeader />}
|
|
4867
5288
|
{ongoingCallView}
|
|
5289
|
+
{showSmartReplies && showSmartRepliesView && (
|
|
5290
|
+
<CometChatSmartReplies
|
|
5291
|
+
key={smartRepliesKey}
|
|
5292
|
+
getSmartReplies={fetchSmartReplies}
|
|
5293
|
+
onSuggestionClicked={(text) => {
|
|
5294
|
+
setShowSmartRepliesView(false);
|
|
5295
|
+
onSuggestedMessageClick?.(text);
|
|
5296
|
+
}}
|
|
5297
|
+
closeCallback={() => setShowSmartRepliesView(false)}
|
|
5298
|
+
/>
|
|
5299
|
+
)}
|
|
4868
5300
|
{FooterView && (
|
|
4869
|
-
<View style={
|
|
5301
|
+
<View style={staticStyles.bottomZero}>
|
|
4870
5302
|
<FooterView
|
|
4871
5303
|
group={group}
|
|
4872
5304
|
user={user}
|
|
@@ -4982,6 +5414,7 @@ export const CometChatMessageList = memo(
|
|
|
4982
5414
|
}}
|
|
4983
5415
|
/>
|
|
4984
5416
|
</View>
|
|
5417
|
+
</CometChatBatchMediaContext.Provider>
|
|
4985
5418
|
);
|
|
4986
5419
|
|
|
4987
5420
|
}
|
|
@@ -5004,6 +5437,27 @@ const staticStyles = StyleSheet.create({
|
|
|
5004
5437
|
alignItems: 'center' as 'center',
|
|
5005
5438
|
marginBottom: 8,
|
|
5006
5439
|
},
|
|
5440
|
+
// Collapse the padding on the side of a message row that faces a same-batch neighbour,
|
|
5441
|
+
// so a fanned-out batch reads as one grouped message (vs the default paddingVertical: 8).
|
|
5442
|
+
messageTightTop: {
|
|
5443
|
+
paddingTop: 2,
|
|
5444
|
+
},
|
|
5445
|
+
messageTightBottom: {
|
|
5446
|
+
paddingBottom: 2,
|
|
5447
|
+
},
|
|
5448
|
+
// Full-bleed highlight behind a message row; the background colour is animated at the call site.
|
|
5449
|
+
highlightOverlay: {
|
|
5450
|
+
position: 'absolute' as 'absolute',
|
|
5451
|
+
left: 0,
|
|
5452
|
+
right: 0,
|
|
5453
|
+
top: 0,
|
|
5454
|
+
bottom: 0,
|
|
5455
|
+
zIndex: 1,
|
|
5456
|
+
},
|
|
5457
|
+
// When a date separator sits above the row, drop the highlight below it (separator height).
|
|
5458
|
+
highlightOverlayBelowSeparator: {
|
|
5459
|
+
top: 40,
|
|
5460
|
+
},
|
|
5007
5461
|
footerContainer: {
|
|
5008
5462
|
padding: 10,
|
|
5009
5463
|
alignItems: 'center' as 'center',
|
|
@@ -5011,6 +5465,10 @@ const staticStyles = StyleSheet.create({
|
|
|
5011
5465
|
itemSeparator: {
|
|
5012
5466
|
height: 8,
|
|
5013
5467
|
},
|
|
5468
|
+
// Collapsed gap between two members of the same fan-out batch (grouped-message look).
|
|
5469
|
+
itemSeparatorTight: {
|
|
5470
|
+
height: 2,
|
|
5471
|
+
},
|
|
5014
5472
|
loadingContainer: {
|
|
5015
5473
|
padding: 16,
|
|
5016
5474
|
},
|
|
@@ -5062,6 +5520,20 @@ const staticStyles = StyleSheet.create({
|
|
|
5062
5520
|
alignItems: "center",
|
|
5063
5521
|
justifyContent: "center",
|
|
5064
5522
|
},
|
|
5523
|
+
receiptRow: {
|
|
5524
|
+
flexDirection: "row",
|
|
5525
|
+
alignItems: "center",
|
|
5526
|
+
},
|
|
5527
|
+
suggestionsWrap: {
|
|
5528
|
+
flexDirection: "row",
|
|
5529
|
+
flexWrap: "wrap",
|
|
5530
|
+
justifyContent: "center",
|
|
5531
|
+
paddingHorizontal: 0,
|
|
5532
|
+
maxWidth: "100%",
|
|
5533
|
+
},
|
|
5534
|
+
bottomZero: {
|
|
5535
|
+
bottom: 0,
|
|
5536
|
+
},
|
|
5065
5537
|
positionRelative: {
|
|
5066
5538
|
position: 'relative',
|
|
5067
5539
|
},
|