@cometchat/chat-uikit-react-native 5.2.5 → 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 +1 -1
- package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +23 -7
- package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +34 -2
- package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +4 -1
- package/src/CometChatMessageList/CometChatMessageList.tsx +104 -28
- package/src/CometChatSearch/CometChatSearch.tsx +0 -1
- package/src/shared/services/stream-message.service.ts +17 -13
- package/src/shared/views/CometChatAvatar/CometChatAvatar.tsx +10 -2
- package/src/shared/views/CometChatList/CometChatList.tsx +8 -0
- package/src/shared/views/CometChatList/Header.tsx +1 -0
- package/src/shared/views/CometChatList/styles.ts +4 -2
- package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +8 -0
package/package.json
CHANGED
|
@@ -264,12 +264,18 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
264
264
|
const [tooltipVisible, setTooltipVisible] = useState(false);
|
|
265
265
|
const [modalType, setModalType] = useState<"ban" | "kick" | "">("");
|
|
266
266
|
const modalVisible = modalType !== "";
|
|
267
|
-
const [selectedRole, setSelectedRole] = useState("
|
|
267
|
+
const [selectedRole, setSelectedRole] = useState<string>("");
|
|
268
268
|
const [currentUserRole, setCurrentUserRole] = useState<string | null>(null);
|
|
269
269
|
const listRef = useRef<any>(null);
|
|
270
270
|
const [isToolTipDismissed, setIsToolTipDismissed] = useState(false);
|
|
271
271
|
const loggedInUser = React.useRef(CometChatUIKit.loggedInUser!);
|
|
272
272
|
|
|
273
|
+
// Derived: whether selected scope equals current user scope
|
|
274
|
+
const isScopeUnchanged = React.useMemo(() => {
|
|
275
|
+
if (!selectedItem) return true;
|
|
276
|
+
return selectedRole === selectedItem.getScope();
|
|
277
|
+
}, [selectedItem, selectedRole]);
|
|
278
|
+
|
|
273
279
|
|
|
274
280
|
// Define role permissions for current user actions
|
|
275
281
|
const RolePermissions: { [key: string]: string[] } = {
|
|
@@ -517,9 +523,9 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
517
523
|
onPress: () => {
|
|
518
524
|
const currentScope = item.getScope();
|
|
519
525
|
setTooltipVisible(false);
|
|
520
|
-
const formattedScope = currentScope.charAt(0).toUpperCase() + currentScope.slice(1);
|
|
521
526
|
setIsBottomSheetVisible(true);
|
|
522
|
-
|
|
527
|
+
// Preselect to current scope (lowercase) for accurate comparison
|
|
528
|
+
setSelectedRole(currentScope);
|
|
523
529
|
},
|
|
524
530
|
icon: (
|
|
525
531
|
<ChangeCircle
|
|
@@ -771,8 +777,12 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
771
777
|
onClose={() => {
|
|
772
778
|
setIsBottomSheetVisible(false);
|
|
773
779
|
setSelectedItem(null);
|
|
780
|
+
setSelectedRole("");
|
|
781
|
+
}}
|
|
782
|
+
onDismiss={() => {
|
|
783
|
+
setSelectedItem(null);
|
|
784
|
+
setSelectedRole("");
|
|
774
785
|
}}
|
|
775
|
-
onDismiss={() => setSelectedItem(null)}
|
|
776
786
|
>
|
|
777
787
|
{selectedItem ? (
|
|
778
788
|
<View style={mergedStyle?.changeScope?.container}>
|
|
@@ -861,6 +871,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
861
871
|
onPress={() => {
|
|
862
872
|
setIsBottomSheetVisible(false);
|
|
863
873
|
setSelectedItem(null);
|
|
874
|
+
setSelectedRole("");
|
|
864
875
|
}}
|
|
865
876
|
>
|
|
866
877
|
<Text style={mergedStyle?.changeScope?.cancelStyle?.textStyle}>
|
|
@@ -868,8 +879,13 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
868
879
|
</Text>
|
|
869
880
|
</TouchableOpacity>
|
|
870
881
|
<TouchableOpacity
|
|
871
|
-
style={
|
|
882
|
+
style={[
|
|
883
|
+
mergedStyle?.changeScope?.confirmStyle?.containerStyle,
|
|
884
|
+
isScopeUnchanged ? {opacity: 0.5} : {}
|
|
885
|
+
]}
|
|
886
|
+
disabled={isScopeUnchanged}
|
|
872
887
|
onPress={async () => {
|
|
888
|
+
if (isScopeUnchanged) return;
|
|
873
889
|
if (selectedItem && selectedRole) {
|
|
874
890
|
const currentScope = selectedItem.getScope();
|
|
875
891
|
const scopeToSet = selectedRole;
|
|
@@ -878,7 +894,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
878
894
|
if (scopeToSet === currentScope) {
|
|
879
895
|
setIsBottomSheetVisible(false);
|
|
880
896
|
setSelectedItem(null);
|
|
881
|
-
setSelectedRole("
|
|
897
|
+
setSelectedRole("");
|
|
882
898
|
return;
|
|
883
899
|
}
|
|
884
900
|
|
|
@@ -925,7 +941,7 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
|
|
|
925
941
|
}
|
|
926
942
|
);
|
|
927
943
|
setSelectedItem(null);
|
|
928
|
-
setSelectedRole("
|
|
944
|
+
setSelectedRole("");
|
|
929
945
|
} catch (error) {
|
|
930
946
|
console.error("Error updating user scope:", error);
|
|
931
947
|
}
|
|
@@ -164,14 +164,14 @@ export interface CometChatMessageComposerInterface {
|
|
|
164
164
|
id?: string | number;
|
|
165
165
|
|
|
166
166
|
/**
|
|
167
|
-
* CometChat SDK
|
|
167
|
+
* CometChat SDK's user object.
|
|
168
168
|
*
|
|
169
169
|
* @type {CometChat.User}
|
|
170
170
|
*/
|
|
171
171
|
user?: CometChat.User;
|
|
172
172
|
|
|
173
173
|
/**
|
|
174
|
-
* CometChat SDK
|
|
174
|
+
* CometChat SDK's group object.
|
|
175
175
|
*
|
|
176
176
|
* @type {CometChat.Group}
|
|
177
177
|
*/
|
|
@@ -1611,6 +1611,16 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
1611
1611
|
return false; // No mention found at the cursor position
|
|
1612
1612
|
}
|
|
1613
1613
|
|
|
1614
|
+
function getMentionRangeAtCursor(mentionRanges: any, cursorPosition: number): { start: number; end: number } | null {
|
|
1615
|
+
for (let [range] of mentionRanges) {
|
|
1616
|
+
const [start, end] = range.split("_").map(Number);
|
|
1617
|
+
if (cursorPosition >= start && cursorPosition <= end) {
|
|
1618
|
+
return { start, end }; // Return the boundary positions
|
|
1619
|
+
}
|
|
1620
|
+
}
|
|
1621
|
+
return null; // No mention found at the cursor position
|
|
1622
|
+
}
|
|
1623
|
+
|
|
1614
1624
|
function shouldOpenList(
|
|
1615
1625
|
selection: {
|
|
1616
1626
|
start: number;
|
|
@@ -2284,9 +2294,31 @@ export const CometChatMessageComposer = React.forwardRef(
|
|
|
2284
2294
|
},
|
|
2285
2295
|
}}
|
|
2286
2296
|
onSelectionChange={({ nativeEvent: { selection } }) => {
|
|
2297
|
+
const cursorPos = selection.start;
|
|
2298
|
+
const mentionRange = getMentionRangeAtCursor(mentionMap.current, cursorPos);
|
|
2299
|
+
|
|
2300
|
+
if (mentionRange) {
|
|
2301
|
+
console.log('Mention boundary positions:', mentionRange);
|
|
2302
|
+
const distanceToStart = cursorPos - mentionRange.start;
|
|
2303
|
+
const distanceToEnd = mentionRange.end - cursorPos;
|
|
2304
|
+
let targetPosition: number;
|
|
2305
|
+
if (distanceToStart <= distanceToEnd) {
|
|
2306
|
+
targetPosition = mentionRange.start;
|
|
2307
|
+
} else {
|
|
2308
|
+
targetPosition = mentionRange.end;
|
|
2309
|
+
}
|
|
2310
|
+
if (targetPosition !== cursorPos) {
|
|
2311
|
+
InteractionManager.runAfterInteractions(() => {
|
|
2312
|
+
setSelectionPosition({ start: targetPosition, end: targetPosition });
|
|
2313
|
+
});
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
}
|
|
2317
|
+
|
|
2287
2318
|
setSelectionPosition(selection);
|
|
2288
2319
|
openList(selection);
|
|
2289
2320
|
}}
|
|
2321
|
+
selection={selectionPosition}
|
|
2290
2322
|
onChangeText={textChangeHandler}
|
|
2291
2323
|
VoiceRecordingButtonView={voiceRecoringButtonElem}
|
|
2292
2324
|
SecondaryButtonView={SecondaryButtonViewElem}
|
|
@@ -335,7 +335,10 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
|
|
|
335
335
|
};
|
|
336
336
|
|
|
337
337
|
const handleUserStatus = (userDetails: CometChat.User) => {
|
|
338
|
-
if (userDetails.getUid() === userObj?.getUid())
|
|
338
|
+
if (userDetails.getUid() === userObj?.getUid()) {
|
|
339
|
+
setUserObj(userDetails);
|
|
340
|
+
setUserStatus(userDetails.getStatus());
|
|
341
|
+
}
|
|
339
342
|
};
|
|
340
343
|
|
|
341
344
|
const msgTypingIndicator = (typist: CometChat.TypingIndicator, status: string) => {
|
|
@@ -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]
|
|
@@ -559,7 +575,7 @@ export const CometChatMessageList = memo(
|
|
|
559
575
|
const hideReactionOption = isAgenticUser() ? true : propHideReactionOption;
|
|
560
576
|
const hideMessagePrivatelyOption = isAgenticUser() ? true : propHideMessagePrivatelyOption;
|
|
561
577
|
const hideCopyMessageOption = isAgenticUser() ? true : propHideCopyMessageOption;
|
|
562
|
-
const hideMessageInfoOption = isAgenticUser() ? true : propHideMessageInfoOption;
|
|
578
|
+
const hideMessageInfoOption = isAgenticUser() ? true : (propHideMessageInfoOption || !receiptsVisibility);
|
|
563
579
|
const hideGroupActionMessages = isAgenticUser() ? true : propHideGroupActionMessages;
|
|
564
580
|
const hideFlagMessageOption = isAgenticUser() ? true : propHideFlagMessageOption;
|
|
565
581
|
|
|
@@ -1261,7 +1277,7 @@ export const CometChatMessageList = memo(
|
|
|
1261
1277
|
hideReactionOption: isAgenticUserCheck || hideReactionOption,
|
|
1262
1278
|
hideMessagePrivatelyOption: isAgenticUserCheck || hideMessagePrivatelyOption,
|
|
1263
1279
|
hideCopyMessageOption: isAgenticUserCheck || hideCopyMessageOption,
|
|
1264
|
-
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption,
|
|
1280
|
+
hideMessageInfoOption: isAgenticUserCheck || hideMessageInfoOption || !receiptsVisibility,
|
|
1265
1281
|
hideFlagMessageOption: isAgenticUserCheck || hideFlagMessageOption,
|
|
1266
1282
|
hideGroupActionMessages,
|
|
1267
1283
|
onReplyClick: (messageId: string) => {
|
|
@@ -1310,6 +1326,7 @@ export const CometChatMessageList = memo(
|
|
|
1310
1326
|
hideCopyMessageOption,
|
|
1311
1327
|
hideMessageInfoOption,
|
|
1312
1328
|
hideGroupActionMessages,
|
|
1329
|
+
receiptsVisibility,
|
|
1313
1330
|
]);
|
|
1314
1331
|
|
|
1315
1332
|
const getPlainString = (underlyingText: string, messageObject: CometChat.BaseMessage) => {
|
|
@@ -1639,11 +1656,11 @@ export const CometChatMessageList = memo(
|
|
|
1639
1656
|
// If found, update it in place instead of inserting again.
|
|
1640
1657
|
if (!isAgenticUser) {
|
|
1641
1658
|
try {
|
|
1642
|
-
const incomingId = (newMessage as any)?.getId
|
|
1643
|
-
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);
|
|
1644
1661
|
const existingIndex = messagesContentListRef.current.findIndex((m: any) => {
|
|
1645
|
-
const mid = m?.getId
|
|
1646
|
-
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);
|
|
1647
1664
|
return (
|
|
1648
1665
|
(incomingId && mid && String(mid) === String(incomingId)) ||
|
|
1649
1666
|
(incomingMuid && mmuid && String(mmuid) === String(incomingMuid))
|
|
@@ -1966,18 +1983,52 @@ export const CometChatMessageList = memo(
|
|
|
1966
1983
|
setQueueCompletionCallback(
|
|
1967
1984
|
runId,
|
|
1968
1985
|
(aiAssistantMessage, aiToolResultMessage, aiToolArgumentMessage) => {
|
|
1969
|
-
|
|
1970
|
-
aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1986
|
+
const replacement = aiAssistantMessage || aiToolResultMessage || aiToolArgumentMessage;
|
|
1971
1987
|
if (!replacement) return;
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
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);
|
|
1980
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);
|
|
1981
2032
|
messagesContentListRef.current = updatedList;
|
|
1982
2033
|
setMessagesList(updatedList);
|
|
1983
2034
|
onLoad && onLoad([...updatedList].reverse());
|
|
@@ -2139,13 +2190,15 @@ export const CometChatMessageList = memo(
|
|
|
2139
2190
|
//todo show unsupported bubble
|
|
2140
2191
|
},
|
|
2141
2192
|
onAIAssistantMessageReceived: (aiAssistantMessage: CometChat.AIAssistantMessage) => {
|
|
2142
|
-
const
|
|
2143
|
-
|
|
2144
|
-
|
|
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;
|
|
2145
2197
|
|
|
2198
|
+
const parentMsgId = typeof aiAssistantMessage.getParentMessageId === 'function' ? aiAssistantMessage.getParentMessageId() : (aiAssistantMessage as any)?.parentMessageId;
|
|
2146
2199
|
if (
|
|
2147
2200
|
parentMessageId &&
|
|
2148
|
-
String(parentMessageId) !== String(
|
|
2201
|
+
String(parentMessageId) !== String(parentMsgId)
|
|
2149
2202
|
) {
|
|
2150
2203
|
return;
|
|
2151
2204
|
}
|
|
@@ -2332,6 +2385,7 @@ export const CometChatMessageList = memo(
|
|
|
2332
2385
|
|
|
2333
2386
|
useEffect(() => {
|
|
2334
2387
|
if (selectedEmoji) {
|
|
2388
|
+
Keyboard.dismiss();
|
|
2335
2389
|
setShowReactionList(true);
|
|
2336
2390
|
}
|
|
2337
2391
|
}, [selectedEmoji]);
|
|
@@ -3292,8 +3346,11 @@ export const CometChatMessageList = memo(
|
|
|
3292
3346
|
const index = idx;
|
|
3293
3347
|
lastMessageDate.current = getSentAtTimestamp(item);
|
|
3294
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
|
+
|
|
3295
3352
|
return (
|
|
3296
|
-
<React.Fragment key={`${
|
|
3353
|
+
<React.Fragment key={`${id}_${muid}`}>
|
|
3297
3354
|
<MessageView message={item} currentIndex={index} />
|
|
3298
3355
|
</React.Fragment>
|
|
3299
3356
|
);
|
|
@@ -3301,13 +3358,31 @@ export const CometChatMessageList = memo(
|
|
|
3301
3358
|
[mergedTheme, isAgenticUser, messagesList, getSentAtTimestamp, dateSeparatorPattern]
|
|
3302
3359
|
);
|
|
3303
3360
|
|
|
3304
|
-
const keyExtractor = useCallback((item: any) => {
|
|
3305
|
-
|
|
3306
|
-
const
|
|
3307
|
-
|
|
3308
|
-
|
|
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);
|
|
3309
3384
|
}
|
|
3310
|
-
return
|
|
3385
|
+
return `index_${index}`;
|
|
3311
3386
|
}, []);
|
|
3312
3387
|
|
|
3313
3388
|
const itemSeparator = useCallback(() => <View style={{ height: 8 }} />, []);
|
|
@@ -3683,7 +3758,8 @@ export const CometChatMessageList = memo(
|
|
|
3683
3758
|
}
|
|
3684
3759
|
}
|
|
3685
3760
|
const ms = sentAtToMs(item) ?? Date.now();
|
|
3686
|
-
const
|
|
3761
|
+
const itemId = typeof item?.getId === 'function' ? item.getId() : (item as any)?.id;
|
|
3762
|
+
const isHighlighted = highlightedMessageId === String(itemId);
|
|
3687
3763
|
|
|
3688
3764
|
const separatorHeight = showSeparator ? 40 : 0;
|
|
3689
3765
|
|
|
@@ -681,7 +681,6 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
|
|
|
681
681
|
const handleClearSearch = useCallback(() => {
|
|
682
682
|
setSearchValue("");
|
|
683
683
|
dispatch({ type: "setSearchText", searchText: "" });
|
|
684
|
-
dispatch({ type: "resetActiveFilters" });
|
|
685
684
|
dispatch({ type: "clearResults" });
|
|
686
685
|
}, []);
|
|
687
686
|
|
|
@@ -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) {
|
|
@@ -52,8 +52,16 @@ export const CometChatAvatar = (props: CometChatAvatarProps) => {
|
|
|
52
52
|
return <Image source={imageSource} style={[avatarStyle.imageStyle]} />;
|
|
53
53
|
}
|
|
54
54
|
const initials = [...(name || "")].slice(0, 2).join("").toUpperCase();
|
|
55
|
-
|
|
56
|
-
return
|
|
55
|
+
|
|
56
|
+
return (
|
|
57
|
+
<Text
|
|
58
|
+
style={[avatarStyle.textStyle]}
|
|
59
|
+
adjustsFontSizeToFit={true}
|
|
60
|
+
numberOfLines={1}
|
|
61
|
+
>
|
|
62
|
+
{initials}
|
|
63
|
+
</Text>
|
|
64
|
+
);
|
|
57
65
|
}, [image, name, avatarStyle.imageStyle, avatarStyle.textStyle]);
|
|
58
66
|
|
|
59
67
|
return <View style={[avatarStyle.containerStyle]}>{getImageView()}</View>;
|
|
@@ -6,6 +6,7 @@ import {
|
|
|
6
6
|
GestureResponderEvent,
|
|
7
7
|
ImageSourcePropType,
|
|
8
8
|
ImageStyle,
|
|
9
|
+
Platform,
|
|
9
10
|
StyleProp,
|
|
10
11
|
Text,
|
|
11
12
|
TextStyle,
|
|
@@ -245,11 +246,17 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
245
246
|
|
|
246
247
|
const listHandlerRef = useRef<any>(null);
|
|
247
248
|
const initialRunRef = useRef(true);
|
|
249
|
+
const selectionEffectDidMountRef = useRef(false);
|
|
248
250
|
|
|
249
251
|
const [list, setList] = useState<any[]>([]);
|
|
250
252
|
const [dataLoadingStatus, setDataLoadingStatus] = useState<string>(LOADING);
|
|
251
253
|
|
|
252
254
|
useEffect(() => {
|
|
255
|
+
// Skip calling onSelection on initial mount; only trigger after a user-driven change
|
|
256
|
+
if (!selectionEffectDidMountRef.current) {
|
|
257
|
+
selectionEffectDidMountRef.current = true;
|
|
258
|
+
return;
|
|
259
|
+
}
|
|
253
260
|
if (props.onSelection) {
|
|
254
261
|
const selectedArray = Object.values(selectedItems);
|
|
255
262
|
props.onSelection(selectedArray);
|
|
@@ -766,6 +773,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
|
|
|
766
773
|
showsVerticalScrollIndicator={false}
|
|
767
774
|
ListFooterComponent={renderFooter}
|
|
768
775
|
keyboardShouldPersistTaps='always'
|
|
776
|
+
keyboardDismissMode={Platform.OS === 'ios' ? 'on-drag' : 'none'}
|
|
769
777
|
/>
|
|
770
778
|
</View>
|
|
771
779
|
);
|
|
@@ -39,7 +39,8 @@ const styles = StyleSheet.create({
|
|
|
39
39
|
flexDirection: "row",
|
|
40
40
|
alignItems: "center",
|
|
41
41
|
justifyContent: "center",
|
|
42
|
-
|
|
42
|
+
minHeight: 44, // minHeight for accessibility
|
|
43
|
+
paddingVertical:8,
|
|
43
44
|
},
|
|
44
45
|
selectedCountText: {
|
|
45
46
|
paddingLeft: 10,
|
|
@@ -90,11 +91,12 @@ const styles = StyleSheet.create({
|
|
|
90
91
|
width: "100%",
|
|
91
92
|
},
|
|
92
93
|
headerLetterStyle: {
|
|
93
|
-
|
|
94
|
+
minHeight: 24, // minHeight for accessibility
|
|
94
95
|
fontWeight: "500",
|
|
95
96
|
fontFamily: undefined,
|
|
96
97
|
fontSize: 13,
|
|
97
98
|
marginTop: 8,
|
|
99
|
+
paddingVertical: 4,
|
|
98
100
|
},
|
|
99
101
|
dividerStyle: {
|
|
100
102
|
height: 1,
|
|
@@ -88,6 +88,12 @@ export interface CometChatMessageInputInterface {
|
|
|
88
88
|
* @type {RefObject<any>}
|
|
89
89
|
*/
|
|
90
90
|
messageInputRef?: RefObject<any>;
|
|
91
|
+
/**
|
|
92
|
+
* Selection state for the TextInput to control cursor position.
|
|
93
|
+
*
|
|
94
|
+
* @type {{ start: number; end: number } | undefined}
|
|
95
|
+
*/
|
|
96
|
+
selection?: { start: number; end: number };
|
|
91
97
|
}
|
|
92
98
|
|
|
93
99
|
/**
|
|
@@ -112,6 +118,7 @@ export const CometChatMessageInput = (props: CometChatMessageInputInterface) =>
|
|
|
112
118
|
onSelectionChange,
|
|
113
119
|
messageInputRef,
|
|
114
120
|
VoiceRecordingButtonView,
|
|
121
|
+
selection,
|
|
115
122
|
} = props;
|
|
116
123
|
|
|
117
124
|
return (
|
|
@@ -125,6 +132,7 @@ export const CometChatMessageInput = (props: CometChatMessageInputInterface) =>
|
|
|
125
132
|
textAlignVertical='top'
|
|
126
133
|
placeholder={placeHolderText}
|
|
127
134
|
onSelectionChange={onSelectionChange}
|
|
135
|
+
selection={selection}
|
|
128
136
|
onFocus={() => {
|
|
129
137
|
CometChatUIEventHandler.emitUIEvent(CometChatUIEvents.hidePanel, {
|
|
130
138
|
alignment: ViewAlignment.composerBottom,
|