@cometchat/chat-uikit-react-native 5.2.4 → 5.2.6
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/CometChatGroupMembers/CometChatGroupMembers.tsx +23 -7
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +34 -2
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +165 -89
- package/src/CometChatSearch/CometChatSearch.tsx +604 -158
- package/src/shared/helper/helperFunctions.ts +1 -2
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +10 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +8 -0
- package/src/shared/views/CometChatList/Header.tsx +1 -0
- package/src/shared/views/CometChatList/styles.ts +4 -2
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +8 -0
- package/src/theme/provider.tsx +17 -8
|
@@ -559,7 +559,7 @@ export const CometChatMessageList = memo(
|
|
|
559
559
|
const hideReactionOption = isAgenticUser() ? true : propHideReactionOption;
|
|
560
560
|
const hideMessagePrivatelyOption = isAgenticUser() ? true : propHideMessagePrivatelyOption;
|
|
561
561
|
const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
|
|
562
|
-
const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
|
|
562
|
+
const hideMessageInfoOption = isAgenticUser() ? true : (propHideMessageInfoOption || !receiptsVisibility);
|
|
563
563
|
const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
|
|
564
564
|
const hideFlagMessageOption = isAgenticUser() ? true : propHideFlagMessageOption;
|
|
565
565
|
|
|
@@ -823,6 +823,11 @@ export const CometChatMessageList = memo(
|
|
|
823
823
|
const [loadingMessages, setLoadingMessages] = useState(false);
|
|
824
824
|
/** this is required to prevent duplicate api calls. Cannot use state for this since this is being used in scrollHandler **/
|
|
825
825
|
const loadingMessagesRef = useRef(false);
|
|
826
|
+
const loadingPrevMessagesRef = useRef(false);
|
|
827
|
+
// State for showing loading when navigating to far messages
|
|
828
|
+
const [navigationLoading, setNavigationLoading] = useState(false);
|
|
829
|
+
// State for showing bottom loading indicator when fetching next messages
|
|
830
|
+
const [bottomLoading, setBottomLoading] = useState(false);
|
|
826
831
|
const [unreadCount, setUnreadCount] = useState(0);
|
|
827
832
|
const [showMessageOptions, setShowMessageOptions] = useState<any[]>([]);
|
|
828
833
|
const [ExtensionsComponent, setExtensionsComponent] = useState<JSX.Element | null>(null);
|
|
@@ -847,8 +852,8 @@ export const CometChatMessageList = memo(
|
|
|
847
852
|
const bottomSheetRef = useRef<any>(null);
|
|
848
853
|
const conversationId = useRef<string | null>(null);
|
|
849
854
|
const streamSubscriptionRef = useRef<any>(null);
|
|
850
|
-
|
|
851
|
-
|
|
855
|
+
const lastID = useRef(0);
|
|
856
|
+
const reachedFirstMessage = useRef<boolean>(false);
|
|
852
857
|
const agenticParentMessageIdRef = useRef<string | undefined>(undefined);
|
|
853
858
|
const [hasTargetMessageId, setHasTargetMessageId] = useState(false);
|
|
854
859
|
const hasReachedBottomRef = useRef(true);
|
|
@@ -860,6 +865,21 @@ export const CometChatMessageList = memo(
|
|
|
860
865
|
CometChat.markAsRead(messagesContentListRef.current[0]);
|
|
861
866
|
setUnreadCount(0);
|
|
862
867
|
};
|
|
868
|
+
const prevMsgListLengthRef = useRef<number>(0);
|
|
869
|
+
const aMessageWasSentByMeRef = useRef<boolean>(false);
|
|
870
|
+
const latestMessageRef = useRef<any | null>(null);
|
|
871
|
+
|
|
872
|
+
useEffect(() => {
|
|
873
|
+
if (messagesList.length === prevMsgListLengthRef.current + 1 && aMessageWasSentByMeRef.current) {
|
|
874
|
+
aMessageWasSentByMeRef.current = false;
|
|
875
|
+
setTimeout(() => {
|
|
876
|
+
messageListRef.current?.scrollToOffset({ offset: 0, animated: true });
|
|
877
|
+
}, 100);
|
|
878
|
+
}
|
|
879
|
+
prevMsgListLengthRef.current = messagesList.length;
|
|
880
|
+
}, [messagesList]);
|
|
881
|
+
|
|
882
|
+
|
|
863
883
|
|
|
864
884
|
const newMsgIndicatorPressed = useCallback(async () => {
|
|
865
885
|
if (hasTargetMessageId) {
|
|
@@ -868,6 +888,9 @@ export const CometChatMessageList = memo(
|
|
|
868
888
|
messagesContentListRef.current = [];
|
|
869
889
|
setMessagesList([]);
|
|
870
890
|
setListState("loading");
|
|
891
|
+
reachedFirstMessage.current = false;
|
|
892
|
+
msgRequestBuilder.current?.setMessageId(0);
|
|
893
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
871
894
|
await getPreviousMessages();
|
|
872
895
|
setTimeout(() => {
|
|
873
896
|
scrollToBottom();
|
|
@@ -891,6 +914,10 @@ export const CometChatMessageList = memo(
|
|
|
891
914
|
}, [onLoad, hasTargetMessageId]);
|
|
892
915
|
|
|
893
916
|
const getPreviousMessages = async () => {
|
|
917
|
+
if (loadingPrevMessagesRef.current) {
|
|
918
|
+
return;
|
|
919
|
+
}
|
|
920
|
+
loadingPrevMessagesRef.current = true;
|
|
894
921
|
// For agent chats (non-thread), don't fetch previous messages
|
|
895
922
|
if (isAgenticUser() && !parentMessageId) {
|
|
896
923
|
return;
|
|
@@ -963,18 +990,11 @@ export const CometChatMessageList = memo(
|
|
|
963
990
|
}
|
|
964
991
|
);
|
|
965
992
|
if (previousMessagesFetched.length > 0) {
|
|
966
|
-
const existingIds = new Set(messagesContentListRef.current.map(m => m.getId()));
|
|
967
|
-
const newMessages = previousMessagesFetched.filter(m => !existingIds.has(m.getId()));
|
|
968
|
-
|
|
969
993
|
messagesContentListRef.current = [
|
|
970
994
|
...messagesContentListRef.current,
|
|
971
|
-
...
|
|
995
|
+
...previousMessagesFetched,
|
|
972
996
|
];
|
|
973
|
-
setMessagesList(
|
|
974
|
-
const prevIds = new Set(prev.map(m => m.getId()));
|
|
975
|
-
const uniqueNew = previousMessagesFetched.filter(m => !prevIds.has(m.getId()));
|
|
976
|
-
return [...prev, ...uniqueNew];
|
|
977
|
-
});
|
|
997
|
+
setMessagesList(messagesContentListRef.current);
|
|
978
998
|
}
|
|
979
999
|
if (messagesContentListRef.current.length == 0) {
|
|
980
1000
|
onEmpty && onEmpty();
|
|
@@ -993,6 +1013,8 @@ export const CometChatMessageList = memo(
|
|
|
993
1013
|
loadingMessagesRef.current = false;
|
|
994
1014
|
}
|
|
995
1015
|
onError && onError(e);
|
|
1016
|
+
}).finally(() => {
|
|
1017
|
+
loadingPrevMessagesRef.current = false;
|
|
996
1018
|
});
|
|
997
1019
|
};
|
|
998
1020
|
|
|
@@ -1026,11 +1048,24 @@ export const CometChatMessageList = memo(
|
|
|
1026
1048
|
}
|
|
1027
1049
|
|
|
1028
1050
|
fetchingAroundIdRef.current = messageId; // Mark this message as being fetched
|
|
1029
|
-
|
|
1030
|
-
|
|
1051
|
+
|
|
1052
|
+
// Check if message exists in current list
|
|
1053
|
+
const messageExists = messagesContentListRef.current.find(msg =>
|
|
1054
|
+
String(msg.getId()) === String(messageId)
|
|
1055
|
+
);
|
|
1056
|
+
|
|
1057
|
+
if (messageExists) {
|
|
1058
|
+
setHasTargetMessageId(true);
|
|
1059
|
+
} else {
|
|
1060
|
+
// Message is far, show navigation loading
|
|
1061
|
+
setNavigationLoading(true);
|
|
1062
|
+
setHasTargetMessageId(true);
|
|
1063
|
+
}
|
|
1031
1064
|
|
|
1032
1065
|
try {
|
|
1033
1066
|
const targetMessageId = Number(messageId);
|
|
1067
|
+
msgRequestBuilder.current?.setMessageId(targetMessageId);
|
|
1068
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1034
1069
|
|
|
1035
1070
|
// Get the target message first to ensure it exists
|
|
1036
1071
|
const targetMessage = await CometChat.getMessageDetails(targetMessageId);
|
|
@@ -1039,48 +1074,39 @@ export const CometChatMessageList = memo(
|
|
|
1039
1074
|
return;
|
|
1040
1075
|
}
|
|
1041
1076
|
|
|
1042
|
-
// Create request builder for previous messages (messages before the target)
|
|
1043
|
-
let prevMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
1044
|
-
.setLimit(15)
|
|
1045
|
-
.setMessageId(targetMessageId);
|
|
1046
|
-
|
|
1047
1077
|
// Create request builder for next messages (messages after the target)
|
|
1048
1078
|
let nextMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
1049
1079
|
.setLimit(15)
|
|
1050
1080
|
.setMessageId(targetMessageId);
|
|
1051
1081
|
|
|
1052
1082
|
if (user) {
|
|
1053
|
-
prevMessagesRequest = prevMessagesRequest.setUID(user.getUid());
|
|
1054
1083
|
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
1055
1084
|
}
|
|
1056
1085
|
|
|
1057
1086
|
if (group) {
|
|
1058
|
-
prevMessagesRequest = prevMessagesRequest.setGUID(group.getGuid());
|
|
1059
1087
|
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
1060
1088
|
}
|
|
1061
1089
|
|
|
1062
1090
|
if (parentMessageId) {
|
|
1063
|
-
prevMessagesRequest = prevMessagesRequest.setParentMessageId(Number(parentMessageId));
|
|
1064
1091
|
nextMessagesRequest = nextMessagesRequest.setParentMessageId(Number(parentMessageId));
|
|
1065
1092
|
}
|
|
1066
1093
|
|
|
1067
1094
|
// Fetch messages before and after the target message
|
|
1068
|
-
const previousMessages = await prevMessagesRequest.build().fetchPrevious();
|
|
1069
1095
|
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
1070
1096
|
|
|
1071
1097
|
// Combine messages: previous (reversed) + target + next
|
|
1072
1098
|
const allMessages = [
|
|
1073
|
-
...previousMessages
|
|
1099
|
+
// ...previousMessages,
|
|
1074
1100
|
targetMessage,
|
|
1075
1101
|
...nextMessages
|
|
1076
|
-
];
|
|
1077
|
-
|
|
1102
|
+
].reverse();
|
|
1103
|
+
|
|
1078
1104
|
// Remove duplicates and sort by timestamp (newest at top for FlatList)
|
|
1079
1105
|
const uniqueMessages = allMessages
|
|
1080
|
-
.filter((message, index, array) =>
|
|
1081
|
-
|
|
1082
|
-
)
|
|
1083
|
-
.sort((a, b) => b.getSentAt() - a.getSentAt());
|
|
1106
|
+
// .filter((message, index, array) =>
|
|
1107
|
+
// array.findIndex(m => m.getId() === message.getId()) === index
|
|
1108
|
+
// )
|
|
1109
|
+
// .sort((a, b) => b.getSentAt() - a.getSentAt());
|
|
1084
1110
|
|
|
1085
1111
|
if (uniqueMessages.length > 0) {
|
|
1086
1112
|
messagesContentListRef.current = uniqueMessages;
|
|
@@ -1097,6 +1123,7 @@ export const CometChatMessageList = memo(
|
|
|
1097
1123
|
setListState("error");
|
|
1098
1124
|
onError && onError(error as CometChat.CometChatException);
|
|
1099
1125
|
} finally {
|
|
1126
|
+
setNavigationLoading(false);
|
|
1100
1127
|
fetchingAroundIdRef.current = null;
|
|
1101
1128
|
}
|
|
1102
1129
|
};
|
|
@@ -1234,7 +1261,7 @@ export const CometChatMessageList = memo(
|
|
|
1234
1261
|
hideReactionOption: isAgenticUserCheck || hideReactionOption,
|
|
1235
1262
|
hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
|
|
1236
1263
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1237
|
-
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
|
|
1264
|
+
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption || !receiptsVisibility,
|
|
1238
1265
|
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1239
1266
|
hideGroupActionMessages,
|
|
1240
1267
|
onReplyClick: (messageId: string) => {
|
|
@@ -1283,6 +1310,7 @@ export const CometChatMessageList = memo(
|
|
|
1283
1310
|
hideCopyMessageOption,
|
|
1284
1311
|
hideMessageInfoOption,
|
|
1285
1312
|
hideGroupActionMessages,
|
|
1313
|
+
receiptsVisibility,
|
|
1286
1314
|
]);
|
|
1287
1315
|
|
|
1288
1316
|
const getPlainString = (underlyingText: string, messageObject: CometChat.BaseMessage) => {
|
|
@@ -1591,7 +1619,7 @@ export const CometChatMessageList = memo(
|
|
|
1591
1619
|
}
|
|
1592
1620
|
};
|
|
1593
1621
|
|
|
1594
|
-
const addToMessageList = (newMessage: CometChat.BaseMessage) => {
|
|
1622
|
+
const addToMessageList = async (newMessage: CometChat.BaseMessage) => {
|
|
1595
1623
|
if (isAgenticUser() && !conversationId.current) {
|
|
1596
1624
|
if (newMessage.getConversationId()) {
|
|
1597
1625
|
conversationId.current = newMessage.getConversationId();
|
|
@@ -1610,28 +1638,30 @@ export const CometChatMessageList = memo(
|
|
|
1610
1638
|
// ----------------------------------------------------------------------------------
|
|
1611
1639
|
// Fix: Before inserting, check for an existing message with matching id OR muid.
|
|
1612
1640
|
// If found, update it in place instead of inserting again.
|
|
1613
|
-
|
|
1614
|
-
|
|
1615
|
-
|
|
1616
|
-
|
|
1617
|
-
const
|
|
1618
|
-
|
|
1619
|
-
|
|
1620
|
-
|
|
1621
|
-
|
|
1622
|
-
|
|
1623
|
-
|
|
1624
|
-
|
|
1625
|
-
|
|
1626
|
-
|
|
1627
|
-
|
|
1628
|
-
|
|
1629
|
-
|
|
1630
|
-
|
|
1631
|
-
|
|
1641
|
+
if (!isAgenticUser) {
|
|
1642
|
+
try {
|
|
1643
|
+
const incomingId = (newMessage as any)?.getId?.();
|
|
1644
|
+
const incomingMuid = (newMessage as any)?.muid || (newMessage as any)?.getMuid?.();
|
|
1645
|
+
const existingIndex = messagesContentListRef.current.findIndex((m: any) => {
|
|
1646
|
+
const mid = m?.getId?.();
|
|
1647
|
+
const mmuid = m?.muid || m?.getMuid?.();
|
|
1648
|
+
return (
|
|
1649
|
+
(incomingId && mid && String(mid) === String(incomingId)) ||
|
|
1650
|
+
(incomingMuid && mmuid && String(mmuid) === String(incomingMuid))
|
|
1651
|
+
);
|
|
1652
|
+
});
|
|
1653
|
+
if (existingIndex !== -1) {
|
|
1654
|
+
// Update existing message instead of duplicating.
|
|
1655
|
+
const updatedList = [...messagesContentListRef.current];
|
|
1656
|
+
updatedList[existingIndex] = CommonUtils.clone(newMessage);
|
|
1657
|
+
messagesContentListRef.current = updatedList;
|
|
1658
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1659
|
+
setMessagesList(updatedList);
|
|
1660
|
+
return; // prevent duplicate insert
|
|
1661
|
+
}
|
|
1662
|
+
} catch (e) {
|
|
1663
|
+
console.log("Error in message de-duplication:", e);
|
|
1632
1664
|
}
|
|
1633
|
-
} catch (e) {
|
|
1634
|
-
console.log('Error in message de-duplication:', e);
|
|
1635
1665
|
}
|
|
1636
1666
|
|
|
1637
1667
|
const isStreamMessage = (newMessage as any).isStreamMessage;
|
|
@@ -1658,8 +1688,20 @@ export const CometChatMessageList = memo(
|
|
|
1658
1688
|
return;
|
|
1659
1689
|
}
|
|
1660
1690
|
}
|
|
1691
|
+
if (latestMessageRef.current !== null &&
|
|
1692
|
+
messagesContentListRef.current[0]?.id !== latestMessageRef.current.id
|
|
1693
|
+
&& messagesContentListRef.current[0]?.muid !== latestMessageRef.current.muid
|
|
1694
|
+
) {
|
|
1695
|
+
reachedFirstMessage.current = false;
|
|
1696
|
+
msgRequestBuilder.current?.setMessageId(0);
|
|
1697
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1698
|
+
messagesContentListRef.current = [];
|
|
1699
|
+
await getPreviousMessages();
|
|
1700
|
+
}
|
|
1661
1701
|
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
1662
1702
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1703
|
+
latestMessageRef.current = newMessage;
|
|
1704
|
+
aMessageWasSentByMeRef.current = true;
|
|
1663
1705
|
setMessagesList((prev) => [newMessage, ...prev]);
|
|
1664
1706
|
};
|
|
1665
1707
|
|
|
@@ -1811,6 +1853,7 @@ export const CometChatMessageList = memo(
|
|
|
1811
1853
|
} else {
|
|
1812
1854
|
getPreviousMessages();
|
|
1813
1855
|
}
|
|
1856
|
+
fetchLatestMessage();
|
|
1814
1857
|
}
|
|
1815
1858
|
})
|
|
1816
1859
|
.catch((e: any) => {
|
|
@@ -1827,6 +1870,28 @@ export const CometChatMessageList = memo(
|
|
|
1827
1870
|
};
|
|
1828
1871
|
}, []);
|
|
1829
1872
|
|
|
1873
|
+
|
|
1874
|
+
const fetchLatestMessage = useCallback(() => {
|
|
1875
|
+
const messageRequestBuilder = new CometChat.MessagesRequestBuilder()
|
|
1876
|
+
.setLimit(1)
|
|
1877
|
+
.setMessageId(0);
|
|
1878
|
+
|
|
1879
|
+
if (user) {
|
|
1880
|
+
messageRequestBuilder.setUID(user.getUid());
|
|
1881
|
+
}
|
|
1882
|
+
if (group) {
|
|
1883
|
+
messageRequestBuilder.setGUID(group.getGuid());
|
|
1884
|
+
}
|
|
1885
|
+
messageRequestBuilder
|
|
1886
|
+
.build()
|
|
1887
|
+
.fetchPrevious()
|
|
1888
|
+
.then((messages) => {
|
|
1889
|
+
if (messages[0]) {
|
|
1890
|
+
latestMessageRef.current = messages[0];
|
|
1891
|
+
}
|
|
1892
|
+
});
|
|
1893
|
+
}, []);
|
|
1894
|
+
|
|
1830
1895
|
// Callback to add stream message and register queue completion callback
|
|
1831
1896
|
const createStreamMessage = useCallback(
|
|
1832
1897
|
(userMessage: CometChat.BaseMessage) => {
|
|
@@ -2057,7 +2122,7 @@ export const CometChatMessageList = memo(
|
|
|
2057
2122
|
messageEdited(editedMessage);
|
|
2058
2123
|
},
|
|
2059
2124
|
onMessageModerated: (moderatedMessage: any) => {
|
|
2060
|
-
messageEdited(moderatedMessage);
|
|
2125
|
+
!isAgenticUser() && messageEdited(moderatedMessage);
|
|
2061
2126
|
},
|
|
2062
2127
|
onFormMessageReceived: (formMessage: any) => {
|
|
2063
2128
|
newMessage(formMessage);
|
|
@@ -2268,6 +2333,7 @@ export const CometChatMessageList = memo(
|
|
|
2268
2333
|
|
|
2269
2334
|
useEffect(() => {
|
|
2270
2335
|
if (selectedEmoji) {
|
|
2336
|
+
Keyboard.dismiss();
|
|
2271
2337
|
setShowReactionList(true);
|
|
2272
2338
|
}
|
|
2273
2339
|
}, [selectedEmoji]);
|
|
@@ -2673,8 +2739,8 @@ export const CometChatMessageList = memo(
|
|
|
2673
2739
|
let _style = getCurrentBubbleStyle(item);
|
|
2674
2740
|
const moderationStatus = getModerationStatus(item);
|
|
2675
2741
|
const isOutgoing = item.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
2676
|
-
if (isOutgoing && moderationStatus
|
|
2677
|
-
return undefined; // hide thread view if
|
|
2742
|
+
if (isOutgoing && moderationStatus === "disapproved") {
|
|
2743
|
+
return undefined; // hide thread view if disapproved
|
|
2678
2744
|
}
|
|
2679
2745
|
return !isThreaded ? undefined : (
|
|
2680
2746
|
<TouchableOpacity
|
|
@@ -2907,7 +2973,7 @@ export const CometChatMessageList = memo(
|
|
|
2907
2973
|
if (effectiveHideModeration) {
|
|
2908
2974
|
return hasTemplate?.BottomView && hasTemplate?.BottomView(message, bubbleAlignment);
|
|
2909
2975
|
} else {
|
|
2910
|
-
if (isOutgoing && moderationStatus === "disapproved") {
|
|
2976
|
+
if (isOutgoing && moderationStatus === "disapproved" && !isAgenticUser()) {
|
|
2911
2977
|
return (
|
|
2912
2978
|
<ModerationBottomView
|
|
2913
2979
|
status={moderationStatus}
|
|
@@ -3004,7 +3070,7 @@ export const CometChatMessageList = memo(
|
|
|
3004
3070
|
|
|
3005
3071
|
const moderationStatus = getModerationStatus(message);
|
|
3006
3072
|
const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
3007
|
-
if (isOutgoing && moderationStatus && moderationStatus !== "approved") return;
|
|
3073
|
+
if (isOutgoing && moderationStatus && moderationStatus !== "approved" && moderationStatus !== "unmoderated") return;
|
|
3008
3074
|
|
|
3009
3075
|
// Trigger reply if threshold is met
|
|
3010
3076
|
if (translationX > swipeThreshold || velocityX > 500) {
|
|
@@ -3198,30 +3264,6 @@ export const CometChatMessageList = memo(
|
|
|
3198
3264
|
});
|
|
3199
3265
|
}, [messagesList]);
|
|
3200
3266
|
|
|
3201
|
-
const showDateSeparatorAtIndex = useMemo(() => {
|
|
3202
|
-
const n = messagesList.length;
|
|
3203
|
-
const flags = new Array<boolean>(n).fill(false);
|
|
3204
|
-
// helper to find next non-null key to the right
|
|
3205
|
-
const nextNonNullKey = (startIdx: number) => {
|
|
3206
|
-
for (let j = startIdx; j < n; j++) {
|
|
3207
|
-
if (messageDayKeys[j] != null) return messageDayKeys[j];
|
|
3208
|
-
}
|
|
3209
|
-
return null;
|
|
3210
|
-
};
|
|
3211
|
-
|
|
3212
|
-
for (let i = 0; i < n; i++) {
|
|
3213
|
-
const currKey = messageDayKeys[i] ?? nextNonNullKey(i);
|
|
3214
|
-
const nextKey = i + 1 < n ? (messageDayKeys[i + 1] ?? nextNonNullKey(i + 1)) : null;
|
|
3215
|
-
if (currKey != null && currKey !== nextKey) {
|
|
3216
|
-
flags[i] = true;
|
|
3217
|
-
} else if (i === n - 1 && currKey != null) {
|
|
3218
|
-
// last message in list show header
|
|
3219
|
-
flags[i] = true;
|
|
3220
|
-
}
|
|
3221
|
-
}
|
|
3222
|
-
return flags;
|
|
3223
|
-
}, [messageDayKeys, messagesList.length]);
|
|
3224
|
-
|
|
3225
3267
|
const isSameLocalDay = (ms?: number) => {
|
|
3226
3268
|
if (!ms) return false;
|
|
3227
3269
|
const a = new Date(ms);
|
|
@@ -3261,10 +3303,13 @@ export const CometChatMessageList = memo(
|
|
|
3261
3303
|
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
3262
3304
|
);
|
|
3263
3305
|
|
|
3264
|
-
const keyExtractor = useCallback((item: any
|
|
3306
|
+
const keyExtractor = useCallback((item: any) => {
|
|
3265
3307
|
const id = item?.getId();
|
|
3266
3308
|
const muid = item?.getMuid();
|
|
3267
|
-
|
|
3309
|
+
if (!id && !muid) {
|
|
3310
|
+
console.log("item has no id or muid", item);
|
|
3311
|
+
}
|
|
3312
|
+
return `${id}_${muid}`;
|
|
3268
3313
|
}, []);
|
|
3269
3314
|
|
|
3270
3315
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
@@ -3495,7 +3540,7 @@ export const CometChatMessageList = memo(
|
|
|
3495
3540
|
|
|
3496
3541
|
const newestMessage = messagesContentListRef.current[0];
|
|
3497
3542
|
const newestMessageId = newestMessage.getId();
|
|
3498
|
-
|
|
3543
|
+
setBottomLoading(true);
|
|
3499
3544
|
loadingMessagesRef.current = true;
|
|
3500
3545
|
|
|
3501
3546
|
try {
|
|
@@ -3519,7 +3564,7 @@ export const CometChatMessageList = memo(
|
|
|
3519
3564
|
const uniqueNewMessages = nextMessages.filter(m => !existingIds.has(m.getId()));
|
|
3520
3565
|
|
|
3521
3566
|
if (uniqueNewMessages.length > 0) {
|
|
3522
|
-
const reversedNewMessages =
|
|
3567
|
+
const reversedNewMessages = uniqueNewMessages.reverse();
|
|
3523
3568
|
messagesContentListRef.current = [
|
|
3524
3569
|
...reversedNewMessages,
|
|
3525
3570
|
...messagesContentListRef.current
|
|
@@ -3535,11 +3580,20 @@ export const CometChatMessageList = memo(
|
|
|
3535
3580
|
} catch (error) {
|
|
3536
3581
|
console.error('[fetchNextMessages] Error:', error);
|
|
3537
3582
|
} finally {
|
|
3538
|
-
|
|
3583
|
+
setBottomLoading(false);
|
|
3539
3584
|
loadingMessagesRef.current = false;
|
|
3540
3585
|
}
|
|
3541
3586
|
};
|
|
3542
3587
|
|
|
3588
|
+
const renderFooter = () => {
|
|
3589
|
+
if (!bottomLoading) return null;
|
|
3590
|
+
return (
|
|
3591
|
+
<View style={{ padding: 10, alignItems: "center" }}>
|
|
3592
|
+
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
3593
|
+
</View>
|
|
3594
|
+
);
|
|
3595
|
+
};
|
|
3596
|
+
|
|
3543
3597
|
const handleScroll = (event: any) => {
|
|
3544
3598
|
if (loadingMessagesRef.current) {
|
|
3545
3599
|
return;
|
|
@@ -3618,7 +3672,18 @@ export const CometChatMessageList = memo(
|
|
|
3618
3672
|
const memoizedRenderItem = useCallback(
|
|
3619
3673
|
({ item, index, separators }: any) => {
|
|
3620
3674
|
// index here is FlatList's index in messagesList (newest-first)
|
|
3621
|
-
|
|
3675
|
+
let showSeparator = false;
|
|
3676
|
+
const nextItem = messagesContentListRef.current[index + 1];
|
|
3677
|
+
{
|
|
3678
|
+
const currentItemMs = sentAtToMs(item);
|
|
3679
|
+
const nextItemMs = sentAtToMs(nextItem);
|
|
3680
|
+
if (currentItemMs && nextItemMs) {
|
|
3681
|
+
showSeparator = new Date(currentItemMs).getDate() !== new Date(nextItemMs).getDate();
|
|
3682
|
+
}
|
|
3683
|
+
if (index === messagesContentListRef.current.length - 1 && messagesContentListRef.current.length < 30) {
|
|
3684
|
+
showSeparator = true;
|
|
3685
|
+
}
|
|
3686
|
+
}
|
|
3622
3687
|
const ms = sentAtToMs(item) ?? Date.now();
|
|
3623
3688
|
const isHighlighted = highlightedMessageId === String(item.getId());
|
|
3624
3689
|
|
|
@@ -3659,7 +3724,7 @@ export const CometChatMessageList = memo(
|
|
|
3659
3724
|
</View>
|
|
3660
3725
|
);
|
|
3661
3726
|
},
|
|
3662
|
-
[mergedTheme,
|
|
3727
|
+
[mergedTheme, highlightedMessageId]
|
|
3663
3728
|
);
|
|
3664
3729
|
|
|
3665
3730
|
return (
|
|
@@ -3691,6 +3756,9 @@ export const CometChatMessageList = memo(
|
|
|
3691
3756
|
<ActivityIndicator size='small' color={mergedTheme.color.primary} />
|
|
3692
3757
|
</View>
|
|
3693
3758
|
)}
|
|
3759
|
+
|
|
3760
|
+
{/* Navigation loading for far message fetching */}
|
|
3761
|
+
{navigationLoading && getLoadingStateView()}
|
|
3694
3762
|
|
|
3695
3763
|
<FlatList
|
|
3696
3764
|
showsVerticalScrollIndicator={false}
|
|
@@ -3698,6 +3766,13 @@ export const CometChatMessageList = memo(
|
|
|
3698
3766
|
onMomentumScrollEnd={handleScroll}
|
|
3699
3767
|
onScroll={shouldShowScrollToBottomButton}
|
|
3700
3768
|
inverted={true}
|
|
3769
|
+
maintainVisibleContentPosition={{
|
|
3770
|
+
minIndexForVisible: 0,
|
|
3771
|
+
}}
|
|
3772
|
+
onEndReached={getPreviousMessages}
|
|
3773
|
+
onEndReachedThreshold={0.5}
|
|
3774
|
+
onStartReached={fetchNextMessages}
|
|
3775
|
+
onStartReachedThreshold={0.5}
|
|
3701
3776
|
scrollEventThrottle={16}
|
|
3702
3777
|
keyboardShouldPersistTaps={Platform.OS === "ios" ? "handled" : "always"}
|
|
3703
3778
|
data={messagesList}
|
|
@@ -3706,6 +3781,7 @@ export const CometChatMessageList = memo(
|
|
|
3706
3781
|
onLayout={() => {
|
|
3707
3782
|
setIsListLayoutComplete(true);
|
|
3708
3783
|
}}
|
|
3784
|
+
ListHeaderComponent={renderFooter}
|
|
3709
3785
|
onScrollToIndexFailed={(error) => {
|
|
3710
3786
|
const averageItemLength = error.averageItemLength || 120;
|
|
3711
3787
|
const targetOffset = error.index * averageItemLength;
|