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

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 (36) hide show
  1. package/package.json +2 -1
  2. package/src/CometChatConversations/CometChatConversations.tsx +107 -18
  3. package/src/CometChatMessageList/CometChatMessageList.tsx +24 -5
  4. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +811 -0
  5. package/src/CometChatNotificationFeed/Skeleton.tsx +43 -0
  6. package/src/CometChatNotificationFeed/index.ts +19 -0
  7. package/src/CometChatNotificationFeed/style.ts +333 -0
  8. package/src/CometChatNotificationFeed/utils.ts +124 -0
  9. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +22 -18
  10. package/src/extensions/LinkPreview/LinkPreviewExtensionDecorator.tsx +1 -1
  11. package/src/extensions/ThumbnailGeneration/ThumbnailGenerationDecorator.tsx +5 -1
  12. package/src/index.ts +7 -0
  13. package/src/shared/icons/components/notification-empty.tsx +27 -0
  14. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +8 -1
  15. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +8 -1
  16. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +8 -1
  17. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +8 -1
  18. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +8 -1
  19. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +8 -1
  20. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +8 -1
  21. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +8 -1
  22. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +8 -1
  23. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +8 -1
  24. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +8 -1
  25. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +8 -1
  26. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +8 -1
  27. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +8 -1
  28. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +8 -1
  29. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +8 -1
  30. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +8 -1
  31. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +8 -1
  32. package/src/shared/utils/MessageReceiptUtils.ts +0 -1
  33. package/src/shared/views/CometChatInlineAudioRecorder/useAudioRecorder.ts +53 -21
  34. package/src/shared/views/CometChatList/CometChatList.tsx +26 -15
  35. package/src/theme/default/default.ts +6 -0
  36. package/src/theme/type.ts +2 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cometchat/chat-uikit-react-native",
3
- "version": "5.3.4",
3
+ "version": "5.3.6",
4
4
  "description": "Ready-to-use Chat UI Components for React Native",
5
5
  "main": "src/index",
6
6
  "module": "src/index",
@@ -65,6 +65,7 @@
65
65
  "typescript": "^5.0.4"
66
66
  },
67
67
  "dependencies": {
68
+ "@cometchat/cards-react-native": "^1.0.0",
68
69
  "@types/prop-types": "^15.7.14",
69
70
  "prop-types": "^15.8.1",
70
71
  "react-native-markdown-display": "^7.0.2",
@@ -300,6 +300,9 @@ export const CometChatConversations = (props: ConversationInterface) => {
300
300
  const conversationListRef = React.useRef<CometChatListActionsInterface>(null);
301
301
  // Store the logged in user for comparison and event handling.
302
302
  const loggedInUser = React.useRef<CometChat.User>(undefined);
303
+ // Buffer receipts by messageId to handle race conditions where receipts arrive
304
+ // before the message becomes the conversation's last message (due to async updateLastMessage)
305
+ const pendingReceiptsMap = React.useRef<Map<string, { readAt?: number; deliveredAt?: number }>>(new Map());
303
306
  // State to control the confirmation dialog for deleting a conversation.
304
307
  const [confirmDelete, setConfirmDelete] = React.useState<string | undefined>(undefined);
305
308
  // State to control selection mode for conversation items.
@@ -445,6 +448,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
445
448
  (conversationListRef.current?.getListItem(
446
449
  `${loggedInUser.current?.getUid()}_user_${uid}`
447
450
  ) as unknown as CometChat.Conversation);
451
+ if (!item) return;
448
452
  const user: CometChat.User = item.getConversationWith();
449
453
  if (user.getBlockedByMe() || user.getHasBlockedMe()) return;
450
454
  if (item) {
@@ -513,6 +517,31 @@ export const CometChatConversations = (props: ConversationInterface) => {
513
517
  if (!conver) return;
514
518
  let lastMessageId = conver.getLastMessage().getId();
515
519
  if (lastMessageId == newMessage.getId()) {
520
+ // Preserve the real-time user status from the existing conversation.
521
+ // The server-returned conversation may have stale user status/lastActiveAt.
522
+ const existingWith = conver.getConversationWith();
523
+ const newWith = conversation.getConversationWith();
524
+ if (existingWith instanceof CometChat.User && newWith instanceof CometChat.User) {
525
+ if (existingWith.getStatus() === "online" && newWith.getStatus() !== "online") {
526
+ newWith.setStatus("online");
527
+ const existingLastActive = existingWith.getLastActiveAt();
528
+ if (existingLastActive) {
529
+ newWith.setLastActiveAt(existingLastActive);
530
+ }
531
+ }
532
+ }
533
+ // Preserve receipt status from the existing conversation if the server-returned
534
+ // conversation has stale receipt info (due to async timing)
535
+ const existingLastMsg = conver.getLastMessage();
536
+ const newLastMsg = conversation.getLastMessage();
537
+ if (existingLastMsg && newLastMsg && existingLastMsg.getId() === newLastMsg.getId()) {
538
+ if (existingLastMsg.getReadAt?.() && !newLastMsg.getReadAt?.()) {
539
+ newLastMsg.setReadAt(existingLastMsg.getReadAt());
540
+ }
541
+ if (existingLastMsg.getDeliveredAt?.() && !newLastMsg.getDeliveredAt?.()) {
542
+ newLastMsg.setDeliveredAt(existingLastMsg.getDeliveredAt());
543
+ }
544
+ }
516
545
  conversationListRef.current!.updateList(CommonUtils.clone(conversation));
517
546
  }
518
547
  }
@@ -593,6 +622,29 @@ export const CometChatConversations = (props: ConversationInterface) => {
593
622
  .catch((err) => onError && onError(err));
594
623
  return;
595
624
  }
625
+ // Preserve receipt status if the existing last message is the same message
626
+ // (receipts may have arrived while this async operation was in flight)
627
+ const existingLastMessage = oldConversation.getLastMessage();
628
+ if (existingLastMessage && existingLastMessage.getId() === newMessage.getId()) {
629
+ if (existingLastMessage.getReadAt?.() && !newMessage.getReadAt?.()) {
630
+ newMessage.setReadAt(existingLastMessage.getReadAt());
631
+ }
632
+ if (existingLastMessage.getDeliveredAt?.() && !newMessage.getDeliveredAt?.()) {
633
+ newMessage.setDeliveredAt(existingLastMessage.getDeliveredAt());
634
+ }
635
+ }
636
+ // Also check if a receipt arrived BEFORE this message was set as lastMessage
637
+ // (race condition: receipt fires before updateLastMessage completes)
638
+ const newMsgId = String(newMessage.getId?.() ?? "");
639
+ const bufferedReceipt = pendingReceiptsMap.current.get(newMsgId);
640
+ if (bufferedReceipt) {
641
+ if (bufferedReceipt.readAt && !newMessage.getReadAt?.()) {
642
+ newMessage.setReadAt(bufferedReceipt.readAt);
643
+ }
644
+ if (bufferedReceipt.deliveredAt && !newMessage.getDeliveredAt?.()) {
645
+ newMessage.setDeliveredAt(bufferedReceipt.deliveredAt);
646
+ }
647
+ }
596
648
  // Update last message and unread count.
597
649
  oldConversation.setLastMessage(newMessage);
598
650
  if (newMessage.getSender().getUid() != loggedInUser.current?.getUid())
@@ -641,6 +693,17 @@ export const CometChatConversations = (props: ConversationInterface) => {
641
693
  * @param receipt - The message receipt.
642
694
  */
643
695
  const updateMessageReceipt = (receipt: CometChat.MessageReceipt) => {
696
+ const receiptMessageId = typeof (receipt as any).getMessageId === 'function' ? String((receipt as any).getMessageId()) : String((receipt as any)["messageId"] ?? "");
697
+
698
+ // Always buffer the receipt by messageId — this handles race conditions where
699
+ // the receipt arrives before updateLastMessage has set the message as lastMessage
700
+ if (receiptMessageId) {
701
+ const existing = pendingReceiptsMap.current.get(receiptMessageId) || {};
702
+ if (receipt.getReadAt()) existing.readAt = receipt.getReadAt();
703
+ if (receipt.getDeliveredAt()) existing.deliveredAt = receipt.getDeliveredAt();
704
+ pendingReceiptsMap.current.set(receiptMessageId, existing);
705
+ }
706
+
644
707
  const conv: CometChat.Conversation | boolean =
645
708
  receipt?.getReceiverType() === ReceiverTypeConstants.user
646
709
  ? (conversationListRef.current?.getListItem(
@@ -659,25 +722,44 @@ export const CometChatConversations = (props: ConversationInterface) => {
659
722
 
660
723
  if (
661
724
  conv &&
662
- conv.getConversationType() == ConversationTypeConstants.group &&
663
- conv.getLastMessage().getSender().getUid() !== loggedInUser.current!.getUid()
725
+ (conv as CometChat.Conversation).getConversationType() == ConversationTypeConstants.group &&
726
+ (conv as CometChat.Conversation).getLastMessage().getSender().getUid() !== loggedInUser.current!.getUid()
664
727
  ) {
665
728
  return;
666
729
  }
667
730
 
668
- if (
669
- conv &&
670
- conv?.getLastMessage &&
671
- (String(typeof conv.getLastMessage().getId === 'function' ? conv.getLastMessage().getId() : conv.getLastMessage().id) === String(receipt.getMessageId()))
672
- ) {
673
- let newConversation = CommonUtils.clone(conv);
674
- if (receipt.getReadAt()) {
675
- newConversation.getLastMessage().setReadAt(receipt.getReadAt());
731
+ if (conv && (conv as CometChat.Conversation)?.getLastMessage) {
732
+ let newConversation = CommonUtils.clone(conv as CometChat.Conversation);
733
+ const lastMessage = newConversation.getLastMessage();
734
+
735
+ // Only update if the last message was sent by the logged-in user (receipts are for outgoing messages)
736
+ if (lastMessage?.getSender?.()?.getUid?.() !== loggedInUser.current?.getUid()) {
737
+ return;
676
738
  }
677
- if (receipt.getDeliveredAt()) {
678
- newConversation.getLastMessage().setDeliveredAt(receipt.getDeliveredAt());
739
+
740
+ // Apply any buffered receipt for this specific message
741
+ const lastMsgId = String(lastMessage?.getId?.() ?? "");
742
+ const pending = pendingReceiptsMap.current.get(lastMsgId);
743
+
744
+ let updated = false;
745
+
746
+ // Apply read status — never downgrade (if already read, skip)
747
+ const readAtToApply = pending?.readAt || (receipt.getReadAt() && String(receiptMessageId) === lastMsgId ? receipt.getReadAt() : undefined);
748
+ if (readAtToApply && !lastMessage.getReadAt?.()) {
749
+ lastMessage.setReadAt(readAtToApply);
750
+ updated = true;
751
+ }
752
+
753
+ // Apply delivered status — never downgrade (if already read or delivered, skip delivered)
754
+ const deliveredAtToApply = pending?.deliveredAt || (receipt.getDeliveredAt() && String(receiptMessageId) === lastMsgId ? receipt.getDeliveredAt() : undefined);
755
+ if (deliveredAtToApply && !lastMessage.getDeliveredAt?.() && !lastMessage.getReadAt?.()) {
756
+ lastMessage.setDeliveredAt(deliveredAtToApply);
757
+ updated = true;
758
+ }
759
+
760
+ if (updated) {
761
+ conversationListRef.current?.updateList(newConversation);
679
762
  }
680
- conversationListRef.current?.updateList(newConversation);
681
763
  }
682
764
  };
683
765
 
@@ -1156,7 +1238,11 @@ export const CometChatConversations = (props: ConversationInterface) => {
1156
1238
  * @returns The updated conversation.
1157
1239
  */
1158
1240
  const updateUnreadMessageCount = (conversation: CometChat.Conversation) => {
1159
- const oldConversation: CometChat.Conversation = conversationListRef.current!.getListItem(
1241
+ if (!conversationListRef.current) {
1242
+ conversation.setUnreadMessageCount(1);
1243
+ return conversation;
1244
+ }
1245
+ const oldConversation: CometChat.Conversation = conversationListRef.current.getListItem(
1160
1246
  conversation["conversationId"]
1161
1247
  ) as unknown as CometChat.Conversation;
1162
1248
  if (oldConversation == undefined) {
@@ -1201,7 +1287,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1201
1287
  }
1202
1288
  conversation = updateUnreadMessageCount(conversation);
1203
1289
  conversation.setLastMessage(call);
1204
- conversationListRef.current!.updateList(conversation);
1290
+ conversationListRef.current?.updateList(conversation);
1205
1291
  })
1206
1292
  .catch((e) => {
1207
1293
  onError && onError(e);
@@ -1215,7 +1301,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1215
1301
  }
1216
1302
  conversation = updateUnreadMessageCount(conversation);
1217
1303
  conversation.setLastMessage(call);
1218
- conversationListRef.current!.updateList(conversation);
1304
+ conversationListRef.current?.updateList(conversation);
1219
1305
  })
1220
1306
  .catch((e) => {
1221
1307
  onError && onError(e);
@@ -1229,7 +1315,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1229
1315
  }
1230
1316
  conversation = updateUnreadMessageCount(conversation);
1231
1317
  conversation.setLastMessage(call);
1232
- conversationListRef.current!.updateList(conversation);
1318
+ conversationListRef.current?.updateList(conversation);
1233
1319
  })
1234
1320
  .catch((e) => {
1235
1321
  onError && onError(e);
@@ -1243,7 +1329,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1243
1329
  }
1244
1330
  conversation = updateUnreadMessageCount(conversation);
1245
1331
  conversation.setLastMessage(call);
1246
- conversationListRef.current!.updateList(conversation);
1332
+ conversationListRef.current?.updateList(conversation);
1247
1333
  })
1248
1334
  .catch((e) => {
1249
1335
  onError && onError(e);
@@ -1434,6 +1520,9 @@ export const CometChatConversations = (props: ConversationInterface) => {
1434
1520
  messageEventHandler(customInteractiveMessage);
1435
1521
  !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1436
1522
  },
1523
+ onMessageModerated: (moderatedMessage: CometChat.BaseMessage) => {
1524
+ checkAndUpdateLastMessage(moderatedMessage);
1525
+ },
1437
1526
  });
1438
1527
  // Listen for additional group events.
1439
1528
  CometChatUIEventHandler.addGroupListener(groupListenerId, {
@@ -1114,7 +1114,13 @@ export const CometChatMessageList = memo(
1114
1114
  // as the user might want to keep messages unread for reference.
1115
1115
  if (messagesList.length === 0 && !navigatedFromSearch) {
1116
1116
  //marking most recent unread message as read
1117
- if (user) {
1117
+ // Use markAsRead on the latest message instead of markConversationAsRead
1118
+ // to avoid marking thread replies as read when user only opens the main chat.
1119
+ if (!parentMessageId && lastMessage) {
1120
+ CometChat.markAsRead(lastMessage).catch((e: any) => {
1121
+ console.log("Error marking message as read", e);
1122
+ });
1123
+ } else if (user) {
1118
1124
  CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
1119
1125
  console.log("Error marking user conversation as read", e);
1120
1126
  });
@@ -1146,7 +1152,8 @@ export const CometChatMessageList = memo(
1146
1152
  CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageRead, {
1147
1153
  message,
1148
1154
  });
1149
- } else break;
1155
+ }
1156
+ else break;
1150
1157
  }
1151
1158
  }
1152
1159
  previousMessagesFetched = previousMessagesFetched.map(
@@ -1304,7 +1311,13 @@ export const CometChatMessageList = memo(
1304
1311
  if (startFromUnreadMessages && isInitialLoad && !navigatedFromSearch && !goToMessageId) {
1305
1312
  shouldSuppressHighlightRef.current = true;
1306
1313
  //marking most recent unread message as read
1307
- if (user) {
1314
+ // Use markAsRead on the latest message instead of markConversationAsRead
1315
+ // to avoid marking thread replies as read when user only opens the main chat.
1316
+ if (!parentMessageId && uniqueMessages[0]) {
1317
+ CometChat.markAsRead(uniqueMessages[0]).catch((e: any) => {
1318
+ console.log("Error marking message as read", e);
1319
+ });
1320
+ } else if (user) {
1308
1321
  CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
1309
1322
  console.log("Error marking user conversation as read", e);
1310
1323
  });
@@ -4444,7 +4457,13 @@ export const CometChatMessageList = memo(
4444
4457
  );
4445
4458
 
4446
4459
  if (indicatorItem) {
4447
- if (user) {
4460
+ // Use markAsRead on the indicator message instead of markConversationAsRead
4461
+ // to avoid marking thread replies as read when user only views the main chat.
4462
+ if (!parentMessageId && indicatorItem.item) {
4463
+ CometChat.markAsRead(indicatorItem.item).catch((e: any) => {
4464
+ console.log("Error marking message as read", e);
4465
+ });
4466
+ } else if (user) {
4448
4467
  CometChat.markConversationAsRead(user.getUid(), CometChat.RECEIVER_TYPE.USER).catch((e) => {
4449
4468
  console.log("Error marking user conversation as read", e);
4450
4469
  });
@@ -4456,7 +4475,7 @@ export const CometChatMessageList = memo(
4456
4475
  setUnreadCount(0);
4457
4476
  }
4458
4477
  }
4459
- }, [navigatedFromSearch, newMessageIndicatorId, unreadCount, user, group, hasManuallyMarkedUnread]);
4478
+ }, [navigatedFromSearch, newMessageIndicatorId, unreadCount, user, group, hasManuallyMarkedUnread, parentMessageId]);
4460
4479
 
4461
4480
 
4462
4481