@cometchat/chat-uikit-react-native 5.2.8 → 5.2.10
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/package.json +2 -2
- package/src/CometChatConversations/CometChatConversations.tsx +8 -1
- package/src/CometChatGroups/CometChatGroups.tsx +5 -3
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +78 -18
- package/src/CometChatMessageList/CometChatMessageList.tsx +1181 -577
- package/src/CometChatMessageList/components/MessageListItem.tsx +127 -0
- package/src/CometChatMessageList/components/MessageModals.tsx +60 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +130 -0
- package/src/CometChatMessageList/components/ReactionModals.tsx +70 -0
- package/src/CometChatUsers/CometChatUsers.tsx +4 -1
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +27 -36
- package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +13 -9
- package/src/shared/base/Types.ts +1 -0
- package/src/shared/constants/UIKitConstants.ts +1 -0
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +4 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -1
- package/src/shared/events/conversations.ts +1 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +71 -14
- package/src/shared/framework/MessageDataSource.tsx +79 -17
- package/src/shared/index.ts +2 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +3 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +3 -1
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +7 -4
- package/src/shared/views/CometChatAudioBubble/CometChatAudioBubble.tsx +20 -12
- package/src/shared/views/CometChatBadge/CometChatBadge.tsx +6 -3
- package/src/shared/views/CometChatBottomSheet/CometChatBottomSheet.tsx +2 -1
- package/src/shared/views/CometChatList/CometChatList.tsx +20 -1
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -1
- package/src/shared/views/CometChatNewMessageIndicator/CometChatNewMessageIndicator.tsx +55 -0
- package/src/shared/views/CometChatNewMessageIndicator/index.ts +3 -0
- package/src/shared/views/CometChatNewMessageIndicator/styles.ts +33 -0
- package/src/shared/views/CometChatRetryButton/CometChatRetryButton.tsx +54 -0
- package/src/shared/views/CometChatRetryButton/index.ts +3 -0
- package/src/shared/views/index.ts +15 -0
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/android/.gradle/7.4/gc.properties +0 -0
- package/android/.gradle/vcs-1/gc.properties +0 -0
|
@@ -27,6 +27,8 @@ import {
|
|
|
27
27
|
TouchableOpacity,
|
|
28
28
|
View,
|
|
29
29
|
ViewStyle,
|
|
30
|
+
StyleSheet,
|
|
31
|
+
StyleProp,
|
|
30
32
|
} from "react-native";
|
|
31
33
|
import {
|
|
32
34
|
PanGestureHandler,
|
|
@@ -35,22 +37,18 @@ import {
|
|
|
35
37
|
PanGestureHandlerStateChangeEvent,
|
|
36
38
|
} from "react-native-gesture-handler";
|
|
37
39
|
import { CometChatMessageEvents } from "../shared/events/CometChatMessageEvents";
|
|
38
|
-
import {
|
|
40
|
+
import { CometChatConversationEvents } from "../shared/events/conversations";
|
|
39
41
|
import {
|
|
40
|
-
CometChatActionSheet,
|
|
41
|
-
CometChatBottomSheet,
|
|
42
42
|
CometChatMentionsFormatter,
|
|
43
43
|
CometChatSoundManager,
|
|
44
44
|
CometChatTextFormatter,
|
|
45
45
|
CometChatUiKitConstants,
|
|
46
46
|
CometChatUrlsFormatter,
|
|
47
|
-
MessageDataSource,
|
|
48
47
|
SuggestionItem,
|
|
49
48
|
} from "../shared";
|
|
50
49
|
import {
|
|
51
50
|
MessageBubbleAlignmentType,
|
|
52
51
|
MessageListAlignmentType,
|
|
53
|
-
MessageTimeAlignmentType,
|
|
54
52
|
} from "../shared/base/Types";
|
|
55
53
|
import {
|
|
56
54
|
CallTypeConstants,
|
|
@@ -72,15 +70,12 @@ import { Icon } from "../shared/icons/Icon";
|
|
|
72
70
|
import { CometChatMessageTemplate } from "../shared/modals/CometChatMessageTemplate";
|
|
73
71
|
import { getUnixTimestamp, messageStatus } from "../shared/utils/CometChatMessageHelper";
|
|
74
72
|
import { CommonUtils } from "../shared/utils/CommonUtils";
|
|
75
|
-
import {
|
|
73
|
+
import { CometChatNewMessageIndicator, CometChatReceipt, NewMessageIndicatorStyle } from "../shared/views";
|
|
76
74
|
import { CometChatAvatar } from "../shared/views/CometChatAvatar";
|
|
77
75
|
import { CometChatBadge } from "../shared/views/CometChatBadge";
|
|
78
76
|
import { CometChatDate } from "../shared/views/CometChatDate";
|
|
79
|
-
import { CometChatEmojiKeyboard } from "../shared/views/CometChatEmojiKeyboard";
|
|
80
77
|
import { CometChatMessageBubble } from "../shared/views/CometChatMessageBubble";
|
|
81
78
|
import { getModerationStatus, ModerationBottomView } from "../shared/utils/MessageUtils";
|
|
82
|
-
import { CometChatQuickReactions } from "../shared/views/CometChatQuickReactions";
|
|
83
|
-
import { CometChatReactionList } from "../shared/views/CometChatReactionList";
|
|
84
79
|
import { CometChatReactions } from "../shared/views/CometChatReactions";
|
|
85
80
|
import { useTheme } from "../theme";
|
|
86
81
|
import { MessageSkeleton } from "./Skeleton";
|
|
@@ -90,29 +85,29 @@ import { ExtensionConstants } from "../extensions";
|
|
|
90
85
|
//@ts-ignore
|
|
91
86
|
import { getExtensionData } from "../shared/helper/functions";
|
|
92
87
|
import { DeepPartial } from "../shared/helper/types";
|
|
93
|
-
import { CometChatDateSeparator } from "../shared/views/CometChatDateSeperator";
|
|
94
88
|
import {
|
|
95
89
|
handleWebsocketMessage,
|
|
96
|
-
messageStream,
|
|
97
90
|
setAIAssistantTools,
|
|
98
91
|
setStreamSpeed,
|
|
99
|
-
startStreamingForRunId,
|
|
100
92
|
setQueueCompletionCallback,
|
|
101
|
-
removeQueueCompletionCallback,
|
|
102
93
|
onConnected as streamOnConnected,
|
|
103
94
|
onDisconnected as streamOnDisconnected,
|
|
104
|
-
onConnectionError as streamOnConnectionError,
|
|
105
95
|
checkAndTriggerQueueCompletion,
|
|
106
96
|
storeAIAssistantMessage,
|
|
107
|
-
QueueCompletionCallback,
|
|
108
97
|
} from "../shared/services/stream-message.service";
|
|
109
98
|
import { CometChatAIAssistantTools } from "../shared/modals/CometChatAIAssistantTools";
|
|
110
99
|
import { StreamMessage } from "../shared/modals";
|
|
111
100
|
import { internalMessageDataSource } from "../shared/framework/MessageDataSource";
|
|
112
101
|
import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
|
|
102
|
+
import { MessageModals } from "./components/MessageModals";
|
|
103
|
+
import { ReactionModals } from "./components/ReactionModals";
|
|
104
|
+
import { MessageOptionsSheet } from "./components/MessageOptionsSheet";
|
|
105
|
+
import { MessageListItem } from "./components/MessageListItem";
|
|
113
106
|
|
|
114
107
|
let _defaultRequestBuilder: CometChat.MessagesRequestBuilder;
|
|
115
|
-
|
|
108
|
+
const SEPARATOR_HEIGHT = 40;
|
|
109
|
+
const AVERAGE_ITEM_LENGTH = 120;
|
|
110
|
+
const SMALL_LIST_THRESHOLD = 30;
|
|
116
111
|
/**
|
|
117
112
|
* Helper function to safely get message ID
|
|
118
113
|
* Prevents "undefined is not a function" errors in release builds
|
|
@@ -129,6 +124,22 @@ const safeGetMuid = (item: any): string | undefined => {
|
|
|
129
124
|
return typeof item?.getMuid === 'function' ? item.getMuid() : item?.muid;
|
|
130
125
|
};
|
|
131
126
|
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Batch state updates using requestAnimationFrame
|
|
131
|
+
* It delays the callback until the next animation frame,
|
|
132
|
+
* so all state updates inside the callback happen together,
|
|
133
|
+
* just before the UI paints.
|
|
134
|
+
*/
|
|
135
|
+
|
|
136
|
+
function batchStateUpdates(callback: () => void): void {
|
|
137
|
+
requestAnimationFrame(() => {
|
|
138
|
+
callback();
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
|
|
132
143
|
/**
|
|
133
144
|
* Uses Inverted Flat List
|
|
134
145
|
* Array needs to be reversed meaning the latest message will be at array[0]
|
|
@@ -224,6 +235,28 @@ export interface CometChatMessageListProps {
|
|
|
224
235
|
* If true, the message list will scroll to the bottom when new messages arrive.
|
|
225
236
|
*/
|
|
226
237
|
scrollToBottomOnNewMessages?: boolean;
|
|
238
|
+
/**
|
|
239
|
+
* If true, the "Mark as Unread" option will be shown in the message options.
|
|
240
|
+
* @defaultValue false
|
|
241
|
+
*/
|
|
242
|
+
showMarkAsUnreadOption?: boolean;
|
|
243
|
+
/**
|
|
244
|
+
* If true, the message list will start from the first unread message.
|
|
245
|
+
* @defaultValue false
|
|
246
|
+
*/
|
|
247
|
+
startFromUnreadMessages?: boolean;
|
|
248
|
+
/**
|
|
249
|
+
* Custom component to render the "New Messages" indicator.
|
|
250
|
+
*/
|
|
251
|
+
NewMessageIndicatorView?: React.ComponentType<any>;
|
|
252
|
+
/**
|
|
253
|
+
* Custom styles for the "New Messages" indicator.
|
|
254
|
+
*/
|
|
255
|
+
newMessageIndicatorStyle?: NewMessageIndicatorStyle;
|
|
256
|
+
/**
|
|
257
|
+
* Text to display in the "New Messages" indicator.
|
|
258
|
+
*/
|
|
259
|
+
newMessageIndicatorText?: string;
|
|
227
260
|
/**
|
|
228
261
|
* Callback invoked when the thread replies view is pressed.
|
|
229
262
|
*
|
|
@@ -440,6 +473,18 @@ export interface CometChatMessageListProps {
|
|
|
440
473
|
* When provided, matching text in messages will be highlighted.
|
|
441
474
|
*/
|
|
442
475
|
searchKeyword?: string;
|
|
476
|
+
/**
|
|
477
|
+
* @internal
|
|
478
|
+
* Flag to indicate if the user navigated from search results.
|
|
479
|
+
* When true, this modifies the message list behavior for better search navigation UX:
|
|
480
|
+
* - The target message from search is highlighted with a temporary animation
|
|
481
|
+
* - The "New Messages" indicator is suppressed to avoid visual clutter
|
|
482
|
+
* - When startFromUnreadMessages is enabled, prevents automatic marking of messages as read
|
|
483
|
+
* to preserve unread status for user reference
|
|
484
|
+
* This ensures users can easily find their searched message without UI distractions
|
|
485
|
+
* and maintain their unread message state for later review.
|
|
486
|
+
*/
|
|
487
|
+
navigatedFromSearch?: boolean;
|
|
443
488
|
}
|
|
444
489
|
|
|
445
490
|
/**
|
|
@@ -556,31 +601,38 @@ export const CometChatMessageList = memo(
|
|
|
556
601
|
streamingSpeed = 30,
|
|
557
602
|
goToMessageId,
|
|
558
603
|
searchKeyword,
|
|
604
|
+
navigatedFromSearch = false,
|
|
559
605
|
hideFlagRemarkField,
|
|
560
606
|
hideFlagMessageOption: propHideFlagMessageOption = false,
|
|
607
|
+
showMarkAsUnreadOption = false,//change it to false default is false
|
|
608
|
+
startFromUnreadMessages = false,//change it to false default is false
|
|
609
|
+
NewMessageIndicatorView,
|
|
610
|
+
newMessageIndicatorStyle,
|
|
611
|
+
newMessageIndicatorText,
|
|
561
612
|
} = props;
|
|
562
613
|
|
|
563
|
-
// Helper
|
|
564
|
-
const isAgenticUser =
|
|
614
|
+
// Helper to check if user is agentic - memoized as boolean for performance
|
|
615
|
+
const isAgenticUser = useMemo(() => {
|
|
565
616
|
return user?.getRole?.() === "@agentic";
|
|
566
617
|
}, [user]);
|
|
567
618
|
|
|
568
619
|
// hiding props for @agentic users
|
|
569
|
-
const hideReplyOption = isAgenticUser
|
|
570
|
-
const hideReplyInThreadOption = isAgenticUser
|
|
571
|
-
const hideShareMessageOption = isAgenticUser
|
|
572
|
-
const hideEditMessageOption = isAgenticUser
|
|
573
|
-
const hideTranslateMessageOption = isAgenticUser
|
|
574
|
-
const hideDeleteMessageOption = isAgenticUser
|
|
575
|
-
const hideReactionOption = isAgenticUser
|
|
576
|
-
const hideMessagePrivatelyOption = isAgenticUser
|
|
577
|
-
const hideCopyMessageOption = isAgenticUser
|
|
578
|
-
const hideMessageInfoOption = isAgenticUser
|
|
579
|
-
const hideGroupActionMessages = isAgenticUser
|
|
580
|
-
const hideFlagMessageOption = isAgenticUser
|
|
620
|
+
const hideReplyOption = isAgenticUser ? true : propHideReplyOption;
|
|
621
|
+
const hideReplyInThreadOption = isAgenticUser ? true : propHideReplyInThreadOption;
|
|
622
|
+
const hideShareMessageOption = isAgenticUser ? true : propHideShareMessageOption;
|
|
623
|
+
const hideEditMessageOption = isAgenticUser ? true : propHideEditMessageOption;
|
|
624
|
+
const hideTranslateMessageOption = isAgenticUser ? true : propHideTranslateMessageOption;
|
|
625
|
+
const hideDeleteMessageOption = isAgenticUser ? true : propHideDeleteMessageOption;
|
|
626
|
+
const hideReactionOption = isAgenticUser ? true : propHideReactionOption;
|
|
627
|
+
const hideMessagePrivatelyOption = isAgenticUser ? true : propHideMessagePrivatelyOption;
|
|
628
|
+
const hideCopyMessageOption = isAgenticUser ? true : propHideCopyMessageOption;
|
|
629
|
+
const hideMessageInfoOption = isAgenticUser ? true : (propHideMessageInfoOption || !receiptsVisibility);
|
|
630
|
+
const hideGroupActionMessages = isAgenticUser ? true : propHideGroupActionMessages;
|
|
631
|
+
const hideFlagMessageOption = isAgenticUser ? true : propHideFlagMessageOption;
|
|
632
|
+
const hideMarkAsUnreadOption = (isAgenticUser || !!parentMessageId) ? true : !showMarkAsUnreadOption;//hide for threads and agentic users
|
|
581
633
|
|
|
582
634
|
const callListenerId = "call_" + new Date().getTime();
|
|
583
|
-
const effectiveHideModeration =
|
|
635
|
+
const effectiveHideModeration = hideModerationStatus;
|
|
584
636
|
const groupListenerId = "group_" + new Date().getTime();
|
|
585
637
|
const uiEventListener = "uiEvent_" + new Date().getTime();
|
|
586
638
|
const callEventListener = "callEvent_" + new Date().getTime();
|
|
@@ -591,10 +643,11 @@ export const CometChatMessageList = memo(
|
|
|
591
643
|
const groupEventListener = "groupEvent_" + new Date().getTime();
|
|
592
644
|
const streamListenerId = "agent_" + new Date().getTime();
|
|
593
645
|
const deleteItem = useRef<CometChat.BaseMessage>(undefined);
|
|
646
|
+
const shouldSuppressHighlightRef = useRef(false);
|
|
594
647
|
|
|
595
648
|
useLayoutEffect(() => {
|
|
596
649
|
// For agent chats (non-thread), don't set up message request builder
|
|
597
|
-
if (isAgenticUser
|
|
650
|
+
if (isAgenticUser && !parentMessageId) {
|
|
598
651
|
msgRequestBuilder.current = null as any;
|
|
599
652
|
return;
|
|
600
653
|
}
|
|
@@ -632,7 +685,7 @@ export const CometChatMessageList = memo(
|
|
|
632
685
|
_updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setParentMessageId(
|
|
633
686
|
parseInt(parentMessageId)
|
|
634
687
|
);
|
|
635
|
-
if (isAgenticUser
|
|
688
|
+
if (isAgenticUser) {
|
|
636
689
|
_updatedCustomRequestBuilder.hideReplies(false);
|
|
637
690
|
_updatedCustomRequestBuilder.withParent(true);
|
|
638
691
|
}
|
|
@@ -820,13 +873,13 @@ export const CometChatMessageList = memo(
|
|
|
820
873
|
layoutHeight: 0,
|
|
821
874
|
contentHeight: 0,
|
|
822
875
|
});
|
|
823
|
-
const messagesLength = useRef(0);
|
|
824
|
-
const prevMessagesLength = useRef(0);
|
|
825
|
-
const messageListRef = useRef<FlatList | null>(null);
|
|
826
|
-
const loggedInUser = useRef<CometChat.User | null | any>(null);
|
|
827
|
-
const messageRequest = useRef<CometChat.MessagesRequest | null>(null);
|
|
828
|
-
const messagesContentListRef = useRef<any[]>([]);
|
|
829
|
-
const temporaryMessageListRef = useRef<any[]>([]);
|
|
876
|
+
const messagesLength = useRef(0); // Tracks total message count to detect additions/updates
|
|
877
|
+
const prevMessagesLength = useRef(0); // Tracks previous message count to handle scroll position adjustments when loading history
|
|
878
|
+
const messageListRef = useRef<FlatList | null>(null); // Reference to the FlatList for programmatic scrolling
|
|
879
|
+
const loggedInUser = useRef<CometChat.User | null | any>(null); // Stores current user to check sender identity (me vs others)
|
|
880
|
+
const messageRequest = useRef<CometChat.MessagesRequest | null>(null); // Manages pagination state for fetching messages
|
|
881
|
+
const messagesContentListRef = useRef<any[]>([]); // "Main Stage": Source of Truth for visible messages. Kept in sync with state to handle real-time updates without closure staleness.
|
|
882
|
+
const temporaryMessageListRef = useRef<any[]>([]); // "Waiting Room": Buffer for new messages arriving while scrolled up. Prevents UI jumps/insertions while reading history.
|
|
830
883
|
|
|
831
884
|
const msgRequestBuilder = useRef<CometChat.MessagesRequestBuilder>(undefined);
|
|
832
885
|
const lastMessageDate = useRef(new Date().getTime());
|
|
@@ -834,7 +887,7 @@ export const CometChatMessageList = memo(
|
|
|
834
887
|
// states
|
|
835
888
|
const [messagesList, setMessagesList] = useState<any[]>([]);
|
|
836
889
|
const [listState, setListState] = useState(
|
|
837
|
-
isAgenticUser
|
|
890
|
+
isAgenticUser && !parentMessageId ? "loaded" : "loading"
|
|
838
891
|
);
|
|
839
892
|
const [loadingMessages, setLoadingMessages] = useState(false);
|
|
840
893
|
/** this is required to prevent duplicate api calls. Cannot use state for this since this is being used in scrollHandler **/
|
|
@@ -842,12 +895,18 @@ export const CometChatMessageList = memo(
|
|
|
842
895
|
const loadingPrevMessagesRef = useRef(false);
|
|
843
896
|
// State for showing loading when navigating to far messages
|
|
844
897
|
const [navigationLoading, setNavigationLoading] = useState(false);
|
|
898
|
+
// State for showing loading when scrolling to searched messages
|
|
899
|
+
const [scrollLoading, setScrollLoading] = useState(false);
|
|
845
900
|
// State for showing bottom loading indicator when fetching next messages
|
|
846
901
|
const [bottomLoading, setBottomLoading] = useState(false);
|
|
847
|
-
const [unreadCount, setUnreadCount] = useState(0);
|
|
902
|
+
const [unreadCount, setUnreadCount] = useState<number>(0);
|
|
848
903
|
const [showMessageOptions, setShowMessageOptions] = useState<any[]>([]);
|
|
849
904
|
const [ExtensionsComponent, setExtensionsComponent] = useState<JSX.Element | null>(null);
|
|
850
905
|
const [CustomListHeader, setCustomListHeader] = useState<any>(null);
|
|
906
|
+
// State to track new message indicator visibility
|
|
907
|
+
const [newMessageIndicatorId, setNewMessageIndicatorId] = useState<string | null>(null);
|
|
908
|
+
// State to track if user has manually marked messages as unread
|
|
909
|
+
const [hasManuallyMarkedUnread, setHasManuallyMarkedUnread] = useState<boolean>(false);
|
|
851
910
|
const [messageInfo, setMessageInfo] = useState(false);
|
|
852
911
|
const [showReportDialog, setShowReportDialog] = useState(false);
|
|
853
912
|
const [ongoingCallView, setOngoingCallView] = useState(null);
|
|
@@ -862,7 +921,6 @@ export const CometChatMessageList = memo(
|
|
|
862
921
|
const [highlightedMessageId, setHighlightedMessageId] = useState<string | null>(null);
|
|
863
922
|
const [scrollTargetId, setScrollTargetId] = useState<string | null>(null);
|
|
864
923
|
const highlightAnimatedValue = useRef(new Animated.Value(0)).current;
|
|
865
|
-
const [isListLayoutComplete, setIsListLayoutComplete] = useState<boolean>(false);
|
|
866
924
|
const reportedMessageRef = useRef<CometChat.BaseMessage | null>(null);
|
|
867
925
|
const pendingReportRef = useRef<boolean>(false);
|
|
868
926
|
const bottomSheetRef = useRef<any>(null);
|
|
@@ -872,19 +930,24 @@ export const CometChatMessageList = memo(
|
|
|
872
930
|
const reachedFirstMessage = useRef<boolean>(false);
|
|
873
931
|
const agenticParentMessageIdRef = useRef<string | undefined>(undefined);
|
|
874
932
|
const [hasTargetMessageId, setHasTargetMessageId] = useState(false);
|
|
875
|
-
const hasReachedBottomRef = useRef(true);
|
|
876
933
|
const fetchingAroundIdRef = useRef<string | null>(null); // Track which message ID we're currently fetching
|
|
877
|
-
const
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
934
|
+
const [itemPositions, setItemPositions] = useState<Map<string, { y: number; height: number }>>(new Map());
|
|
935
|
+
const markUnreadMessageAsRead = (message?: CometChat.BaseMessage) => {
|
|
936
|
+
const messageToMark = message || messagesContentListRef.current[0];
|
|
937
|
+
if (messageToMark) {
|
|
938
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
939
|
+
message: messageToMark,
|
|
940
|
+
});
|
|
941
|
+
CometChat.markAsRead(messageToMark);
|
|
942
|
+
setUnreadCount(0);
|
|
943
|
+
}
|
|
883
944
|
};
|
|
884
945
|
const prevMsgListLengthRef = useRef<number>(0);
|
|
885
946
|
const aMessageWasSentByMeRef = useRef<boolean>(false);
|
|
886
947
|
const latestMessageRef = useRef<any | null>(null);
|
|
887
948
|
|
|
949
|
+
|
|
950
|
+
|
|
888
951
|
useEffect(() => {
|
|
889
952
|
if (messagesList.length === prevMsgListLengthRef.current + 1 && aMessageWasSentByMeRef.current) {
|
|
890
953
|
aMessageWasSentByMeRef.current = false;
|
|
@@ -896,7 +959,6 @@ export const CometChatMessageList = memo(
|
|
|
896
959
|
}, [messagesList]);
|
|
897
960
|
|
|
898
961
|
|
|
899
|
-
|
|
900
962
|
const newMsgIndicatorPressed = useCallback(async () => {
|
|
901
963
|
if (hasTargetMessageId) {
|
|
902
964
|
try {
|
|
@@ -916,26 +978,43 @@ export const CometChatMessageList = memo(
|
|
|
916
978
|
setListState("");
|
|
917
979
|
}
|
|
918
980
|
} else {
|
|
981
|
+
// Merge temporary messages when unread count button is pressed
|
|
919
982
|
messagesContentListRef.current = [
|
|
920
983
|
...temporaryMessageListRef.current,
|
|
921
984
|
...messagesContentListRef.current,
|
|
922
985
|
];
|
|
923
|
-
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
924
|
-
setMessagesList((prev) => [...temporaryMessageListRef.current, ...prev]);
|
|
925
986
|
temporaryMessageListRef.current = [];
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
987
|
+
|
|
988
|
+
// Update latestMessageRef after merge
|
|
989
|
+
if (messagesContentListRef.current.length > 0) {
|
|
990
|
+
latestMessageRef.current = messagesContentListRef.current[0];
|
|
991
|
+
}
|
|
992
|
+
|
|
993
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
994
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
995
|
+
|
|
996
|
+
setTimeout(() => {
|
|
997
|
+
scrollToBottom();
|
|
998
|
+
setHideScrollToBottomButton(true);
|
|
999
|
+
markUnreadMessageAsRead();
|
|
1000
|
+
}, 100);
|
|
929
1001
|
}
|
|
930
1002
|
}, [onLoad, hasTargetMessageId]);
|
|
931
1003
|
|
|
932
1004
|
const getPreviousMessages = async () => {
|
|
1005
|
+
if (fetchingAroundIdRef.current) return;
|
|
1006
|
+
|
|
933
1007
|
if (loadingPrevMessagesRef.current) {
|
|
934
1008
|
return;
|
|
935
1009
|
}
|
|
936
1010
|
loadingPrevMessagesRef.current = true;
|
|
937
1011
|
// For agent chats (non-thread), don't fetch previous messages
|
|
938
|
-
if (isAgenticUser
|
|
1012
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1013
|
+
return;
|
|
1014
|
+
}
|
|
1015
|
+
|
|
1016
|
+
// Prevent concurrent API calls
|
|
1017
|
+
if (loadingMessagesRef.current) {
|
|
939
1018
|
return;
|
|
940
1019
|
}
|
|
941
1020
|
|
|
@@ -962,6 +1041,7 @@ export const CometChatMessageList = memo(
|
|
|
962
1041
|
reachedFirstMessage.current = true;
|
|
963
1042
|
}
|
|
964
1043
|
let previousMessagesFetched = [...msgs].reverse(); // Reverse for UI use
|
|
1044
|
+
|
|
965
1045
|
if (messagesList.length === 0 && msgs?.length > 0) {
|
|
966
1046
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccActiveChatChanged, {
|
|
967
1047
|
message: previousMessagesFetched[0],
|
|
@@ -982,19 +1062,62 @@ export const CometChatMessageList = memo(
|
|
|
982
1062
|
});
|
|
983
1063
|
}
|
|
984
1064
|
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
994
|
-
|
|
995
|
-
|
|
1065
|
+
// When startFromUnreadMessages is enabled, the chat starts from the first unread message
|
|
1066
|
+
// and shows a "New Messages" indicator above the oldest unread message.
|
|
1067
|
+
// This allows users to quickly see where unread messages begin.
|
|
1068
|
+
if (startFromUnreadMessages && previousMessagesFetched.length > 0) {
|
|
1069
|
+
const lastMessage = previousMessagesFetched[0];//latest message
|
|
1070
|
+
if (!goToMessageId && messagesList.length === 0) {
|
|
1071
|
+
// If we are not navigating to a specific message, we want to show the new message indicator
|
|
1072
|
+
// above the oldest unread message (which is the last one in the fetched list since it's reversed).
|
|
1073
|
+
const oldestMessage = previousMessagesFetched[previousMessagesFetched.length];
|
|
1074
|
+
|
|
1075
|
+
if (oldestMessage) {
|
|
1076
|
+
const msgId = safeGetId(oldestMessage);
|
|
1077
|
+
if (msgId !== undefined) {
|
|
1078
|
+
setNewMessageIndicatorId(String(msgId));
|
|
1079
|
+
}
|
|
1080
|
+
}
|
|
1081
|
+
}
|
|
1082
|
+
|
|
1083
|
+
// Only mark conversation as read on initial load.
|
|
1084
|
+
// If we do this on every fetch (pagination), it would reset the unread count
|
|
1085
|
+
// even if the user manually marked a message as unread.
|
|
1086
|
+
// The !navigatedFromSearch condition ensures we don't mark as read when navigating from search results,
|
|
1087
|
+
// as the user might want to keep messages unread for reference.
|
|
1088
|
+
if (messagesList.length === 0 && !navigatedFromSearch) {
|
|
1089
|
+
//marking most recent unread message as read
|
|
1090
|
+
if (user) {
|
|
1091
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1092
|
+
console.log("Error marking user conversation as read", e);
|
|
1093
|
+
});
|
|
1094
|
+
} else if (group) {
|
|
1095
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
1096
|
+
console.log("Error marking group conversation as read", e);
|
|
996
1097
|
});
|
|
997
|
-
|
|
1098
|
+
}
|
|
1099
|
+
setUnreadCount(0);
|
|
1100
|
+
//emitting event to update read receipts in other components
|
|
1101
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1102
|
+
message: lastMessage,
|
|
1103
|
+
});
|
|
1104
|
+
}
|
|
1105
|
+
|
|
1106
|
+
} else {
|
|
1107
|
+
for (let index = 0; index < previousMessagesFetched.length; index++) {
|
|
1108
|
+
const message: CometChat.BaseMessage = previousMessagesFetched[index];
|
|
1109
|
+
if (
|
|
1110
|
+
message &&
|
|
1111
|
+
!message.hasOwnProperty("readAt") &&
|
|
1112
|
+
loggedInUser.current?.getUid() != message?.getSender()?.getUid()
|
|
1113
|
+
) {
|
|
1114
|
+
CometChat.markAsRead(message);
|
|
1115
|
+
if (index == 0)
|
|
1116
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1117
|
+
message,
|
|
1118
|
+
});
|
|
1119
|
+
} else break;
|
|
1120
|
+
}
|
|
998
1121
|
}
|
|
999
1122
|
previousMessagesFetched = previousMessagesFetched.map(
|
|
1000
1123
|
(item: CometChat.BaseMessage, index: any) => {
|
|
@@ -1058,18 +1181,18 @@ export const CometChatMessageList = memo(
|
|
|
1058
1181
|
if (fetchingAroundIdRef.current === messageId) {
|
|
1059
1182
|
return;
|
|
1060
1183
|
}
|
|
1061
|
-
|
|
1062
|
-
if (isAgenticUser
|
|
1184
|
+
|
|
1185
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1063
1186
|
return;
|
|
1064
1187
|
}
|
|
1065
1188
|
|
|
1066
1189
|
fetchingAroundIdRef.current = messageId; // Mark this message as being fetched
|
|
1067
|
-
|
|
1190
|
+
|
|
1068
1191
|
// Check if message exists in current list
|
|
1069
|
-
const messageExists = messagesContentListRef.current.find(msg =>
|
|
1192
|
+
const messageExists = messagesContentListRef.current.find(msg =>
|
|
1070
1193
|
String(msg.getId()) === String(messageId)
|
|
1071
1194
|
);
|
|
1072
|
-
|
|
1195
|
+
|
|
1073
1196
|
if (messageExists) {
|
|
1074
1197
|
setHasTargetMessageId(true);
|
|
1075
1198
|
} else {
|
|
@@ -1082,7 +1205,7 @@ export const CometChatMessageList = memo(
|
|
|
1082
1205
|
const targetMessageId = Number(messageId);
|
|
1083
1206
|
msgRequestBuilder.current?.setMessageId(targetMessageId);
|
|
1084
1207
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1085
|
-
|
|
1208
|
+
|
|
1086
1209
|
// Get the target message first to ensure it exists
|
|
1087
1210
|
const targetMessage = await CometChat.getMessageDetails(targetMessageId);
|
|
1088
1211
|
if (!targetMessage) {
|
|
@@ -1098,18 +1221,28 @@ export const CometChatMessageList = memo(
|
|
|
1098
1221
|
if (user) {
|
|
1099
1222
|
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
1100
1223
|
}
|
|
1101
|
-
|
|
1224
|
+
|
|
1102
1225
|
if (group) {
|
|
1103
1226
|
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
1104
1227
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1228
|
+
|
|
1229
|
+
// Main chat: Server excludes thread replies
|
|
1230
|
+
if (!parentMessageId) {
|
|
1231
|
+
nextMessagesRequest = nextMessagesRequest.hideReplies(true);
|
|
1232
|
+
}
|
|
1233
|
+
// Thread: Server includes only relevant messages
|
|
1234
|
+
else {
|
|
1235
|
+
nextMessagesRequest = nextMessagesRequest
|
|
1236
|
+
.setParentMessageId(Number(parentMessageId))
|
|
1237
|
+
.hideReplies(false);
|
|
1238
|
+
if (isAgenticUser) {
|
|
1239
|
+
nextMessagesRequest = nextMessagesRequest.withParent(true);
|
|
1240
|
+
}
|
|
1108
1241
|
}
|
|
1109
1242
|
|
|
1110
1243
|
// Fetch messages before and after the target message
|
|
1111
1244
|
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
1112
|
-
|
|
1245
|
+
|
|
1113
1246
|
// Combine messages: previous (reversed) + target + next
|
|
1114
1247
|
const allMessages = [
|
|
1115
1248
|
// ...previousMessages,
|
|
@@ -1119,17 +1252,101 @@ export const CometChatMessageList = memo(
|
|
|
1119
1252
|
|
|
1120
1253
|
// Remove duplicates and sort by timestamp (newest at top for FlatList)
|
|
1121
1254
|
const uniqueMessages = allMessages
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1255
|
+
// .filter((message, index, array) =>
|
|
1256
|
+
// array.findIndex(m => m.getId() === message.getId()) === index
|
|
1257
|
+
// )
|
|
1258
|
+
// .sort((a, b) => b.getSentAt() - a.getSentAt());
|
|
1126
1259
|
|
|
1127
1260
|
if (uniqueMessages.length > 0) {
|
|
1128
|
-
|
|
1261
|
+
// Check if this is the initial load using ref to ensure fresh state
|
|
1262
|
+
const isInitialLoad = messagesContentListRef.current.length === 0;
|
|
1263
|
+
messagesContentListRef.current = uniqueMessages;
|
|
1129
1264
|
setMessagesList(uniqueMessages);
|
|
1130
1265
|
onLoad && onLoad([...uniqueMessages].reverse());
|
|
1131
1266
|
|
|
1267
|
+
//This check is used to determine if this is the Initial Load of the chat screen.
|
|
1268
|
+
// Check if this is the initial load (messagesList is empty).
|
|
1269
|
+
// We check messagesList.length === 0 because setMessagesList above is async,
|
|
1270
|
+
// so messagesList still reflects the state before this update.
|
|
1271
|
+
// We only want to mark as read on the first load, not during subsequent updates.
|
|
1272
|
+
// The !navigatedFromSearch condition ensures we don't mark as read when navigating from search results,
|
|
1273
|
+
// as the user might want to keep messages unread for reference.
|
|
1274
|
+
if (startFromUnreadMessages && isInitialLoad && !navigatedFromSearch && !goToMessageId) {
|
|
1275
|
+
shouldSuppressHighlightRef.current = true;
|
|
1276
|
+
//marking most recent unread message as read
|
|
1277
|
+
if (user) {
|
|
1278
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1279
|
+
console.log("Error marking user conversation as read", e);
|
|
1280
|
+
});
|
|
1281
|
+
} else if (group) {
|
|
1282
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
1283
|
+
console.log("Error marking group conversation as read", e);
|
|
1284
|
+
});
|
|
1285
|
+
}
|
|
1286
|
+
setUnreadCount(0);
|
|
1287
|
+
// If we have next messages (unread messages), set the indicator on the first one.
|
|
1288
|
+
// Otherwise, fallback to the target message (last read message).
|
|
1289
|
+
if (nextMessages.length > 0) {
|
|
1290
|
+
setNewMessageIndicatorId(String(nextMessages[0].getId()));
|
|
1291
|
+
} else {
|
|
1292
|
+
setNewMessageIndicatorId(messageId);
|
|
1293
|
+
}
|
|
1294
|
+
//emitting event to update read receipts in other components
|
|
1295
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1296
|
+
message: uniqueMessages[0],
|
|
1297
|
+
});
|
|
1298
|
+
} else if (navigatedFromSearch) {
|
|
1299
|
+
// If we navigated from search, we want to show the "New Messages" indicator
|
|
1300
|
+
// but NOT mark the conversation as read immediately.
|
|
1301
|
+
// We fetch the first unread message to place the indicator correctly.
|
|
1302
|
+
const fetchFirstUnread = async () => {
|
|
1303
|
+
try {
|
|
1304
|
+
const convId = user?.getUid() ?? group?.getGuid();
|
|
1305
|
+
const conversationType = user
|
|
1306
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
1307
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
1308
|
+
|
|
1309
|
+
if (!convId) return;
|
|
1310
|
+
|
|
1311
|
+
const conversation = await CometChat.getConversation(convId, conversationType);
|
|
1312
|
+
const unreadCount = conversation.getUnreadMessageCount();
|
|
1313
|
+
setUnreadCount(unreadCount);
|
|
1314
|
+
|
|
1315
|
+
if (unreadCount > 0) {
|
|
1316
|
+
const lastReadMsgId = conversation.getLastReadMessageId();
|
|
1317
|
+
|
|
1318
|
+
if (lastReadMsgId) {
|
|
1319
|
+
let request = new CometChat.MessagesRequestBuilder()
|
|
1320
|
+
.setLimit(1)
|
|
1321
|
+
.setMessageId(Number(lastReadMsgId));
|
|
1322
|
+
|
|
1323
|
+
if (user) request = request.setUID(user.getUid());
|
|
1324
|
+
if (group) request = request.setGUID(group.getGuid());
|
|
1325
|
+
|
|
1326
|
+
if (!parentMessageId) {
|
|
1327
|
+
request = request.hideReplies(true);
|
|
1328
|
+
} else {
|
|
1329
|
+
request = request.setParentMessageId(Number(parentMessageId)).hideReplies(false);
|
|
1330
|
+
if (isAgenticUser) {
|
|
1331
|
+
request = request.withParent(true);
|
|
1332
|
+
}
|
|
1333
|
+
}
|
|
1334
|
+
|
|
1335
|
+
const unreadMessages = await request.build().fetchNext();
|
|
1336
|
+
if (unreadMessages.length > 0) {
|
|
1337
|
+
setNewMessageIndicatorId(String(unreadMessages[0].getId()));
|
|
1338
|
+
}
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
} catch (e) {
|
|
1342
|
+
console.log("Error fetching first unread message", e);
|
|
1343
|
+
}
|
|
1344
|
+
};
|
|
1345
|
+
fetchFirstUnread();
|
|
1346
|
+
}
|
|
1347
|
+
|
|
1132
1348
|
// Reset layout state and set up for scrolling to target message
|
|
1349
|
+
// console.log(`Setting scroll target to message: ${messageId}`);
|
|
1133
1350
|
setScrollTargetId(messageId);
|
|
1134
1351
|
}
|
|
1135
1352
|
|
|
@@ -1137,39 +1354,91 @@ export const CometChatMessageList = memo(
|
|
|
1137
1354
|
} catch (error) {
|
|
1138
1355
|
console.log("Error fetching messages around ID:", error);
|
|
1139
1356
|
setListState("error");
|
|
1357
|
+
setNavigationLoading(false);
|
|
1140
1358
|
onError && onError(error as CometChat.CometChatException);
|
|
1141
1359
|
} finally {
|
|
1142
|
-
setNavigationLoading(false);
|
|
1360
|
+
// setNavigationLoading(false);
|
|
1143
1361
|
fetchingAroundIdRef.current = null;
|
|
1144
1362
|
}
|
|
1145
1363
|
};
|
|
1146
1364
|
|
|
1147
|
-
|
|
1365
|
+
// Scrolls to a specific message by ID, centering it in the view
|
|
1366
|
+
// Uses position data from itemPositions map for precise scrolling
|
|
1367
|
+
const scrollToMessage = (messageId: string, retryCount: number = 0) => {
|
|
1148
1368
|
if (messageListRef.current && messagesContentListRef.current.length > 0) {
|
|
1369
|
+
// Show loading indicator during scroll operation
|
|
1370
|
+
setNavigationLoading(true);
|
|
1371
|
+
|
|
1149
1372
|
const targetIndex = messagesContentListRef.current.findIndex(
|
|
1150
1373
|
(msg) => String(msg.getId()) === messageId
|
|
1151
1374
|
);
|
|
1152
|
-
|
|
1375
|
+
|
|
1153
1376
|
if (targetIndex !== -1) {
|
|
1154
|
-
//
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
//
|
|
1165
|
-
const
|
|
1377
|
+
// Get the actual position of the target message
|
|
1378
|
+
const targetMessage = messagesContentListRef.current[targetIndex];
|
|
1379
|
+
const position = itemPositions.get(String(targetMessage.getId()));
|
|
1380
|
+
|
|
1381
|
+
if (position) {
|
|
1382
|
+
// Calculate centered offset for the message
|
|
1383
|
+
// For inverted list, we need to position it from the top of the visible area
|
|
1384
|
+
const screenHeight = currentScrollPosition.current.scrollViewHeight || Dimensions.get('window').height;
|
|
1385
|
+
|
|
1386
|
+
// Center the message: place it at middle of the screen
|
|
1387
|
+
// In inverted list: offset = message.y - (screenHeight/2 - messageHeight/2)
|
|
1388
|
+
const centeredOffset = Math.max(0, position.y - (screenHeight / 2) + (position.height / 2));
|
|
1389
|
+
|
|
1390
|
+
// console.log(`📍 Scrolling to position-based offset ${centeredOffset.toFixed(1)}px for message ${messageId}`);
|
|
1166
1391
|
messageListRef.current?.scrollToOffset({
|
|
1167
|
-
offset:
|
|
1392
|
+
offset: centeredOffset,
|
|
1168
1393
|
animated: true,
|
|
1169
1394
|
});
|
|
1170
|
-
|
|
1395
|
+
|
|
1396
|
+
// Highlight after scroll animation starts
|
|
1397
|
+
setTimeout(() => {
|
|
1398
|
+
// console.log(`Highlighting message ${messageId} after position-based scroll`);
|
|
1399
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1400
|
+
highlightMessage(messageId);
|
|
1401
|
+
}
|
|
1402
|
+
shouldSuppressHighlightRef.current = false;
|
|
1403
|
+
setNavigationLoading(false); // Clear loading when scroll completes
|
|
1404
|
+
}, 150);
|
|
1405
|
+
} else {
|
|
1406
|
+
// Position not measured yet - retry with faster progressive delays (up to 5 times)
|
|
1407
|
+
if (retryCount < 5) {
|
|
1408
|
+
// Faster progressive delays: 100ms, 200ms, 300ms, 400ms, 500ms
|
|
1409
|
+
const delay = (retryCount + 1) * 100;
|
|
1410
|
+
// console.log(`Retrying scroll for message ${messageId} (attempt ${retryCount + 1}/5) after ${delay}ms - waiting for layout`);
|
|
1411
|
+
setTimeout(() => {
|
|
1412
|
+
scrollToMessage(messageId, retryCount + 1);
|
|
1413
|
+
}, delay);
|
|
1414
|
+
} else {
|
|
1415
|
+
// Final fallback: use scrollToIndex with onScrollToIndexFailed handling for dynamic heights
|
|
1416
|
+
try {
|
|
1417
|
+
messageListRef.current?.scrollToIndex({
|
|
1418
|
+
index: targetIndex,
|
|
1419
|
+
animated: true,
|
|
1420
|
+
viewPosition: 0.5, // For inverted FlatList
|
|
1421
|
+
});
|
|
1422
|
+
// onScrollToIndexFailed will handle retry logic if this fails
|
|
1423
|
+
setTimeout(() => {
|
|
1424
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1425
|
+
highlightMessage(messageId);
|
|
1426
|
+
}
|
|
1427
|
+
shouldSuppressHighlightRef.current = false;
|
|
1428
|
+
setNavigationLoading(false); // Clear loading when scroll completes
|
|
1429
|
+
}, 250);
|
|
1430
|
+
} catch (scrollError) {
|
|
1431
|
+
console.error('scrollToIndex failed immediately:', scrollError);
|
|
1432
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1433
|
+
highlightMessage(messageId);
|
|
1434
|
+
}
|
|
1435
|
+
shouldSuppressHighlightRef.current = false;
|
|
1436
|
+
setNavigationLoading(false); // Clear loading on final failure
|
|
1437
|
+
}
|
|
1438
|
+
}
|
|
1171
1439
|
}
|
|
1172
1440
|
} else {
|
|
1441
|
+
setNavigationLoading(false); // Clear loading since we're fetching
|
|
1173
1442
|
getMessagesAroundId(messageId);
|
|
1174
1443
|
}
|
|
1175
1444
|
}
|
|
@@ -1177,7 +1446,7 @@ export const CometChatMessageList = memo(
|
|
|
1177
1446
|
|
|
1178
1447
|
const getUpdatedPreviousMessages = () => {
|
|
1179
1448
|
// For agent chats (non-thread), don't fetch updated previous messages
|
|
1180
|
-
if (isAgenticUser
|
|
1449
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1181
1450
|
return;
|
|
1182
1451
|
}
|
|
1183
1452
|
|
|
@@ -1265,7 +1534,7 @@ export const CometChatMessageList = memo(
|
|
|
1265
1534
|
};
|
|
1266
1535
|
|
|
1267
1536
|
const templatesMap = useMemo(() => {
|
|
1268
|
-
const isAgenticUserCheck = isAgenticUser
|
|
1537
|
+
const isAgenticUserCheck = isAgenticUser;
|
|
1269
1538
|
const options = {
|
|
1270
1539
|
textFormatters: textFormatters || [],
|
|
1271
1540
|
hideReplyOption: isAgenticUserCheck || hideReplyOption,
|
|
@@ -1279,6 +1548,7 @@ export const CometChatMessageList = memo(
|
|
|
1279
1548
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1280
1549
|
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption || !receiptsVisibility,
|
|
1281
1550
|
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1551
|
+
hideMarkAsUnreadOption: isAgenticUserCheck || hideMarkAsUnreadOption,
|
|
1282
1552
|
hideGroupActionMessages,
|
|
1283
1553
|
onReplyClick: (messageId: string) => {
|
|
1284
1554
|
scrollToMessage(messageId);
|
|
@@ -1289,9 +1559,9 @@ export const CometChatMessageList = memo(
|
|
|
1289
1559
|
templates && templates.length
|
|
1290
1560
|
? templates
|
|
1291
1561
|
: [
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1562
|
+
...ChatConfigurator.dataSource.getAllMessageTemplates(mergedTheme, options),
|
|
1563
|
+
...addTemplates,
|
|
1564
|
+
];
|
|
1295
1565
|
//for internal use only
|
|
1296
1566
|
const streamTemplate = internalMessageDataSource.getStreamMessageTemplate(
|
|
1297
1567
|
mergedTheme,
|
|
@@ -1434,6 +1704,46 @@ export const CometChatMessageList = memo(
|
|
|
1434
1704
|
});
|
|
1435
1705
|
}
|
|
1436
1706
|
};
|
|
1707
|
+
/**
|
|
1708
|
+
* Marks a specific message as unread in the conversation.
|
|
1709
|
+
* This function calls the CometChat SDK to mark the message as unread,
|
|
1710
|
+
* updates the conversation's unread count, and emits events to notify
|
|
1711
|
+
* other components of the conversation update. It also sets the new
|
|
1712
|
+
* message indicator to appear above this message.
|
|
1713
|
+
* @param message - The message to mark as unread
|
|
1714
|
+
*/
|
|
1715
|
+
const markMessageAsUnread = (message: CometChat.BaseMessage) => {
|
|
1716
|
+
CometChat.markMessageAsUnread(message).then(
|
|
1717
|
+
(response: any) => {
|
|
1718
|
+
setShowMessageOptions([]);
|
|
1719
|
+
setHasManuallyMarkedUnread(true);
|
|
1720
|
+
let convId: string = "";
|
|
1721
|
+
let conversationType: string = "";
|
|
1722
|
+
if (user) {
|
|
1723
|
+
convId = user?.getUid();
|
|
1724
|
+
conversationType = CometChat.RECEIVER_TYPE.USER;
|
|
1725
|
+
} else if (group) {
|
|
1726
|
+
convId = group?.getGuid();
|
|
1727
|
+
conversationType = CometChat.RECEIVER_TYPE.GROUP;
|
|
1728
|
+
}
|
|
1729
|
+
//getting convesation using conversationId=Uid and conversationType
|
|
1730
|
+
CometChat.getConversation(convId, conversationType).then((conversation) => {
|
|
1731
|
+
// Emitting conversation update event
|
|
1732
|
+
CometChatUIEventHandler.emitConversationEvent(
|
|
1733
|
+
CometChatConversationEvents.ccUpdateConversation,
|
|
1734
|
+
{ conversation }
|
|
1735
|
+
);
|
|
1736
|
+
setUnreadCount(conversation.getUnreadMessageCount());
|
|
1737
|
+
setNewMessageIndicatorId(message.getId().toString());
|
|
1738
|
+
}).catch((error) => {
|
|
1739
|
+
console.log("Error fetching conversation after marking as unread", error);
|
|
1740
|
+
});
|
|
1741
|
+
},
|
|
1742
|
+
(error: any) => {
|
|
1743
|
+
console.log("Error marking as unread", error);
|
|
1744
|
+
}
|
|
1745
|
+
);
|
|
1746
|
+
};
|
|
1437
1747
|
|
|
1438
1748
|
function checkMessageInSameConversation(message: CometChat.BaseMessage | any): boolean {
|
|
1439
1749
|
return (
|
|
@@ -1461,34 +1771,36 @@ export const CometChatMessageList = memo(
|
|
|
1461
1771
|
);
|
|
1462
1772
|
}
|
|
1463
1773
|
useEffect(() => {
|
|
1464
|
-
if (isAgenticUser
|
|
1774
|
+
if (isAgenticUser && parentMessageId && !conversationId.current) {
|
|
1465
1775
|
conversationId.current = parentMessageId;
|
|
1466
1776
|
}
|
|
1467
1777
|
}, [parentMessageId, isAgenticUser]);
|
|
1468
1778
|
|
|
1469
1779
|
// Handle scrolling to highlighted message when FlatList layout is complete
|
|
1470
1780
|
useEffect(() => {
|
|
1471
|
-
let
|
|
1781
|
+
let rafId: number | undefined;
|
|
1782
|
+
|
|
1472
1783
|
if (scrollTargetId && messagesList.length > 0) {
|
|
1473
|
-
|
|
1784
|
+
rafId = requestAnimationFrame(() => {
|
|
1474
1785
|
scrollToMessage(scrollTargetId);
|
|
1475
1786
|
setScrollTargetId(null);
|
|
1476
|
-
}
|
|
1787
|
+
});
|
|
1477
1788
|
}
|
|
1789
|
+
|
|
1478
1790
|
return () => {
|
|
1479
|
-
if (
|
|
1791
|
+
if (rafId) cancelAnimationFrame(rafId);
|
|
1480
1792
|
};
|
|
1481
1793
|
}, [scrollTargetId, messagesList.length]);
|
|
1482
1794
|
|
|
1483
1795
|
function checkSameConversation(message: CometChat.BaseMessage): boolean {
|
|
1484
1796
|
if ((message as any).isStreamMessage) {
|
|
1485
|
-
if (isAgenticUser
|
|
1797
|
+
if (isAgenticUser) {
|
|
1486
1798
|
return (message as any).targetMessageId === agenticParentMessageIdRef.current;
|
|
1487
1799
|
}
|
|
1488
1800
|
return true;
|
|
1489
1801
|
}
|
|
1490
1802
|
|
|
1491
|
-
if (isAgenticUser
|
|
1803
|
+
if (isAgenticUser) {
|
|
1492
1804
|
if (parentMessageId && agenticParentMessageIdRef.current) {
|
|
1493
1805
|
return (
|
|
1494
1806
|
message.getParentMessageId &&
|
|
@@ -1519,6 +1831,12 @@ export const CometChatMessageList = memo(
|
|
|
1519
1831
|
if (!layoutHeight) {
|
|
1520
1832
|
return true;
|
|
1521
1833
|
}
|
|
1834
|
+
|
|
1835
|
+
// If we have navigated from search and are viewing old messages, we are NOT near bottom
|
|
1836
|
+
if (navigatedFromSearch && hasTargetMessageId) {
|
|
1837
|
+
return false;
|
|
1838
|
+
}
|
|
1839
|
+
|
|
1522
1840
|
let scrollPosFromTopInPercentage = (scrollPos / layoutHeight) * 100;
|
|
1523
1841
|
|
|
1524
1842
|
// If the user has scrolled to within 30% from the top (which is the "bottom" in this case),
|
|
@@ -1535,7 +1853,7 @@ export const CometChatMessageList = memo(
|
|
|
1535
1853
|
//todo show unsupported bubble
|
|
1536
1854
|
}
|
|
1537
1855
|
|
|
1538
|
-
if (isAgenticUser
|
|
1856
|
+
if (isAgenticUser) {
|
|
1539
1857
|
if (
|
|
1540
1858
|
String(baseMessage.getParentMessageId()) === String(parentMessageId) ||
|
|
1541
1859
|
String(baseMessage.getId()) === String(parentMessageId)
|
|
@@ -1551,7 +1869,11 @@ export const CometChatMessageList = memo(
|
|
|
1551
1869
|
checkMessageInSameConversation(baseMessage) ||
|
|
1552
1870
|
messageToSameConversation(baseMessage)
|
|
1553
1871
|
) {
|
|
1554
|
-
|
|
1872
|
+
if (user) {
|
|
1873
|
+
CometChat.markConversationAsDelivered(user.getUid(), CometChat.RECEIVER_TYPE.USER);
|
|
1874
|
+
} else if (group) {
|
|
1875
|
+
CometChat.markConversationAsDelivered(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP);
|
|
1876
|
+
}
|
|
1555
1877
|
if (!parentMessageId && newMessage.getParentMessageId()) {
|
|
1556
1878
|
const parentId = String(
|
|
1557
1879
|
newMessage.getParentMessageId
|
|
@@ -1629,14 +1951,78 @@ export const CometChatMessageList = memo(
|
|
|
1629
1951
|
}
|
|
1630
1952
|
scrollToBottom();
|
|
1631
1953
|
markMessageAsRead(newMessage);
|
|
1954
|
+
latestMessageRef.current = newMessage;
|
|
1632
1955
|
} else {
|
|
1633
|
-
|
|
1634
|
-
|
|
1956
|
+
const lastMsg = messagesContentListRef.current[0];
|
|
1957
|
+
|
|
1958
|
+
// Helper to process the message after checking conversation state
|
|
1959
|
+
const processMessage = (isSequenceCorrect: boolean) => {
|
|
1960
|
+
if (isSequenceCorrect && temporaryMessageListRef.current.length === 0) {
|
|
1961
|
+
if (!skipAddToList) addToMessageList(newMessage);
|
|
1962
|
+
latestMessageRef.current = newMessage;
|
|
1963
|
+
} else {
|
|
1964
|
+
temporaryMessageListRef.current = [newMessage, ...temporaryMessageListRef.current];
|
|
1965
|
+
}
|
|
1966
|
+
setUnreadCount((prev) => prev + 1);
|
|
1967
|
+
};
|
|
1968
|
+
|
|
1969
|
+
let conversationWith = "";
|
|
1970
|
+
const conversationType = newMessage.getReceiverType();
|
|
1971
|
+
|
|
1972
|
+
if (conversationType === CometChat.RECEIVER_TYPE.USER) {
|
|
1973
|
+
const senderUid = newMessage.getSender()?.getUid();
|
|
1974
|
+
conversationWith =
|
|
1975
|
+
senderUid === loggedInUser.current?.getUid()
|
|
1976
|
+
? newMessage.getReceiverId()
|
|
1977
|
+
: senderUid;
|
|
1978
|
+
} else {
|
|
1979
|
+
conversationWith = newMessage.getReceiverId();
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
/**
|
|
1983
|
+
* Sequence Integrity Check for New Message Handling
|
|
1984
|
+
*
|
|
1985
|
+
* Purpose:
|
|
1986
|
+
* Ensures message sequence integrity when appending new messages to the chat list while the user is scrolled up.
|
|
1987
|
+
* Prevents silent gaps in the conversation history due to network latency or missed real-time events.
|
|
1988
|
+
*
|
|
1989
|
+
* Implementation:
|
|
1990
|
+
* Fetches the latest conversation state from the server to compare the local last message ID with the server's last message ID.
|
|
1991
|
+
* If they match, the sequence is intact and the message can be safely appended to the visible list.
|
|
1992
|
+
* If they differ, a gap exists, and the message is buffered in the temporary list to prompt the user to load missing messages.
|
|
1993
|
+
*
|
|
1994
|
+
* Performance Considerations:
|
|
1995
|
+
* This asynchronous operation is conditionally executed only when the user is not at the bottom of the chat,
|
|
1996
|
+
* minimizing unnecessary network calls during active scrolling or bottom-positioned interactions.
|
|
1997
|
+
* A fallback mechanism reverts to local state comparison if the network request fails, ensuring robustness.
|
|
1998
|
+
*/
|
|
1999
|
+
CometChat.getConversation(conversationWith, conversationType)
|
|
2000
|
+
.then((conversation) => {
|
|
2001
|
+
const convLastMsg = conversation?.getLastMessage();
|
|
2002
|
+
// Check if the last message in our list matches the conversation's last message
|
|
2003
|
+
// This ensures we don't have a gap
|
|
2004
|
+
// THE CORE LOGIC:
|
|
2005
|
+
// Does the ID of the last message in our list (lastMsg)
|
|
2006
|
+
// MATCH the ID of the last message the server knows about (convLastMsg)?
|
|
2007
|
+
const isSequenceCorrect =
|
|
2008
|
+
lastMsg && convLastMsg && lastMsg.getId() === convLastMsg.getId();
|
|
2009
|
+
processMessage(isSequenceCorrect);
|
|
2010
|
+
})
|
|
2011
|
+
.catch((e) => {
|
|
2012
|
+
console.log("Error fetching conversation in bottomHandler", e);
|
|
2013
|
+
// Fall back to checking our local variable latestMessageRef.
|
|
2014
|
+
const isLatest =
|
|
2015
|
+
lastMsg &&
|
|
2016
|
+
latestMessageRef.current &&
|
|
2017
|
+
lastMsg.getId() === latestMessageRef.current.getId();
|
|
2018
|
+
processMessage(isLatest);
|
|
2019
|
+
});
|
|
1635
2020
|
}
|
|
1636
2021
|
};
|
|
1637
2022
|
|
|
1638
2023
|
const addToMessageList = async (newMessage: CometChat.BaseMessage) => {
|
|
1639
|
-
|
|
2024
|
+
// Handle incoming messages and prevent duplicate key errors
|
|
2025
|
+
if (isAgenticUser && !conversationId.current) {
|
|
1640
2026
|
if (newMessage.getConversationId()) {
|
|
1641
2027
|
conversationId.current = newMessage.getConversationId();
|
|
1642
2028
|
} else if (!parentMessageId) {
|
|
@@ -1649,11 +2035,7 @@ export const CometChatMessageList = memo(
|
|
|
1649
2035
|
conversationId.current = newMessage.getConversationId();
|
|
1650
2036
|
}
|
|
1651
2037
|
|
|
1652
|
-
//
|
|
1653
|
-
// De-duplication / in-place update logic
|
|
1654
|
-
// ----------------------------------------------------------------------------------
|
|
1655
|
-
// Fix: Before inserting, check for an existing message with matching id OR muid.
|
|
1656
|
-
// If found, update it in place instead of inserting again.
|
|
2038
|
+
// Prevent duplicate messages by checking existing messages
|
|
1657
2039
|
if (!isAgenticUser) {
|
|
1658
2040
|
try {
|
|
1659
2041
|
const incomingId = typeof (newMessage as any)?.getId === 'function' ? (newMessage as any).getId() : (newMessage as any)?.id;
|
|
@@ -1667,13 +2049,13 @@ export const CometChatMessageList = memo(
|
|
|
1667
2049
|
);
|
|
1668
2050
|
});
|
|
1669
2051
|
if (existingIndex !== -1) {
|
|
1670
|
-
// Update existing message instead of duplicating
|
|
2052
|
+
// Update existing message instead of duplicating
|
|
1671
2053
|
const updatedList = [...messagesContentListRef.current];
|
|
1672
2054
|
updatedList[existingIndex] = CommonUtils.clone(newMessage);
|
|
1673
2055
|
messagesContentListRef.current = updatedList;
|
|
1674
2056
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1675
2057
|
setMessagesList(updatedList);
|
|
1676
|
-
return;
|
|
2058
|
+
return;
|
|
1677
2059
|
}
|
|
1678
2060
|
} catch (e) {
|
|
1679
2061
|
console.log("Error in message de-duplication:", e);
|
|
@@ -1704,21 +2086,43 @@ export const CometChatMessageList = memo(
|
|
|
1704
2086
|
return;
|
|
1705
2087
|
}
|
|
1706
2088
|
}
|
|
1707
|
-
|
|
1708
|
-
|
|
1709
|
-
|
|
2089
|
+
// Check for message sequence gaps and skip for own messages
|
|
2090
|
+
const isOwnMessage = (newMessage.getSender()?.getUid() || (newMessage as any)?.["sender"]?.["uid"]) === loggedInUser.current?.["uid"];
|
|
2091
|
+
|
|
2092
|
+
if (!isOwnMessage &&
|
|
2093
|
+
latestMessageRef.current !== null &&
|
|
2094
|
+
messagesContentListRef.current.length > 0
|
|
1710
2095
|
) {
|
|
1711
|
-
|
|
1712
|
-
|
|
1713
|
-
|
|
1714
|
-
|
|
1715
|
-
|
|
2096
|
+
const firstMsg = messagesContentListRef.current[0];
|
|
2097
|
+
const firstMsgId = firstMsg?.getId?.();
|
|
2098
|
+
const firstMsgMuid = firstMsg?.getMuid?.() || (firstMsg as any)?.muid;
|
|
2099
|
+
const latestMsgId = latestMessageRef.current?.getId?.();
|
|
2100
|
+
const latestMsgMuid = latestMessageRef.current?.getMuid?.() || (latestMessageRef.current as any)?.muid;
|
|
2101
|
+
|
|
2102
|
+
const hasGap = (firstMsgId && latestMsgId && String(firstMsgId) !== String(latestMsgId)) &&
|
|
2103
|
+
(firstMsgMuid && latestMsgMuid && String(firstMsgMuid) !== String(latestMsgMuid));
|
|
2104
|
+
|
|
2105
|
+
if (hasGap) {
|
|
2106
|
+
reachedFirstMessage.current = false;
|
|
2107
|
+
msgRequestBuilder.current?.setMessageId(0);
|
|
2108
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
2109
|
+
messagesContentListRef.current = [];
|
|
2110
|
+
await getPreviousMessages();
|
|
2111
|
+
}
|
|
1716
2112
|
}
|
|
1717
2113
|
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
1718
2114
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
2115
|
+
// Update latestMessageRef for gap detection
|
|
1719
2116
|
latestMessageRef.current = newMessage;
|
|
2117
|
+
|
|
2118
|
+
// Batch state updates for better performance
|
|
2119
|
+
batchStateUpdates(() => {
|
|
2120
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
2121
|
+
if (hideScrollToBottomButton === false && unreadCount < 1 && !hasTargetMessageId) {
|
|
2122
|
+
setHideScrollToBottomButton(true);
|
|
2123
|
+
}
|
|
2124
|
+
});
|
|
1720
2125
|
aMessageWasSentByMeRef.current = true;
|
|
1721
|
-
setMessagesList((prev) => [newMessage, ...prev]);
|
|
1722
2126
|
};
|
|
1723
2127
|
|
|
1724
2128
|
const markParentMessageAsRead = (message: CometChat.BaseMessage) => {
|
|
@@ -1744,6 +2148,7 @@ export const CometChatMessageList = memo(
|
|
|
1744
2148
|
} else condition = (msg) => msg.getId() == editedMessage.getId();
|
|
1745
2149
|
let msgIndex = messagesContentListRef.current.findIndex(condition);
|
|
1746
2150
|
if (msgIndex > -1) {
|
|
2151
|
+
|
|
1747
2152
|
let tmpList = [...messagesContentListRef.current];
|
|
1748
2153
|
if (editedMessage.getCategory() === MessageCategoryConstants.interactive) {
|
|
1749
2154
|
//todo show unsupported bubble
|
|
@@ -1779,12 +2184,11 @@ export const CometChatMessageList = memo(
|
|
|
1779
2184
|
.catch((rej: any) => {
|
|
1780
2185
|
deleteItem.current = undefined;
|
|
1781
2186
|
setShowDeleteModal(false);
|
|
1782
|
-
console.log(rej);
|
|
1783
2187
|
onError && onError(rej);
|
|
1784
2188
|
});
|
|
1785
2189
|
};
|
|
1786
2190
|
|
|
1787
|
-
const createActionMessage = () => {};
|
|
2191
|
+
const createActionMessage = () => { };
|
|
1788
2192
|
|
|
1789
2193
|
const updateMessageReceipt = (receipt: any) => {
|
|
1790
2194
|
if (
|
|
@@ -1856,16 +2260,52 @@ export const CometChatMessageList = memo(
|
|
|
1856
2260
|
},
|
|
1857
2261
|
});
|
|
1858
2262
|
CometChat.getLoggedinUser()
|
|
1859
|
-
.then((u: any) => {
|
|
2263
|
+
.then(async (u: any) => {
|
|
1860
2264
|
loggedInUser.current = u;
|
|
1861
|
-
if (isAgenticUser
|
|
2265
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1862
2266
|
messageRequest.current = null;
|
|
1863
2267
|
} else {
|
|
1864
2268
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1865
2269
|
}
|
|
1866
|
-
if (!isAgenticUser
|
|
2270
|
+
if (!isAgenticUser || (isAgenticUser && parentMessageId)) {
|
|
1867
2271
|
if (goToMessageId) {
|
|
1868
2272
|
getMessagesAroundId(goToMessageId);
|
|
2273
|
+
} else if (startFromUnreadMessages) {
|
|
2274
|
+
|
|
2275
|
+
|
|
2276
|
+
try {
|
|
2277
|
+
const convId = user?.getUid() ?? group?.getGuid();
|
|
2278
|
+
const conversationType = user
|
|
2279
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
2280
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
2281
|
+
|
|
2282
|
+
|
|
2283
|
+
if (convId && conversationType) {
|
|
2284
|
+
|
|
2285
|
+
const conversation = await CometChat.getConversation(
|
|
2286
|
+
convId,
|
|
2287
|
+
conversationType
|
|
2288
|
+
);
|
|
2289
|
+
if (conversation.getUnreadMessageCount() > 0) {
|
|
2290
|
+
setUnreadCount(conversation.getUnreadMessageCount());
|
|
2291
|
+
const lastReadMessageId = conversation.getLastReadMessageId();
|
|
2292
|
+
//if lastReadMessageId is 0, it means no messages have been read yet
|
|
2293
|
+
if (lastReadMessageId && Number(lastReadMessageId) !== 0) {
|
|
2294
|
+
getMessagesAroundId(String(lastReadMessageId));
|
|
2295
|
+
} else {
|
|
2296
|
+
getPreviousMessages();
|
|
2297
|
+
}
|
|
2298
|
+
} else {
|
|
2299
|
+
getPreviousMessages();
|
|
2300
|
+
}
|
|
2301
|
+
} else {
|
|
2302
|
+
getPreviousMessages();
|
|
2303
|
+
}
|
|
2304
|
+
} catch (e) {
|
|
2305
|
+
console.log("Error while getting conversation", e);
|
|
2306
|
+
|
|
2307
|
+
getPreviousMessages();
|
|
2308
|
+
}
|
|
1869
2309
|
} else {
|
|
1870
2310
|
getPreviousMessages();
|
|
1871
2311
|
}
|
|
@@ -1952,7 +2392,7 @@ export const CometChatMessageList = memo(
|
|
|
1952
2392
|
);
|
|
1953
2393
|
|
|
1954
2394
|
useEffect(() => {
|
|
1955
|
-
if (isAgenticUser
|
|
2395
|
+
if (isAgenticUser) {
|
|
1956
2396
|
agenticParentMessageIdRef.current = undefined;
|
|
1957
2397
|
}
|
|
1958
2398
|
}, [user?.getUid(), group?.getGuid(), isAgenticUser]);
|
|
@@ -1961,7 +2401,7 @@ export const CometChatMessageList = memo(
|
|
|
1961
2401
|
//add listeners
|
|
1962
2402
|
|
|
1963
2403
|
// AI Assistant listener for agent chats
|
|
1964
|
-
if (isAgenticUser
|
|
2404
|
+
if (isAgenticUser && user && (!parentMessageId || (parentMessageId && isAgenticUser))) {
|
|
1965
2405
|
CometChat.addAIAssistantListener(streamListenerId, {
|
|
1966
2406
|
onAIAssistantEventReceived: (message: CometChat.AIAssistantBaseEvent) => {
|
|
1967
2407
|
if (
|
|
@@ -1985,33 +2425,32 @@ export const CometChatMessageList = memo(
|
|
|
1985
2425
|
(aiAssistantMessage, aiToolResultMessage, aiToolArgumentMessage) => {
|
|
1986
2426
|
const replacement = aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1987
2427
|
if (!replacement) return;
|
|
1988
|
-
console.log("replacement", replacement);
|
|
1989
2428
|
|
|
1990
2429
|
const replacementId = typeof (replacement as any)?.getId === 'function' ? (replacement as any).getId() : (replacement as any)?.id;
|
|
1991
2430
|
const replacementRunId = (replacement as any)?.data?.runId;
|
|
1992
|
-
|
|
1993
|
-
if(messagesContentListRef.current?.[0]?.isStreamMessage && messagesContentListRef.current?.[0]?.targetMessageId === runId){
|
|
2431
|
+
|
|
2432
|
+
if (messagesContentListRef.current?.[0]?.isStreamMessage && messagesContentListRef.current?.[0]?.targetMessageId === runId) {
|
|
1994
2433
|
latestMessageRef.current = replacement;
|
|
1995
2434
|
}
|
|
1996
|
-
|
|
2435
|
+
|
|
1997
2436
|
const list = messagesContentListRef.current;
|
|
1998
2437
|
let updatedList: any[];
|
|
1999
|
-
|
|
2438
|
+
|
|
2000
2439
|
// Find indices in one pass
|
|
2001
2440
|
const existingIndex = list.findIndex((msg) => {
|
|
2002
2441
|
const msgId = typeof (msg as any)?.getId === 'function' ? (msg as any).getId() : (msg as any)?.id;
|
|
2003
2442
|
return msgId && String(msgId) === String(replacementId);
|
|
2004
2443
|
});
|
|
2005
|
-
|
|
2006
|
-
const streamIndex = existingIndex === -1 ? list.findIndex((msg) =>
|
|
2444
|
+
|
|
2445
|
+
const streamIndex = existingIndex === -1 ? list.findIndex((msg) =>
|
|
2007
2446
|
(msg as any).isStreamMessage === true && (msg as any).targetMessageId === runId
|
|
2008
2447
|
) : -1;
|
|
2009
|
-
|
|
2448
|
+
|
|
2010
2449
|
const matchingIndex = (existingIndex === -1 && streamIndex === -1) ? list.findIndex((msg) => {
|
|
2011
2450
|
const msgRunId = (msg as any)?.data?.runId;
|
|
2012
2451
|
return msgRunId && String(msgRunId) === String(replacementRunId);
|
|
2013
2452
|
}) : -1;
|
|
2014
|
-
|
|
2453
|
+
|
|
2015
2454
|
// Update list based on what we found
|
|
2016
2455
|
if (existingIndex !== -1) {
|
|
2017
2456
|
// Update existing message
|
|
@@ -2027,8 +2466,7 @@ export const CometChatMessageList = memo(
|
|
|
2027
2466
|
// Add at beginning
|
|
2028
2467
|
updatedList = [replacement, ...list];
|
|
2029
2468
|
}
|
|
2030
|
-
|
|
2031
|
-
console.log("updatedList", updatedList);
|
|
2469
|
+
|
|
2032
2470
|
messagesContentListRef.current = updatedList;
|
|
2033
2471
|
setMessagesList(updatedList);
|
|
2034
2472
|
onLoad && onLoad([...updatedList].reverse());
|
|
@@ -2081,13 +2519,23 @@ export const CometChatMessageList = memo(
|
|
|
2081
2519
|
CometChatUIEventHandler.addMessageListener(messageEventListener, {
|
|
2082
2520
|
ccMessageSent: ({ message, status }: any) => {
|
|
2083
2521
|
if (status == MessageStatusConstants.inprogress) {
|
|
2522
|
+
// Remove incomplete stream messages before adding new user message (for agentic users)
|
|
2523
|
+
if (isAgenticUser) {
|
|
2524
|
+
const filteredList = messagesContentListRef.current.filter(
|
|
2525
|
+
(msg) => !(msg as any).isStreamMessage
|
|
2526
|
+
);
|
|
2527
|
+
if (filteredList.length !== messagesContentListRef.current.length) {
|
|
2528
|
+
messagesContentListRef.current = filteredList;
|
|
2529
|
+
setMessagesList(filteredList);
|
|
2530
|
+
}
|
|
2531
|
+
}
|
|
2084
2532
|
newMessage(message, false);
|
|
2085
2533
|
}
|
|
2086
2534
|
|
|
2087
2535
|
if (status == MessageStatusConstants.success) {
|
|
2088
2536
|
messageEdited(message, true);
|
|
2089
2537
|
if (
|
|
2090
|
-
isAgenticUser
|
|
2538
|
+
isAgenticUser &&
|
|
2091
2539
|
agenticParentMessageIdRef.current === undefined &&
|
|
2092
2540
|
messagesList.length !== 0 &&
|
|
2093
2541
|
message.getType() === MessageTypeConstants.text &&
|
|
@@ -2095,7 +2543,7 @@ export const CometChatMessageList = memo(
|
|
|
2095
2543
|
) {
|
|
2096
2544
|
agenticParentMessageIdRef.current = String(message.getId());
|
|
2097
2545
|
}
|
|
2098
|
-
if (isAgenticUser
|
|
2546
|
+
if (isAgenticUser && agenticParentMessageIdRef.current !== undefined) {
|
|
2099
2547
|
const streamMessage = createStreamMessage(message);
|
|
2100
2548
|
addToMessageList(streamMessage);
|
|
2101
2549
|
}
|
|
@@ -2118,12 +2566,12 @@ export const CometChatMessageList = memo(
|
|
|
2118
2566
|
}
|
|
2119
2567
|
},
|
|
2120
2568
|
onTextMessageReceived: (textMessage: any) => {
|
|
2121
|
-
if (isAgenticUser
|
|
2569
|
+
if (isAgenticUser) {
|
|
2122
2570
|
if (
|
|
2123
2571
|
textMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2124
2572
|
textMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2125
2573
|
textMessage.getCategory?.() ===
|
|
2126
|
-
|
|
2574
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2127
2575
|
) {
|
|
2128
2576
|
newMessage(textMessage);
|
|
2129
2577
|
}
|
|
@@ -2132,12 +2580,12 @@ export const CometChatMessageList = memo(
|
|
|
2132
2580
|
}
|
|
2133
2581
|
},
|
|
2134
2582
|
onMediaMessageReceived: (mediaMessage: any) => {
|
|
2135
|
-
if (isAgenticUser
|
|
2583
|
+
if (isAgenticUser) {
|
|
2136
2584
|
if (
|
|
2137
2585
|
mediaMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2138
2586
|
mediaMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2139
2587
|
mediaMessage.getCategory?.() ===
|
|
2140
|
-
|
|
2588
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2141
2589
|
) {
|
|
2142
2590
|
newMessage(mediaMessage);
|
|
2143
2591
|
}
|
|
@@ -2146,12 +2594,12 @@ export const CometChatMessageList = memo(
|
|
|
2146
2594
|
}
|
|
2147
2595
|
},
|
|
2148
2596
|
onCustomMessageReceived: (customMessage: any) => {
|
|
2149
|
-
if (isAgenticUser
|
|
2597
|
+
if (isAgenticUser) {
|
|
2150
2598
|
if (
|
|
2151
2599
|
customMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2152
2600
|
customMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2153
2601
|
customMessage.getCategory?.() ===
|
|
2154
|
-
|
|
2602
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2155
2603
|
) {
|
|
2156
2604
|
newMessage(customMessage);
|
|
2157
2605
|
}
|
|
@@ -2165,14 +2613,19 @@ export const CometChatMessageList = memo(
|
|
|
2165
2613
|
onMessagesRead: (messageReceipt: any) => {
|
|
2166
2614
|
updateMessageReceipt(messageReceipt);
|
|
2167
2615
|
},
|
|
2616
|
+
//suraj
|
|
2168
2617
|
onMessageDeleted: (deletedMessage: any) => {
|
|
2618
|
+
// If the deleted message was unread, decrement the unread count
|
|
2619
|
+
if (!deletedMessage.getReadAt?.() && deletedMessage.getSender()?.getUid() !== loggedInUser.current?.getUid()) {
|
|
2620
|
+
setUnreadCount(prev => Math.max(0, prev - 1));
|
|
2621
|
+
}
|
|
2169
2622
|
messageEdited(deletedMessage);
|
|
2170
2623
|
},
|
|
2171
2624
|
onMessageEdited: (editedMessage: any) => {
|
|
2172
2625
|
messageEdited(editedMessage);
|
|
2173
2626
|
},
|
|
2174
2627
|
onMessageModerated: (moderatedMessage: any) => {
|
|
2175
|
-
!isAgenticUser
|
|
2628
|
+
!isAgenticUser && messageEdited(moderatedMessage);
|
|
2176
2629
|
},
|
|
2177
2630
|
onFormMessageReceived: (formMessage: any) => {
|
|
2178
2631
|
newMessage(formMessage);
|
|
@@ -2194,8 +2647,8 @@ export const CometChatMessageList = memo(
|
|
|
2194
2647
|
const runIdFromData = assistantData && typeof assistantData.getRunId === 'function' ? assistantData.getRunId() : null;
|
|
2195
2648
|
const runIdFromId = typeof aiAssistantMessage.getId === 'function' ? aiAssistantMessage.getId() : (aiAssistantMessage as any)?.id;
|
|
2196
2649
|
const runId = runIdFromData || runIdFromId;
|
|
2197
|
-
|
|
2198
2650
|
const parentMsgId = typeof aiAssistantMessage.getParentMessageId === 'function' ? aiAssistantMessage.getParentMessageId() : (aiAssistantMessage as any)?.parentMessageId;
|
|
2651
|
+
|
|
2199
2652
|
if (
|
|
2200
2653
|
parentMessageId &&
|
|
2201
2654
|
String(parentMessageId) !== String(parentMsgId)
|
|
@@ -2323,15 +2776,13 @@ export const CometChatMessageList = memo(
|
|
|
2323
2776
|
connectionListenerId,
|
|
2324
2777
|
new CometChat.ConnectionListener({
|
|
2325
2778
|
onConnected: () => {
|
|
2326
|
-
console.log("CONNECTED...");
|
|
2327
2779
|
streamOnConnected();
|
|
2328
2780
|
if (lastID.current) {
|
|
2329
2781
|
getUpdatedPreviousMessages();
|
|
2330
2782
|
}
|
|
2331
2783
|
},
|
|
2332
|
-
inConnecting: () => {},
|
|
2784
|
+
inConnecting: () => { },
|
|
2333
2785
|
onDisconnected: () => {
|
|
2334
|
-
console.log("DISCONNECTED...");
|
|
2335
2786
|
streamOnDisconnected();
|
|
2336
2787
|
if (!messagesList[0].id) {
|
|
2337
2788
|
for (let i = 0; i < messagesList.length; i++) {
|
|
@@ -2356,7 +2807,7 @@ export const CometChatMessageList = memo(
|
|
|
2356
2807
|
CometChat.removeGroupListener(groupListenerId);
|
|
2357
2808
|
CometChat.removeCallListener(callListenerId);
|
|
2358
2809
|
CometChat.removeConnectionListener(connectionListenerId);
|
|
2359
|
-
if (isAgenticUser
|
|
2810
|
+
if (isAgenticUser) {
|
|
2360
2811
|
CometChat.removeAIAssistantListener(streamListenerId);
|
|
2361
2812
|
if (streamSubscriptionRef.current) {
|
|
2362
2813
|
streamSubscriptionRef.current.unsubscribe();
|
|
@@ -2389,6 +2840,7 @@ export const CometChatMessageList = memo(
|
|
|
2389
2840
|
setShowReactionList(true);
|
|
2390
2841
|
}
|
|
2391
2842
|
}, [selectedEmoji]);
|
|
2843
|
+
|
|
2392
2844
|
useImperativeHandle(ref, () => {
|
|
2393
2845
|
return {
|
|
2394
2846
|
addMessage: newMessage,
|
|
@@ -2511,7 +2963,7 @@ export const CometChatMessageList = memo(
|
|
|
2511
2963
|
avatarVisibility &&
|
|
2512
2964
|
(alignment === "leftAligned" ||
|
|
2513
2965
|
(isIncomingMessage && !user) ||
|
|
2514
|
-
(isAgenticUser
|
|
2966
|
+
(isAgenticUser && isIncomingMessage));
|
|
2515
2967
|
|
|
2516
2968
|
if (shouldShowAvatar) {
|
|
2517
2969
|
return (
|
|
@@ -2609,7 +3061,7 @@ export const CometChatMessageList = memo(
|
|
|
2609
3061
|
item.getEditedAt?.() &&
|
|
2610
3062
|
(item as CometChat.BaseMessage).getType() === MessageTypeConstants.text;
|
|
2611
3063
|
|
|
2612
|
-
const shouldShowTimestamp = isAgenticUser
|
|
3064
|
+
const shouldShowTimestamp = isAgenticUser ? isOutgoingMessage : !hideTimestamp;
|
|
2613
3065
|
return (
|
|
2614
3066
|
<View>
|
|
2615
3067
|
<View
|
|
@@ -2640,7 +3092,7 @@ export const CometChatMessageList = memo(
|
|
|
2640
3092
|
timeStamp={
|
|
2641
3093
|
!hideTimestamp
|
|
2642
3094
|
? (item.getDeletedAt() || item.getSentAt()) * 1000 ||
|
|
2643
|
-
|
|
3095
|
+
getSentAtTimestamp(item)
|
|
2644
3096
|
: undefined
|
|
2645
3097
|
}
|
|
2646
3098
|
pattern={"timeFormat"}
|
|
@@ -2649,9 +3101,9 @@ export const CometChatMessageList = memo(
|
|
|
2649
3101
|
/>
|
|
2650
3102
|
)}
|
|
2651
3103
|
{receiptsVisibility &&
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
3104
|
+
alignment !== "leftAligned" &&
|
|
3105
|
+
isOutgoingMessage &&
|
|
3106
|
+
!item.getDeletedAt?.() ? (
|
|
2655
3107
|
<View style={{ marginLeft: 2, alignItems: "center", justifyContent: "center" }}>
|
|
2656
3108
|
<CometChatReceipt
|
|
2657
3109
|
receipt={messageState}
|
|
@@ -2677,6 +3129,94 @@ export const CometChatMessageList = memo(
|
|
|
2677
3129
|
[mergedTheme, isAgenticUser, hideTimestamp]
|
|
2678
3130
|
);
|
|
2679
3131
|
|
|
3132
|
+
const reactToMessage = (emoji: string, messageObj?: CometChat.BaseMessage) => {
|
|
3133
|
+
const originalMessage = messageObj || selectedMessage;
|
|
3134
|
+
const msgObj = CommonUtils.clone(originalMessage);
|
|
3135
|
+
|
|
3136
|
+
if (!msgObj.getId() && originalMessage?.getId()) {
|
|
3137
|
+
msgObj.getId = () => originalMessage.getId();
|
|
3138
|
+
}
|
|
3139
|
+
|
|
3140
|
+
const messageId = msgObj?.getId();
|
|
3141
|
+
const reactions = msgObj?.getReactions() || [];
|
|
3142
|
+
const emojiObject = reactions?.find((reaction: any) => {
|
|
3143
|
+
return reaction?.reaction == emoji;
|
|
3144
|
+
});
|
|
3145
|
+
|
|
3146
|
+
if (emojiObject && emojiObject?.getReactedByMe()) {
|
|
3147
|
+
const updatedReactions: any[] = [];
|
|
3148
|
+
reactions.forEach((reaction: any) => {
|
|
3149
|
+
if (reaction?.getReaction() == emoji) {
|
|
3150
|
+
if (reaction?.getCount() === 1) {
|
|
3151
|
+
return;
|
|
3152
|
+
} else {
|
|
3153
|
+
reaction.setCount(reaction?.getCount() - 1);
|
|
3154
|
+
reaction.setReactedByMe(false);
|
|
3155
|
+
updatedReactions.push(reaction);
|
|
3156
|
+
}
|
|
3157
|
+
} else {
|
|
3158
|
+
updatedReactions.push(reaction);
|
|
3159
|
+
}
|
|
3160
|
+
});
|
|
3161
|
+
|
|
3162
|
+
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3163
|
+
newMessageObj.setReactions(updatedReactions);
|
|
3164
|
+
|
|
3165
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3166
|
+
message: newMessageObj,
|
|
3167
|
+
status: messageStatus.success,
|
|
3168
|
+
});
|
|
3169
|
+
|
|
3170
|
+
CometChat.removeReaction(messageId, emoji)
|
|
3171
|
+
.then((message: any) => { })
|
|
3172
|
+
.catch((error: any) => {
|
|
3173
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3174
|
+
message: msgObj,
|
|
3175
|
+
status: messageStatus.success,
|
|
3176
|
+
});
|
|
3177
|
+
});
|
|
3178
|
+
} else {
|
|
3179
|
+
const updatedReactions: any[] = [];
|
|
3180
|
+
const reactionAvailable = reactions.find((reaction: any) => {
|
|
3181
|
+
return reaction?.getReaction() == emoji;
|
|
3182
|
+
});
|
|
3183
|
+
|
|
3184
|
+
reactions.forEach((reaction: any) => {
|
|
3185
|
+
if (reaction?.getReaction() == emoji) {
|
|
3186
|
+
reaction.setCount(reaction?.getCount() + 1);
|
|
3187
|
+
reaction.setReactedByMe(true);
|
|
3188
|
+
updatedReactions.push(reaction);
|
|
3189
|
+
} else {
|
|
3190
|
+
updatedReactions.push(reaction);
|
|
3191
|
+
}
|
|
3192
|
+
});
|
|
3193
|
+
if (!reactionAvailable) {
|
|
3194
|
+
const react: CometChat.ReactionCount = new CometChat.ReactionCount(emoji, 1, true);
|
|
3195
|
+
updatedReactions.push(react);
|
|
3196
|
+
}
|
|
3197
|
+
|
|
3198
|
+
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3199
|
+
|
|
3200
|
+
newMessageObj.setReactions(updatedReactions);
|
|
3201
|
+
|
|
3202
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3203
|
+
message: newMessageObj,
|
|
3204
|
+
status: messageStatus.success,
|
|
3205
|
+
});
|
|
3206
|
+
|
|
3207
|
+
CometChat.addReaction(messageId, emoji)
|
|
3208
|
+
.then((response: any) => { })
|
|
3209
|
+
.catch((error: any) => {
|
|
3210
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3211
|
+
message: msgObj,
|
|
3212
|
+
status: messageStatus.success,
|
|
3213
|
+
});
|
|
3214
|
+
});
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
setShowMessageOptions([]);
|
|
3218
|
+
};
|
|
3219
|
+
|
|
2680
3220
|
const onReactionPress = useCallback(
|
|
2681
3221
|
(reaction: CometChat.ReactionCount, messageObject: CometChat.BaseMessage) => {
|
|
2682
3222
|
if (reaction.getReaction() == "All") {
|
|
@@ -2713,17 +3253,17 @@ export const CometChatMessageList = memo(
|
|
|
2713
3253
|
messageObject?.getReactions().length > 0;
|
|
2714
3254
|
return hasReaction
|
|
2715
3255
|
? (params: { maxContentWidth?: number }) => {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
3256
|
+
return (
|
|
3257
|
+
<CometChatReactions
|
|
3258
|
+
messageObject={messageObject}
|
|
3259
|
+
onReactionPress={onReactionPress}
|
|
3260
|
+
onReactionLongPress={onReactionLongPress}
|
|
3261
|
+
alignment={alignment}
|
|
3262
|
+
style={getCurrentBubbleStyle(messageObject).reactionStyles}
|
|
3263
|
+
maxContentWidth={params?.maxContentWidth}
|
|
3264
|
+
/>
|
|
3265
|
+
);
|
|
3266
|
+
}
|
|
2727
3267
|
: null;
|
|
2728
3268
|
},
|
|
2729
3269
|
[mergedTheme]
|
|
@@ -2735,7 +3275,7 @@ export const CometChatMessageList = memo(
|
|
|
2735
3275
|
if (
|
|
2736
3276
|
alignment == "standard" &&
|
|
2737
3277
|
(item.getSender()?.getUid() || item?.["sender"]?.["uid"]) ==
|
|
2738
|
-
|
|
3278
|
+
loggedInUser.current?.getUid()
|
|
2739
3279
|
)
|
|
2740
3280
|
return "right";
|
|
2741
3281
|
return "left";
|
|
@@ -2751,7 +3291,7 @@ export const CometChatMessageList = memo(
|
|
|
2751
3291
|
|
|
2752
3292
|
const openReportDialog = (message: any) => {
|
|
2753
3293
|
reportedMessageRef.current = message;
|
|
2754
|
-
// On iOS wait for BottomSheet modal dismiss animation
|
|
3294
|
+
// On iOS wait for BottomSheet modal dismiss animation to avoid flashing
|
|
2755
3295
|
if (Platform.OS === "ios") {
|
|
2756
3296
|
pendingReportRef.current = true;
|
|
2757
3297
|
} else {
|
|
@@ -2807,9 +3347,8 @@ export const CometChatMessageList = memo(
|
|
|
2807
3347
|
|
|
2808
3348
|
<Text
|
|
2809
3349
|
style={_style.threadedMessageStyles?.indicatorTextStyle}
|
|
2810
|
-
>{`${item.getReplyCount()} ${
|
|
2811
|
-
|
|
2812
|
-
}`}</Text>
|
|
3350
|
+
>{`${item.getReplyCount()} ${item.getReplyCount() > 1 ? t("REPLIES") : t("REPLY")
|
|
3351
|
+
}`}</Text>
|
|
2813
3352
|
<CometChatBadge
|
|
2814
3353
|
style={{
|
|
2815
3354
|
containerStyle: _style.threadedMessageStyles?.unreadCountStyle?.containerStyle,
|
|
@@ -2827,7 +3366,6 @@ export const CometChatMessageList = memo(
|
|
|
2827
3366
|
setShowMessageOptions([]);
|
|
2828
3367
|
CometChat.getUser(item.getSender().getUid())
|
|
2829
3368
|
.then((user: any) => {
|
|
2830
|
-
console.log({ user });
|
|
2831
3369
|
CometChatUIEventHandler.emitUIEvent("openChat", { user });
|
|
2832
3370
|
})
|
|
2833
3371
|
.catch((e: any) => {
|
|
@@ -2858,7 +3396,6 @@ export const CometChatMessageList = memo(
|
|
|
2858
3396
|
};
|
|
2859
3397
|
|
|
2860
3398
|
NativeModules.FileManager.shareMessage(shareObj, (callback: any) => {
|
|
2861
|
-
console.log("shareMessage Callback", callback);
|
|
2862
3399
|
});
|
|
2863
3400
|
};
|
|
2864
3401
|
|
|
@@ -2917,6 +3454,9 @@ export const CometChatMessageList = memo(
|
|
|
2917
3454
|
case MessageOptionConstants.shareMessage:
|
|
2918
3455
|
option.onPress = shareMedia.bind(this, item);
|
|
2919
3456
|
break;
|
|
3457
|
+
case MessageOptionConstants.markAsUnread:
|
|
3458
|
+
option.onPress = markMessageAsUnread.bind(this, item);
|
|
3459
|
+
break;
|
|
2920
3460
|
}
|
|
2921
3461
|
else {
|
|
2922
3462
|
// If overriding `onPress`, make sure to pass `item` explicitly
|
|
@@ -3004,7 +3544,7 @@ export const CometChatMessageList = memo(
|
|
|
3004
3544
|
}, [hasTemplate, isThreaded, getFooterView, message, bubbleAlignment]);
|
|
3005
3545
|
|
|
3006
3546
|
const ThreadedView = useMemo(() => {
|
|
3007
|
-
if (isAgenticUser
|
|
3547
|
+
if (isAgenticUser) return undefined;
|
|
3008
3548
|
return !isThreaded
|
|
3009
3549
|
? !message.getDeletedBy()
|
|
3010
3550
|
? getThreadView(message, bubbleAlignment)
|
|
@@ -3025,7 +3565,7 @@ export const CometChatMessageList = memo(
|
|
|
3025
3565
|
if (effectiveHideModeration) {
|
|
3026
3566
|
return hasTemplate?.BottomView && hasTemplate?.BottomView(message, bubbleAlignment);
|
|
3027
3567
|
} else {
|
|
3028
|
-
if (isOutgoing && moderationStatus === "disapproved" && !isAgenticUser
|
|
3568
|
+
if (isOutgoing && moderationStatus === "disapproved" && !isAgenticUser) {
|
|
3029
3569
|
return (
|
|
3030
3570
|
<ModerationBottomView
|
|
3031
3571
|
status={moderationStatus}
|
|
@@ -3062,6 +3602,7 @@ export const CometChatMessageList = memo(
|
|
|
3062
3602
|
if (!message.getId()) {
|
|
3063
3603
|
return;
|
|
3064
3604
|
}
|
|
3605
|
+
// console.log({hasTemplate});
|
|
3065
3606
|
|
|
3066
3607
|
setSelectedMessage(message);
|
|
3067
3608
|
hasTemplate && openOptionsForMessage(message, hasTemplate);
|
|
@@ -3075,7 +3616,7 @@ export const CometChatMessageList = memo(
|
|
|
3075
3616
|
const onReply = useCallback(() => {
|
|
3076
3617
|
if (message.getDeletedBy() != null) return;
|
|
3077
3618
|
if (!message.getId()) return;
|
|
3078
|
-
|
|
3619
|
+
|
|
3079
3620
|
CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
|
|
3080
3621
|
message: message,
|
|
3081
3622
|
status: messageStatus.inprogress,
|
|
@@ -3087,16 +3628,16 @@ export const CometChatMessageList = memo(
|
|
|
3087
3628
|
|
|
3088
3629
|
const handlePanGesture = useCallback((event: PanGestureHandlerGestureEvent) => {
|
|
3089
3630
|
const { translationX, velocityX } = event.nativeEvent;
|
|
3090
|
-
|
|
3631
|
+
|
|
3091
3632
|
// Only allow swiping from left to right for replies
|
|
3092
3633
|
if (translationX <= 0) return;
|
|
3093
|
-
|
|
3634
|
+
|
|
3094
3635
|
const swipeThreshold = 80; // Threshold to trigger reply
|
|
3095
3636
|
const maxSwipeDistance = 120; // Maximum swipe distance
|
|
3096
|
-
|
|
3637
|
+
|
|
3097
3638
|
// Calculate progress (0 to 1)
|
|
3098
3639
|
const progress = Math.min(translationX / maxSwipeDistance, 1);
|
|
3099
|
-
|
|
3640
|
+
|
|
3100
3641
|
// Update animated values
|
|
3101
3642
|
swipeAnimatedValue.setValue(Math.min(translationX, maxSwipeDistance));
|
|
3102
3643
|
replyIconOpacity.setValue(progress);
|
|
@@ -3104,10 +3645,10 @@ export const CometChatMessageList = memo(
|
|
|
3104
3645
|
|
|
3105
3646
|
const handlePanStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {
|
|
3106
3647
|
const { state, translationX, velocityX } = event.nativeEvent;
|
|
3107
|
-
|
|
3648
|
+
|
|
3108
3649
|
if (state === State.END) {
|
|
3109
3650
|
const swipeThreshold = 80;
|
|
3110
|
-
|
|
3651
|
+
|
|
3111
3652
|
// Reset animations
|
|
3112
3653
|
Animated.parallel([
|
|
3113
3654
|
Animated.spring(swipeAnimatedValue, {
|
|
@@ -3119,11 +3660,11 @@ export const CometChatMessageList = memo(
|
|
|
3119
3660
|
useNativeDriver: true,
|
|
3120
3661
|
}),
|
|
3121
3662
|
]).start();
|
|
3122
|
-
|
|
3663
|
+
|
|
3123
3664
|
const moderationStatus = getModerationStatus(message);
|
|
3124
3665
|
const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
3125
3666
|
if (isOutgoing && moderationStatus && moderationStatus !== "approved" && moderationStatus !== "unmoderated") return;
|
|
3126
|
-
|
|
3667
|
+
|
|
3127
3668
|
// Trigger reply if threshold is met
|
|
3128
3669
|
if (translationX > swipeThreshold || velocityX > 500) {
|
|
3129
3670
|
onReply();
|
|
@@ -3132,7 +3673,7 @@ export const CometChatMessageList = memo(
|
|
|
3132
3673
|
}, [onReply, message]);
|
|
3133
3674
|
|
|
3134
3675
|
return (
|
|
3135
|
-
message.getCategory() === MessageCategoryConstants.action ? (
|
|
3676
|
+
message.getCategory() === MessageCategoryConstants.action || isAgenticUser ? (
|
|
3136
3677
|
<View style={{ position: 'relative' }}>
|
|
3137
3678
|
<TouchableOpacity
|
|
3138
3679
|
activeOpacity={1}
|
|
@@ -3208,106 +3749,23 @@ export const CometChatMessageList = memo(
|
|
|
3208
3749
|
return item.getSentAt() ? item.getSentAt() * 1000 : Date.now();
|
|
3209
3750
|
}, []);
|
|
3210
3751
|
|
|
3211
|
-
const reactToMessage = (emoji: string, messageObj?: CometChat.BaseMessage) => {
|
|
3212
|
-
const msgObj = CommonUtils.clone(messageObj) || CommonUtils.clone(selectedMessage);
|
|
3213
|
-
|
|
3214
|
-
const messageId = msgObj?.getId();
|
|
3215
|
-
const reactions = msgObj?.getReactions() || [];
|
|
3216
|
-
const emojiObject = reactions?.find((reaction: any) => {
|
|
3217
|
-
return reaction?.reaction == emoji;
|
|
3218
|
-
});
|
|
3219
|
-
if (emojiObject && emojiObject?.getReactedByMe()) {
|
|
3220
|
-
const updatedReactions: any[] = [];
|
|
3221
|
-
reactions.forEach((reaction: any) => {
|
|
3222
|
-
if (reaction?.getReaction() == emoji) {
|
|
3223
|
-
if (reaction?.getCount() === 1) {
|
|
3224
|
-
return;
|
|
3225
|
-
} else {
|
|
3226
|
-
reaction.setCount(reaction?.getCount() - 1);
|
|
3227
|
-
reaction.setReactedByMe(false);
|
|
3228
|
-
updatedReactions.push(reaction);
|
|
3229
|
-
}
|
|
3230
|
-
} else {
|
|
3231
|
-
updatedReactions.push(reaction);
|
|
3232
|
-
}
|
|
3233
|
-
});
|
|
3234
|
-
|
|
3235
|
-
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3236
|
-
newMessageObj.setReactions(updatedReactions);
|
|
3237
|
-
|
|
3238
|
-
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3239
|
-
message: newMessageObj,
|
|
3240
|
-
status: messageStatus.success,
|
|
3241
|
-
});
|
|
3242
|
-
CometChat.removeReaction(messageId, emoji)
|
|
3243
|
-
.then((message: any) => {})
|
|
3244
|
-
.catch((error: any) => {
|
|
3245
|
-
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3246
|
-
message: msgObj,
|
|
3247
|
-
status: messageStatus.success,
|
|
3248
|
-
});
|
|
3249
|
-
console.log(error);
|
|
3250
|
-
});
|
|
3251
|
-
} else {
|
|
3252
|
-
const updatedReactions: any[] = [];
|
|
3253
|
-
const reactionAvailable = reactions.find((reaction: any) => {
|
|
3254
|
-
return reaction?.getReaction() == emoji;
|
|
3255
|
-
});
|
|
3256
|
-
reactions.forEach((reaction: any) => {
|
|
3257
|
-
if (reaction?.getReaction() == emoji) {
|
|
3258
|
-
reaction.setCount(reaction?.getCount() + 1);
|
|
3259
|
-
reaction.setReactedByMe(true);
|
|
3260
|
-
updatedReactions.push(reaction);
|
|
3261
|
-
} else {
|
|
3262
|
-
updatedReactions.push(reaction);
|
|
3263
|
-
}
|
|
3264
|
-
});
|
|
3265
|
-
if (!reactionAvailable) {
|
|
3266
|
-
const react: CometChat.ReactionCount = new CometChat.ReactionCount(emoji, 1, true);
|
|
3267
|
-
updatedReactions.push(react);
|
|
3268
|
-
}
|
|
3269
|
-
|
|
3270
|
-
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3271
|
-
|
|
3272
|
-
newMessageObj.setReactions(updatedReactions);
|
|
3273
|
-
|
|
3274
|
-
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3275
|
-
message: newMessageObj,
|
|
3276
|
-
status: messageStatus.success,
|
|
3277
|
-
});
|
|
3278
|
-
|
|
3279
|
-
CometChat.addReaction(messageId, emoji)
|
|
3280
|
-
.then((response: any) => {})
|
|
3281
|
-
.catch((error: any) => {
|
|
3282
|
-
console.log(error);
|
|
3283
|
-
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3284
|
-
message: msgObj,
|
|
3285
|
-
status: messageStatus.success,
|
|
3286
|
-
});
|
|
3287
|
-
});
|
|
3288
|
-
}
|
|
3289
|
-
|
|
3290
|
-
setShowMessageOptions([]);
|
|
3291
|
-
};
|
|
3292
3752
|
|
|
3293
|
-
|
|
3753
|
+
//extract once per item
|
|
3754
|
+
const sentAtToMs = useCallback((msg?: any): number | undefined => {
|
|
3294
3755
|
if (!msg) return undefined;
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
? msg.getSentAt()
|
|
3299
|
-
: (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
|
|
3756
|
+
const raw = typeof msg.getSentAt === "function"
|
|
3757
|
+
? msg.getSentAt()
|
|
3758
|
+
: (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
|
|
3300
3759
|
if (raw === undefined || raw === null) return undefined;
|
|
3301
|
-
// if raw looks like seconds (10 digits) convert to ms
|
|
3302
3760
|
return raw < 1e12 ? raw * 1000 : raw;
|
|
3303
|
-
};
|
|
3761
|
+
}, []);
|
|
3304
3762
|
|
|
3305
|
-
const makeDayKey = (ms?: number | undefined) => {
|
|
3763
|
+
const makeDayKey = useCallback((ms?: number | undefined) => {
|
|
3306
3764
|
if (!ms) return null;
|
|
3307
3765
|
const d = new Date(ms);
|
|
3308
3766
|
// use local date parts so "Today" follows user's timezone
|
|
3309
3767
|
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
|
3310
|
-
};
|
|
3768
|
+
}, []);
|
|
3311
3769
|
|
|
3312
3770
|
const messageDayKeys = useMemo(() => {
|
|
3313
3771
|
return messagesList.map((m) => {
|
|
@@ -3316,22 +3774,58 @@ export const CometChatMessageList = memo(
|
|
|
3316
3774
|
});
|
|
3317
3775
|
}, [messagesList]);
|
|
3318
3776
|
|
|
3319
|
-
|
|
3777
|
+
//extract once per item
|
|
3778
|
+
const isSameLocalDay = useCallback((ms?: number) => {
|
|
3320
3779
|
if (!ms) return false;
|
|
3321
|
-
const
|
|
3322
|
-
const
|
|
3780
|
+
const now = new Date();
|
|
3781
|
+
const date = new Date(ms);
|
|
3323
3782
|
return (
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3783
|
+
date.getFullYear() === now.getFullYear() &&
|
|
3784
|
+
date.getMonth() === now.getMonth() &&
|
|
3785
|
+
date.getDate() === now.getDate()
|
|
3327
3786
|
);
|
|
3328
|
-
};
|
|
3787
|
+
}, []);
|
|
3788
|
+
|
|
3789
|
+
// Memoize separator calculation with cache
|
|
3790
|
+
const separatorCache = useRef(new Map<string, boolean>());
|
|
3791
|
+
const shouldShowSeparator = useCallback((index: number, currentMs?: number, nextMs?: number) => {
|
|
3792
|
+
const cacheKey = `${index}-${currentMs}-${nextMs}`;
|
|
3793
|
+
|
|
3794
|
+
if (separatorCache.current.has(cacheKey)) {
|
|
3795
|
+
return separatorCache.current.get(cacheKey)!;
|
|
3796
|
+
}
|
|
3797
|
+
|
|
3798
|
+
const listLength = messagesContentListRef.current.length;
|
|
3799
|
+
|
|
3800
|
+
// Last item in small list
|
|
3801
|
+
if (index === listLength - 1 && listLength < SMALL_LIST_THRESHOLD) {
|
|
3802
|
+
separatorCache.current.set(cacheKey, true);
|
|
3803
|
+
return true;
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
// Different days
|
|
3807
|
+
if (currentMs && nextMs) {
|
|
3808
|
+
const currentDate = new Date(currentMs).getDate();
|
|
3809
|
+
const nextDate = new Date(nextMs).getDate();
|
|
3810
|
+
const result = currentDate !== nextDate;
|
|
3811
|
+
separatorCache.current.set(cacheKey, result);
|
|
3812
|
+
return result;
|
|
3813
|
+
}
|
|
3814
|
+
|
|
3815
|
+
separatorCache.current.set(cacheKey, false);
|
|
3816
|
+
return false;
|
|
3817
|
+
}, []);
|
|
3818
|
+
|
|
3819
|
+
// Clear cache when messages change
|
|
3820
|
+
useEffect(() => {
|
|
3821
|
+
separatorCache.current.clear();
|
|
3822
|
+
}, [messagesList.length]);
|
|
3329
3823
|
|
|
3330
|
-
const getDayHeaderString = (ms?: number | undefined) => {
|
|
3824
|
+
const getDayHeaderString = useCallback((ms?: number | undefined) => {
|
|
3331
3825
|
if (!ms) return undefined;
|
|
3332
3826
|
if (isSameLocalDay(ms)) return t("TODAY") || "Today";
|
|
3333
3827
|
return dateSeparatorPattern ? dateSeparatorPattern(ms) : undefined;
|
|
3334
|
-
};
|
|
3828
|
+
}, [isSameLocalDay, t, dateSeparatorPattern]);
|
|
3335
3829
|
|
|
3336
3830
|
const RenderMessageItem = useCallback(
|
|
3337
3831
|
({
|
|
@@ -3345,39 +3839,48 @@ export const CometChatMessageList = memo(
|
|
|
3345
3839
|
}) => {
|
|
3346
3840
|
const index = idx;
|
|
3347
3841
|
lastMessageDate.current = getSentAtTimestamp(item);
|
|
3348
|
-
|
|
3349
3842
|
const id = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3350
3843
|
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : (item as any)?.muid;
|
|
3351
|
-
|
|
3352
3844
|
return (
|
|
3353
3845
|
<React.Fragment key={`${id}_${muid}`}>
|
|
3354
3846
|
<MessageView message={item} currentIndex={index} />
|
|
3355
3847
|
</React.Fragment>
|
|
3356
3848
|
);
|
|
3357
3849
|
},
|
|
3358
|
-
[
|
|
3850
|
+
[] // Empty dependencies - MessageView handles its own memoization
|
|
3359
3851
|
);
|
|
3360
3852
|
|
|
3361
3853
|
const keyExtractor = useCallback((item: any, index: number) => {
|
|
3362
3854
|
// Safely check if methods exist before calling them
|
|
3363
3855
|
const id = typeof item?.getId === 'function' ? item.getId() : item?.id;
|
|
3364
3856
|
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : item?.muid;
|
|
3365
|
-
|
|
3857
|
+
|
|
3858
|
+
|
|
3859
|
+
// For stream messages in agentic mode, use a unique combination
|
|
3860
|
+
// to prevent duplicate keys when navigating between chat and history
|
|
3861
|
+
if (item?.isStreamMessage) {
|
|
3862
|
+
const targetId = item?.targetMessageId || '';
|
|
3863
|
+
return `stream_${id}_${targetId}_${index}`;
|
|
3864
|
+
}
|
|
3865
|
+
|
|
3366
3866
|
// Use id + muid if both exist
|
|
3367
3867
|
if (id && muid) {
|
|
3368
3868
|
return `${id}_${muid}`;
|
|
3369
3869
|
}
|
|
3370
|
-
|
|
3870
|
+
|
|
3871
|
+
|
|
3371
3872
|
// Use muid if id doesn't exist (pending message)
|
|
3372
3873
|
if (muid) {
|
|
3373
3874
|
return `muid_${muid}`;
|
|
3374
3875
|
}
|
|
3375
|
-
|
|
3876
|
+
|
|
3877
|
+
|
|
3376
3878
|
// Use id if muid doesn't exist
|
|
3377
3879
|
if (id) {
|
|
3378
3880
|
return `id_${id}`;
|
|
3379
3881
|
}
|
|
3380
|
-
|
|
3882
|
+
|
|
3883
|
+
|
|
3381
3884
|
// Fallback to index if neither exist (should not happen, but prevents duplicates)
|
|
3382
3885
|
if (__DEV__) {
|
|
3383
3886
|
console.warn('[MessageList] Message without id or muid at index:', index, item);
|
|
@@ -3385,7 +3888,7 @@ export const CometChatMessageList = memo(
|
|
|
3385
3888
|
return `index_${index}`;
|
|
3386
3889
|
}, []);
|
|
3387
3890
|
|
|
3388
|
-
const itemSeparator = useCallback(() => <View style={
|
|
3891
|
+
const itemSeparator = useCallback(() => <View style={staticStyles.itemSeparator} />, [staticStyles]);
|
|
3389
3892
|
|
|
3390
3893
|
const getAgentEmptyView = useCallback(() => {
|
|
3391
3894
|
if (!user) return <></>;
|
|
@@ -3406,45 +3909,23 @@ export const CometChatMessageList = memo(
|
|
|
3406
3909
|
|
|
3407
3910
|
return (
|
|
3408
3911
|
<ScrollView
|
|
3409
|
-
contentContainerStyle={
|
|
3410
|
-
flex: 1,
|
|
3411
|
-
justifyContent: "center",
|
|
3412
|
-
alignItems: "center",
|
|
3413
|
-
}}
|
|
3912
|
+
contentContainerStyle={staticStyles.emptyScrollView}
|
|
3414
3913
|
showsVerticalScrollIndicator={false}
|
|
3415
3914
|
>
|
|
3416
|
-
<View
|
|
3417
|
-
style={{
|
|
3418
|
-
alignItems: "center",
|
|
3419
|
-
justifyContent: "center",
|
|
3420
|
-
padding: 24,
|
|
3421
|
-
}}
|
|
3422
|
-
>
|
|
3915
|
+
<View style={staticStyles.emptyContainer}>
|
|
3423
3916
|
{emptyChatImageView || (
|
|
3424
3917
|
<CometChatAvatar
|
|
3425
3918
|
image={imageSource}
|
|
3426
3919
|
name={user.getName()}
|
|
3427
3920
|
style={{
|
|
3428
3921
|
containerStyle: {
|
|
3429
|
-
|
|
3430
|
-
height: 60,
|
|
3431
|
-
borderRadius: 40,
|
|
3432
|
-
marginBottom: 20,
|
|
3433
|
-
alignItems: "center",
|
|
3434
|
-
justifyContent: "center",
|
|
3922
|
+
...staticStyles.avatarContainer,
|
|
3435
3923
|
backgroundColor: mergedTheme.avatarStyle.containerStyle?.backgroundColor,
|
|
3436
3924
|
},
|
|
3437
|
-
imageStyle:
|
|
3438
|
-
width: 60,
|
|
3439
|
-
height: 60,
|
|
3440
|
-
borderRadius: 40,
|
|
3441
|
-
},
|
|
3925
|
+
imageStyle: staticStyles.avatarImage,
|
|
3442
3926
|
textStyle: {
|
|
3443
|
-
|
|
3444
|
-
fontWeight: "bold",
|
|
3927
|
+
...staticStyles.avatarText,
|
|
3445
3928
|
color: mergedTheme.avatarStyle.textStyle?.color,
|
|
3446
|
-
textAlign: "center",
|
|
3447
|
-
textAlignVertical: "center",
|
|
3448
3929
|
},
|
|
3449
3930
|
}}
|
|
3450
3931
|
/>
|
|
@@ -3627,28 +4108,37 @@ export const CometChatMessageList = memo(
|
|
|
3627
4108
|
if (group) {
|
|
3628
4109
|
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
3629
4110
|
}
|
|
3630
|
-
if (parentMessageId) {
|
|
3631
|
-
nextMessagesRequest = nextMessagesRequest.
|
|
4111
|
+
if (!parentMessageId) {
|
|
4112
|
+
nextMessagesRequest = nextMessagesRequest.hideReplies(true);
|
|
4113
|
+
}
|
|
4114
|
+
// Thread: Server includes only relevant messages
|
|
4115
|
+
else {
|
|
4116
|
+
nextMessagesRequest = nextMessagesRequest
|
|
4117
|
+
.setParentMessageId(Number(parentMessageId))
|
|
4118
|
+
.hideReplies(false);
|
|
4119
|
+
if (isAgenticUser) {
|
|
4120
|
+
nextMessagesRequest = nextMessagesRequest.withParent(true);
|
|
4121
|
+
}
|
|
3632
4122
|
}
|
|
3633
4123
|
|
|
3634
4124
|
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
3635
4125
|
if (nextMessages.length > 0) {
|
|
4126
|
+
|
|
3636
4127
|
const existingIds = new Set(messagesContentListRef.current.map(m => m.getId()));
|
|
3637
4128
|
const uniqueNewMessages = nextMessages.filter(m => !existingIds.has(m.getId()));
|
|
3638
|
-
|
|
4129
|
+
|
|
3639
4130
|
if (uniqueNewMessages.length > 0) {
|
|
3640
4131
|
const reversedNewMessages = uniqueNewMessages.reverse();
|
|
3641
4132
|
messagesContentListRef.current = [
|
|
3642
4133
|
...reversedNewMessages,
|
|
3643
4134
|
...messagesContentListRef.current
|
|
3644
4135
|
];
|
|
3645
|
-
|
|
4136
|
+
|
|
3646
4137
|
setMessagesList(messagesContentListRef.current);
|
|
3647
4138
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
3648
4139
|
}
|
|
3649
4140
|
} else {
|
|
3650
4141
|
setHasTargetMessageId(false);
|
|
3651
|
-
hasReachedBottomRef.current = true;
|
|
3652
4142
|
}
|
|
3653
4143
|
} catch (error) {
|
|
3654
4144
|
console.error('[fetchNextMessages] Error:', error);
|
|
@@ -3667,37 +4157,6 @@ export const CometChatMessageList = memo(
|
|
|
3667
4157
|
);
|
|
3668
4158
|
};
|
|
3669
4159
|
|
|
3670
|
-
const handleScroll = (event: any) => {
|
|
3671
|
-
if (loadingMessagesRef.current) {
|
|
3672
|
-
return;
|
|
3673
|
-
}
|
|
3674
|
-
|
|
3675
|
-
// For agent chats (non-thread), don't fetch previous messages when scrolling to top
|
|
3676
|
-
if (isAgenticUser() && !parentMessageId) {
|
|
3677
|
-
scrollHandler(event);
|
|
3678
|
-
return;
|
|
3679
|
-
}
|
|
3680
|
-
|
|
3681
|
-
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
|
|
3682
|
-
if (
|
|
3683
|
-
Math.floor(contentOffset.y) >= Math.floor(contentSize.height - layoutMeasurement.height)
|
|
3684
|
-
) {
|
|
3685
|
-
getPreviousMessages();
|
|
3686
|
-
}
|
|
3687
|
-
if (hasTargetMessageId && contentOffset.y <= 50) {
|
|
3688
|
-
fetchNextMessages();
|
|
3689
|
-
}
|
|
3690
|
-
scrollHandler(event);
|
|
3691
|
-
};
|
|
3692
|
-
|
|
3693
|
-
const shouldShowScrollToBottomButton = useCallback((event: any) => {
|
|
3694
|
-
const { contentOffset, contentSize } = event.nativeEvent;
|
|
3695
|
-
|
|
3696
|
-
currentScrollPosition.current.y = contentOffset.y;
|
|
3697
|
-
currentScrollPosition.current.contentHeight = contentSize.height;
|
|
3698
|
-
setHideScrollToBottomButton(isNearBottom());
|
|
3699
|
-
}, []);
|
|
3700
|
-
|
|
3701
4160
|
const scrollHandler = (event: any) => {
|
|
3702
4161
|
/********************************************************************************
|
|
3703
4162
|
* layoutMeasurement.height: The height of the visible area within the ScrollView.
|
|
@@ -3709,12 +4168,6 @@ export const CometChatMessageList = memo(
|
|
|
3709
4168
|
* contentSize.height: The total height of the scrollable content.
|
|
3710
4169
|
*********************************************************************************/
|
|
3711
4170
|
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
|
|
3712
|
-
const screenHeight = Dimensions.get("window").height;
|
|
3713
|
-
|
|
3714
|
-
// Calculate the scroll position
|
|
3715
|
-
const scrollPosition = layoutMeasurement.height + contentOffset.y;
|
|
3716
|
-
const scrollEndPosition = contentSize.height - screenHeight;
|
|
3717
|
-
|
|
3718
4171
|
currentScrollPosition.current.y = contentOffset.y;
|
|
3719
4172
|
currentScrollPosition.current.contentHeight = contentSize.height;
|
|
3720
4173
|
|
|
@@ -3725,82 +4178,238 @@ export const CometChatMessageList = memo(
|
|
|
3725
4178
|
currentScrollPosition.current.scrollViewHeight = contentSize.height;
|
|
3726
4179
|
}
|
|
3727
4180
|
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
4181
|
+
const nearBottom = isNearBottom();
|
|
4182
|
+
setHideScrollToBottomButton(nearBottom);
|
|
4183
|
+
|
|
4184
|
+
if (nearBottom && temporaryMessageListRef.current.length > 0) {
|
|
4185
|
+
// Merge temporary messages when scrolling near bottom
|
|
4186
|
+
messagesContentListRef.current = [
|
|
4187
|
+
...temporaryMessageListRef.current,
|
|
4188
|
+
...messagesContentListRef.current,
|
|
4189
|
+
];
|
|
4190
|
+
temporaryMessageListRef.current = [];
|
|
4191
|
+
|
|
4192
|
+
// Update latestMessageRef after merge
|
|
4193
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4194
|
+
latestMessageRef.current = messagesContentListRef.current[0];
|
|
4195
|
+
}
|
|
4196
|
+
|
|
4197
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
4198
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
4199
|
+
|
|
4200
|
+
setUnreadCount(0);
|
|
4201
|
+
|
|
4202
|
+
if (hasManuallyMarkedUnread) {
|
|
4203
|
+
setHasManuallyMarkedUnread(false);
|
|
4204
|
+
}
|
|
4205
|
+
|
|
4206
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4207
|
+
const latestMessage = messagesContentListRef.current[0];
|
|
4208
|
+
markMessageAsRead(latestMessage);
|
|
4209
|
+
}
|
|
4210
|
+
}
|
|
3731
4211
|
};
|
|
3732
4212
|
|
|
3733
4213
|
const scrollToBottom = useCallback((scrollToFirstUnread = false) => {
|
|
3734
|
-
|
|
4214
|
+
// Merge temporary messages when scrolling to bottom
|
|
4215
|
+
if (temporaryMessageListRef.current.length > 0) {
|
|
4216
|
+
messagesContentListRef.current = [
|
|
4217
|
+
...temporaryMessageListRef.current,
|
|
4218
|
+
...messagesContentListRef.current,
|
|
4219
|
+
];
|
|
4220
|
+
temporaryMessageListRef.current = [];
|
|
4221
|
+
|
|
4222
|
+
// Update latestMessageRef after merge
|
|
4223
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4224
|
+
latestMessageRef.current = messagesContentListRef.current[0];
|
|
4225
|
+
}
|
|
4226
|
+
|
|
4227
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
4228
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
4229
|
+
|
|
4230
|
+
if (hasManuallyMarkedUnread) {
|
|
4231
|
+
setHasManuallyMarkedUnread(false);
|
|
4232
|
+
}
|
|
4233
|
+
}
|
|
4234
|
+
|
|
4235
|
+
setUnreadCount(0);
|
|
4236
|
+
setHideScrollToBottomButton(true);
|
|
4237
|
+
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3735
4238
|
// Clear navigation flags
|
|
3736
4239
|
setHasTargetMessageId(false);
|
|
3737
4240
|
setHighlightedMessageId(null);
|
|
3738
|
-
|
|
4241
|
+
setHasManuallyMarkedUnread(false);
|
|
4242
|
+
|
|
4243
|
+
// Mark latest message as read if available
|
|
4244
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4245
|
+
const latestMessage = messagesContentListRef.current[0];
|
|
4246
|
+
markMessageAsRead(latestMessage);
|
|
4247
|
+
}
|
|
4248
|
+
// setNavigatedFromSearch(false); // navigatedFromSearch is a prop, cannot set it
|
|
3739
4249
|
}, [hasTargetMessageId, messagesList.length]);
|
|
3740
4250
|
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
4251
|
+
const handleScrollInternal = useCallback((event: any) => {
|
|
4252
|
+
scrollHandler(event);
|
|
4253
|
+
}, [scrollHandler]);
|
|
3744
4254
|
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
4255
|
+
|
|
4256
|
+
const handleScrollToIndexFailed = useCallback((error: any) => {
|
|
4257
|
+
|
|
4258
|
+
// Calculate dynamic average height from measured items
|
|
4259
|
+
const measuredItems = Array.from(itemPositions.values());
|
|
4260
|
+
let averageHeight = AVERAGE_ITEM_LENGTH;
|
|
4261
|
+
|
|
4262
|
+
if (measuredItems.length > 0) {
|
|
4263
|
+
const totalHeight = measuredItems.reduce((sum, item) => sum + item.height, 0);
|
|
4264
|
+
averageHeight = totalHeight / measuredItems.length;
|
|
4265
|
+
}
|
|
4266
|
+
|
|
4267
|
+
// Scroll to estimated position to load more items
|
|
4268
|
+
const targetOffset = error.index * averageHeight;
|
|
4269
|
+
|
|
4270
|
+
messageListRef.current?.scrollToOffset({
|
|
4271
|
+
offset: targetOffset,
|
|
4272
|
+
animated: true,
|
|
4273
|
+
});
|
|
4274
|
+
|
|
4275
|
+
// After scrolling to load more items, retry scrollToIndex
|
|
4276
|
+
setTimeout(() => {
|
|
4277
|
+
if (messageListRef.current) {
|
|
4278
|
+
try {
|
|
4279
|
+
messageListRef.current.scrollToIndex({
|
|
4280
|
+
index: error.index,
|
|
4281
|
+
animated: true,
|
|
4282
|
+
viewPosition: 0.5, // For inverted FlatList
|
|
4283
|
+
});
|
|
4284
|
+
} catch (retryError) {
|
|
4285
|
+
console.warn('Retry scrollToIndex also failed:', retryError);
|
|
3755
4286
|
}
|
|
3756
|
-
|
|
3757
|
-
|
|
4287
|
+
}
|
|
4288
|
+
}, 300); // Wait for items to load
|
|
4289
|
+
}, [itemPositions]);
|
|
4290
|
+
|
|
4291
|
+
|
|
4292
|
+
|
|
4293
|
+
// Clear item positions when messages list changes significantly
|
|
4294
|
+
// Don't clear on minor changes (like adding one message) or when navigating
|
|
4295
|
+
useEffect(() => {
|
|
4296
|
+
const lengthDiff = Math.abs(messagesList.length - prevMessagesLength.current);
|
|
4297
|
+
const isSignificantChange = lengthDiff > 5; // Only clear if 5+ messages added/removed
|
|
4298
|
+
|
|
4299
|
+
if (isSignificantChange) {
|
|
4300
|
+
setItemPositions(new Map());
|
|
4301
|
+
}
|
|
4302
|
+
|
|
4303
|
+
prevMessagesLength.current = messagesList.length;
|
|
4304
|
+
}, [messagesList.length]);
|
|
4305
|
+
|
|
4306
|
+
// Handle layout measurement for accurate scrolling
|
|
4307
|
+
const handleItemLayout = useCallback((event: any, messageId: string) => {
|
|
4308
|
+
const { y, height } = event.nativeEvent.layout;
|
|
4309
|
+
setItemPositions(prev => {
|
|
4310
|
+
const newMap = new Map(prev);
|
|
4311
|
+
newMap.set(messageId, { y, height });
|
|
4312
|
+
return newMap;
|
|
4313
|
+
});
|
|
4314
|
+
}, []);
|
|
4315
|
+
//
|
|
4316
|
+
// Configuration for determining when list items are considered "viewable" (visible on screen)
|
|
4317
|
+
// itemVisiblePercentThreshold: 50 means an item is viewable when at least 50% of it is visible
|
|
4318
|
+
// This is used by onViewableItemsChanged to detect when messages come into view for auto-read functionality
|
|
4319
|
+
const viewabilityConfig = useRef({
|
|
4320
|
+
itemVisiblePercentThreshold: 50,
|
|
4321
|
+
}).current;
|
|
4322
|
+
|
|
4323
|
+
// This function handles marking the conversation as read ONLY when the user scrolls
|
|
4324
|
+
// to the "New Message" indicator (the first unread message).
|
|
4325
|
+
// This preserves the unread count while the user is viewing searched messages.
|
|
4326
|
+
const handleViewableItemsChanged = useCallback(({ viewableItems }: any) => {
|
|
4327
|
+
if (navigatedFromSearch && newMessageIndicatorId && unreadCount > 0 && !hasManuallyMarkedUnread) {
|
|
4328
|
+
const indicatorItem = viewableItems.find(
|
|
4329
|
+
(item: any) => String(item.item.getId()) === newMessageIndicatorId
|
|
4330
|
+
);
|
|
4331
|
+
|
|
4332
|
+
if (indicatorItem) {
|
|
4333
|
+
if (user) {
|
|
4334
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
4335
|
+
console.log("Error marking user conversation as read", e);
|
|
4336
|
+
});
|
|
4337
|
+
} else if (group) {
|
|
4338
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
4339
|
+
console.log("Error marking group conversation as read", e);
|
|
4340
|
+
});
|
|
3758
4341
|
}
|
|
4342
|
+
setUnreadCount(0);
|
|
3759
4343
|
}
|
|
3760
|
-
|
|
4344
|
+
}
|
|
4345
|
+
}, [navigatedFromSearch, newMessageIndicatorId, unreadCount, user, group, hasManuallyMarkedUnread]);
|
|
4346
|
+
|
|
4347
|
+
|
|
4348
|
+
|
|
4349
|
+
// Optimized FlatList renderItem using memoized component
|
|
4350
|
+
const memoizedRenderItem = useCallback(
|
|
4351
|
+
({ item, index }: any) => {
|
|
4352
|
+
const nextItem = messagesContentListRef.current[index + 1];
|
|
4353
|
+
const currentItemMs = sentAtToMs(item);
|
|
4354
|
+
const nextItemMs = sentAtToMs(nextItem);
|
|
4355
|
+
const showSeparator = shouldShowSeparator(index, currentItemMs, nextItemMs);
|
|
4356
|
+
const ms = currentItemMs ?? Date.now();
|
|
3761
4357
|
const itemId = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3762
4358
|
const isHighlighted = highlightedMessageId === String(itemId);
|
|
3763
|
-
|
|
3764
|
-
|
|
3765
|
-
|
|
3766
|
-
|
|
3767
|
-
|
|
3768
|
-
|
|
3769
|
-
|
|
3770
|
-
|
|
3771
|
-
position: 'absolute' as 'absolute',
|
|
3772
|
-
left: 0,
|
|
3773
|
-
right: 0,
|
|
3774
|
-
top: separatorHeight,
|
|
3775
|
-
bottom: 0,
|
|
3776
|
-
zIndex: 1,
|
|
3777
|
-
};
|
|
4359
|
+
const dayHeaderString = getDayHeaderString(ms);
|
|
4360
|
+
// Show the "New Messages" indicator above a message if:
|
|
4361
|
+
// - startFromUnreadMessages is enabled (to indicate unread messages start here), OR
|
|
4362
|
+
// - showMarkAsUnreadOption is enabled (to show where a message was marked as unread)
|
|
4363
|
+
// - OR navigatedFromSearch is true (when navigating from search to unread messages)
|
|
4364
|
+
// - and this message matches the newMessageIndicatorId
|
|
4365
|
+
// - and NOT in agentic mode (agentic chats don't support unread indicators)
|
|
4366
|
+
const showNewMessageIndicator = !isAgenticUser && (startFromUnreadMessages || showMarkAsUnreadOption || navigatedFromSearch) && newMessageIndicatorId === String(item.getId());
|
|
3778
4367
|
|
|
3779
4368
|
return (
|
|
3780
|
-
<View
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
{
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
{
|
|
3797
|
-
|
|
4369
|
+
<View>
|
|
4370
|
+
<MessageListItem
|
|
4371
|
+
item={item}
|
|
4372
|
+
index={index}
|
|
4373
|
+
showSeparator={showSeparator}
|
|
4374
|
+
isHighlighted={isHighlighted}
|
|
4375
|
+
highlightAnimatedValue={highlightAnimatedValue}
|
|
4376
|
+
theme={mergedTheme}
|
|
4377
|
+
timestamp={ms}
|
|
4378
|
+
dayHeaderString={dayHeaderString}
|
|
4379
|
+
RenderMessageItem={RenderMessageItem}
|
|
4380
|
+
itemSeparator={itemSeparator}
|
|
4381
|
+
staticStyles={staticStyles}
|
|
4382
|
+
onLayout={handleItemLayout}
|
|
4383
|
+
showNewMessageIndicator={showNewMessageIndicator}
|
|
4384
|
+
NewMessageIndicatorView={NewMessageIndicatorView}
|
|
4385
|
+
newMessageIndicatorStyle={newMessageIndicatorStyle}
|
|
4386
|
+
newMessageIndicatorText={newMessageIndicatorText}
|
|
4387
|
+
/>
|
|
3798
4388
|
</View>
|
|
3799
4389
|
);
|
|
3800
4390
|
},
|
|
3801
|
-
[
|
|
4391
|
+
[
|
|
4392
|
+
mergedTheme,
|
|
4393
|
+
highlightedMessageId,
|
|
4394
|
+
highlightAnimatedValue,
|
|
4395
|
+
sentAtToMs,
|
|
4396
|
+
shouldShowSeparator,
|
|
4397
|
+
getDayHeaderString,
|
|
4398
|
+
itemSeparator,
|
|
4399
|
+
RenderMessageItem,
|
|
4400
|
+
handleItemLayout,
|
|
4401
|
+
newMessageIndicatorId,
|
|
4402
|
+
NewMessageIndicatorView,
|
|
4403
|
+
newMessageIndicatorStyle,
|
|
4404
|
+
newMessageIndicatorText,
|
|
4405
|
+
startFromUnreadMessages,
|
|
4406
|
+
showMarkAsUnreadOption,
|
|
4407
|
+
navigatedFromSearch,
|
|
4408
|
+
isAgenticUser
|
|
4409
|
+
]
|
|
3802
4410
|
);
|
|
3803
4411
|
|
|
4412
|
+
|
|
3804
4413
|
return (
|
|
3805
4414
|
<View style={mergedTheme.messageListStyles.containerStyle}>
|
|
3806
4415
|
{listState == "loading" && messagesList.length == 0 ? (
|
|
@@ -3830,45 +4439,40 @@ export const CometChatMessageList = memo(
|
|
|
3830
4439
|
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
3831
4440
|
</View>
|
|
3832
4441
|
)}
|
|
3833
|
-
|
|
3834
|
-
{/* Navigation loading for far message fetching */}
|
|
3835
|
-
{navigationLoading && getLoadingStateView()}
|
|
3836
4442
|
|
|
4443
|
+
{/* Navigation loading for far message fetching and scroll operations */}
|
|
4444
|
+
{navigationLoading && (getLoadingStateView())}
|
|
3837
4445
|
<FlatList
|
|
3838
4446
|
showsVerticalScrollIndicator={false}
|
|
3839
4447
|
ref={messageListRef}
|
|
3840
|
-
onMomentumScrollEnd={
|
|
3841
|
-
onScroll={
|
|
4448
|
+
onMomentumScrollEnd={handleScrollInternal}
|
|
4449
|
+
onScroll={handleScrollInternal}
|
|
3842
4450
|
inverted={true}
|
|
3843
4451
|
maintainVisibleContentPosition={{
|
|
3844
4452
|
minIndexForVisible: 0,
|
|
3845
4453
|
}}
|
|
3846
|
-
onEndReached={getPreviousMessages}
|
|
3847
4454
|
onEndReachedThreshold={0.5}
|
|
4455
|
+
onEndReached={getPreviousMessages}
|
|
3848
4456
|
onStartReached={fetchNextMessages}
|
|
3849
4457
|
onStartReachedThreshold={0.5}
|
|
3850
4458
|
scrollEventThrottle={16}
|
|
3851
|
-
keyboardShouldPersistTaps={Platform.OS === "ios" ? "handled" : "always"}
|
|
4459
|
+
keyboardShouldPersistTaps={(Platform.OS === "ios" ? "handled" : "always") as "handled" | "always"}
|
|
3852
4460
|
data={messagesList}
|
|
3853
4461
|
keyExtractor={keyExtractor}
|
|
3854
4462
|
renderItem={memoizedRenderItem}
|
|
3855
|
-
onLayout={() => {
|
|
3856
|
-
setIsListLayoutComplete(true);
|
|
3857
|
-
}}
|
|
3858
4463
|
ListHeaderComponent={renderFooter}
|
|
3859
|
-
onScrollToIndexFailed={
|
|
3860
|
-
|
|
3861
|
-
|
|
3862
|
-
|
|
3863
|
-
|
|
3864
|
-
|
|
3865
|
-
|
|
3866
|
-
}
|
|
3867
|
-
|
|
3868
|
-
/**Test the same on release mode. Dev mode could be laggy**/
|
|
3869
|
-
windowSize={33}
|
|
4464
|
+
onScrollToIndexFailed={handleScrollToIndexFailed}
|
|
4465
|
+
viewabilityConfig={viewabilityConfig}
|
|
4466
|
+
onViewableItemsChanged={handleViewableItemsChanged}
|
|
4467
|
+
// Performance optimizations
|
|
4468
|
+
windowSize={10}
|
|
4469
|
+
removeClippedSubviews={Platform.OS === 'android'}
|
|
4470
|
+
maxToRenderPerBatch={5}
|
|
4471
|
+
updateCellsBatchingPeriod={100}
|
|
4472
|
+
initialNumToRender={15}
|
|
3870
4473
|
/>
|
|
3871
4474
|
|
|
4475
|
+
|
|
3872
4476
|
{CustomListHeader && <CustomListHeader />}
|
|
3873
4477
|
{ongoingCallView}
|
|
3874
4478
|
{FooterView && (
|
|
@@ -3916,151 +4520,151 @@ export const CometChatMessageList = memo(
|
|
|
3916
4520
|
</Pressable>
|
|
3917
4521
|
)}
|
|
3918
4522
|
|
|
3919
|
-
<
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
4523
|
+
<MessageModals
|
|
4524
|
+
showDeleteModal={showDeleteModal}
|
|
4525
|
+
showReportDialog={showReportDialog}
|
|
4526
|
+
deleteItem={deleteItem}
|
|
4527
|
+
reportedMessageRef={reportedMessageRef}
|
|
4528
|
+
theme={theme}
|
|
4529
|
+
hideFlagRemarkField={hideFlagRemarkField}
|
|
4530
|
+
t={t}
|
|
4531
|
+
onDeleteCancel={() => {
|
|
3928
4532
|
deleteItem.current = undefined;
|
|
3929
4533
|
setShowDeleteModal(false);
|
|
3930
4534
|
}}
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
}}
|
|
3934
|
-
/>
|
|
3935
|
-
|
|
3936
|
-
<CometChatReportDialog
|
|
3937
|
-
isOpen={showReportDialog}
|
|
3938
|
-
message={reportedMessageRef.current || undefined}
|
|
3939
|
-
onCancel={() => {
|
|
4535
|
+
onDeleteConfirm={deleteMessage}
|
|
4536
|
+
onReportCancel={() => {
|
|
3940
4537
|
setShowReportDialog(false);
|
|
3941
4538
|
reportedMessageRef.current = null;
|
|
3942
4539
|
}}
|
|
3943
|
-
|
|
3944
|
-
onReport={(payload) => {
|
|
3945
|
-
console.log("Report submitted", {
|
|
3946
|
-
messageId: payload.message?.getId?.(),
|
|
3947
|
-
payload,
|
|
3948
|
-
});
|
|
4540
|
+
onReportSubmit={(payload) => {
|
|
3949
4541
|
setShowReportDialog(false);
|
|
3950
4542
|
reportedMessageRef.current = null;
|
|
3951
4543
|
}}
|
|
3952
4544
|
/>
|
|
3953
4545
|
|
|
3954
|
-
<
|
|
3955
|
-
|
|
4546
|
+
<MessageOptionsSheet
|
|
4547
|
+
bottomSheetRef={bottomSheetRef}
|
|
4548
|
+
isOpen={showMessageOptions.length > 0 || Boolean(ExtensionsComponent) || messageInfo}
|
|
4549
|
+
showMessageOptions={showMessageOptions}
|
|
4550
|
+
ExtensionsComponent={ExtensionsComponent}
|
|
4551
|
+
messageInfo={messageInfo}
|
|
4552
|
+
infoObject={infoObject}
|
|
4553
|
+
selectedMessage={selectedMessage}
|
|
4554
|
+
hideReactionOption={hideReactionOption}
|
|
4555
|
+
quickReactionList={quickReactionList as [string, string?, string?, string?, string?]}
|
|
4556
|
+
templatesMap={templatesMap}
|
|
4557
|
+
mergedTheme={mergedTheme}
|
|
4558
|
+
deleteItem={deleteItem}
|
|
4559
|
+
pendingReportRef={pendingReportRef}
|
|
3956
4560
|
onClose={() => {
|
|
3957
4561
|
if (ExtensionsComponent) setExtensionsComponent(null);
|
|
3958
4562
|
setShowMessageOptions([]);
|
|
3959
4563
|
infoObject.current = null;
|
|
3960
4564
|
setMessageInfo(false);
|
|
3961
4565
|
}}
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
|
|
3971
|
-
}
|
|
3972
|
-
}
|
|
3973
|
-
}}
|
|
3974
|
-
isOpen={showMessageOptions.length > 0 || Boolean(ExtensionsComponent) || messageInfo}
|
|
3975
|
-
style={{
|
|
3976
|
-
paddingHorizontal: 0,
|
|
3977
|
-
maxHeight: messageInfo
|
|
3978
|
-
? Dimensions.get("window").height * 0.9
|
|
3979
|
-
: Dimensions.get("window").height * 0.52,
|
|
3980
|
-
|
|
3981
|
-
minHeight: Dimensions.get("window").height * 0.5,
|
|
3982
|
-
}}
|
|
3983
|
-
>
|
|
3984
|
-
{ExtensionsComponent ? (
|
|
3985
|
-
ExtensionsComponent
|
|
3986
|
-
) : messageInfo && infoObject.current ? (
|
|
3987
|
-
<CometChatMessageInformation
|
|
3988
|
-
message={infoObject.current}
|
|
3989
|
-
template={templatesMap.get(
|
|
3990
|
-
`${infoObject.current?.getCategory()}_${infoObject.current?.getType()}`
|
|
3991
|
-
)}
|
|
3992
|
-
onBack={() => {
|
|
3993
|
-
infoObject.current = null;
|
|
3994
|
-
setMessageInfo(false);
|
|
3995
|
-
}}
|
|
3996
|
-
style={mergedTheme?.messageListStyles?.messageInformationStyles}
|
|
3997
|
-
/>
|
|
3998
|
-
) : (
|
|
3999
|
-
<View style={{ flex: 1 }}>
|
|
4000
|
-
{/* Show quick reactions for disapproved messages */}
|
|
4001
|
-
{!hideReactionOption && getModerationStatus(selectedMessage) !== "disapproved" && (
|
|
4002
|
-
<CometChatQuickReactions
|
|
4003
|
-
quickReactions={quickReactionList}
|
|
4004
|
-
onReactionPress={reactToMessage}
|
|
4005
|
-
onAddReactionPress={
|
|
4006
|
-
onAddReactionPress ??
|
|
4007
|
-
(() => {
|
|
4008
|
-
setShowMessageOptions([]);
|
|
4009
|
-
setTimeout(() => {
|
|
4010
|
-
setShowEmojiKeyboard(true);
|
|
4011
|
-
}, 200);
|
|
4012
|
-
})
|
|
4013
|
-
}
|
|
4014
|
-
style={mergedTheme.quickReactionStyle}
|
|
4015
|
-
/>
|
|
4016
|
-
)}
|
|
4017
|
-
|
|
4018
|
-
<CometChatActionSheet
|
|
4019
|
-
actions={showMessageOptions}
|
|
4020
|
-
style={mergedTheme.messageListStyles.messageOptionsStyles}
|
|
4021
|
-
/>
|
|
4022
|
-
</View>
|
|
4023
|
-
)}
|
|
4024
|
-
</CometChatBottomSheet>
|
|
4025
|
-
<CometChatBottomSheet
|
|
4026
|
-
isOpen={showEmojiKeyboard}
|
|
4027
|
-
onClose={() => setShowEmojiKeyboard(false)}
|
|
4028
|
-
style={{
|
|
4029
|
-
maxHeight: Dimensions.get("window").height * 0.49,
|
|
4030
|
-
}}
|
|
4031
|
-
>
|
|
4032
|
-
<CometChatEmojiKeyboard
|
|
4033
|
-
onClick={(item) => {
|
|
4034
|
-
setShowEmojiKeyboard(false);
|
|
4035
|
-
reactToMessage(item, selectedMessage);
|
|
4036
|
-
}}
|
|
4037
|
-
/>
|
|
4038
|
-
</CometChatBottomSheet>
|
|
4566
|
+
onReactionPress={reactToMessage}
|
|
4567
|
+
onAddReactionPress={onAddReactionPress}
|
|
4568
|
+
setShowDeleteModal={setShowDeleteModal}
|
|
4569
|
+
setShowReportDialog={setShowReportDialog}
|
|
4570
|
+
setShowMessageOptions={setShowMessageOptions}
|
|
4571
|
+
setExtensionsComponent={setExtensionsComponent}
|
|
4572
|
+
setMessageInfo={setMessageInfo}
|
|
4573
|
+
setShowEmojiKeyboard={setShowEmojiKeyboard}
|
|
4574
|
+
/>
|
|
4039
4575
|
|
|
4040
|
-
<
|
|
4041
|
-
|
|
4042
|
-
|
|
4576
|
+
<ReactionModals
|
|
4577
|
+
showEmojiKeyboard={showEmojiKeyboard}
|
|
4578
|
+
showReactionList={showReactionList}
|
|
4579
|
+
selectedMessage={selectedMessage}
|
|
4580
|
+
selectedEmoji={selectedEmoji}
|
|
4581
|
+
reactionsRequestBuilder={reactionsRequestBuilder}
|
|
4582
|
+
onReactionListItemPress={onReactionListItemPressProp}
|
|
4583
|
+
onEmojiSelect={reactToMessage}
|
|
4584
|
+
onEmojiKeyboardClose={() => setShowEmojiKeyboard(false)}
|
|
4585
|
+
onReactionListClose={() => {
|
|
4043
4586
|
setShowReactionList(false);
|
|
4044
4587
|
setSelectedEmoji(undefined);
|
|
4045
4588
|
}}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4589
|
+
onReactionListEmpty={() => {
|
|
4590
|
+
setShowReactionList(false);
|
|
4591
|
+
setSelectedEmoji(undefined);
|
|
4049
4592
|
}}
|
|
4050
|
-
|
|
4051
|
-
<CometChatReactionList
|
|
4052
|
-
message={selectedMessage}
|
|
4053
|
-
selectedReaction={selectedEmoji}
|
|
4054
|
-
onPress={onReactionListItemPressProp}
|
|
4055
|
-
reactionsRequestBuilder={reactionsRequestBuilder}
|
|
4056
|
-
onListEmpty={() => {
|
|
4057
|
-
setShowReactionList(false);
|
|
4058
|
-
setSelectedEmoji(undefined);
|
|
4059
|
-
}}
|
|
4060
|
-
/>
|
|
4061
|
-
</CometChatBottomSheet>
|
|
4593
|
+
/>
|
|
4062
4594
|
</View>
|
|
4063
4595
|
);
|
|
4596
|
+
|
|
4064
4597
|
}
|
|
4065
4598
|
)
|
|
4066
4599
|
);
|
|
4600
|
+
|
|
4601
|
+
|
|
4602
|
+
const staticStyles = StyleSheet.create({
|
|
4603
|
+
container: {
|
|
4604
|
+
flex: 1,
|
|
4605
|
+
paddingHorizontal: 16,
|
|
4606
|
+
paddingVertical: 8,
|
|
4607
|
+
position: 'relative' as 'relative',
|
|
4608
|
+
},
|
|
4609
|
+
contentWrapper: {
|
|
4610
|
+
position: 'relative' as 'relative',
|
|
4611
|
+
zIndex: 2,
|
|
4612
|
+
},
|
|
4613
|
+
separatorContainer: {
|
|
4614
|
+
alignItems: 'center' as 'center',
|
|
4615
|
+
marginBottom: 8,
|
|
4616
|
+
},
|
|
4617
|
+
footerContainer: {
|
|
4618
|
+
padding: 10,
|
|
4619
|
+
alignItems: 'center' as 'center',
|
|
4620
|
+
},
|
|
4621
|
+
itemSeparator: {
|
|
4622
|
+
height: 8,
|
|
4623
|
+
},
|
|
4624
|
+
loadingContainer: {
|
|
4625
|
+
padding: 16,
|
|
4626
|
+
},
|
|
4627
|
+
listContainer: {
|
|
4628
|
+
height: '100%',
|
|
4629
|
+
width: '100%',
|
|
4630
|
+
},
|
|
4631
|
+
headerContainer: {
|
|
4632
|
+
top: 0,
|
|
4633
|
+
},
|
|
4634
|
+
activityIndicatorContainer: {
|
|
4635
|
+
position: 'absolute' as 'absolute',
|
|
4636
|
+
alignSelf: 'center' as 'center',
|
|
4637
|
+
},
|
|
4638
|
+
flexOne: {
|
|
4639
|
+
flex: 1,
|
|
4640
|
+
},
|
|
4641
|
+
emptyScrollView: {
|
|
4642
|
+
flex: 1,
|
|
4643
|
+
justifyContent: "center",
|
|
4644
|
+
alignItems: "center",
|
|
4645
|
+
},
|
|
4646
|
+
emptyContainer: {
|
|
4647
|
+
alignItems: "center",
|
|
4648
|
+
justifyContent: "center",
|
|
4649
|
+
padding: 24,
|
|
4650
|
+
},
|
|
4651
|
+
avatarContainer: {
|
|
4652
|
+
width: 60,
|
|
4653
|
+
height: 60,
|
|
4654
|
+
borderRadius: 40,
|
|
4655
|
+
marginBottom: 20,
|
|
4656
|
+
alignItems: "center",
|
|
4657
|
+
justifyContent: "center",
|
|
4658
|
+
},
|
|
4659
|
+
avatarImage: {
|
|
4660
|
+
width: 60,
|
|
4661
|
+
height: 60,
|
|
4662
|
+
borderRadius: 40,
|
|
4663
|
+
},
|
|
4664
|
+
avatarText: {
|
|
4665
|
+
fontSize: 32,
|
|
4666
|
+
fontWeight: "bold",
|
|
4667
|
+
textAlign: "center",
|
|
4668
|
+
textAlignVertical: "center",
|
|
4669
|
+
},
|
|
4670
|
+
})//30/dec/2025 6.48pm
|