@cometchat/chat-uikit-react-native 5.2.8 → 5.2.9
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 +1 -1
- package/src/CometChatConversations/CometChatConversations.tsx +8 -1
- package/src/CometChatGroups/CometChatGroups.tsx +5 -3
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +55 -8
- package/src/CometChatMessageList/CometChatMessageList.tsx +1169 -548
- 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/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 +2 -3
- 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
|
@@ -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,28 +601,35 @@ 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
635
|
const effectiveHideModeration = hideModerationStatus;
|
|
@@ -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,59 @@ 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
|
+
setNewMessageIndicatorId(oldestMessage.getId().toString());
|
|
1077
|
+
}
|
|
1078
|
+
}
|
|
1079
|
+
|
|
1080
|
+
// Only mark conversation as read on initial load.
|
|
1081
|
+
// If we do this on every fetch (pagination), it would reset the unread count
|
|
1082
|
+
// even if the user manually marked a message as unread.
|
|
1083
|
+
// The !navigatedFromSearch condition ensures we don't mark as read when navigating from search results,
|
|
1084
|
+
// as the user might want to keep messages unread for reference.
|
|
1085
|
+
if (messagesList.length === 0 && !navigatedFromSearch) {
|
|
1086
|
+
//marking most recent unread message as read
|
|
1087
|
+
if (user) {
|
|
1088
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1089
|
+
console.log("Error marking user conversation as read", e);
|
|
996
1090
|
});
|
|
997
|
-
|
|
1091
|
+
} else if (group) {
|
|
1092
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
1093
|
+
console.log("Error marking group conversation as read", e);
|
|
1094
|
+
});
|
|
1095
|
+
}
|
|
1096
|
+
setUnreadCount(0);
|
|
1097
|
+
//emitting event to update read receipts in other components
|
|
1098
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1099
|
+
message: lastMessage,
|
|
1100
|
+
});
|
|
1101
|
+
}
|
|
1102
|
+
|
|
1103
|
+
} else {
|
|
1104
|
+
for (let index = 0; index < previousMessagesFetched.length; index++) {
|
|
1105
|
+
const message: CometChat.BaseMessage = previousMessagesFetched[index];
|
|
1106
|
+
if (
|
|
1107
|
+
message &&
|
|
1108
|
+
!message.hasOwnProperty("readAt") &&
|
|
1109
|
+
loggedInUser.current?.getUid() != message?.getSender()?.getUid()
|
|
1110
|
+
) {
|
|
1111
|
+
CometChat.markAsRead(message);
|
|
1112
|
+
if (index == 0)
|
|
1113
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1114
|
+
message,
|
|
1115
|
+
});
|
|
1116
|
+
} else break;
|
|
1117
|
+
}
|
|
998
1118
|
}
|
|
999
1119
|
previousMessagesFetched = previousMessagesFetched.map(
|
|
1000
1120
|
(item: CometChat.BaseMessage, index: any) => {
|
|
@@ -1058,18 +1178,18 @@ export const CometChatMessageList = memo(
|
|
|
1058
1178
|
if (fetchingAroundIdRef.current === messageId) {
|
|
1059
1179
|
return;
|
|
1060
1180
|
}
|
|
1061
|
-
|
|
1062
|
-
if (isAgenticUser
|
|
1181
|
+
|
|
1182
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1063
1183
|
return;
|
|
1064
1184
|
}
|
|
1065
1185
|
|
|
1066
1186
|
fetchingAroundIdRef.current = messageId; // Mark this message as being fetched
|
|
1067
|
-
|
|
1187
|
+
|
|
1068
1188
|
// Check if message exists in current list
|
|
1069
|
-
const messageExists = messagesContentListRef.current.find(msg =>
|
|
1189
|
+
const messageExists = messagesContentListRef.current.find(msg =>
|
|
1070
1190
|
String(msg.getId()) === String(messageId)
|
|
1071
1191
|
);
|
|
1072
|
-
|
|
1192
|
+
|
|
1073
1193
|
if (messageExists) {
|
|
1074
1194
|
setHasTargetMessageId(true);
|
|
1075
1195
|
} else {
|
|
@@ -1082,7 +1202,7 @@ export const CometChatMessageList = memo(
|
|
|
1082
1202
|
const targetMessageId = Number(messageId);
|
|
1083
1203
|
msgRequestBuilder.current?.setMessageId(targetMessageId);
|
|
1084
1204
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1085
|
-
|
|
1205
|
+
|
|
1086
1206
|
// Get the target message first to ensure it exists
|
|
1087
1207
|
const targetMessage = await CometChat.getMessageDetails(targetMessageId);
|
|
1088
1208
|
if (!targetMessage) {
|
|
@@ -1098,18 +1218,28 @@ export const CometChatMessageList = memo(
|
|
|
1098
1218
|
if (user) {
|
|
1099
1219
|
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
1100
1220
|
}
|
|
1101
|
-
|
|
1221
|
+
|
|
1102
1222
|
if (group) {
|
|
1103
1223
|
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
1104
1224
|
}
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1225
|
+
|
|
1226
|
+
// Main chat: Server excludes thread replies
|
|
1227
|
+
if (!parentMessageId) {
|
|
1228
|
+
nextMessagesRequest = nextMessagesRequest.hideReplies(true);
|
|
1229
|
+
}
|
|
1230
|
+
// Thread: Server includes only relevant messages
|
|
1231
|
+
else {
|
|
1232
|
+
nextMessagesRequest = nextMessagesRequest
|
|
1233
|
+
.setParentMessageId(Number(parentMessageId))
|
|
1234
|
+
.hideReplies(false);
|
|
1235
|
+
if (isAgenticUser) {
|
|
1236
|
+
nextMessagesRequest = nextMessagesRequest.withParent(true);
|
|
1237
|
+
}
|
|
1108
1238
|
}
|
|
1109
1239
|
|
|
1110
1240
|
// Fetch messages before and after the target message
|
|
1111
1241
|
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
1112
|
-
|
|
1242
|
+
|
|
1113
1243
|
// Combine messages: previous (reversed) + target + next
|
|
1114
1244
|
const allMessages = [
|
|
1115
1245
|
// ...previousMessages,
|
|
@@ -1119,17 +1249,101 @@ export const CometChatMessageList = memo(
|
|
|
1119
1249
|
|
|
1120
1250
|
// Remove duplicates and sort by timestamp (newest at top for FlatList)
|
|
1121
1251
|
const uniqueMessages = allMessages
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1252
|
+
// .filter((message, index, array) =>
|
|
1253
|
+
// array.findIndex(m => m.getId() === message.getId()) === index
|
|
1254
|
+
// )
|
|
1255
|
+
// .sort((a, b) => b.getSentAt() - a.getSentAt());
|
|
1126
1256
|
|
|
1127
1257
|
if (uniqueMessages.length > 0) {
|
|
1128
|
-
|
|
1258
|
+
// Check if this is the initial load using ref to ensure fresh state
|
|
1259
|
+
const isInitialLoad = messagesContentListRef.current.length === 0;
|
|
1260
|
+
messagesContentListRef.current = uniqueMessages;
|
|
1129
1261
|
setMessagesList(uniqueMessages);
|
|
1130
1262
|
onLoad && onLoad([...uniqueMessages].reverse());
|
|
1131
1263
|
|
|
1264
|
+
//This check is used to determine if this is the Initial Load of the chat screen.
|
|
1265
|
+
// Check if this is the initial load (messagesList is empty).
|
|
1266
|
+
// We check messagesList.length === 0 because setMessagesList above is async,
|
|
1267
|
+
// so messagesList still reflects the state before this update.
|
|
1268
|
+
// We only want to mark as read on the first load, not during subsequent updates.
|
|
1269
|
+
// The !navigatedFromSearch condition ensures we don't mark as read when navigating from search results,
|
|
1270
|
+
// as the user might want to keep messages unread for reference.
|
|
1271
|
+
if (startFromUnreadMessages && isInitialLoad && !navigatedFromSearch && !goToMessageId) {
|
|
1272
|
+
shouldSuppressHighlightRef.current = true;
|
|
1273
|
+
//marking most recent unread message as read
|
|
1274
|
+
if (user) {
|
|
1275
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1276
|
+
console.log("Error marking user conversation as read", e);
|
|
1277
|
+
});
|
|
1278
|
+
} else if (group) {
|
|
1279
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
1280
|
+
console.log("Error marking group conversation as read", e);
|
|
1281
|
+
});
|
|
1282
|
+
}
|
|
1283
|
+
setUnreadCount(0);
|
|
1284
|
+
// If we have next messages (unread messages), set the indicator on the first one.
|
|
1285
|
+
// Otherwise, fallback to the target message (last read message).
|
|
1286
|
+
if (nextMessages.length > 0) {
|
|
1287
|
+
setNewMessageIndicatorId(String(nextMessages[0].getId()));
|
|
1288
|
+
} else {
|
|
1289
|
+
setNewMessageIndicatorId(messageId);
|
|
1290
|
+
}
|
|
1291
|
+
//emitting event to update read receipts in other components
|
|
1292
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1293
|
+
message: uniqueMessages[0],
|
|
1294
|
+
});
|
|
1295
|
+
} else if (navigatedFromSearch) {
|
|
1296
|
+
// If we navigated from search, we want to show the "New Messages" indicator
|
|
1297
|
+
// but NOT mark the conversation as read immediately.
|
|
1298
|
+
// We fetch the first unread message to place the indicator correctly.
|
|
1299
|
+
const fetchFirstUnread = async () => {
|
|
1300
|
+
try {
|
|
1301
|
+
const convId = user?.getUid() ?? group?.getGuid();
|
|
1302
|
+
const conversationType = user
|
|
1303
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
1304
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
1305
|
+
|
|
1306
|
+
if (!convId) return;
|
|
1307
|
+
|
|
1308
|
+
const conversation = await CometChat.getConversation(convId, conversationType);
|
|
1309
|
+
const unreadCount = conversation.getUnreadMessageCount();
|
|
1310
|
+
setUnreadCount(unreadCount);
|
|
1311
|
+
|
|
1312
|
+
if (unreadCount > 0) {
|
|
1313
|
+
const lastReadMsgId = conversation.getLastReadMessageId();
|
|
1314
|
+
|
|
1315
|
+
if (lastReadMsgId) {
|
|
1316
|
+
let request = new CometChat.MessagesRequestBuilder()
|
|
1317
|
+
.setLimit(1)
|
|
1318
|
+
.setMessageId(Number(lastReadMsgId));
|
|
1319
|
+
|
|
1320
|
+
if (user) request = request.setUID(user.getUid());
|
|
1321
|
+
if (group) request = request.setGUID(group.getGuid());
|
|
1322
|
+
|
|
1323
|
+
if (!parentMessageId) {
|
|
1324
|
+
request = request.hideReplies(true);
|
|
1325
|
+
} else {
|
|
1326
|
+
request = request.setParentMessageId(Number(parentMessageId)).hideReplies(false);
|
|
1327
|
+
if (isAgenticUser) {
|
|
1328
|
+
request = request.withParent(true);
|
|
1329
|
+
}
|
|
1330
|
+
}
|
|
1331
|
+
|
|
1332
|
+
const unreadMessages = await request.build().fetchNext();
|
|
1333
|
+
if (unreadMessages.length > 0) {
|
|
1334
|
+
setNewMessageIndicatorId(String(unreadMessages[0].getId()));
|
|
1335
|
+
}
|
|
1336
|
+
}
|
|
1337
|
+
}
|
|
1338
|
+
} catch (e) {
|
|
1339
|
+
console.log("Error fetching first unread message", e);
|
|
1340
|
+
}
|
|
1341
|
+
};
|
|
1342
|
+
fetchFirstUnread();
|
|
1343
|
+
}
|
|
1344
|
+
|
|
1132
1345
|
// Reset layout state and set up for scrolling to target message
|
|
1346
|
+
// console.log(`Setting scroll target to message: ${messageId}`);
|
|
1133
1347
|
setScrollTargetId(messageId);
|
|
1134
1348
|
}
|
|
1135
1349
|
|
|
@@ -1137,39 +1351,92 @@ export const CometChatMessageList = memo(
|
|
|
1137
1351
|
} catch (error) {
|
|
1138
1352
|
console.log("Error fetching messages around ID:", error);
|
|
1139
1353
|
setListState("error");
|
|
1354
|
+
setNavigationLoading(false);
|
|
1140
1355
|
onError && onError(error as CometChat.CometChatException);
|
|
1141
1356
|
} finally {
|
|
1142
|
-
setNavigationLoading(false);
|
|
1357
|
+
// setNavigationLoading(false);
|
|
1143
1358
|
fetchingAroundIdRef.current = null;
|
|
1144
1359
|
}
|
|
1145
1360
|
};
|
|
1146
1361
|
|
|
1147
|
-
|
|
1362
|
+
// Scrolls to a specific message by ID, centering it in the view
|
|
1363
|
+
// Uses position data from itemPositions map for precise scrolling
|
|
1364
|
+
const scrollToMessage = (messageId: string, retryCount: number = 0) => {
|
|
1148
1365
|
if (messageListRef.current && messagesContentListRef.current.length > 0) {
|
|
1366
|
+
// Show loading indicator during scroll operation
|
|
1367
|
+
setNavigationLoading(true);
|
|
1368
|
+
|
|
1149
1369
|
const targetIndex = messagesContentListRef.current.findIndex(
|
|
1150
1370
|
(msg) => String(msg.getId()) === messageId
|
|
1151
1371
|
);
|
|
1152
|
-
|
|
1372
|
+
|
|
1153
1373
|
if (targetIndex !== -1) {
|
|
1154
|
-
//
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
//
|
|
1165
|
-
const
|
|
1374
|
+
// Get the actual position of the target message
|
|
1375
|
+
const targetMessage = messagesContentListRef.current[targetIndex];
|
|
1376
|
+
const position = itemPositions.get(String(targetMessage.getId()));
|
|
1377
|
+
|
|
1378
|
+
if (position) {
|
|
1379
|
+
// Calculate centered offset for the message
|
|
1380
|
+
// For inverted list, we need to position it from the top of the visible area
|
|
1381
|
+
const screenHeight = currentScrollPosition.current.scrollViewHeight || Dimensions.get('window').height;
|
|
1382
|
+
|
|
1383
|
+
// Center the message: place it at middle of the screen
|
|
1384
|
+
// In inverted list: offset = message.y - (screenHeight/2 - messageHeight/2)
|
|
1385
|
+
const centeredOffset = Math.max(0, position.y - (screenHeight / 2) + (position.height / 2));
|
|
1386
|
+
console.log({centeredOffset});
|
|
1387
|
+
|
|
1388
|
+
// console.log(`📍 Scrolling to position-based offset ${centeredOffset.toFixed(1)}px for message ${messageId}`);
|
|
1166
1389
|
messageListRef.current?.scrollToOffset({
|
|
1167
|
-
offset:
|
|
1390
|
+
offset: centeredOffset,
|
|
1168
1391
|
animated: true,
|
|
1169
1392
|
});
|
|
1170
|
-
|
|
1393
|
+
|
|
1394
|
+
// Highlight after scroll animation starts
|
|
1395
|
+
setTimeout(() => {
|
|
1396
|
+
// console.log(`Highlighting message ${messageId} after position-based scroll`);
|
|
1397
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1398
|
+
highlightMessage(messageId);
|
|
1399
|
+
}
|
|
1400
|
+
shouldSuppressHighlightRef.current = false;
|
|
1401
|
+
setNavigationLoading(false); // Clear loading when scroll completes
|
|
1402
|
+
}, 150);
|
|
1403
|
+
} else {
|
|
1404
|
+
// Position not measured yet - retry with faster progressive delays (up to 5 times)
|
|
1405
|
+
if (retryCount < 5) {
|
|
1406
|
+
// Faster progressive delays: 100ms, 200ms, 300ms, 400ms, 500ms
|
|
1407
|
+
const delay = (retryCount + 1) * 100;
|
|
1408
|
+
// console.log(`Retrying scroll for message ${messageId} (attempt ${retryCount + 1}/5) after ${delay}ms - waiting for layout`);
|
|
1409
|
+
setTimeout(() => {
|
|
1410
|
+
scrollToMessage(messageId, retryCount + 1);
|
|
1411
|
+
}, delay);
|
|
1412
|
+
} else {
|
|
1413
|
+
// Final fallback: use scrollToIndex with onScrollToIndexFailed handling for dynamic heights
|
|
1414
|
+
try {
|
|
1415
|
+
messageListRef.current?.scrollToIndex({
|
|
1416
|
+
index: targetIndex,
|
|
1417
|
+
animated: true,
|
|
1418
|
+
viewPosition: 0.5, // For inverted FlatList
|
|
1419
|
+
});
|
|
1420
|
+
// onScrollToIndexFailed will handle retry logic if this fails
|
|
1421
|
+
setTimeout(() => {
|
|
1422
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1423
|
+
highlightMessage(messageId);
|
|
1424
|
+
}
|
|
1425
|
+
shouldSuppressHighlightRef.current = false;
|
|
1426
|
+
setNavigationLoading(false); // Clear loading when scroll completes
|
|
1427
|
+
}, 250);
|
|
1428
|
+
} catch (scrollError) {
|
|
1429
|
+
console.error('scrollToIndex failed immediately:', scrollError);
|
|
1430
|
+
if (!shouldSuppressHighlightRef.current) {
|
|
1431
|
+
highlightMessage(messageId);
|
|
1432
|
+
}
|
|
1433
|
+
shouldSuppressHighlightRef.current = false;
|
|
1434
|
+
setNavigationLoading(false); // Clear loading on final failure
|
|
1435
|
+
}
|
|
1436
|
+
}
|
|
1171
1437
|
}
|
|
1172
1438
|
} else {
|
|
1439
|
+
setNavigationLoading(false); // Clear loading since we're fetching
|
|
1173
1440
|
getMessagesAroundId(messageId);
|
|
1174
1441
|
}
|
|
1175
1442
|
}
|
|
@@ -1177,7 +1444,7 @@ export const CometChatMessageList = memo(
|
|
|
1177
1444
|
|
|
1178
1445
|
const getUpdatedPreviousMessages = () => {
|
|
1179
1446
|
// For agent chats (non-thread), don't fetch updated previous messages
|
|
1180
|
-
if (isAgenticUser
|
|
1447
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1181
1448
|
return;
|
|
1182
1449
|
}
|
|
1183
1450
|
|
|
@@ -1265,7 +1532,7 @@ export const CometChatMessageList = memo(
|
|
|
1265
1532
|
};
|
|
1266
1533
|
|
|
1267
1534
|
const templatesMap = useMemo(() => {
|
|
1268
|
-
const isAgenticUserCheck = isAgenticUser
|
|
1535
|
+
const isAgenticUserCheck = isAgenticUser;
|
|
1269
1536
|
const options = {
|
|
1270
1537
|
textFormatters: textFormatters || [],
|
|
1271
1538
|
hideReplyOption: isAgenticUserCheck || hideReplyOption,
|
|
@@ -1279,6 +1546,7 @@ export const CometChatMessageList = memo(
|
|
|
1279
1546
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1280
1547
|
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption || !receiptsVisibility,
|
|
1281
1548
|
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1549
|
+
hideMarkAsUnreadOption: isAgenticUserCheck || hideMarkAsUnreadOption,
|
|
1282
1550
|
hideGroupActionMessages,
|
|
1283
1551
|
onReplyClick: (messageId: string) => {
|
|
1284
1552
|
scrollToMessage(messageId);
|
|
@@ -1289,9 +1557,9 @@ export const CometChatMessageList = memo(
|
|
|
1289
1557
|
templates && templates.length
|
|
1290
1558
|
? templates
|
|
1291
1559
|
: [
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1560
|
+
...ChatConfigurator.dataSource.getAllMessageTemplates(mergedTheme, options),
|
|
1561
|
+
...addTemplates,
|
|
1562
|
+
];
|
|
1295
1563
|
//for internal use only
|
|
1296
1564
|
const streamTemplate = internalMessageDataSource.getStreamMessageTemplate(
|
|
1297
1565
|
mergedTheme,
|
|
@@ -1434,6 +1702,48 @@ export const CometChatMessageList = memo(
|
|
|
1434
1702
|
});
|
|
1435
1703
|
}
|
|
1436
1704
|
};
|
|
1705
|
+
/**
|
|
1706
|
+
* Marks a specific message as unread in the conversation.
|
|
1707
|
+
* This function calls the CometChat SDK to mark the message as unread,
|
|
1708
|
+
* updates the conversation's unread count, and emits events to notify
|
|
1709
|
+
* other components of the conversation update. It also sets the new
|
|
1710
|
+
* message indicator to appear above this message.
|
|
1711
|
+
* @param message - The message to mark as unread
|
|
1712
|
+
*/
|
|
1713
|
+
const markMessageAsUnread = (message: CometChat.BaseMessage) => {
|
|
1714
|
+
CometChat.markMessageAsUnread(message).then(
|
|
1715
|
+
(response: any) => {
|
|
1716
|
+
setShowMessageOptions([]);
|
|
1717
|
+
setHasManuallyMarkedUnread(true);
|
|
1718
|
+
let convId:string = "";
|
|
1719
|
+
let conversationType:string = "";
|
|
1720
|
+
if (user) {
|
|
1721
|
+
convId = user?.getUid();
|
|
1722
|
+
conversationType = CometChat.RECEIVER_TYPE.USER;
|
|
1723
|
+
} else if (group) {
|
|
1724
|
+
convId = group?.getGuid();
|
|
1725
|
+
conversationType = CometChat.RECEIVER_TYPE.GROUP;
|
|
1726
|
+
}
|
|
1727
|
+
//getting convesation using conversationId=Uid and conversationType
|
|
1728
|
+
CometChat.getConversation(convId, conversationType).then((conversation) => {
|
|
1729
|
+
// Emitting conversation update event
|
|
1730
|
+
console.log("Emitting ccUpdateConversation event for mark as unread", conversation);
|
|
1731
|
+
CometChatUIEventHandler.emitConversationEvent(
|
|
1732
|
+
CometChatConversationEvents.ccUpdateConversation,
|
|
1733
|
+
{ conversation }
|
|
1734
|
+
);
|
|
1735
|
+
console.log("latest",conversation.getUnreadMessageCount());
|
|
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
|
|
@@ -1856,16 +2261,56 @@ export const CometChatMessageList = memo(
|
|
|
1856
2261
|
},
|
|
1857
2262
|
});
|
|
1858
2263
|
CometChat.getLoggedinUser()
|
|
1859
|
-
.then((u: any) => {
|
|
2264
|
+
.then(async (u: any) => {
|
|
2265
|
+
console.log({startFromUnreadMessages});
|
|
2266
|
+
|
|
1860
2267
|
loggedInUser.current = u;
|
|
1861
|
-
if (isAgenticUser
|
|
2268
|
+
if (isAgenticUser && !parentMessageId) {
|
|
1862
2269
|
messageRequest.current = null;
|
|
1863
2270
|
} else {
|
|
1864
2271
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1865
2272
|
}
|
|
1866
|
-
if (!isAgenticUser
|
|
2273
|
+
if (!isAgenticUser || (isAgenticUser && parentMessageId)) {
|
|
1867
2274
|
if (goToMessageId) {
|
|
1868
2275
|
getMessagesAroundId(goToMessageId);
|
|
2276
|
+
} else if (startFromUnreadMessages) {
|
|
2277
|
+
|
|
2278
|
+
|
|
2279
|
+
try {
|
|
2280
|
+
const convId = user?.getUid() ?? group?.getGuid();
|
|
2281
|
+
const conversationType = user
|
|
2282
|
+
? CometChat.RECEIVER_TYPE.USER
|
|
2283
|
+
: CometChat.RECEIVER_TYPE.GROUP;
|
|
2284
|
+
|
|
2285
|
+
|
|
2286
|
+
if (convId && conversationType) {
|
|
2287
|
+
|
|
2288
|
+
const conversation = await CometChat.getConversation(
|
|
2289
|
+
convId,
|
|
2290
|
+
conversationType
|
|
2291
|
+
);
|
|
2292
|
+
console.log({convId,conversationType,user,group,conversation,getUnreadMessageCount:conversation.getUnreadMessageCount()});
|
|
2293
|
+
// console.log("lower", conversation);
|
|
2294
|
+
if (conversation.getUnreadMessageCount() > 0) {
|
|
2295
|
+
setUnreadCount(conversation.getUnreadMessageCount());
|
|
2296
|
+
const lastReadMessageId = conversation.getLastReadMessageId();
|
|
2297
|
+
//if lastReadMessageId is 0, it means no messages have been read yet
|
|
2298
|
+
if (lastReadMessageId && Number(lastReadMessageId) !== 0) {
|
|
2299
|
+
getMessagesAroundId(String(lastReadMessageId));
|
|
2300
|
+
} else {
|
|
2301
|
+
getPreviousMessages();
|
|
2302
|
+
}
|
|
2303
|
+
} else {
|
|
2304
|
+
getPreviousMessages();
|
|
2305
|
+
}
|
|
2306
|
+
} else {
|
|
2307
|
+
getPreviousMessages();
|
|
2308
|
+
}
|
|
2309
|
+
} catch (e) {
|
|
2310
|
+
console.log("Error while getting conversation", e);
|
|
2311
|
+
|
|
2312
|
+
getPreviousMessages();
|
|
2313
|
+
}
|
|
1869
2314
|
} else {
|
|
1870
2315
|
getPreviousMessages();
|
|
1871
2316
|
}
|
|
@@ -1952,7 +2397,7 @@ export const CometChatMessageList = memo(
|
|
|
1952
2397
|
);
|
|
1953
2398
|
|
|
1954
2399
|
useEffect(() => {
|
|
1955
|
-
if (isAgenticUser
|
|
2400
|
+
if (isAgenticUser) {
|
|
1956
2401
|
agenticParentMessageIdRef.current = undefined;
|
|
1957
2402
|
}
|
|
1958
2403
|
}, [user?.getUid(), group?.getGuid(), isAgenticUser]);
|
|
@@ -1961,7 +2406,7 @@ export const CometChatMessageList = memo(
|
|
|
1961
2406
|
//add listeners
|
|
1962
2407
|
|
|
1963
2408
|
// AI Assistant listener for agent chats
|
|
1964
|
-
if (isAgenticUser
|
|
2409
|
+
if (isAgenticUser && user && (!parentMessageId || (parentMessageId && isAgenticUser))) {
|
|
1965
2410
|
CometChat.addAIAssistantListener(streamListenerId, {
|
|
1966
2411
|
onAIAssistantEventReceived: (message: CometChat.AIAssistantBaseEvent) => {
|
|
1967
2412
|
if (
|
|
@@ -2081,13 +2526,23 @@ export const CometChatMessageList = memo(
|
|
|
2081
2526
|
CometChatUIEventHandler.addMessageListener(messageEventListener, {
|
|
2082
2527
|
ccMessageSent: ({ message, status }: any) => {
|
|
2083
2528
|
if (status == MessageStatusConstants.inprogress) {
|
|
2529
|
+
// Remove incomplete stream messages before adding new user message (for agentic users)
|
|
2530
|
+
if (isAgenticUser) {
|
|
2531
|
+
const filteredList = messagesContentListRef.current.filter(
|
|
2532
|
+
(msg) => !(msg as any).isStreamMessage
|
|
2533
|
+
);
|
|
2534
|
+
if (filteredList.length !== messagesContentListRef.current.length) {
|
|
2535
|
+
messagesContentListRef.current = filteredList;
|
|
2536
|
+
setMessagesList(filteredList);
|
|
2537
|
+
}
|
|
2538
|
+
}
|
|
2084
2539
|
newMessage(message, false);
|
|
2085
2540
|
}
|
|
2086
2541
|
|
|
2087
2542
|
if (status == MessageStatusConstants.success) {
|
|
2088
2543
|
messageEdited(message, true);
|
|
2089
2544
|
if (
|
|
2090
|
-
isAgenticUser
|
|
2545
|
+
isAgenticUser &&
|
|
2091
2546
|
agenticParentMessageIdRef.current === undefined &&
|
|
2092
2547
|
messagesList.length !== 0 &&
|
|
2093
2548
|
message.getType() === MessageTypeConstants.text &&
|
|
@@ -2095,7 +2550,7 @@ export const CometChatMessageList = memo(
|
|
|
2095
2550
|
) {
|
|
2096
2551
|
agenticParentMessageIdRef.current = String(message.getId());
|
|
2097
2552
|
}
|
|
2098
|
-
if (isAgenticUser
|
|
2553
|
+
if (isAgenticUser && agenticParentMessageIdRef.current !== undefined) {
|
|
2099
2554
|
const streamMessage = createStreamMessage(message);
|
|
2100
2555
|
addToMessageList(streamMessage);
|
|
2101
2556
|
}
|
|
@@ -2118,12 +2573,12 @@ export const CometChatMessageList = memo(
|
|
|
2118
2573
|
}
|
|
2119
2574
|
},
|
|
2120
2575
|
onTextMessageReceived: (textMessage: any) => {
|
|
2121
|
-
if (isAgenticUser
|
|
2576
|
+
if (isAgenticUser) {
|
|
2122
2577
|
if (
|
|
2123
2578
|
textMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2124
2579
|
textMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2125
2580
|
textMessage.getCategory?.() ===
|
|
2126
|
-
|
|
2581
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2127
2582
|
) {
|
|
2128
2583
|
newMessage(textMessage);
|
|
2129
2584
|
}
|
|
@@ -2132,12 +2587,12 @@ export const CometChatMessageList = memo(
|
|
|
2132
2587
|
}
|
|
2133
2588
|
},
|
|
2134
2589
|
onMediaMessageReceived: (mediaMessage: any) => {
|
|
2135
|
-
if (isAgenticUser
|
|
2590
|
+
if (isAgenticUser) {
|
|
2136
2591
|
if (
|
|
2137
2592
|
mediaMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2138
2593
|
mediaMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2139
2594
|
mediaMessage.getCategory?.() ===
|
|
2140
|
-
|
|
2595
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2141
2596
|
) {
|
|
2142
2597
|
newMessage(mediaMessage);
|
|
2143
2598
|
}
|
|
@@ -2146,12 +2601,12 @@ export const CometChatMessageList = memo(
|
|
|
2146
2601
|
}
|
|
2147
2602
|
},
|
|
2148
2603
|
onCustomMessageReceived: (customMessage: any) => {
|
|
2149
|
-
if (isAgenticUser
|
|
2604
|
+
if (isAgenticUser) {
|
|
2150
2605
|
if (
|
|
2151
2606
|
customMessage.getSender?.()?.getRole?.() === "@agentic" ||
|
|
2152
2607
|
customMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
2153
2608
|
customMessage.getCategory?.() ===
|
|
2154
|
-
|
|
2609
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
2155
2610
|
) {
|
|
2156
2611
|
newMessage(customMessage);
|
|
2157
2612
|
}
|
|
@@ -2165,14 +2620,19 @@ export const CometChatMessageList = memo(
|
|
|
2165
2620
|
onMessagesRead: (messageReceipt: any) => {
|
|
2166
2621
|
updateMessageReceipt(messageReceipt);
|
|
2167
2622
|
},
|
|
2623
|
+
//suraj
|
|
2168
2624
|
onMessageDeleted: (deletedMessage: any) => {
|
|
2625
|
+
// If the deleted message was unread, decrement the unread count
|
|
2626
|
+
if (!deletedMessage.getReadAt?.() && deletedMessage.getSender()?.getUid() !== loggedInUser.current?.getUid()) {
|
|
2627
|
+
setUnreadCount(prev => Math.max(0, prev - 1));
|
|
2628
|
+
}
|
|
2169
2629
|
messageEdited(deletedMessage);
|
|
2170
2630
|
},
|
|
2171
2631
|
onMessageEdited: (editedMessage: any) => {
|
|
2172
2632
|
messageEdited(editedMessage);
|
|
2173
2633
|
},
|
|
2174
2634
|
onMessageModerated: (moderatedMessage: any) => {
|
|
2175
|
-
!isAgenticUser
|
|
2635
|
+
!isAgenticUser && messageEdited(moderatedMessage);
|
|
2176
2636
|
},
|
|
2177
2637
|
onFormMessageReceived: (formMessage: any) => {
|
|
2178
2638
|
newMessage(formMessage);
|
|
@@ -2194,8 +2654,8 @@ export const CometChatMessageList = memo(
|
|
|
2194
2654
|
const runIdFromData = assistantData && typeof assistantData.getRunId === 'function' ? assistantData.getRunId() : null;
|
|
2195
2655
|
const runIdFromId = typeof aiAssistantMessage.getId === 'function' ? aiAssistantMessage.getId() : (aiAssistantMessage as any)?.id;
|
|
2196
2656
|
const runId = runIdFromData || runIdFromId;
|
|
2197
|
-
|
|
2198
2657
|
const parentMsgId = typeof aiAssistantMessage.getParentMessageId === 'function' ? aiAssistantMessage.getParentMessageId() : (aiAssistantMessage as any)?.parentMessageId;
|
|
2658
|
+
|
|
2199
2659
|
if (
|
|
2200
2660
|
parentMessageId &&
|
|
2201
2661
|
String(parentMessageId) !== String(parentMsgId)
|
|
@@ -2356,7 +2816,7 @@ export const CometChatMessageList = memo(
|
|
|
2356
2816
|
CometChat.removeGroupListener(groupListenerId);
|
|
2357
2817
|
CometChat.removeCallListener(callListenerId);
|
|
2358
2818
|
CometChat.removeConnectionListener(connectionListenerId);
|
|
2359
|
-
if (isAgenticUser
|
|
2819
|
+
if (isAgenticUser) {
|
|
2360
2820
|
CometChat.removeAIAssistantListener(streamListenerId);
|
|
2361
2821
|
if (streamSubscriptionRef.current) {
|
|
2362
2822
|
streamSubscriptionRef.current.unsubscribe();
|
|
@@ -2389,6 +2849,7 @@ export const CometChatMessageList = memo(
|
|
|
2389
2849
|
setShowReactionList(true);
|
|
2390
2850
|
}
|
|
2391
2851
|
}, [selectedEmoji]);
|
|
2852
|
+
|
|
2392
2853
|
useImperativeHandle(ref, () => {
|
|
2393
2854
|
return {
|
|
2394
2855
|
addMessage: newMessage,
|
|
@@ -2511,7 +2972,7 @@ export const CometChatMessageList = memo(
|
|
|
2511
2972
|
avatarVisibility &&
|
|
2512
2973
|
(alignment === "leftAligned" ||
|
|
2513
2974
|
(isIncomingMessage && !user) ||
|
|
2514
|
-
(isAgenticUser
|
|
2975
|
+
(isAgenticUser && isIncomingMessage));
|
|
2515
2976
|
|
|
2516
2977
|
if (shouldShowAvatar) {
|
|
2517
2978
|
return (
|
|
@@ -2609,7 +3070,7 @@ export const CometChatMessageList = memo(
|
|
|
2609
3070
|
item.getEditedAt?.() &&
|
|
2610
3071
|
(item as CometChat.BaseMessage).getType() === MessageTypeConstants.text;
|
|
2611
3072
|
|
|
2612
|
-
const shouldShowTimestamp = isAgenticUser
|
|
3073
|
+
const shouldShowTimestamp = isAgenticUser ? isOutgoingMessage : !hideTimestamp;
|
|
2613
3074
|
return (
|
|
2614
3075
|
<View>
|
|
2615
3076
|
<View
|
|
@@ -2640,7 +3101,7 @@ export const CometChatMessageList = memo(
|
|
|
2640
3101
|
timeStamp={
|
|
2641
3102
|
!hideTimestamp
|
|
2642
3103
|
? (item.getDeletedAt() || item.getSentAt()) * 1000 ||
|
|
2643
|
-
|
|
3104
|
+
getSentAtTimestamp(item)
|
|
2644
3105
|
: undefined
|
|
2645
3106
|
}
|
|
2646
3107
|
pattern={"timeFormat"}
|
|
@@ -2649,9 +3110,9 @@ export const CometChatMessageList = memo(
|
|
|
2649
3110
|
/>
|
|
2650
3111
|
)}
|
|
2651
3112
|
{receiptsVisibility &&
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
3113
|
+
alignment !== "leftAligned" &&
|
|
3114
|
+
isOutgoingMessage &&
|
|
3115
|
+
!item.getDeletedAt?.() ? (
|
|
2655
3116
|
<View style={{ marginLeft: 2, alignItems: "center", justifyContent: "center" }}>
|
|
2656
3117
|
<CometChatReceipt
|
|
2657
3118
|
receipt={messageState}
|
|
@@ -2677,6 +3138,94 @@ export const CometChatMessageList = memo(
|
|
|
2677
3138
|
[mergedTheme, isAgenticUser, hideTimestamp]
|
|
2678
3139
|
);
|
|
2679
3140
|
|
|
3141
|
+
const reactToMessage = (emoji: string, messageObj?: CometChat.BaseMessage) => {
|
|
3142
|
+
const originalMessage = messageObj || selectedMessage;
|
|
3143
|
+
const msgObj = CommonUtils.clone(originalMessage);
|
|
3144
|
+
|
|
3145
|
+
if (!msgObj.getId() && originalMessage?.getId()) {
|
|
3146
|
+
msgObj.getId = () => originalMessage.getId();
|
|
3147
|
+
}
|
|
3148
|
+
|
|
3149
|
+
const messageId = msgObj?.getId();
|
|
3150
|
+
const reactions = msgObj?.getReactions() || [];
|
|
3151
|
+
const emojiObject = reactions?.find((reaction: any) => {
|
|
3152
|
+
return reaction?.reaction == emoji;
|
|
3153
|
+
});
|
|
3154
|
+
|
|
3155
|
+
if (emojiObject && emojiObject?.getReactedByMe()) {
|
|
3156
|
+
const updatedReactions: any[] = [];
|
|
3157
|
+
reactions.forEach((reaction: any) => {
|
|
3158
|
+
if (reaction?.getReaction() == emoji) {
|
|
3159
|
+
if (reaction?.getCount() === 1) {
|
|
3160
|
+
return;
|
|
3161
|
+
} else {
|
|
3162
|
+
reaction.setCount(reaction?.getCount() - 1);
|
|
3163
|
+
reaction.setReactedByMe(false);
|
|
3164
|
+
updatedReactions.push(reaction);
|
|
3165
|
+
}
|
|
3166
|
+
} else {
|
|
3167
|
+
updatedReactions.push(reaction);
|
|
3168
|
+
}
|
|
3169
|
+
});
|
|
3170
|
+
|
|
3171
|
+
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3172
|
+
newMessageObj.setReactions(updatedReactions);
|
|
3173
|
+
|
|
3174
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3175
|
+
message: newMessageObj,
|
|
3176
|
+
status: messageStatus.success,
|
|
3177
|
+
});
|
|
3178
|
+
|
|
3179
|
+
CometChat.removeReaction(messageId, emoji)
|
|
3180
|
+
.then((message: any) => { })
|
|
3181
|
+
.catch((error: any) => {
|
|
3182
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3183
|
+
message: msgObj,
|
|
3184
|
+
status: messageStatus.success,
|
|
3185
|
+
});
|
|
3186
|
+
});
|
|
3187
|
+
} else {
|
|
3188
|
+
const updatedReactions: any[] = [];
|
|
3189
|
+
const reactionAvailable = reactions.find((reaction: any) => {
|
|
3190
|
+
return reaction?.getReaction() == emoji;
|
|
3191
|
+
});
|
|
3192
|
+
|
|
3193
|
+
reactions.forEach((reaction: any) => {
|
|
3194
|
+
if (reaction?.getReaction() == emoji) {
|
|
3195
|
+
reaction.setCount(reaction?.getCount() + 1);
|
|
3196
|
+
reaction.setReactedByMe(true);
|
|
3197
|
+
updatedReactions.push(reaction);
|
|
3198
|
+
} else {
|
|
3199
|
+
updatedReactions.push(reaction);
|
|
3200
|
+
}
|
|
3201
|
+
});
|
|
3202
|
+
if (!reactionAvailable) {
|
|
3203
|
+
const react: CometChat.ReactionCount = new CometChat.ReactionCount(emoji, 1, true);
|
|
3204
|
+
updatedReactions.push(react);
|
|
3205
|
+
}
|
|
3206
|
+
|
|
3207
|
+
const newMessageObj = CommonUtils.clone(msgObj);
|
|
3208
|
+
|
|
3209
|
+
newMessageObj.setReactions(updatedReactions);
|
|
3210
|
+
|
|
3211
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3212
|
+
message: newMessageObj,
|
|
3213
|
+
status: messageStatus.success,
|
|
3214
|
+
});
|
|
3215
|
+
|
|
3216
|
+
CometChat.addReaction(messageId, emoji)
|
|
3217
|
+
.then((response: any) => { })
|
|
3218
|
+
.catch((error: any) => {
|
|
3219
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageEdited, {
|
|
3220
|
+
message: msgObj,
|
|
3221
|
+
status: messageStatus.success,
|
|
3222
|
+
});
|
|
3223
|
+
});
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
setShowMessageOptions([]);
|
|
3227
|
+
};
|
|
3228
|
+
|
|
2680
3229
|
const onReactionPress = useCallback(
|
|
2681
3230
|
(reaction: CometChat.ReactionCount, messageObject: CometChat.BaseMessage) => {
|
|
2682
3231
|
if (reaction.getReaction() == "All") {
|
|
@@ -2713,17 +3262,17 @@ export const CometChatMessageList = memo(
|
|
|
2713
3262
|
messageObject?.getReactions().length > 0;
|
|
2714
3263
|
return hasReaction
|
|
2715
3264
|
? (params: { maxContentWidth?: number }) => {
|
|
2716
|
-
|
|
2717
|
-
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
2722
|
-
|
|
2723
|
-
|
|
2724
|
-
|
|
2725
|
-
|
|
2726
|
-
|
|
3265
|
+
return (
|
|
3266
|
+
<CometChatReactions
|
|
3267
|
+
messageObject={messageObject}
|
|
3268
|
+
onReactionPress={onReactionPress}
|
|
3269
|
+
onReactionLongPress={onReactionLongPress}
|
|
3270
|
+
alignment={alignment}
|
|
3271
|
+
style={getCurrentBubbleStyle(messageObject).reactionStyles}
|
|
3272
|
+
maxContentWidth={params?.maxContentWidth}
|
|
3273
|
+
/>
|
|
3274
|
+
);
|
|
3275
|
+
}
|
|
2727
3276
|
: null;
|
|
2728
3277
|
},
|
|
2729
3278
|
[mergedTheme]
|
|
@@ -2735,7 +3284,7 @@ export const CometChatMessageList = memo(
|
|
|
2735
3284
|
if (
|
|
2736
3285
|
alignment == "standard" &&
|
|
2737
3286
|
(item.getSender()?.getUid() || item?.["sender"]?.["uid"]) ==
|
|
2738
|
-
|
|
3287
|
+
loggedInUser.current?.getUid()
|
|
2739
3288
|
)
|
|
2740
3289
|
return "right";
|
|
2741
3290
|
return "left";
|
|
@@ -2751,7 +3300,7 @@ export const CometChatMessageList = memo(
|
|
|
2751
3300
|
|
|
2752
3301
|
const openReportDialog = (message: any) => {
|
|
2753
3302
|
reportedMessageRef.current = message;
|
|
2754
|
-
// On iOS wait for BottomSheet modal dismiss animation
|
|
3303
|
+
// On iOS wait for BottomSheet modal dismiss animation to avoid flashing
|
|
2755
3304
|
if (Platform.OS === "ios") {
|
|
2756
3305
|
pendingReportRef.current = true;
|
|
2757
3306
|
} else {
|
|
@@ -2809,7 +3358,7 @@ export const CometChatMessageList = memo(
|
|
|
2809
3358
|
style={_style.threadedMessageStyles?.indicatorTextStyle}
|
|
2810
3359
|
>{`${item.getReplyCount()} ${
|
|
2811
3360
|
item.getReplyCount() > 1 ? t("REPLIES") : t("REPLY")
|
|
2812
|
-
|
|
3361
|
+
}`}</Text>
|
|
2813
3362
|
<CometChatBadge
|
|
2814
3363
|
style={{
|
|
2815
3364
|
containerStyle: _style.threadedMessageStyles?.unreadCountStyle?.containerStyle,
|
|
@@ -2864,6 +3413,7 @@ export const CometChatMessageList = memo(
|
|
|
2864
3413
|
|
|
2865
3414
|
const openOptionsForMessage = useCallback(
|
|
2866
3415
|
(item: CometChat.BaseMessage | any, template: CometChatMessageTemplate) => {
|
|
3416
|
+
console.log("Opening options for message:", item);
|
|
2867
3417
|
let options = template?.options
|
|
2868
3418
|
? loggedInUser.current
|
|
2869
3419
|
? template.options(loggedInUser.current, item, mergedTheme, group)
|
|
@@ -2917,6 +3467,9 @@ export const CometChatMessageList = memo(
|
|
|
2917
3467
|
case MessageOptionConstants.shareMessage:
|
|
2918
3468
|
option.onPress = shareMedia.bind(this, item);
|
|
2919
3469
|
break;
|
|
3470
|
+
case MessageOptionConstants.markAsUnread:
|
|
3471
|
+
option.onPress = markMessageAsUnread.bind(this, item);
|
|
3472
|
+
break;
|
|
2920
3473
|
}
|
|
2921
3474
|
else {
|
|
2922
3475
|
// If overriding `onPress`, make sure to pass `item` explicitly
|
|
@@ -3004,7 +3557,7 @@ export const CometChatMessageList = memo(
|
|
|
3004
3557
|
}, [hasTemplate, isThreaded, getFooterView, message, bubbleAlignment]);
|
|
3005
3558
|
|
|
3006
3559
|
const ThreadedView = useMemo(() => {
|
|
3007
|
-
if (isAgenticUser
|
|
3560
|
+
if (isAgenticUser) return undefined;
|
|
3008
3561
|
return !isThreaded
|
|
3009
3562
|
? !message.getDeletedBy()
|
|
3010
3563
|
? getThreadView(message, bubbleAlignment)
|
|
@@ -3025,7 +3578,7 @@ export const CometChatMessageList = memo(
|
|
|
3025
3578
|
if (effectiveHideModeration) {
|
|
3026
3579
|
return hasTemplate?.BottomView && hasTemplate?.BottomView(message, bubbleAlignment);
|
|
3027
3580
|
} else {
|
|
3028
|
-
if (isOutgoing && moderationStatus === "disapproved" && !isAgenticUser
|
|
3581
|
+
if (isOutgoing && moderationStatus === "disapproved" && !isAgenticUser) {
|
|
3029
3582
|
return (
|
|
3030
3583
|
<ModerationBottomView
|
|
3031
3584
|
status={moderationStatus}
|
|
@@ -3062,6 +3615,7 @@ export const CometChatMessageList = memo(
|
|
|
3062
3615
|
if (!message.getId()) {
|
|
3063
3616
|
return;
|
|
3064
3617
|
}
|
|
3618
|
+
// console.log({hasTemplate});
|
|
3065
3619
|
|
|
3066
3620
|
setSelectedMessage(message);
|
|
3067
3621
|
hasTemplate && openOptionsForMessage(message, hasTemplate);
|
|
@@ -3075,7 +3629,7 @@ export const CometChatMessageList = memo(
|
|
|
3075
3629
|
const onReply = useCallback(() => {
|
|
3076
3630
|
if (message.getDeletedBy() != null) return;
|
|
3077
3631
|
if (!message.getId()) return;
|
|
3078
|
-
|
|
3632
|
+
|
|
3079
3633
|
CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
|
|
3080
3634
|
message: message,
|
|
3081
3635
|
status: messageStatus.inprogress,
|
|
@@ -3087,16 +3641,16 @@ export const CometChatMessageList = memo(
|
|
|
3087
3641
|
|
|
3088
3642
|
const handlePanGesture = useCallback((event: PanGestureHandlerGestureEvent) => {
|
|
3089
3643
|
const { translationX, velocityX } = event.nativeEvent;
|
|
3090
|
-
|
|
3644
|
+
|
|
3091
3645
|
// Only allow swiping from left to right for replies
|
|
3092
3646
|
if (translationX <= 0) return;
|
|
3093
|
-
|
|
3647
|
+
|
|
3094
3648
|
const swipeThreshold = 80; // Threshold to trigger reply
|
|
3095
3649
|
const maxSwipeDistance = 120; // Maximum swipe distance
|
|
3096
|
-
|
|
3650
|
+
|
|
3097
3651
|
// Calculate progress (0 to 1)
|
|
3098
3652
|
const progress = Math.min(translationX / maxSwipeDistance, 1);
|
|
3099
|
-
|
|
3653
|
+
|
|
3100
3654
|
// Update animated values
|
|
3101
3655
|
swipeAnimatedValue.setValue(Math.min(translationX, maxSwipeDistance));
|
|
3102
3656
|
replyIconOpacity.setValue(progress);
|
|
@@ -3104,10 +3658,10 @@ export const CometChatMessageList = memo(
|
|
|
3104
3658
|
|
|
3105
3659
|
const handlePanStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {
|
|
3106
3660
|
const { state, translationX, velocityX } = event.nativeEvent;
|
|
3107
|
-
|
|
3661
|
+
|
|
3108
3662
|
if (state === State.END) {
|
|
3109
3663
|
const swipeThreshold = 80;
|
|
3110
|
-
|
|
3664
|
+
|
|
3111
3665
|
// Reset animations
|
|
3112
3666
|
Animated.parallel([
|
|
3113
3667
|
Animated.spring(swipeAnimatedValue, {
|
|
@@ -3119,11 +3673,11 @@ export const CometChatMessageList = memo(
|
|
|
3119
3673
|
useNativeDriver: true,
|
|
3120
3674
|
}),
|
|
3121
3675
|
]).start();
|
|
3122
|
-
|
|
3676
|
+
|
|
3123
3677
|
const moderationStatus = getModerationStatus(message);
|
|
3124
3678
|
const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
3125
3679
|
if (isOutgoing && moderationStatus && moderationStatus !== "approved" && moderationStatus !== "unmoderated") return;
|
|
3126
|
-
|
|
3680
|
+
|
|
3127
3681
|
// Trigger reply if threshold is met
|
|
3128
3682
|
if (translationX > swipeThreshold || velocityX > 500) {
|
|
3129
3683
|
onReply();
|
|
@@ -3132,7 +3686,7 @@ export const CometChatMessageList = memo(
|
|
|
3132
3686
|
}, [onReply, message]);
|
|
3133
3687
|
|
|
3134
3688
|
return (
|
|
3135
|
-
message.getCategory() === MessageCategoryConstants.action ? (
|
|
3689
|
+
message.getCategory() === MessageCategoryConstants.action || isAgenticUser ? (
|
|
3136
3690
|
<View style={{ position: 'relative' }}>
|
|
3137
3691
|
<TouchableOpacity
|
|
3138
3692
|
activeOpacity={1}
|
|
@@ -3208,106 +3762,23 @@ export const CometChatMessageList = memo(
|
|
|
3208
3762
|
return item.getSentAt() ? item.getSentAt() * 1000 : Date.now();
|
|
3209
3763
|
}, []);
|
|
3210
3764
|
|
|
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
3765
|
|
|
3274
|
-
|
|
3275
|
-
|
|
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
|
-
|
|
3293
|
-
const sentAtToMs = (msg?: any): number | undefined => {
|
|
3766
|
+
//extract once per item
|
|
3767
|
+
const sentAtToMs = useCallback((msg?: any): number | undefined => {
|
|
3294
3768
|
if (!msg) return undefined;
|
|
3295
|
-
|
|
3296
|
-
|
|
3297
|
-
|
|
3298
|
-
? msg.getSentAt()
|
|
3299
|
-
: (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
|
|
3769
|
+
const raw = typeof msg.getSentAt === "function"
|
|
3770
|
+
? msg.getSentAt()
|
|
3771
|
+
: (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
|
|
3300
3772
|
if (raw === undefined || raw === null) return undefined;
|
|
3301
|
-
// if raw looks like seconds (10 digits) convert to ms
|
|
3302
3773
|
return raw < 1e12 ? raw * 1000 : raw;
|
|
3303
|
-
};
|
|
3774
|
+
}, []);
|
|
3304
3775
|
|
|
3305
|
-
const makeDayKey = (ms?: number | undefined) => {
|
|
3776
|
+
const makeDayKey = useCallback((ms?: number | undefined) => {
|
|
3306
3777
|
if (!ms) return null;
|
|
3307
3778
|
const d = new Date(ms);
|
|
3308
3779
|
// use local date parts so "Today" follows user's timezone
|
|
3309
3780
|
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
|
3310
|
-
};
|
|
3781
|
+
}, []);
|
|
3311
3782
|
|
|
3312
3783
|
const messageDayKeys = useMemo(() => {
|
|
3313
3784
|
return messagesList.map((m) => {
|
|
@@ -3316,22 +3787,58 @@ export const CometChatMessageList = memo(
|
|
|
3316
3787
|
});
|
|
3317
3788
|
}, [messagesList]);
|
|
3318
3789
|
|
|
3319
|
-
|
|
3790
|
+
//extract once per item
|
|
3791
|
+
const isSameLocalDay = useCallback((ms?: number) => {
|
|
3320
3792
|
if (!ms) return false;
|
|
3321
|
-
const
|
|
3322
|
-
const
|
|
3793
|
+
const now = new Date();
|
|
3794
|
+
const date = new Date(ms);
|
|
3323
3795
|
return (
|
|
3324
|
-
|
|
3325
|
-
|
|
3326
|
-
|
|
3796
|
+
date.getFullYear() === now.getFullYear() &&
|
|
3797
|
+
date.getMonth() === now.getMonth() &&
|
|
3798
|
+
date.getDate() === now.getDate()
|
|
3327
3799
|
);
|
|
3328
|
-
};
|
|
3800
|
+
}, []);
|
|
3801
|
+
|
|
3802
|
+
// Memoize separator calculation with cache
|
|
3803
|
+
const separatorCache = useRef(new Map<string, boolean>());
|
|
3804
|
+
const shouldShowSeparator = useCallback((index: number, currentMs?: number, nextMs?: number) => {
|
|
3805
|
+
const cacheKey = `${index}-${currentMs}-${nextMs}`;
|
|
3806
|
+
|
|
3807
|
+
if (separatorCache.current.has(cacheKey)) {
|
|
3808
|
+
return separatorCache.current.get(cacheKey)!;
|
|
3809
|
+
}
|
|
3810
|
+
|
|
3811
|
+
const listLength = messagesContentListRef.current.length;
|
|
3812
|
+
|
|
3813
|
+
// Last item in small list
|
|
3814
|
+
if (index === listLength - 1 && listLength < SMALL_LIST_THRESHOLD) {
|
|
3815
|
+
separatorCache.current.set(cacheKey, true);
|
|
3816
|
+
return true;
|
|
3817
|
+
}
|
|
3818
|
+
|
|
3819
|
+
// Different days
|
|
3820
|
+
if (currentMs && nextMs) {
|
|
3821
|
+
const currentDate = new Date(currentMs).getDate();
|
|
3822
|
+
const nextDate = new Date(nextMs).getDate();
|
|
3823
|
+
const result = currentDate !== nextDate;
|
|
3824
|
+
separatorCache.current.set(cacheKey, result);
|
|
3825
|
+
return result;
|
|
3826
|
+
}
|
|
3827
|
+
|
|
3828
|
+
separatorCache.current.set(cacheKey, false);
|
|
3829
|
+
return false;
|
|
3830
|
+
}, []);
|
|
3831
|
+
|
|
3832
|
+
// Clear cache when messages change
|
|
3833
|
+
useEffect(() => {
|
|
3834
|
+
separatorCache.current.clear();
|
|
3835
|
+
}, [messagesList.length]);
|
|
3329
3836
|
|
|
3330
|
-
const getDayHeaderString = (ms?: number | undefined) => {
|
|
3837
|
+
const getDayHeaderString = useCallback((ms?: number | undefined) => {
|
|
3331
3838
|
if (!ms) return undefined;
|
|
3332
3839
|
if (isSameLocalDay(ms)) return t("TODAY") || "Today";
|
|
3333
3840
|
return dateSeparatorPattern ? dateSeparatorPattern(ms) : undefined;
|
|
3334
|
-
};
|
|
3841
|
+
}, [isSameLocalDay, t, dateSeparatorPattern]);
|
|
3335
3842
|
|
|
3336
3843
|
const RenderMessageItem = useCallback(
|
|
3337
3844
|
({
|
|
@@ -3345,38 +3852,47 @@ export const CometChatMessageList = memo(
|
|
|
3345
3852
|
}) => {
|
|
3346
3853
|
const index = idx;
|
|
3347
3854
|
lastMessageDate.current = getSentAtTimestamp(item);
|
|
3348
|
-
|
|
3349
3855
|
const id = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3350
3856
|
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : (item as any)?.muid;
|
|
3351
|
-
|
|
3352
3857
|
return (
|
|
3353
3858
|
<React.Fragment key={`${id}_${muid}`}>
|
|
3354
3859
|
<MessageView message={item} currentIndex={index} />
|
|
3355
3860
|
</React.Fragment>
|
|
3356
3861
|
);
|
|
3357
3862
|
},
|
|
3358
|
-
[
|
|
3863
|
+
[] // Empty dependencies - MessageView handles its own memoization
|
|
3359
3864
|
);
|
|
3360
3865
|
|
|
3361
3866
|
const keyExtractor = useCallback((item: any, index: number) => {
|
|
3362
3867
|
// Safely check if methods exist before calling them
|
|
3363
3868
|
const id = typeof item?.getId === 'function' ? item.getId() : item?.id;
|
|
3364
3869
|
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : item?.muid;
|
|
3870
|
+
|
|
3871
|
+
|
|
3872
|
+
// For stream messages in agentic mode, use a unique combination
|
|
3873
|
+
// to prevent duplicate keys when navigating between chat and history
|
|
3874
|
+
if (item?.isStreamMessage) {
|
|
3875
|
+
const targetId = item?.targetMessageId || '';
|
|
3876
|
+
return `stream_${id}_${targetId}_${index}`;
|
|
3877
|
+
}
|
|
3365
3878
|
|
|
3366
3879
|
// Use id + muid if both exist
|
|
3367
3880
|
if (id && muid) {
|
|
3368
3881
|
return `${id}_${muid}`;
|
|
3369
3882
|
}
|
|
3883
|
+
|
|
3370
3884
|
|
|
3371
3885
|
// Use muid if id doesn't exist (pending message)
|
|
3372
3886
|
if (muid) {
|
|
3373
3887
|
return `muid_${muid}`;
|
|
3374
3888
|
}
|
|
3889
|
+
|
|
3375
3890
|
|
|
3376
3891
|
// Use id if muid doesn't exist
|
|
3377
3892
|
if (id) {
|
|
3378
3893
|
return `id_${id}`;
|
|
3379
3894
|
}
|
|
3895
|
+
|
|
3380
3896
|
|
|
3381
3897
|
// Fallback to index if neither exist (should not happen, but prevents duplicates)
|
|
3382
3898
|
if (__DEV__) {
|
|
@@ -3385,7 +3901,7 @@ export const CometChatMessageList = memo(
|
|
|
3385
3901
|
return `index_${index}`;
|
|
3386
3902
|
}, []);
|
|
3387
3903
|
|
|
3388
|
-
const itemSeparator = useCallback(() => <View style={
|
|
3904
|
+
const itemSeparator = useCallback(() => <View style={staticStyles.itemSeparator} />, [staticStyles]);
|
|
3389
3905
|
|
|
3390
3906
|
const getAgentEmptyView = useCallback(() => {
|
|
3391
3907
|
if (!user) return <></>;
|
|
@@ -3406,45 +3922,23 @@ export const CometChatMessageList = memo(
|
|
|
3406
3922
|
|
|
3407
3923
|
return (
|
|
3408
3924
|
<ScrollView
|
|
3409
|
-
contentContainerStyle={
|
|
3410
|
-
flex: 1,
|
|
3411
|
-
justifyContent: "center",
|
|
3412
|
-
alignItems: "center",
|
|
3413
|
-
}}
|
|
3925
|
+
contentContainerStyle={staticStyles.emptyScrollView}
|
|
3414
3926
|
showsVerticalScrollIndicator={false}
|
|
3415
3927
|
>
|
|
3416
|
-
<View
|
|
3417
|
-
style={{
|
|
3418
|
-
alignItems: "center",
|
|
3419
|
-
justifyContent: "center",
|
|
3420
|
-
padding: 24,
|
|
3421
|
-
}}
|
|
3422
|
-
>
|
|
3928
|
+
<View style={staticStyles.emptyContainer}>
|
|
3423
3929
|
{emptyChatImageView || (
|
|
3424
3930
|
<CometChatAvatar
|
|
3425
3931
|
image={imageSource}
|
|
3426
3932
|
name={user.getName()}
|
|
3427
3933
|
style={{
|
|
3428
3934
|
containerStyle: {
|
|
3429
|
-
|
|
3430
|
-
height: 60,
|
|
3431
|
-
borderRadius: 40,
|
|
3432
|
-
marginBottom: 20,
|
|
3433
|
-
alignItems: "center",
|
|
3434
|
-
justifyContent: "center",
|
|
3935
|
+
...staticStyles.avatarContainer,
|
|
3435
3936
|
backgroundColor: mergedTheme.avatarStyle.containerStyle?.backgroundColor,
|
|
3436
3937
|
},
|
|
3437
|
-
imageStyle:
|
|
3438
|
-
width: 60,
|
|
3439
|
-
height: 60,
|
|
3440
|
-
borderRadius: 40,
|
|
3441
|
-
},
|
|
3938
|
+
imageStyle: staticStyles.avatarImage,
|
|
3442
3939
|
textStyle: {
|
|
3443
|
-
|
|
3444
|
-
fontWeight: "bold",
|
|
3940
|
+
...staticStyles.avatarText,
|
|
3445
3941
|
color: mergedTheme.avatarStyle.textStyle?.color,
|
|
3446
|
-
textAlign: "center",
|
|
3447
|
-
textAlignVertical: "center",
|
|
3448
3942
|
},
|
|
3449
3943
|
}}
|
|
3450
3944
|
/>
|
|
@@ -3627,28 +4121,37 @@ export const CometChatMessageList = memo(
|
|
|
3627
4121
|
if (group) {
|
|
3628
4122
|
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
3629
4123
|
}
|
|
3630
|
-
if (parentMessageId) {
|
|
3631
|
-
nextMessagesRequest = nextMessagesRequest.
|
|
4124
|
+
if (!parentMessageId) {
|
|
4125
|
+
nextMessagesRequest = nextMessagesRequest.hideReplies(true);
|
|
4126
|
+
}
|
|
4127
|
+
// Thread: Server includes only relevant messages
|
|
4128
|
+
else {
|
|
4129
|
+
nextMessagesRequest = nextMessagesRequest
|
|
4130
|
+
.setParentMessageId(Number(parentMessageId))
|
|
4131
|
+
.hideReplies(false);
|
|
4132
|
+
if (isAgenticUser) {
|
|
4133
|
+
nextMessagesRequest = nextMessagesRequest.withParent(true);
|
|
4134
|
+
}
|
|
3632
4135
|
}
|
|
3633
4136
|
|
|
3634
4137
|
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
3635
4138
|
if (nextMessages.length > 0) {
|
|
4139
|
+
|
|
3636
4140
|
const existingIds = new Set(messagesContentListRef.current.map(m => m.getId()));
|
|
3637
4141
|
const uniqueNewMessages = nextMessages.filter(m => !existingIds.has(m.getId()));
|
|
3638
|
-
|
|
4142
|
+
|
|
3639
4143
|
if (uniqueNewMessages.length > 0) {
|
|
3640
4144
|
const reversedNewMessages = uniqueNewMessages.reverse();
|
|
3641
4145
|
messagesContentListRef.current = [
|
|
3642
4146
|
...reversedNewMessages,
|
|
3643
4147
|
...messagesContentListRef.current
|
|
3644
4148
|
];
|
|
3645
|
-
|
|
4149
|
+
|
|
3646
4150
|
setMessagesList(messagesContentListRef.current);
|
|
3647
4151
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
3648
4152
|
}
|
|
3649
4153
|
} else {
|
|
3650
4154
|
setHasTargetMessageId(false);
|
|
3651
|
-
hasReachedBottomRef.current = true;
|
|
3652
4155
|
}
|
|
3653
4156
|
} catch (error) {
|
|
3654
4157
|
console.error('[fetchNextMessages] Error:', error);
|
|
@@ -3667,37 +4170,6 @@ export const CometChatMessageList = memo(
|
|
|
3667
4170
|
);
|
|
3668
4171
|
};
|
|
3669
4172
|
|
|
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
4173
|
const scrollHandler = (event: any) => {
|
|
3702
4174
|
/********************************************************************************
|
|
3703
4175
|
* layoutMeasurement.height: The height of the visible area within the ScrollView.
|
|
@@ -3709,12 +4181,6 @@ export const CometChatMessageList = memo(
|
|
|
3709
4181
|
* contentSize.height: The total height of the scrollable content.
|
|
3710
4182
|
*********************************************************************************/
|
|
3711
4183
|
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
4184
|
currentScrollPosition.current.y = contentOffset.y;
|
|
3719
4185
|
currentScrollPosition.current.contentHeight = contentSize.height;
|
|
3720
4186
|
|
|
@@ -3725,82 +4191,238 @@ export const CometChatMessageList = memo(
|
|
|
3725
4191
|
currentScrollPosition.current.scrollViewHeight = contentSize.height;
|
|
3726
4192
|
}
|
|
3727
4193
|
|
|
3728
|
-
|
|
3729
|
-
|
|
3730
|
-
|
|
4194
|
+
const nearBottom = isNearBottom();
|
|
4195
|
+
setHideScrollToBottomButton(nearBottom);
|
|
4196
|
+
|
|
4197
|
+
if (nearBottom && temporaryMessageListRef.current.length > 0) {
|
|
4198
|
+
// Merge temporary messages when scrolling near bottom
|
|
4199
|
+
messagesContentListRef.current = [
|
|
4200
|
+
...temporaryMessageListRef.current,
|
|
4201
|
+
...messagesContentListRef.current,
|
|
4202
|
+
];
|
|
4203
|
+
temporaryMessageListRef.current = [];
|
|
4204
|
+
|
|
4205
|
+
// Update latestMessageRef after merge
|
|
4206
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4207
|
+
latestMessageRef.current = messagesContentListRef.current[0];
|
|
4208
|
+
}
|
|
4209
|
+
|
|
4210
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
4211
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
4212
|
+
|
|
4213
|
+
setUnreadCount(0);
|
|
4214
|
+
|
|
4215
|
+
if (hasManuallyMarkedUnread) {
|
|
4216
|
+
setHasManuallyMarkedUnread(false);
|
|
4217
|
+
}
|
|
4218
|
+
|
|
4219
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4220
|
+
const latestMessage = messagesContentListRef.current[0];
|
|
4221
|
+
markMessageAsRead(latestMessage);
|
|
4222
|
+
}
|
|
4223
|
+
}
|
|
3731
4224
|
};
|
|
3732
4225
|
|
|
3733
4226
|
const scrollToBottom = useCallback((scrollToFirstUnread = false) => {
|
|
3734
|
-
|
|
4227
|
+
// Merge temporary messages when scrolling to bottom
|
|
4228
|
+
if (temporaryMessageListRef.current.length > 0) {
|
|
4229
|
+
messagesContentListRef.current = [
|
|
4230
|
+
...temporaryMessageListRef.current,
|
|
4231
|
+
...messagesContentListRef.current,
|
|
4232
|
+
];
|
|
4233
|
+
temporaryMessageListRef.current = [];
|
|
4234
|
+
|
|
4235
|
+
// Update latestMessageRef after merge
|
|
4236
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4237
|
+
latestMessageRef.current = messagesContentListRef.current[0];
|
|
4238
|
+
}
|
|
4239
|
+
|
|
4240
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
4241
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
4242
|
+
|
|
4243
|
+
if (hasManuallyMarkedUnread) {
|
|
4244
|
+
setHasManuallyMarkedUnread(false);
|
|
4245
|
+
}
|
|
4246
|
+
}
|
|
4247
|
+
|
|
4248
|
+
setUnreadCount(0);
|
|
4249
|
+
setHideScrollToBottomButton(true);
|
|
4250
|
+
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3735
4251
|
// Clear navigation flags
|
|
3736
4252
|
setHasTargetMessageId(false);
|
|
3737
4253
|
setHighlightedMessageId(null);
|
|
3738
|
-
|
|
4254
|
+
setHasManuallyMarkedUnread(false);
|
|
4255
|
+
|
|
4256
|
+
// Mark latest message as read if available
|
|
4257
|
+
if (messagesContentListRef.current.length > 0) {
|
|
4258
|
+
const latestMessage = messagesContentListRef.current[0];
|
|
4259
|
+
markMessageAsRead(latestMessage);
|
|
4260
|
+
}
|
|
4261
|
+
// setNavigatedFromSearch(false); // navigatedFromSearch is a prop, cannot set it
|
|
3739
4262
|
}, [hasTargetMessageId, messagesList.length]);
|
|
3740
4263
|
|
|
3741
|
-
|
|
3742
|
-
|
|
3743
|
-
|
|
4264
|
+
const handleScrollInternal = useCallback((event: any) => {
|
|
4265
|
+
scrollHandler(event);
|
|
4266
|
+
}, [scrollHandler]);
|
|
3744
4267
|
|
|
3745
|
-
|
|
3746
|
-
|
|
3747
|
-
|
|
3748
|
-
|
|
3749
|
-
|
|
3750
|
-
|
|
3751
|
-
|
|
3752
|
-
|
|
3753
|
-
|
|
3754
|
-
|
|
4268
|
+
|
|
4269
|
+
const handleScrollToIndexFailed = useCallback((error: any) => {
|
|
4270
|
+
|
|
4271
|
+
// Calculate dynamic average height from measured items
|
|
4272
|
+
const measuredItems = Array.from(itemPositions.values());
|
|
4273
|
+
let averageHeight = AVERAGE_ITEM_LENGTH;
|
|
4274
|
+
|
|
4275
|
+
if (measuredItems.length > 0) {
|
|
4276
|
+
const totalHeight = measuredItems.reduce((sum, item) => sum + item.height, 0);
|
|
4277
|
+
averageHeight = totalHeight / measuredItems.length;
|
|
4278
|
+
}
|
|
4279
|
+
|
|
4280
|
+
// Scroll to estimated position to load more items
|
|
4281
|
+
const targetOffset = error.index * averageHeight;
|
|
4282
|
+
|
|
4283
|
+
messageListRef.current?.scrollToOffset({
|
|
4284
|
+
offset: targetOffset,
|
|
4285
|
+
animated: true,
|
|
4286
|
+
});
|
|
4287
|
+
|
|
4288
|
+
// After scrolling to load more items, retry scrollToIndex
|
|
4289
|
+
setTimeout(() => {
|
|
4290
|
+
if (messageListRef.current) {
|
|
4291
|
+
try {
|
|
4292
|
+
messageListRef.current.scrollToIndex({
|
|
4293
|
+
index: error.index,
|
|
4294
|
+
animated: true,
|
|
4295
|
+
viewPosition: 0.5, // For inverted FlatList
|
|
4296
|
+
});
|
|
4297
|
+
} catch (retryError) {
|
|
4298
|
+
console.warn('Retry scrollToIndex also failed:', retryError);
|
|
3755
4299
|
}
|
|
3756
|
-
|
|
3757
|
-
|
|
4300
|
+
}
|
|
4301
|
+
}, 300); // Wait for items to load
|
|
4302
|
+
}, [itemPositions]);
|
|
4303
|
+
|
|
4304
|
+
|
|
4305
|
+
|
|
4306
|
+
// Clear item positions when messages list changes significantly
|
|
4307
|
+
// Don't clear on minor changes (like adding one message) or when navigating
|
|
4308
|
+
useEffect(() => {
|
|
4309
|
+
const lengthDiff = Math.abs(messagesList.length - prevMessagesLength.current);
|
|
4310
|
+
const isSignificantChange = lengthDiff > 5; // Only clear if 5+ messages added/removed
|
|
4311
|
+
|
|
4312
|
+
if (isSignificantChange) {
|
|
4313
|
+
setItemPositions(new Map());
|
|
4314
|
+
}
|
|
4315
|
+
|
|
4316
|
+
prevMessagesLength.current = messagesList.length;
|
|
4317
|
+
}, [messagesList.length]);
|
|
4318
|
+
|
|
4319
|
+
// Handle layout measurement for accurate scrolling
|
|
4320
|
+
const handleItemLayout = useCallback((event: any, messageId: string) => {
|
|
4321
|
+
const { y, height } = event.nativeEvent.layout;
|
|
4322
|
+
setItemPositions(prev => {
|
|
4323
|
+
const newMap = new Map(prev);
|
|
4324
|
+
newMap.set(messageId, { y, height });
|
|
4325
|
+
return newMap;
|
|
4326
|
+
});
|
|
4327
|
+
}, []);
|
|
4328
|
+
//
|
|
4329
|
+
// Configuration for determining when list items are considered "viewable" (visible on screen)
|
|
4330
|
+
// itemVisiblePercentThreshold: 50 means an item is viewable when at least 50% of it is visible
|
|
4331
|
+
// This is used by onViewableItemsChanged to detect when messages come into view for auto-read functionality
|
|
4332
|
+
const viewabilityConfig = useRef({
|
|
4333
|
+
itemVisiblePercentThreshold: 50,
|
|
4334
|
+
}).current;
|
|
4335
|
+
|
|
4336
|
+
// This function handles marking the conversation as read ONLY when the user scrolls
|
|
4337
|
+
// to the "New Message" indicator (the first unread message).
|
|
4338
|
+
// This preserves the unread count while the user is viewing searched messages.
|
|
4339
|
+
const handleViewableItemsChanged = useCallback(({ viewableItems }: any) => {
|
|
4340
|
+
if (navigatedFromSearch && newMessageIndicatorId && unreadCount > 0 && !hasManuallyMarkedUnread) {
|
|
4341
|
+
const indicatorItem = viewableItems.find(
|
|
4342
|
+
(item: any) => String(item.item.getId()) === newMessageIndicatorId
|
|
4343
|
+
);
|
|
4344
|
+
|
|
4345
|
+
if (indicatorItem) {
|
|
4346
|
+
if (user) {
|
|
4347
|
+
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
4348
|
+
console.log("Error marking user conversation as read", e);
|
|
4349
|
+
});
|
|
4350
|
+
} else if (group) {
|
|
4351
|
+
CometChat.markConversationAsRead(group.getGuid(), CometChat.RECEIVER_TYPE.GROUP).catch((e) => {
|
|
4352
|
+
console.log("Error marking group conversation as read", e);
|
|
4353
|
+
});
|
|
3758
4354
|
}
|
|
4355
|
+
setUnreadCount(0);
|
|
3759
4356
|
}
|
|
3760
|
-
|
|
4357
|
+
}
|
|
4358
|
+
}, [navigatedFromSearch, newMessageIndicatorId, unreadCount, user, group, hasManuallyMarkedUnread]);
|
|
4359
|
+
|
|
4360
|
+
|
|
4361
|
+
|
|
4362
|
+
// Optimized FlatList renderItem using memoized component
|
|
4363
|
+
const memoizedRenderItem = useCallback(
|
|
4364
|
+
({ item, index }: any) => {
|
|
4365
|
+
const nextItem = messagesContentListRef.current[index + 1];
|
|
4366
|
+
const currentItemMs = sentAtToMs(item);
|
|
4367
|
+
const nextItemMs = sentAtToMs(nextItem);
|
|
4368
|
+
const showSeparator = shouldShowSeparator(index, currentItemMs, nextItemMs);
|
|
4369
|
+
const ms = currentItemMs ?? Date.now();
|
|
3761
4370
|
const itemId = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3762
4371
|
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
|
-
};
|
|
4372
|
+
const dayHeaderString = getDayHeaderString(ms);
|
|
4373
|
+
// Show the "New Messages" indicator above a message if:
|
|
4374
|
+
// - startFromUnreadMessages is enabled (to indicate unread messages start here), OR
|
|
4375
|
+
// - showMarkAsUnreadOption is enabled (to show where a message was marked as unread)
|
|
4376
|
+
// - OR navigatedFromSearch is true (when navigating from search to unread messages)
|
|
4377
|
+
// - and this message matches the newMessageIndicatorId
|
|
4378
|
+
// - and NOT in agentic mode (agentic chats don't support unread indicators)
|
|
4379
|
+
const showNewMessageIndicator = !isAgenticUser && (startFromUnreadMessages || showMarkAsUnreadOption || navigatedFromSearch) && newMessageIndicatorId === String(item.getId());
|
|
3778
4380
|
|
|
3779
4381
|
return (
|
|
3780
|
-
<View
|
|
3781
|
-
|
|
3782
|
-
|
|
3783
|
-
|
|
3784
|
-
|
|
3785
|
-
{
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
3789
|
-
|
|
3790
|
-
|
|
3791
|
-
|
|
3792
|
-
|
|
3793
|
-
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
{
|
|
3797
|
-
|
|
4382
|
+
<View>
|
|
4383
|
+
<MessageListItem
|
|
4384
|
+
item={item}
|
|
4385
|
+
index={index}
|
|
4386
|
+
showSeparator={showSeparator}
|
|
4387
|
+
isHighlighted={isHighlighted}
|
|
4388
|
+
highlightAnimatedValue={highlightAnimatedValue}
|
|
4389
|
+
theme={mergedTheme}
|
|
4390
|
+
timestamp={ms}
|
|
4391
|
+
dayHeaderString={dayHeaderString}
|
|
4392
|
+
RenderMessageItem={RenderMessageItem}
|
|
4393
|
+
itemSeparator={itemSeparator}
|
|
4394
|
+
staticStyles={staticStyles}
|
|
4395
|
+
onLayout={handleItemLayout}
|
|
4396
|
+
showNewMessageIndicator={showNewMessageIndicator}
|
|
4397
|
+
NewMessageIndicatorView={NewMessageIndicatorView}
|
|
4398
|
+
newMessageIndicatorStyle={newMessageIndicatorStyle}
|
|
4399
|
+
newMessageIndicatorText={newMessageIndicatorText}
|
|
4400
|
+
/>
|
|
3798
4401
|
</View>
|
|
3799
4402
|
);
|
|
3800
4403
|
},
|
|
3801
|
-
[
|
|
4404
|
+
[
|
|
4405
|
+
mergedTheme,
|
|
4406
|
+
highlightedMessageId,
|
|
4407
|
+
highlightAnimatedValue,
|
|
4408
|
+
sentAtToMs,
|
|
4409
|
+
shouldShowSeparator,
|
|
4410
|
+
getDayHeaderString,
|
|
4411
|
+
itemSeparator,
|
|
4412
|
+
RenderMessageItem,
|
|
4413
|
+
handleItemLayout,
|
|
4414
|
+
newMessageIndicatorId,
|
|
4415
|
+
NewMessageIndicatorView,
|
|
4416
|
+
newMessageIndicatorStyle,
|
|
4417
|
+
newMessageIndicatorText,
|
|
4418
|
+
startFromUnreadMessages,
|
|
4419
|
+
showMarkAsUnreadOption,
|
|
4420
|
+
navigatedFromSearch,
|
|
4421
|
+
isAgenticUser
|
|
4422
|
+
]
|
|
3802
4423
|
);
|
|
3803
4424
|
|
|
4425
|
+
|
|
3804
4426
|
return (
|
|
3805
4427
|
<View style={mergedTheme.messageListStyles.containerStyle}>
|
|
3806
4428
|
{listState == "loading" && messagesList.length == 0 ? (
|
|
@@ -3830,45 +4452,40 @@ export const CometChatMessageList = memo(
|
|
|
3830
4452
|
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
3831
4453
|
</View>
|
|
3832
4454
|
)}
|
|
3833
|
-
|
|
3834
|
-
{/* Navigation loading for far message fetching */}
|
|
3835
|
-
{navigationLoading && getLoadingStateView()}
|
|
3836
4455
|
|
|
4456
|
+
{/* Navigation loading for far message fetching and scroll operations */}
|
|
4457
|
+
{navigationLoading&& (getLoadingStateView())}
|
|
3837
4458
|
<FlatList
|
|
3838
4459
|
showsVerticalScrollIndicator={false}
|
|
3839
4460
|
ref={messageListRef}
|
|
3840
|
-
onMomentumScrollEnd={
|
|
3841
|
-
onScroll={
|
|
4461
|
+
onMomentumScrollEnd={handleScrollInternal}
|
|
4462
|
+
onScroll={handleScrollInternal}
|
|
3842
4463
|
inverted={true}
|
|
3843
4464
|
maintainVisibleContentPosition={{
|
|
3844
4465
|
minIndexForVisible: 0,
|
|
3845
4466
|
}}
|
|
3846
|
-
onEndReached={getPreviousMessages}
|
|
3847
4467
|
onEndReachedThreshold={0.5}
|
|
4468
|
+
onEndReached={getPreviousMessages}
|
|
3848
4469
|
onStartReached={fetchNextMessages}
|
|
3849
4470
|
onStartReachedThreshold={0.5}
|
|
3850
4471
|
scrollEventThrottle={16}
|
|
3851
|
-
keyboardShouldPersistTaps={Platform.OS === "ios" ? "handled" : "always"}
|
|
4472
|
+
keyboardShouldPersistTaps={(Platform.OS === "ios" ? "handled" : "always") as "handled" | "always"}
|
|
3852
4473
|
data={messagesList}
|
|
3853
4474
|
keyExtractor={keyExtractor}
|
|
3854
4475
|
renderItem={memoizedRenderItem}
|
|
3855
|
-
onLayout={() => {
|
|
3856
|
-
setIsListLayoutComplete(true);
|
|
3857
|
-
}}
|
|
3858
4476
|
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}
|
|
4477
|
+
onScrollToIndexFailed={handleScrollToIndexFailed}
|
|
4478
|
+
viewabilityConfig={viewabilityConfig}
|
|
4479
|
+
onViewableItemsChanged={handleViewableItemsChanged}
|
|
4480
|
+
// Performance optimizations
|
|
4481
|
+
windowSize={10}
|
|
4482
|
+
removeClippedSubviews={Platform.OS === 'android'}
|
|
4483
|
+
maxToRenderPerBatch={5}
|
|
4484
|
+
updateCellsBatchingPeriod={100}
|
|
4485
|
+
initialNumToRender={15}
|
|
3870
4486
|
/>
|
|
3871
4487
|
|
|
4488
|
+
|
|
3872
4489
|
{CustomListHeader && <CustomListHeader />}
|
|
3873
4490
|
{ongoingCallView}
|
|
3874
4491
|
{FooterView && (
|
|
@@ -3916,32 +4533,24 @@ export const CometChatMessageList = memo(
|
|
|
3916
4533
|
</Pressable>
|
|
3917
4534
|
)}
|
|
3918
4535
|
|
|
3919
|
-
<
|
|
3920
|
-
|
|
3921
|
-
|
|
3922
|
-
|
|
3923
|
-
|
|
3924
|
-
|
|
3925
|
-
|
|
3926
|
-
|
|
3927
|
-
|
|
4536
|
+
<MessageModals
|
|
4537
|
+
showDeleteModal={showDeleteModal}
|
|
4538
|
+
showReportDialog={showReportDialog}
|
|
4539
|
+
deleteItem={deleteItem}
|
|
4540
|
+
reportedMessageRef={reportedMessageRef}
|
|
4541
|
+
theme={theme}
|
|
4542
|
+
hideFlagRemarkField={hideFlagRemarkField}
|
|
4543
|
+
t={t}
|
|
4544
|
+
onDeleteCancel={() => {
|
|
3928
4545
|
deleteItem.current = undefined;
|
|
3929
4546
|
setShowDeleteModal(false);
|
|
3930
4547
|
}}
|
|
3931
|
-
|
|
3932
|
-
|
|
3933
|
-
}}
|
|
3934
|
-
/>
|
|
3935
|
-
|
|
3936
|
-
<CometChatReportDialog
|
|
3937
|
-
isOpen={showReportDialog}
|
|
3938
|
-
message={reportedMessageRef.current || undefined}
|
|
3939
|
-
onCancel={() => {
|
|
4548
|
+
onDeleteConfirm={deleteMessage}
|
|
4549
|
+
onReportCancel={() => {
|
|
3940
4550
|
setShowReportDialog(false);
|
|
3941
4551
|
reportedMessageRef.current = null;
|
|
3942
4552
|
}}
|
|
3943
|
-
|
|
3944
|
-
onReport={(payload) => {
|
|
4553
|
+
onReportSubmit={(payload) => {
|
|
3945
4554
|
console.log("Report submitted", {
|
|
3946
4555
|
messageId: payload.message?.getId?.(),
|
|
3947
4556
|
payload,
|
|
@@ -3951,116 +4560,128 @@ export const CometChatMessageList = memo(
|
|
|
3951
4560
|
}}
|
|
3952
4561
|
/>
|
|
3953
4562
|
|
|
3954
|
-
<
|
|
3955
|
-
|
|
4563
|
+
<MessageOptionsSheet
|
|
4564
|
+
bottomSheetRef={bottomSheetRef}
|
|
4565
|
+
isOpen={showMessageOptions.length > 0 || Boolean(ExtensionsComponent) || messageInfo}
|
|
4566
|
+
showMessageOptions={showMessageOptions}
|
|
4567
|
+
ExtensionsComponent={ExtensionsComponent}
|
|
4568
|
+
messageInfo={messageInfo}
|
|
4569
|
+
infoObject={infoObject}
|
|
4570
|
+
selectedMessage={selectedMessage}
|
|
4571
|
+
hideReactionOption={hideReactionOption}
|
|
4572
|
+
quickReactionList={quickReactionList as [string, string?, string?, string?, string?]}
|
|
4573
|
+
templatesMap={templatesMap}
|
|
4574
|
+
mergedTheme={mergedTheme}
|
|
4575
|
+
deleteItem={deleteItem}
|
|
4576
|
+
pendingReportRef={pendingReportRef}
|
|
3956
4577
|
onClose={() => {
|
|
3957
4578
|
if (ExtensionsComponent) setExtensionsComponent(null);
|
|
3958
4579
|
setShowMessageOptions([]);
|
|
3959
4580
|
infoObject.current = null;
|
|
3960
4581
|
setMessageInfo(false);
|
|
3961
4582
|
}}
|
|
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>
|
|
4583
|
+
onReactionPress={reactToMessage}
|
|
4584
|
+
onAddReactionPress={onAddReactionPress}
|
|
4585
|
+
setShowDeleteModal={setShowDeleteModal}
|
|
4586
|
+
setShowReportDialog={setShowReportDialog}
|
|
4587
|
+
setShowMessageOptions={setShowMessageOptions}
|
|
4588
|
+
setExtensionsComponent={setExtensionsComponent}
|
|
4589
|
+
setMessageInfo={setMessageInfo}
|
|
4590
|
+
setShowEmojiKeyboard={setShowEmojiKeyboard}
|
|
4591
|
+
/>
|
|
4039
4592
|
|
|
4040
|
-
<
|
|
4041
|
-
|
|
4042
|
-
|
|
4593
|
+
<ReactionModals
|
|
4594
|
+
showEmojiKeyboard={showEmojiKeyboard}
|
|
4595
|
+
showReactionList={showReactionList}
|
|
4596
|
+
selectedMessage={selectedMessage}
|
|
4597
|
+
selectedEmoji={selectedEmoji}
|
|
4598
|
+
reactionsRequestBuilder={reactionsRequestBuilder}
|
|
4599
|
+
onReactionListItemPress={onReactionListItemPressProp}
|
|
4600
|
+
onEmojiSelect={reactToMessage}
|
|
4601
|
+
onEmojiKeyboardClose={() => setShowEmojiKeyboard(false)}
|
|
4602
|
+
onReactionListClose={() => {
|
|
4043
4603
|
setShowReactionList(false);
|
|
4044
4604
|
setSelectedEmoji(undefined);
|
|
4045
4605
|
}}
|
|
4046
|
-
|
|
4047
|
-
|
|
4048
|
-
|
|
4606
|
+
onReactionListEmpty={() => {
|
|
4607
|
+
setShowReactionList(false);
|
|
4608
|
+
setSelectedEmoji(undefined);
|
|
4049
4609
|
}}
|
|
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>
|
|
4610
|
+
/>
|
|
4062
4611
|
</View>
|
|
4063
4612
|
);
|
|
4613
|
+
|
|
4064
4614
|
}
|
|
4065
4615
|
)
|
|
4066
4616
|
);
|
|
4617
|
+
|
|
4618
|
+
|
|
4619
|
+
const staticStyles = StyleSheet.create({
|
|
4620
|
+
container: {
|
|
4621
|
+
flex: 1,
|
|
4622
|
+
paddingHorizontal: 16,
|
|
4623
|
+
paddingVertical: 8,
|
|
4624
|
+
position: 'relative' as 'relative',
|
|
4625
|
+
},
|
|
4626
|
+
contentWrapper: {
|
|
4627
|
+
position: 'relative' as 'relative',
|
|
4628
|
+
zIndex: 2,
|
|
4629
|
+
},
|
|
4630
|
+
separatorContainer: {
|
|
4631
|
+
alignItems: 'center' as 'center',
|
|
4632
|
+
marginBottom: 8,
|
|
4633
|
+
},
|
|
4634
|
+
footerContainer: {
|
|
4635
|
+
padding: 10,
|
|
4636
|
+
alignItems: 'center' as 'center',
|
|
4637
|
+
},
|
|
4638
|
+
itemSeparator: {
|
|
4639
|
+
height: 8,
|
|
4640
|
+
},
|
|
4641
|
+
loadingContainer: {
|
|
4642
|
+
padding: 16,
|
|
4643
|
+
},
|
|
4644
|
+
listContainer: {
|
|
4645
|
+
height: '100%',
|
|
4646
|
+
width: '100%',
|
|
4647
|
+
},
|
|
4648
|
+
headerContainer: {
|
|
4649
|
+
top: 0,
|
|
4650
|
+
},
|
|
4651
|
+
activityIndicatorContainer: {
|
|
4652
|
+
position: 'absolute' as 'absolute',
|
|
4653
|
+
alignSelf: 'center' as 'center',
|
|
4654
|
+
},
|
|
4655
|
+
flexOne: {
|
|
4656
|
+
flex: 1,
|
|
4657
|
+
},
|
|
4658
|
+
emptyScrollView: {
|
|
4659
|
+
flex: 1,
|
|
4660
|
+
justifyContent: "center",
|
|
4661
|
+
alignItems: "center",
|
|
4662
|
+
},
|
|
4663
|
+
emptyContainer: {
|
|
4664
|
+
alignItems: "center",
|
|
4665
|
+
justifyContent: "center",
|
|
4666
|
+
padding: 24,
|
|
4667
|
+
},
|
|
4668
|
+
avatarContainer: {
|
|
4669
|
+
width: 60,
|
|
4670
|
+
height: 60,
|
|
4671
|
+
borderRadius: 40,
|
|
4672
|
+
marginBottom: 20,
|
|
4673
|
+
alignItems: "center",
|
|
4674
|
+
justifyContent: "center",
|
|
4675
|
+
},
|
|
4676
|
+
avatarImage: {
|
|
4677
|
+
width: 60,
|
|
4678
|
+
height: 60,
|
|
4679
|
+
borderRadius: 40,
|
|
4680
|
+
},
|
|
4681
|
+
avatarText: {
|
|
4682
|
+
fontSize: 32,
|
|
4683
|
+
fontWeight: "bold",
|
|
4684
|
+
textAlign: "center",
|
|
4685
|
+
textAlignVertical: "center",
|
|
4686
|
+
},
|
|
4687
|
+
})//30/dec/2025 6.48pm
|