@cometchat/chat-uikit-react-native 5.5.3 → 5.6.0

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 (100) hide show
  1. package/android/build.gradle +5 -0
  2. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  3. package/android/src/main/java/com/reactnativecometchatuikit/RichTextEditorView.kt +47 -4
  4. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  5. package/android/src/main/java/com/reactnativecometchatuikit/SoundPlayer.java +209 -119
  6. package/ios/CCLocalFileGuard.h +19 -0
  7. package/ios/CCLocalFileGuard.m +34 -0
  8. package/ios/FileManager.m +70 -6
  9. package/ios/RichTextEditorView.swift +96 -1
  10. package/ios/SoundPlayer.m +152 -6
  11. package/ios/VideoManager.m +1 -1
  12. package/package.json +18 -3
  13. package/react-native-cometchat-ui-kit.podspec +1 -1
  14. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +167 -79
  15. package/src/CometChatConversations/CometChatConversations.tsx +240 -117
  16. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
  17. package/src/CometChatGroups/CometChatGroups.tsx +61 -52
  18. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +173 -85
  19. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
  20. package/src/CometChatMessageHeader/listners.ts +76 -56
  21. package/src/CometChatMessageList/CometChatMessageList.tsx +1423 -205
  22. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
  23. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
  24. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
  25. package/src/CometChatSearch/CometChatSearch.tsx +353 -101
  26. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
  27. package/src/CometChatUsers/CometChatUsers.tsx +2 -0
  28. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
  29. package/src/extensions/LinkPreview/LinkPreviewBubble.tsx +48 -47
  30. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
  31. package/src/index.ts +6 -0
  32. package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
  33. package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
  34. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  35. package/src/shared/events/index.ts +4 -0
  36. package/src/shared/events/offline.ts +28 -0
  37. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
  38. package/src/shared/framework/MessageDataSource.tsx +34 -14
  39. package/src/shared/index.ts +2 -0
  40. package/src/shared/offline/OfflineHub.ts +651 -0
  41. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  42. package/src/shared/offline/OfflineViews.tsx +218 -0
  43. package/src/shared/offline/conversationPins.ts +137 -0
  44. package/src/shared/offline/conversations.ts +325 -0
  45. package/src/shared/offline/frameProbe.ts +24 -0
  46. package/src/shared/offline/gate.ts +94 -0
  47. package/src/shared/offline/groupActions.ts +81 -0
  48. package/src/shared/offline/identity.ts +162 -0
  49. package/src/shared/offline/index.ts +76 -0
  50. package/src/shared/offline/media.ts +247 -0
  51. package/src/shared/offline/notices.ts +90 -0
  52. package/src/shared/offline/reconcile.ts +296 -0
  53. package/src/shared/offline/searchOutcome.ts +62 -0
  54. package/src/shared/offline/send.ts +430 -0
  55. package/src/shared/offline/stateContract.ts +85 -0
  56. package/src/shared/offline/threadReplies.ts +125 -0
  57. package/src/shared/offline/twoPhase.ts +372 -0
  58. package/src/shared/offline/unsentActions.ts +168 -0
  59. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  60. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  61. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  62. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  63. package/src/shared/offline/usePresenceHidden.ts +33 -0
  64. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
  72. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
  73. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
  74. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
  75. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
  76. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
  77. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
  78. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
  79. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
  80. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
  81. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
  82. package/src/shared/services/UploadQueueService.ts +106 -1
  83. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  84. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  85. package/src/shared/utils/catchUpCursor.ts +36 -0
  86. package/src/shared/utils/failedMessageRetry.ts +73 -0
  87. package/src/shared/utils/messageIdentity.ts +38 -0
  88. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
  89. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
  90. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  91. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
  92. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
  93. package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
  94. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
  95. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
  96. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
  97. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  98. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
  99. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  100. package/src/theme/type.ts +17 -0
@@ -68,6 +68,21 @@ import { useTheme } from "../theme";
68
68
  import { Skeleton } from "./Skeleton";
69
69
  import { ConversationStyle, Style } from "./style";
70
70
  import MessageReceiptUtils from "../shared/utils/MessageReceiptUtils";
71
+ import { OfflineHub } from "../shared/offline/OfflineHub";
72
+ import {
73
+ failStrandedPreviews,
74
+ forgetStrandedPreview,
75
+ isFilteredConversationRequest,
76
+ refreshPreviewAfterDiscard,
77
+ routeIncomingMessage,
78
+ strandedPreviewsToRestore,
79
+ } from "../shared/offline/conversations";
80
+ import { dispatchSweptGroupAction } from "../shared/offline/groupActions";
81
+ import { resolveTwoPhase } from "../shared/offline/twoPhase";
82
+ import { isOfflineOn, offlineSdk } from "../shared/offline/gate";
83
+ import { conversationRowTestID } from "../shared/offline/stateContract";
84
+ import { onRemotePinEvent } from "../shared/offline/conversationPins";
85
+ import { OfflineNoticeView, useOfflineNotice } from "../shared/offline/OfflineViews";
71
86
  import { deepMerge } from "../shared/helper/helperFunctions";
72
87
  import Delete from "../shared/icons/components/delete";
73
88
  import { DeepPartial } from "../shared/helper/types";
@@ -185,6 +200,11 @@ export interface ConversationInterface {
185
200
  * Hide error view.
186
201
  */
187
202
  hideError?: boolean;
203
+ /**
204
+ * Offline support: hide the one-line notices (cache rebuilt, unsent messages lost). Has no
205
+ * effect with offline off. Default `false`.
206
+ */
207
+ hideOfflineNotices?: boolean;
188
208
  /**
189
209
  * Callback for when a conversation item is pressed.
190
210
  */
@@ -299,6 +319,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
299
319
  SubtitleView,
300
320
  TrailingView,
301
321
  hideError = false,
322
+ hideOfflineNotices = false,
302
323
  onItemPress,
303
324
  onItemLongPress,
304
325
  onError,
@@ -766,7 +787,11 @@ export const CometChatConversations = (props: ConversationInterface) => {
766
787
  * Updates the conversation with a new message and moves it to the top of the list.
767
788
  * @param newMessage - The new message to update.
768
789
  */
769
- const updateLastMessage = (newMessage: CometChat.BaseMessage) => {
790
+ /**
791
+ * @param countUnread false for a message the SDK's catch-up sweep delivered (offline ON): the
792
+ * synced conversation counts already include it (UIK-SYNC-02).
793
+ */
794
+ const updateLastMessage = (newMessage: CometChat.BaseMessage, countUnread: boolean = true) => {
770
795
  CometChat.CometChatHelper.getConversationFromMessage(newMessage)
771
796
  .then((conversation) => {
772
797
  if (newMessage.getCategory() === MessageCategoryConstants.interactive) {
@@ -780,6 +805,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
780
805
  CometChat.CometChatHelper.getConversationFromMessage(newMessage)
781
806
  .then((newConversation) => {
782
807
  if (
808
+ countUnread &&
783
809
  newConversation?.getLastMessage().getSender().getUid() !==
784
810
  loggedInUser.current?.getUid()
785
811
  )
@@ -814,7 +840,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
814
840
  }
815
841
  // Update last message and unread count.
816
842
  oldConversation.setLastMessage(newMessage);
817
- if (newMessage.getSender().getUid() != loggedInUser.current?.getUid())
843
+ if (countUnread && newMessage.getSender().getUid() != loggedInUser.current?.getUid())
818
844
  oldConversation.setUnreadMessageCount(oldConversation.getUnreadMessageCount() + 1);
819
845
  placeConversation(CommonUtils.clone(oldConversation));
820
846
  })
@@ -1498,6 +1524,108 @@ export const CometChatConversations = (props: ConversationInterface) => {
1498
1524
  return oldConversation;
1499
1525
  };
1500
1526
 
1527
+ // Offline (ON path): an own pending send moves its chat to the top with that preview
1528
+ // (BEH-CONV-01); a failed one keeps the preview with its failed mark. Private hub channel,
1529
+ // inert while offline is off.
1530
+ const offlineSendStateRef = React.useRef<(event: any) => void>(() => {});
1531
+ // Kill switch (UIK-LIFE-03): previews the SDK dropped when offline turned off.
1532
+ const strandedPreviewsRef = React.useRef(new Map<string, any>());
1533
+ const usedOfflineRef = React.useRef(false);
1534
+ const failStrandedPreviewsRef = React.useRef<() => void>(() => {});
1535
+ failStrandedPreviewsRef.current = () => {
1536
+ const hub = OfflineHub.getInstance();
1537
+ const rows = conversationListRef.current?.getAllListItems?.() ?? [];
1538
+ const count = failStrandedPreviews(rows, strandedPreviewsRef.current, hub);
1539
+ if (count > 0) hub.notify({ kind: "messages_not_sent", count, previewsOnly: true });
1540
+ };
1541
+ offlineSendStateRef.current = (event: any) => {
1542
+ if (event.gen !== OfflineHub.getInstance().gen) return;
1543
+ if (event.state === "sent" || event.state === "discarded") forgetStrandedPreview(strandedPreviewsRef.current, event.message);
1544
+ if (event.state === "discarded") {
1545
+ // The SDK moved this chat's preview back (or removed a local-only chat): show its answer.
1546
+ void refreshPreviewAfterDiscard(event.message, {
1547
+ rows: () => conversationListRef.current?.getAllListItems?.() ?? [],
1548
+ fetchConversation: (withId: string, type: string) =>
1549
+ resolveTwoPhase<CometChat.Conversation>(
1550
+ (listener) => offlineSdk().getConversation(withId, type, listener),
1551
+ "Conversation"
1552
+ ).catch((e: any) => {
1553
+ if (e?.code === "ERR_CONVERSATION_NOT_ACCESSIBLE" || e?.code === "ERR_CONVERSATION_NOT_FOUND") return null;
1554
+ throw e;
1555
+ }),
1556
+ update: (row: any) => conversationListRef.current?.updateList(CommonUtils.clone(row)),
1557
+ remove: (id: string) => conversationListRef.current?.removeItemFromList(id),
1558
+ });
1559
+ return;
1560
+ }
1561
+ if (event.state !== "sending" && event.state !== "failed") return;
1562
+ const message = event.message;
1563
+ if (!message || message.getParentMessageId?.()) return;
1564
+ if (!shouldUpdateLastMessageAndUnreadCount(message)) return;
1565
+ updateLastMessage(message, false);
1566
+ };
1567
+ React.useEffect(() => {
1568
+ const hub = OfflineHub.getInstance();
1569
+ usedOfflineRef.current = isOfflineOn();
1570
+ const subscriptions = [
1571
+ hub.sendState$.subscribe((e) => {
1572
+ usedOfflineRef.current = true;
1573
+ offlineSendStateRef.current(e);
1574
+ }),
1575
+ hub.connected$.subscribe(() => {
1576
+ if (isOfflineOn()) {
1577
+ usedOfflineRef.current = true;
1578
+ return;
1579
+ }
1580
+ // Offline was on and is off now. A list that never used offline does nothing at all.
1581
+ if (!usedOfflineRef.current) return;
1582
+ // After this tick's other connection listeners: an open chat counts its own rows first.
1583
+ setTimeout(() => failStrandedPreviewsRef.current(), 0);
1584
+ }),
1585
+ hub.session$.subscribe(() => strandedPreviewsRef.current.clear()),
1586
+ ];
1587
+ return () => subscriptions.forEach((s) => s.unsubscribe());
1588
+ }, []);
1589
+ // Offline (ON path): a pin or unpin made on another device or by an admin moves the row
1590
+ // (UIK-CONV-01). The gate is read per event; with offline off the event is ignored, as the
1591
+ // release before it did. Own pins keep updating from the pin call's onSuccess.
1592
+ const remotePinRef = React.useRef<(event: any) => void>(() => {});
1593
+ remotePinRef.current = (event: any) => {
1594
+ onRemotePinEvent(event, {
1595
+ rows: () => conversationListRef.current?.getAllListItems?.() ?? [],
1596
+ place: placeConversation,
1597
+ clone: (row: any) => CommonUtils.clone(row),
1598
+ loggedInUid: () => loggedInUser.current?.getUid?.(),
1599
+ filtered: () => !!searchText || isFilteredConversationRequest(conversationsRequestBuilder),
1600
+ fetchConversation: (withId: string, type: string) => CometChat.getConversation(withId, type),
1601
+ });
1602
+ };
1603
+ React.useEffect(() => {
1604
+ const subscription = OfflineHub.getInstance().conversationPin$.subscribe((e) => remotePinRef.current(e));
1605
+ return () => subscription.unsubscribe();
1606
+ }, []);
1607
+ const { notice: offlineNotice, dismiss: dismissOfflineNotice } = useOfflineNotice(
1608
+ !hideOfflineNotices,
1609
+ // Session-wide notices (cache rebuilt, sends lost) belong on the chat list.
1610
+ (n) => !n.conversationId && !n.message
1611
+ );
1612
+
1613
+ /**
1614
+ * Every incoming message, whatever its category: a swept (SYNC, offline ON) message updates
1615
+ * the preview only (no sound, no unread +1, no receipt; UIK-SYNC-02); a live one runs today's
1616
+ * handling.
1617
+ */
1618
+ const onIncomingMessage = (message: any) => {
1619
+ routeIncomingMessage(message, {
1620
+ accepts: shouldUpdateLastMessageAndUnreadCount,
1621
+ previewOnly: (m: any) => updateLastMessage(m, false),
1622
+ live: (m: any) => {
1623
+ messageEventHandler(m);
1624
+ !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1625
+ },
1626
+ });
1627
+ };
1628
+
1501
1629
  // Set up event listeners for user, call, group and message events.
1502
1630
  React.useEffect(() => {
1503
1631
  // Get logged in user.
@@ -1584,83 +1712,88 @@ export const CometChatConversations = (props: ConversationInterface) => {
1584
1712
  );
1585
1713
 
1586
1714
  // Listen for group events.
1587
- CometChat.addGroupListener(
1588
- groupListenerId,
1589
- new CometChat.GroupListener({
1590
- onGroupMemberScopeChanged: (
1591
- message: CometChat.Action,
1592
- changedUser: CometChat.GroupMember,
1593
- newScope: CometChat.GroupMemberScope,
1594
- oldScope: CometChat.GroupMemberScope,
1595
- changedGroup: CometChat.Group
1596
- ) => {
1597
- groupHandler(message, {
1598
- action: "scopeChange",
1599
- actionOn: changedUser,
1600
- newScope: newScope,
1601
- oldScope: oldScope,
1602
- group: changedGroup,
1603
- });
1604
- },
1605
- onGroupMemberKicked: (
1606
- message: CometChat.Action,
1607
- kickedUser: CometChat.User,
1608
- kickedBy: CometChat.User,
1609
- kickedFrom: CometChat.Group
1610
- ) => {
1611
- groupHandler(message, {
1612
- action: "kicked",
1613
- actionOn: kickedUser,
1614
- actionBy: kickedBy,
1615
- group: kickedFrom,
1616
- });
1617
- },
1618
- onGroupMemberLeft: (
1619
- message: CometChat.Action,
1620
- leavingUser: CometChat.User,
1621
- group: CometChat.Group
1622
- ) => {
1623
- groupHandler(message, { action: "left", actionOn: leavingUser, group });
1624
- },
1625
- onGroupMemberUnbanned: (message: CometChat.Action) => {
1626
- groupHandler(message);
1627
- },
1628
- onGroupMemberBanned: (
1629
- message: CometChat.Action,
1630
- bannedUser: CometChat.User,
1631
- bannedBy: CometChat.User,
1632
- bannedFrom: CometChat.Group
1633
- ) => {
1715
+ const groupListenerHandlers = {
1716
+ onGroupMemberScopeChanged: (
1717
+ message: CometChat.Action,
1718
+ changedUser: CometChat.GroupMember,
1719
+ newScope: CometChat.GroupMemberScope,
1720
+ oldScope: CometChat.GroupMemberScope,
1721
+ changedGroup: CometChat.Group
1722
+ ) => {
1723
+ groupHandler(message, {
1724
+ action: "scopeChange",
1725
+ actionOn: changedUser,
1726
+ newScope: newScope,
1727
+ oldScope: oldScope,
1728
+ group: changedGroup,
1729
+ });
1730
+ },
1731
+ onGroupMemberKicked: (
1732
+ message: CometChat.Action,
1733
+ kickedUser: CometChat.User,
1734
+ kickedBy: CometChat.User,
1735
+ kickedFrom: CometChat.Group
1736
+ ) => {
1737
+ groupHandler(message, {
1738
+ action: "kicked",
1739
+ actionOn: kickedUser,
1740
+ actionBy: kickedBy,
1741
+ group: kickedFrom,
1742
+ });
1743
+ },
1744
+ onGroupMemberLeft: (
1745
+ message: CometChat.Action,
1746
+ leavingUser: CometChat.User,
1747
+ group: CometChat.Group
1748
+ ) => {
1749
+ groupHandler(message, { action: "left", actionOn: leavingUser, group });
1750
+ },
1751
+ onGroupMemberUnbanned: (message: CometChat.Action) => {
1752
+ groupHandler(message);
1753
+ },
1754
+ onGroupMemberBanned: (
1755
+ message: CometChat.Action,
1756
+ bannedUser: CometChat.User,
1757
+ bannedBy: CometChat.User,
1758
+ bannedFrom: CometChat.Group
1759
+ ) => {
1760
+ groupHandler(message, {
1761
+ action: "banned",
1762
+ actionOn: bannedUser,
1763
+ actionBy: bannedBy,
1764
+ group: bannedFrom,
1765
+ });
1766
+ },
1767
+ onMemberAddedToGroup: (
1768
+ message: CometChat.Action,
1769
+ userAdded: CometChat.User,
1770
+ userAddedBy: CometChat.User,
1771
+ userAddedIn: CometChat.Group
1772
+ ) => {
1773
+ if (onMemberAddedToGroupDebounceTimer.current) {
1774
+ clearTimeout(onMemberAddedToGroupDebounceTimer.current);
1775
+ }
1776
+ onMemberAddedToGroupDebounceTimer.current = setTimeout(() => {
1634
1777
  groupHandler(message, {
1635
- action: "banned",
1636
- actionOn: bannedUser,
1637
- actionBy: bannedBy,
1638
- group: bannedFrom,
1778
+ action: "joined",
1779
+ actionOn: userAdded,
1780
+ actionBy: userAddedBy,
1781
+ group: userAddedIn,
1639
1782
  });
1640
- },
1641
- onMemberAddedToGroup: (
1642
- message: CometChat.Action,
1643
- userAdded: CometChat.User,
1644
- userAddedBy: CometChat.User,
1645
- userAddedIn: CometChat.Group
1646
- ) => {
1647
- if (onMemberAddedToGroupDebounceTimer.current) {
1648
- clearTimeout(onMemberAddedToGroupDebounceTimer.current);
1649
- }
1650
- onMemberAddedToGroupDebounceTimer.current = setTimeout(() => {
1651
- groupHandler(message, {
1652
- action: "joined",
1653
- actionOn: userAdded,
1654
- actionBy: userAddedBy,
1655
- group: userAddedIn,
1656
- });
1657
- }, 50);
1658
- },
1659
- onGroupMemberJoined: (message: CometChat.Action) => {
1660
- groupHandler(message);
1661
- },
1662
- })
1663
- );
1783
+ }, 50);
1784
+ },
1785
+ onGroupMemberJoined: (message: CometChat.Action) => {
1786
+ groupHandler(message);
1787
+ },
1788
+ };
1789
+ CometChat.addGroupListener(groupListenerId, new CometChat.GroupListener(groupListenerHandlers));
1790
+ // Offline (ON path): a group action the catch-up sweep delivered while the device was offline
1791
+ // (me kicked, banned or removed) fires no GroupListener callback; run the same handlers for it,
1792
+ // so that conversation leaves the list as it would have live (UIT-SYNC-13). Inert with offline off.
1793
+ const sweptGroupActions = OfflineHub.getInstance().groupActionSwept$.subscribe((event) => {
1794
+ if (event.gen !== OfflineHub.getInstance().gen) return;
1795
+ dispatchSweptGroupAction(event.message, groupListenerHandlers);
1796
+ });
1664
1797
 
1665
1798
  // Listen for conversation deletion events.
1666
1799
  CometChatUIEventHandler.addConversationListener(conversationListenerId, {
@@ -1704,25 +1837,13 @@ export const CometChatConversations = (props: ConversationInterface) => {
1704
1837
  checkAndUpdateLastMessage(message);
1705
1838
  },
1706
1839
  onTextMessageReceived: (textMessage: CometChat.TextMessage) => {
1707
- if (!shouldUpdateLastMessageAndUnreadCount(textMessage)) {
1708
- return;
1709
- }
1710
- messageEventHandler(textMessage);
1711
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1840
+ onIncomingMessage(textMessage);
1712
1841
  },
1713
1842
  onMediaMessageReceived: (mediaMessage: CometChat.MediaMessage) => {
1714
- if (!shouldUpdateLastMessageAndUnreadCount(mediaMessage)) {
1715
- return;
1716
- }
1717
- messageEventHandler(mediaMessage);
1718
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1843
+ onIncomingMessage(mediaMessage);
1719
1844
  },
1720
1845
  onCustomMessageReceived: (customMessage: CometChat.CustomMessage) => {
1721
- if (!shouldUpdateLastMessageAndUnreadCount(customMessage)) {
1722
- return;
1723
- }
1724
- messageEventHandler(customMessage);
1725
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1846
+ onIncomingMessage(customMessage);
1726
1847
  },
1727
1848
  onMessageDeleted: (deletedMessage: CometChat.BaseMessage) => {
1728
1849
  // Skip thread replies — they don't affect conversation unread count
@@ -1751,41 +1872,21 @@ export const CometChatConversations = (props: ConversationInterface) => {
1751
1872
  typingEventHandler(typingIndicator, false);
1752
1873
  },
1753
1874
  onFormMessageReceived: (formMessage: any) => {
1754
- if (!shouldUpdateLastMessageAndUnreadCount(formMessage)) {
1755
- return;
1756
- }
1757
- messageEventHandler(formMessage);
1758
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1875
+ onIncomingMessage(formMessage);
1759
1876
  },
1760
1877
  onCardMessageReceived: (cardMessage: any) => {
1761
- if (!shouldUpdateLastMessageAndUnreadCount(cardMessage)) {
1762
- return;
1763
- }
1764
- messageEventHandler(cardMessage);
1765
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1878
+ onIncomingMessage(cardMessage);
1766
1879
  },
1767
1880
  onSchedulerMessageReceived: (schedulerMessage: any) => {
1768
- if (!shouldUpdateLastMessageAndUnreadCount(schedulerMessage)) {
1769
- return;
1770
- }
1771
- messageEventHandler(schedulerMessage);
1772
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1881
+ onIncomingMessage(schedulerMessage);
1773
1882
  },
1774
1883
  onCustomInteractiveMessageReceived: (customInteractiveMessage: any) => {
1775
- if (!shouldUpdateLastMessageAndUnreadCount(customInteractiveMessage)) {
1776
- return;
1777
- }
1778
- messageEventHandler(customInteractiveMessage);
1779
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1884
+ onIncomingMessage(customInteractiveMessage);
1780
1885
  },
1781
1886
  // Agent (agentic/assistant) reply — update the conversation's last message + unread
1782
1887
  // count in real time, otherwise the subtitle only refreshes after a re-fetch.
1783
1888
  onAIAssistantMessageReceived: (aiAssistantMessage: any) => {
1784
- if (!shouldUpdateLastMessageAndUnreadCount(aiAssistantMessage)) {
1785
- return;
1786
- }
1787
- messageEventHandler(aiAssistantMessage);
1788
- !disableSoundForMessages && CometChatSoundManager.play("incomingMessage");
1889
+ onIncomingMessage(aiAssistantMessage);
1789
1890
  },
1790
1891
  onMessageModerated: (moderatedMessage: CometChat.BaseMessage) => {
1791
1892
  checkAndUpdateLastMessage(moderatedMessage);
@@ -1981,6 +2082,7 @@ export const CometChatConversations = (props: ConversationInterface) => {
1981
2082
  CometChat.removeUserListener(userListenerId);
1982
2083
  CometChat.removeCallListener(callListenerId);
1983
2084
  CometChat.removeGroupListener(groupListenerId);
2085
+ sweptGroupActions.unsubscribe();
1984
2086
  CometChatUIEventHandler.removeMessageListener(messageListenerId);
1985
2087
  CometChatUIEventHandler.removeConversationListener(conversationListenerId);
1986
2088
  CometChatUIEventHandler.removeGroupListener(groupListenerId);
@@ -2123,10 +2225,15 @@ export const CometChatConversations = (props: ConversationInterface) => {
2123
2225
  }
2124
2226
  }}
2125
2227
  listItemKey={"conversationId"}
2228
+ // The id carries the peer's uid/guid: built only with offline support on, so a release build
2229
+ // with it off has rows exactly as before the offline work.
2230
+ itemTestID={isOfflineOn() ? conversationRowTestID : undefined}
2126
2231
  LoadingView={LoadingView ?? (() => <Skeleton style={mergedStyles.skeletonStyle} />)}
2127
2232
  ItemView={ItemView}
2128
2233
  EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
2234
+ customEmptyView={!!EmptyView}
2129
2235
  ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
2236
+ customErrorView={!!ErrorView}
2130
2237
  onBack={onBack}
2131
2238
  hideBackButton={hideBackButton}
2132
2239
  onSelection={onSelection}
@@ -2134,6 +2241,12 @@ export const CometChatConversations = (props: ConversationInterface) => {
2134
2241
  selectionMode={selectionMode}
2135
2242
  hideError={hideError}
2136
2243
  onListFetched={(conversations: CometChat.Conversation[]) => {
2244
+ // Kill switch: a refetch with offline off must not take a failed preview back.
2245
+ if (strandedPreviewsRef.current.size > 0) {
2246
+ strandedPreviewsToRestore(conversations, strandedPreviewsRef.current).forEach((m) =>
2247
+ updateLastMessage(m, false)
2248
+ );
2249
+ }
2137
2250
  if (conversations.length === 0) {
2138
2251
  onEmpty?.();
2139
2252
  } else {
@@ -2253,6 +2366,16 @@ export const CometChatConversations = (props: ConversationInterface) => {
2253
2366
  {/* Without this the useToast hook runs but nothing ever appears — the
2254
2367
  conversation pin/unpin toasts and every error message are invisible. */}
2255
2368
  {ToastElement}
2369
+ {offlineNotice && !hideOfflineNotices ? (
2370
+ <OfflineNoticeView
2371
+ notice={offlineNotice}
2372
+ t={t}
2373
+ onDismiss={dismissOfflineNotice}
2374
+ containerStyle={theme.messageListStyles?.offlineStyles?.noticeStyle?.containerStyle}
2375
+ textStyle={theme.messageListStyles?.offlineStyles?.noticeStyle?.textStyle}
2376
+ actionTextStyle={theme.messageListStyles?.offlineStyles?.noticeStyle?.actionTextStyle}
2377
+ />
2378
+ ) : null}
2256
2379
  </View>
2257
2380
  );
2258
2381
  };
@@ -28,6 +28,7 @@ import {
28
28
  import { CometChatStatusIndicatorInterface } from "../shared/views/CometChatStatusIndicator";
29
29
  import { CometChatTooltipMenu } from "../shared/views/CometChatTooltipMenu";
30
30
  import { ErrorEmptyView } from "../shared/views/ErrorEmptyView/ErrorEmptyView";
31
+ import { OFFLINE_STRING_KEYS } from "../shared/offline/notices";
31
32
  import { useTheme } from "../theme";
32
33
  import { Skeleton } from "./Skeleton";
33
34
  import { GroupMemberStyle } from "./style";
@@ -658,7 +659,10 @@ export const CometChatGroupMembers = (props: CometChatGroupMembersInterface) =>
658
659
  : () => <Skeleton />
659
660
  }
660
661
  EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
662
+ customEmptyView={!!EmptyView}
663
+ connectToLoadKey={OFFLINE_STRING_KEYS.connectToLoadMembers}
661
664
  ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
665
+ customErrorView={!!ErrorView}
662
666
  statusIndicatorType={(user: CometChat.User) =>
663
667
  usersStatusVisibility
664
668
  ? (user?.getStatus() as CometChatStatusIndicatorInterface["type"])
@@ -20,6 +20,8 @@ import { Skeleton } from "./Skeleton";
20
20
  import { Style } from "./style";
21
21
  import { JSX } from "react";
22
22
  import { useCometChatTranslation } from "../shared/resources/CometChatLocalizeNew";
23
+ import { OfflineHub } from "../shared/offline/OfflineHub";
24
+ import { dispatchSweptGroupAction } from "../shared/offline/groupActions";
23
25
 
24
26
  // Unique listener IDs for group events and UI events.
25
27
  const groupListenerId = "grouplist_" + Date.now() + "_" + (++__listenerIdCounter);
@@ -418,58 +420,62 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
418
420
  * Set up group listeners when the component mounts.
419
421
  */
420
422
  useEffect(() => {
421
- CometChat.addGroupListener(
422
- groupListenerId,
423
- new CometChat.GroupListener({
424
- onGroupMemberScopeChanged: (
425
- message: CometChat.Action,
426
- changedUser: CometChat.User,
427
- newScope: CometChat.GroupMemberScope,
428
- oldScope: CometChat.GroupMemberScope,
429
- changedGroup: CometChat.Group
430
- ) => {
431
- handleGroupMemberScopeChange(message, changedUser, newScope, oldScope, changedGroup);
432
- },
433
- onGroupMemberKicked: (
434
- message: CometChat.Action,
435
- kickedUser: CometChat.User,
436
- kickedBy: CometChat.User,
437
- kickedFrom: CometChat.Group
438
- ) => {
439
- handleGroupMemberRemoval(message, kickedUser, kickedBy, kickedFrom);
440
- },
441
- onGroupMemberLeft: (
442
- message: CometChat.Action,
443
- leavingUser: CometChat.User,
444
- group: CometChat.Group
445
- ) => {
446
- handleGroupMemberRemoval(message, leavingUser, null, group);
447
- },
448
- onGroupMemberBanned: (
449
- message: CometChat.Action,
450
- bannedUser: CometChat.User,
451
- bannedBy: CometChat.User,
452
- bannedFrom: CometChat.Group
453
- ) => {
454
- handleGroupMemberBan(message, bannedUser, bannedBy, bannedFrom);
455
- },
456
- onMemberAddedToGroup: (
457
- message: CometChat.Action,
458
- userAdded: CometChat.User,
459
- userAddedBy: CometChat.User,
460
- userAddedIn: CometChat.Group
461
- ) => {
462
- handleGroupMemberAddition(message, userAdded, userAddedBy, userAddedIn);
463
- },
464
- onGroupMemberJoined: (
465
- message: CometChat.Action,
466
- joinedUser: CometChat.User,
467
- joinedGroup: CometChat.Group
468
- ) => {
469
- handleGroupMemberAddition(message, joinedUser, null, joinedGroup);
470
- },
471
- })
472
- );
423
+ const groupListenerHandlers = {
424
+ onGroupMemberScopeChanged: (
425
+ message: CometChat.Action,
426
+ changedUser: CometChat.User,
427
+ newScope: CometChat.GroupMemberScope,
428
+ oldScope: CometChat.GroupMemberScope,
429
+ changedGroup: CometChat.Group
430
+ ) => {
431
+ handleGroupMemberScopeChange(message, changedUser, newScope, oldScope, changedGroup);
432
+ },
433
+ onGroupMemberKicked: (
434
+ message: CometChat.Action,
435
+ kickedUser: CometChat.User,
436
+ kickedBy: CometChat.User,
437
+ kickedFrom: CometChat.Group
438
+ ) => {
439
+ handleGroupMemberRemoval(message, kickedUser, kickedBy, kickedFrom);
440
+ },
441
+ onGroupMemberLeft: (
442
+ message: CometChat.Action,
443
+ leavingUser: CometChat.User,
444
+ group: CometChat.Group
445
+ ) => {
446
+ handleGroupMemberRemoval(message, leavingUser, null, group);
447
+ },
448
+ onGroupMemberBanned: (
449
+ message: CometChat.Action,
450
+ bannedUser: CometChat.User,
451
+ bannedBy: CometChat.User,
452
+ bannedFrom: CometChat.Group
453
+ ) => {
454
+ handleGroupMemberBan(message, bannedUser, bannedBy, bannedFrom);
455
+ },
456
+ onMemberAddedToGroup: (
457
+ message: CometChat.Action,
458
+ userAdded: CometChat.User,
459
+ userAddedBy: CometChat.User,
460
+ userAddedIn: CometChat.Group
461
+ ) => {
462
+ handleGroupMemberAddition(message, userAdded, userAddedBy, userAddedIn);
463
+ },
464
+ onGroupMemberJoined: (
465
+ message: CometChat.Action,
466
+ joinedUser: CometChat.User,
467
+ joinedGroup: CometChat.Group
468
+ ) => {
469
+ handleGroupMemberAddition(message, joinedUser, null, joinedGroup);
470
+ },
471
+ };
472
+ CometChat.addGroupListener(groupListenerId, new CometChat.GroupListener(groupListenerHandlers));
473
+ // Offline (ON path): a group action the catch-up sweep delivered fires no GroupListener
474
+ // callback; run the same handlers for it (UIT-SYNC-13). Inert with offline off.
475
+ const sweptGroupActions = OfflineHub.getInstance().groupActionSwept$.subscribe((event) => {
476
+ if (event.gen !== OfflineHub.getInstance().gen) return;
477
+ dispatchSweptGroupAction(event.message, groupListenerHandlers);
478
+ });
473
479
 
474
480
  CometChatUIEventHandler.addGroupListener(uiEventListener, {
475
481
  ccGroupCreated: ({ group }: { group: CometChat.Group }) => {
@@ -509,6 +515,7 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
509
515
  });
510
516
 
511
517
  return () => {
518
+ sweptGroupActions.unsubscribe();
512
519
  CometChat.removeGroupListener(groupListenerId);
513
520
  CometChatUIEventHandler.removeGroupListener(uiEventListener);
514
521
  };
@@ -567,7 +574,9 @@ export const CometChatGroups = React.forwardRef((props: CometChatGroupsInterface
567
574
  : () => <Skeleton style={mergedStyle.skeletonStyle} />
568
575
  }
569
576
  EmptyView={EmptyView ? EmptyView : () => <EmptyStateView />}
577
+ customEmptyView={!!EmptyView}
570
578
  ErrorView={ErrorView ? ErrorView : () => <ErrorStateView />}
579
+ customErrorView={!!ErrorView}
571
580
  searchPlaceholderText={searchPlaceholderText}
572
581
  ref={groupListRef}
573
582
  listItemKey='guid'