@cometchat/chat-uikit-react-native 5.3.6 → 5.3.8

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.
Files changed (48) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +18 -1
  2. package/ios/FileManager.m +14 -3
  3. package/ios/SoundPlayer.m +24 -1
  4. package/package.json +1 -1
  5. package/src/CometChatAIAssistantChatHistory/CometChatAIAssistantChatHistory.tsx +8 -3
  6. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +14 -11
  7. package/src/CometChatConversations/CometChatConversations.tsx +89 -51
  8. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +10 -11
  9. package/src/CometChatGroups/CometChatGroups.tsx +49 -42
  10. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +10 -7
  11. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +12 -10
  12. package/src/CometChatMessageInformation/CometChatMessageInformation.tsx +4 -3
  13. package/src/CometChatMessageList/CometChatMessageList.tsx +398 -144
  14. package/src/CometChatMessageList/MANUAL_TEST_CASES.md +154 -0
  15. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +4 -1
  16. package/src/CometChatSearch/CometChatSearch.tsx +8 -6
  17. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +4 -3
  18. package/src/CometChatUsers/CometChatUsers.tsx +56 -43
  19. package/src/calls/CallingExtensionDecorator.tsx +1 -1
  20. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -2
  21. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +7 -6
  22. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -1
  23. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -1
  24. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +4 -4
  25. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +5 -3
  26. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
  27. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -5
  28. package/src/extensions/Polls/PollsBubble.tsx +1 -1
  29. package/src/extensions/Polls/PollsDecorator.tsx +1 -1
  30. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -2
  31. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +9 -5
  32. package/src/shared/CometChatUiKit/CometChatUIKit.ts +87 -1
  33. package/src/shared/events/ListenerInitializer.ts +2 -1
  34. package/src/shared/framework/MessageDataSource.tsx +19 -15
  35. package/src/shared/helper/helperFunctions.ts +5 -4
  36. package/src/shared/services/stream-message.service.ts +0 -1
  37. package/src/shared/utils/CommonUtils.ts +1 -1
  38. package/src/shared/utils/MessageUtils.tsx +15 -13
  39. package/src/shared/utils/conversationUtils.ts +2 -2
  40. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +2 -2
  41. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +17 -5
  42. package/src/shared/views/CometChatList/CometChatList.tsx +11 -15
  43. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +3 -3
  44. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +2 -1
  45. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +15 -4
  46. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -3
  47. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +15 -1
  48. package/src/theme/provider.tsx +12 -12
@@ -0,0 +1,154 @@
1
+ # Manual Test Cases — `loadLastAgentConversation`
2
+
3
+ ## Prerequisites
4
+ - An `@agentic` user configured in your CometChat dashboard
5
+ - The example app running with `loadLastAgentConversation={true}` on `CometChatMessageList`
6
+ - At least one previous conversation with the agent (send a message, get a response)
7
+
8
+ ---
9
+
10
+ ## TC-1: Auto-loads last conversation on open
11
+
12
+ **Steps:**
13
+ 1. Have at least one previous conversation with the agent (send "Hello", wait for reply)
14
+ 2. Navigate away from the agent chat (go back to conversation list)
15
+ 3. Open the agent chat again
16
+
17
+ **Expected:**
18
+ - A loading indicator appears briefly
19
+ - The previous conversation messages load automatically
20
+ - You see your last messages and the agent's responses
21
+
22
+ ---
23
+
24
+ ## TC-2: Shows greeting/empty state when no previous conversation exists
25
+
26
+ **Steps:**
27
+ 1. Use a fresh `@agentic` user with no message history (or use a new logged-in user who hasn't chatted with the agent)
28
+ 2. Open the agent chat
29
+
30
+ **Expected:**
31
+ - The agent greeting view appears (avatar, greeting message, suggested messages)
32
+ - No loading spinner hangs indefinitely
33
+
34
+ ---
35
+
36
+ ## TC-3: "New Chat" button from header shows empty state
37
+
38
+ **Steps:**
39
+ 1. Open the agent chat (previous conversation auto-loads)
40
+ 2. Tap the "New Chat" button (pencil/compose icon) in the header
41
+
42
+ **Expected:**
43
+ - The screen resets to the greeting/empty state
44
+ - The previous conversation is NOT re-loaded
45
+ - You can type a fresh message to start a new conversation
46
+
47
+ ---
48
+
49
+ ## TC-4: "New Chat" button from Chat History drawer works
50
+
51
+ **Steps:**
52
+ 1. Open the agent chat
53
+ 2. Tap the "Chat History" button in the header to open the history drawer
54
+ 3. Tap the "New Chat" button inside the history drawer
55
+
56
+ **Expected:**
57
+ - The history drawer closes
58
+ - The message list resets to greeting/empty state
59
+ - The previous conversation is NOT re-loaded
60
+
61
+ ---
62
+
63
+ ## TC-5: Loading a specific conversation from Chat History still works
64
+
65
+ **Steps:**
66
+ 1. Open the agent chat (previous conversation auto-loads)
67
+ 2. Tap the "Chat History" button in the header
68
+ 3. Tap on a specific past conversation from the list
69
+
70
+ **Expected:**
71
+ - The selected conversation loads with all its messages
72
+ - Streaming/responses still work if you send a new message in that thread
73
+
74
+ ---
75
+
76
+ ## TC-6: Sending a new message after "New Chat" starts a new thread
77
+
78
+ **Steps:**
79
+ 1. Open the agent chat (previous conversation auto-loads)
80
+ 2. Tap "New Chat" (message list resets to empty)
81
+ 3. Type and send a message (e.g., "What's the weather?")
82
+
83
+ **Expected:**
84
+ - Your message appears in the list
85
+ - A streaming indicator shows while the agent responds
86
+ - The agent's reply appears correctly
87
+ - This is now a NEW conversation thread (not appended to the old one)
88
+
89
+ ---
90
+
91
+ ## TC-7: Re-opening after new chat shows the NEW conversation
92
+
93
+ **Steps:**
94
+ 1. Complete TC-6 (start a new chat, send message, get reply)
95
+ 2. Navigate away from the agent chat
96
+ 3. Open the agent chat again
97
+
98
+ **Expected:**
99
+ - The most recent conversation (from step 1-2) auto-loads
100
+ - You see the "What's the weather?" message and the agent's response
101
+ - NOT the older conversation from before
102
+
103
+ ---
104
+
105
+ ## TC-8: `loadLastAgentConversation={false}` preserves existing behavior
106
+
107
+ **Steps:**
108
+ 1. Change the prop to `loadLastAgentConversation={false}` (or remove it) in Messages.tsx
109
+ 2. Open the agent chat (even with previous conversations)
110
+
111
+ **Expected:**
112
+ - The greeting/empty state shows immediately
113
+ - No automatic loading of previous conversation
114
+ - Behaves exactly as before this feature was added
115
+
116
+ ---
117
+
118
+ ## TC-9: Non-agentic users are unaffected
119
+
120
+ **Steps:**
121
+ 1. With `loadLastAgentConversation={true}` still set
122
+ 2. Open a regular (non-agentic) user chat that has message history
123
+
124
+ **Expected:**
125
+ - Messages load normally (standard behavior)
126
+ - No change in behavior — the prop only applies to `@agentic` users
127
+
128
+ ---
129
+
130
+ ## TC-10: Scroll up to load older messages in auto-loaded conversation
131
+
132
+ **Steps:**
133
+ 1. Have a long conversation history with the agent (30+ messages)
134
+ 2. Open the agent chat (auto-loads last conversation)
135
+ 3. Scroll up to the top of the loaded messages
136
+
137
+ **Expected:**
138
+ - Older messages load (pagination works)
139
+ - No crash or infinite spinner
140
+ - The loading indicator appears at the top while fetching
141
+
142
+ ---
143
+
144
+ ## TC-11: Delete all history from Chat History panel
145
+
146
+ **Steps:**
147
+ 1. Open the agent chat
148
+ 2. Open Chat History drawer
149
+ 3. Long-press and delete all conversations one by one until none remain
150
+
151
+ **Expected:**
152
+ - When the last conversation is deleted, the list shows empty state
153
+ - The message list resets to greeting/empty view
154
+ - Re-opening the chat shows greeting (no conversation to auto-load)
@@ -77,12 +77,15 @@ export const MessageOptionsSheet: React.FC<MessageOptionsSheetProps> = ({
77
77
  onDismiss?.();
78
78
  }}
79
79
  isOpen={isOpen}
80
+ doNotOccupyEntireHeight={!messageInfo && !ExtensionsComponent}
80
81
  style={{
81
82
  paddingHorizontal: 0,
82
83
  maxHeight: messageInfo
83
84
  ? Dimensions.get('window').height * 0.9
84
85
  : Dimensions.get('window').height * 0.52,
85
- minHeight: Dimensions.get('window').height * 0.5,
86
+ ...(messageInfo || ExtensionsComponent
87
+ ? { minHeight: Dimensions.get('window').height * 0.5 }
88
+ : { minHeight: 50 }),
86
89
  }}
87
90
  >
88
91
  {ExtensionsComponent ? (
@@ -1016,8 +1016,9 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1016
1016
  return;
1017
1017
  }
1018
1018
 
1019
- conversationRequestRef.current = buildConversationsRequest();
1020
- const conversations = await conversationRequestRef.current!.fetchNext();
1019
+ const request = buildConversationsRequest();
1020
+ conversationRequestRef.current = request;
1021
+ const conversations = await request.fetchNext();
1021
1022
 
1022
1023
  if (conversations.length > 0) {
1023
1024
  const limit = (guid || uid || searchState.activeFilters.length > 0) ? 30 : 3;
@@ -1145,8 +1146,9 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1145
1146
  return;
1146
1147
  }
1147
1148
 
1148
- messageRequestRef.current = buildMessagesRequest();
1149
- const messages = await messageRequestRef.current!.fetchPrevious();
1149
+ const request = buildMessagesRequest();
1150
+ messageRequestRef.current = request;
1151
+ const messages = await request.fetchPrevious();
1150
1152
 
1151
1153
  if (messages.length > 0) {
1152
1154
  const reversedList = messages.reverse();
@@ -1811,7 +1813,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
1811
1813
  (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
1812
1814
  ]}>
1813
1815
  <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
1814
- {message.getSender().getName()}
1816
+ {message.getSender()?.getName()}
1815
1817
  </Text>
1816
1818
  <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
1817
1819
  {(() => {
@@ -2083,7 +2085,7 @@ export const CometChatSearch: React.FC<CometChatSearchProps> = ({
2083
2085
  (message.getType() === 'image' || message.getType() === 'video') && mergedStyles.messageItemStyle?.textContainerStyle
2084
2086
  ]}>
2085
2087
  <Text style={mergedStyles.messageItemStyle?.titleStyle} numberOfLines={1}>
2086
- {message.getSender().getName()}
2088
+ {message.getSender()?.getName()}
2087
2089
  </Text>
2088
2090
  <Text style={mergedStyles.messageItemStyle?.subtitleStyle} numberOfLines={2}>
2089
2091
  {(() => {
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import React, { useEffect, useState, useMemo, JSX } from "react";
2
3
  import { ScrollView, Text, View } from "react-native";
3
4
  import {
@@ -26,7 +27,7 @@ import { urlPattern } from "../shared/constants/UIKitConstants";
26
27
  /**
27
28
  * Unique UI event identifier for CometChatUIEventHandler.
28
29
  */
29
- const uiEventId = "ccUiEvent" + new Date().getTime();
30
+ const uiEventId = "ccUiEvent" + Date.now() + "_" + (++__listenerIdCounter);
30
31
 
31
32
  /**
32
33
  * Interface for the props of CometChatThreadHeader component.
@@ -121,7 +122,7 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
121
122
 
122
123
  const theme = useTheme();
123
124
  const { t } = useCometChatTranslation();
124
- const style = deepMerge(theme.threadHeaderStyles, props.style ?? {});
125
+ const style = useMemo(() => deepMerge(theme.threadHeaderStyles, props.style ?? {}), [theme, props.style]);
125
126
 
126
127
  /**
127
128
  * Checks if an updated message belongs to the same thread as the current message.
@@ -270,7 +271,7 @@ export const CometChatThreadHeader = (props: CometChatThreadHeaderInterface): JS
270
271
  }),
271
272
  alignment: alignment
272
273
  ? alignment
273
- : message.getSender().getUid() === CometChatUIKit.loggedInUser!.getUid()
274
+ : message.getSender()?.getUid() === CometChatUIKit.loggedInUser?.getUid()
274
275
  ? "right"
275
276
  : "left",
276
277
  theme: mergedTheme,
@@ -1,5 +1,6 @@
1
+ let __listenerIdCounter = 0;
1
2
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
- import React, { JSX, useCallback, useEffect, useRef, useState } from "react";
3
+ import React, { JSX, useCallback, useEffect, useMemo, useRef, useState } from "react";
3
4
  import { ColorValue, KeyboardAvoidingView, Platform, View } from "react-native";
4
5
  import {
5
6
  CometChatList,
@@ -227,7 +228,7 @@ export const CometChatUsers = React.forwardRef<
227
228
  CometChatUsersActionsInterface,
228
229
  CometChatUsersInterface
229
230
  >((props, ref) => {
230
- const userListenerId = "userStatus_" + new Date().getTime();
231
+ const userListenerId = useRef("userStatus_" + Date.now() + "_" + (++__listenerIdCounter)).current;
231
232
  const theme = useTheme();
232
233
  const {t}= useCometChatTranslation()
233
234
  const [hideSearchError, setHideSearchError] = useState(false);
@@ -263,20 +264,20 @@ export const CometChatUsers = React.forwardRef<
263
264
  ...newProps
264
265
  } = props;
265
266
  const userRef = useRef<CometChatUsersActionsInterface>(null);
266
- const mergedStyle = deepMerge(theme.userStyles, style);
267
+ const mergedStyle = useMemo(() => deepMerge(theme.userStyles, style), [theme, style]);
267
268
 
268
269
  // ----- Tooltip functionality for users -----
269
270
  const [tooltipVisible, setTooltipVisible] = useState(false);
270
271
  const [selectedUser, setSelectedUser] = useState<CometChat.User | null>(null);
271
272
  const tooltipPosition = useRef({ pageX: 0, pageY: 0 });
272
273
 
273
- const buildMenuItems = (user: CometChat.User): MenuItemInterface[] => {
274
+ const buildMenuItems = useCallback((user: CometChat.User): MenuItemInterface[] => {
274
275
  if (options) return options(user);
275
276
  if (addOptions) return addOptions(user);
276
277
  return [];
277
- };
278
+ }, [options, addOptions]);
278
279
 
279
- const handleItemLongPress = (user: CometChat.User, e?: any) => {
280
+ const handleItemLongPress = useCallback((user: CometChat.User, e?: any) => {
280
281
  if (props.onItemLongPress) {
281
282
  props.onItemLongPress(user);
282
283
  return;
@@ -293,7 +294,7 @@ export const CometChatUsers = React.forwardRef<
293
294
  }
294
295
  setSelectedUser(user);
295
296
  setTooltipVisible(true);
296
- };
297
+ }, [props.onItemLongPress, buildMenuItems]);
297
298
 
298
299
  useEffect(() => {
299
300
  // Listen for changes in user online/offline status.
@@ -302,12 +303,12 @@ export const CometChatUsers = React.forwardRef<
302
303
  new CometChat.UserListener({
303
304
  onUserOnline: (onlineUser: CometChat.User) => {
304
305
  if (!onlineUser.getBlockedByMe()) {
305
- userRef.current!.updateList(onlineUser);
306
+ userRef.current?.updateList(onlineUser);
306
307
  }
307
308
  },
308
309
  onUserOffline: (offlineUser: CometChat.User) => {
309
310
  if (!offlineUser.getBlockedByMe()) {
310
- userRef.current!.updateList(offlineUser);
311
+ userRef.current?.updateList(offlineUser);
311
312
  }
312
313
  },
313
314
  })
@@ -324,7 +325,7 @@ export const CometChatUsers = React.forwardRef<
324
325
  const clonedUser = CommonUtils.clone(user);
325
326
  clonedUser.blockedByMe = true;
326
327
  clonedUser.hasBlockedMe = true;
327
- userRef.current!.updateList(clonedUser);
328
+ userRef.current?.updateList(clonedUser);
328
329
  };
329
330
 
330
331
  /**
@@ -336,10 +337,10 @@ export const CometChatUsers = React.forwardRef<
336
337
  const clonedUser = CommonUtils.clone(user);
337
338
  clonedUser.blockedByMe = false;
338
339
  clonedUser.hasBlockedMe = false;
339
- userRef.current!.updateList(clonedUser);
340
+ userRef.current?.updateList(clonedUser);
340
341
 
341
342
  CometChat.getUser(clonedUser.getUid()).then((updatedUser) => {
342
- userRef.current!.updateList(updatedUser);
343
+ userRef.current?.updateList(updatedUser);
343
344
  });
344
345
  };
345
346
 
@@ -436,6 +437,45 @@ export const CometChatUsers = React.forwardRef<
436
437
  );
437
438
  }, [theme, mergedStyle, hideError]);
438
439
 
440
+ // Memoize tooltip menu items — avoids .map() creating new array on every render
441
+ const tooltipMenuItems = useMemo(() => {
442
+ if (!selectedUser) return [];
443
+ return buildMenuItems(selectedUser).map((menuItem) => ({
444
+ text: menuItem.text,
445
+ onPress: () => {
446
+ menuItem.onPress();
447
+ setTooltipVisible(false);
448
+ },
449
+ textColor: menuItem.textColor,
450
+ iconColor: menuItem.iconColor,
451
+ disabled: menuItem.disabled,
452
+ }));
453
+ }, [selectedUser, tooltipVisible, buildMenuItems]);
454
+
455
+ // Stable onListFetched callback
456
+ const handleListFetched = useCallback((users: CometChat.User[]) => {
457
+ if (users.length === 0) {
458
+ onEmpty?.();
459
+ } else {
460
+ onLoad?.(users);
461
+ }
462
+ }, [onEmpty, onLoad]);
463
+
464
+ // Stable request builder — avoids creating new instance every render
465
+ const defaultRequestBuilder = useMemo(
466
+ () => (usersRequestBuilder && usersRequestBuilder.setSearchKeyword(searchKeyword)) ||
467
+ new CometChat.UsersRequestBuilder()
468
+ .setLimit(30)
469
+ .hideBlockedUsers(false)
470
+ .setRoles([])
471
+ .friendsOnly(false)
472
+ .setStatus("")
473
+ .setTags([])
474
+ .setUIDs([])
475
+ .setSearchKeyword(searchKeyword),
476
+ [usersRequestBuilder, searchKeyword]
477
+ );
478
+
439
479
  return (
440
480
  <View style={theme.userStyles.containerStyle}>
441
481
  <CometChatList
@@ -453,30 +493,12 @@ export const CometChatUsers = React.forwardRef<
453
493
  LeadingView={LeadingView}
454
494
  onSelection={onSelection}
455
495
  onSubmit={onSubmit}
456
- // Pass our custom long press handler which shows tooltip if options exist.
457
- onItemLongPress={(user: CometChat.User, e: any) => handleItemLongPress(user, e)}
496
+ onItemLongPress={handleItemLongPress}
458
497
  ItemView={props.ItemView}
459
- onListFetched={(users: CometChat.User[]) => {
460
- if (users.length === 0) {
461
- onEmpty?.();
462
- } else {
463
- onLoad?.(users);
464
- }
465
- }}
498
+ onListFetched={handleListFetched}
466
499
  ref={userRef}
467
500
  hideSearch={hideSearch ? hideSearch : hideSearchError}
468
- requestBuilder={
469
- (usersRequestBuilder && usersRequestBuilder.setSearchKeyword(searchKeyword)) ||
470
- new CometChat.UsersRequestBuilder()
471
- .setLimit(30)
472
- .hideBlockedUsers(false)
473
- .setRoles([])
474
- .friendsOnly(false)
475
- .setStatus("")
476
- .setTags([])
477
- .setUIDs([])
478
- .setSearchKeyword(searchKeyword)
479
- }
501
+ requestBuilder={defaultRequestBuilder}
480
502
  listStyle={mergedStyle}
481
503
  hideStickyHeader={!stickyHeaderVisibility}
482
504
  listItemKey='uid'
@@ -516,16 +538,7 @@ export const CometChatUsers = React.forwardRef<
516
538
  event={{
517
539
  nativeEvent: tooltipPosition.current,
518
540
  }}
519
- menuItems={buildMenuItems(selectedUser).map((menuItem) => ({
520
- text: menuItem.text,
521
- onPress: () => {
522
- menuItem.onPress();
523
- setTooltipVisible(false);
524
- },
525
- textColor: menuItem.textColor,
526
- iconColor: menuItem.iconColor,
527
- disabled: menuItem.disabled,
528
- }))}
541
+ menuItems={tooltipMenuItems}
529
542
  />
530
543
  </View>
531
544
  )}
@@ -220,7 +220,7 @@ export class CallingExtensionDecorator extends DataSourceDecorator {
220
220
  if (this.isDeletedMessage(message))
221
221
  return ChatConfigurator.dataSource.getDeleteMessageBubble(message, theme);
222
222
 
223
- const isSentByMe = message.getSender().getUid() === loggedInUser!.getUid();
223
+ const isSentByMe = message.getSender()?.getUid() === loggedInUser?.getUid();
224
224
 
225
225
  const _style = isSentByMe
226
226
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.meetCallBubbleStyles
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
3
  import React, { useEffect, useMemo, useRef, useState } from "react";
3
4
  import {
@@ -27,7 +28,7 @@ import { JSX } from "react";
27
28
 
28
29
  const CometChatCalls = CallingPackage.CometChatCalls;
29
30
 
30
- const listenerId = "callEventListener_" + new Date().getTime();
31
+ const listenerId = "callEventListener_" + Date.now() + "_" + (++__listenerIdCounter);
31
32
 
32
33
  /**
33
34
  * Props for the CometChatCallButtons component.
@@ -153,7 +154,7 @@ export const CometChatCallButtons = (props: CometChatCallButtonsInterface): JSX.
153
154
  );
154
155
  customMessage.setCategory(CometChat.CATEGORY_CUSTOM as CometChat.MessageCategory);
155
156
  customMessage.setMuid(String(getUnixTimestampInMilliseconds()));
156
- customMessage.setSender(loggedInUser.current!);
157
+ customMessage.setSender(loggedInUser.current);
157
158
  customMessage.setReceiver(group);
158
159
  customMessage.setMetadata({
159
160
  ...customMessage.getMetadata(),
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
3
  import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
3
4
  import {
@@ -30,7 +31,7 @@ import { CometChatTooltipMenu, MenuItemInterface } from "../../shared/views/Come
30
31
  import { JSX } from "react";
31
32
  import { useCometChatTranslation, useLocalizedDate, LocalizedDateHelper } from "../../shared";
32
33
 
33
- const listenerId = "callEventListener_" + new Date().getTime();
34
+ const listenerId = "callEventListener_" + Date.now() + "_" + (++__listenerIdCounter);
34
35
  const CometChatCalls = CallingPackage.CometChatCalls;
35
36
 
36
37
  /**
@@ -210,10 +211,10 @@ export const CometChatCallLogs = (props: CometChatCallLogsConfigurationInterface
210
211
  */
211
212
  function setRequestBuilder() {
212
213
  const reqBuilder = callLogRequestBuilder
213
- ? callLogRequestBuilder.setAuthToken(loggedInUser.current!.getAuthToken())
214
+ ? callLogRequestBuilder.setAuthToken(loggedInUser.current?.getAuthToken())
214
215
  : new CometChatCalls.CallLogRequestBuilder()
215
216
  .setLimit(30)
216
- .setAuthToken(loggedInUser.current!.getAuthToken() || "")
217
+ .setAuthToken(loggedInUser.current?.getAuthToken() || "")
217
218
  .setCallCategory("call");
218
219
  callLogRequestBuilderRef.current = reqBuilder.build();
219
220
  }
@@ -225,9 +226,9 @@ export const CometChatCallLogs = (props: CometChatCallLogsConfigurationInterface
225
226
  const fetchCallLogs = (isAppending: boolean = true) => {
226
227
  setListState("loading");
227
228
  callLogRequestBuilderRef
228
- .current!.fetchNext()
229
+ .current?.fetchNext()
229
230
  .then((callLogs: any) => {
230
- if (callLogRequestBuilderRef.current!.limit > callLogs.length) {
231
+ if (callLogRequestBuilderRef.current?.limit > callLogs.length) {
231
232
  setHasMoreData(false);
232
233
  }
233
234
  if (callLogs.length > 0) {
@@ -409,7 +410,7 @@ export const CometChatCallLogs = (props: CometChatCallLogsConfigurationInterface
409
410
  if (ItemView) return ItemView(item);
410
411
 
411
412
  const { title, avatarUrl } = getCallDetails(item);
412
- const callStatus = CallUtils.getCallStatusForCallLogs(item, loggedInUser.current!);
413
+ const callStatus = CallUtils.getCallStatusForCallLogs(item, loggedInUser.current);
413
414
 
414
415
  return (
415
416
  <TouchableOpacity
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
3
  import React, { useEffect, useMemo, useRef, useState } from "react";
3
4
  import { Text, TouchableOpacity, View, StyleSheet } from "react-native";
@@ -20,7 +21,7 @@ import { JSX } from "react";
20
21
  import { useCometChatTranslation } from "../../shared/resources/CometChatLocalizeNew";
21
22
  import { SafeAreaView } from "react-native-safe-area-context";
22
23
 
23
- const listnerID = "CALL_LISTENER_" + new Date().getTime();
24
+ const listnerID = "CALL_LISTENER_" + Date.now() + "_" + (++__listenerIdCounter);
24
25
  const CometChatCalls = CallingPackage.CometChatCalls;
25
26
 
26
27
  /**
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
3
  import React, { JSX, useEffect, useMemo, useRef, useState } from "react";
3
4
  import { Modal, Text, TouchableOpacity, View } from "react-native";
@@ -19,7 +20,7 @@ import { DeepPartial } from "../../shared/helper/types";
19
20
  import { useCometChatTranslation } from "../../shared/resources/CometChatLocalizeNew";
20
21
  import { SafeAreaView } from "react-native-safe-area-context";
21
22
 
22
- const listenerId = "callListener_" + new Date().getTime();
23
+ const listenerId = "callListener_" + Date.now() + "_" + (++__listenerIdCounter);
23
24
  const CometChatCalls = CallingPackage.CometChatCalls;
24
25
 
25
26
  /**
@@ -53,9 +53,9 @@ export class CollaborativeDocumentExtensionDecorator extends DataSourceDecorator
53
53
  }
54
54
 
55
55
  if (
56
- conversation.getLastMessage().getType() == ExtensionTypeConstants.document &&
57
- conversation.getLastMessage().getCategory() == MessageCategoryConstants.custom &&
58
- conversation.getLastMessage().getDeletedAt() === undefined
56
+ conversation.getLastMessage()?.getType() == ExtensionTypeConstants.document &&
57
+ conversation.getLastMessage()?.getCategory() == MessageCategoryConstants.custom &&
58
+ conversation.getLastMessage()?.getDeletedAt() === undefined
59
59
  ) {
60
60
  return getMessagePreviewInternal(
61
61
  "collaborative-document-fill",
@@ -253,7 +253,7 @@ export class CollaborativeDocumentExtensionDecorator extends DataSourceDecorator
253
253
  let url: string = documentData.document_url;
254
254
 
255
255
  const _style =
256
- message.getSender().getUid() === loggedInUser!.getUid()
256
+ message.getSender()?.getUid() === loggedInUser?.getUid()
257
257
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.collaborativeBubbleStyles
258
258
  : theme.messageListStyles.incomingMessageBubbleStyles?.collaborativeBubbleStyles;
259
259
 
@@ -36,7 +36,7 @@ const t = getCometChatTranslation();
36
36
  export class CollaborativeWhiteboardExtensionDecorator extends DataSourceDecorator {
37
37
  whiteboardUrl: string = "v1/create";
38
38
 
39
- loggedInUser!: CometChat.User;
39
+ loggedInUser: CometChat.User | null = null;
40
40
 
41
41
  /**
42
42
  * Creates an instance of CollaborativeWhiteboardExtensionDecorator.
@@ -48,7 +48,9 @@ export class CollaborativeWhiteboardExtensionDecorator extends DataSourceDecorat
48
48
 
49
49
  CometChat.getLoggedinUser()
50
50
  .then((u) => {
51
- this.loggedInUser = u!;
51
+ if (u) {
52
+ this.loggedInUser = u;
53
+ }
52
54
  })
53
55
  .catch((err) => console.log(err));
54
56
  }
@@ -330,7 +332,7 @@ export class CollaborativeWhiteboardExtensionDecorator extends DataSourceDecorat
330
332
  const username = this.loggedInUser?.getName()?.replace(" ", "_");
331
333
  const url: string = whiteboardData.board_url + "&username=" + username;
332
334
  const _style =
333
- message.getSender().getUid() === loggedInUser!.getUid()
335
+ message.getSender()?.getUid() === loggedInUser?.getUid()
334
336
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.collaborativeBubbleStyles
335
337
  : theme.messageListStyles.incomingMessageBubbleStyles?.collaborativeBubbleStyles;
336
338
 
@@ -65,7 +65,7 @@ export class LinkPreviewExtensionDecorator extends DataSourceDecorator {
65
65
  return super.getTextMessageContentView(message, alignment, theme, additionalParams);
66
66
  } else {
67
67
  const _style: DeepPartial<BubbleStyles["linkPreviewBubbleStyles"]> =
68
- message.getSender().getUid() === loggedInUser!.getUid()
68
+ message.getSender()?.getUid() === loggedInUser?.getUid()
69
69
  ? theme.messageListStyles?.outgoingMessageBubbleStyles?.linkPreviewBubbleStyles
70
70
  : theme.messageListStyles?.incomingMessageBubbleStyles?.linkPreviewBubbleStyles;
71
71
  const { image, favicon, title, url, description } = linkData.links[0];
@@ -294,7 +294,7 @@ export class MessageTranslationExtensionDecorator extends DataSourceDecorator {
294
294
  let textFormatters = [...(additionalParams?.textFormatters || [])];
295
295
 
296
296
  // Determine if the message was sent by the logged-in user.
297
- const isMessageSentByLoggedInUser = message.getSender().getUid() === loggedInUser!.getUid();
297
+ const isMessageSentByLoggedInUser = message.getSender()?.getUid() === loggedInUser?.getUid();
298
298
 
299
299
  // Select the appropriate style based on the sender.
300
300
  const _style: Partial<CometChatTheme["textBubbleStyles"]> = isMessageSentByLoggedInUser
@@ -304,9 +304,9 @@ export class MessageTranslationExtensionDecorator extends DataSourceDecorator {
304
304
  .textBubbleStyles as CometChatTheme["textBubbleStyles"]);
305
305
 
306
306
  // Create URL formatter and set properties.
307
- let linksTextFormatter = ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser!);
307
+ let linksTextFormatter = ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser);
308
308
  let mentionsTextFormatter = ChatConfigurator.getDataSource().getMentionsFormatter(
309
- loggedInUser!,
309
+ loggedInUser,
310
310
  theme
311
311
  );
312
312
  linksTextFormatter.setMessage(message);
@@ -319,7 +319,7 @@ export class MessageTranslationExtensionDecorator extends DataSourceDecorator {
319
319
 
320
320
  // Configure mentions formatter if mentioned users are present.
321
321
  if (!additionalParams?.disableMentions && mentionedUsers && mentionedUsers.length) {
322
- mentionsTextFormatter.setLoggedInUser(loggedInUser!);
322
+ mentionsTextFormatter.setLoggedInUser(loggedInUser);
323
323
  mentionsTextFormatter.setMessage(message);
324
324
  mentionsTextFormatter.setId("ccDefaultMentionFormatterId");
325
325
  }
@@ -337,7 +337,7 @@ export class MessageTranslationExtensionDecorator extends DataSourceDecorator {
337
337
  mentionsFormatterExists = true;
338
338
  formatter.setMessage(message);
339
339
  formatter.setTargetElement(MentionsTargetElement.textbubble);
340
- formatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
340
+ formatter.setLoggedInUser(CometChatUIKit.loggedInUser);
341
341
  formatter.setContext(isMessageSentByLoggedInUser ? "outgoing" : "incoming");
342
342
  }
343
343
  formatter.setMessage(message);
@@ -193,7 +193,7 @@ export const PollsBubble = (props: PollsBubbleInterface) => {
193
193
  */
194
194
  const handleResult = (id: string) => {
195
195
  let newOptionsMetaData = { ...optionsMetaData };
196
- if (newOptionsMetaData.results?.options[id]?.["voters"]?.[loggedInUser!.getUid()]) return;
196
+ if (newOptionsMetaData.results?.options[id]?.["voters"]?.[loggedInUser?.getUid()]) return;
197
197
  // Set the loading option id here
198
198
  setLoadingOption(id);
199
199
  setIsLoading(true);
@@ -245,7 +245,7 @@ export class PollsExtensionDecorator extends DataSourceDecorator {
245
245
  if (message && _loggedInUser) {
246
246
  const metaData = getExtensionData(message, MetadataConstants.extensions?.polls);
247
247
  const _style =
248
- message.getSender().getUid() === _loggedInUser.getUid()
248
+ message.getSender()?.getUid() === _loggedInUser.getUid()
249
249
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.pollBubbleStyles
250
250
  : theme.messageListStyles.incomingMessageBubbleStyles?.pollBubbleStyles;
251
251