@cometchat/chat-uikit-react-native 5.2.2 → 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 +170 -91
- 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 +603 -65
- package/src/CometChatMessageList/style.ts +47 -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/CometChatUIEventHandler.ts +3 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +8 -0
- package/src/shared/events/ListenerInitializer.ts +3 -0
- package/src/shared/events/messages.ts +1 -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 +32 -0
- package/src/shared/icons/components/unread.tsx +29 -0
- package/src/shared/icons/icon-mapping.tsx +9 -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 +22 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +75 -36
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +65 -27
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +66 -27
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +43 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +43 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +43 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +45 -7
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +43 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +43 -5
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +43 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +42 -4
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +45 -7
- package/src/shared/utils/CometChatMessagePreview/CometChatMessagePreview.tsx +274 -23
- package/src/shared/utils/MessageReceiptUtils.ts +32 -0
- package/src/shared/utils/MessageUtils.tsx +106 -4
- 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 +21 -1
|
@@ -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,12 +72,13 @@ 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";
|
|
71
79
|
import { CometChatEmojiKeyboard } from "../shared/views/CometChatEmojiKeyboard";
|
|
72
80
|
import { CometChatMessageBubble } from "../shared/views/CometChatMessageBubble";
|
|
81
|
+
import { getModerationStatus, ModerationBottomView } from "../shared/utils/MessageUtils";
|
|
73
82
|
import { CometChatQuickReactions } from "../shared/views/CometChatQuickReactions";
|
|
74
83
|
import { CometChatReactionList } from "../shared/views/CometChatReactionList";
|
|
75
84
|
import { CometChatReactions } from "../shared/views/CometChatReactions";
|
|
@@ -157,6 +166,10 @@ export interface CometChatMessageListProps {
|
|
|
157
166
|
* Custom sound URL for messages.
|
|
158
167
|
*/
|
|
159
168
|
customSoundForMessages?: string;
|
|
169
|
+
/**
|
|
170
|
+
* Hides moderation status UI (bottom view) and suppresses moderation toasts.
|
|
171
|
+
*/
|
|
172
|
+
hideModerationStatus?: boolean;
|
|
160
173
|
/**
|
|
161
174
|
* Alignment type for the message list.
|
|
162
175
|
*/
|
|
@@ -313,6 +326,10 @@ export interface CometChatMessageListProps {
|
|
|
313
326
|
* @param messageList - Array of CometChat.BaseMessage
|
|
314
327
|
*/
|
|
315
328
|
onEmpty?: () => void;
|
|
329
|
+
/**
|
|
330
|
+
* Flag to hide the reply option
|
|
331
|
+
*/
|
|
332
|
+
hideReplyOption?: boolean;
|
|
316
333
|
/**
|
|
317
334
|
* Flag to hide the reply in thread option
|
|
318
335
|
*/
|
|
@@ -349,6 +366,14 @@ export interface CometChatMessageListProps {
|
|
|
349
366
|
* Flag to hide the message info option
|
|
350
367
|
*/
|
|
351
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;
|
|
352
377
|
/**
|
|
353
378
|
* Flag to hide group action messages
|
|
354
379
|
*/
|
|
@@ -389,6 +414,16 @@ export interface CometChatMessageListProps {
|
|
|
389
414
|
* Controls the speed of AI message streaming (only applies to @agentic users)
|
|
390
415
|
*/
|
|
391
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;
|
|
392
427
|
}
|
|
393
428
|
|
|
394
429
|
/**
|
|
@@ -459,6 +494,7 @@ export const CometChatMessageList = memo(
|
|
|
459
494
|
receiptsVisibility = true,
|
|
460
495
|
disableSoundForMessages,
|
|
461
496
|
customSoundForMessages,
|
|
497
|
+
hideModerationStatus = false,
|
|
462
498
|
alignment = "standard",
|
|
463
499
|
avatarVisibility = true,
|
|
464
500
|
datePattern,
|
|
@@ -482,6 +518,7 @@ export const CometChatMessageList = memo(
|
|
|
482
518
|
addTemplates = [],
|
|
483
519
|
onLoad,
|
|
484
520
|
onEmpty,
|
|
521
|
+
hideReplyOption: propHideReplyOption = false,
|
|
485
522
|
hideReplyInThreadOption: propHideReplyInThreadOption = false,
|
|
486
523
|
hideShareMessageOption: propHideShareMessageOption = false,
|
|
487
524
|
hideEditMessageOption: propHideEditMessageOption = false,
|
|
@@ -501,6 +538,10 @@ export const CometChatMessageList = memo(
|
|
|
501
538
|
onSuggestedMessageClick,
|
|
502
539
|
aiAssistantTools,
|
|
503
540
|
streamingSpeed = 30,
|
|
541
|
+
goToMessageId,
|
|
542
|
+
searchKeyword,
|
|
543
|
+
hideFlagRemarkField,
|
|
544
|
+
hideFlagMessageOption: propHideFlagMessageOption = false,
|
|
504
545
|
} = props;
|
|
505
546
|
|
|
506
547
|
// Helper function to check if user is agentic
|
|
@@ -509,6 +550,7 @@ export const CometChatMessageList = memo(
|
|
|
509
550
|
}, [user]);
|
|
510
551
|
|
|
511
552
|
// hiding props for @agentic users
|
|
553
|
+
const hideReplyOption = isAgenticUser() ? true : propHideReplyOption;
|
|
512
554
|
const hideReplyInThreadOption = isAgenticUser() ? true : propHideReplyInThreadOption;
|
|
513
555
|
const hideShareMessageOption = isAgenticUser() ? true : propHideShareMessageOption;
|
|
514
556
|
const hideEditMessageOption = isAgenticUser() ? true : propHideEditMessageOption;
|
|
@@ -519,8 +561,10 @@ export const CometChatMessageList = memo(
|
|
|
519
561
|
const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
|
|
520
562
|
const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
|
|
521
563
|
const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
|
|
564
|
+
const hideFlagMessageOption = isAgenticUser() ? true : propHideFlagMessageOption;
|
|
522
565
|
|
|
523
566
|
const callListenerId = "call_" + new Date().getTime();
|
|
567
|
+
const effectiveHideModeration = hideModerationStatus;
|
|
524
568
|
const groupListenerId = "group_" + new Date().getTime();
|
|
525
569
|
const uiEventListener = "uiEvent_" + new Date().getTime();
|
|
526
570
|
const callEventListener = "callEvent_" + new Date().getTime();
|
|
@@ -625,14 +669,24 @@ export const CometChatMessageList = memo(
|
|
|
625
669
|
outgoing: deepMerge(outgoingBubbleStyles, outgoingBubbleStyles.imageBubbleStyles ?? {}),
|
|
626
670
|
});
|
|
627
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
|
+
|
|
628
677
|
styleCache.set(MessageTypeConstants.file, {
|
|
629
|
-
incoming:
|
|
630
|
-
outgoing:
|
|
678
|
+
incoming: fileIncoming,
|
|
679
|
+
outgoing: fileOutgoing,
|
|
631
680
|
});
|
|
632
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
|
+
|
|
633
687
|
styleCache.set(MessageTypeConstants.audio, {
|
|
634
|
-
incoming:
|
|
635
|
-
outgoing:
|
|
688
|
+
incoming: audioIncoming,
|
|
689
|
+
outgoing: audioOutgoing,
|
|
636
690
|
});
|
|
637
691
|
|
|
638
692
|
styleCache.set(MessageTypeConstants.messageDeleted, {
|
|
@@ -774,6 +828,7 @@ export const CometChatMessageList = memo(
|
|
|
774
828
|
const [ExtensionsComponent, setExtensionsComponent] = useState<JSX.Element | null>(null);
|
|
775
829
|
const [CustomListHeader, setCustomListHeader] = useState<any>(null);
|
|
776
830
|
const [messageInfo, setMessageInfo] = useState(false);
|
|
831
|
+
const [showReportDialog, setShowReportDialog] = useState(false);
|
|
777
832
|
const [ongoingCallView, setOngoingCallView] = useState(null);
|
|
778
833
|
const [selectedMessage, setSelectedMessage] = useState<any>(null);
|
|
779
834
|
const [showEmojiKeyboard, setShowEmojiKeyboard] = useState(false);
|
|
@@ -783,12 +838,21 @@ export const CometChatMessageList = memo(
|
|
|
783
838
|
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
|
784
839
|
|
|
785
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);
|
|
786
847
|
const bottomSheetRef = useRef<any>(null);
|
|
787
848
|
const conversationId = useRef<string | null>(null);
|
|
788
849
|
const streamSubscriptionRef = useRef<any>(null);
|
|
789
850
|
let lastID = useRef(0);
|
|
790
851
|
let reachedFirstMessage = useRef<boolean>(false);
|
|
791
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
|
|
792
856
|
const markUnreadMessageAsRead = () => {
|
|
793
857
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
794
858
|
message: messagesContentListRef.current[0],
|
|
@@ -797,17 +861,34 @@ export const CometChatMessageList = memo(
|
|
|
797
861
|
setUnreadCount(0);
|
|
798
862
|
};
|
|
799
863
|
|
|
800
|
-
const newMsgIndicatorPressed = useCallback(() => {
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
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]);
|
|
811
892
|
|
|
812
893
|
const getPreviousMessages = async () => {
|
|
813
894
|
// For agent chats (non-thread), don't fetch previous messages
|
|
@@ -882,11 +963,18 @@ export const CometChatMessageList = memo(
|
|
|
882
963
|
}
|
|
883
964
|
);
|
|
884
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
|
+
|
|
885
969
|
messagesContentListRef.current = [
|
|
886
970
|
...messagesContentListRef.current,
|
|
887
|
-
...
|
|
971
|
+
...newMessages,
|
|
888
972
|
];
|
|
889
|
-
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
|
+
});
|
|
890
978
|
}
|
|
891
979
|
if (messagesContentListRef.current.length == 0) {
|
|
892
980
|
onEmpty && onEmpty();
|
|
@@ -908,6 +996,142 @@ export const CometChatMessageList = memo(
|
|
|
908
996
|
});
|
|
909
997
|
};
|
|
910
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
|
+
|
|
911
1135
|
const getUpdatedPreviousMessages = () => {
|
|
912
1136
|
// For agent chats (non-thread), don't fetch updated previous messages
|
|
913
1137
|
if (isAgenticUser() && !parentMessageId) {
|
|
@@ -1001,6 +1225,7 @@ export const CometChatMessageList = memo(
|
|
|
1001
1225
|
const isAgenticUserCheck = isAgenticUser();
|
|
1002
1226
|
const options = {
|
|
1003
1227
|
textFormatters: textFormatters || [],
|
|
1228
|
+
hideReplyOption: isAgenticUserCheck || hideReplyOption,
|
|
1004
1229
|
hideReplyInThreadOption: isAgenticUserCheck || hideReplyInThreadOption,
|
|
1005
1230
|
hideShareMessageOption: isAgenticUserCheck || hideShareMessageOption,
|
|
1006
1231
|
hideEditMessageOption: isAgenticUserCheck || hideEditMessageOption,
|
|
@@ -1010,7 +1235,11 @@ export const CometChatMessageList = memo(
|
|
|
1010
1235
|
hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
|
|
1011
1236
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1012
1237
|
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
|
|
1238
|
+
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1013
1239
|
hideGroupActionMessages,
|
|
1240
|
+
onReplyClick: (messageId: string) => {
|
|
1241
|
+
scrollToMessage(messageId);
|
|
1242
|
+
},
|
|
1014
1243
|
};
|
|
1015
1244
|
let _formatters = textFormatters || [];
|
|
1016
1245
|
let tempTemplates: CometChatMessageTemplate[] =
|
|
@@ -1193,6 +1422,20 @@ export const CometChatMessageList = memo(
|
|
|
1193
1422
|
}
|
|
1194
1423
|
}, [parentMessageId, isAgenticUser]);
|
|
1195
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
|
+
|
|
1196
1439
|
function checkSameConversation(message: CometChat.BaseMessage): boolean {
|
|
1197
1440
|
if ((message as any).isStreamMessage) {
|
|
1198
1441
|
if (isAgenticUser()) {
|
|
@@ -1297,10 +1540,8 @@ export const CometChatMessageList = memo(
|
|
|
1297
1540
|
|
|
1298
1541
|
const isAtBottom = () => {
|
|
1299
1542
|
//0 or null
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
}
|
|
1303
|
-
return false;
|
|
1543
|
+
const atBottom = !currentScrollPosition.current.y || currentScrollPosition.current.y === 0;
|
|
1544
|
+
return atBottom;
|
|
1304
1545
|
};
|
|
1305
1546
|
|
|
1306
1547
|
const bottomHandler = (
|
|
@@ -1565,7 +1806,11 @@ export const CometChatMessageList = memo(
|
|
|
1565
1806
|
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1566
1807
|
}
|
|
1567
1808
|
if (!isAgenticUser() || (isAgenticUser() && parentMessageId)) {
|
|
1568
|
-
|
|
1809
|
+
if (goToMessageId) {
|
|
1810
|
+
getMessagesAroundId(goToMessageId);
|
|
1811
|
+
} else {
|
|
1812
|
+
getPreviousMessages();
|
|
1813
|
+
}
|
|
1569
1814
|
}
|
|
1570
1815
|
})
|
|
1571
1816
|
.catch((e: any) => {
|
|
@@ -1811,6 +2056,9 @@ export const CometChatMessageList = memo(
|
|
|
1811
2056
|
onMessageEdited: (editedMessage: any) => {
|
|
1812
2057
|
messageEdited(editedMessage);
|
|
1813
2058
|
},
|
|
2059
|
+
onMessageModerated: (moderatedMessage: any) => {
|
|
2060
|
+
messageEdited(moderatedMessage);
|
|
2061
|
+
},
|
|
1814
2062
|
onFormMessageReceived: (formMessage: any) => {
|
|
1815
2063
|
newMessage(formMessage);
|
|
1816
2064
|
},
|
|
@@ -2223,6 +2471,8 @@ export const CometChatMessageList = memo(
|
|
|
2223
2471
|
const nextItemIsDelivered =
|
|
2224
2472
|
messagesContentListRef.current[currentIndex! - 1] &&
|
|
2225
2473
|
messagesContentListRef.current[currentIndex! - 1].getDeliveredAt();
|
|
2474
|
+
// Moderation status should override other receipt states for immediate error display
|
|
2475
|
+
const moderationStatus = getModerationStatus(item);
|
|
2226
2476
|
if (item.getReadAt() || nextItemIsRead) messageState = MessageReceipt.READ;
|
|
2227
2477
|
else if (item.getDeliveredAt() || nextItemIsDelivered)
|
|
2228
2478
|
messageState = MessageReceipt.DELIVERED;
|
|
@@ -2231,6 +2481,10 @@ export const CometChatMessageList = memo(
|
|
|
2231
2481
|
else if (isOutgoingMessage) messageState = MessageReceipt.WAIT;
|
|
2232
2482
|
else messageState = MessageReceipt.ERROR;
|
|
2233
2483
|
|
|
2484
|
+
// Moderation overrides
|
|
2485
|
+
if (moderationStatus === "disapproved") {
|
|
2486
|
+
messageState = MessageReceipt.ERROR;
|
|
2487
|
+
}
|
|
2234
2488
|
// Determine if message has been edited.
|
|
2235
2489
|
// This example assumes you have a method (or property) like getEditedAt() that returns a timestamp when edited.
|
|
2236
2490
|
const isEdited =
|
|
@@ -2377,6 +2631,17 @@ export const CometChatMessageList = memo(
|
|
|
2377
2631
|
setShowMessageOptions([]);
|
|
2378
2632
|
};
|
|
2379
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
|
+
|
|
2380
2645
|
const openThreadView = (...params: any[]) => {
|
|
2381
2646
|
if (onThreadRepliesPress) {
|
|
2382
2647
|
onThreadRepliesPress(params[0], () => (
|
|
@@ -2406,6 +2671,11 @@ export const CometChatMessageList = memo(
|
|
|
2406
2671
|
let isThreaded = item.getReplyCount() > 0;
|
|
2407
2672
|
|
|
2408
2673
|
let _style = getCurrentBubbleStyle(item);
|
|
2674
|
+
const moderationStatus = getModerationStatus(item);
|
|
2675
|
+
const isOutgoing = item.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
2676
|
+
if (isOutgoing && moderationStatus && moderationStatus !== "unmoderated") {
|
|
2677
|
+
return undefined; // hide thread view if moderated
|
|
2678
|
+
}
|
|
2409
2679
|
return !isThreaded ? undefined : (
|
|
2410
2680
|
<TouchableOpacity
|
|
2411
2681
|
onPress={() => openThreadView(item, null)}
|
|
@@ -2481,12 +2751,28 @@ export const CometChatMessageList = memo(
|
|
|
2481
2751
|
? template.options(loggedInUser.current, item, mergedTheme, group)
|
|
2482
2752
|
: []
|
|
2483
2753
|
: [];
|
|
2754
|
+
if (hideFlagMessageOption) {
|
|
2755
|
+
options = options.filter((opt: any) => opt.id !== MessageOptionConstants.reportMessage);
|
|
2756
|
+
}
|
|
2484
2757
|
let optionsWithPressHandling = options.map((option) => {
|
|
2485
2758
|
if (!option.onPress)
|
|
2486
2759
|
switch (option.id) {
|
|
2487
2760
|
case MessageOptionConstants.messageInformation:
|
|
2488
2761
|
option.onPress = openMessageInfo.bind(this, item);
|
|
2489
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;
|
|
2490
2776
|
case MessageOptionConstants.replyInThread:
|
|
2491
2777
|
option.onPress = openThreadView.bind(this, item);
|
|
2492
2778
|
break;
|
|
@@ -2532,6 +2818,20 @@ export const CometChatMessageList = memo(
|
|
|
2532
2818
|
}
|
|
2533
2819
|
return option;
|
|
2534
2820
|
});
|
|
2821
|
+
// Restrict options for disapproved outgoing messages (only delete + copy for text)
|
|
2822
|
+
const moderationStatus = getModerationStatus(item);
|
|
2823
|
+
const isOutgoing = item.getSender?.()?.getUid?.() === loggedInUser.current?.getUid?.();
|
|
2824
|
+
if (moderationStatus === "disapproved" && isOutgoing) {
|
|
2825
|
+
optionsWithPressHandling = optionsWithPressHandling.filter((opt) => {
|
|
2826
|
+
if (opt.id === MessageOptionConstants.deleteMessage) return true;
|
|
2827
|
+
if (
|
|
2828
|
+
opt.id === MessageOptionConstants.copyMessage &&
|
|
2829
|
+
(item.getType?.() === MessageTypeConstants.text || item?.getType === MessageTypeConstants.text)
|
|
2830
|
+
)
|
|
2831
|
+
return true;
|
|
2832
|
+
return false;
|
|
2833
|
+
});
|
|
2834
|
+
}
|
|
2535
2835
|
setShowMessageOptions(optionsWithPressHandling);
|
|
2536
2836
|
},
|
|
2537
2837
|
[mergedTheme]
|
|
@@ -2602,8 +2902,24 @@ export const CometChatMessageList = memo(
|
|
|
2602
2902
|
}, [isThreaded, message, getLeadingView, hasTemplate, bubbleAlignment]);
|
|
2603
2903
|
|
|
2604
2904
|
const BottomView = useMemo(() => {
|
|
2605
|
-
|
|
2606
|
-
|
|
2905
|
+
const moderationStatus = getModerationStatus(message);
|
|
2906
|
+
const isOutgoing = message.getSender()?.getUid() === loggedInUser.current?.getUid();
|
|
2907
|
+
if (effectiveHideModeration) {
|
|
2908
|
+
return hasTemplate?.BottomView && hasTemplate?.BottomView(message, bubbleAlignment);
|
|
2909
|
+
} else {
|
|
2910
|
+
if (isOutgoing && moderationStatus === "disapproved") {
|
|
2911
|
+
return (
|
|
2912
|
+
<ModerationBottomView
|
|
2913
|
+
status={moderationStatus}
|
|
2914
|
+
moderationStyle={
|
|
2915
|
+
mergedTheme.messageListStyles.outgoingMessageBubbleStyles.moderationStyle
|
|
2916
|
+
}
|
|
2917
|
+
/>
|
|
2918
|
+
);
|
|
2919
|
+
}
|
|
2920
|
+
return hasTemplate?.BottomView && hasTemplate?.BottomView(message, bubbleAlignment);
|
|
2921
|
+
}
|
|
2922
|
+
}, [hasTemplate, message, bubbleAlignment, effectiveHideModeration]);
|
|
2607
2923
|
|
|
2608
2924
|
const StatusInfoView = useMemo(() => {
|
|
2609
2925
|
return hasTemplate?.StatusInfoView &&
|
|
@@ -2612,6 +2928,10 @@ export const CometChatMessageList = memo(
|
|
|
2612
2928
|
: getStatusInfoView(message, bubbleAlignment, currentIndex);
|
|
2613
2929
|
}, [hasTemplate, message, bubbleAlignment, currentIndex, getStatusInfoView]);
|
|
2614
2930
|
|
|
2931
|
+
const ReplyView = useMemo(() => {
|
|
2932
|
+
return hasTemplate?.ReplyView?.(message, bubbleAlignment) || null;
|
|
2933
|
+
}, [hasTemplate, message, bubbleAlignment]);
|
|
2934
|
+
|
|
2615
2935
|
if (hasTemplate) {
|
|
2616
2936
|
if (hasTemplate?.BubbleView) return hasTemplate?.BubbleView(message);
|
|
2617
2937
|
|
|
@@ -2633,25 +2953,121 @@ export const CometChatMessageList = memo(
|
|
|
2633
2953
|
Keyboard.dismiss();
|
|
2634
2954
|
}, []);
|
|
2635
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
|
+
|
|
2636
3016
|
return (
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
-
|
|
2640
|
-
|
|
2641
|
-
|
|
2642
|
-
|
|
2643
|
-
|
|
2644
|
-
|
|
2645
|
-
|
|
2646
|
-
|
|
2647
|
-
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
2654
|
-
|
|
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
|
+
)
|
|
2655
3071
|
);
|
|
2656
3072
|
} else {
|
|
2657
3073
|
return null;
|
|
@@ -2666,6 +3082,7 @@ export const CometChatMessageList = memo(
|
|
|
2666
3082
|
getFooterView,
|
|
2667
3083
|
getLeadingView,
|
|
2668
3084
|
getAlignment,
|
|
3085
|
+
highlightedMessageId,
|
|
2669
3086
|
]
|
|
2670
3087
|
);
|
|
2671
3088
|
|
|
@@ -2844,7 +3261,11 @@ export const CometChatMessageList = memo(
|
|
|
2844
3261
|
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
2845
3262
|
);
|
|
2846
3263
|
|
|
2847
|
-
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
|
+
}, []);
|
|
2848
3269
|
|
|
2849
3270
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
2850
3271
|
|
|
@@ -3067,6 +3488,58 @@ export const CometChatMessageList = memo(
|
|
|
3067
3488
|
);
|
|
3068
3489
|
}, []);
|
|
3069
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
|
+
|
|
3070
3543
|
const handleScroll = (event: any) => {
|
|
3071
3544
|
if (loadingMessagesRef.current) {
|
|
3072
3545
|
return;
|
|
@@ -3083,7 +3556,9 @@ export const CometChatMessageList = memo(
|
|
|
3083
3556
|
Math.floor(contentOffset.y) >= Math.floor(contentSize.height - layoutMeasurement.height)
|
|
3084
3557
|
) {
|
|
3085
3558
|
getPreviousMessages();
|
|
3086
|
-
|
|
3559
|
+
}
|
|
3560
|
+
if (hasTargetMessageId && contentOffset.y <= 50) {
|
|
3561
|
+
fetchNextMessages();
|
|
3087
3562
|
}
|
|
3088
3563
|
scrollHandler(event);
|
|
3089
3564
|
};
|
|
@@ -3129,8 +3604,12 @@ export const CometChatMessageList = memo(
|
|
|
3129
3604
|
};
|
|
3130
3605
|
|
|
3131
3606
|
const scrollToBottom = useCallback((scrollToFirstUnread = false) => {
|
|
3132
|
-
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3133
|
-
|
|
3607
|
+
messageListRef.current?.scrollToOffset({ offset: 0 });
|
|
3608
|
+
// Clear navigation flags
|
|
3609
|
+
setHasTargetMessageId(false);
|
|
3610
|
+
setHighlightedMessageId(null);
|
|
3611
|
+
hasReachedBottomRef.current = true;
|
|
3612
|
+
}, [hasTargetMessageId, messagesList.length]);
|
|
3134
3613
|
|
|
3135
3614
|
// const windowSize = useMemo(() => {
|
|
3136
3615
|
// return messagesList.length > 50 ? messagesList.length / 2 : 21;
|
|
@@ -3141,25 +3620,46 @@ export const CometChatMessageList = memo(
|
|
|
3141
3620
|
// index here is FlatList's index in messagesList (newest-first)
|
|
3142
3621
|
const showSeparator = showDateSeparatorAtIndex[index];
|
|
3143
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
|
+
};
|
|
3144
3639
|
|
|
3145
3640
|
return (
|
|
3146
|
-
<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8 }}>
|
|
3147
|
-
{
|
|
3148
|
-
<View style={
|
|
3149
|
-
<CometChatDateSeparator
|
|
3150
|
-
timeStamp={ms}
|
|
3151
|
-
pattern={"dayDateFormat"}
|
|
3152
|
-
customDateString={getDayHeaderString(ms)}
|
|
3153
|
-
style={mergedTheme.messageListStyles.dateSeparatorStyle}
|
|
3154
|
-
/>
|
|
3155
|
-
</View>
|
|
3641
|
+
<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8, position: 'relative' }}>
|
|
3642
|
+
{isHighlighted && (
|
|
3643
|
+
<Animated.View style={animatedBackgroundStyle} />
|
|
3156
3644
|
)}
|
|
3157
|
-
<
|
|
3158
|
-
|
|
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>
|
|
3159
3659
|
</View>
|
|
3160
3660
|
);
|
|
3161
3661
|
},
|
|
3162
|
-
[mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys]
|
|
3662
|
+
[mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys, highlightedMessageId, highlightAnimatedValue]
|
|
3163
3663
|
);
|
|
3164
3664
|
|
|
3165
3665
|
return (
|
|
@@ -3168,7 +3668,7 @@ export const CometChatMessageList = memo(
|
|
|
3168
3668
|
getLoadingStateView()
|
|
3169
3669
|
) : listState == "error" ? (
|
|
3170
3670
|
getErrorStateView()
|
|
3171
|
-
) :
|
|
3671
|
+
) : (
|
|
3172
3672
|
messagesList.length == 0 ? (
|
|
3173
3673
|
getEmptyStateView()
|
|
3174
3674
|
) : (
|
|
@@ -3203,6 +3703,17 @@ export const CometChatMessageList = memo(
|
|
|
3203
3703
|
data={messagesList}
|
|
3204
3704
|
keyExtractor={keyExtractor}
|
|
3205
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
|
+
}}
|
|
3206
3717
|
/**Please do not push changes to windowSize without testing infinite scroll and UI interactions and response time**/
|
|
3207
3718
|
/**Test the same on release mode. Dev mode could be laggy**/
|
|
3208
3719
|
windowSize={33}
|
|
@@ -3225,7 +3736,7 @@ export const CometChatMessageList = memo(
|
|
|
3225
3736
|
)}
|
|
3226
3737
|
</View>
|
|
3227
3738
|
)
|
|
3228
|
-
)
|
|
3739
|
+
)}
|
|
3229
3740
|
|
|
3230
3741
|
{!hideScrollToBottomButton && (
|
|
3231
3742
|
<Pressable
|
|
@@ -3272,6 +3783,24 @@ export const CometChatMessageList = memo(
|
|
|
3272
3783
|
}}
|
|
3273
3784
|
/>
|
|
3274
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
|
+
|
|
3275
3804
|
<CometChatBottomSheet
|
|
3276
3805
|
ref={bottomSheetRef}
|
|
3277
3806
|
onClose={() => {
|
|
@@ -3281,8 +3810,16 @@ export const CometChatMessageList = memo(
|
|
|
3281
3810
|
setMessageInfo(false);
|
|
3282
3811
|
}}
|
|
3283
3812
|
onDismiss={() => {
|
|
3284
|
-
//
|
|
3285
|
-
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
|
+
}
|
|
3286
3823
|
}}
|
|
3287
3824
|
isOpen={showMessageOptions.length > 0 || Boolean(ExtensionsComponent) || messageInfo}
|
|
3288
3825
|
style={{
|
|
@@ -3310,7 +3847,8 @@ export const CometChatMessageList = memo(
|
|
|
3310
3847
|
/>
|
|
3311
3848
|
) : (
|
|
3312
3849
|
<View style={{ flex: 1 }}>
|
|
3313
|
-
{
|
|
3850
|
+
{/* Show quick reactions for disapproved messages */}
|
|
3851
|
+
{!hideReactionOption && getModerationStatus(selectedMessage) !== "disapproved" && (
|
|
3314
3852
|
<CometChatQuickReactions
|
|
3315
3853
|
quickReactions={quickReactionList}
|
|
3316
3854
|
onReactionPress={reactToMessage}
|