@cometchat/chat-uikit-react-native 5.2.3 → 5.2.4
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 +167 -86
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +312 -116
- package/src/CometChatMessageComposer/styles.tsx +2 -1
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +83 -17
- package/src/CometChatMessageList/CometChatMessageList.tsx +549 -70
- package/src/CometChatMessageList/style.ts +4 -2
- package/src/CometChatSearch/CometChatSearch.tsx +1718 -0
- package/src/CometChatSearch/SearchConstants.ts +46 -0
- package/src/CometChatSearch/Skeleton.tsx +192 -0
- package/src/CometChatSearch/index.ts +1 -0
- package/src/CometChatSearch/style.ts +414 -0
- package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +43 -7
- package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +45 -7
- package/src/extensions/Polls/Polls.tsx +36 -2
- package/src/extensions/Polls/PollsBubble.tsx +13 -9
- package/src/extensions/Polls/PollsDecorator.tsx +13 -1
- package/src/extensions/Stickers/StickersExtensionDecorator.tsx +50 -11
- package/src/extensions/Stickers/style.ts +0 -1
- package/src/index.ts +5 -0
- package/src/shared/base/Types.ts +8 -0
- package/src/shared/constants/UIKitConstants.ts +2 -0
- package/src/shared/events/CometChatMessageEvents/index.ts +8 -7
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
- package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +158 -27
- package/src/shared/framework/DataSource.ts +7 -0
- package/src/shared/framework/DataSourceDecorator.tsx +12 -0
- package/src/shared/framework/MessageDataSource.tsx +182 -1
- package/src/shared/helper/functions.js +0 -67
- package/src/shared/helper/helperFunctions.ts +73 -0
- package/src/shared/icons/components/documents.tsx +23 -0
- package/src/shared/icons/components/empty-search.tsx +52 -0
- package/src/shared/icons/components/message-blocked.tsx +1 -1
- package/src/shared/icons/components/unread.tsx +29 -0
- package/src/shared/icons/icon-mapping.tsx +7 -0
- package/src/shared/index.ts +2 -1
- package/src/shared/modals/CometChatMessageTemplate.ts +23 -0
- package/src/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.ts +4 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +17 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +70 -34
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +60 -24
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +60 -24
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +40 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +38 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +37 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +40 -4
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +274 -23
- package/src/shared/utils/MessageUtils.tsx +0 -1
- package/src/shared/views/CometChatAudioBubble/style.ts +0 -2
- package/src/shared/views/CometChatFileBubble/style.ts +0 -4
- package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
- package/src/shared/views/CometChatList/CometChatList.tsx +12 -0
- package/src/shared/views/CometChatList/Header.tsx +79 -49
- package/src/shared/views/CometChatMessageBubble/CometChatMessageBubble.tsx +14 -4
- package/src/shared/views/CometChatReportDialog/CometChatReportDialog.tsx +390 -0
- package/src/shared/views/CometChatReportDialog/index.ts +3 -0
- package/src/shared/views/CometChatReportDialog/style.ts +164 -0
- package/src/shared/views/CometChatStatusIndicator/private.png +0 -0
- package/src/shared/views/CometChatStatusIndicator/protected.png +0 -0
- package/src/shared/views/CometChatStatusIndicator/styles.ts +2 -2
- package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +18 -2
- package/src/shared/views/index.ts +6 -0
- package/src/theme/default/default.ts +3 -0
- package/src/theme/provider.tsx +7 -5
- package/src/theme/type.ts +2 -0
|
@@ -14,6 +14,7 @@ import React, {
|
|
|
14
14
|
} from "react";
|
|
15
15
|
import {
|
|
16
16
|
ActivityIndicator,
|
|
17
|
+
Animated,
|
|
17
18
|
Dimensions,
|
|
18
19
|
FlatList,
|
|
19
20
|
Keyboard,
|
|
@@ -27,6 +28,13 @@ import {
|
|
|
27
28
|
View,
|
|
28
29
|
ViewStyle,
|
|
29
30
|
} from "react-native";
|
|
31
|
+
import {
|
|
32
|
+
PanGestureHandler,
|
|
33
|
+
State,
|
|
34
|
+
PanGestureHandlerGestureEvent,
|
|
35
|
+
PanGestureHandlerStateChangeEvent,
|
|
36
|
+
} from "react-native-gesture-handler";
|
|
37
|
+
import { CometChatMessageEvents } from "../shared/events/CometChatMessageEvents";
|
|
30
38
|
import { CometChatMessageInformation } from "../CometChatMessageInformation/CometChatMessageInformation";
|
|
31
39
|
import {
|
|
32
40
|
CometChatActionSheet,
|
|
@@ -64,7 +72,7 @@ import { Icon } from "../shared/icons/Icon";
|
|
|
64
72
|
import { CometChatMessageTemplate } from "../shared/modals/CometChatMessageTemplate";
|
|
65
73
|
import { getUnixTimestamp, messageStatus } from "../shared/utils/CometChatMessageHelper";
|
|
66
74
|
import { CommonUtils } from "../shared/utils/CommonUtils";
|
|
67
|
-
import { CometChatConfirmDialog, CometChatReceipt } from "../shared/views";
|
|
75
|
+
import { CometChatConfirmDialog, CometChatReceipt, CometChatReportDialog } from "../shared/views";
|
|
68
76
|
import { CometChatAvatar } from "../shared/views/CometChatAvatar";
|
|
69
77
|
import { CometChatBadge } from "../shared/views/CometChatBadge";
|
|
70
78
|
import { CometChatDate } from "../shared/views/CometChatDate";
|
|
@@ -318,6 +326,10 @@ export interface CometChatMessageListProps {
|
|
|
318
326
|
* @param messageList - Array of CometChat.BaseMessage
|
|
319
327
|
*/
|
|
320
328
|
onEmpty?: () => void;
|
|
329
|
+
/**
|
|
330
|
+
* Flag to hide the reply option
|
|
331
|
+
*/
|
|
332
|
+
hideReplyOption?: boolean;
|
|
321
333
|
/**
|
|
322
334
|
* Flag to hide the reply in thread option
|
|
323
335
|
*/
|
|
@@ -354,6 +366,14 @@ export interface CometChatMessageListProps {
|
|
|
354
366
|
* Flag to hide the message info option
|
|
355
367
|
*/
|
|
356
368
|
hideMessageInfoOption?: boolean;
|
|
369
|
+
/**
|
|
370
|
+
* Flag to hide the "Flag Message" option from the actions menu
|
|
371
|
+
*/
|
|
372
|
+
hideFlagMessageOption?: boolean;
|
|
373
|
+
/**
|
|
374
|
+
* Flag to hide the remark text area in the flag dialog
|
|
375
|
+
*/
|
|
376
|
+
hideFlagRemarkField?: boolean;
|
|
357
377
|
/**
|
|
358
378
|
* Flag to hide group action messages
|
|
359
379
|
*/
|
|
@@ -394,6 +414,16 @@ export interface CometChatMessageListProps {
|
|
|
394
414
|
* Controls the speed of AI message streaming (only applies to @agentic users)
|
|
395
415
|
*/
|
|
396
416
|
streamingSpeed?: number;
|
|
417
|
+
/**
|
|
418
|
+
* Message ID to navigate to and highlight in the message list.
|
|
419
|
+
* When provided, the message list will fetch messages around this ID and scroll to it.
|
|
420
|
+
*/
|
|
421
|
+
goToMessageId?: string;
|
|
422
|
+
/**
|
|
423
|
+
* Search keyword to highlight in message text.
|
|
424
|
+
* When provided, matching text in messages will be highlighted.
|
|
425
|
+
*/
|
|
426
|
+
searchKeyword?: string;
|
|
397
427
|
}
|
|
398
428
|
|
|
399
429
|
/**
|
|
@@ -488,6 +518,7 @@ export const CometChatMessageList = memo(
|
|
|
488
518
|
addTemplates = [],
|
|
489
519
|
onLoad,
|
|
490
520
|
onEmpty,
|
|
521
|
+
hideReplyOption: propHideReplyOption = false,
|
|
491
522
|
hideReplyInThreadOption: propHideReplyInThreadOption = false,
|
|
492
523
|
hideShareMessageOption: propHideShareMessageOption = false,
|
|
493
524
|
hideEditMessageOption: propHideEditMessageOption = false,
|
|
@@ -507,6 +538,10 @@ export const CometChatMessageList = memo(
|
|
|
507
538
|
onSuggestedMessageClick,
|
|
508
539
|
aiAssistantTools,
|
|
509
540
|
streamingSpeed = 30,
|
|
541
|
+
goToMessageId,
|
|
542
|
+
searchKeyword,
|
|
543
|
+
hideFlagRemarkField,
|
|
544
|
+
hideFlagMessageOption: propHideFlagMessageOption = false,
|
|
510
545
|
} = props;
|
|
511
546
|
|
|
512
547
|
// Helper function to check if user is agentic
|
|
@@ -515,6 +550,7 @@ export const CometChatMessageList = memo(
|
|
|
515
550
|
}, [user]);
|
|
516
551
|
|
|
517
552
|
// hiding props for @agentic users
|
|
553
|
+
const hideReplyOption = isAgenticUser() ? true : propHideReplyOption;
|
|
518
554
|
const hideReplyInThreadOption = isAgenticUser() ? true : propHideReplyInThreadOption;
|
|
519
555
|
const hideShareMessageOption = isAgenticUser() ? true : propHideShareMessageOption;
|
|
520
556
|
const hideEditMessageOption = isAgenticUser() ? true : propHideEditMessageOption;
|
|
@@ -525,6 +561,7 @@ export const CometChatMessageList = memo(
|
|
|
525
561
|
const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
|
|
526
562
|
const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
|
|
527
563
|
const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
|
|
564
|
+
const hideFlagMessageOption = isAgenticUser() ? true : propHideFlagMessageOption;
|
|
528
565
|
|
|
529
566
|
const callListenerId = "call_" + new Date().getTime();
|
|
530
567
|
const effectiveHideModeration = hideModerationStatus;
|
|
@@ -632,14 +669,24 @@ export const CometChatMessageList = memo(
|
|
|
632
669
|
outgoing: deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.imageBubbleStyles ?? {}),
|
|
633
670
|
});
|
|
634
671
|
|
|
672
|
+
const fileIncoming = deepMerge(incomingBubbleStyles, incomingBubbleStyles.fileBubbleStyles ?? {});
|
|
673
|
+
if (fileIncoming.containerStyle) fileIncoming.containerStyle.height = undefined;
|
|
674
|
+
const fileOutgoing = deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.fileBubbleStyles ?? {});
|
|
675
|
+
if (fileOutgoing.containerStyle) fileOutgoing.containerStyle.height = undefined;
|
|
676
|
+
|
|
635
677
|
styleCache.set(MessageTypeConstants.file, {
|
|
636
|
-
incoming:
|
|
637
|
-
outgoing:
|
|
678
|
+
incoming: fileIncoming,
|
|
679
|
+
outgoing: fileOutgoing,
|
|
638
680
|
});
|
|
639
681
|
|
|
682
|
+
const audioIncoming = deepMerge(incomingBubbleStyles, incomingBubbleStyles.audioBubbleStyles ?? {});
|
|
683
|
+
if (audioIncoming.containerStyle) audioIncoming.containerStyle.height = undefined;
|
|
684
|
+
const audioOutgoing = deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.audioBubbleStyles ?? {});
|
|
685
|
+
if (audioOutgoing.containerStyle) audioOutgoing.containerStyle.height = undefined;
|
|
686
|
+
|
|
640
687
|
styleCache.set(MessageTypeConstants.audio, {
|
|
641
|
-
incoming:
|
|
642
|
-
outgoing:
|
|
688
|
+
incoming: audioIncoming,
|
|
689
|
+
outgoing: audioOutgoing,
|
|
643
690
|
});
|
|
644
691
|
|
|
645
692
|
styleCache.set(MessageTypeConstants.messageDeleted, {
|
|
@@ -781,6 +828,7 @@ export const CometChatMessageList = memo(
|
|
|
781
828
|
const [ExtensionsComponent, setExtensionsComponent] = useState<JSX.Element | null>(null);
|
|
782
829
|
const [CustomListHeader, setCustomListHeader] = useState<any>(null);
|
|
783
830
|
const [messageInfo, setMessageInfo] = useState(false);
|
|
831
|
+
const [showReportDialog, setShowReportDialog] = useState(false);
|
|
784
832
|
const [ongoingCallView, setOngoingCallView] = useState(null);
|
|
785
833
|
const [selectedMessage, setSelectedMessage] = useState<any>(null);
|
|
786
834
|
const [showEmojiKeyboard, setShowEmojiKeyboard] = useState(false);
|
|
@@ -790,12 +838,21 @@ export const CometChatMessageList = memo(
|
|
|
790
838
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
|
791
839
|
|
|
792
840
|
const infoObject = useRef<CometChat.BaseMessage | null>(undefined);
|
|
841
|
+
const [highlightedMessageId, setHighlightedMessageId] = useState<string | null>(null);
|
|
842
|
+
const [scrollTargetId, setScrollTargetId] = useState<string | null>(null);
|
|
843
|
+
const highlightAnimatedValue = useRef(new Animated.Value(0)).current;
|
|
844
|
+
const [isListLayoutComplete, setIsListLayoutComplete] = useState<boolean>(false);
|
|
845
|
+
const reportedMessageRef = useRef<CometChat.BaseMessage | null>(null);
|
|
846
|
+
const pendingReportRef = useRef<boolean>(false);
|
|
793
847
|
const bottomSheetRef = useRef<any>(null);
|
|
794
848
|
const conversationId = useRef<string | null>(null);
|
|
795
849
|
const streamSubscriptionRef = useRef<any>(null);
|
|
796
850
|
let lastID = useRef(0);
|
|
797
851
|
let reachedFirstMessage = useRef<boolean>(false);
|
|
798
852
|
const agenticParentMessageIdRef = useRef<string | undefined>(undefined);
|
|
853
|
+
const [hasTargetMessageId, setHasTargetMessageId] = useState(false);
|
|
854
|
+
const hasReachedBottomRef = useRef(true);
|
|
855
|
+
const fetchingAroundIdRef = useRef<string | null>(null); // Track which message ID we're currently fetching
|
|
799
856
|
const markUnreadMessageAsRead = () => {
|
|
800
857
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
801
858
|
message: messagesContentListRef.current[0],
|
|
@@ -804,17 +861,34 @@ export const CometChatMessageList = memo(
|
|
|
804
861
|
setUnreadCount(0);
|
|
805
862
|
};
|
|
806
863
|
|
|
807
|
-
const newMsgIndicatorPressed = useCallback(() => {
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
864
|
+
const newMsgIndicatorPressed = useCallback(async () => {
|
|
865
|
+
if (hasTargetMessageId) {
|
|
866
|
+
try {
|
|
867
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
868
|
+
messagesContentListRef.current = [];
|
|
869
|
+
setMessagesList([]);
|
|
870
|
+
setListState("loading");
|
|
871
|
+
await getPreviousMessages();
|
|
872
|
+
setTimeout(() => {
|
|
873
|
+
scrollToBottom();
|
|
874
|
+
setHideScrollToBottomButton(true);
|
|
875
|
+
}, 100);
|
|
876
|
+
} catch (error) {
|
|
877
|
+
setListState("");
|
|
878
|
+
}
|
|
879
|
+
} else {
|
|
880
|
+
messagesContentListRef.current = [
|
|
881
|
+
...temporaryMessageListRef.current,
|
|
882
|
+
...messagesContentListRef.current,
|
|
883
|
+
];
|
|
884
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
885
|
+
setMessagesList((prev) => [...temporaryMessageListRef.current, ...prev]);
|
|
886
|
+
temporaryMessageListRef.current = [];
|
|
887
|
+
scrollToBottom();
|
|
888
|
+
setHideScrollToBottomButton(true);
|
|
889
|
+
markUnreadMessageAsRead();
|
|
890
|
+
}
|
|
891
|
+
}, [onLoad, hasTargetMessageId]);
|
|
818
892
|
|
|
819
893
|
const getPreviousMessages = async () => {
|
|
820
894
|
// For agent chats (non-thread), don't fetch previous messages
|
|
@@ -889,11 +963,18 @@ export const CometChatMessageList = memo(
|
|
|
889
963
|
}
|
|
890
964
|
);
|
|
891
965
|
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
|
+
|
|
892
969
|
messagesContentListRef.current = [
|
|
893
970
|
...messagesContentListRef.current,
|
|
894
|
-
...
|
|
971
|
+
...newMessages,
|
|
895
972
|
];
|
|
896
|
-
setMessagesList((prev) =>
|
|
973
|
+
setMessagesList((prev) => {
|
|
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
|
+
});
|
|
897
978
|
}
|
|
898
979
|
if (messagesContentListRef.current.length == 0) {
|
|
899
980
|
onEmpty && onEmpty();
|
|
@@ -915,6 +996,142 @@ export const CometChatMessageList = memo(
|
|
|
915
996
|
});
|
|
916
997
|
};
|
|
917
998
|
|
|
999
|
+
const highlightMessage = (messageId: string) => {
|
|
1000
|
+
setHighlightedMessageId(messageId);
|
|
1001
|
+
highlightAnimatedValue.setValue(0);
|
|
1002
|
+
Animated.sequence([
|
|
1003
|
+
Animated.timing(highlightAnimatedValue, {
|
|
1004
|
+
toValue: 1,
|
|
1005
|
+
duration: 300,
|
|
1006
|
+
useNativeDriver: false,
|
|
1007
|
+
}),
|
|
1008
|
+
Animated.delay(2000), // Hold highlighted state for 2 seconds
|
|
1009
|
+
Animated.timing(highlightAnimatedValue, {
|
|
1010
|
+
toValue: 0,
|
|
1011
|
+
duration: 500,
|
|
1012
|
+
useNativeDriver: false,
|
|
1013
|
+
}),
|
|
1014
|
+
]).start(() => {
|
|
1015
|
+
setHighlightedMessageId(null);
|
|
1016
|
+
});
|
|
1017
|
+
};
|
|
1018
|
+
|
|
1019
|
+
const getMessagesAroundId = async (messageId: string) => {
|
|
1020
|
+
if (fetchingAroundIdRef.current === messageId) {
|
|
1021
|
+
return;
|
|
1022
|
+
}
|
|
1023
|
+
|
|
1024
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
1025
|
+
return;
|
|
1026
|
+
}
|
|
1027
|
+
|
|
1028
|
+
fetchingAroundIdRef.current = messageId; // Mark this message as being fetched
|
|
1029
|
+
setListState("loading");
|
|
1030
|
+
setHasTargetMessageId(true); // Track that we're navigating to a specific message
|
|
1031
|
+
|
|
1032
|
+
try {
|
|
1033
|
+
const targetMessageId = Number(messageId);
|
|
1034
|
+
|
|
1035
|
+
// Get the target message first to ensure it exists
|
|
1036
|
+
const targetMessage = await CometChat.getMessageDetails(targetMessageId);
|
|
1037
|
+
if (!targetMessage) {
|
|
1038
|
+
setListState("");
|
|
1039
|
+
return;
|
|
1040
|
+
}
|
|
1041
|
+
|
|
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
|
+
// Create request builder for next messages (messages after the target)
|
|
1048
|
+
let nextMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
1049
|
+
.setLimit(15)
|
|
1050
|
+
.setMessageId(targetMessageId);
|
|
1051
|
+
|
|
1052
|
+
if (user) {
|
|
1053
|
+
prevMessagesRequest = prevMessagesRequest.setUID(user.getUid());
|
|
1054
|
+
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
if (group) {
|
|
1058
|
+
prevMessagesRequest = prevMessagesRequest.setGUID(group.getGuid());
|
|
1059
|
+
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
1060
|
+
}
|
|
1061
|
+
|
|
1062
|
+
if (parentMessageId) {
|
|
1063
|
+
prevMessagesRequest = prevMessagesRequest.setParentMessageId(Number(parentMessageId));
|
|
1064
|
+
nextMessagesRequest = nextMessagesRequest.setParentMessageId(Number(parentMessageId));
|
|
1065
|
+
}
|
|
1066
|
+
|
|
1067
|
+
// Fetch messages before and after the target message
|
|
1068
|
+
const previousMessages = await prevMessagesRequest.build().fetchPrevious();
|
|
1069
|
+
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
1070
|
+
|
|
1071
|
+
// Combine messages: previous (reversed) + target + next
|
|
1072
|
+
const allMessages = [
|
|
1073
|
+
...previousMessages.reverse(),
|
|
1074
|
+
targetMessage,
|
|
1075
|
+
...nextMessages
|
|
1076
|
+
];
|
|
1077
|
+
|
|
1078
|
+
// Remove duplicates and sort by timestamp (newest at top for FlatList)
|
|
1079
|
+
const uniqueMessages = allMessages
|
|
1080
|
+
.filter((message, index, array) =>
|
|
1081
|
+
array.findIndex(m => m.getId() === message.getId()) === index
|
|
1082
|
+
)
|
|
1083
|
+
.sort((a, b) => b.getSentAt() - a.getSentAt());
|
|
1084
|
+
|
|
1085
|
+
if (uniqueMessages.length > 0) {
|
|
1086
|
+
messagesContentListRef.current = uniqueMessages;
|
|
1087
|
+
setMessagesList(uniqueMessages);
|
|
1088
|
+
onLoad && onLoad([...uniqueMessages].reverse());
|
|
1089
|
+
|
|
1090
|
+
// Reset layout state and set up for scrolling to target message
|
|
1091
|
+
setScrollTargetId(messageId);
|
|
1092
|
+
}
|
|
1093
|
+
|
|
1094
|
+
setListState("");
|
|
1095
|
+
} catch (error) {
|
|
1096
|
+
console.log("Error fetching messages around ID:", error);
|
|
1097
|
+
setListState("error");
|
|
1098
|
+
onError && onError(error as CometChat.CometChatException);
|
|
1099
|
+
} finally {
|
|
1100
|
+
fetchingAroundIdRef.current = null;
|
|
1101
|
+
}
|
|
1102
|
+
};
|
|
1103
|
+
|
|
1104
|
+
const scrollToMessage = (messageId: string) => {
|
|
1105
|
+
if (messageListRef.current && messagesContentListRef.current.length > 0) {
|
|
1106
|
+
const targetIndex = messagesContentListRef.current.findIndex(
|
|
1107
|
+
(msg) => String(msg.getId()) === messageId
|
|
1108
|
+
);
|
|
1109
|
+
|
|
1110
|
+
if (targetIndex !== -1) {
|
|
1111
|
+
// Message exists in list, just scroll to it without refetching
|
|
1112
|
+
try {
|
|
1113
|
+
messageListRef.current?.scrollToIndex({
|
|
1114
|
+
index: targetIndex,
|
|
1115
|
+
animated: true,
|
|
1116
|
+
viewPosition: 0.5, // Center the message
|
|
1117
|
+
});
|
|
1118
|
+
highlightMessage(messageId);
|
|
1119
|
+
} catch (scrollError) {
|
|
1120
|
+
console.error('Error during scrollToIndex execution:', scrollError);
|
|
1121
|
+
// Fallback to offset scroll if scrollToIndex fails
|
|
1122
|
+
const approximateOffset = targetIndex * 120;
|
|
1123
|
+
messageListRef.current?.scrollToOffset({
|
|
1124
|
+
offset: approximateOffset,
|
|
1125
|
+
animated: true,
|
|
1126
|
+
});
|
|
1127
|
+
highlightMessage(messageId);
|
|
1128
|
+
}
|
|
1129
|
+
} else {
|
|
1130
|
+
getMessagesAroundId(messageId);
|
|
1131
|
+
}
|
|
1132
|
+
}
|
|
1133
|
+
};
|
|
1134
|
+
|
|
918
1135
|
const getUpdatedPreviousMessages = () => {
|
|
919
1136
|
// For agent chats (non-thread), don't fetch updated previous messages
|
|
920
1137
|
if (isAgenticUser() && !parentMessageId) {
|
|
@@ -1008,6 +1225,7 @@ export const CometChatMessageList = memo(
|
|
|
1008
1225
|
const isAgenticUserCheck = isAgenticUser();
|
|
1009
1226
|
const options = {
|
|
1010
1227
|
textFormatters: textFormatters || [],
|
|
1228
|
+
hideReplyOption: isAgenticUserCheck || hideReplyOption,
|
|
1011
1229
|
hideReplyInThreadOption: isAgenticUserCheck || hideReplyInThreadOption,
|
|
1012
1230
|
hideShareMessageOption: isAgenticUserCheck || hideShareMessageOption,
|
|
1013
1231
|
hideEditMessageOption: isAgenticUserCheck || hideEditMessageOption,
|
|
@@ -1017,7 +1235,11 @@ export const CometChatMessageList = memo(
|
|
|
1017
1235
|
hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
|
|
1018
1236
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1019
1237
|
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
|
|
1238
|
+
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1020
1239
|
hideGroupActionMessages,
|
|
1240
|
+
onReplyClick: (messageId: string) => {
|
|
1241
|
+
scrollToMessage(messageId);
|
|
1242
|
+
},
|
|
1021
1243
|
};
|
|
1022
1244
|
let _formatters = textFormatters || [];
|
|
1023
1245
|
let tempTemplates: CometChatMessageTemplate[] =
|
|
@@ -1200,6 +1422,20 @@ export const CometChatMessageList = memo(
|
|
|
1200
1422
|
}
|
|
1201
1423
|
}, [parentMessageId, isAgenticUser]);
|
|
1202
1424
|
|
|
1425
|
+
// Handle scrolling to highlighted message when FlatList layout is complete
|
|
1426
|
+
useEffect(() => {
|
|
1427
|
+
let timer: any;
|
|
1428
|
+
if (scrollTargetId && messagesList.length > 0) {
|
|
1429
|
+
timer = setTimeout(() => {
|
|
1430
|
+
scrollToMessage(scrollTargetId);
|
|
1431
|
+
setScrollTargetId(null);
|
|
1432
|
+
}, 100);
|
|
1433
|
+
}
|
|
1434
|
+
return () => {
|
|
1435
|
+
if (timer) clearTimeout(timer);
|
|
1436
|
+
};
|
|
1437
|
+
}, [scrollTargetId, messagesList.length]);
|
|
1438
|
+
|
|
1203
1439
|
function checkSameConversation(message: CometChat.BaseMessage): boolean {
|
|
1204
1440
|
if ((message as any).isStreamMessage) {
|
|
1205
1441
|
if (isAgenticUser()) {
|
|
@@ -1304,10 +1540,8 @@ export const CometChatMessageList = memo(
|
|
|
1304
1540
|
|
|
1305
1541
|
const isAtBottom = () => {
|
|
1306
1542
|
//0 or null
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
}
|
|
1310
|
-
return false;
|
|
1543
|
+
const atBottom = !currentScrollPosition.current.y || currentScrollPosition.current.y === 0;
|
|
1544
|
+
return atBottom;
|
|
1311
1545
|
};
|
|
1312
1546
|
|
|
1313
1547
|
const bottomHandler = (
|
|
@@ -1572,7 +1806,11 @@ export const CometChatMessageList = memo(
|
|
|
1572
1806
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1573
1807
|
}
|
|
1574
1808
|
if (!isAgenticUser() || (isAgenticUser() && parentMessageId)) {
|
|
1575
|
-
|
|
1809
|
+
if (goToMessageId) {
|
|
1810
|
+
getMessagesAroundId(goToMessageId);
|
|
1811
|
+
} else {
|
|
1812
|
+
getPreviousMessages();
|
|
1813
|
+
}
|
|
1576
1814
|
}
|
|
1577
1815
|
})
|
|
1578
1816
|
.catch((e: any) => {
|
|
@@ -2244,9 +2482,7 @@ export const CometChatMessageList = memo(
|
|
|
2244
2482
|
else messageState = MessageReceipt.ERROR;
|
|
2245
2483
|
|
|
2246
2484
|
// Moderation overrides
|
|
2247
|
-
if (moderationStatus === "
|
|
2248
|
-
messageState = MessageReceipt.WAIT; // show wait icon until approved/disapproved
|
|
2249
|
-
} else if (moderationStatus === "disapproved") {
|
|
2485
|
+
if (moderationStatus === "disapproved") {
|
|
2250
2486
|
messageState = MessageReceipt.ERROR;
|
|
2251
2487
|
}
|
|
2252
2488
|
// Determine if message has been edited.
|
|
@@ -2357,11 +2593,6 @@ export const CometChatMessageList = memo(
|
|
|
2357
2593
|
messageObject?.getReactions &&
|
|
2358
2594
|
messageObject?.getReactions() &&
|
|
2359
2595
|
messageObject?.getReactions().length > 0;
|
|
2360
|
-
const moderationStatus = getModerationStatus(messageObject);
|
|
2361
|
-
const isOutgoing = messageObject.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
2362
|
-
if (isOutgoing && moderationStatus && moderationStatus !== "unmoderated") {
|
|
2363
|
-
return null;
|
|
2364
|
-
}
|
|
2365
2596
|
return hasReaction
|
|
2366
2597
|
? (params: { maxContentWidth?: number }) => {
|
|
2367
2598
|
return (
|
|
@@ -2400,6 +2631,17 @@ export const CometChatMessageList = memo(
|
|
|
2400
2631
|
setShowMessageOptions([]);
|
|
2401
2632
|
};
|
|
2402
2633
|
|
|
2634
|
+
const openReportDialog = (message: any) => {
|
|
2635
|
+
reportedMessageRef.current = message;
|
|
2636
|
+
// On iOS wait for BottomSheet modal dismiss animation completion to avoid flashing
|
|
2637
|
+
if (Platform.OS === "ios") {
|
|
2638
|
+
pendingReportRef.current = true;
|
|
2639
|
+
} else {
|
|
2640
|
+
setShowReportDialog(true);
|
|
2641
|
+
}
|
|
2642
|
+
setShowMessageOptions([]);
|
|
2643
|
+
};
|
|
2644
|
+
|
|
2403
2645
|
const openThreadView = (...params: any[]) => {
|
|
2404
2646
|
if (onThreadRepliesPress) {
|
|
2405
2647
|
onThreadRepliesPress(params[0], () => (
|
|
@@ -2509,12 +2751,28 @@ export const CometChatMessageList = memo(
|
|
|
2509
2751
|
? template.options(loggedInUser.current, item, mergedTheme, group)
|
|
2510
2752
|
: []
|
|
2511
2753
|
: [];
|
|
2754
|
+
if (hideFlagMessageOption) {
|
|
2755
|
+
options = options.filter((opt: any) => opt.id !== MessageOptionConstants.reportMessage);
|
|
2756
|
+
}
|
|
2512
2757
|
let optionsWithPressHandling = options.map((option) => {
|
|
2513
2758
|
if (!option.onPress)
|
|
2514
2759
|
switch (option.id) {
|
|
2515
2760
|
case MessageOptionConstants.messageInformation:
|
|
2516
2761
|
option.onPress = openMessageInfo.bind(this, item);
|
|
2517
2762
|
break;
|
|
2763
|
+
case MessageOptionConstants.replyMessage:
|
|
2764
|
+
option.onPress = () => {
|
|
2765
|
+
// Trigger swipe-to-reply functionality
|
|
2766
|
+
CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
|
|
2767
|
+
message: item,
|
|
2768
|
+
status: messageStatus.inprogress,
|
|
2769
|
+
});
|
|
2770
|
+
setShowMessageOptions([]);
|
|
2771
|
+
};
|
|
2772
|
+
break;
|
|
2773
|
+
case MessageOptionConstants.reportMessage:
|
|
2774
|
+
option.onPress = openReportDialog.bind(this, item);
|
|
2775
|
+
break;
|
|
2518
2776
|
case MessageOptionConstants.replyInThread:
|
|
2519
2777
|
option.onPress = openThreadView.bind(this, item);
|
|
2520
2778
|
break;
|
|
@@ -2670,6 +2928,10 @@ export const CometChatMessageList = memo(
|
|
|
2670
2928
|
: getStatusInfoView(message, bubbleAlignment, currentIndex);
|
|
2671
2929
|
}, [hasTemplate, message, bubbleAlignment, currentIndex, getStatusInfoView]);
|
|
2672
2930
|
|
|
2931
|
+
const ReplyView = useMemo(() => {
|
|
2932
|
+
return hasTemplate?.ReplyView?.(message, bubbleAlignment) || null;
|
|
2933
|
+
}, [hasTemplate, message, bubbleAlignment]);
|
|
2934
|
+
|
|
2673
2935
|
if (hasTemplate) {
|
|
2674
2936
|
if (hasTemplate?.BubbleView) return hasTemplate?.BubbleView(message);
|
|
2675
2937
|
|
|
@@ -2691,25 +2953,121 @@ export const CometChatMessageList = memo(
|
|
|
2691
2953
|
Keyboard.dismiss();
|
|
2692
2954
|
}, []);
|
|
2693
2955
|
|
|
2956
|
+
// Swipe-to-reply functionality
|
|
2957
|
+
const onReply = useCallback(() => {
|
|
2958
|
+
if (message.getDeletedBy() != null) return;
|
|
2959
|
+
if (!message.getId()) return;
|
|
2960
|
+
|
|
2961
|
+
CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
|
|
2962
|
+
message: message,
|
|
2963
|
+
status: messageStatus.inprogress,
|
|
2964
|
+
});
|
|
2965
|
+
}, [message]);
|
|
2966
|
+
|
|
2967
|
+
const swipeAnimatedValue = useRef(new Animated.Value(0)).current;
|
|
2968
|
+
const replyIconOpacity = useRef(new Animated.Value(0)).current;
|
|
2969
|
+
|
|
2970
|
+
const handlePanGesture = useCallback((event: PanGestureHandlerGestureEvent) => {
|
|
2971
|
+
const { translationX, velocityX } = event.nativeEvent;
|
|
2972
|
+
|
|
2973
|
+
// Only allow swiping from left to right for replies
|
|
2974
|
+
if (translationX <= 0) return;
|
|
2975
|
+
|
|
2976
|
+
const swipeThreshold = 80; // Threshold to trigger reply
|
|
2977
|
+
const maxSwipeDistance = 120; // Maximum swipe distance
|
|
2978
|
+
|
|
2979
|
+
// Calculate progress (0 to 1)
|
|
2980
|
+
const progress = Math.min(translationX / maxSwipeDistance, 1);
|
|
2981
|
+
|
|
2982
|
+
// Update animated values
|
|
2983
|
+
swipeAnimatedValue.setValue(Math.min(translationX, maxSwipeDistance));
|
|
2984
|
+
replyIconOpacity.setValue(progress);
|
|
2985
|
+
}, []);
|
|
2986
|
+
|
|
2987
|
+
const handlePanStateChange = useCallback((event: PanGestureHandlerStateChangeEvent) => {
|
|
2988
|
+
const { state, translationX, velocityX } = event.nativeEvent;
|
|
2989
|
+
|
|
2990
|
+
if (state === State.END) {
|
|
2991
|
+
const swipeThreshold = 80;
|
|
2992
|
+
|
|
2993
|
+
// Reset animations
|
|
2994
|
+
Animated.parallel([
|
|
2995
|
+
Animated.spring(swipeAnimatedValue, {
|
|
2996
|
+
toValue: 0,
|
|
2997
|
+
useNativeDriver: true,
|
|
2998
|
+
}),
|
|
2999
|
+
Animated.spring(replyIconOpacity, {
|
|
3000
|
+
toValue: 0,
|
|
3001
|
+
useNativeDriver: true,
|
|
3002
|
+
}),
|
|
3003
|
+
]).start();
|
|
3004
|
+
|
|
3005
|
+
const moderationStatus = getModerationStatus(message);
|
|
3006
|
+
const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
3007
|
+
if (isOutgoing && moderationStatus && moderationStatus !== "approved") return;
|
|
3008
|
+
|
|
3009
|
+
// Trigger reply if threshold is met
|
|
3010
|
+
if (translationX > swipeThreshold || velocityX > 500) {
|
|
3011
|
+
onReply();
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
}, [onReply, message]);
|
|
3015
|
+
|
|
2694
3016
|
return (
|
|
2695
|
-
|
|
2696
|
-
|
|
2697
|
-
|
|
2698
|
-
|
|
2699
|
-
|
|
2700
|
-
|
|
2701
|
-
|
|
2702
|
-
|
|
2703
|
-
|
|
2704
|
-
|
|
2705
|
-
|
|
2706
|
-
|
|
2707
|
-
|
|
2708
|
-
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
3017
|
+
message.getCategory() === MessageCategoryConstants.action ? (
|
|
3018
|
+
<View style={{ position: 'relative' }}>
|
|
3019
|
+
<TouchableOpacity
|
|
3020
|
+
activeOpacity={1}
|
|
3021
|
+
onPress={Platform.OS === "ios" ? onPress : undefined}
|
|
3022
|
+
onLongPress={() => (showOptions ? onLongPress() : undefined)}
|
|
3023
|
+
>
|
|
3024
|
+
<CometChatMessageBubble
|
|
3025
|
+
id={`${message.getId()}`}
|
|
3026
|
+
LeadingView={LeadingView}
|
|
3027
|
+
HeaderView={HeaderView}
|
|
3028
|
+
FooterView={FooterView}
|
|
3029
|
+
ReplyView={ReplyView}
|
|
3030
|
+
alignment={isThreaded ? "left" : bubbleAlignment}
|
|
3031
|
+
ContentView={ContentView}
|
|
3032
|
+
ThreadView={ThreadedView}
|
|
3033
|
+
BottomView={BottomView}
|
|
3034
|
+
StatusInfoView={StatusInfoView}
|
|
3035
|
+
style={getCurrentBubbleStyle(message)}
|
|
3036
|
+
/>
|
|
3037
|
+
</TouchableOpacity>
|
|
3038
|
+
</View>
|
|
3039
|
+
) : (
|
|
3040
|
+
<PanGestureHandler
|
|
3041
|
+
onGestureEvent={handlePanGesture}
|
|
3042
|
+
onHandlerStateChange={handlePanStateChange}
|
|
3043
|
+
activeOffsetX={[-10, 10]}
|
|
3044
|
+
failOffsetY={[-50, 50]}
|
|
3045
|
+
>
|
|
3046
|
+
<Animated.View style={{ transform: [{ translateX: swipeAnimatedValue }] }}>
|
|
3047
|
+
<View style={{ position: 'relative' }}>
|
|
3048
|
+
<TouchableOpacity
|
|
3049
|
+
activeOpacity={1}
|
|
3050
|
+
onPress={Platform.OS === "ios" ? onPress : undefined}
|
|
3051
|
+
onLongPress={() => (showOptions ? onLongPress() : undefined)}
|
|
3052
|
+
>
|
|
3053
|
+
<CometChatMessageBubble
|
|
3054
|
+
id={`${message.getId()}`}
|
|
3055
|
+
LeadingView={LeadingView}
|
|
3056
|
+
HeaderView={HeaderView}
|
|
3057
|
+
FooterView={FooterView}
|
|
3058
|
+
ReplyView={ReplyView}
|
|
3059
|
+
alignment={isThreaded ? "left" : bubbleAlignment}
|
|
3060
|
+
ContentView={ContentView}
|
|
3061
|
+
ThreadView={ThreadedView}
|
|
3062
|
+
BottomView={BottomView}
|
|
3063
|
+
StatusInfoView={StatusInfoView}
|
|
3064
|
+
style={getCurrentBubbleStyle(message)}
|
|
3065
|
+
/>
|
|
3066
|
+
</TouchableOpacity>
|
|
3067
|
+
</View>
|
|
3068
|
+
</Animated.View>
|
|
3069
|
+
</PanGestureHandler>
|
|
3070
|
+
)
|
|
2713
3071
|
);
|
|
2714
3072
|
} else {
|
|
2715
3073
|
return null;
|
|
@@ -2724,6 +3082,7 @@ export const CometChatMessageList = memo(
|
|
|
2724
3082
|
getFooterView,
|
|
2725
3083
|
getLeadingView,
|
|
2726
3084
|
getAlignment,
|
|
3085
|
+
highlightedMessageId,
|
|
2727
3086
|
]
|
|
2728
3087
|
);
|
|
2729
3088
|
|
|
@@ -2902,7 +3261,11 @@ export const CometChatMessageList = memo(
|
|
|
2902
3261
|
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
2903
3262
|
);
|
|
2904
3263
|
|
|
2905
|
-
const keyExtractor = useCallback((item: any) =>
|
|
3264
|
+
const keyExtractor = useCallback((item: any, index: number) => {
|
|
3265
|
+
const id = item?.getId();
|
|
3266
|
+
const muid = item?.getMuid();
|
|
3267
|
+
return muid ? `${id}_${muid}` : `${id}_${index}`;
|
|
3268
|
+
}, []);
|
|
2906
3269
|
|
|
2907
3270
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
2908
3271
|
|
|
@@ -3125,6 +3488,58 @@ export const CometChatMessageList = memo(
|
|
|
3125
3488
|
);
|
|
3126
3489
|
}, []);
|
|
3127
3490
|
|
|
3491
|
+
const fetchNextMessages = async () => {
|
|
3492
|
+
if (loadingMessagesRef.current || !hasTargetMessageId) return;
|
|
3493
|
+
|
|
3494
|
+
if (messagesContentListRef.current.length === 0) return;
|
|
3495
|
+
|
|
3496
|
+
const newestMessage = messagesContentListRef.current[0];
|
|
3497
|
+
const newestMessageId = newestMessage.getId();
|
|
3498
|
+
setLoadingMessages(true);
|
|
3499
|
+
loadingMessagesRef.current = true;
|
|
3500
|
+
|
|
3501
|
+
try {
|
|
3502
|
+
let nextMessagesRequest = new CometChat.MessagesRequestBuilder()
|
|
3503
|
+
.setLimit(30)
|
|
3504
|
+
.setMessageId(newestMessageId);
|
|
3505
|
+
|
|
3506
|
+
if (user) {
|
|
3507
|
+
nextMessagesRequest = nextMessagesRequest.setUID(user.getUid());
|
|
3508
|
+
}
|
|
3509
|
+
if (group) {
|
|
3510
|
+
nextMessagesRequest = nextMessagesRequest.setGUID(group.getGuid());
|
|
3511
|
+
}
|
|
3512
|
+
if (parentMessageId) {
|
|
3513
|
+
nextMessagesRequest = nextMessagesRequest.setParentMessageId(Number(parentMessageId));
|
|
3514
|
+
}
|
|
3515
|
+
|
|
3516
|
+
const nextMessages = await nextMessagesRequest.build().fetchNext();
|
|
3517
|
+
if (nextMessages.length > 0) {
|
|
3518
|
+
const existingIds = new Set(messagesContentListRef.current.map(m => m.getId()));
|
|
3519
|
+
const uniqueNewMessages = nextMessages.filter(m => !existingIds.has(m.getId()));
|
|
3520
|
+
|
|
3521
|
+
if (uniqueNewMessages.length > 0) {
|
|
3522
|
+
const reversedNewMessages = [...uniqueNewMessages].reverse();
|
|
3523
|
+
messagesContentListRef.current = [
|
|
3524
|
+
...reversedNewMessages,
|
|
3525
|
+
...messagesContentListRef.current
|
|
3526
|
+
];
|
|
3527
|
+
|
|
3528
|
+
setMessagesList(messagesContentListRef.current);
|
|
3529
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
3530
|
+
}
|
|
3531
|
+
} else {
|
|
3532
|
+
setHasTargetMessageId(false);
|
|
3533
|
+
hasReachedBottomRef.current = true;
|
|
3534
|
+
}
|
|
3535
|
+
} catch (error) {
|
|
3536
|
+
console.error('[fetchNextMessages] Error:', error);
|
|
3537
|
+
} finally {
|
|
3538
|
+
setLoadingMessages(false);
|
|
3539
|
+
loadingMessagesRef.current = false;
|
|
3540
|
+
}
|
|
3541
|
+
};
|
|
3542
|
+
|
|
3128
3543
|
const handleScroll = (event: any) => {
|
|
3129
3544
|
if (loadingMessagesRef.current) {
|
|
3130
3545
|
return;
|
|
@@ -3141,7 +3556,9 @@ export const CometChatMessageList = memo(
|
|
|
3141
3556
|
Math.floor(contentOffset.y) >= Math.floor(contentSize.height - layoutMeasurement.height)
|
|
3142
3557
|
) {
|
|
3143
3558
|
getPreviousMessages();
|
|
3144
|
-
|
|
3559
|
+
}
|
|
3560
|
+
if (hasTargetMessageId && contentOffset.y <= 50) {
|
|
3561
|
+
fetchNextMessages();
|
|
3145
3562
|
}
|
|
3146
3563
|
scrollHandler(event);
|
|
3147
3564
|
};
|
|
@@ -3187,8 +3604,12 @@ export const CometChatMessageList = memo(
|
|
|
3187
3604
|
};
|
|
3188
3605
|
|
|
3189
3606
|
const scrollToBottom = useCallback((scrollToFirstUnread = false) => {
|
|
3190
|
-
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3191
|
-
|
|
3607
|
+
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3608
|
+
// Clear navigation flags
|
|
3609
|
+
setHasTargetMessageId(false);
|
|
3610
|
+
setHighlightedMessageId(null);
|
|
3611
|
+
hasReachedBottomRef.current = true;
|
|
3612
|
+
}, [hasTargetMessageId, messagesList.length]);
|
|
3192
3613
|
|
|
3193
3614
|
// const windowSize = useMemo(() => {
|
|
3194
3615
|
// return messagesList.length > 50 ? messagesList.length / 2 : 21;
|
|
@@ -3199,25 +3620,46 @@ export const CometChatMessageList = memo(
|
|
|
3199
3620
|
// index here is FlatList's index in messagesList (newest-first)
|
|
3200
3621
|
const showSeparator = showDateSeparatorAtIndex[index];
|
|
3201
3622
|
const ms = sentAtToMs(item) ?? Date.now();
|
|
3623
|
+
const isHighlighted = highlightedMessageId === String(item.getId());
|
|
3624
|
+
|
|
3625
|
+
const separatorHeight = showSeparator ? 40 : 0;
|
|
3626
|
+
|
|
3627
|
+
const animatedBackgroundStyle = {
|
|
3628
|
+
backgroundColor: highlightAnimatedValue.interpolate({
|
|
3629
|
+
inputRange: [0, 1],
|
|
3630
|
+
outputRange: ['transparent', String(mergedTheme.color.extendedPrimary200)],
|
|
3631
|
+
}),
|
|
3632
|
+
position: 'absolute' as 'absolute',
|
|
3633
|
+
left: 0,
|
|
3634
|
+
right: 0,
|
|
3635
|
+
top: separatorHeight,
|
|
3636
|
+
bottom: 0,
|
|
3637
|
+
zIndex: 1,
|
|
3638
|
+
};
|
|
3202
3639
|
|
|
3203
3640
|
return (
|
|
3204
|
-
<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8 }}>
|
|
3205
|
-
{
|
|
3206
|
-
<View style={
|
|
3207
|
-
<CometChatDateSeparator
|
|
3208
|
-
timeStamp={ms}
|
|
3209
|
-
pattern={"dayDateFormat"}
|
|
3210
|
-
customDateString={getDayHeaderString(ms)}
|
|
3211
|
-
style={mergedTheme.messageListStyles.dateSeparatorStyle}
|
|
3212
|
-
/>
|
|
3213
|
-
</View>
|
|
3641
|
+
<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8, position: 'relative' }}>
|
|
3642
|
+
{isHighlighted && (
|
|
3643
|
+
<Animated.View style={animatedBackgroundStyle} />
|
|
3214
3644
|
)}
|
|
3215
|
-
<
|
|
3216
|
-
|
|
3645
|
+
<View style={{ position: 'relative', zIndex: 2 }}>
|
|
3646
|
+
{showSeparator && (
|
|
3647
|
+
<View style={{ alignItems: "center", marginBottom: 8 }}>
|
|
3648
|
+
<CometChatDateSeparator
|
|
3649
|
+
timeStamp={ms}
|
|
3650
|
+
pattern={"dayDateFormat"}
|
|
3651
|
+
customDateString={getDayHeaderString(ms)}
|
|
3652
|
+
style={mergedTheme.messageListStyles.dateSeparatorStyle}
|
|
3653
|
+
/>
|
|
3654
|
+
</View>
|
|
3655
|
+
)}
|
|
3656
|
+
<RenderMessageItem item={item} theme={mergedTheme} idx={index} />
|
|
3657
|
+
{itemSeparator()}
|
|
3658
|
+
</View>
|
|
3217
3659
|
</View>
|
|
3218
3660
|
);
|
|
3219
3661
|
},
|
|
3220
|
-
[mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys]
|
|
3662
|
+
[mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys, highlightedMessageId, highlightAnimatedValue]
|
|
3221
3663
|
);
|
|
3222
3664
|
|
|
3223
3665
|
return (
|
|
@@ -3226,7 +3668,7 @@ export const CometChatMessageList = memo(
|
|
|
3226
3668
|
getLoadingStateView()
|
|
3227
3669
|
) : listState == "error" ? (
|
|
3228
3670
|
getErrorStateView()
|
|
3229
|
-
) :
|
|
3671
|
+
) : (
|
|
3230
3672
|
messagesList.length == 0 ? (
|
|
3231
3673
|
getEmptyStateView()
|
|
3232
3674
|
) : (
|
|
@@ -3261,6 +3703,17 @@ export const CometChatMessageList = memo(
|
|
|
3261
3703
|
data={messagesList}
|
|
3262
3704
|
keyExtractor={keyExtractor}
|
|
3263
3705
|
renderItem={memoizedRenderItem}
|
|
3706
|
+
onLayout={() => {
|
|
3707
|
+
setIsListLayoutComplete(true);
|
|
3708
|
+
}}
|
|
3709
|
+
onScrollToIndexFailed={(error) => {
|
|
3710
|
+
const averageItemLength = error.averageItemLength || 120;
|
|
3711
|
+
const targetOffset = error.index * averageItemLength;
|
|
3712
|
+
messageListRef.current?.scrollToOffset({
|
|
3713
|
+
offset: targetOffset,
|
|
3714
|
+
animated: true,
|
|
3715
|
+
});
|
|
3716
|
+
}}
|
|
3264
3717
|
/**Please do not push changes to windowSize without testing infinite scroll and UI interactions and response time**/
|
|
3265
3718
|
/**Test the same on release mode. Dev mode could be laggy**/
|
|
3266
3719
|
windowSize={33}
|
|
@@ -3283,7 +3736,7 @@ export const CometChatMessageList = memo(
|
|
|
3283
3736
|
)}
|
|
3284
3737
|
</View>
|
|
3285
3738
|
)
|
|
3286
|
-
)
|
|
3739
|
+
)}
|
|
3287
3740
|
|
|
3288
3741
|
{!hideScrollToBottomButton && (
|
|
3289
3742
|
<Pressable
|
|
@@ -3330,6 +3783,24 @@ export const CometChatMessageList = memo(
|
|
|
3330
3783
|
}}
|
|
3331
3784
|
/>
|
|
3332
3785
|
|
|
3786
|
+
<CometChatReportDialog
|
|
3787
|
+
isOpen={showReportDialog}
|
|
3788
|
+
message={reportedMessageRef.current || undefined}
|
|
3789
|
+
onCancel={() => {
|
|
3790
|
+
setShowReportDialog(false);
|
|
3791
|
+
reportedMessageRef.current = null;
|
|
3792
|
+
}}
|
|
3793
|
+
hideFlagRemarkField={hideFlagRemarkField}
|
|
3794
|
+
onReport={(payload) => {
|
|
3795
|
+
console.log("Report submitted", {
|
|
3796
|
+
messageId: payload.message?.getId?.(),
|
|
3797
|
+
payload,
|
|
3798
|
+
});
|
|
3799
|
+
setShowReportDialog(false);
|
|
3800
|
+
reportedMessageRef.current = null;
|
|
3801
|
+
}}
|
|
3802
|
+
/>
|
|
3803
|
+
|
|
3333
3804
|
<CometChatBottomSheet
|
|
3334
3805
|
ref={bottomSheetRef}
|
|
3335
3806
|
onClose={() => {
|
|
@@ -3339,8 +3810,16 @@ export const CometChatMessageList = memo(
|
|
|
3339
3810
|
setMessageInfo(false);
|
|
3340
3811
|
}}
|
|
3341
3812
|
onDismiss={() => {
|
|
3342
|
-
//
|
|
3343
|
-
Platform.OS === "ios"
|
|
3813
|
+
// iOS: Open any deferred modals only after dismiss animation completes
|
|
3814
|
+
if (Platform.OS === "ios") {
|
|
3815
|
+
if (deleteItem.current) {
|
|
3816
|
+
setShowDeleteModal(true);
|
|
3817
|
+
}
|
|
3818
|
+
if (pendingReportRef.current) {
|
|
3819
|
+
pendingReportRef.current = false;
|
|
3820
|
+
setShowReportDialog(true);
|
|
3821
|
+
}
|
|
3822
|
+
}
|
|
3344
3823
|
}}
|
|
3345
3824
|
isOpen={showMessageOptions.length > 0 || Boolean(ExtensionsComponent) || messageInfo}
|
|
3346
3825
|
style={{
|