@cometchat/chat-uikit-react-native 5.5.4 → 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 (98) hide show
  1. package/android/src/main/java/com/reactnativecometchatuikit/FileManager.java +78 -3
  2. package/android/src/main/java/com/reactnativecometchatuikit/SafeFileName.java +78 -0
  3. package/ios/CCLocalFileGuard.h +19 -0
  4. package/ios/CCLocalFileGuard.m +34 -0
  5. package/ios/FileManager.m +70 -6
  6. package/ios/VideoManager.m +1 -1
  7. package/package.json +18 -3
  8. package/src/CometChatCompactMessageComposer/CometChatCompactMessageComposer.tsx +124 -55
  9. package/src/CometChatConversations/CometChatConversations.tsx +240 -117
  10. package/src/CometChatGroupMembers/CometChatGroupMembers.tsx +4 -0
  11. package/src/CometChatGroups/CometChatGroups.tsx +61 -52
  12. package/src/CometChatMessageComposer/CometChatMessageComposer.tsx +146 -66
  13. package/src/CometChatMessageHeader/CometChatMessageHeader.tsx +7 -3
  14. package/src/CometChatMessageHeader/listners.ts +76 -56
  15. package/src/CometChatMessageList/CometChatMessageList.tsx +1371 -188
  16. package/src/CometChatNotificationFeed/CometChatNotificationFeed.tsx +71 -7
  17. package/src/CometChatPinnedMessages/CometChatPinnedMessages.tsx +74 -2
  18. package/src/CometChatSavedMessages/CometChatSavedMessages.tsx +69 -4
  19. package/src/CometChatSearch/CometChatSearch.tsx +353 -101
  20. package/src/CometChatThreadHeader/CometChatThreadHeader.tsx +23 -1
  21. package/src/CometChatUsers/CometChatUsers.tsx +2 -0
  22. package/src/calls/CometChatCallButtons/CometChatCallButtons.tsx +19 -0
  23. package/src/extensions/Stickers/StickersExtensionDecorator.tsx +2 -0
  24. package/src/index.ts +6 -0
  25. package/src/shared/CometChatUiKit/CometChatUIKit.ts +85 -2
  26. package/src/shared/CometChatUiKit/UIKitSettings.ts +20 -0
  27. package/src/shared/events/CometChatUIEventHandler/Listener.ts +10 -0
  28. package/src/shared/events/index.ts +4 -0
  29. package/src/shared/events/offline.ts +28 -0
  30. package/src/shared/formatters/CometChatMentionsFormatter/CometChatMentionsFormatter.tsx +5 -3
  31. package/src/shared/framework/MessageDataSource.tsx +34 -14
  32. package/src/shared/index.ts +2 -0
  33. package/src/shared/offline/OfflineHub.ts +651 -0
  34. package/src/shared/offline/OfflineMediaBubble.tsx +49 -0
  35. package/src/shared/offline/OfflineViews.tsx +218 -0
  36. package/src/shared/offline/conversationPins.ts +137 -0
  37. package/src/shared/offline/conversations.ts +325 -0
  38. package/src/shared/offline/frameProbe.ts +24 -0
  39. package/src/shared/offline/gate.ts +94 -0
  40. package/src/shared/offline/groupActions.ts +81 -0
  41. package/src/shared/offline/identity.ts +162 -0
  42. package/src/shared/offline/index.ts +76 -0
  43. package/src/shared/offline/media.ts +247 -0
  44. package/src/shared/offline/notices.ts +90 -0
  45. package/src/shared/offline/reconcile.ts +296 -0
  46. package/src/shared/offline/searchOutcome.ts +62 -0
  47. package/src/shared/offline/send.ts +430 -0
  48. package/src/shared/offline/stateContract.ts +85 -0
  49. package/src/shared/offline/threadReplies.ts +125 -0
  50. package/src/shared/offline/twoPhase.ts +372 -0
  51. package/src/shared/offline/unsentActions.ts +168 -0
  52. package/src/shared/offline/useOfflineMediaUri.ts +87 -0
  53. package/src/shared/offline/useOfflineReconnect.ts +25 -0
  54. package/src/shared/offline/useOfflineSessionEnded.ts +22 -0
  55. package/src/shared/offline/useOfflineUploadTray.ts +76 -0
  56. package/src/shared/offline/usePresenceHidden.ts +33 -0
  57. package/src/shared/resources/CometChatLocalizeNew/resources/de/translation.json +24 -1
  58. package/src/shared/resources/CometChatLocalizeNew/resources/en/translation.json +24 -1
  59. package/src/shared/resources/CometChatLocalizeNew/resources/es/translation.json +24 -1
  60. package/src/shared/resources/CometChatLocalizeNew/resources/fr/translation.json +24 -1
  61. package/src/shared/resources/CometChatLocalizeNew/resources/hi/translation.json +24 -1
  62. package/src/shared/resources/CometChatLocalizeNew/resources/hu/translation.json +24 -1
  63. package/src/shared/resources/CometChatLocalizeNew/resources/it/translation.json +24 -1
  64. package/src/shared/resources/CometChatLocalizeNew/resources/ja/translation.json +24 -1
  65. package/src/shared/resources/CometChatLocalizeNew/resources/ko/translation.json +24 -1
  66. package/src/shared/resources/CometChatLocalizeNew/resources/lt/translation.json +24 -1
  67. package/src/shared/resources/CometChatLocalizeNew/resources/ms/translation.json +24 -1
  68. package/src/shared/resources/CometChatLocalizeNew/resources/nl/translation.json +24 -1
  69. package/src/shared/resources/CometChatLocalizeNew/resources/pt/translation.json +24 -1
  70. package/src/shared/resources/CometChatLocalizeNew/resources/ru/translation.json +24 -1
  71. package/src/shared/resources/CometChatLocalizeNew/resources/sv/translation.json +24 -1
  72. package/src/shared/resources/CometChatLocalizeNew/resources/tr/translation.json +24 -1
  73. package/src/shared/resources/CometChatLocalizeNew/resources/zh/translation.json +24 -1
  74. package/src/shared/resources/CometChatLocalizeNew/resources/zh-tw/translation.json +24 -1
  75. package/src/shared/services/UploadQueueService.ts +106 -1
  76. package/src/shared/utils/MessageReceiptUtils.ts +8 -0
  77. package/src/shared/utils/SavedMessagesHelper.ts +18 -1
  78. package/src/shared/utils/catchUpCursor.ts +36 -0
  79. package/src/shared/utils/failedMessageRetry.ts +73 -0
  80. package/src/shared/utils/messageIdentity.ts +38 -0
  81. package/src/shared/views/CometChatAttachmentViewer/CometChatAttachmentViewer.tsx +34 -5
  82. package/src/shared/views/CometChatAudiosBubble/CometChatAudiosBubble.tsx +10 -2
  83. package/src/shared/views/CometChatFileBubble/CometChatFileBubble.tsx +13 -27
  84. package/src/shared/views/CometChatFilesBubble/CometChatFilesBubble.tsx +60 -11
  85. package/src/shared/views/CometChatImagesBubble/CometChatImagesBubble.tsx +27 -2
  86. package/src/shared/views/CometChatList/CometChatList.tsx +468 -7
  87. package/src/shared/views/CometChatMediaViewer/CometChatMediaViewer.tsx +27 -5
  88. package/src/shared/views/CometChatMessageInput/CometChatMessageInput.tsx +1 -0
  89. package/src/shared/views/CometChatReactionList/CometChatReactionList.tsx +56 -10
  90. package/src/shared/views/CometChatStatusIndicator/CometChatStatusIndicator.tsx +4 -0
  91. package/src/shared/views/CometChatVideosBubble/CometChatVideosBubble.tsx +36 -2
  92. package/src/shared/views/CometChatVoiceNoteBubble/CometChatVoiceNoteBubble.tsx +24 -12
  93. package/src/theme/type.ts +17 -0
  94. package/android/.gradle/7.4/checksums/checksums.lock +0 -0
  95. package/android/.gradle/7.4/fileChanges/last-build.bin +0 -0
  96. package/android/.gradle/7.4/fileHashes/fileHashes.lock +0 -0
  97. package/android/.gradle/7.4/gc.properties +0 -0
  98. package/android/.gradle/vcs-1/gc.properties +0 -0
@@ -48,6 +48,10 @@ import {
48
48
  ViewAlignment,
49
49
  } from "../shared/constants/UIKitConstants";
50
50
  import { MessageEvents } from "../shared/events";
51
+ import { afterFirstAnswer, quietAwareOnError, routeSend } from "../shared/offline/send";
52
+ import { isOfflineOn } from "../shared/offline/gate";
53
+ import { useOfflineThreadTrayReset, useOfflineUploadTray } from "../shared/offline/useOfflineUploadTray";
54
+ import { offlineMutationErrorText } from "../shared/offline/notices";
51
55
  import { CometChatUIEventHandler } from "../shared/events/CometChatUIEventHandler/CometChatUIEventHandler";
52
56
  import { CometChatMessageEvents } from "../shared/events/CometChatMessageEvents";
53
57
  import { CometChatMessageComposerAction, DeepPartial } from "../shared/helper/types";
@@ -753,10 +757,10 @@ export const CometChatMessageComposer = React.forwardRef(
753
757
  // RBAC/SBAC presign authorization. Read the refs fresh here (uploadQueue is memoized at mount,
754
758
  // the refs are not) — constructor-time capture would be stale.
755
759
  newAttachments.forEach(a =>
756
- uploadQueue.enqueue(a, { receiver: chatWithId.current, receiverType: chatWith.current })
760
+ uploadQueue.enqueue(a, { receiver: chatWithId.current, receiverType: chatWith.current, parentMessageId })
757
761
  );
758
762
  },
759
- [selectedAttachments, uploadQueue]
763
+ [selectedAttachments, uploadQueue, parentMessageId]
760
764
  );
761
765
 
762
766
  const handleRemoveAttachment = useCallback(
@@ -820,7 +824,8 @@ export const CometChatMessageComposer = React.forwardRef(
820
824
  if (sendButtonDelayTimer.current) {
821
825
  clearTimeout(sendButtonDelayTimer.current);
822
826
  }
823
- uploadQueue.cancelAll();
827
+ // Offline OFF: destroy the batch as today; ON: detach so it can be restored.
828
+ uploadQueue.leave();
824
829
  };
825
830
  }, []);
826
831
 
@@ -1198,31 +1203,46 @@ export const CometChatMessageComposer = React.forwardRef(
1198
1203
 
1199
1204
  // §7/§12.1 — independent per-message send: one kind can fail while others deliver.
1200
1205
  const outgoing = buildMessage(group, index, muid);
1201
- CometChat.sendMediaMessage(outgoing)
1202
- .then((msg: any) => {
1203
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1204
- message: msg,
1205
- status: messageStatus.success,
1206
+ // Gate read once, at send: OFF runs today's code unchanged; ON goes through the
1207
+ // kit's one send helper (hub reports state and the public events, once).
1208
+ const routed = routeSend(outgoing, "media", () => {
1209
+ CometChat.sendMediaMessage(outgoing)
1210
+ .then((msg: any) => {
1211
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1212
+ message: msg,
1213
+ status: messageStatus.success,
1214
+ });
1215
+ if (replyMessageId) {
1216
+ CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
1217
+ message: msg,
1218
+ status: messageStatus.success,
1219
+ });
1220
+ }
1221
+ })
1222
+ .catch((error: any) => {
1223
+ // Preserve the batch metadata; just flag this message's optimistic echo as failed.
1224
+ const currentData = localMessage.getData() || {};
1225
+ localMessage.setData({ ...currentData, metaData: { error: true } });
1226
+ const md = (localMessage.getMetadata?.() as Record<string, unknown>) || {};
1227
+ localMessage.setMetadata({ ...md, error: true });
1228
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1229
+ message: localMessage,
1230
+ status: messageStatus.error,
1231
+ });
1232
+ onError && onError(error);
1206
1233
  });
1234
+ }, {
1235
+ onSent: (msg: any) => {
1207
1236
  if (replyMessageId) {
1208
1237
  CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
1209
1238
  message: msg,
1210
1239
  status: messageStatus.success,
1211
1240
  });
1212
1241
  }
1213
- })
1214
- .catch((error: any) => {
1215
- // Preserve the batch metadata; just flag this message's optimistic echo as failed.
1216
- const currentData = localMessage.getData() || {};
1217
- localMessage.setData({ ...currentData, metaData: { error: true } });
1218
- const md = (localMessage.getMetadata?.() as Record<string, unknown>) || {};
1219
- localMessage.setMetadata({ ...md, error: true });
1220
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1221
- message: localMessage,
1222
- status: messageStatus.error,
1223
- });
1224
- onError && onError(error);
1225
- });
1242
+ },
1243
+ onFailed: quietAwareOnError(onError),
1244
+ });
1245
+ void routed;
1226
1246
  });
1227
1247
 
1228
1248
  // Clear composer state immediately
@@ -1384,8 +1404,36 @@ export const CometChatMessageComposer = React.forwardRef(
1384
1404
  }, 1000);
1385
1405
  }
1386
1406
 
1387
- CometChat.sendMessage(textMessage)
1388
- .then((message: any) => {
1407
+ // Gate read once, at send: OFF runs today's code unchanged; ON goes through the
1408
+ // kit's one send helper (hub reports state and the public events, once).
1409
+ const routed = routeSend(textMessage, "text", () => {
1410
+ CometChat.sendMessage(textMessage)
1411
+ .then((message: any) => {
1412
+ if (isAgenticUser() && !parentMessageId && message?.getId) {
1413
+ const messageId = typeof message.getId() === 'string' ? Number(message.getId()) : message.getId();
1414
+ if (!isNaN(messageId) && !parentMessageIdRef.current) {
1415
+ parentMessageIdRef.current = messageId;
1416
+ }
1417
+ if (messageId && !isNaN(messageId)) {
1418
+ startStreamingForRunId(String(messageId));
1419
+ }
1420
+ }
1421
+
1422
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1423
+ message: message,
1424
+ status: messageStatus.success,
1425
+ });
1426
+ })
1427
+ .catch((error: any) => {
1428
+ onError && onError(error);
1429
+ textMessage.setMetadata({ error: true });
1430
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1431
+ message: textMessage,
1432
+ status: messageStatus.error,
1433
+ });
1434
+ });
1435
+ }, {
1436
+ onSent: (message: any) => {
1389
1437
  if (isAgenticUser() && !parentMessageId && message?.getId) {
1390
1438
  const messageId = typeof message.getId() === 'string' ? Number(message.getId()) : message.getId();
1391
1439
  if (!isNaN(messageId) && !parentMessageIdRef.current) {
@@ -1395,20 +1443,10 @@ export const CometChatMessageComposer = React.forwardRef(
1395
1443
  startStreamingForRunId(String(messageId));
1396
1444
  }
1397
1445
  }
1398
-
1399
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1400
- message: message,
1401
- status: messageStatus.success,
1402
- });
1403
- })
1404
- .catch((error: any) => {
1405
- onError && onError(error);
1406
- textMessage.setMetadata({ error: true });
1407
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1408
- message: textMessage,
1409
- status: messageStatus.error,
1410
- });
1411
- });
1446
+ },
1447
+ onFailed: quietAwareOnError(onError),
1448
+ });
1449
+ void routed;
1412
1450
  };
1413
1451
 
1414
1452
  /** edit message */
@@ -1454,6 +1492,11 @@ export const CometChatMessageComposer = React.forwardRef(
1454
1492
  outgoing = textMessage;
1455
1493
  }
1456
1494
 
1495
+ // The composer is cleared and leaves edit mode before the request, offline on or off. A failed
1496
+ // edit goes to onError (plus the offline error notice below); the text is not put back, as on
1497
+ // the Android UI Kit.
1498
+ const offlineOn = isOfflineOn();
1499
+
1457
1500
  inputValueRef.current = "";
1458
1501
  clearInputBox();
1459
1502
 
@@ -1477,6 +1520,9 @@ export const CometChatMessageComposer = React.forwardRef(
1477
1520
  })
1478
1521
  .catch((error: any) => {
1479
1522
  onError && onError(error);
1523
+ // Offline ON: today's error notice too (ENG-41199).
1524
+ const errorText = offlineMutationErrorText(offlineOn, t);
1525
+ if (errorText) showToast(errorText);
1480
1526
  });
1481
1527
  };
1482
1528
 
@@ -1611,25 +1657,40 @@ export const CometChatMessageComposer = React.forwardRef(
1611
1657
  });
1612
1658
 
1613
1659
  if (!disableSoundForOutgoingMessages) playAudio();
1614
- CometChat.sendMediaMessage(mediaMessage)
1615
- .then((message: any) => {
1616
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1617
- message: message,
1618
- status: messageStatus.success,
1619
- });
1620
- if (replyMessageId) {
1621
- CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
1660
+ // Gate read once, at send: OFF runs today's code unchanged; ON goes through the
1661
+ // kit's one send helper (hub reports state and the public events, once).
1662
+ const routed = routeSend(mediaMessage, "media", () => {
1663
+ CometChat.sendMediaMessage(mediaMessage)
1664
+ .then((message: any) => {
1665
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1622
1666
  message: message,
1623
1667
  status: messageStatus.success,
1624
1668
  });
1625
- }
1626
- setReplyMessage(null);
1627
- setWarningMessage("");
1628
- setShowRecordAudio(false);
1629
- })
1630
- .catch((error: any) => {
1631
- setShowRecordAudio(false);
1632
- if (error?.code === "ERR_PERMISSION_DENIED") {
1669
+ if (replyMessageId) {
1670
+ CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
1671
+ message: message,
1672
+ status: messageStatus.success,
1673
+ });
1674
+ }
1675
+ setReplyMessage(null);
1676
+ setWarningMessage("");
1677
+ setShowRecordAudio(false);
1678
+ })
1679
+ .catch((error: any) => {
1680
+ setShowRecordAudio(false);
1681
+ if (error?.code === "ERR_PERMISSION_DENIED") {
1682
+ onError && onError(error);
1683
+ // Set error in data.metaData where the message list receipt logic checks
1684
+ const currentData = localMessage.getData() || {};
1685
+ localMessage.setData({ ...currentData, metaData: { error: true } });
1686
+ localMessage.setMetadata({ error: true });
1687
+ CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1688
+ message: localMessage,
1689
+ status: messageStatus.error,
1690
+ });
1691
+ setReplyMessage(null);
1692
+ return;
1693
+ }
1633
1694
  onError && onError(error);
1634
1695
  // Set error in data.metaData where the message list receipt logic checks
1635
1696
  const currentData = localMessage.getData() || {};
@@ -1640,19 +1701,19 @@ export const CometChatMessageComposer = React.forwardRef(
1640
1701
  status: messageStatus.error,
1641
1702
  });
1642
1703
  setReplyMessage(null);
1643
- return;
1644
- }
1645
- onError && onError(error);
1646
- // Set error in data.metaData where the message list receipt logic checks
1647
- const currentData = localMessage.getData() || {};
1648
- localMessage.setData({ ...currentData, metaData: { error: true } });
1649
- localMessage.setMetadata({ error: true });
1650
- CometChatUIEventHandler.emitMessageEvent(MessageEvents.ccMessageSent, {
1651
- message: localMessage,
1652
- status: messageStatus.error,
1653
1704
  });
1654
- setReplyMessage(null);
1655
- });
1705
+ }, {
1706
+ onSent: (message: any) => {
1707
+ if (replyMessageId) {
1708
+ CometChatMessageEvents.emit(CometChatMessageEvents.ccReplyToMessage, {
1709
+ message: message,
1710
+ status: messageStatus.success,
1711
+ });
1712
+ }
1713
+ },
1714
+ onFailed: quietAwareOnError(onError),
1715
+ });
1716
+ afterFirstAnswer(routed, () => { setReplyMessage(null); setWarningMessage(""); setShowRecordAudio(false); });
1656
1717
  };
1657
1718
 
1658
1719
  const startTyping = (endTypingTimeout?: any, typingMetadata?: any) => {
@@ -1875,6 +1936,7 @@ export const CometChatMessageComposer = React.forwardRef(
1875
1936
  : sendTextMessage;
1876
1937
  return (
1877
1938
  <TouchableOpacity
1939
+ testID="CometChatComposer.send"
1878
1940
  onPress={handleSendPress}
1879
1941
  style={[
1880
1942
  {
@@ -1954,7 +2016,9 @@ export const CometChatMessageComposer = React.forwardRef(
1954
2016
  // for the SAME conversation doesn't wipe a tray the user is mid-staging. Skip the first
1955
2017
  // assignment (chatWithId.current === null → nothing staged yet).
1956
2018
  if (chatWithId.current != null && chatWithId.current !== newChatWithId) {
1957
- uploadQueue.cancelAll();
2019
+ // Offline OFF: destroy the batch as today. Offline ON: detach; the SDK keeps it for a
2020
+ // restore when the user comes back (BEH-UPLOAD-14).
2021
+ uploadQueue.leave();
1958
2022
  setSelectedAttachments([]);
1959
2023
  selectedAttachmentsRef.current = [];
1960
2024
  }
@@ -1977,6 +2041,22 @@ export const CometChatMessageComposer = React.forwardRef(
1977
2041
  }
1978
2042
  }, [user, group, chatRef]);
1979
2043
 
2044
+ // Offline ON: a thread switch in the same chat lets go of the previous thread's tray. The
2045
+ // receiver guard above only sees chat switches. Offline OFF: nothing.
2046
+ useOfflineThreadTrayReset(uploadQueue, parentMessageId, selectedAttachmentsRef, setSelectedAttachments);
2047
+
2048
+ // Offline ON: restore this chat's tray and clear it with the session. Offline OFF: nothing.
2049
+ useOfflineUploadTray(
2050
+ uploadQueue,
2051
+ {
2052
+ receiver: user?.getUid?.() ?? group?.getGuid?.(),
2053
+ receiverType: user?.getUid?.() ? ReceiverTypeConstants.user : group?.getGuid?.() ? ReceiverTypeConstants.group : undefined,
2054
+ parentMessageId,
2055
+ },
2056
+ selectedAttachmentsRef,
2057
+ setSelectedAttachments
2058
+ );
2059
+
1980
2060
  const handleOnClick = (CustomView: any) => {
1981
2061
  let view = CustomView(
1982
2062
  user,
@@ -11,6 +11,7 @@ import { deepMerge } from "../shared/helper/helperFunctions";
11
11
  import { Icon } from "../shared/icons/Icon";
12
12
  import { CometChatAvatar } from "../shared/views/CometChatAvatar";
13
13
  import { CometChatStatusIndicator } from "../shared/views/CometChatStatusIndicator";
14
+ import { usePresenceHidden } from "../shared/offline/usePresenceHidden";
14
15
  import { useTheme } from "../theme";
15
16
  import { MessageHeaderStyle } from "./styles";
16
17
  import { CommonUtils } from "../shared/utils/CommonUtils";
@@ -230,6 +231,8 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
230
231
  const [userObj, setUserObj] = useState<CometChat.User | undefined>(user);
231
232
  const [userStatus, setUserStatus] = useState(user && user.getStatus ? user.getStatus() : "");
232
233
  const [typingText, setTypingText] = useState("");
234
+ // Offline ON, SDK not connected: no presence subtitle and no typing text (nothing can arrive).
235
+ const presenceHidden = usePresenceHidden();
233
236
  const [showOptionsMenu, setShowOptionsMenu] = useState(false);
234
237
  const [tooltipPosition, setTooltipPosition] = useState({ pageX: 0, pageY: 0 });
235
238
  const receiverTypeRef = useRef(
@@ -450,7 +453,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
450
453
  */
451
454
  const SubtitleViewFnc = useCallback(() => {
452
455
  try {
453
- if (typingText !== "")
456
+ if (typingText !== "" && !presenceHidden)
454
457
  return (
455
458
  <Text
456
459
  numberOfLines={1}
@@ -473,7 +476,8 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
473
476
  userObj &&
474
477
  !(userObj.getBlockedByMe() || userObj.getHasBlockedMe()) &&
475
478
  usersStatusVisibility &&
476
- userStatus
479
+ userStatus &&
480
+ !presenceHidden
477
481
  ) {
478
482
  subtitle =
479
483
  userStatus === UserStatusConstants.online
@@ -490,7 +494,7 @@ export const CometChatMessageHeader = (props: CometChatMessageHeaderInterface) =
490
494
  errorHandler(error);
491
495
  return <></>;
492
496
  }
493
- }, [userObj, groupObj, messageHeaderStyles, usersStatusVisibility, userStatus]);
497
+ }, [userObj, groupObj, messageHeaderStyles, usersStatusVisibility, userStatus, presenceHidden]);
494
498
 
495
499
  /**
496
500
  * Error handler to call onError with a proper CometChatException.
@@ -1,5 +1,64 @@
1
1
  import { CometChat } from "@cometchat/chat-sdk-react-native";
2
2
  import { CometChatUIEventHandler, CometChatUIKit } from "../shared";
3
+ import { OfflineHub } from "../shared/offline/OfflineHub";
4
+ import { dispatchSweptGroupAction } from "../shared/offline/groupActions";
5
+
6
+ /** Hub subscriptions for swept group actions, per header group listener id. */
7
+ const sweptGroupActionSubscriptions = new Map<string, { unsubscribe(): void }>();
8
+
9
+ /** The header's GroupListener handlers, shared by the live listener and swept actions. */
10
+ export const groupListenerHandlers = (handleGroupListener: (group: CometChat.Group) => void) => ({
11
+ onGroupMemberKicked: (
12
+ message: any,
13
+ kickedUser: CometChat.User,
14
+ kickedBy: CometChat.User,
15
+ kickedFrom: CometChat.Group
16
+ ) => {
17
+ handleGroupListener(kickedFrom);
18
+ },
19
+ onGroupMemberBanned: (
20
+ message: any,
21
+ bannedUser: CometChat.User,
22
+ bannedBy: CometChat.User,
23
+ bannedFrom: CometChat.Group
24
+ ) => {
25
+ handleGroupListener(bannedFrom);
26
+ },
27
+ onMemberAddedToGroup: (
28
+ message: any,
29
+ userAdded: CometChat.User,
30
+ userAddedBy: CometChat.User,
31
+ userAddedIn: CometChat.Group
32
+ ) => {
33
+ console.log("onMemberAddedToGroup", userAddedIn);
34
+ handleGroupListener(userAddedIn);
35
+ },
36
+ onGroupMemberLeft: (
37
+ message: any,
38
+ leavingUser: CometChat.User,
39
+ group: CometChat.Group
40
+ ) => {
41
+ handleGroupListener(group);
42
+ },
43
+ onGroupMemberJoined: (
44
+ message: any,
45
+ joinedUser: CometChat.User,
46
+ joinedGroup: CometChat.Group
47
+ ) => {
48
+ handleGroupListener(joinedGroup);
49
+ },
50
+ onGroupMemberScopeChanged: (
51
+ message: CometChat.Action,
52
+ changedUser: CometChat.GroupMember,
53
+ newScope: CometChat.GroupMemberScope,
54
+ oldScope: CometChat.GroupMemberScope,
55
+ changedGroup: CometChat.Group
56
+ ) => {
57
+ if (changedUser.getUid() !== CometChatUIKit.loggedInUser?.getUid()) return;
58
+ changedGroup.setScope(newScope);
59
+ handleGroupListener(changedGroup);
60
+ },
61
+ });
3
62
 
4
63
  export const listners = {
5
64
  addListener: {
@@ -26,62 +85,20 @@ export const listners = {
26
85
  msgTypingIndicator(typistDetails, "");
27
86
  },
28
87
  }),
29
- groupListener: ({ groupListenerId, handleGroupListener }: any) =>
30
- CometChat.addGroupListener(
88
+ groupListener: ({ groupListenerId, handleGroupListener }: any) => {
89
+ const handlers = groupListenerHandlers(handleGroupListener);
90
+ CometChat.addGroupListener(groupListenerId, new CometChat.GroupListener(handlers));
91
+ // Offline (ON path): a group action the catch-up sweep delivered fires no GroupListener
92
+ // callback; run the same handlers for it (UIT-SYNC-13). Inert with offline off.
93
+ sweptGroupActionSubscriptions.get(groupListenerId)?.unsubscribe();
94
+ sweptGroupActionSubscriptions.set(
31
95
  groupListenerId,
32
- new CometChat.GroupListener({
33
- onGroupMemberKicked: (
34
- message: any,
35
- kickedUser: CometChat.User,
36
- kickedBy: CometChat.User,
37
- kickedFrom: CometChat.Group
38
- ) => {
39
- handleGroupListener(kickedFrom);
40
- },
41
- onGroupMemberBanned: (
42
- message: any,
43
- bannedUser: CometChat.User,
44
- bannedBy: CometChat.User,
45
- bannedFrom: CometChat.Group
46
- ) => {
47
- handleGroupListener(bannedFrom);
48
- },
49
- onMemberAddedToGroup: (
50
- message: any,
51
- userAdded: CometChat.User,
52
- userAddedBy: CometChat.User,
53
- userAddedIn: CometChat.Group
54
- ) => {
55
- console.log("onMemberAddedToGroup", userAddedIn);
56
- handleGroupListener(userAddedIn);
57
- },
58
- onGroupMemberLeft: (
59
- message: any,
60
- leavingUser: CometChat.User,
61
- group: CometChat.Group
62
- ) => {
63
- handleGroupListener(group);
64
- },
65
- onGroupMemberJoined: (
66
- message: any,
67
- joinedUser: CometChat.User,
68
- joinedGroup: CometChat.Group
69
- ) => {
70
- handleGroupListener(joinedGroup);
71
- },
72
- onGroupMemberScopeChanged: (
73
- message: CometChat.Action,
74
- changedUser: CometChat.GroupMember,
75
- newScope: CometChat.GroupMemberScope,
76
- oldScope: CometChat.GroupMemberScope,
77
- changedGroup: CometChat.Group
78
- ) => {
79
- if (changedUser.getUid() !== CometChatUIKit.loggedInUser?.getUid()) return;
80
- changedGroup.setScope(newScope);
81
- handleGroupListener(changedGroup);
82
- },
96
+ OfflineHub.getInstance().groupActionSwept$.subscribe((event) => {
97
+ if (event.gen !== OfflineHub.getInstance().gen) return;
98
+ dispatchSweptGroupAction(event.message, handlers);
83
99
  })
84
- ),
100
+ );
101
+ },
85
102
  },
86
103
  removeListner: {
87
104
  removeUserListener: ({ userStatusListenerId }: any) =>
@@ -90,7 +107,10 @@ export const listners = {
90
107
  removeMessageListener: ({ msgTypingListenerId }: any) =>
91
108
  CometChatUIEventHandler.removeMessageListener(msgTypingListenerId),
92
109
 
93
- removeGroupListener: ({ groupListenerId }: any) =>
94
- CometChat.removeGroupListener(groupListenerId),
110
+ removeGroupListener: ({ groupListenerId }: any) => {
111
+ sweptGroupActionSubscriptions.get(groupListenerId)?.unsubscribe();
112
+ sweptGroupActionSubscriptions.delete(groupListenerId);
113
+ return CometChat.removeGroupListener(groupListenerId);
114
+ },
95
115
  },
96
116
  };