@cometchat/chat-uikit-react-native 5.3.5 → 5.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +18 -1
- package/ios/FileManager.m +14 -3
- package/ios/SoundPlayer.m +24 -1
- package/package.json +2 -1
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +8 -3
- package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +14 -11
- package/src/CometChatConversations/CometChatConversations.tsx +89 -51
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +10 -11
- package/src/CometChatGroups/CometChatGroups.tsx +49 -42
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +10 -7
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +12 -10
- package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +4 -3
- package/src/CometChatMessageList/CometChatMessageList.tsx +398 -144
- package/src/CometChatMessageList/PERFORMANCE_ARCHITECTURE.md +478 -0
- package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
- package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +4 -1
- package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +811 -0
- package/src/CometChatNotificationFeed/Skeleton.tsx +43 -0
- package/src/CometChatNotificationFeed/index.ts +19 -0
- package/src/CometChatNotificationFeed/style.ts +333 -0
- package/src/CometChatNotificationFeed/utils.ts +124 -0
- package/src/CometChatSearch/CometChatSearch.tsx +8 -6
- package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +4 -3
- package/src/CometChatUsers/CometChatUsers.tsx +56 -43
- package/src/calls/CallingExtensionDecorator.tsx +1 -1
- package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -2
- package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +7 -6
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -1
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -1
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +4 -4
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +5 -3
- package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
- package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -5
- package/src/extensions/Polls/PollsBubble.tsx +1 -1
- package/src/extensions/Polls/PollsDecorator.tsx +1 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -2
- package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +9 -5
- package/src/index.ts +7 -0
- package/src/shared/CometChatUiKit/CometChatUIKit.ts +48 -20
- package/src/shared/events/ListenerInitializer.ts +2 -1
- package/src/shared/framework/MessageDataSource.tsx +19 -15
- package/src/shared/helper/helperFunctions.ts +5 -4
- package/src/shared/icons/components/notification-empty.tsx +27 -0
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +8 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +8 -1
- package/src/shared/services/stream-message.service.ts +0 -1
- package/src/shared/utils/CommonUtils.ts +1 -1
- package/src/shared/utils/MessageUtils.tsx +15 -13
- package/src/shared/utils/conversationUtils.ts +2 -2
- package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +2 -2
- package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +17 -5
- package/src/shared/views/CometChatList/CometChatList.tsx +11 -15
- package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +3 -3
- package/src/shared/views/CometChatReactions/CometChatReactions.tsx +2 -1
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +15 -4
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -3
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +15 -1
- package/src/theme/default/default.ts +6 -0
- package/src/theme/provider.tsx +12 -12
- package/src/theme/type.ts +2 -0
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
let __listenerIdCounter = 0;
|
|
1
2
|
import { CometChat } from "@cometchat/chat-sdk-react-native";
|
|
2
3
|
import Clipboard from "@react-native-clipboard/clipboard";
|
|
3
4
|
import React, {
|
|
@@ -109,6 +110,22 @@ let _defaultRequestBuilder: CometChat.MessagesRequestBuilder;
|
|
|
109
110
|
const SEPARATOR_HEIGHT = 40;
|
|
110
111
|
const AVERAGE_ITEM_LENGTH = 120;
|
|
111
112
|
const SMALL_LIST_THRESHOLD = 30;
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Module-level flag to skip auto-loading the last agent conversation.
|
|
116
|
+
* Set to true by `skipNextAgentAutoLoad()` (called by "New Chat" button).
|
|
117
|
+
* Consumed and cleared on the next message list mount.
|
|
118
|
+
*/
|
|
119
|
+
let _skipAgentAutoLoad = false;
|
|
120
|
+
|
|
121
|
+
/**
|
|
122
|
+
* Call this before remounting the message list to prevent it from
|
|
123
|
+
* auto-loading the last agent conversation. Used by the "New Chat" button
|
|
124
|
+
* to ensure a fresh empty state on remount.
|
|
125
|
+
*/
|
|
126
|
+
export function skipNextAgentAutoLoad(): void {
|
|
127
|
+
_skipAgentAutoLoad = true;
|
|
128
|
+
}
|
|
112
129
|
/**
|
|
113
130
|
* Helper function to safely get message ID
|
|
114
131
|
* Prevents "undefined is not a function" errors in release builds
|
|
@@ -504,6 +521,13 @@ export interface CometChatMessageListProps {
|
|
|
504
521
|
* and maintain their unread message state for later review.
|
|
505
522
|
*/
|
|
506
523
|
navigatedFromSearch?: boolean;
|
|
524
|
+
/**
|
|
525
|
+
* If true, the message list will automatically load the most recent agent conversation
|
|
526
|
+
* on mount (only applies to @agentic users). When false or omitted, a new agent chat
|
|
527
|
+
* is started each time (current default behavior).
|
|
528
|
+
* @defaultValue false
|
|
529
|
+
*/
|
|
530
|
+
loadLastAgentConversation?: boolean;
|
|
507
531
|
}
|
|
508
532
|
|
|
509
533
|
/**
|
|
@@ -628,6 +652,7 @@ export const CometChatMessageList = memo(
|
|
|
628
652
|
NewMessageIndicatorView,
|
|
629
653
|
newMessageIndicatorStyle,
|
|
630
654
|
newMessageIndicatorText,
|
|
655
|
+
loadLastAgentConversation = false,
|
|
631
656
|
} = props;
|
|
632
657
|
|
|
633
658
|
// Helper to check if user is agentic - memoized as boolean for performance
|
|
@@ -650,17 +675,17 @@ export const CometChatMessageList = memo(
|
|
|
650
675
|
const hideFlagMessageOption = isAgenticUser ? true : propHideFlagMessageOption;
|
|
651
676
|
const hideMarkAsUnreadOption = (isAgenticUser || !!parentMessageId) ? true : !showMarkAsUnreadOption;//hide for threads and agentic users
|
|
652
677
|
|
|
653
|
-
const callListenerId = "call_" +
|
|
678
|
+
const callListenerId = "call_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
654
679
|
const effectiveHideModeration = hideModerationStatus;
|
|
655
|
-
const groupListenerId = "group_" +
|
|
656
|
-
const uiEventListener = "uiEvent_" +
|
|
657
|
-
const callEventListener = "callEvent_" +
|
|
658
|
-
const uiEventListenerShow = "uiEvent_show_" +
|
|
659
|
-
const uiEventListenerHide = "uiEvent_hide_" +
|
|
660
|
-
const connectionListenerId = "connectionListener_" +
|
|
661
|
-
const messageEventListener = "messageEvent_" +
|
|
662
|
-
const groupEventListener = "groupEvent_" +
|
|
663
|
-
const streamListenerId = "agent_" +
|
|
680
|
+
const groupListenerId = "group_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
681
|
+
const uiEventListener = "uiEvent_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
682
|
+
const callEventListener = "callEvent_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
683
|
+
const uiEventListenerShow = "uiEvent_show_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
684
|
+
const uiEventListenerHide = "uiEvent_hide_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
685
|
+
const connectionListenerId = "connectionListener_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
686
|
+
const messageEventListener = "messageEvent_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
687
|
+
const groupEventListener = "groupEvent_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
688
|
+
const streamListenerId = "agent_" + Date.now() + "_" + (++__listenerIdCounter);
|
|
664
689
|
const deleteItem = useRef<CometChat.BaseMessage>(undefined);
|
|
665
690
|
const shouldSuppressHighlightRef = useRef(false);
|
|
666
691
|
|
|
@@ -897,18 +922,20 @@ export const CometChatMessageList = memo(
|
|
|
897
922
|
const messagesLength = useRef(0); // Tracks total message count to detect additions/updates
|
|
898
923
|
const prevMessagesLength = useRef(0); // Tracks previous message count to handle scroll position adjustments when loading history
|
|
899
924
|
const messageListRef = useRef<FlatList | null>(null); // Reference to the FlatList for programmatic scrolling
|
|
900
|
-
const loggedInUser = useRef<CometChat.User | null
|
|
925
|
+
const loggedInUser = useRef<CometChat.User | null>(null); // Stores current user to check sender identity (me vs others)
|
|
901
926
|
const messageRequest = useRef<CometChat.MessagesRequest | null>(null); // Manages pagination state for fetching messages
|
|
902
927
|
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.
|
|
903
928
|
const temporaryMessageListRef = useRef<any[]>([]); // "Waiting Room": Buffer for new messages arriving while scrolled up. Prevents UI jumps/insertions while reading history.
|
|
904
929
|
|
|
905
930
|
const msgRequestBuilder = useRef<CometChat.MessagesRequestBuilder>(undefined);
|
|
906
|
-
const lastMessageDate = useRef(
|
|
931
|
+
const lastMessageDate = useRef(Date.now());
|
|
907
932
|
|
|
908
933
|
// states
|
|
909
|
-
const [messagesList, setMessagesList] = useState<any[]>([]);
|
|
934
|
+
const [messagesList, setMessagesList] = useState<any[]>([]);
|
|
910
935
|
const [listState, setListState] = useState(
|
|
911
|
-
isAgenticUser && !parentMessageId
|
|
936
|
+
isAgenticUser && !parentMessageId
|
|
937
|
+
? (loadLastAgentConversation && !_skipAgentAutoLoad ? "loading" : "loaded")
|
|
938
|
+
: "loading"
|
|
912
939
|
);
|
|
913
940
|
const [loadingMessages, setLoadingMessages] = useState(false);
|
|
914
941
|
/** this is required to prevent duplicate api calls. Cannot use state for this since this is being used in scrollHandler **/
|
|
@@ -1035,8 +1062,8 @@ export const CometChatMessageList = memo(
|
|
|
1035
1062
|
return;
|
|
1036
1063
|
}
|
|
1037
1064
|
loadingPrevMessagesRef.current = true;
|
|
1038
|
-
// For agent chats
|
|
1039
|
-
if (isAgenticUser && !parentMessageId) {
|
|
1065
|
+
// For agent chats with no conversation loaded, don't fetch previous messages
|
|
1066
|
+
if (isAgenticUser && !parentMessageId && !agenticParentMessageIdRef.current) {
|
|
1040
1067
|
return;
|
|
1041
1068
|
}
|
|
1042
1069
|
|
|
@@ -1053,22 +1080,53 @@ export const CometChatMessageList = memo(
|
|
|
1053
1080
|
setLoadingMessages(true);
|
|
1054
1081
|
loadingMessagesRef.current = true;
|
|
1055
1082
|
}
|
|
1056
|
-
//
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1083
|
+
// Fixed: Previously passed undefined GUID to getGroup() which always failed.
|
|
1084
|
+
// Now we skip the scope fetch entirely when GUID is missing — the scope
|
|
1085
|
+
// will be populated when the group data arrives from a valid source.
|
|
1086
|
+
if (group != undefined && !group.getGuid()) {
|
|
1087
|
+
console.warn("[CometChatMessageList] Group has no GUID — skipping scope fetch.");
|
|
1088
|
+
} else if (group != undefined && group.getGuid() && !group.getScope()) {
|
|
1089
|
+
try {
|
|
1090
|
+
const fetchedGroup = await CometChat.getGroup(group.getGuid());
|
|
1091
|
+
if (fetchedGroup) {
|
|
1092
|
+
group.setScope(fetchedGroup.getScope?.() ?? "participant");
|
|
1093
|
+
}
|
|
1094
|
+
} catch (e: any) {
|
|
1095
|
+
console.warn("[CometChatMessageList] Failed to fetch group scope:", e);
|
|
1060
1096
|
onError && onError(e);
|
|
1061
|
-
}
|
|
1062
|
-
group.setScope(fetchedGroup["scope"]);
|
|
1097
|
+
}
|
|
1063
1098
|
}
|
|
1064
|
-
messageRequest.current
|
|
1099
|
+
return messageRequest.current
|
|
1065
1100
|
?.fetchPrevious()
|
|
1066
1101
|
.then((msgs: any[]) => {
|
|
1067
|
-
if (messageRequest.current
|
|
1102
|
+
if ((messageRequest.current?.getLimit() ?? 0) > msgs.length) {
|
|
1068
1103
|
reachedFirstMessage.current = true;
|
|
1069
1104
|
}
|
|
1070
1105
|
let previousMessagesFetched = [...msgs].reverse(); // Reverse for UI use
|
|
1071
1106
|
|
|
1107
|
+
// For agentic users with parentMessageId: the server returns the parent
|
|
1108
|
+
// message (via withParent) at the END of the array, out of chronological order.
|
|
1109
|
+
// Sort by ID to restore correct order (higher ID = newer message = first in inverted list).
|
|
1110
|
+
if (isAgenticUser && parentMessageId) {
|
|
1111
|
+
previousMessagesFetched.sort((a, b) => {
|
|
1112
|
+
const aId = Number(typeof a.getId === 'function' ? a.getId() : 0);
|
|
1113
|
+
const bId = Number(typeof b.getId === 'function' ? b.getId() : 0);
|
|
1114
|
+
return bId - aId;
|
|
1115
|
+
});
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// Deduplicate within the batch for agentic users
|
|
1119
|
+
// (withParent can include parent as both the thread parent and a reply)
|
|
1120
|
+
if (isAgenticUser) {
|
|
1121
|
+
const seenIds = new Set<number>();
|
|
1122
|
+
previousMessagesFetched = previousMessagesFetched.filter((msg) => {
|
|
1123
|
+
const msgId = Number(typeof msg.getId === 'function' ? msg.getId() : (msg as any)?.id);
|
|
1124
|
+
if (!msgId || seenIds.has(msgId)) return false;
|
|
1125
|
+
seenIds.add(msgId);
|
|
1126
|
+
return true;
|
|
1127
|
+
});
|
|
1128
|
+
}
|
|
1129
|
+
|
|
1072
1130
|
if (messagesList.length === 0 && msgs?.length > 0) {
|
|
1073
1131
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccActiveChatChanged, {
|
|
1074
1132
|
message: previousMessagesFetched[0],
|
|
@@ -1097,7 +1155,7 @@ export const CometChatMessageList = memo(
|
|
|
1097
1155
|
if (!goToMessageId && messagesList.length === 0) {
|
|
1098
1156
|
// If we are not navigating to a specific message, we want to show the new message indicator
|
|
1099
1157
|
// above the oldest unread message (which is the last one in the fetched list since it's reversed).
|
|
1100
|
-
const oldestMessage = previousMessagesFetched[previousMessagesFetched.length];
|
|
1158
|
+
const oldestMessage = previousMessagesFetched[previousMessagesFetched.length - 1];
|
|
1101
1159
|
|
|
1102
1160
|
if (oldestMessage) {
|
|
1103
1161
|
const msgId = safeGetId(oldestMessage);
|
|
@@ -1110,17 +1168,9 @@ export const CometChatMessageList = memo(
|
|
|
1110
1168
|
// Only mark conversation as read on initial load.
|
|
1111
1169
|
// If we do this on every fetch (pagination), it would reset the unread count
|
|
1112
1170
|
// even if the user manually marked a message as unread.
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
//marking most recent unread message as read
|
|
1117
|
-
// Use markAsRead on the latest message instead of markConversationAsRead
|
|
1118
|
-
// to avoid marking thread replies as read when user only opens the main chat.
|
|
1119
|
-
if (!parentMessageId && lastMessage) {
|
|
1120
|
-
CometChat.markAsRead(lastMessage).catch((e: any) => {
|
|
1121
|
-
console.log("Error marking message as read", e);
|
|
1122
|
-
});
|
|
1123
|
-
} else if (user) {
|
|
1171
|
+
if (messagesContentListRef.current.length === 0 && !navigatedFromSearch) {
|
|
1172
|
+
// Mark entire conversation as read — clears unread count on server
|
|
1173
|
+
if (user) {
|
|
1124
1174
|
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1125
1175
|
console.log("Error marking user conversation as read", e);
|
|
1126
1176
|
});
|
|
@@ -1130,6 +1180,7 @@ export const CometChatMessageList = memo(
|
|
|
1130
1180
|
});
|
|
1131
1181
|
}
|
|
1132
1182
|
setUnreadCount(0);
|
|
1183
|
+
setNewMessageIndicatorId(null);
|
|
1133
1184
|
//emitting event to update read receipts in other components
|
|
1134
1185
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
1135
1186
|
message: lastMessage,
|
|
@@ -1166,10 +1217,24 @@ export const CometChatMessageList = memo(
|
|
|
1166
1217
|
}
|
|
1167
1218
|
);
|
|
1168
1219
|
if (previousMessagesFetched.length > 0) {
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1220
|
+
// For agentic users, deduplicate across batches to prevent duplicate keys
|
|
1221
|
+
if (isAgenticUser && messagesContentListRef.current.length > 0) {
|
|
1222
|
+
const existingIds = new Set(
|
|
1223
|
+
messagesContentListRef.current.map((msg) =>
|
|
1224
|
+
Number(typeof msg.getId === 'function' ? msg.getId() : (msg as any)?.id)
|
|
1225
|
+
)
|
|
1226
|
+
);
|
|
1227
|
+
previousMessagesFetched = previousMessagesFetched.filter((msg) => {
|
|
1228
|
+
const msgId = Number(typeof msg.getId === 'function' ? msg.getId() : (msg as any)?.id);
|
|
1229
|
+
return !msgId || !existingIds.has(msgId);
|
|
1230
|
+
});
|
|
1231
|
+
}
|
|
1232
|
+
if (previousMessagesFetched.length > 0) {
|
|
1233
|
+
messagesContentListRef.current = [
|
|
1234
|
+
...messagesContentListRef.current,
|
|
1235
|
+
...previousMessagesFetched,
|
|
1236
|
+
];
|
|
1237
|
+
}
|
|
1173
1238
|
setMessagesList(messagesContentListRef.current);
|
|
1174
1239
|
}
|
|
1175
1240
|
if (messagesContentListRef.current.length == 0) {
|
|
@@ -1219,7 +1284,7 @@ export const CometChatMessageList = memo(
|
|
|
1219
1284
|
return;
|
|
1220
1285
|
}
|
|
1221
1286
|
|
|
1222
|
-
if (isAgenticUser && !parentMessageId) {
|
|
1287
|
+
if (isAgenticUser && !parentMessageId && !agenticParentMessageIdRef.current) {
|
|
1223
1288
|
return;
|
|
1224
1289
|
}
|
|
1225
1290
|
|
|
@@ -1310,14 +1375,8 @@ export const CometChatMessageList = memo(
|
|
|
1310
1375
|
// as the user might want to keep messages unread for reference.
|
|
1311
1376
|
if (startFromUnreadMessages && isInitialLoad && !navigatedFromSearch && !goToMessageId) {
|
|
1312
1377
|
shouldSuppressHighlightRef.current = true;
|
|
1313
|
-
//
|
|
1314
|
-
|
|
1315
|
-
// to avoid marking thread replies as read when user only opens the main chat.
|
|
1316
|
-
if (!parentMessageId && uniqueMessages[0]) {
|
|
1317
|
-
CometChat.markAsRead(uniqueMessages[0]).catch((e: any) => {
|
|
1318
|
-
console.log("Error marking message as read", e);
|
|
1319
|
-
});
|
|
1320
|
-
} else if (user) {
|
|
1378
|
+
// Mark entire conversation as read — clears unread count on server
|
|
1379
|
+
if (user) {
|
|
1321
1380
|
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
1322
1381
|
console.log("Error marking user conversation as read", e);
|
|
1323
1382
|
});
|
|
@@ -1489,8 +1548,8 @@ export const CometChatMessageList = memo(
|
|
|
1489
1548
|
};
|
|
1490
1549
|
|
|
1491
1550
|
const getUpdatedPreviousMessages = () => {
|
|
1492
|
-
// For agent chats
|
|
1493
|
-
if (isAgenticUser && !parentMessageId) {
|
|
1551
|
+
// For agent chats with no conversation loaded, don't fetch updated previous messages
|
|
1552
|
+
if (isAgenticUser && !parentMessageId && !agenticParentMessageIdRef.current) {
|
|
1494
1553
|
return;
|
|
1495
1554
|
}
|
|
1496
1555
|
|
|
@@ -1547,7 +1606,7 @@ export const CometChatMessageList = memo(
|
|
|
1547
1606
|
setMessagesList(tmpList);
|
|
1548
1607
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1549
1608
|
for (let i = 0; i < newMessages.length; i++) {
|
|
1550
|
-
if (newMessages[i].getSender()
|
|
1609
|
+
if (newMessages[i].getSender()?.getUid() !== loggedInUser.current?.getUid()) {
|
|
1551
1610
|
bottomHandler(newMessages[i], true, true);
|
|
1552
1611
|
break;
|
|
1553
1612
|
}
|
|
@@ -1658,7 +1717,7 @@ export const CometChatMessageList = memo(
|
|
|
1658
1717
|
|
|
1659
1718
|
let allFormatters = [...(textFormatters || [])];
|
|
1660
1719
|
let mentionsTextFormatter = ChatConfigurator.getDataSource().getMentionsFormatter(
|
|
1661
|
-
loggedInUser.current
|
|
1720
|
+
loggedInUser.current ?? undefined
|
|
1662
1721
|
);
|
|
1663
1722
|
allFormatters.push(mentionsTextFormatter);
|
|
1664
1723
|
|
|
@@ -1849,7 +1908,7 @@ export const CometChatMessageList = memo(
|
|
|
1849
1908
|
}
|
|
1850
1909
|
|
|
1851
1910
|
if (isAgenticUser) {
|
|
1852
|
-
if (
|
|
1911
|
+
if (agenticParentMessageIdRef.current) {
|
|
1853
1912
|
return (
|
|
1854
1913
|
message.getParentMessageId &&
|
|
1855
1914
|
String(message.getParentMessageId()) === String(agenticParentMessageIdRef.current)
|
|
@@ -1971,6 +2030,19 @@ export const CometChatMessageList = memo(
|
|
|
1971
2030
|
return;
|
|
1972
2031
|
}
|
|
1973
2032
|
|
|
2033
|
+
// Thread mismatch check — must run BEFORE the sender check to prevent
|
|
2034
|
+
// messages from appearing in the wrong context (main list vs thread)
|
|
2035
|
+
// when the same user is logged in on multiple devices.
|
|
2036
|
+
if (
|
|
2037
|
+
(!parentMessageId && newMessage.getParentMessageId()) ||
|
|
2038
|
+
(parentMessageId && !newMessage.getParentMessageId()) ||
|
|
2039
|
+
(parentMessageId &&
|
|
2040
|
+
newMessage.getParentMessageId() &&
|
|
2041
|
+
parentMessageId != newMessage.getParentMessageId())
|
|
2042
|
+
) {
|
|
2043
|
+
return;
|
|
2044
|
+
}
|
|
2045
|
+
|
|
1974
2046
|
if (
|
|
1975
2047
|
(newMessage.getSender()?.getUid() || newMessage?.["sender"]?.["uid"]) ==
|
|
1976
2048
|
loggedInUser.current?.["uid"]
|
|
@@ -1984,15 +2056,6 @@ export const CometChatMessageList = memo(
|
|
|
1984
2056
|
if (!isReceived) {
|
|
1985
2057
|
return;
|
|
1986
2058
|
}
|
|
1987
|
-
if (
|
|
1988
|
-
(!parentMessageId && newMessage.getParentMessageId()) ||
|
|
1989
|
-
(parentMessageId && !newMessage.getParentMessageId()) ||
|
|
1990
|
-
(parentMessageId &&
|
|
1991
|
-
newMessage.getParentMessageId() &&
|
|
1992
|
-
parentMessageId != newMessage.getParentMessageId())
|
|
1993
|
-
) {
|
|
1994
|
-
return;
|
|
1995
|
-
}
|
|
1996
2059
|
if (isAtBottom() || isNearBottom() || scrollToBottomOnNewMessages) {
|
|
1997
2060
|
if (!skipAddToList) {
|
|
1998
2061
|
addToMessageList(newMessage);
|
|
@@ -2157,11 +2220,44 @@ export const CometChatMessageList = memo(
|
|
|
2157
2220
|
(firstMsgMuid && latestMsgMuid && String(firstMsgMuid) !== String(latestMsgMuid));
|
|
2158
2221
|
|
|
2159
2222
|
if (hasGap) {
|
|
2223
|
+
// A gap means our list is behind the server. Rebuild it from the server,
|
|
2224
|
+
// then only prepend the incoming message if the rebuilt page didn't
|
|
2225
|
+
// already include it. This avoids the double-insert that caused the
|
|
2226
|
+
// duplicate, while still covering the race where the read API hasn't
|
|
2227
|
+
// caught up with the just-received message yet.
|
|
2160
2228
|
reachedFirstMessage.current = false;
|
|
2161
2229
|
msgRequestBuilder.current?.setMessageId(0);
|
|
2162
2230
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
2163
2231
|
messagesContentListRef.current = [];
|
|
2164
2232
|
await getPreviousMessages();
|
|
2233
|
+
|
|
2234
|
+
const incomingId = newMessage?.getId?.() ?? (newMessage as any)?.id;
|
|
2235
|
+
const incomingMuid =
|
|
2236
|
+
(newMessage as any)?.muid ??
|
|
2237
|
+
(typeof newMessage?.getMuid === "function" ? newMessage.getMuid() : undefined);
|
|
2238
|
+
const alreadyPresent = messagesContentListRef.current.some((msg: any) => {
|
|
2239
|
+
const mid = typeof msg?.getId === "function" ? msg.getId() : msg?.id;
|
|
2240
|
+
const mmuid = (msg as any)?.muid ?? (typeof msg?.getMuid === "function" ? msg.getMuid() : undefined);
|
|
2241
|
+
return (
|
|
2242
|
+
(incomingId != null && mid != null && String(mid) === String(incomingId)) ||
|
|
2243
|
+
(incomingMuid != null && mmuid != null && String(mmuid) === String(incomingMuid))
|
|
2244
|
+
);
|
|
2245
|
+
});
|
|
2246
|
+
|
|
2247
|
+
if (!alreadyPresent) {
|
|
2248
|
+
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
2249
|
+
}
|
|
2250
|
+
|
|
2251
|
+
latestMessageRef.current = messagesContentListRef.current[0] ?? newMessage;
|
|
2252
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
2253
|
+
batchStateUpdates(() => {
|
|
2254
|
+
setMessagesList([...messagesContentListRef.current]);
|
|
2255
|
+
if (hideScrollToBottomButton === false && unreadCount < 1 && !hasTargetMessageId) {
|
|
2256
|
+
setHideScrollToBottomButton(true);
|
|
2257
|
+
}
|
|
2258
|
+
});
|
|
2259
|
+
aMessageWasSentByMeRef.current = true;
|
|
2260
|
+
return;
|
|
2165
2261
|
}
|
|
2166
2262
|
}
|
|
2167
2263
|
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
@@ -2255,39 +2351,48 @@ export const CometChatMessageList = memo(
|
|
|
2255
2351
|
return;
|
|
2256
2352
|
}
|
|
2257
2353
|
// Use getter method for messageId (SDK receipt objects expose it via getMessageId())
|
|
2258
|
-
|
|
2259
|
-
|
|
2354
|
+
const receiptMessageId = typeof receipt.getMessageId === 'function' ? receipt.getMessageId() : receipt["messageId"];
|
|
2355
|
+
const index = messagesContentListRef.current.findIndex(
|
|
2260
2356
|
(msg) => {
|
|
2261
2357
|
const msgId = typeof msg.getId === 'function' ? msg.getId() : msg["id"];
|
|
2262
2358
|
return String(msgId) === String(receiptMessageId);
|
|
2263
2359
|
}
|
|
2264
2360
|
);
|
|
2265
2361
|
|
|
2266
|
-
if (index
|
|
2267
|
-
|
|
2268
|
-
|
|
2269
|
-
|
|
2270
|
-
|
|
2271
|
-
|
|
2272
|
-
|
|
2273
|
-
|
|
2274
|
-
|
|
2275
|
-
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
2282
|
-
|
|
2362
|
+
if (index === -1) return;
|
|
2363
|
+
|
|
2364
|
+
// Clone-first approach: shallow copy the array, then clone only messages
|
|
2365
|
+
// whose receipt status actually changes. Unchanged items keep original references
|
|
2366
|
+
// so FlatList skips re-rendering them.
|
|
2367
|
+
const updatedList = [...messagesContentListRef.current];
|
|
2368
|
+
let hasChanges = false;
|
|
2369
|
+
|
|
2370
|
+
for (let i = index; i < updatedList.length; i++) {
|
|
2371
|
+
const msg = updatedList[i];
|
|
2372
|
+
// Skip messages already marked as read — they're implicitly delivered too
|
|
2373
|
+
if (msg?.getReadAt?.()) continue;
|
|
2374
|
+
|
|
2375
|
+
if (!Number.isNaN(Number(msg.getId()))) {
|
|
2376
|
+
const deliveredNeedsUpdate = receipt.getDeliveredAt() && !msg.getDeliveredAt?.();
|
|
2377
|
+
const readNeedsUpdate = receipt.getReadAt() && !msg.getReadAt?.();
|
|
2378
|
+
|
|
2379
|
+
if (deliveredNeedsUpdate || readNeedsUpdate) {
|
|
2380
|
+
// Clone BEFORE mutating — never mutate objects React is holding
|
|
2381
|
+
const cloned = CommonUtils.clone(msg);
|
|
2382
|
+
if (deliveredNeedsUpdate) cloned.setDeliveredAt(receipt.getDeliveredAt());
|
|
2383
|
+
if (readNeedsUpdate) cloned.setReadAt(receipt.getReadAt());
|
|
2384
|
+
updatedList[i] = cloned;
|
|
2385
|
+
hasChanges = true;
|
|
2283
2386
|
}
|
|
2284
2387
|
}
|
|
2285
|
-
tmpList[i] = CommonUtils.clone(tmpMsg);
|
|
2286
2388
|
}
|
|
2287
2389
|
|
|
2288
|
-
|
|
2289
|
-
|
|
2290
|
-
|
|
2390
|
+
// Only trigger re-render if at least one message was actually updated
|
|
2391
|
+
if (hasChanges) {
|
|
2392
|
+
messagesContentListRef.current = updatedList;
|
|
2393
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
2394
|
+
setMessagesList(updatedList);
|
|
2395
|
+
}
|
|
2291
2396
|
};
|
|
2292
2397
|
|
|
2293
2398
|
const handlePannel = (item: any) => {
|
|
@@ -2322,13 +2427,109 @@ export const CometChatMessageList = memo(
|
|
|
2322
2427
|
loggedInUser.current = u;
|
|
2323
2428
|
if (isAgenticUser && !parentMessageId) {
|
|
2324
2429
|
messageRequest.current = null;
|
|
2430
|
+
// Auto-load the last agent conversation if enabled
|
|
2431
|
+
if (loadLastAgentConversation && !_skipAgentAutoLoad) {
|
|
2432
|
+
try {
|
|
2433
|
+
const lastMsgBuilder = new CometChat.MessagesRequestBuilder()
|
|
2434
|
+
.setLimit(1)
|
|
2435
|
+
.setCategories(ChatConfigurator.dataSource.getAllMessageCategories())
|
|
2436
|
+
.setTypes(ChatConfigurator.dataSource.getAllMessageTypes())
|
|
2437
|
+
.hideDeletedMessages(true)
|
|
2438
|
+
.hideReplies(true)
|
|
2439
|
+
|
|
2440
|
+
|
|
2441
|
+
if (user) {
|
|
2442
|
+
lastMsgBuilder.setUID(user.getUid());
|
|
2443
|
+
}
|
|
2444
|
+
if (group) {
|
|
2445
|
+
lastMsgBuilder.setGUID(group.getGuid());
|
|
2446
|
+
}
|
|
2447
|
+
const lastMessages = await lastMsgBuilder.build().fetchPrevious();
|
|
2448
|
+
if (lastMessages && lastMessages.length > 0) {
|
|
2449
|
+
const lastMsg = lastMessages[0];
|
|
2450
|
+
// Determine the conversation's parent message ID
|
|
2451
|
+
const rawParentId = typeof lastMsg.getParentMessageId === 'function'
|
|
2452
|
+
? lastMsg.getParentMessageId()
|
|
2453
|
+
: 0;
|
|
2454
|
+
const lastParentId = rawParentId && Number(rawParentId) > 0
|
|
2455
|
+
? String(rawParentId)
|
|
2456
|
+
: String(lastMsg.getId());
|
|
2457
|
+
agenticParentMessageIdRef.current = lastParentId;
|
|
2458
|
+
latestMessageRef.current = lastMsg;
|
|
2459
|
+
|
|
2460
|
+
// Build request to fetch messages for this conversation
|
|
2461
|
+
let agentRequestBuilder = new CometChat.MessagesRequestBuilder()
|
|
2462
|
+
.setLimit(30)
|
|
2463
|
+
.setTags([]);
|
|
2464
|
+
if (user) {
|
|
2465
|
+
agentRequestBuilder = agentRequestBuilder.setUID(user.getUid());
|
|
2466
|
+
}
|
|
2467
|
+
if (group) {
|
|
2468
|
+
agentRequestBuilder = agentRequestBuilder.setGUID(group.getGuid());
|
|
2469
|
+
}
|
|
2470
|
+
agentRequestBuilder = agentRequestBuilder.setParentMessageId(
|
|
2471
|
+
parseInt(lastParentId)
|
|
2472
|
+
);
|
|
2473
|
+
agentRequestBuilder.hideReplies(false);
|
|
2474
|
+
agentRequestBuilder.withParent(true);
|
|
2475
|
+
agentRequestBuilder.setTypes(
|
|
2476
|
+
ChatConfigurator.dataSource.getAllMessageTypes()
|
|
2477
|
+
);
|
|
2478
|
+
agentRequestBuilder.setCategories(
|
|
2479
|
+
ChatConfigurator.dataSource.getAllMessageCategories()
|
|
2480
|
+
);
|
|
2481
|
+
|
|
2482
|
+
messageRequest.current = agentRequestBuilder.build();
|
|
2483
|
+
setListState("loading");
|
|
2484
|
+
const msgs = await messageRequest.current.fetchPrevious();
|
|
2485
|
+
if (msgs && msgs.length > 0) {
|
|
2486
|
+
// Sort by ID descending (newest first for inverted list)
|
|
2487
|
+
// Server returns parent (via withParent) at end, out of chronological order
|
|
2488
|
+
const sorted = [...msgs].sort((a, b) => {
|
|
2489
|
+
const aId = Number(typeof a.getId === 'function' ? a.getId() : 0);
|
|
2490
|
+
const bId = Number(typeof b.getId === 'function' ? b.getId() : 0);
|
|
2491
|
+
return bId - aId;
|
|
2492
|
+
});
|
|
2493
|
+
// Deduplicate (withParent may include parent twice)
|
|
2494
|
+
const seenIds = new Set<number>();
|
|
2495
|
+
const uniqueMsgs = sorted.filter((msg) => {
|
|
2496
|
+
const msgId = Number(typeof msg.getId === 'function' ? msg.getId() : 0);
|
|
2497
|
+
if (!msgId || seenIds.has(msgId)) return false;
|
|
2498
|
+
seenIds.add(msgId);
|
|
2499
|
+
return true;
|
|
2500
|
+
});
|
|
2501
|
+
if (msgs.length < 30) {
|
|
2502
|
+
reachedFirstMessage.current = true;
|
|
2503
|
+
}
|
|
2504
|
+
messagesContentListRef.current = uniqueMsgs;
|
|
2505
|
+
setMessagesList(uniqueMsgs);
|
|
2506
|
+
onLoad && onLoad([...uniqueMsgs].reverse());
|
|
2507
|
+
setListState("loaded");
|
|
2508
|
+
} else {
|
|
2509
|
+
setListState("loaded");
|
|
2510
|
+
onEmpty && onEmpty();
|
|
2511
|
+
}
|
|
2512
|
+
} else {
|
|
2513
|
+
// No previous conversation — show empty/greeting state
|
|
2514
|
+
setListState("loaded");
|
|
2515
|
+
onEmpty && onEmpty();
|
|
2516
|
+
}
|
|
2517
|
+
} catch (e) {
|
|
2518
|
+
console.log("Error auto-loading last agent conversation", e);
|
|
2519
|
+
setListState("loaded");
|
|
2520
|
+
onEmpty && onEmpty();
|
|
2521
|
+
}
|
|
2522
|
+
} else {
|
|
2523
|
+
// Clear skip flag if it was set
|
|
2524
|
+
_skipAgentAutoLoad = false;
|
|
2525
|
+
}
|
|
2325
2526
|
} else {
|
|
2326
2527
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
2327
2528
|
}
|
|
2328
2529
|
if (!isAgenticUser || (isAgenticUser && parentMessageId)) {
|
|
2329
2530
|
if (goToMessageId) {
|
|
2330
2531
|
getMessagesAroundId(goToMessageId);
|
|
2331
|
-
} else if (startFromUnreadMessages) {
|
|
2532
|
+
} else if (startFromUnreadMessages && !(isAgenticUser && parentMessageId)) {
|
|
2332
2533
|
|
|
2333
2534
|
|
|
2334
2535
|
try {
|
|
@@ -2349,7 +2550,29 @@ export const CometChatMessageList = memo(
|
|
|
2349
2550
|
const lastReadMessageId = conversation.getLastReadMessageId();
|
|
2350
2551
|
//if lastReadMessageId is 0, it means no messages have been read yet
|
|
2351
2552
|
if (lastReadMessageId && Number(lastReadMessageId) !== 0) {
|
|
2352
|
-
|
|
2553
|
+
// Validate that lastReadMessageId is not a thread reply.
|
|
2554
|
+
// getLastReadMessageId() can return a thread reply's ID when the user
|
|
2555
|
+
// read messages inside a thread. Using a thread reply as the anchor
|
|
2556
|
+
// for getMessagesAroundId causes it to leak into the main message list.
|
|
2557
|
+
if (!parentMessageId) {
|
|
2558
|
+
try {
|
|
2559
|
+
const lastReadMsg = await CometChat.getMessageDetails(Number(lastReadMessageId));
|
|
2560
|
+
const lastReadParentId = lastReadMsg?.getParentMessageId
|
|
2561
|
+
? lastReadMsg.getParentMessageId()
|
|
2562
|
+
: (lastReadMsg as any)?.parentMessageId;
|
|
2563
|
+
if (lastReadParentId) {
|
|
2564
|
+
// Last read message is a thread reply — use its parent as anchor instead
|
|
2565
|
+
getMessagesAroundId(String(lastReadParentId));
|
|
2566
|
+
} else {
|
|
2567
|
+
getMessagesAroundId(String(lastReadMessageId));
|
|
2568
|
+
}
|
|
2569
|
+
} catch (e) {
|
|
2570
|
+
// If we can't validate, fall back to normal load
|
|
2571
|
+
getPreviousMessages();
|
|
2572
|
+
}
|
|
2573
|
+
} else {
|
|
2574
|
+
getMessagesAroundId(String(lastReadMessageId));
|
|
2575
|
+
}
|
|
2353
2576
|
} else {
|
|
2354
2577
|
getPreviousMessages();
|
|
2355
2578
|
}
|
|
@@ -2396,6 +2619,18 @@ export const CometChatMessageList = memo(
|
|
|
2396
2619
|
if (group) {
|
|
2397
2620
|
messageRequestBuilder.setGUID(group.getGuid());
|
|
2398
2621
|
}
|
|
2622
|
+
|
|
2623
|
+
// Mirror the main list's population so latestMessageRef stays comparable to
|
|
2624
|
+
// the list head. The main list hides thread replies (hideReplies), while a
|
|
2625
|
+
// thread view scopes to its parent. Without this, latestMessageRef could be
|
|
2626
|
+
// set to a thread reply that never appears in the main list, which makes the
|
|
2627
|
+
// gap check in addToMessageList read a false "gap" on the next message.
|
|
2628
|
+
if (parentMessageId) {
|
|
2629
|
+
messageRequestBuilder.setParentMessageId(parseInt(parentMessageId)).hideReplies(false);
|
|
2630
|
+
} else {
|
|
2631
|
+
messageRequestBuilder.hideReplies(true);
|
|
2632
|
+
}
|
|
2633
|
+
|
|
2399
2634
|
messageRequestBuilder
|
|
2400
2635
|
.build()
|
|
2401
2636
|
.fetchPrevious()
|
|
@@ -2404,7 +2639,7 @@ export const CometChatMessageList = memo(
|
|
|
2404
2639
|
latestMessageRef.current = messages[0];
|
|
2405
2640
|
}
|
|
2406
2641
|
});
|
|
2407
|
-
}, []);
|
|
2642
|
+
}, [user, group, parentMessageId]);
|
|
2408
2643
|
|
|
2409
2644
|
// Callback to add stream message and register queue completion callback
|
|
2410
2645
|
const createStreamMessage = useCallback(
|
|
@@ -2420,7 +2655,7 @@ export const CometChatMessageList = memo(
|
|
|
2420
2655
|
if (user) {
|
|
2421
2656
|
streamMessage.setSender(user);
|
|
2422
2657
|
}
|
|
2423
|
-
streamMessage.setReceiver(loggedInUser.current);
|
|
2658
|
+
streamMessage.setReceiver(loggedInUser.current as CometChat.User);
|
|
2424
2659
|
streamMessage.setReceiverType(CometChat.RECEIVER_TYPE.USER);
|
|
2425
2660
|
streamMessage.setSentAt(Math.floor(Date.now() / 1000));
|
|
2426
2661
|
(streamMessage as any).targetMessageId = runId;
|
|
@@ -2465,7 +2700,7 @@ export const CometChatMessageList = memo(
|
|
|
2465
2700
|
if (
|
|
2466
2701
|
message.getConversationId &&
|
|
2467
2702
|
(!message.getConversationId()?.includes(user.getUid()) ||
|
|
2468
|
-
!message.getConversationId()?.includes(loggedInUser.current?.getUid()))
|
|
2703
|
+
!message.getConversationId()?.includes(loggedInUser.current?.getUid() ?? ""))
|
|
2469
2704
|
) {
|
|
2470
2705
|
return;
|
|
2471
2706
|
}
|
|
@@ -2577,16 +2812,6 @@ export const CometChatMessageList = memo(
|
|
|
2577
2812
|
CometChatUIEventHandler.addMessageListener(messageEventListener, {
|
|
2578
2813
|
ccMessageSent: ({ message, status }: any) => {
|
|
2579
2814
|
if (status == MessageStatusConstants.inprogress) {
|
|
2580
|
-
// Remove incomplete stream messages before adding new user message (for agentic users)
|
|
2581
|
-
if (isAgenticUser) {
|
|
2582
|
-
const filteredList = messagesContentListRef.current.filter(
|
|
2583
|
-
(msg) => !(msg as any).isStreamMessage
|
|
2584
|
-
);
|
|
2585
|
-
if (filteredList.length !== messagesContentListRef.current.length) {
|
|
2586
|
-
messagesContentListRef.current = filteredList;
|
|
2587
|
-
setMessagesList(filteredList);
|
|
2588
|
-
}
|
|
2589
|
-
}
|
|
2590
2815
|
newMessage(message, false);
|
|
2591
2816
|
}
|
|
2592
2817
|
|
|
@@ -2595,7 +2820,7 @@ export const CometChatMessageList = memo(
|
|
|
2595
2820
|
if (
|
|
2596
2821
|
isAgenticUser &&
|
|
2597
2822
|
agenticParentMessageIdRef.current === undefined &&
|
|
2598
|
-
|
|
2823
|
+
messagesContentListRef.current.length !== 0 &&
|
|
2599
2824
|
message.getType() === MessageTypeConstants.text &&
|
|
2600
2825
|
message.getCategory() === MessageCategoryConstants.message
|
|
2601
2826
|
) {
|
|
@@ -2835,7 +3060,7 @@ export const CometChatMessageList = memo(
|
|
|
2835
3060
|
new CometChat.ConnectionListener({
|
|
2836
3061
|
onConnected: () => {
|
|
2837
3062
|
streamOnConnected();
|
|
2838
|
-
if (lastID.current) {
|
|
3063
|
+
if (lastID.current && !isAgenticUser) {
|
|
2839
3064
|
getUpdatedPreviousMessages();
|
|
2840
3065
|
}
|
|
2841
3066
|
},
|
|
@@ -2914,7 +3139,10 @@ export const CometChatMessageList = memo(
|
|
|
2914
3139
|
});
|
|
2915
3140
|
|
|
2916
3141
|
const getMessageById = (messageId: string): CometChat.BaseMessage => {
|
|
2917
|
-
|
|
3142
|
+
// Read from the live ref so reactions resolve against the current list.
|
|
3143
|
+
const message = messagesContentListRef.current.find(
|
|
3144
|
+
(message) => message.getId() === messageId
|
|
3145
|
+
);
|
|
2918
3146
|
return message;
|
|
2919
3147
|
};
|
|
2920
3148
|
|
|
@@ -2922,29 +3150,41 @@ export const CometChatMessageList = memo(
|
|
|
2922
3150
|
const receiverId = receipt?.getReceiverId();
|
|
2923
3151
|
const receiverType = receipt?.getReceiverType();
|
|
2924
3152
|
const reactedById = receipt?.getReaction()?.getReactedBy()?.getUid();
|
|
2925
|
-
const
|
|
2926
|
-
|
|
2927
|
-
|
|
2928
|
-
|
|
3153
|
+
const reactionMessageId = receipt?.getReaction()?.getMessageId();
|
|
3154
|
+
|
|
3155
|
+
// If the reacted message is rendered in this list, the reaction belongs here.
|
|
3156
|
+
if (reactionMessageId != null) {
|
|
3157
|
+
const exists = messagesContentListRef.current.some(
|
|
3158
|
+
(msg) => String(msg.getId?.() ?? msg.id) === String(reactionMessageId)
|
|
3159
|
+
);
|
|
3160
|
+
if (exists) return true;
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
const reactionParentId = receipt?.getParentMessageId();
|
|
3164
|
+
|
|
3165
|
+
// Thread list: message not loaded yet, accept only if it belongs to this thread.
|
|
3166
|
+
if (parentMessageId) {
|
|
3167
|
+
return (
|
|
3168
|
+
Boolean(reactionParentId) &&
|
|
3169
|
+
String(reactionParentId) === String(parentMessageId)
|
|
3170
|
+
);
|
|
3171
|
+
}
|
|
3172
|
+
|
|
3173
|
+
// Main list: reject reactions that belong to a thread.
|
|
3174
|
+
if (reactionParentId) {
|
|
3175
|
+
return false;
|
|
3176
|
+
}
|
|
3177
|
+
|
|
3178
|
+
if (user) {
|
|
3179
|
+
if (
|
|
3180
|
+
receiverType === ReceiverTypeConstants.user &&
|
|
3181
|
+
(receiverId === user.getUid() || reactedById === user.getUid())
|
|
3182
|
+
) {
|
|
2929
3183
|
return true;
|
|
2930
|
-
} else {
|
|
2931
|
-
return false;
|
|
2932
3184
|
}
|
|
2933
|
-
} else {
|
|
2934
|
-
if (
|
|
2935
|
-
return
|
|
2936
|
-
}
|
|
2937
|
-
if (user) {
|
|
2938
|
-
if (
|
|
2939
|
-
receiverType === ReceiverTypeConstants.user &&
|
|
2940
|
-
(receiverId === user.getUid() || reactedById === user.getUid())
|
|
2941
|
-
) {
|
|
2942
|
-
return true;
|
|
2943
|
-
}
|
|
2944
|
-
} else if (group) {
|
|
2945
|
-
if (receiverType === ReceiverTypeConstants.group && receiverId === group.getGuid()) {
|
|
2946
|
-
return true;
|
|
2947
|
-
}
|
|
3185
|
+
} else if (group) {
|
|
3186
|
+
if (receiverType === ReceiverTypeConstants.group && receiverId === group.getGuid()) {
|
|
3187
|
+
return true;
|
|
2948
3188
|
}
|
|
2949
3189
|
}
|
|
2950
3190
|
return false;
|
|
@@ -3029,7 +3269,7 @@ export const CometChatMessageList = memo(
|
|
|
3029
3269
|
<CometChatAvatar
|
|
3030
3270
|
image={
|
|
3031
3271
|
item?.getSender()?.getAvatar && item?.getSender()?.getAvatar()
|
|
3032
|
-
? { uri: item.getSender()
|
|
3272
|
+
? { uri: item.getSender()?.getAvatar() }
|
|
3033
3273
|
: undefined
|
|
3034
3274
|
}
|
|
3035
3275
|
name={
|
|
@@ -3056,7 +3296,7 @@ export const CometChatMessageList = memo(
|
|
|
3056
3296
|
) {
|
|
3057
3297
|
const senderName = (item.getSender()?.getName() || "").trim();
|
|
3058
3298
|
return (
|
|
3059
|
-
<View style={
|
|
3299
|
+
<View style={staticStyles.flexRow}>
|
|
3060
3300
|
{Boolean(senderName) && (
|
|
3061
3301
|
<Text
|
|
3062
3302
|
style={_style.senderNameTextStyles}
|
|
@@ -3169,7 +3409,7 @@ export const CometChatMessageList = memo(
|
|
|
3169
3409
|
alignment !== "leftAligned" &&
|
|
3170
3410
|
isOutgoingMessage &&
|
|
3171
3411
|
!item.getDeletedAt?.() ? (
|
|
3172
|
-
<View style={
|
|
3412
|
+
<View style={staticStyles.receiptContainer}>
|
|
3173
3413
|
<CometChatReceipt
|
|
3174
3414
|
receipt={messageState}
|
|
3175
3415
|
style={{
|
|
@@ -3434,7 +3674,7 @@ export const CometChatMessageList = memo(
|
|
|
3434
3674
|
|
|
3435
3675
|
const privateMessage = (item: CometChat.BaseMessage) => {
|
|
3436
3676
|
setShowMessageOptions([]);
|
|
3437
|
-
CometChat.getUser(item.getSender()
|
|
3677
|
+
CometChat.getUser(item.getSender()?.getUid())
|
|
3438
3678
|
.then((user: any) => {
|
|
3439
3679
|
CometChatUIEventHandler.emitUIEvent("openChat", { user });
|
|
3440
3680
|
})
|
|
@@ -3801,7 +4041,7 @@ export const CometChatMessageList = memo(
|
|
|
3801
4041
|
|
|
3802
4042
|
return (
|
|
3803
4043
|
message.getCategory() === MessageCategoryConstants.action || isAgenticUser ? (
|
|
3804
|
-
<View style={
|
|
4044
|
+
<View style={staticStyles.positionRelative}>
|
|
3805
4045
|
<TouchableOpacity
|
|
3806
4046
|
activeOpacity={1}
|
|
3807
4047
|
onPress={Platform.OS === "ios" ? onPress : undefined}
|
|
@@ -3830,7 +4070,7 @@ export const CometChatMessageList = memo(
|
|
|
3830
4070
|
failOffsetY={[-50, 50]}
|
|
3831
4071
|
>
|
|
3832
4072
|
<Animated.View style={{ transform: [{ translateX: swipeAnimatedValue }] }}>
|
|
3833
|
-
<View style={
|
|
4073
|
+
<View style={staticStyles.positionRelative}>
|
|
3834
4074
|
<TouchableOpacity
|
|
3835
4075
|
activeOpacity={1}
|
|
3836
4076
|
onPress={Platform.OS === "ios" ? onPress : undefined}
|
|
@@ -4208,7 +4448,7 @@ export const CometChatMessageList = memo(
|
|
|
4208
4448
|
if (LoadingView) return LoadingView();
|
|
4209
4449
|
|
|
4210
4450
|
return (
|
|
4211
|
-
<View style={
|
|
4451
|
+
<View style={staticStyles.skeletonPadding}>
|
|
4212
4452
|
<MessageSkeleton />
|
|
4213
4453
|
</View>
|
|
4214
4454
|
);
|
|
@@ -4278,7 +4518,7 @@ export const CometChatMessageList = memo(
|
|
|
4278
4518
|
const renderFooter = () => {
|
|
4279
4519
|
if (!bottomLoading) return null;
|
|
4280
4520
|
return (
|
|
4281
|
-
<View style={
|
|
4521
|
+
<View style={staticStyles.footerContainer}>
|
|
4282
4522
|
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
4283
4523
|
</View>
|
|
4284
4524
|
);
|
|
@@ -4457,13 +4697,8 @@ export const CometChatMessageList = memo(
|
|
|
4457
4697
|
);
|
|
4458
4698
|
|
|
4459
4699
|
if (indicatorItem) {
|
|
4460
|
-
//
|
|
4461
|
-
|
|
4462
|
-
if (!parentMessageId && indicatorItem.item) {
|
|
4463
|
-
CometChat.markAsRead(indicatorItem.item).catch((e: any) => {
|
|
4464
|
-
console.log("Error marking message as read", e);
|
|
4465
|
-
});
|
|
4466
|
-
} else if (user) {
|
|
4700
|
+
// Mark entire conversation as read when user scrolls to the unread indicator
|
|
4701
|
+
if (user) {
|
|
4467
4702
|
CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
|
|
4468
4703
|
console.log("Error marking user conversation as read", e);
|
|
4469
4704
|
});
|
|
@@ -4473,6 +4708,9 @@ export const CometChatMessageList = memo(
|
|
|
4473
4708
|
});
|
|
4474
4709
|
}
|
|
4475
4710
|
setUnreadCount(0);
|
|
4711
|
+
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
4712
|
+
message: indicatorItem.item,
|
|
4713
|
+
});
|
|
4476
4714
|
}
|
|
4477
4715
|
}
|
|
4478
4716
|
}, [navigatedFromSearch, newMessageIndicatorId, unreadCount, user, group, hasManuallyMarkedUnread, parentMessageId]);
|
|
@@ -4555,9 +4793,9 @@ export const CometChatMessageList = memo(
|
|
|
4555
4793
|
messagesList.length == 0 ? (
|
|
4556
4794
|
getEmptyStateView()
|
|
4557
4795
|
) : (
|
|
4558
|
-
<View style={
|
|
4796
|
+
<View style={staticStyles.listContainer}>
|
|
4559
4797
|
{HeaderView && (
|
|
4560
|
-
<View style={
|
|
4798
|
+
<View style={staticStyles.headerContainer}>
|
|
4561
4799
|
<HeaderView
|
|
4562
4800
|
group={group}
|
|
4563
4801
|
user={user}
|
|
@@ -4570,7 +4808,7 @@ export const CometChatMessageList = memo(
|
|
|
4570
4808
|
</View>
|
|
4571
4809
|
)}
|
|
4572
4810
|
{loadingMessages && (
|
|
4573
|
-
<View style={
|
|
4811
|
+
<View style={staticStyles.activityIndicatorContainer}>
|
|
4574
4812
|
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
4575
4813
|
</View>
|
|
4576
4814
|
)}
|
|
@@ -4803,4 +5041,20 @@ const staticStyles = StyleSheet.create({
|
|
|
4803
5041
|
textAlign: "center",
|
|
4804
5042
|
textAlignVertical: "center",
|
|
4805
5043
|
},
|
|
4806
|
-
|
|
5044
|
+
receiptContainer: {
|
|
5045
|
+
marginLeft: 2,
|
|
5046
|
+
alignItems: "center",
|
|
5047
|
+
justifyContent: "center",
|
|
5048
|
+
},
|
|
5049
|
+
positionRelative: {
|
|
5050
|
+
position: 'relative',
|
|
5051
|
+
},
|
|
5052
|
+
flexRow: {
|
|
5053
|
+
flexDirection: "row",
|
|
5054
|
+
},
|
|
5055
|
+
skeletonPadding: {
|
|
5056
|
+
padding: 16,
|
|
5057
|
+
},
|
|
5058
|
+
})
|
|
5059
|
+
|
|
5060
|
+
|