@cometchat/chat-uikit-react-native 5.3.6 → 5.3.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.
Files changed (49) 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/PERFORMANCE_ARCHITECTURE.md +478 -0
  15. package/src/CometChatMessageList/SEARCH_NAV_PERF_PLAN.md +613 -0
  16. package/src/CometChatMessageList/components/MessageOptionsSheet.tsx +4 -1
  17. package/src/CometChatSearch/CometChatSearch.tsx +8 -6
  18. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +4 -3
  19. package/src/CometChatUsers/CometChatUsers.tsx +56 -43
  20. package/src/calls/CallingExtensionDecorator.tsx +1 -1
  21. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +3 -2
  22. package/src/calls/CometChatCallLogs/CometChatCallLogs.tsx +7 -6
  23. package/src/calls/CometChatIncomingCall/CometChatIncomingCall.tsx +2 -1
  24. package/src/calls/CometChatOutgoingCall/CometChatOutgoingCall.tsx +2 -1
  25. package/src/extensions/CollaborativeDocument/CollaborativeDocumentExtensionDecorator.tsx +4 -4
  26. package/src/extensions/CollaborativeWhiteboard/CollaborativeWhiteboardExtensionDecorator.tsx +5 -3
  27. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
  28. package/src/extensions/MessageTranslation/MessageTranslationDecorator.tsx +5 -5
  29. package/src/extensions/Polls/PollsBubble.tsx +1 -1
  30. package/src/extensions/Polls/PollsDecorator.tsx +1 -1
  31. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -2
  32. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +9 -5
  33. package/src/shared/CometChatUiKit/CometChatUIKit.ts +48 -20
  34. package/src/shared/events/ListenerInitializer.ts +2 -1
  35. package/src/shared/framework/MessageDataSource.tsx +19 -15
  36. package/src/shared/helper/helperFunctions.ts +5 -4
  37. package/src/shared/services/stream-message.service.ts +0 -1
  38. package/src/shared/utils/CommonUtils.ts +1 -1
  39. package/src/shared/utils/MessageUtils.tsx +15 -13
  40. package/src/shared/utils/conversationUtils.ts +2 -2
  41. package/src/shared/views/CometChatActionSheet/CometChatActionSheet.tsx +2 -2
  42. package/src/shared/views/CometChatImageBubble/CometChatImageLoader.tsx +17 -5
  43. package/src/shared/views/CometChatList/CometChatList.tsx +11 -15
  44. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +3 -3
  45. package/src/shared/views/CometChatReactions/CometChatReactions.tsx +2 -1
  46. package/src/shared/views/CometChatStreamMessageBubble/CometChatStreamMessageBubble.tsx +15 -4
  47. package/src/shared/views/CometChatSuggestionList/CometChatSuggestionList.tsx +3 -3
  48. package/src/shared/views/CometChatTextBubble/CometChatTextBubble.tsx +15 -1
  49. package/src/theme/provider.tsx +12 -12
@@ -1030,7 +1030,7 @@ export class MessageDataSource implements DataSource {
1030
1030
 
1031
1031
  // Check if the original message is outgoing to determine styling
1032
1032
  const loggedInUser = CometChatUIKit.loggedInUser;
1033
- const isOutgoingMessage = loggedInUser && message.getSender().getUid() === loggedInUser.getUid();
1033
+ const isOutgoingMessage = loggedInUser && message.getSender()?.getUid() === loggedInUser?.getUid();
1034
1034
 
1035
1035
  const isQuotedMessageDeleted = hasQuotedMessage.getDeletedBy() != null;
1036
1036
 
@@ -1099,7 +1099,7 @@ export class MessageDataSource implements DataSource {
1099
1099
  let loggedInUser = CometChatUIKit.loggedInUser;
1100
1100
 
1101
1101
  const _style =
1102
- loggedInUser && message.getSender().getUid() === loggedInUser.getUid()
1102
+ loggedInUser && message.getSender()?.getUid() === loggedInUser?.getUid()
1103
1103
  ? theme.messageListStyles.outgoingMessageBubbleStyles
1104
1104
  : theme.messageListStyles.incomingMessageBubbleStyles;
1105
1105
  return <CometChatDeletedBubble style={_style?.deletedBubbleStyles} />;
@@ -1114,7 +1114,7 @@ export class MessageDataSource implements DataSource {
1114
1114
  let loggedInUser = CometChatUIKit.loggedInUser;
1115
1115
  if (isVideoMessage(message)) {
1116
1116
  const _style =
1117
- message.getSender().getUid() === loggedInUser!.getUid()
1117
+ message.getSender()?.getUid() === loggedInUser?.getUid()
1118
1118
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.videoBubbleStyles
1119
1119
  : theme.messageListStyles.incomingMessageBubbleStyles?.videoBubbleStyles;
1120
1120
  return (
@@ -1142,21 +1142,21 @@ export class MessageDataSource implements DataSource {
1142
1142
  let loggedInUser = CometChatUIKit.loggedInUser;
1143
1143
  let mentionedUsers = message.getMentionedUsers();
1144
1144
  let textFormatters = [...(additionalParams?.textFormatters || [])];
1145
- const isMessageSentByLoggedInUser = message.getSender().getUid() === loggedInUser!.getUid();
1145
+ const isMessageSentByLoggedInUser = message.getSender()?.getUid() === loggedInUser?.getUid();
1146
1146
  const _style: Partial<CometChatTheme["textBubbleStyles"]> = isMessageSentByLoggedInUser
1147
1147
  ? (theme.messageListStyles.outgoingMessageBubbleStyles
1148
1148
  .textBubbleStyles as CometChatTheme["textBubbleStyles"])
1149
1149
  : (theme.messageListStyles.incomingMessageBubbleStyles
1150
1150
  .textBubbleStyles as CometChatTheme["textBubbleStyles"]);
1151
1151
 
1152
- let linksTextFormatter = ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser!);
1152
+ let linksTextFormatter = ChatConfigurator.getDataSource().getUrlsFormatter(loggedInUser ?? undefined);
1153
1153
  let mentionsTextFormatter = ChatConfigurator.getDataSource().getMentionsFormatter(
1154
- loggedInUser!,
1154
+ loggedInUser ?? undefined,
1155
1155
  theme
1156
1156
  );
1157
1157
 
1158
1158
  // Create rich text formatter for markdown parsing
1159
- let richTextFormatter = new CometChatRichTextFormatter(loggedInUser!);
1159
+ let richTextFormatter = new CometChatRichTextFormatter(loggedInUser ?? undefined);
1160
1160
  richTextFormatter.setMessage(message);
1161
1161
  richTextFormatter.setId("ccDefaultRichTextFormatterId");
1162
1162
  // Use same link color as CometChatUrlsFormatter for consistency
@@ -1243,7 +1243,9 @@ export class MessageDataSource implements DataSource {
1243
1243
  }
1244
1244
 
1245
1245
  if (!additionalParams?.disableMentions && mentionedUsers && mentionedUsers.length) {
1246
- mentionsTextFormatter.setLoggedInUser(loggedInUser!);
1246
+ if (loggedInUser) {
1247
+ mentionsTextFormatter.setLoggedInUser(loggedInUser);
1248
+ }
1247
1249
  mentionsTextFormatter.setMessage(message);
1248
1250
  mentionsTextFormatter.setId("ccDefaultMentionFormatterId");
1249
1251
  }
@@ -1263,7 +1265,9 @@ export class MessageDataSource implements DataSource {
1263
1265
  mentionsFormatterExists = true;
1264
1266
  formatter.setMessage(message);
1265
1267
  formatter.setTargetElement(MentionsTargetElement.textbubble);
1266
- formatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
1268
+ if (CometChatUIKit.loggedInUser) {
1269
+ formatter.setLoggedInUser(CometChatUIKit.loggedInUser);
1270
+ }
1267
1271
  formatter.setContext(isMessageSentByLoggedInUser ? "outgoing" : "incoming");
1268
1272
  }
1269
1273
 
@@ -1307,7 +1311,7 @@ export class MessageDataSource implements DataSource {
1307
1311
  let loggedInUser = CometChatUIKit.loggedInUser;
1308
1312
  if (isImageMessage(message)) {
1309
1313
  const _style =
1310
- message.getSender().getUid() === loggedInUser!.getUid()
1314
+ message.getSender()?.getUid() === loggedInUser?.getUid()
1311
1315
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.imageBubbleStyles
1312
1316
  : theme.messageListStyles.incomingMessageBubbleStyles?.imageBubbleStyles;
1313
1317
 
@@ -1326,7 +1330,7 @@ export class MessageDataSource implements DataSource {
1326
1330
  let loggedInUser = CometChatUIKit.loggedInUser;
1327
1331
  if (isAudioMessage(message)) {
1328
1332
  const _style =
1329
- message.getSender().getUid() === loggedInUser!.getUid()
1333
+ message.getSender()?.getUid() === loggedInUser?.getUid()
1330
1334
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.audioBubbleStyles
1331
1335
  : theme.messageListStyles.incomingMessageBubbleStyles?.audioBubbleStyles;
1332
1336
  return (
@@ -1392,7 +1396,7 @@ export class MessageDataSource implements DataSource {
1392
1396
  }
1393
1397
 
1394
1398
  const _style =
1395
- message.getSender().getUid() === loggedInUser!.getUid()
1399
+ message.getSender()?.getUid() === loggedInUser?.getUid()
1396
1400
  ? theme.messageListStyles.outgoingMessageBubbleStyles?.fileBubbleStyles
1397
1401
  : theme.messageListStyles.incomingMessageBubbleStyles?.fileBubbleStyles;
1398
1402
  return (
@@ -1645,7 +1649,7 @@ export class MessageDataSource implements DataSource {
1645
1649
  ContentView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1646
1650
  const loggedInUser = CometChatUIKit.loggedInUser;
1647
1651
  const _style =
1648
- loggedInUser && message.getSender().getUid() === loggedInUser.getUid()
1652
+ loggedInUser && message.getSender()?.getUid() === loggedInUser?.getUid()
1649
1653
  ? theme.messageListStyles.outgoingMessageBubbleStyles
1650
1654
  : theme.messageListStyles.incomingMessageBubbleStyles;
1651
1655
  return (
@@ -1672,7 +1676,7 @@ export class MessageDataSource implements DataSource {
1672
1676
  ContentView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1673
1677
  const loggedInUser = CometChatUIKit.loggedInUser;
1674
1678
  const _style =
1675
- loggedInUser && message.getSender().getUid() === loggedInUser.getUid()
1679
+ loggedInUser && message.getSender()?.getUid() === loggedInUser?.getUid()
1676
1680
  ? theme.messageListStyles.outgoingMessageBubbleStyles
1677
1681
  : theme.messageListStyles.incomingMessageBubbleStyles;
1678
1682
  return (
@@ -1699,7 +1703,7 @@ export class MessageDataSource implements DataSource {
1699
1703
  ContentView: (message: CometChat.BaseMessage, alignment: MessageBubbleAlignmentType) => {
1700
1704
  const loggedInUser = CometChatUIKit.loggedInUser;
1701
1705
  const _style =
1702
- loggedInUser && message.getSender().getUid() === loggedInUser.getUid()
1706
+ loggedInUser && message.getSender()?.getUid() === loggedInUser?.getUid()
1703
1707
  ? theme.messageListStyles.outgoingMessageBubbleStyles
1704
1708
  : theme.messageListStyles.incomingMessageBubbleStyles;
1705
1709
  return (
@@ -76,9 +76,11 @@ export function deepClone<T>(obj: T, seen = new WeakMap()): T {
76
76
 
77
77
  export function getLastSeenTime(timestamp: number | null | undefined): string {
78
78
  try {
79
+ // Hook must be called unconditionally (Rules of Hooks)
80
+ const { language, t } = useCometChatTranslation();
81
+
79
82
  if (timestamp === null || timestamp === undefined) {
80
- // Move the hook call inside the function, just like in functions.js
81
- return "";
83
+ return t("OFFLINE");
82
84
  }
83
85
 
84
86
  // Convert to milliseconds if in seconds
@@ -86,8 +88,7 @@ export function getLastSeenTime(timestamp: number | null | undefined): string {
86
88
  timestamp *= 1000;
87
89
  }
88
90
 
89
- // Get user's current language from the translation hook (exactly like functions.js)
90
- const { language, t } = useCometChatTranslation();
91
+ // Set the appropriate Day.js locale
91
92
 
92
93
  // Set the appropriate Day.js locale
93
94
  dayjs.locale(language);
@@ -77,7 +77,6 @@ function checkQueueEmptyStatus(runId: string) {
77
77
  if (
78
78
  queue && queue.length === 0 &&
79
79
  streamingComplete[runId] === true &&
80
- renderingComplete[runId] === true &&
81
80
  queueCompletionCallbacks[runId]
82
81
  ) {
83
82
  const aiMsgEntry = lastAIAssistantMessages.find(item => item.runId === runId);
@@ -146,7 +146,7 @@ export class CommonUtils {
146
146
  static getComponentIdFromMessage(message: CometChat.BaseMessage): Object {
147
147
  let id: any = {};
148
148
  if (message.getReceiver() instanceof CometChat.User) {
149
- id["uid"] = message.getSender().getUid();
149
+ id["uid"] = message.getSender()?.getUid();
150
150
  } else if (message.getReceiver() instanceof CometChat.Group) {
151
151
  id["guid"] = (message.getReceiver() as CometChat.Group).getGuid();
152
152
  }
@@ -151,7 +151,7 @@ const getLeadingView = (
151
151
  <CometChatAvatar
152
152
  image={
153
153
  item?.getSender()?.getAvatar && item?.getSender()?.getAvatar()
154
- ? { uri: item.getSender().getAvatar() }
154
+ ? { uri: item.getSender()?.getAvatar() }
155
155
  : undefined
156
156
  }
157
157
  name={
@@ -189,7 +189,7 @@ const getHeaderView = (
189
189
  return undefined;
190
190
  };
191
191
  const getBubbleStyle = (item: CometChat.BaseMessage, theme: CometChatTheme): BubbleStyles => {
192
- const loggedInUser = CometChatUIKit.loggedInUser!;
192
+ const loggedInUser = CometChatUIKit.loggedInUser;
193
193
  const type = (() => {
194
194
  if (item.getDeletedAt()) {
195
195
  return MessageTypeConstants.messageDeleted;
@@ -197,7 +197,7 @@ const getBubbleStyle = (item: CometChat.BaseMessage, theme: CometChatTheme): Bub
197
197
  return item.getType();
198
198
  })();
199
199
 
200
- if (item.getSender().getUid() != loggedInUser.getUid()) {
200
+ if (item.getSender()?.getUid() != loggedInUser?.getUid()) {
201
201
  return (
202
202
  getOverridenBubbleStyles(theme).get(type)?.incoming ??
203
203
  theme.messageListStyles.incomingMessageBubbleStyles
@@ -226,9 +226,9 @@ const getStatusInfoView = (
226
226
  receiptsVisibility: boolean = true,
227
227
  datePattern?: (message: CometChat.BaseMessage) => string
228
228
  ): JSX.Element | undefined => {
229
- const loggedInUser = CometChatUIKit.loggedInUser!;
229
+ const loggedInUser = CometChatUIKit.loggedInUser;
230
230
 
231
- let isOutgoingMessage = item.getSender()?.getUid() == loggedInUser.getUid();
231
+ let isOutgoingMessage = item.getSender()?.getUid() == loggedInUser?.getUid();
232
232
  let _style = getBubbleStyle(item, theme);
233
233
 
234
234
  let messageState;
@@ -286,12 +286,12 @@ export const MessageUtils = {
286
286
  receiptsVisibility,
287
287
  avatarVisibility,
288
288
  } = params;
289
- const templatesMap = getTemplatesMap(templates!);
289
+ const templatesMap = getTemplatesMap(templates ?? []);
290
290
  const baseStyle = getBubbleStyle(message, theme);
291
291
 
292
292
  let hasTemplate = templatesMap.get(`${message.getCategory()}_${message.getType()}`);
293
- if (templates!.length > 0) {
294
- let customTemplate = templates!.find(
293
+ if ((templates?.length ?? 0) > 0) {
294
+ let customTemplate = templates?.find(
295
295
  (template) =>
296
296
  template.type == message.getType() && template.category == message.getCategory()
297
297
  );
@@ -322,8 +322,8 @@ export const MessageUtils = {
322
322
  id={`${message.getId()}`}
323
323
  alignment={alignment}
324
324
  ContentView={
325
- hasTemplate!.ContentView!(message, alignment!) ||
326
- MessageContentView({ message, alignment: alignment!, theme: theme! })
325
+ hasTemplate?.ContentView?.(message, alignment ?? "left") ||
326
+ MessageContentView({ message, alignment: alignment ?? "left", theme: theme! })
327
327
  }
328
328
  LeadingView={
329
329
  message.getReceiverType() === "group"
@@ -335,10 +335,10 @@ export const MessageUtils = {
335
335
  }
336
336
  BottomView={
337
337
  DefaultModerationBottomView ||
338
- (hasTemplate?.BottomView && hasTemplate?.BottomView(message, alignment!))
338
+ (hasTemplate?.BottomView && hasTemplate?.BottomView(message, alignment ?? "left"))
339
339
  }
340
340
  StatusInfoView={
341
- (hasTemplate?.StatusInfoView && hasTemplate!.StatusInfoView(message, alignment!)) ||
341
+ (hasTemplate?.StatusInfoView && hasTemplate?.StatusInfoView(message, alignment ?? "left")) ||
342
342
  getStatusInfoView(message, theme, receiptsVisibility, datePattern)
343
343
  }
344
344
  style={styleForThisMessage}
@@ -404,7 +404,9 @@ export const applyMentionsFormatting = (
404
404
  try {
405
405
  let mentionsFormatter = ChatConfigurator.getDataSource().getMentionsFormatter();
406
406
  mentionsFormatter.setContext("conversation");
407
- mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser!);
407
+ if (CometChatUIKit.loggedInUser) {
408
+ mentionsFormatter.setLoggedInUser(CometChatUIKit.loggedInUser);
409
+ }
408
410
  mentionsFormatter.setTargetElement(MentionsTargetElement.conversation);
409
411
  mentionsFormatter.setMessage(message);
410
412
  if (mentionsStyle) {
@@ -35,7 +35,7 @@ export class CometChatConversationUtils {
35
35
  lastMessage: CometChat.BaseMessage,
36
36
  theme?: CometChatTheme
37
37
  ): string | JSX.Element => {
38
- const uid = CometChatUIKit.loggedInUser!.getUid();
38
+ const uid = CometChatUIKit.loggedInUser?.getUid();
39
39
  if (lastMessage != undefined) {
40
40
  if (lastMessage.getDeletedAt() !== undefined) {
41
41
  return getMessagePreviewInternal("block-fill", t("DELETE_MSG_TEXT"), {theme});
@@ -56,7 +56,7 @@ export class CometChatConversationUtils {
56
56
  if (lastMessage.getType() == "audio") {
57
57
  text = "Voice call";
58
58
  }
59
- if (uid === lastMessage.getSender().getUid()) {
59
+ if (uid === lastMessage.getSender()?.getUid()) {
60
60
  iconName = "phone-outgoing-fill";
61
61
  } else if ((lastMessage as CometChat.Call).getAction() === "unanswered") {
62
62
  color = theme?.color?.error;
@@ -74,7 +74,7 @@ export const CometChatActionSheet = (props: CometChatActionSheetInterface) => {
74
74
 
75
75
  Hooks(props, setActionList);
76
76
 
77
- const _render = ({ item }: { item: any }) => {
77
+ const _render = useCallback(({ item }: { item: any }) => {
78
78
  return (
79
79
  <OptionListView
80
80
  id={item.id}
@@ -83,7 +83,7 @@ export const CometChatActionSheet = (props: CometChatActionSheetInterface) => {
83
83
  style={deepMerge(actionSheetStyles.optionsItemStyle, item?.style ?? {})}
84
84
  />
85
85
  );
86
- };
86
+ }, [actionSheetStyles]);
87
87
 
88
88
  const getList = () => {
89
89
  return (
@@ -77,6 +77,7 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
77
77
  const [isLoaded, setIsLoaded] = useState(false);
78
78
  const [isVisible, setIsVisible] = useState(false);
79
79
  const [imageSource, setImageSource] = useState<ImageSourcePropType>();
80
+ const isUpgraded = useRef(false);
80
81
 
81
82
  // Ref to record touch press time for detecting quick taps
82
83
  const pressTime = useRef<number | null>(0);
@@ -110,17 +111,27 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
110
111
  };
111
112
 
112
113
  useEffect(() => {
113
- // Prefetch the thumbnail if available, else fallback to the full image
114
+ isUpgraded.current = false;
115
+ // Show thumbnail quickly as placeholder, then upgrade to full-resolution image
114
116
  if (thumbnailUrl && typeof thumbnailUrl === "object" && "uri" in thumbnailUrl) {
117
+ // Start with thumbnail for fast display
115
118
  CommonUtils.prefetchThumbnail(thumbnailUrl.uri!).then((success: any) => {
116
- if (success) {
119
+ if (success && !isUpgraded.current) {
117
120
  setImageSource(thumbnailUrl);
118
- } else {
119
- setImageSource(imageUrl); // Fallback to original imageUrl if prefetch fails
120
121
  }
121
122
  });
123
+
124
+ // Prefetch the full-resolution image and upgrade once ready
125
+ if (imageUrl && typeof imageUrl === "object" && "uri" in imageUrl && imageUrl.uri) {
126
+ CommonUtils.prefetchThumbnail(imageUrl.uri!).then((success: any) => {
127
+ if (success) {
128
+ isUpgraded.current = true;
129
+ setImageSource(imageUrl);
130
+ }
131
+ });
132
+ }
122
133
  } else {
123
- setImageSource(imageUrl); // No thumbnail available, fallback to imageUrl
134
+ setImageSource(imageUrl); // No thumbnail available, use full image directly
124
135
  }
125
136
  }, [thumbnailUrl, imageUrl]);
126
137
 
@@ -152,6 +163,7 @@ export const CometChatImageLoader = (props: CometChatImageLoaderPropType) => {
152
163
  {/* Render the image. It is initially hidden until loaded. */}
153
164
  <Image
154
165
  resizeMode={imageResizeMode || "cover"}
166
+ resizeMethod="scale"
155
167
  source={imageSource}
156
168
  style={[styles.image, style]}
157
169
  onLoad={() => setIsLoaded(true)}
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import React, { JSX, useCallback, useEffect, useImperativeHandle, useRef, useState } from "react";
2
3
  import {
3
4
  ActivityIndicator,
@@ -160,7 +161,7 @@ let lastReject: Function;
160
161
 
161
162
  export const CometChatList = React.forwardRef<CometChatListActionsInterface, CometChatListProps>(
162
163
  (props, ref) => {
163
- const connectionListenerId = "connectionListener_" + new Date().getTime();
164
+ const connectionListenerId = "connectionListener_" + Date.now() + "_" + (++__listenerIdCounter);
164
165
  const theme = useTheme();
165
166
  const { t } = useCometChatTranslation();
166
167
  const [isLoadingMore, setIsLoadingMore] = useState(false);
@@ -344,6 +345,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
344
345
  .then((newlist: any[]) => {
345
346
  setDataLoadingStatus(NO_DATA_FOUND);
346
347
  setList(newlist);
348
+ setHasMoreData(true); // Reset pagination since we rebuilt the request
349
+ props.onListFetched?.(newlist);
347
350
  })
348
351
  .catch((error) => {
349
352
  if (error && error["message"] === "Promise cancelled") {
@@ -496,8 +499,10 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
496
499
  }
497
500
  setList(finalList);
498
501
  } else {
499
- // Append to existing list
500
- finalList = [...list, ...newlist];
502
+ // Append to existing list, deduplicating by listItemKey
503
+ const existingKeys = new Set(list.map((item: any) => item[listItemKey]));
504
+ const uniqueNewItems = newlist.filter((item: any) => !existingKeys.has(item[listItemKey]));
505
+ finalList = [...list, ...uniqueNewItems];
501
506
  setList(finalList);
502
507
 
503
508
  // When the backend returns nothing more, mark the end of data
@@ -643,8 +648,8 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
643
648
  TitleView={TitleView && TitleView(item.value)}
644
649
  title={
645
650
  item.value.uid &&
646
- item.value.uid === CometChatUIKit.loggedInUser!.getUid() &&
647
- item.value.name === CometChatUIKit.loggedInUser!.getName()
651
+ item.value.uid === CometChatUIKit.loggedInUser?.getUid() &&
652
+ item.value.name === CometChatUIKit.loggedInUser?.getName()
648
653
  ? t("YOU")
649
654
  : item.value.name
650
655
  }
@@ -669,11 +674,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
669
674
  onPress={() => {
670
675
  onListItemPress(item);
671
676
  }}
672
- // onLongPress={() => {
673
- // onListItemLongPress(item);
674
- // }}
675
677
  onLongPress={(id: any, e: any) => {
676
- // const listItem = getListItem(id);
677
678
  onListItemLongPress(item, e);
678
679
  }}
679
680
  />
@@ -813,12 +814,7 @@ export const CometChatList = React.forwardRef<CometChatListActionsInterface, Com
813
814
  return messageContainer;
814
815
  }, [list, selectedItems, theme, dataLoadingStatus, isLoadingMore, hasMoreData, shouldSelect]);
815
816
 
816
- /**
817
- * Handle the rendering based on loading status
818
- */
819
- // if (list.length === 0 && dataLoadingStatus.toLowerCase() === LOADING) {
820
- // if (LoadingView) return <LoadingView />;
821
- // } else {
817
+
822
818
  return (
823
819
  <View style={{ flex: 1 }}>
824
820
  <Header
@@ -269,7 +269,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
269
269
  );
270
270
 
271
271
  const removeReaction = (reactionObj: CometChat.Reaction) => {
272
- let reactedByMe = loggedInUser.current!.getUid() === reactionObj?.getReactedBy()?.getUid();
272
+ let reactedByMe = loggedInUser.current?.getUid() === reactionObj?.getReactedBy()?.getUid();
273
273
  if (onPress) {
274
274
  onPress(reactionObj, newMessageObj.current);
275
275
  return;
@@ -332,7 +332,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
332
332
  };
333
333
 
334
334
  const subtitleView = useCallback((item: any) => {
335
- let reactedByMe = loggedInUser.current!.getUid() === item?.reactedBy?.uid;
335
+ let reactedByMe = loggedInUser.current?.getUid() === item?.reactedBy?.uid;
336
336
  return reactedByMe ? (
337
337
  <Text style={reactionListStyleFromTheme.subtitleStyle}>{t("TAP_TO_REMOVE")}</Text>
338
338
  ) : null;
@@ -340,7 +340,7 @@ export const CometChatReactionList = (props: CometChatReactionListInterface) =>
340
340
 
341
341
  const _render = ({ item, index }: { item: any; index: number }) => {
342
342
  function getName() {
343
- let reactedByMe = loggedInUser.current!.getUid() === item?.reactedBy?.uid;
343
+ let reactedByMe = loggedInUser.current?.getUid() === item?.reactedBy?.uid;
344
344
  return reactedByMe ? t("YOU") : item?.reactedBy?.name;
345
345
  }
346
346
 
@@ -1,3 +1,4 @@
1
+ let __listenerIdCounter = 0;
1
2
  import React, { JSX, useLayoutEffect } from "react";
2
3
  import { PixelRatio, Text, TouchableOpacity, View } from "react-native";
3
4
  import { CometChat } from "@cometchat/chat-sdk-react-native";
@@ -106,7 +107,7 @@ const CometChatReactions = (props: CometChatReactionsInterface) => {
106
107
  onLongPress={() => {
107
108
  onReactionLongPress && onReactionLongPress(AllObj, messageObject);
108
109
  }}
109
- key={new Date().getTime()}
110
+ key={"extra_reactions_view"}
110
111
  style={
111
112
  reactedByMe
112
113
  ? style?.extraReactionStyle?.activeContainerStyle
@@ -164,14 +164,25 @@ const CometChatStreamMessageBubble: React.FC<CometChatStreamMessageBubbleProps>
164
164
  }, []);
165
165
 
166
166
  useEffect(() => {
167
+ let disconnectTimeout: ReturnType<typeof setTimeout> | null = null;
167
168
  const sub = streamConnection$.subscribe(({ status, error }) => {
168
169
  setConnectionStatus(status);
169
- if (status === 'disconnected' || status === 'error') {
170
- setHasError(true);
171
- stopStreamingForRunId();
170
+ if (status === 'connected') {
171
+ if (disconnectTimeout) {
172
+ clearTimeout(disconnectTimeout);
173
+ disconnectTimeout = null;
174
+ }
175
+ setHasError(false);
176
+ } else if (status === 'disconnected' || status === 'error') {
177
+ disconnectTimeout = setTimeout(() => {
178
+ setHasError(true);
179
+ }, 5000);
172
180
  }
173
181
  });
174
- return () => sub.unsubscribe();
182
+ return () => {
183
+ sub.unsubscribe();
184
+ if (disconnectTimeout) clearTimeout(disconnectTimeout);
185
+ };
175
186
  }, []);
176
187
 
177
188
  // Create markdown styles based on theme
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from "react";
1
+ import React, { useCallback, useEffect, useState } from "react";
2
2
  import { ActivityIndicator, FlatList, ListRenderItemInfo, View, Text } from "react-native";
3
3
  import { CometChatListItem } from "../CometChatListItem";
4
4
  import { SuggestionItem } from "./SuggestionItem";
@@ -52,7 +52,7 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
52
52
  }, 800);
53
53
  }, []);
54
54
 
55
- const _render = ({ item, index }: ListRenderItemInfo<SuggestionItem>) => {
55
+ const _render = useCallback(({ item, index }: ListRenderItemInfo<SuggestionItem>) => {
56
56
  let shouldLoadAvatarName = item.hideLeadingIcon ? {} : { avatarName: item.name };
57
57
  const isAllAlias = item.underlyingText?.startsWith?.('<@all:');
58
58
  const TitleView = isAllAlias ? (
@@ -82,7 +82,7 @@ export const CometChatSuggestionList = (props: CometChatSuggestionListInterface)
82
82
  {...shouldLoadAvatarName}
83
83
  />
84
84
  );
85
- };
85
+ }, [listStyle, theme, t, onPress]);
86
86
 
87
87
  return (
88
88
  <View>
@@ -1,4 +1,4 @@
1
- import React, { useLayoutEffect, useState, useRef, useCallback, useMemo, JSX } from "react";
1
+ import React, { useLayoutEffect, useEffect, useState, useRef, useCallback, useMemo, JSX } from "react";
2
2
  import {
3
3
  StyleProp,
4
4
  Text,
@@ -8,6 +8,7 @@ import {
8
8
  TouchableOpacity,
9
9
  LayoutChangeEvent,
10
10
  TextLayoutEvent,
11
+ Platform,
11
12
  } from "react-native";
12
13
  import {
13
14
  CometChatMentionsFormatter,
@@ -120,6 +121,19 @@ export const CometChatTextBubbleText = (
120
121
  }
121
122
  }, [text]);
122
123
 
124
+ // Android fallback: onTextLayout doesn't fire reliably for short texts.
125
+ // If measurement hasn't completed after 100ms, force it to resolve.
126
+ useEffect(() => {
127
+ if (Platform.OS === 'android' && !measurementComplete && containerWidth != null) {
128
+ const timeout = setTimeout(() => {
129
+ if (!measurementComplete) {
130
+ setMeasurementComplete(true);
131
+ }
132
+ }, 100);
133
+ return () => clearTimeout(timeout);
134
+ }
135
+ }, [text, containerWidth, measurementComplete]);
136
+
123
137
  // Handler to capture container width - use functional update to avoid dependency
124
138
  const onContainerLayout = useCallback((e: LayoutChangeEvent) => {
125
139
  const w = Math.round(e.nativeEvent.layout.width);
@@ -42,10 +42,9 @@ export const CometChatThemeProvider = ({
42
42
  theme = {} as any,
43
43
  }: PropsWithChildren<CometChatThemeProviderProps>) => {
44
44
  const rawScheme = useColorScheme();
45
- // For iOS, debounce the scheme value (300ms delay in this example).
46
- // For Android, use the raw value.
47
- const scheme =
48
- Platform.OS === "ios" ? useDebounce(rawScheme, 300) : rawScheme;
45
+ // Always call the hook unconditionally (Rules of Hooks), use result conditionally
46
+ const debouncedScheme = useDebounce(rawScheme, 300);
47
+ const scheme = Platform.OS === "ios" ? debouncedScheme : rawScheme;
49
48
 
50
49
  const parentProviderTheme = useThemeInternal();
51
50
  const {
@@ -113,15 +112,15 @@ export const CometChatThemeProvider = ({
113
112
  return parentProviderTheme.dark;
114
113
  }, [dark, parentProviderTheme.dark]);
115
114
 
116
- const themeValue = {
115
+ const resolvedMode = mode === "auto"
116
+ ? (typeof scheme === "string" ? scheme : "light")
117
+ : mode;
118
+
119
+ const themeValue = useMemo(() => ({
117
120
  light: lightTheme,
118
121
  dark: darkTheme,
119
- // Use the (conditionally) debounced scheme when determining the mode
120
- mode:
121
- mode === "auto"
122
- ? (typeof scheme === "string" ? scheme : "light")
123
- : mode,
124
- };
122
+ mode: resolvedMode,
123
+ }), [lightTheme, darkTheme, resolvedMode]);
125
124
 
126
125
  return (
127
126
  <ThemeContext.Provider value={themeValue}>
@@ -138,8 +137,9 @@ export const CometChatCompThemeProvider = ({
138
137
  children,
139
138
  theme = {} as any,
140
139
  }: PropsWithChildren<CometChatCompThemeProviderProps>) => {
140
+ const stableTheme = useMemo(() => theme, [theme]);
141
141
  return (
142
- <CompThemeContext.Provider value={theme}>
142
+ <CompThemeContext.Provider value={stableTheme}>
143
143
  {children}
144
144
  </CompThemeContext.Provider>
145
145
  );