@cometchat/chat-uikit-react-native 5.2.6 → 5.2.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -113,6 +113,22 @@ import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNe
|
|
|
113
113
|
|
|
114
114
|
let _defaultRequestBuilder: CometChat.MessagesRequestBuilder;
|
|
115
115
|
|
|
116
|
+
/**
|
|
117
|
+
* Helper function to safely get message ID
|
|
118
|
+
* Prevents "undefined is not a function" errors in release builds
|
|
119
|
+
*/
|
|
120
|
+
const safeGetId = (item: any): string | number | undefined => {
|
|
121
|
+
return typeof item?.getId === 'function' ? item.getId() : item?.id;
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Helper function to safely get message MUID
|
|
126
|
+
* Prevents "undefined is not a function" errors in release builds
|
|
127
|
+
*/
|
|
128
|
+
const safeGetMuid = (item: any): string | undefined => {
|
|
129
|
+
return typeof item?.getMuid === 'function' ? item.getMuid() : item?.muid;
|
|
130
|
+
};
|
|
131
|
+
|
|
116
132
|
/**
|
|
117
133
|
* Uses Inverted Flat List
|
|
118
134
|
* Array needs to be reversed meaning the latest message will be at array[0]
|
|
@@ -1640,11 +1656,11 @@ export const CometChatMessageList = memo(
|
|
|
1640
1656
|
// If found, update it in place instead of inserting again.
|
|
1641
1657
|
if (!isAgenticUser) {
|
|
1642
1658
|
try {
|
|
1643
|
-
const incomingId = (newMessage as any)?.getId
|
|
1644
|
-
const incomingMuid = (newMessage as any)?.muid || (newMessage as any)?.getMuid
|
|
1659
|
+
const incomingId = typeof (newMessage as any)?.getId === 'function' ? (newMessage as any).getId() : (newMessage as any)?.id;
|
|
1660
|
+
const incomingMuid = (newMessage as any)?.muid || (typeof (newMessage as any)?.getMuid === 'function' ? (newMessage as any).getMuid() : undefined);
|
|
1645
1661
|
const existingIndex = messagesContentListRef.current.findIndex((m: any) => {
|
|
1646
|
-
const mid = m?.getId
|
|
1647
|
-
const mmuid = m?.muid || m?.getMuid
|
|
1662
|
+
const mid = typeof m?.getId === 'function' ? m.getId() : m?.id;
|
|
1663
|
+
const mmuid = m?.muid || (typeof m?.getMuid === 'function' ? m.getMuid() : undefined);
|
|
1648
1664
|
return (
|
|
1649
1665
|
(incomingId && mid && String(mid) === String(incomingId)) ||
|
|
1650
1666
|
(incomingMuid && mmuid && String(mmuid) === String(incomingMuid))
|
|
@@ -1967,18 +1983,52 @@ export const CometChatMessageList = memo(
|
|
|
1967
1983
|
setQueueCompletionCallback(
|
|
1968
1984
|
runId,
|
|
1969
1985
|
(aiAssistantMessage, aiToolResultMessage, aiToolArgumentMessage) => {
|
|
1970
|
-
|
|
1971
|
-
aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1986
|
+
const replacement = aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1972
1987
|
if (!replacement) return;
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1988
|
+
console.log("replacement", replacement);
|
|
1989
|
+
|
|
1990
|
+
const replacementId = typeof (replacement as any)?.getId === 'function' ? (replacement as any).getId() : (replacement as any)?.id;
|
|
1991
|
+
const replacementRunId = (replacement as any)?.data?.runId;
|
|
1992
|
+
|
|
1993
|
+
if(messagesContentListRef.current?.[0]?.isStreamMessage && messagesContentListRef.current?.[0]?.targetMessageId === runId){
|
|
1994
|
+
latestMessageRef.current = replacement;
|
|
1995
|
+
}
|
|
1996
|
+
|
|
1997
|
+
const list = messagesContentListRef.current;
|
|
1998
|
+
let updatedList: any[];
|
|
1999
|
+
|
|
2000
|
+
// Find indices in one pass
|
|
2001
|
+
const existingIndex = list.findIndex((msg) => {
|
|
2002
|
+
const msgId = typeof (msg as any)?.getId === 'function' ? (msg as any).getId() : (msg as any)?.id;
|
|
2003
|
+
return msgId && String(msgId) === String(replacementId);
|
|
1981
2004
|
});
|
|
2005
|
+
|
|
2006
|
+
const streamIndex = existingIndex === -1 ? list.findIndex((msg) =>
|
|
2007
|
+
(msg as any).isStreamMessage === true && (msg as any).targetMessageId === runId
|
|
2008
|
+
) : -1;
|
|
2009
|
+
|
|
2010
|
+
const matchingIndex = (existingIndex === -1 && streamIndex === -1) ? list.findIndex((msg) => {
|
|
2011
|
+
const msgRunId = (msg as any)?.data?.runId;
|
|
2012
|
+
return msgRunId && String(msgRunId) === String(replacementRunId);
|
|
2013
|
+
}) : -1;
|
|
2014
|
+
|
|
2015
|
+
// Update list based on what we found
|
|
2016
|
+
if (existingIndex !== -1) {
|
|
2017
|
+
// Update existing message
|
|
2018
|
+
updatedList = list.map((msg, idx) => idx === existingIndex ? replacement : msg);
|
|
2019
|
+
} else if (streamIndex !== -1) {
|
|
2020
|
+
// Replace stream message
|
|
2021
|
+
updatedList = list.map((msg, idx) => idx === streamIndex ? replacement : msg);
|
|
2022
|
+
} else if (matchingIndex !== -1) {
|
|
2023
|
+
// Insert before matching message
|
|
2024
|
+
updatedList = [...list];
|
|
2025
|
+
updatedList.splice(matchingIndex, 0, replacement);
|
|
2026
|
+
} else {
|
|
2027
|
+
// Add at beginning
|
|
2028
|
+
updatedList = [replacement, ...list];
|
|
2029
|
+
}
|
|
2030
|
+
|
|
2031
|
+
console.log("updatedList", updatedList);
|
|
1982
2032
|
messagesContentListRef.current = updatedList;
|
|
1983
2033
|
setMessagesList(updatedList);
|
|
1984
2034
|
onLoad && onLoad([...updatedList].reverse());
|
|
@@ -2140,13 +2190,15 @@ export const CometChatMessageList = memo(
|
|
|
2140
2190
|
//todo show unsupported bubble
|
|
2141
2191
|
},
|
|
2142
2192
|
onAIAssistantMessageReceived: (aiAssistantMessage: CometChat.AIAssistantMessage) => {
|
|
2143
|
-
const
|
|
2144
|
-
|
|
2145
|
-
|
|
2193
|
+
const assistantData = typeof aiAssistantMessage.getAssistantMessageData === 'function' ? aiAssistantMessage.getAssistantMessageData() : null;
|
|
2194
|
+
const runIdFromData = assistantData && typeof assistantData.getRunId === 'function' ? assistantData.getRunId() : null;
|
|
2195
|
+
const runIdFromId = typeof aiAssistantMessage.getId === 'function' ? aiAssistantMessage.getId() : (aiAssistantMessage as any)?.id;
|
|
2196
|
+
const runId = runIdFromData || runIdFromId;
|
|
2146
2197
|
|
|
2198
|
+
const parentMsgId = typeof aiAssistantMessage.getParentMessageId === 'function' ? aiAssistantMessage.getParentMessageId() : (aiAssistantMessage as any)?.parentMessageId;
|
|
2147
2199
|
if (
|
|
2148
2200
|
parentMessageId &&
|
|
2149
|
-
String(parentMessageId) !== String(
|
|
2201
|
+
String(parentMessageId) !== String(parentMsgId)
|
|
2150
2202
|
) {
|
|
2151
2203
|
return;
|
|
2152
2204
|
}
|
|
@@ -3294,8 +3346,11 @@ export const CometChatMessageList = memo(
|
|
|
3294
3346
|
const index = idx;
|
|
3295
3347
|
lastMessageDate.current = getSentAtTimestamp(item);
|
|
3296
3348
|
|
|
3349
|
+
const id = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3350
|
+
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : (item as any)?.muid;
|
|
3351
|
+
|
|
3297
3352
|
return (
|
|
3298
|
-
<React.Fragment key={`${
|
|
3353
|
+
<React.Fragment key={`${id}_${muid}`}>
|
|
3299
3354
|
<MessageView message={item} currentIndex={index} />
|
|
3300
3355
|
</React.Fragment>
|
|
3301
3356
|
);
|
|
@@ -3303,13 +3358,31 @@ export const CometChatMessageList = memo(
|
|
|
3303
3358
|
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
3304
3359
|
);
|
|
3305
3360
|
|
|
3306
|
-
const keyExtractor = useCallback((item: any) => {
|
|
3307
|
-
|
|
3308
|
-
const
|
|
3309
|
-
|
|
3310
|
-
|
|
3361
|
+
const keyExtractor = useCallback((item: any, index: number) => {
|
|
3362
|
+
// Safely check if methods exist before calling them
|
|
3363
|
+
const id = typeof item?.getId === 'function' ? item.getId() : item?.id;
|
|
3364
|
+
const muid = typeof item?.getMuid === 'function' ? item.getMuid() : item?.muid;
|
|
3365
|
+
|
|
3366
|
+
// Use id + muid if both exist
|
|
3367
|
+
if (id && muid) {
|
|
3368
|
+
return `${id}_${muid}`;
|
|
3369
|
+
}
|
|
3370
|
+
|
|
3371
|
+
// Use muid if id doesn't exist (pending message)
|
|
3372
|
+
if (muid) {
|
|
3373
|
+
return `muid_${muid}`;
|
|
3374
|
+
}
|
|
3375
|
+
|
|
3376
|
+
// Use id if muid doesn't exist
|
|
3377
|
+
if (id) {
|
|
3378
|
+
return `id_${id}`;
|
|
3379
|
+
}
|
|
3380
|
+
|
|
3381
|
+
// Fallback to index if neither exist (should not happen, but prevents duplicates)
|
|
3382
|
+
if (__DEV__) {
|
|
3383
|
+
console.warn('[MessageList] Message without id or muid at index:', index, item);
|
|
3311
3384
|
}
|
|
3312
|
-
return
|
|
3385
|
+
return `index_${index}`;
|
|
3313
3386
|
}, []);
|
|
3314
3387
|
|
|
3315
3388
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
@@ -3685,7 +3758,8 @@ export const CometChatMessageList = memo(
|
|
|
3685
3758
|
}
|
|
3686
3759
|
}
|
|
3687
3760
|
const ms = sentAtToMs(item) ?? Date.now();
|
|
3688
|
-
const
|
|
3761
|
+
const itemId = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3762
|
+
const isHighlighted = highlightedMessageId === String(itemId);
|
|
3689
3763
|
|
|
3690
3764
|
const separatorHeight = showSeparator ? 40 : 0;
|
|
3691
3765
|
|
|
@@ -52,13 +52,18 @@ let streamedMessages: { [runId: string]: string } = {};
|
|
|
52
52
|
* Per-runId event queue, matching Android logic
|
|
53
53
|
*/
|
|
54
54
|
const eventQueues: { [runId: string]: CometChat.AIAssistantBaseEvent[] } = {};
|
|
55
|
-
let lastAIAssistantMessages: {
|
|
55
|
+
let lastAIAssistantMessages: Array<{ runId: string, message: CometChat.AIAssistantMessage }> = [];
|
|
56
56
|
|
|
57
57
|
/**
|
|
58
58
|
* Store AIAssistantMessage for a runId
|
|
59
59
|
*/
|
|
60
60
|
export const storeAIAssistantMessage = (runId: string, message: CometChat.AIAssistantMessage) => {
|
|
61
|
-
lastAIAssistantMessages
|
|
61
|
+
const existingIndex = lastAIAssistantMessages.findIndex(item => item.runId === runId);
|
|
62
|
+
if (existingIndex !== -1) {
|
|
63
|
+
lastAIAssistantMessages[existingIndex].message = message;
|
|
64
|
+
} else {
|
|
65
|
+
lastAIAssistantMessages.push({ runId, message });
|
|
66
|
+
}
|
|
62
67
|
checkQueueEmptyStatus(runId);
|
|
63
68
|
};
|
|
64
69
|
|
|
@@ -75,17 +80,16 @@ function checkQueueEmptyStatus(runId: string) {
|
|
|
75
80
|
renderingComplete[runId] === true &&
|
|
76
81
|
queueCompletionCallbacks[runId]
|
|
77
82
|
) {
|
|
78
|
-
const
|
|
79
|
-
const
|
|
80
|
-
const
|
|
83
|
+
const aiMsgEntry = lastAIAssistantMessages.find(item => item.runId === runId);
|
|
84
|
+
const aiMsg = aiMsgEntry?.message;
|
|
85
|
+
const toolResult = lastAIToolResultMessages[runId]?.message;
|
|
86
|
+
const toolArg = lastAIToolArgumentMessages[runId]?.message;
|
|
87
|
+
const indexToDelete = lastAIAssistantMessages.findIndex(item => item.runId === runId);
|
|
88
|
+
if (indexToDelete !== -1) {
|
|
89
|
+
lastAIAssistantMessages.splice(indexToDelete, 1);
|
|
90
|
+
}
|
|
81
91
|
if (aiMsg || toolResult || toolArg) {
|
|
82
92
|
queueCompletionCallbacks[runId](aiMsg, toolResult, toolArg);
|
|
83
|
-
delete queueCompletionCallbacks[runId];
|
|
84
|
-
delete lastAIAssistantMessages[runId];
|
|
85
|
-
delete lastAIToolResultMessages[runId];
|
|
86
|
-
delete lastAIToolArgumentMessages[runId];
|
|
87
|
-
delete streamingComplete[runId];
|
|
88
|
-
delete renderingComplete[runId];
|
|
89
93
|
}
|
|
90
94
|
}
|
|
91
95
|
}
|
|
@@ -445,7 +449,7 @@ export const stopStreamingForRunId = (runId?: string) => {
|
|
|
445
449
|
delete streamedMessages[runId];
|
|
446
450
|
delete processedDeltas[runId];
|
|
447
451
|
delete queueCompletionCallbacks[runId];
|
|
448
|
-
|
|
452
|
+
lastAIAssistantMessages = lastAIAssistantMessages.filter(item => item.runId !== runId);
|
|
449
453
|
delete lastAIToolResultMessages[runId];
|
|
450
454
|
delete lastAIToolArgumentMessages[runId];
|
|
451
455
|
delete streamingComplete[runId];
|
|
@@ -456,7 +460,7 @@ export const stopStreamingForRunId = (runId?: string) => {
|
|
|
456
460
|
processedDeltas = {};
|
|
457
461
|
streamingComplete = {};
|
|
458
462
|
renderingComplete = {};
|
|
459
|
-
lastAIAssistantMessages =
|
|
463
|
+
lastAIAssistantMessages = [];
|
|
460
464
|
lastAIToolResultMessages = {};
|
|
461
465
|
lastAIToolArgumentMessages = {};
|
|
462
466
|
for (const key in queueCompletionCallbacks) {
|