@cometchat/chat-uikit-react-native 5.1.1 → 5.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/.gradle/7.4/checksums/checksums.lock +0 -0
- package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
- package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.d.ts +40 -0
- package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js +467 -0
- package/lib/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.js.map +1 -0
- package/lib/CometChatAIAssistantChatHistory/Skeleton.d.ts +24 -0
- package/lib/CometChatAIAssistantChatHistory/Skeleton.js +130 -0
- package/lib/CometChatAIAssistantChatHistory/Skeleton.js.map +1 -0
- package/lib/CometChatAIAssistantChatHistory/index.d.ts +1 -0
- package/lib/CometChatAIAssistantChatHistory/index.js +2 -0
- package/lib/CometChatAIAssistantChatHistory/index.js.map +1 -0
- package/lib/CometChatAIAssistantChatHistory/style.d.ts +30 -0
- package/lib/CometChatAIAssistantChatHistory/style.js +122 -0
- package/lib/CometChatAIAssistantChatHistory/style.js.map +1 -0
- package/lib/CometChatConversations/CometChatConversations.js +26 -5
- package/lib/CometChatConversations/CometChatConversations.js.map +1 -1
- package/lib/CometChatMessageComposer/CometChatMessageComposer.d.ts +7 -0
- package/lib/CometChatMessageComposer/CometChatMessageComposer.js +101 -13
- package/lib/CometChatMessageComposer/CometChatMessageComposer.js.map +1 -1
- package/lib/CometChatMessageHeader/CometChatMessageHeader.d.ts +16 -0
- package/lib/CometChatMessageHeader/CometChatMessageHeader.js +63 -13
- package/lib/CometChatMessageHeader/CometChatMessageHeader.js.map +1 -1
- package/lib/CometChatMessageList/CometChatMessageList.d.ts +33 -0
- package/lib/CometChatMessageList/CometChatMessageList.js +535 -76
- package/lib/CometChatMessageList/CometChatMessageList.js.map +1 -1
- package/lib/CometChatMessageList/style.js +74 -2
- package/lib/CometChatMessageList/style.js.map +1 -1
- package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js +6 -12
- package/lib/calls/CometChatIncomingCall/CometChatIncomingCall.js.map +1 -1
- package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js +4 -3
- package/lib/calls/CometChatOutgoingCall/CometChatOutgoingCall.js.map +1 -1
- package/lib/extensions/Polls/Polls.js +38 -17
- package/lib/extensions/Polls/Polls.js.map +1 -1
- package/lib/index.d.ts +5 -1
- package/lib/index.js +6 -2
- package/lib/index.js.map +1 -1
- package/lib/shared/constants/UIKitConstants.d.ts +16 -0
- package/lib/shared/constants/UIKitConstants.js +16 -0
- package/lib/shared/constants/UIKitConstants.js.map +1 -1
- package/lib/shared/events/CometChatMessageEvents/index.d.ts +3 -0
- package/lib/shared/events/CometChatMessageEvents/index.js +3 -0
- package/lib/shared/events/CometChatMessageEvents/index.js.map +1 -1
- package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js +3 -0
- package/lib/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.js.map +1 -1
- package/lib/shared/events/CometChatUIEventHandler/Listener.d.ts +3 -1
- package/lib/shared/events/CometChatUIEventHandler/Listener.js +4 -1
- package/lib/shared/events/CometChatUIEventHandler/Listener.js.map +1 -1
- package/lib/shared/events/ListenerInitializer.d.ts +3 -1
- package/lib/shared/events/ListenerInitializer.js +5 -1
- package/lib/shared/events/ListenerInitializer.js.map +1 -1
- package/lib/shared/events/messages.d.ts +2 -1
- package/lib/shared/events/messages.js +1 -0
- package/lib/shared/events/messages.js.map +1 -1
- package/lib/shared/framework/DataSource.d.ts +3 -1
- package/lib/shared/framework/DataSourceDecorator.d.ts +3 -1
- package/lib/shared/framework/DataSourceDecorator.js +8 -2
- package/lib/shared/framework/DataSourceDecorator.js.map +1 -1
- package/lib/shared/framework/MessageDataSource.d.ts +6 -0
- package/lib/shared/framework/MessageDataSource.js +64 -1
- package/lib/shared/framework/MessageDataSource.js.map +1 -1
- package/lib/shared/icons/components/ai-chat-history.d.ts +8 -0
- package/lib/shared/icons/components/ai-chat-history.js +9 -0
- package/lib/shared/icons/components/ai-chat-history.js.map +1 -0
- package/lib/shared/icons/components/ai-copy-option.d.ts +8 -0
- package/lib/shared/icons/components/ai-copy-option.js +9 -0
- package/lib/shared/icons/components/ai-copy-option.js.map +1 -0
- package/lib/shared/icons/components/ai-new-chat.d.ts +8 -0
- package/lib/shared/icons/components/ai-new-chat.js +9 -0
- package/lib/shared/icons/components/ai-new-chat.js.map +1 -0
- package/lib/shared/icons/components/ai-send-button.d.ts +8 -0
- package/lib/shared/icons/components/ai-send-button.js +9 -0
- package/lib/shared/icons/components/ai-send-button.js.map +1 -0
- package/lib/shared/icons/components/right-arrow.d.ts +3 -0
- package/lib/shared/icons/components/right-arrow.js +6 -0
- package/lib/shared/icons/components/right-arrow.js.map +1 -0
- package/lib/shared/icons/components/stop-fill.js +8 -7
- package/lib/shared/icons/components/stop-fill.js.map +1 -1
- package/lib/shared/icons/icon-mapping.d.ts +11 -0
- package/lib/shared/icons/icon-mapping.js +11 -0
- package/lib/shared/icons/icon-mapping.js.map +1 -1
- package/lib/shared/modals/CometChatAIAssistantTools.d.ts +47 -0
- package/lib/shared/modals/CometChatAIAssistantTools.js +44 -0
- package/lib/shared/modals/CometChatAIAssistantTools.js.map +1 -0
- package/lib/shared/modals/StreamMessage.d.ts +4 -0
- package/lib/shared/modals/StreamMessage.js +11 -0
- package/lib/shared/modals/StreamMessage.js.map +1 -0
- package/lib/shared/modals/index.d.ts +3 -1
- package/lib/shared/modals/index.js +3 -1
- package/lib/shared/modals/index.js.map +1 -1
- package/lib/shared/resources/CometChatLocalizeNew/CometChatLocalizationHelper.d.ts +126 -0
- package/lib/shared/resources/CometChatLocalizeNew/resources/de/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/en/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/es/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/it/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +7 -1
- package/lib/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +7 -1
- package/lib/shared/services/stream-message.service.d.ts +84 -0
- package/lib/shared/services/stream-message.service.js +406 -0
- package/lib/shared/services/stream-message.service.js.map +1 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.d.ts +9 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js +248 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.js.map +1 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/index.d.ts +3 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js +4 -0
- package/lib/shared/views/CometChatAIAssistantMessageBubble/index.js.map +1 -0
- package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js +5 -2
- package/lib/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.js.map +1 -1
- package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js +1 -1
- package/lib/shared/views/CometChatImageBubble/CometChatImageLoader.js.map +1 -1
- package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js +52 -32
- package/lib/shared/views/CometChatImageViewerModal/ImageViewerModal.js.map +1 -1
- package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.d.ts +10 -0
- package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js +54 -0
- package/lib/shared/views/CometChatSendButtonView/CometChatSendButtonView.js.map +1 -0
- package/lib/shared/views/CometChatSendButtonView/index.d.ts +1 -0
- package/lib/shared/views/CometChatSendButtonView/index.js +2 -0
- package/lib/shared/views/CometChatSendButtonView/index.js.map +1 -0
- package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.d.ts +8 -0
- package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js +436 -0
- package/lib/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.js.map +1 -0
- package/lib/shared/views/CometChatStreamMessageBubble/index.d.ts +3 -0
- package/lib/shared/views/CometChatStreamMessageBubble/index.js +3 -0
- package/lib/shared/views/CometChatStreamMessageBubble/index.js.map +1 -0
- package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.d.ts +14 -6
- package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js +82 -57
- package/lib/shared/views/CometChatTextBubble/CometChatTextBubble.js.map +1 -1
- package/lib/theme/context.d.ts +96 -15
- package/lib/theme/type.d.ts +14 -1
- package/package.json +6 -3
- package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +627 -0
- package/src/CometChatAIAssistantChatHistory/Skeleton.tsx +228 -0
- package/src/CometChatAIAssistantChatHistory/index.ts +2 -0
- package/src/CometChatAIAssistantChatHistory/style.ts +160 -0
- package/src/CometChatConversations/CometChatConversations.tsx +36 -10
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +137 -19
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +106 -18
- package/src/CometChatMessageList/CometChatMessageList.tsx +721 -116
- package/src/CometChatMessageList/style.ts +74 -2
- package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +13 -29
- package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +8 -5
- package/src/extensions/Polls/Polls.tsx +50 -22
- package/src/index.ts +31 -1
- package/src/shared/constants/UIKitConstants.ts +17 -0
- package/src/shared/events/CometChatMessageEvents/index.ts +3 -1
- package/src/shared/events/CometChatUIEventHandler/CometChatUIEventHandler.ts +3 -0
- package/src/shared/events/CometChatUIEventHandler/Listener.ts +4 -0
- package/src/shared/events/ListenerInitializer.ts +6 -1
- package/src/shared/events/messages.ts +1 -0
- package/src/shared/framework/DataSource.ts +4 -2
- package/src/shared/framework/DataSourceDecorator.tsx +10 -2
- package/src/shared/framework/MessageDataSource.tsx +75 -2
- package/src/shared/icons/Icon.tsx +1 -1
- package/src/shared/icons/components/ai-chat-history.tsx +21 -0
- package/src/shared/icons/components/ai-copy-option.tsx +21 -0
- package/src/shared/icons/components/ai-new-chat.tsx +21 -0
- package/src/shared/icons/components/ai-send-button.tsx +24 -0
- package/src/shared/icons/components/right-arrow.tsx +13 -0
- package/src/shared/icons/components/stop-fill.tsx +14 -12
- package/src/shared/icons/icon-mapping.tsx +14 -0
- package/src/shared/modals/CometChatAIAssistantTools.ts +65 -0
- package/src/shared/modals/StreamMessage.ts +12 -0
- package/src/shared/modals/index.ts +5 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +7 -2
- package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +7 -1
- package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +7 -1
- package/src/shared/services/stream-message.service.ts +470 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/CometChatAIAssistantMessageBubble.tsx +262 -0
- package/src/shared/views/CometChatAIAssistantMessageBubble/index.ts +4 -0
- package/src/shared/views/CometChatEmojiKeyboard/CometChatEmojiKeyboard.tsx +5 -1
- package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +1 -0
- package/src/shared/views/CometChatImageViewerModal/ImageViewerModal.tsx +57 -45
- package/src/shared/views/CometChatSendButtonView/CometChatSendButtonView.tsx +86 -0
- package/src/shared/views/CometChatSendButtonView/index.ts +1 -0
- package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +493 -0
- package/src/shared/views/CometChatStreamMessageBubble/index.ts +9 -0
- package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +121 -74
- package/src/theme/type.ts +14 -1
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.d.ts +0 -79
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js +0 -152
- package/lib/shared/resources/CometChatLocalize/CometChatLocalize.js.map +0 -1
- package/lib/shared/resources/CometChatLocalize/index.d.ts +0 -2
- package/lib/shared/resources/CometChatLocalize/index.js +0 -3
- package/lib/shared/resources/CometChatLocalize/index.js.map +0 -1
- package/lib/shared/resources/CometChatLocalize/resources/ar/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/de/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/en/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/es/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/fr/translation.json +0 -446
- package/lib/shared/resources/CometChatLocalize/resources/hi/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/hu/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/lt/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/ms/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/pt/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/ru/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/sv/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/zh/translation.json +0 -447
- package/lib/shared/resources/CometChatLocalize/resources/zh-tw/translation.json +0 -446
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.d.ts +0 -29
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js +0 -29
- package/lib/shared/utils/CometChatMessagePreview/MessagePreviewStyle.js.map +0 -1
|
@@ -36,6 +36,7 @@ import {
|
|
|
36
36
|
CometChatTextFormatter,
|
|
37
37
|
CometChatUiKitConstants,
|
|
38
38
|
CometChatUrlsFormatter,
|
|
39
|
+
MessageDataSource,
|
|
39
40
|
SuggestionItem,
|
|
40
41
|
} from "../shared";
|
|
41
42
|
import {
|
|
@@ -81,6 +82,10 @@ import { ExtensionConstants } from "../extensions";
|
|
|
81
82
|
import { getExtensionData } from "../shared/helper/functions";
|
|
82
83
|
import { DeepPartial } from "../shared/helper/types";
|
|
83
84
|
import { CometChatDateSeparator } from "../shared/views/CometChatDateSeperator";
|
|
85
|
+
import { handleWebsocketMessage, messageStream, setAIAssistantTools, setStreamSpeed, startStreamingForRunId, setQueueCompletionCallback, removeQueueCompletionCallback, onConnected as streamOnConnected, onDisconnected as streamOnDisconnected, onConnectionError as streamOnConnectionError, checkAndTriggerQueueCompletion, storeAIAssistantMessage, QueueCompletionCallback } from "../shared/services/stream-message.service";
|
|
86
|
+
import { CometChatAIAssistantTools } from "../shared/modals/CometChatAIAssistantTools";
|
|
87
|
+
import { StreamMessage } from "../shared/modals";
|
|
88
|
+
import { internalMessageDataSource } from "../shared/framework/MessageDataSource";
|
|
84
89
|
import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
|
|
85
90
|
|
|
86
91
|
let _defaultRequestBuilder: CometChat.MessagesRequestBuilder;
|
|
@@ -338,6 +343,38 @@ export interface CometChatMessageListProps {
|
|
|
338
343
|
* Flag to hide the timestamp on message bubbles
|
|
339
344
|
*/
|
|
340
345
|
hideTimestamp?: boolean;
|
|
346
|
+
/**
|
|
347
|
+
* Array of suggested messages for AI agent empty view (only applies to @agentic users)
|
|
348
|
+
*/
|
|
349
|
+
suggestedMessages?: Array<string>;
|
|
350
|
+
/**
|
|
351
|
+
* Flag to hide suggested messages in AI agent empty view (only applies to @agentic users)
|
|
352
|
+
*/
|
|
353
|
+
hideSuggestedMessages?: boolean;
|
|
354
|
+
/**
|
|
355
|
+
* Custom AI agent greeting view (only applies to @agentic users)
|
|
356
|
+
*/
|
|
357
|
+
emptyChatGreetingView?: React.ReactNode;
|
|
358
|
+
/**
|
|
359
|
+
* Custom AI agent intro message view (only applies to @agentic users)
|
|
360
|
+
*/
|
|
361
|
+
emptyChatIntroMessageView?: React.ReactNode;
|
|
362
|
+
/**
|
|
363
|
+
* Custom AI agent image/avatar view (only applies to @agentic users)
|
|
364
|
+
*/
|
|
365
|
+
emptyChatImageView?: React.ReactNode;
|
|
366
|
+
/**
|
|
367
|
+
* Callback when suggested message is clicked (only applies to @agentic users)
|
|
368
|
+
*/
|
|
369
|
+
onSuggestedMessageClick?: (suggestion: string) => void;
|
|
370
|
+
/**
|
|
371
|
+
* Custom AI assistant tools with action functions (only applies to @agentic users)
|
|
372
|
+
*/
|
|
373
|
+
aiAssistantTools?: CometChatAIAssistantTools;
|
|
374
|
+
/**
|
|
375
|
+
* Controls the speed of AI message streaming (only applies to @agentic users)
|
|
376
|
+
*/
|
|
377
|
+
streamingSpeed?: number;
|
|
341
378
|
}
|
|
342
379
|
|
|
343
380
|
/**
|
|
@@ -431,19 +468,44 @@ export const CometChatMessageList = memo(
|
|
|
431
468
|
addTemplates = [],
|
|
432
469
|
onLoad,
|
|
433
470
|
onEmpty,
|
|
434
|
-
hideReplyInThreadOption = false,
|
|
435
|
-
hideShareMessageOption = false,
|
|
436
|
-
hideEditMessageOption = false,
|
|
437
|
-
hideTranslateMessageOption = false,
|
|
438
|
-
hideDeleteMessageOption = false,
|
|
439
|
-
hideReactionOption = false,
|
|
440
|
-
hideMessagePrivatelyOption = false,
|
|
441
|
-
hideCopyMessageOption = false,
|
|
442
|
-
hideMessageInfoOption = false,
|
|
443
|
-
hideGroupActionMessages = false,
|
|
471
|
+
hideReplyInThreadOption: propHideReplyInThreadOption = false,
|
|
472
|
+
hideShareMessageOption: propHideShareMessageOption = false,
|
|
473
|
+
hideEditMessageOption: propHideEditMessageOption = false,
|
|
474
|
+
hideTranslateMessageOption: propHideTranslateMessageOption = false,
|
|
475
|
+
hideDeleteMessageOption: propHideDeleteMessageOption = false,
|
|
476
|
+
hideReactionOption: propHideReactionOption = false,
|
|
477
|
+
hideMessagePrivatelyOption: propHideMessagePrivatelyOption = false,
|
|
478
|
+
hideCopyMessageOption: propHideCopyMessageOption = false,
|
|
479
|
+
hideMessageInfoOption: propHideMessageInfoOption = false,
|
|
480
|
+
hideGroupActionMessages: propHideGroupActionMessages = false,
|
|
444
481
|
hideTimestamp = false,
|
|
482
|
+
suggestedMessages = [],
|
|
483
|
+
hideSuggestedMessages = false,
|
|
484
|
+
emptyChatGreetingView,
|
|
485
|
+
emptyChatIntroMessageView,
|
|
486
|
+
emptyChatImageView,
|
|
487
|
+
onSuggestedMessageClick,
|
|
488
|
+
aiAssistantTools,
|
|
489
|
+
streamingSpeed = 30
|
|
445
490
|
} = props;
|
|
446
491
|
|
|
492
|
+
// Helper function to check if user is agentic
|
|
493
|
+
const isAgenticUser = useCallback(() => {
|
|
494
|
+
return user?.getRole?.() === '@agentic';
|
|
495
|
+
}, [user]);
|
|
496
|
+
|
|
497
|
+
// hiding props for @agentic users
|
|
498
|
+
const hideReplyInThreadOption = isAgenticUser() ? true : propHideReplyInThreadOption;
|
|
499
|
+
const hideShareMessageOption = isAgenticUser() ? true : propHideShareMessageOption;
|
|
500
|
+
const hideEditMessageOption = isAgenticUser() ? true : propHideEditMessageOption;
|
|
501
|
+
const hideTranslateMessageOption = isAgenticUser() ? true : propHideTranslateMessageOption;
|
|
502
|
+
const hideDeleteMessageOption = isAgenticUser() ? true : propHideDeleteMessageOption;
|
|
503
|
+
const hideReactionOption = isAgenticUser() ? true : propHideReactionOption;
|
|
504
|
+
const hideMessagePrivatelyOption = isAgenticUser() ? true : propHideMessagePrivatelyOption;
|
|
505
|
+
const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
|
|
506
|
+
const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
|
|
507
|
+
const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
|
|
508
|
+
|
|
447
509
|
const callListenerId = "call_" + new Date().getTime();
|
|
448
510
|
const groupListenerId = "group_" + new Date().getTime();
|
|
449
511
|
const uiEventListener = "uiEvent_" + new Date().getTime();
|
|
@@ -453,10 +515,16 @@ export const CometChatMessageList = memo(
|
|
|
453
515
|
const connectionListenerId = "connectionListener_" + new Date().getTime();
|
|
454
516
|
const messageEventListener = "messageEvent_" + new Date().getTime();
|
|
455
517
|
const groupEventListener = "groupEvent_" + new Date().getTime();
|
|
456
|
-
const
|
|
518
|
+
const streamListenerId = "agent_" + new Date().getTime();
|
|
457
519
|
const deleteItem = useRef<CometChat.BaseMessage>(undefined);
|
|
458
520
|
|
|
459
521
|
useLayoutEffect(() => {
|
|
522
|
+
// For agent chats (non-thread), don't set up message request builder
|
|
523
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
524
|
+
msgRequestBuilder.current = null as any;
|
|
525
|
+
return;
|
|
526
|
+
}
|
|
527
|
+
|
|
460
528
|
if (user) {
|
|
461
529
|
_defaultRequestBuilder = new CometChat.MessagesRequestBuilder()
|
|
462
530
|
.setLimit(30)
|
|
@@ -486,10 +554,15 @@ export const CometChatMessageList = memo(
|
|
|
486
554
|
_updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setUID(user.getUid());
|
|
487
555
|
if (group)
|
|
488
556
|
_updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setGUID(group.getGuid());
|
|
489
|
-
if (parentMessageId)
|
|
557
|
+
if (parentMessageId) {
|
|
490
558
|
_updatedCustomRequestBuilder = _updatedCustomRequestBuilder.setParentMessageId(
|
|
491
559
|
parseInt(parentMessageId)
|
|
492
560
|
);
|
|
561
|
+
if (isAgenticUser()) {
|
|
562
|
+
_updatedCustomRequestBuilder.hideReplies(false);
|
|
563
|
+
_updatedCustomRequestBuilder.withParent(true);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
493
566
|
let types: any[] = [],
|
|
494
567
|
categories: any[] = [];
|
|
495
568
|
if (templates.length) {
|
|
@@ -512,7 +585,7 @@ export const CometChatMessageList = memo(
|
|
|
512
585
|
}
|
|
513
586
|
|
|
514
587
|
msgRequestBuilder.current = _updatedCustomRequestBuilder;
|
|
515
|
-
}, [hideGroupActionMessages]);
|
|
588
|
+
}, [hideGroupActionMessages, isAgenticUser, parentMessageId]);
|
|
516
589
|
|
|
517
590
|
const theme = useTheme();
|
|
518
591
|
const { t } = useCometChatTranslation();
|
|
@@ -625,6 +698,22 @@ export const CometChatMessageList = memo(
|
|
|
625
698
|
),
|
|
626
699
|
});
|
|
627
700
|
|
|
701
|
+
styleCache.set(MessageTypeConstants.assistant, {
|
|
702
|
+
incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
|
|
703
|
+
});
|
|
704
|
+
|
|
705
|
+
styleCache.set(CometChatUiKitConstants.streamMessageTypes.run_started, {
|
|
706
|
+
incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
|
|
707
|
+
});
|
|
708
|
+
|
|
709
|
+
styleCache.set(CometChatUiKitConstants.streamMessageTypes.run_finished, {
|
|
710
|
+
incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
|
|
711
|
+
});
|
|
712
|
+
|
|
713
|
+
styleCache.set(CometChatUiKitConstants.streamMessageTypes.text_message_content, {
|
|
714
|
+
incoming: deepMerge(incomingBubbleStyles, incomingBubbleStyles.assistantBubbleStyles ?? {}),
|
|
715
|
+
});
|
|
716
|
+
|
|
628
717
|
return styleCache;
|
|
629
718
|
}, [mergedTheme]);
|
|
630
719
|
|
|
@@ -648,7 +737,9 @@ export const CometChatMessageList = memo(
|
|
|
648
737
|
|
|
649
738
|
// states
|
|
650
739
|
const [messagesList, setMessagesList] = useState<any[]>([]);
|
|
651
|
-
const [listState, setListState] = useState(
|
|
740
|
+
const [listState, setListState] = useState(
|
|
741
|
+
isAgenticUser() && !parentMessageId ? "loaded" : "loading"
|
|
742
|
+
);
|
|
652
743
|
const [loadingMessages, setLoadingMessages] = useState(false);
|
|
653
744
|
/** this is required to prevent duplicate api calls. Cannot use state for this since this is being used in scrollHandler **/
|
|
654
745
|
const loadingMessagesRef = useRef(false);
|
|
@@ -663,13 +754,15 @@ export const CometChatMessageList = memo(
|
|
|
663
754
|
const [showReactionList, setShowReactionList] = useState(false);
|
|
664
755
|
const [selectedEmoji, setSelectedEmoji] = useState<string | undefined>(undefined);
|
|
665
756
|
const [hideScrollToBottomButton, setHideScrollToBottomButton] = useState<boolean>(true);
|
|
757
|
+
const [showDeleteModal, setShowDeleteModal] = useState(false);
|
|
666
758
|
|
|
667
759
|
const infoObject = useRef<CometChat.BaseMessage | null>(undefined);
|
|
668
760
|
const bottomSheetRef = useRef<any>(null);
|
|
669
|
-
const conversationId = useRef(null);
|
|
761
|
+
const conversationId = useRef<string | null>(null);
|
|
762
|
+
const streamSubscriptionRef = useRef<any>(null);
|
|
670
763
|
let lastID = useRef(0);
|
|
671
764
|
let reachedFirstMessage = useRef<boolean>(false);
|
|
672
|
-
|
|
765
|
+
const agenticParentMessageIdRef = useRef<string | undefined>(undefined);
|
|
673
766
|
const markUnreadMessageAsRead = () => {
|
|
674
767
|
CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
|
|
675
768
|
message: messagesContentListRef.current[0],
|
|
@@ -691,6 +784,11 @@ export const CometChatMessageList = memo(
|
|
|
691
784
|
}, [onLoad]);
|
|
692
785
|
|
|
693
786
|
const getPreviousMessages = async () => {
|
|
787
|
+
// For agent chats (non-thread), don't fetch previous messages
|
|
788
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
789
|
+
return;
|
|
790
|
+
}
|
|
791
|
+
|
|
694
792
|
if (reachedFirstMessage.current) {
|
|
695
793
|
return;
|
|
696
794
|
}
|
|
@@ -785,6 +883,11 @@ export const CometChatMessageList = memo(
|
|
|
785
883
|
};
|
|
786
884
|
|
|
787
885
|
const getUpdatedPreviousMessages = () => {
|
|
886
|
+
// For agent chats (non-thread), don't fetch updated previous messages
|
|
887
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
888
|
+
return;
|
|
889
|
+
}
|
|
890
|
+
|
|
788
891
|
let messagesRequest = new CometChat.MessagesRequestBuilder().setLimit(50);
|
|
789
892
|
if (user) messagesRequest = messagesRequest.setUID(user.getUid());
|
|
790
893
|
if (group) messagesRequest = messagesRequest.setGUID(group.getGuid());
|
|
@@ -869,26 +972,37 @@ export const CometChatMessageList = memo(
|
|
|
869
972
|
};
|
|
870
973
|
|
|
871
974
|
const templatesMap = useMemo(() => {
|
|
975
|
+
const isAgenticUserCheck = isAgenticUser();
|
|
976
|
+
const options = {
|
|
977
|
+
textFormatters: textFormatters || [],
|
|
978
|
+
hideReplyInThreadOption: isAgenticUserCheck || hideReplyInThreadOption,
|
|
979
|
+
hideShareMessageOption: isAgenticUserCheck || hideShareMessageOption,
|
|
980
|
+
hideEditMessageOption: isAgenticUserCheck || hideEditMessageOption,
|
|
981
|
+
hideTranslateMessageOption: isAgenticUserCheck || hideTranslateMessageOption,
|
|
982
|
+
hideDeleteMessageOption: isAgenticUserCheck || hideDeleteMessageOption,
|
|
983
|
+
hideReactionOption: isAgenticUserCheck || hideReactionOption,
|
|
984
|
+
hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
|
|
985
|
+
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
986
|
+
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
|
|
987
|
+
hideGroupActionMessages,
|
|
988
|
+
};
|
|
872
989
|
let _formatters = textFormatters || [];
|
|
873
990
|
let tempTemplates: CometChatMessageTemplate[] =
|
|
874
991
|
templates && templates.length
|
|
875
992
|
? templates
|
|
876
993
|
: [
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
880
|
-
|
|
881
|
-
|
|
882
|
-
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
}),
|
|
890
|
-
...addTemplates,
|
|
891
|
-
];
|
|
994
|
+
...ChatConfigurator.dataSource.getAllMessageTemplates(mergedTheme, options),
|
|
995
|
+
...addTemplates,
|
|
996
|
+
];
|
|
997
|
+
//for internal use only
|
|
998
|
+
const streamTemplate = internalMessageDataSource.getStreamMessageTemplate(mergedTheme, options);
|
|
999
|
+
|
|
1000
|
+
if (isAgenticUserCheck) {
|
|
1001
|
+
tempTemplates.push(
|
|
1002
|
+
streamTemplate
|
|
1003
|
+
);
|
|
1004
|
+
}
|
|
1005
|
+
|
|
892
1006
|
let templatesMapTemp = new Map<string, CometChatMessageTemplate>();
|
|
893
1007
|
|
|
894
1008
|
tempTemplates.forEach((template) => {
|
|
@@ -902,6 +1016,7 @@ export const CometChatMessageList = memo(
|
|
|
902
1016
|
mergedTheme,
|
|
903
1017
|
templates,
|
|
904
1018
|
addTemplates,
|
|
1019
|
+
isAgenticUser,
|
|
905
1020
|
hideReplyInThreadOption,
|
|
906
1021
|
hideShareMessageOption,
|
|
907
1022
|
hideEditMessageOption,
|
|
@@ -1045,11 +1160,36 @@ export const CometChatMessageList = memo(
|
|
|
1045
1160
|
false
|
|
1046
1161
|
);
|
|
1047
1162
|
}
|
|
1163
|
+
useEffect(() => {
|
|
1164
|
+
if (isAgenticUser() && parentMessageId && !conversationId.current) {
|
|
1165
|
+
conversationId.current = parentMessageId;
|
|
1166
|
+
}
|
|
1167
|
+
}, [parentMessageId, isAgenticUser]);
|
|
1168
|
+
|
|
1048
1169
|
function checkSameConversation(message: CometChat.BaseMessage): boolean {
|
|
1170
|
+
if ((message as any).isStreamMessage) {
|
|
1171
|
+
if (isAgenticUser()) {
|
|
1172
|
+
return (message as any).targetMessageId === agenticParentMessageIdRef.current;
|
|
1173
|
+
}
|
|
1174
|
+
return true;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
if (isAgenticUser()) {
|
|
1178
|
+
if (parentMessageId && agenticParentMessageIdRef.current) {
|
|
1179
|
+
return (
|
|
1180
|
+
message.getParentMessageId &&
|
|
1181
|
+
String(message.getParentMessageId()) === String(agenticParentMessageIdRef.current)
|
|
1182
|
+
);
|
|
1183
|
+
}
|
|
1184
|
+
return false;
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1049
1187
|
return (
|
|
1050
1188
|
message.getConversationId() == conversationId.current ||
|
|
1051
1189
|
(message.getSender()?.getUid() === user?.getUid() &&
|
|
1052
|
-
message.getReceiverType() == CometChatUiKitConstants.ReceiverTypeConstants.user)
|
|
1190
|
+
message.getReceiverType() == CometChatUiKitConstants.ReceiverTypeConstants.user) ||
|
|
1191
|
+
checkMessageInSameConversation(message) ||
|
|
1192
|
+
messageToSameConversation(message)
|
|
1053
1193
|
);
|
|
1054
1194
|
}
|
|
1055
1195
|
|
|
@@ -1080,26 +1220,41 @@ export const CometChatMessageList = memo(
|
|
|
1080
1220
|
if (baseMessage.getCategory() === MessageCategoryConstants.interactive) {
|
|
1081
1221
|
//todo show unsupported bubble
|
|
1082
1222
|
}
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1087
|
-
|
|
1088
|
-
|
|
1089
|
-
|
|
1090
|
-
|
|
1091
|
-
|
|
1092
|
-
let index = messagesList.findIndex((msg) => msg.id === newMessage.parentMessageId);
|
|
1093
|
-
let oldMsg: CometChat.BaseMessage = CommonUtils.clone(messagesList[index]);
|
|
1094
|
-
oldMsg.setReplyCount(oldMsg.getReplyCount() ? oldMsg.getReplyCount() + 1 : 1);
|
|
1095
|
-
let tmpList = [...messagesList];
|
|
1096
|
-
tmpList[index] = oldMsg;
|
|
1097
|
-
messagesContentListRef.current = tmpList;
|
|
1098
|
-
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1099
|
-
setMessagesList(tmpList);
|
|
1223
|
+
|
|
1224
|
+
if (isAgenticUser()) {
|
|
1225
|
+
if (
|
|
1226
|
+
String(baseMessage.getParentMessageId()) === String(parentMessageId) ||
|
|
1227
|
+
String(baseMessage.getId()) === String(parentMessageId)
|
|
1228
|
+
) {
|
|
1229
|
+
CometChat.markAsDelivered(newMessage);
|
|
1230
|
+
bottomHandler(newMessage, isReceived);
|
|
1231
|
+
} else {
|
|
1100
1232
|
return;
|
|
1101
1233
|
}
|
|
1102
|
-
|
|
1234
|
+
} else {
|
|
1235
|
+
if (
|
|
1236
|
+
checkSameConversation(baseMessage) ||
|
|
1237
|
+
checkMessageInSameConversation(baseMessage) ||
|
|
1238
|
+
messageToSameConversation(baseMessage)
|
|
1239
|
+
) {
|
|
1240
|
+
CometChat.markAsDelivered(newMessage);
|
|
1241
|
+
if (!parentMessageId && newMessage.getParentMessageId()) {
|
|
1242
|
+
const parentId = String(newMessage.getParentMessageId ? newMessage.getParentMessageId() : newMessage.parentMessageId);
|
|
1243
|
+
let index = messagesContentListRef.current.findIndex((msg) => String(msg.getId ? msg.getId() : msg.id) === parentId);
|
|
1244
|
+
if (index !== -1 && messagesContentListRef.current[index]) {
|
|
1245
|
+
let oldMsg: CometChat.BaseMessage = CommonUtils.clone(messagesContentListRef.current[index]);
|
|
1246
|
+
oldMsg.setReplyCount(oldMsg.getReplyCount() ? oldMsg.getReplyCount() + 1 : 1);
|
|
1247
|
+
let tmpList = [...messagesContentListRef.current];
|
|
1248
|
+
tmpList[index] = oldMsg;
|
|
1249
|
+
messagesContentListRef.current = tmpList;
|
|
1250
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1251
|
+
setMessagesList(tmpList);
|
|
1252
|
+
}
|
|
1253
|
+
return;
|
|
1254
|
+
}
|
|
1255
|
+
|
|
1256
|
+
bottomHandler(newMessage, isReceived);
|
|
1257
|
+
}
|
|
1103
1258
|
}
|
|
1104
1259
|
|
|
1105
1260
|
playNotificationSound(newMessage);
|
|
@@ -1118,6 +1273,15 @@ export const CometChatMessageList = memo(
|
|
|
1118
1273
|
isReceived = false,
|
|
1119
1274
|
skipAddToList = false
|
|
1120
1275
|
) => {
|
|
1276
|
+
|
|
1277
|
+
if (newMessage?.isStreamMessage) {
|
|
1278
|
+
if (!skipAddToList) {
|
|
1279
|
+
addToMessageList(newMessage);
|
|
1280
|
+
}
|
|
1281
|
+
scrollToBottom();
|
|
1282
|
+
return;
|
|
1283
|
+
}
|
|
1284
|
+
|
|
1121
1285
|
if (
|
|
1122
1286
|
(newMessage.getSender()?.getUid() || newMessage?.["sender"]?.["uid"]) ==
|
|
1123
1287
|
loggedInUser.current?.["uid"]
|
|
@@ -1153,6 +1317,39 @@ export const CometChatMessageList = memo(
|
|
|
1153
1317
|
};
|
|
1154
1318
|
|
|
1155
1319
|
const addToMessageList = (newMessage: CometChat.BaseMessage) => {
|
|
1320
|
+
if (isAgenticUser() && !conversationId.current) {
|
|
1321
|
+
if (newMessage.getConversationId()) {
|
|
1322
|
+
conversationId.current = newMessage.getConversationId();
|
|
1323
|
+
} else if (!parentMessageId) {
|
|
1324
|
+
const msgId = newMessage.getId();
|
|
1325
|
+
if (msgId) {
|
|
1326
|
+
conversationId.current = `${loggedInUser.current?.getUid()}_${user?.getUid()}_${msgId}`;
|
|
1327
|
+
}
|
|
1328
|
+
}
|
|
1329
|
+
} else if (!conversationId.current && newMessage.getConversationId()) {
|
|
1330
|
+
conversationId.current = newMessage.getConversationId();
|
|
1331
|
+
}
|
|
1332
|
+
|
|
1333
|
+
const isStreamMessage = (newMessage as any).isStreamMessage;
|
|
1334
|
+
const targetMessageId = (newMessage as any).targetMessageId;
|
|
1335
|
+
if (isStreamMessage && targetMessageId) {
|
|
1336
|
+
const targetId = String(targetMessageId);
|
|
1337
|
+
let userMsgIdx = messagesContentListRef.current.findIndex(
|
|
1338
|
+
(msg) => String(msg.getId()) === targetId
|
|
1339
|
+
);
|
|
1340
|
+
let updatedList;
|
|
1341
|
+
if (userMsgIdx !== -1) {
|
|
1342
|
+
updatedList = [...messagesContentListRef.current].filter(
|
|
1343
|
+
(msg, idx) =>
|
|
1344
|
+
!(idx === userMsgIdx - 1 && (msg as any).isStreamMessage && (msg as any).targetMessageId === targetId)
|
|
1345
|
+
);
|
|
1346
|
+
updatedList.splice(userMsgIdx, 0, newMessage);
|
|
1347
|
+
messagesContentListRef.current = updatedList;
|
|
1348
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1349
|
+
setMessagesList(updatedList);
|
|
1350
|
+
return;
|
|
1351
|
+
}
|
|
1352
|
+
}
|
|
1156
1353
|
messagesContentListRef.current = [newMessage, ...messagesContentListRef.current];
|
|
1157
1354
|
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1158
1355
|
setMessagesList((prev) => [newMessage, ...prev]);
|
|
@@ -1295,8 +1492,14 @@ export const CometChatMessageList = memo(
|
|
|
1295
1492
|
CometChat.getLoggedinUser()
|
|
1296
1493
|
.then((u: any) => {
|
|
1297
1494
|
loggedInUser.current = u;
|
|
1298
|
-
|
|
1299
|
-
|
|
1495
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
1496
|
+
messageRequest.current = null;
|
|
1497
|
+
} else {
|
|
1498
|
+
messageRequest.current = msgRequestBuilder.current?.build() || null;
|
|
1499
|
+
}
|
|
1500
|
+
if (!isAgenticUser() || (isAgenticUser() && parentMessageId)) {
|
|
1501
|
+
getPreviousMessages();
|
|
1502
|
+
}
|
|
1300
1503
|
})
|
|
1301
1504
|
.catch((e: any) => {
|
|
1302
1505
|
console.log("Error while getting loggedInUser");
|
|
@@ -1312,9 +1515,95 @@ export const CometChatMessageList = memo(
|
|
|
1312
1515
|
};
|
|
1313
1516
|
}, []);
|
|
1314
1517
|
|
|
1518
|
+
// Callback to add stream message and register queue completion callback
|
|
1519
|
+
const createStreamMessage = useCallback((userMessage: CometChat.BaseMessage) => {
|
|
1520
|
+
const runId = String(userMessage.getId());
|
|
1521
|
+
const streamMessage = new StreamMessage(
|
|
1522
|
+
user?.getUid() || group?.getGuid() || '',
|
|
1523
|
+
user ? CometChat.RECEIVER_TYPE.USER : CometChat.RECEIVER_TYPE.GROUP,
|
|
1524
|
+
CometChatUiKitConstants.streamMessageTypes.run_started,
|
|
1525
|
+
CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
1526
|
+
);
|
|
1527
|
+
streamMessage.setId(Number(userMessage.getId()));
|
|
1528
|
+
if (user) {
|
|
1529
|
+
streamMessage.setSender(user);
|
|
1530
|
+
}
|
|
1531
|
+
streamMessage.setReceiver(loggedInUser.current);
|
|
1532
|
+
streamMessage.setReceiverType(CometChat.RECEIVER_TYPE.USER);
|
|
1533
|
+
streamMessage.setSentAt(Math.floor(Date.now() / 1000));
|
|
1534
|
+
(streamMessage as any).targetMessageId = runId;
|
|
1535
|
+
(streamMessage as any).isStreamMessage = true;
|
|
1536
|
+
return streamMessage;
|
|
1537
|
+
}, [user, group, addToMessageList, setMessagesList, onLoad]);
|
|
1538
|
+
|
|
1539
|
+
const updateStreamMessageWithActualId = useCallback((actualMessageId: string, runId: string) => {
|
|
1540
|
+
const updatedList = messagesContentListRef.current.map(msg => {
|
|
1541
|
+
if ((msg as any).isStreamMessage === true &&
|
|
1542
|
+
(msg as any).targetMessageId === runId) {
|
|
1543
|
+
const updatedStreamMessage = { ...msg };
|
|
1544
|
+
msg.setId(actualMessageId);
|
|
1545
|
+
msg.targetMessageId = String(actualMessageId);
|
|
1546
|
+
return msg;
|
|
1547
|
+
}
|
|
1548
|
+
return msg;
|
|
1549
|
+
});
|
|
1550
|
+
|
|
1551
|
+
messagesContentListRef.current = updatedList;
|
|
1552
|
+
onLoad && onLoad([...messagesContentListRef.current].reverse());
|
|
1553
|
+
setMessagesList(updatedList);
|
|
1554
|
+
}, [onLoad]);
|
|
1555
|
+
|
|
1556
|
+
useEffect(() => {
|
|
1557
|
+
if (isAgenticUser()) {
|
|
1558
|
+
agenticParentMessageIdRef.current = undefined;
|
|
1559
|
+
}
|
|
1560
|
+
}, [user?.getUid(), group?.getGuid(), isAgenticUser]);
|
|
1561
|
+
|
|
1315
1562
|
useEffect(() => {
|
|
1316
1563
|
//add listeners
|
|
1317
1564
|
|
|
1565
|
+
// AI Assistant listener for agent chats
|
|
1566
|
+
if (isAgenticUser() && user && (!parentMessageId || (parentMessageId && isAgenticUser()))) {
|
|
1567
|
+
CometChat.addAIAssistantListener(streamListenerId, {
|
|
1568
|
+
onAIAssistantEventReceived: (message: CometChat.AIAssistantBaseEvent) => {
|
|
1569
|
+
if (
|
|
1570
|
+
message.getConversationId &&
|
|
1571
|
+
(!message.getConversationId()?.includes(user.getUid()) ||
|
|
1572
|
+
!message.getConversationId()?.includes(loggedInUser.current?.getUid()))
|
|
1573
|
+
) {
|
|
1574
|
+
return;
|
|
1575
|
+
}
|
|
1576
|
+
|
|
1577
|
+
|
|
1578
|
+
if (message.getType() === CometChatUiKitConstants.streamMessageTypes.run_started) {
|
|
1579
|
+
const lastMessage = messagesContentListRef.current[0];
|
|
1580
|
+
updateStreamMessageWithActualId(message.getMessageId(), message.getRunId());
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
if (message.getType() === CometChatUiKitConstants.streamMessageTypes.run_finished) {
|
|
1584
|
+
const runId = String(message.getRunId?.() || message.getMessageId?.());
|
|
1585
|
+
|
|
1586
|
+
setQueueCompletionCallback(runId, (aiAssistantMessage, aiToolResultMessage, aiToolArgumentMessage) => {
|
|
1587
|
+
let replacement = aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1588
|
+
if (!replacement) return;
|
|
1589
|
+
const updatedList = messagesContentListRef.current.map(msg => {
|
|
1590
|
+
if ((msg as any).isStreamMessage === true && (msg as any).targetMessageId === runId) {
|
|
1591
|
+
return replacement;
|
|
1592
|
+
}
|
|
1593
|
+
return msg;
|
|
1594
|
+
});
|
|
1595
|
+
messagesContentListRef.current = updatedList;
|
|
1596
|
+
setMessagesList(updatedList);
|
|
1597
|
+
onLoad && onLoad([...updatedList].reverse());
|
|
1598
|
+
});
|
|
1599
|
+
checkAndTriggerQueueCompletion(runId);
|
|
1600
|
+
}
|
|
1601
|
+
|
|
1602
|
+
handleWebsocketMessage(message);
|
|
1603
|
+
},
|
|
1604
|
+
});
|
|
1605
|
+
}
|
|
1606
|
+
|
|
1318
1607
|
let reactionListeners = {
|
|
1319
1608
|
onMessageReactionAdded: (reaction: CometChat.ReactionEvent) => {
|
|
1320
1609
|
updateMessageReaction(reaction, true);
|
|
@@ -1359,6 +1648,15 @@ export const CometChatMessageList = memo(
|
|
|
1359
1648
|
|
|
1360
1649
|
if (status == MessageStatusConstants.success) {
|
|
1361
1650
|
messageEdited(message, true);
|
|
1651
|
+
if (isAgenticUser() &&
|
|
1652
|
+
agenticParentMessageIdRef.current === undefined &&
|
|
1653
|
+
messagesList.length !== 0 && message.getType() === MessageTypeConstants.text && message.getCategory() === MessageCategoryConstants.message) {
|
|
1654
|
+
agenticParentMessageIdRef.current = String(message.getId());
|
|
1655
|
+
}
|
|
1656
|
+
if (isAgenticUser() && agenticParentMessageIdRef.current !== undefined) {
|
|
1657
|
+
const streamMessage = createStreamMessage(message);
|
|
1658
|
+
addToMessageList(streamMessage);
|
|
1659
|
+
}
|
|
1362
1660
|
}
|
|
1363
1661
|
if (status == MessageStatusConstants.error) {
|
|
1364
1662
|
messageEdited(message, true);
|
|
@@ -1378,13 +1676,43 @@ export const CometChatMessageList = memo(
|
|
|
1378
1676
|
}
|
|
1379
1677
|
},
|
|
1380
1678
|
onTextMessageReceived: (textMessage: any) => {
|
|
1381
|
-
|
|
1679
|
+
if (isAgenticUser()) {
|
|
1680
|
+
if (
|
|
1681
|
+
textMessage.getSender?.()?.getRole?.() === '@agentic' ||
|
|
1682
|
+
textMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
1683
|
+
textMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
1684
|
+
) {
|
|
1685
|
+
newMessage(textMessage);
|
|
1686
|
+
}
|
|
1687
|
+
} else {
|
|
1688
|
+
newMessage(textMessage);
|
|
1689
|
+
}
|
|
1382
1690
|
},
|
|
1383
1691
|
onMediaMessageReceived: (mediaMessage: any) => {
|
|
1384
|
-
|
|
1692
|
+
if (isAgenticUser()) {
|
|
1693
|
+
if (
|
|
1694
|
+
mediaMessage.getSender?.()?.getRole?.() === '@agentic' ||
|
|
1695
|
+
mediaMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
1696
|
+
mediaMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
1697
|
+
) {
|
|
1698
|
+
newMessage(mediaMessage);
|
|
1699
|
+
}
|
|
1700
|
+
} else {
|
|
1701
|
+
newMessage(mediaMessage);
|
|
1702
|
+
}
|
|
1385
1703
|
},
|
|
1386
1704
|
onCustomMessageReceived: (customMessage: any) => {
|
|
1387
|
-
|
|
1705
|
+
if (isAgenticUser()) {
|
|
1706
|
+
if (
|
|
1707
|
+
customMessage.getSender?.()?.getRole?.() === '@agentic' ||
|
|
1708
|
+
customMessage.getCategory?.() === MessageCategoryConstants.agentic ||
|
|
1709
|
+
customMessage.getCategory?.() === CometChatUiKitConstants.MessageCategoryConstants.stream
|
|
1710
|
+
) {
|
|
1711
|
+
newMessage(customMessage);
|
|
1712
|
+
}
|
|
1713
|
+
} else {
|
|
1714
|
+
newMessage(customMessage);
|
|
1715
|
+
}
|
|
1388
1716
|
},
|
|
1389
1717
|
onMessagesDelivered: (messageReceipt: any) => {
|
|
1390
1718
|
updateMessageReceipt(messageReceipt);
|
|
@@ -1413,6 +1741,16 @@ export const CometChatMessageList = memo(
|
|
|
1413
1741
|
onInteractionGoalCompleted: (interactionReceipt: CometChat.InteractionReceipt) => {
|
|
1414
1742
|
//todo show unsupported bubble
|
|
1415
1743
|
},
|
|
1744
|
+
onAIAssistantMessageReceived: (aiAssistantMessage: CometChat.AIAssistantMessage) => {
|
|
1745
|
+
const runId = aiAssistantMessage.getAssistantMessageData?.()?.getRunId?.() || aiAssistantMessage.getId?.();
|
|
1746
|
+
|
|
1747
|
+
if (parentMessageId && String(parentMessageId) !== String(aiAssistantMessage.getParentMessageId?.())) {
|
|
1748
|
+
return;
|
|
1749
|
+
}
|
|
1750
|
+
if (runId) {
|
|
1751
|
+
storeAIAssistantMessage(String(runId), aiAssistantMessage);
|
|
1752
|
+
}
|
|
1753
|
+
},
|
|
1416
1754
|
...reactionListeners,
|
|
1417
1755
|
onMessagesDeliveredToAll: (messageReceipt: CometChat.MessageReceipt) => {
|
|
1418
1756
|
updateMessageReceipt(messageReceipt);
|
|
@@ -1531,6 +1869,7 @@ export const CometChatMessageList = memo(
|
|
|
1531
1869
|
new CometChat.ConnectionListener({
|
|
1532
1870
|
onConnected: () => {
|
|
1533
1871
|
console.log("CONNECTED...");
|
|
1872
|
+
streamOnConnected();
|
|
1534
1873
|
if (lastID.current) {
|
|
1535
1874
|
getUpdatedPreviousMessages();
|
|
1536
1875
|
}
|
|
@@ -1538,6 +1877,7 @@ export const CometChatMessageList = memo(
|
|
|
1538
1877
|
inConnecting: () => {},
|
|
1539
1878
|
onDisconnected: () => {
|
|
1540
1879
|
console.log("DISCONNECTED...");
|
|
1880
|
+
streamOnDisconnected();
|
|
1541
1881
|
if (!messagesList[0].id) {
|
|
1542
1882
|
for (let i = 0; i < messagesList.length; i++) {
|
|
1543
1883
|
if (messagesList[i].id) {
|
|
@@ -1561,8 +1901,26 @@ export const CometChatMessageList = memo(
|
|
|
1561
1901
|
CometChat.removeGroupListener(groupListenerId);
|
|
1562
1902
|
CometChat.removeCallListener(callListenerId);
|
|
1563
1903
|
CometChat.removeConnectionListener(connectionListenerId);
|
|
1904
|
+
if (isAgenticUser()) {
|
|
1905
|
+
CometChat.removeAIAssistantListener(streamListenerId);
|
|
1906
|
+
if (streamSubscriptionRef.current) {
|
|
1907
|
+
streamSubscriptionRef.current.unsubscribe();
|
|
1908
|
+
}
|
|
1909
|
+
}
|
|
1564
1910
|
};
|
|
1565
|
-
}, [
|
|
1911
|
+
}, [unreadCount, user, group, isAgenticUser, messagesList]);
|
|
1912
|
+
|
|
1913
|
+
useEffect(() => {
|
|
1914
|
+
if (aiAssistantTools) {
|
|
1915
|
+
setAIAssistantTools(aiAssistantTools)
|
|
1916
|
+
}
|
|
1917
|
+
}, [aiAssistantTools])
|
|
1918
|
+
|
|
1919
|
+
// Initialize streaming configuration and subscribe to streaming state
|
|
1920
|
+
useEffect(() => {
|
|
1921
|
+
setStreamSpeed(streamingSpeed);
|
|
1922
|
+
return () => streamSubscriptionRef.current?.unsubscribe();
|
|
1923
|
+
}, [streamingSpeed]);
|
|
1566
1924
|
|
|
1567
1925
|
useEffect(() => {
|
|
1568
1926
|
prevMessagesLength.current =
|
|
@@ -1685,14 +2043,17 @@ export const CometChatMessageList = memo(
|
|
|
1685
2043
|
const getLeadingView = useCallback((item: CometChat.BaseMessage): JSX.Element | undefined => {
|
|
1686
2044
|
let _style = getCurrentBubbleStyle(item);
|
|
1687
2045
|
|
|
1688
|
-
if (
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
)
|
|
1695
|
-
|
|
2046
|
+
if ([MessageCategoryConstants.action, MessageCategoryConstants.call].includes(item.getCategory())) {
|
|
2047
|
+
return undefined;
|
|
2048
|
+
}
|
|
2049
|
+
const isIncomingMessage = item.getSender()?.getUid() !== loggedInUser.current?.getUid();
|
|
2050
|
+
const shouldShowAvatar = avatarVisibility && (
|
|
2051
|
+
alignment === "leftAligned" ||
|
|
2052
|
+
(isIncomingMessage && !user) ||
|
|
2053
|
+
(isAgenticUser() && isIncomingMessage)
|
|
2054
|
+
);
|
|
2055
|
+
|
|
2056
|
+
if (shouldShowAvatar) {
|
|
1696
2057
|
return (
|
|
1697
2058
|
<CometChatAvatar
|
|
1698
2059
|
image={
|
|
@@ -1782,6 +2143,9 @@ export const CometChatMessageList = memo(
|
|
|
1782
2143
|
item.getEditedAt?.() &&
|
|
1783
2144
|
(item as CometChat.BaseMessage).getType() === MessageTypeConstants.text;
|
|
1784
2145
|
|
|
2146
|
+
const shouldShowTimestamp = isAgenticUser()
|
|
2147
|
+
? isOutgoingMessage
|
|
2148
|
+
: !hideTimestamp;
|
|
1785
2149
|
return (
|
|
1786
2150
|
<View>
|
|
1787
2151
|
<View
|
|
@@ -1807,7 +2171,7 @@ export const CometChatMessageList = memo(
|
|
|
1807
2171
|
{t("EDITED")}
|
|
1808
2172
|
</Text>
|
|
1809
2173
|
)}
|
|
1810
|
-
{
|
|
2174
|
+
{shouldShowTimestamp && (
|
|
1811
2175
|
<CometChatDate
|
|
1812
2176
|
timeStamp={
|
|
1813
2177
|
!hideTimestamp
|
|
@@ -1819,7 +2183,7 @@ export const CometChatMessageList = memo(
|
|
|
1819
2183
|
customDateString={datePattern && datePattern(item)}
|
|
1820
2184
|
style={_style.dateStyles}
|
|
1821
2185
|
/>
|
|
1822
|
-
}
|
|
2186
|
+
)}
|
|
1823
2187
|
{receiptsVisibility && alignment !== "leftAligned" && isOutgoingMessage ? (
|
|
1824
2188
|
<View style={{ marginLeft: 2, alignItems: "center", justifyContent: "center" }}>
|
|
1825
2189
|
<CometChatReceipt
|
|
@@ -1843,7 +2207,7 @@ export const CometChatMessageList = memo(
|
|
|
1843
2207
|
</View>
|
|
1844
2208
|
);
|
|
1845
2209
|
},
|
|
1846
|
-
[mergedTheme]
|
|
2210
|
+
[mergedTheme, isAgenticUser, hideTimestamp]
|
|
1847
2211
|
);
|
|
1848
2212
|
|
|
1849
2213
|
const onReactionPress = useCallback(
|
|
@@ -2127,6 +2491,7 @@ export const CometChatMessageList = memo(
|
|
|
2127
2491
|
}, [hasTemplate, isThreaded, getFooterView, message, bubbleAlignment]);
|
|
2128
2492
|
|
|
2129
2493
|
const ThreadedView = useMemo(() => {
|
|
2494
|
+
if (isAgenticUser()) return undefined;
|
|
2130
2495
|
return !isThreaded
|
|
2131
2496
|
? !message.getDeletedBy()
|
|
2132
2497
|
? getThreadView(message, bubbleAlignment)
|
|
@@ -2157,8 +2522,7 @@ export const CometChatMessageList = memo(
|
|
|
2157
2522
|
|
|
2158
2523
|
const onLongPress = useCallback(() => {
|
|
2159
2524
|
if (message.getDeletedBy() != null) return;
|
|
2160
|
-
|
|
2161
|
-
|
|
2525
|
+
|
|
2162
2526
|
if (!message.getId()) {
|
|
2163
2527
|
return;
|
|
2164
2528
|
}
|
|
@@ -2293,58 +2657,277 @@ export const CometChatMessageList = memo(
|
|
|
2293
2657
|
setShowMessageOptions([]);
|
|
2294
2658
|
};
|
|
2295
2659
|
|
|
2296
|
-
const
|
|
2297
|
-
(
|
|
2298
|
-
|
|
2299
|
-
|
|
2300
|
-
|
|
2301
|
-
)
|
|
2302
|
-
|
|
2303
|
-
|
|
2304
|
-
|
|
2305
|
-
|
|
2306
|
-
|
|
2307
|
-
: null;
|
|
2308
|
-
const currentMessageDate = new Date(getSentAtTimestamp(item));
|
|
2309
|
-
const currentDate = isNaN(currentMessageDate.getDate())
|
|
2310
|
-
? undefined
|
|
2311
|
-
: `${currentMessageDate.getDate()}-${currentMessageDate.getMonth()}-${currentMessageDate.getFullYear()}`;
|
|
2312
|
-
|
|
2313
|
-
const previousDate = `${previousMessageDate?.getDate()}-${previousMessageDate?.getMonth()}-${previousMessageDate?.getFullYear()}`;
|
|
2314
|
-
if (currentDate !== undefined && previousDate !== currentDate) {
|
|
2315
|
-
return (
|
|
2316
|
-
<View style={{ marginBottom: 10 }}>
|
|
2317
|
-
<CometChatDateSeparator
|
|
2318
|
-
timeStamp={getSentAtTimestamp(item)}
|
|
2319
|
-
pattern={"dayDateFormat"}
|
|
2320
|
-
customDateString={
|
|
2321
|
-
dateSeparatorPattern ? dateSeparatorPattern(item.getSentAt()) : undefined
|
|
2322
|
-
}
|
|
2323
|
-
style={theme.messageListStyles.dateSeparatorStyle}
|
|
2324
|
-
/>
|
|
2325
|
-
</View>
|
|
2326
|
-
);
|
|
2327
|
-
}
|
|
2328
|
-
return null;
|
|
2329
|
-
}, [item, dateSeparatorPattern, theme]);
|
|
2660
|
+
const sentAtToMs = (msg?: any): number | undefined => {
|
|
2661
|
+
if (!msg) return undefined;
|
|
2662
|
+
// try CometChat getter first
|
|
2663
|
+
const raw =
|
|
2664
|
+
typeof msg.getSentAt === "function"
|
|
2665
|
+
? msg.getSentAt()
|
|
2666
|
+
: (msg?.sentAt ?? msg?.sent_at ?? msg?.sentOn ?? msg?.senton);
|
|
2667
|
+
if (raw === undefined || raw === null) return undefined;
|
|
2668
|
+
// if raw looks like seconds (10 digits) convert to ms
|
|
2669
|
+
return raw < 1e12 ? raw * 1000 : raw;
|
|
2670
|
+
};
|
|
2330
2671
|
|
|
2672
|
+
const makeDayKey = (ms?: number | undefined) => {
|
|
2673
|
+
if (!ms) return null;
|
|
2674
|
+
const d = new Date(ms);
|
|
2675
|
+
// use local date parts so "Today" follows user's timezone
|
|
2676
|
+
return `${d.getFullYear()}-${d.getMonth() + 1}-${d.getDate()}`;
|
|
2677
|
+
};
|
|
2678
|
+
|
|
2679
|
+
const messageDayKeys = useMemo(() => {
|
|
2680
|
+
return messagesList.map((m) => {
|
|
2681
|
+
const ms = sentAtToMs(m);
|
|
2682
|
+
return makeDayKey(ms); // null if no timestamp
|
|
2683
|
+
});
|
|
2684
|
+
}, [messagesList]);
|
|
2685
|
+
|
|
2686
|
+
const showDateSeparatorAtIndex = useMemo(() => {
|
|
2687
|
+
const n = messagesList.length;
|
|
2688
|
+
const flags = new Array<boolean>(n).fill(false);
|
|
2689
|
+
// helper to find next non-null key to the right
|
|
2690
|
+
const nextNonNullKey = (startIdx: number) => {
|
|
2691
|
+
for (let j = startIdx; j < n; j++) {
|
|
2692
|
+
if (messageDayKeys[j] != null) return messageDayKeys[j];
|
|
2693
|
+
}
|
|
2694
|
+
return null;
|
|
2695
|
+
};
|
|
2696
|
+
|
|
2697
|
+
for (let i = 0; i < n; i++) {
|
|
2698
|
+
const currKey = messageDayKeys[i] ?? nextNonNullKey(i);
|
|
2699
|
+
const nextKey = i + 1 < n ? (messageDayKeys[i + 1] ?? nextNonNullKey(i + 1)) : null;
|
|
2700
|
+
if (currKey != null && currKey !== nextKey) {
|
|
2701
|
+
flags[i] = true;
|
|
2702
|
+
} else if (i === n - 1 && currKey != null) {
|
|
2703
|
+
// last message in list show header
|
|
2704
|
+
flags[i] = true;
|
|
2705
|
+
}
|
|
2706
|
+
}
|
|
2707
|
+
return flags;
|
|
2708
|
+
}, [messageDayKeys, messagesList.length]);
|
|
2709
|
+
|
|
2710
|
+
const isSameLocalDay = (ms?: number) => {
|
|
2711
|
+
if (!ms) return false;
|
|
2712
|
+
const a = new Date(ms);
|
|
2713
|
+
const b = new Date();
|
|
2714
|
+
return (
|
|
2715
|
+
a.getFullYear() === b.getFullYear() &&
|
|
2716
|
+
a.getMonth() === b.getMonth() &&
|
|
2717
|
+
a.getDate() === b.getDate()
|
|
2718
|
+
);
|
|
2719
|
+
};
|
|
2720
|
+
|
|
2721
|
+
const getDayHeaderString = (ms?: number | undefined) => {
|
|
2722
|
+
if (!ms) return undefined;
|
|
2723
|
+
if (isSameLocalDay(ms)) return t("TODAY") || "Today";
|
|
2724
|
+
return dateSeparatorPattern ? dateSeparatorPattern(ms) : undefined;
|
|
2725
|
+
};
|
|
2726
|
+
|
|
2727
|
+
const RenderMessageItem = useCallback(
|
|
2728
|
+
({
|
|
2729
|
+
item,
|
|
2730
|
+
theme,
|
|
2731
|
+
idx,
|
|
2732
|
+
}: {
|
|
2733
|
+
item: CometChat.BaseMessage;
|
|
2734
|
+
theme: CometChatTheme;
|
|
2735
|
+
idx: number;
|
|
2736
|
+
}) => {
|
|
2737
|
+
const index = idx;
|
|
2331
2738
|
lastMessageDate.current = getSentAtTimestamp(item);
|
|
2332
2739
|
|
|
2333
2740
|
return (
|
|
2334
|
-
<React.Fragment key={
|
|
2335
|
-
{separatorView}
|
|
2741
|
+
<React.Fragment key={`${item.getId()}_${item.getMuid()}`}>
|
|
2336
2742
|
<MessageView message={item} currentIndex={index} />
|
|
2337
2743
|
</React.Fragment>
|
|
2338
2744
|
);
|
|
2339
2745
|
},
|
|
2340
|
-
[mergedTheme]
|
|
2746
|
+
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
2341
2747
|
);
|
|
2342
2748
|
|
|
2343
2749
|
const keyExtractor = useCallback((item: any) => `${item?.getId()}_${item.getMuid()}`, []);
|
|
2344
2750
|
|
|
2345
2751
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
2346
2752
|
|
|
2753
|
+
const getAgentEmptyView = useCallback(() => {
|
|
2754
|
+
if (!user) return <></>;
|
|
2755
|
+
|
|
2756
|
+
const userMetadata = user.getMetadata() as any;
|
|
2757
|
+
const displaySuggestions =
|
|
2758
|
+
suggestedMessages.length > 0
|
|
2759
|
+
? suggestedMessages
|
|
2760
|
+
: (userMetadata?.suggestedMessages as string[]) || [];
|
|
2761
|
+
|
|
2762
|
+
const isDark = mergedTheme.mode === "dark";
|
|
2763
|
+
const {
|
|
2764
|
+
background2,
|
|
2765
|
+
textPrimary,
|
|
2766
|
+
textSecondary,
|
|
2767
|
+
borderLight,
|
|
2768
|
+
primary,
|
|
2769
|
+
textTertiary,
|
|
2770
|
+
} = mergedTheme.color;
|
|
2771
|
+
|
|
2772
|
+
const avatarURL = user.getAvatar();
|
|
2773
|
+
const isSVG = avatarURL && (avatarURL.includes(".svg") || avatarURL.includes("svg"));
|
|
2774
|
+
const imageSource = !isSVG && avatarURL ? { uri: avatarURL } : undefined;
|
|
2775
|
+
|
|
2776
|
+
return (
|
|
2777
|
+
<ScrollView
|
|
2778
|
+
contentContainerStyle={{
|
|
2779
|
+
flex: 1,
|
|
2780
|
+
justifyContent: "center",
|
|
2781
|
+
alignItems: "center",
|
|
2782
|
+
}}
|
|
2783
|
+
showsVerticalScrollIndicator={false}
|
|
2784
|
+
>
|
|
2785
|
+
<View
|
|
2786
|
+
style={{
|
|
2787
|
+
alignItems: "center",
|
|
2788
|
+
justifyContent: "center",
|
|
2789
|
+
padding: 24,
|
|
2790
|
+
}}
|
|
2791
|
+
>
|
|
2792
|
+
{emptyChatImageView || (
|
|
2793
|
+
<CometChatAvatar
|
|
2794
|
+
image={imageSource}
|
|
2795
|
+
name={user.getName()}
|
|
2796
|
+
style={{
|
|
2797
|
+
containerStyle: {
|
|
2798
|
+
width: 60,
|
|
2799
|
+
height: 60,
|
|
2800
|
+
borderRadius: 40,
|
|
2801
|
+
marginBottom: 20,
|
|
2802
|
+
alignItems: "center",
|
|
2803
|
+
justifyContent: "center",
|
|
2804
|
+
backgroundColor:
|
|
2805
|
+
mergedTheme.avatarStyle.containerStyle?.backgroundColor,
|
|
2806
|
+
},
|
|
2807
|
+
imageStyle: {
|
|
2808
|
+
width: 60,
|
|
2809
|
+
height: 60,
|
|
2810
|
+
borderRadius: 40,
|
|
2811
|
+
},
|
|
2812
|
+
textStyle: {
|
|
2813
|
+
fontSize: 32,
|
|
2814
|
+
fontWeight: "bold",
|
|
2815
|
+
color: mergedTheme.avatarStyle.textStyle?.color,
|
|
2816
|
+
textAlign: "center",
|
|
2817
|
+
textAlignVertical: "center",
|
|
2818
|
+
},
|
|
2819
|
+
}}
|
|
2820
|
+
/>
|
|
2821
|
+
)}
|
|
2822
|
+
|
|
2823
|
+
{emptyChatGreetingView || (
|
|
2824
|
+
<Text
|
|
2825
|
+
style={{
|
|
2826
|
+
fontSize: theme.typography.heading4.medium.fontSize,
|
|
2827
|
+
fontWeight: theme.typography.heading4.medium.fontWeight,
|
|
2828
|
+
textAlign: "center",
|
|
2829
|
+
color: textPrimary,
|
|
2830
|
+
}}
|
|
2831
|
+
>
|
|
2832
|
+
{userMetadata?.greetingMessage ?? `Hi, I'm ${user.getName()}`}
|
|
2833
|
+
</Text>
|
|
2834
|
+
)}
|
|
2835
|
+
|
|
2836
|
+
{emptyChatIntroMessageView || (
|
|
2837
|
+
<Text
|
|
2838
|
+
style={{
|
|
2839
|
+
fontSize: theme.typography.body.regular.fontSize,
|
|
2840
|
+
fontWeight: theme.typography.body.regular.fontWeight,
|
|
2841
|
+
marginBottom: theme.spacing.spacing.s5,
|
|
2842
|
+
textAlign: "center",
|
|
2843
|
+
lineHeight: 22,
|
|
2844
|
+
paddingHorizontal: 20,
|
|
2845
|
+
color: textTertiary,
|
|
2846
|
+
}}
|
|
2847
|
+
>
|
|
2848
|
+
{userMetadata?.introductoryMessage ??
|
|
2849
|
+
"I'm here to help! Ask me anything or choose from the suggestions below."}
|
|
2850
|
+
</Text>
|
|
2851
|
+
)}
|
|
2852
|
+
|
|
2853
|
+
{!hideSuggestedMessages && displaySuggestions?.length > 0 && (
|
|
2854
|
+
<View
|
|
2855
|
+
style={{
|
|
2856
|
+
flexDirection: "row",
|
|
2857
|
+
flexWrap: "wrap",
|
|
2858
|
+
justifyContent: "center",
|
|
2859
|
+
paddingHorizontal: 0,
|
|
2860
|
+
maxWidth: "100%",
|
|
2861
|
+
}}
|
|
2862
|
+
>
|
|
2863
|
+
{displaySuggestions.map((suggestion, idx) => (
|
|
2864
|
+
<TouchableOpacity
|
|
2865
|
+
key={idx}
|
|
2866
|
+
style={{
|
|
2867
|
+
borderRadius: 20,
|
|
2868
|
+
paddingHorizontal: theme.spacing.spacing.s4,
|
|
2869
|
+
paddingVertical: theme.spacing.spacing.s2,
|
|
2870
|
+
margin: theme.spacing.margin.m1,
|
|
2871
|
+
borderWidth: 1,
|
|
2872
|
+
backgroundColor: isDark ? theme.color.background1 : theme.color.background1,
|
|
2873
|
+
borderColor: isDark ? mergedTheme.color.borderDefault : mergedTheme.color.borderDefault,
|
|
2874
|
+
flexDirection: "row",
|
|
2875
|
+
alignItems: "center",
|
|
2876
|
+
maxWidth: "100%",
|
|
2877
|
+
}}
|
|
2878
|
+
onPress={() => {
|
|
2879
|
+
if (onSuggestedMessageClick) {
|
|
2880
|
+
onSuggestedMessageClick(suggestion);
|
|
2881
|
+
} else {
|
|
2882
|
+
CometChatUIEventHandler.emitUIEvent("ccComposeMessage", {
|
|
2883
|
+
text: suggestion,
|
|
2884
|
+
});
|
|
2885
|
+
}
|
|
2886
|
+
}}
|
|
2887
|
+
>
|
|
2888
|
+
<Text
|
|
2889
|
+
style={{
|
|
2890
|
+
fontWeight: theme.typography.body.regular.fontWeight,
|
|
2891
|
+
fontSize: theme.typography.body.regular.fontSize,
|
|
2892
|
+
color: textSecondary,
|
|
2893
|
+
paddingRight: mergedTheme.spacing.padding.p2,
|
|
2894
|
+
flexShrink: 1,
|
|
2895
|
+
}}
|
|
2896
|
+
>
|
|
2897
|
+
{suggestion}
|
|
2898
|
+
</Text>
|
|
2899
|
+
<Icon
|
|
2900
|
+
size={14}
|
|
2901
|
+
name='right-arrow'
|
|
2902
|
+
color={theme.color.iconSecondary}
|
|
2903
|
+
/>
|
|
2904
|
+
</TouchableOpacity>
|
|
2905
|
+
))}
|
|
2906
|
+
</View>
|
|
2907
|
+
)}
|
|
2908
|
+
</View>
|
|
2909
|
+
</ScrollView>
|
|
2910
|
+
);
|
|
2911
|
+
}, [
|
|
2912
|
+
user,
|
|
2913
|
+
suggestedMessages,
|
|
2914
|
+
hideSuggestedMessages,
|
|
2915
|
+
emptyChatGreetingView,
|
|
2916
|
+
emptyChatIntroMessageView,
|
|
2917
|
+
emptyChatImageView,
|
|
2918
|
+
onSuggestedMessageClick,
|
|
2919
|
+
mergedTheme,
|
|
2920
|
+
]);
|
|
2921
|
+
|
|
2922
|
+
|
|
2923
|
+
|
|
2924
|
+
|
|
2347
2925
|
const getEmptyStateView = useCallback(() => {
|
|
2926
|
+
const isAgenticUserCheck = user?.getRole?.() === '@agentic';
|
|
2927
|
+
|
|
2928
|
+
if (isAgenticUserCheck) {
|
|
2929
|
+
return getAgentEmptyView();
|
|
2930
|
+
}
|
|
2348
2931
|
if (EmptyView)
|
|
2349
2932
|
return (
|
|
2350
2933
|
<>
|
|
@@ -2360,7 +2943,7 @@ export const CometChatMessageList = memo(
|
|
|
2360
2943
|
titleStyle={mergedTheme.messageListStyles.emptyStateStyle?.textStyle as TextStyle}
|
|
2361
2944
|
/>
|
|
2362
2945
|
);
|
|
2363
|
-
}, [mergedTheme]);
|
|
2946
|
+
}, [mergedTheme, EmptyView, getAgentEmptyView, user]);
|
|
2364
2947
|
|
|
2365
2948
|
const getErrorStateView = useCallback(() => {
|
|
2366
2949
|
if (hideError) return null;
|
|
@@ -2402,6 +2985,13 @@ export const CometChatMessageList = memo(
|
|
|
2402
2985
|
if (loadingMessagesRef.current) {
|
|
2403
2986
|
return;
|
|
2404
2987
|
}
|
|
2988
|
+
|
|
2989
|
+
// For agent chats (non-thread), don't fetch previous messages when scrolling to top
|
|
2990
|
+
if (isAgenticUser() && !parentMessageId) {
|
|
2991
|
+
scrollHandler(event);
|
|
2992
|
+
return;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2405
2995
|
const { layoutMeasurement, contentOffset, contentSize } = event.nativeEvent;
|
|
2406
2996
|
if (
|
|
2407
2997
|
Math.floor(contentOffset.y) >= Math.floor(contentSize.height - layoutMeasurement.height)
|
|
@@ -2425,7 +3015,6 @@ export const CometChatMessageList = memo(
|
|
|
2425
3015
|
* layoutMeasurement.height: The height of the visible area within the ScrollView.
|
|
2426
3016
|
* contentOffset.y: The current vertical scroll position (distance from the top of the content).
|
|
2427
3017
|
The y value in contentOffset indicates how far the top edge of the visible area is from the top of the scrollable content.
|
|
2428
|
-
The x value (if applicable) indicates how far the left edge of the visible area is from the left of the scrollable content.
|
|
2429
3018
|
For example:
|
|
2430
3019
|
If contentOffset.y is 0, the top of the visible area is aligned with the top of the content.
|
|
2431
3020
|
If contentOffset.y is 50, the top of the visible area is 50 units (pixels) below the top of the content.
|
|
@@ -2462,13 +3051,29 @@ export const CometChatMessageList = memo(
|
|
|
2462
3051
|
// }, [messagesList]);
|
|
2463
3052
|
|
|
2464
3053
|
const memoizedRenderItem = useCallback(
|
|
2465
|
-
({ item, index, separators }: any) =>
|
|
2466
|
-
|
|
2467
|
-
|
|
2468
|
-
|
|
2469
|
-
|
|
2470
|
-
|
|
2471
|
-
|
|
3054
|
+
({ item, index, separators }: any) => {
|
|
3055
|
+
// index here is FlatList's index in messagesList (newest-first)
|
|
3056
|
+
const showSeparator = showDateSeparatorAtIndex[index];
|
|
3057
|
+
const ms = sentAtToMs(item) ?? Date.now();
|
|
3058
|
+
|
|
3059
|
+
return (
|
|
3060
|
+
<View style={{ flex: 1, paddingHorizontal: 16, paddingVertical: 8 }}>
|
|
3061
|
+
{showSeparator && (
|
|
3062
|
+
<View style={{ alignItems: "center", marginBottom: 8 }}>
|
|
3063
|
+
<CometChatDateSeparator
|
|
3064
|
+
timeStamp={ms}
|
|
3065
|
+
pattern={"dayDateFormat"}
|
|
3066
|
+
customDateString={getDayHeaderString(ms)}
|
|
3067
|
+
style={mergedTheme.messageListStyles.dateSeparatorStyle}
|
|
3068
|
+
/>
|
|
3069
|
+
</View>
|
|
3070
|
+
)}
|
|
3071
|
+
<RenderMessageItem item={item} theme={mergedTheme} idx={index} />
|
|
3072
|
+
{itemSeparator()}
|
|
3073
|
+
</View>
|
|
3074
|
+
);
|
|
3075
|
+
},
|
|
3076
|
+
[mergedTheme, showDateSeparatorAtIndex, dateSeparatorPattern, messageDayKeys]
|
|
2472
3077
|
);
|
|
2473
3078
|
|
|
2474
3079
|
return (
|
|
@@ -2477,7 +3082,7 @@ export const CometChatMessageList = memo(
|
|
|
2477
3082
|
getLoadingStateView()
|
|
2478
3083
|
) : listState == "error" ? (
|
|
2479
3084
|
getErrorStateView()
|
|
2480
|
-
) : listState == "" ? (
|
|
3085
|
+
) : (listState == "" || listState == "loaded") ? (
|
|
2481
3086
|
messagesList.length == 0 ? (
|
|
2482
3087
|
getEmptyStateView()
|
|
2483
3088
|
) : (
|