@amityco/ts-sdk-react-native 6.32.2-da6d23d.0 → 6.32.3-89ca939.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 (118) hide show
  1. package/dist/@types/core/events.d.ts +1 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +1 -1
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +1 -1
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/channel.d.ts +1 -0
  8. package/dist/@types/domains/channel.d.ts.map +1 -1
  9. package/dist/channelRepository/api/createChannel.d.ts.map +1 -1
  10. package/dist/channelRepository/api/getChannel.d.ts.map +1 -1
  11. package/dist/channelRepository/api/getChannelByIds.d.ts.map +1 -1
  12. package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
  13. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts +2 -2
  14. package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
  15. package/dist/channelRepository/events/onChannelCreated.d.ts +1 -1
  16. package/dist/channelRepository/events/onChannelCreated.d.ts.map +1 -1
  17. package/dist/channelRepository/events/onChannelDeleted.d.ts +1 -1
  18. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  19. package/dist/channelRepository/events/onChannelFetched.d.ts +1 -1
  20. package/dist/channelRepository/events/onChannelFetched.d.ts.map +1 -1
  21. package/dist/channelRepository/events/onChannelJoined.d.ts +1 -1
  22. package/dist/channelRepository/events/onChannelJoined.d.ts.map +1 -1
  23. package/dist/channelRepository/events/onChannelLeft.d.ts +1 -1
  24. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  25. package/dist/channelRepository/events/onChannelMemberAdded.d.ts +1 -1
  26. package/dist/channelRepository/events/onChannelMemberAdded.d.ts.map +1 -1
  27. package/dist/channelRepository/events/onChannelMemberBanned.d.ts +1 -1
  28. package/dist/channelRepository/events/onChannelMemberBanned.d.ts.map +1 -1
  29. package/dist/channelRepository/events/onChannelMemberRemoved.d.ts +1 -1
  30. package/dist/channelRepository/events/onChannelMemberRemoved.d.ts.map +1 -1
  31. package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts +1 -1
  32. package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts.map +1 -1
  33. package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts +1 -1
  34. package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
  35. package/dist/channelRepository/events/onChannelMemberUnbanned.d.ts +1 -1
  36. package/dist/channelRepository/events/onChannelMemberUnbanned.d.ts.map +1 -1
  37. package/dist/channelRepository/events/onChannelMuted.d.ts +1 -1
  38. package/dist/channelRepository/events/onChannelMuted.d.ts.map +1 -1
  39. package/dist/channelRepository/events/onChannelResolved.d.ts +1 -1
  40. package/dist/channelRepository/events/onChannelResolved.d.ts.map +1 -1
  41. package/dist/channelRepository/events/onChannelUpdated.d.ts +1 -1
  42. package/dist/channelRepository/events/onChannelUpdated.d.ts.map +1 -1
  43. package/dist/channelRepository/events/onUserDeleted.d.ts +1 -1
  44. package/dist/channelRepository/events/onUserDeleted.d.ts.map +1 -1
  45. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  46. package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts +2 -2
  47. package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
  48. package/dist/channelRepository/observers/observeChannel.d.ts.map +1 -1
  49. package/dist/channelRepository/observers/observeChannels.d.ts.map +1 -1
  50. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts +2 -0
  51. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -0
  52. package/dist/channelRepository/utils/prepareChannelPayload.d.ts +1 -1
  53. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  54. package/dist/channelRepository/utils/resolveUnreadInfoOnChannelEvent.d.ts +1 -1
  55. package/dist/channelRepository/utils/resolveUnreadInfoOnChannelEvent.d.ts.map +1 -1
  56. package/dist/client/utils/removeChannelMarkerCache.d.ts +1 -1
  57. package/dist/client/utils/removeChannelMarkerCache.d.ts.map +1 -1
  58. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  59. package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
  60. package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
  61. package/dist/core/transports/http.d.ts.map +1 -1
  62. package/dist/index.cjs.js +161 -135
  63. package/dist/index.esm.js +161 -135
  64. package/dist/index.umd.js +3 -3
  65. package/dist/marker/events/onMessageMarked.d.ts.map +1 -1
  66. package/dist/marker/utils/reCalculateChannelUnreadInfo.d.ts.map +1 -1
  67. package/dist/marker/utils/updateSubChannelUnreadFromMessage.d.ts.map +1 -1
  68. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  69. package/dist/postRepository/events/utils.d.ts.map +1 -1
  70. package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
  71. package/dist/utils/shallowClone.d.ts +1 -1
  72. package/dist/utils/shallowClone.d.ts.map +1 -1
  73. package/package.json +2 -2
  74. package/src/@types/core/events.ts +1 -1
  75. package/src/@types/core/model.ts +1 -1
  76. package/src/@types/core/payload.ts +1 -1
  77. package/src/@types/domains/channel.ts +5 -0
  78. package/src/channelRepository/api/createChannel.ts +2 -1
  79. package/src/channelRepository/api/getChannel.ts +4 -3
  80. package/src/channelRepository/api/getChannelByIds.ts +2 -1
  81. package/src/channelRepository/api/updateChannel.ts +2 -1
  82. package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.ts +2 -2
  83. package/src/channelRepository/events/onChannelCreated.ts +2 -2
  84. package/src/channelRepository/events/onChannelDeleted.ts +2 -2
  85. package/src/channelRepository/events/onChannelFetched.ts +3 -3
  86. package/src/channelRepository/events/onChannelJoined.ts +5 -2
  87. package/src/channelRepository/events/onChannelLeft.ts +5 -2
  88. package/src/channelRepository/events/onChannelMemberAdded.ts +5 -2
  89. package/src/channelRepository/events/onChannelMemberBanned.ts +5 -2
  90. package/src/channelRepository/events/onChannelMemberRemoved.ts +5 -2
  91. package/src/channelRepository/events/onChannelMemberRoleAdded.ts +5 -2
  92. package/src/channelRepository/events/onChannelMemberRoleRemoved.ts +5 -2
  93. package/src/channelRepository/events/onChannelMemberUnbanned.ts +5 -2
  94. package/src/channelRepository/events/onChannelMuted.ts +3 -2
  95. package/src/channelRepository/events/onChannelResolved.ts +2 -2
  96. package/src/channelRepository/events/onChannelUpdated.ts +2 -2
  97. package/src/channelRepository/events/onUserDeleted.ts +8 -2
  98. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +11 -7
  99. package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +2 -2
  100. package/src/channelRepository/observers/observeChannel.ts +5 -4
  101. package/src/channelRepository/observers/observeChannels.ts +6 -4
  102. package/src/channelRepository/utils/constructChannelDynamicValue.ts +22 -0
  103. package/src/channelRepository/utils/prepareChannelPayload.ts +1 -13
  104. package/src/channelRepository/utils/resolveUnreadInfoOnChannelEvent.ts +2 -2
  105. package/src/channelRepository/utils/updateChannelCache.ts +1 -1
  106. package/src/client/utils/removeChannelMarkerCache.ts +1 -1
  107. package/src/commentRepository/events/utils.ts +2 -1
  108. package/src/communityRepository/communityMembership/events/utils.ts +4 -2
  109. package/src/communityRepository/utils/communityWithMembership.ts +15 -8
  110. package/src/core/transports/http.ts +2 -0
  111. package/src/marker/events/onMessageMarked.ts +0 -2
  112. package/src/marker/utils/reCalculateChannelUnreadInfo.ts +6 -0
  113. package/src/marker/utils/updateSubChannelUnreadFromMessage.ts +10 -0
  114. package/src/messageRepository/events/onMessageCreated.ts +2 -0
  115. package/src/postRepository/events/utils.ts +2 -1
  116. package/src/subChannelRepository/utils/updateSubChannelCache.ts +1 -1
  117. package/src/utils/linkedObject/channelLinkedObject.ts +3 -3
  118. package/src/utils/shallowClone.ts +8 -5
package/dist/index.esm.js CHANGED
@@ -89,8 +89,8 @@ const PostContentType = Object.freeze({
89
89
 
90
90
  function getVersion() {
91
91
  try {
92
- // the string ''v6.32.1-esm'' should be replaced by actual value by @rollup/plugin-replace
93
- return 'v6.32.1-esm';
92
+ // the string ''v6.32.3-esm'' should be replaced by actual value by @rollup/plugin-replace
93
+ return 'v6.32.3-esm';
94
94
  }
95
95
  catch (error) {
96
96
  return '__dev__';
@@ -1702,6 +1702,7 @@ const createHttpTransport = (endpoint) => {
1702
1702
  * https://github.com/axios/axios#request-config
1703
1703
  */
1704
1704
  });
1705
+ instance.defaults.withCredentials = false;
1705
1706
  instance.interceptors.request.use(config => {
1706
1707
  // do not check expiration for token creation url
1707
1708
  if (config.url === '/api/v5/sessions') {
@@ -21719,6 +21720,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21719
21720
  var _a;
21720
21721
  const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
21721
21722
  const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
21723
+ console.log('[reCalculateChannelUnreadInfo] cacheChannelUnreadInfo => ', cacheChannelUnreadInfo);
21722
21724
  const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
21723
21725
  const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
21724
21726
  let channelUnreads = 0;
@@ -21727,9 +21729,11 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21727
21729
  const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
21728
21730
  return data.channelId === channelId && !data.isDeleted;
21729
21731
  });
21732
+ console.log('[reCalculateChannelUnreadInfo] subChannelUnreadsInfo => ', subChannelUnreadsInfo);
21730
21733
  channelUnreads = subChannelUnreadsInfo
21731
21734
  .map(({ data }) => data.unreadCount)
21732
21735
  .reduce((acc, cur) => acc + cur, 0);
21736
+ console.log('[reCalculateChannelUnreadInfo] channelUnreads => ', channelUnreads);
21733
21737
  isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
21734
21738
  }
21735
21739
  const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
@@ -22015,8 +22019,28 @@ const markAsRead = async (channelId) => {
22015
22019
  return true;
22016
22020
  };
22017
22021
 
22022
+ /**
22023
+ * ```js
22024
+ * import { shallowClone } from '~/utils/shallowClone'
22025
+ * const newObj = shallowClone(obj)
22026
+ * ```
22027
+ *
22028
+ * Clone an object with same prototype and properties
22029
+ *
22030
+ * @param obj the object to clone
22031
+ * @returns new object with same prototype and properties
22032
+ *
22033
+ * @category utility
22034
+ * @private
22035
+ */
22036
+ function shallowClone(source, target) {
22037
+ return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
22038
+ }
22039
+
22018
22040
  const channelLinkedObject = (channel) => {
22019
- return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
22041
+ return shallowClone(channel, {
22042
+ markAsRead: () => markAsRead(channel.channelInternalId),
22043
+ });
22020
22044
  };
22021
22045
 
22022
22046
  const adLinkedObject = (ad) => {
@@ -22187,31 +22211,10 @@ const updateSubChannelMessagePreviewCache = (rawPayload) => {
22187
22211
  ingestInCache(newData);
22188
22212
  };
22189
22213
 
22190
- /**
22191
- * ```js
22192
- * import { shallowClone } from '~/utils/shallowClone'
22193
- * const newObj = shallowClone(obj)
22194
- * ```
22195
- *
22196
- * Clone an object with same prototype and properties
22197
- *
22198
- * @param obj the object to clone
22199
- * @returns new object with same prototype and properties
22200
- *
22201
- * @category utility
22202
- * @private
22203
- */
22204
- function shallowClone(obj) {
22205
- const clone = Object.create(Object.getPrototypeOf(obj));
22206
- const descriptors = Object.getOwnPropertyDescriptors(obj);
22207
- Object.defineProperties(clone, descriptors);
22208
- return clone;
22209
- }
22210
-
22211
22214
  function updateSubChannelCache(subChannelId, subChannel, params) {
22212
22215
  pushToCache(['subChannel', 'get', subChannelId],
22213
22216
  // eslint-disable-next-line prefer-object-spread
22214
- Object.assign(shallowClone(subChannel), params));
22217
+ shallowClone(subChannel, params));
22215
22218
  }
22216
22219
 
22217
22220
  const handleMessageCreated = async (message) => {
@@ -22390,81 +22393,6 @@ const handleSubChannelUpdated = async (subChannel) => {
22390
22393
  }
22391
22394
  };
22392
22395
 
22393
- const getCachedMarker$1 = (entityId) => {
22394
- var _a;
22395
- const key = {
22396
- entityId,
22397
- userId: getActiveUser()._id,
22398
- };
22399
- return (_a = pullFromCache([
22400
- 'channelMarker',
22401
- 'get',
22402
- getResolver('channelMarker')(key),
22403
- ])) === null || _a === void 0 ? void 0 : _a.data;
22404
- };
22405
- const getUnreadInfoCached$1 = (channelId) => {
22406
- var _a;
22407
- return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
22408
- };
22409
- /**
22410
- * The function use to get value of unreadCount field.
22411
- * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
22412
- *
22413
- * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
22414
- * If not, the function will return the value from the channelMarker cache.
22415
- * If not found in the both cache, use `0` as defaul value.
22416
- */
22417
- const getSubChannelsUnreadCount = (channel, marker) => {
22418
- var _a, _b, _c, _d, _e;
22419
- const client = getActiveClient();
22420
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22421
- // Marker service API uses channelInternalId as channelId
22422
- return (_b = (_a = getUnreadInfoCached$1(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
22423
- }
22424
- if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
22425
- // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
22426
- // leave the channel because currently backend can't handle this, so every time a user is banned
22427
- // from a channel or the channel is deleted the channel's unread count will reset to zero
22428
- return 0;
22429
- }
22430
- return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker$1(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
22431
- };
22432
-
22433
- const getCachedMarker = (entityId) => {
22434
- var _a;
22435
- const key = {
22436
- entityId,
22437
- userId: getActiveUser()._id,
22438
- };
22439
- return (_a = pullFromCache([
22440
- 'channelMarker',
22441
- 'get',
22442
- getResolver('channelMarker')(key),
22443
- ])) === null || _a === void 0 ? void 0 : _a.data;
22444
- };
22445
- const getUnreadInfoCached = (channelId) => {
22446
- var _a;
22447
- return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
22448
- };
22449
- /**
22450
- * The function use to get value of hasMentioned or isMentioned field.
22451
- * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
22452
- *
22453
- * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
22454
- * If not, the function will return the value from the channelMarker cache.
22455
- * If not found in the both cache, use `false` as defaul value.
22456
- */
22457
- const getChannelIsMentioned = (channel, marker) => {
22458
- var _a, _b, _c, _d;
22459
- const client = getActiveClient();
22460
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22461
- return (_b = (_a = getUnreadInfoCached(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
22462
- }
22463
- return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
22464
- ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
22465
- : (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
22466
- };
22467
-
22468
22396
  function convertRawUserToInternalUser(rawUser) {
22469
22397
  return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
22470
22398
  }
@@ -22482,18 +22410,7 @@ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true })
22482
22410
  if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
22483
22411
  messagePreviewId = messagePreviewChannelCache.messagePreviewId;
22484
22412
  }
22485
- return Object.assign(Object.assign({ get unreadCount() {
22486
- return getSubChannelsUnreadCount(channel);
22487
- },
22488
- get hasMentioned() {
22489
- return getChannelIsMentioned(channel);
22490
- },
22491
- get isMentioned() {
22492
- return getChannelIsMentioned(channel);
22493
- },
22494
- get subChannelsUnreadCount() {
22495
- return getSubChannelsUnreadCount(channel);
22496
- } }, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
22413
+ return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
22497
22414
  }
22498
22415
  const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
22499
22416
  ingestInCache({
@@ -22615,6 +22532,98 @@ const prepareUnreadCountInfo = async (rawPayload) => {
22615
22532
  client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
22616
22533
  };
22617
22534
 
22535
+ const getCachedMarker$1 = (entityId) => {
22536
+ var _a;
22537
+ const key = {
22538
+ entityId,
22539
+ userId: getActiveUser()._id,
22540
+ };
22541
+ return (_a = pullFromCache([
22542
+ 'channelMarker',
22543
+ 'get',
22544
+ getResolver('channelMarker')(key),
22545
+ ])) === null || _a === void 0 ? void 0 : _a.data;
22546
+ };
22547
+ const getUnreadInfoCached$1 = (channelId) => {
22548
+ var _a;
22549
+ return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
22550
+ };
22551
+ /**
22552
+ * The function use to get value of hasMentioned or isMentioned field.
22553
+ * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
22554
+ *
22555
+ * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
22556
+ * If not, the function will return the value from the channelMarker cache.
22557
+ * If not found in the both cache, use `false` as defaul value.
22558
+ */
22559
+ const getChannelIsMentioned = (channel, marker) => {
22560
+ var _a, _b, _c, _d;
22561
+ const client = getActiveClient();
22562
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22563
+ return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
22564
+ }
22565
+ return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
22566
+ ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
22567
+ : (_d = (_c = getCachedMarker$1(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
22568
+ };
22569
+
22570
+ const getCachedMarker = (entityId) => {
22571
+ var _a;
22572
+ const key = {
22573
+ entityId,
22574
+ userId: getActiveUser()._id,
22575
+ };
22576
+ return (_a = pullFromCache([
22577
+ 'channelMarker',
22578
+ 'get',
22579
+ getResolver('channelMarker')(key),
22580
+ ])) === null || _a === void 0 ? void 0 : _a.data;
22581
+ };
22582
+ const getUnreadInfoCached = (channelId) => {
22583
+ var _a;
22584
+ return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
22585
+ };
22586
+ /**
22587
+ * The function use to get value of unreadCount field.
22588
+ * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
22589
+ *
22590
+ * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
22591
+ * If not, the function will return the value from the channelMarker cache.
22592
+ * If not found in the both cache, use `0` as defaul value.
22593
+ */
22594
+ const getSubChannelsUnreadCount = (channel, marker) => {
22595
+ var _a, _b, _c, _d, _e;
22596
+ const client = getActiveClient();
22597
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
22598
+ // Marker service API uses channelInternalId as channelId
22599
+ return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
22600
+ }
22601
+ if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
22602
+ // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
22603
+ // leave the channel because currently backend can't handle this, so every time a user is banned
22604
+ // from a channel or the channel is deleted the channel's unread count will reset to zero
22605
+ return 0;
22606
+ }
22607
+ return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
22608
+ };
22609
+
22610
+ const constructChannelDynamicValue = (channel) => {
22611
+ return shallowClone(channel, {
22612
+ get unreadCount() {
22613
+ return getSubChannelsUnreadCount(channel);
22614
+ },
22615
+ get hasMentioned() {
22616
+ return getChannelIsMentioned(channel);
22617
+ },
22618
+ get isMentioned() {
22619
+ return getChannelIsMentioned(channel);
22620
+ },
22621
+ get subChannelsUnreadCount() {
22622
+ return getSubChannelsUnreadCount(channel);
22623
+ },
22624
+ });
22625
+ };
22626
+
22618
22627
  /**
22619
22628
  * ```js
22620
22629
  * import { getChannelByIds } from '@amityco/ts-sdk-react-native'
@@ -22659,7 +22668,7 @@ const getChannelByIds = async (channelIds) => {
22659
22668
  ingestInCache(data, { cachedAt });
22660
22669
  fireEvent('local.channel.fetched', data.channels);
22661
22670
  return {
22662
- data: data.channels.map(channel => LinkedObject.channel(channel)),
22671
+ data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
22663
22672
  cachedAt,
22664
22673
  };
22665
22674
  };
@@ -24749,12 +24758,14 @@ const updateSubChannelUnreadFromMessage = (message) => {
24749
24758
  const client = getActiveClient();
24750
24759
  const cacheKeyUnreadCount = ['subChannelUnreadInfo', 'get', message.messageFeedId];
24751
24760
  const cachedUnreadCount = (_a = pullFromCache(cacheKeyUnreadCount)) === null || _a === void 0 ? void 0 : _a.data;
24761
+ console.log('[updateSubChannelUnreadFromMessage] cachedUnreadCount => ', cachedUnreadCount);
24752
24762
  if (!cachedUnreadCount)
24753
24763
  return;
24754
24764
  const lastSegment = cachedUnreadCount.lastSegment < message.segment
24755
24765
  ? message.segment
24756
24766
  : cachedUnreadCount.lastSegment;
24757
24767
  const unreadCount = lastSegment - cachedUnreadCount.readToSegment;
24768
+ console.log('[updateSubChannelUnreadFromMessage] unreadCount => ', unreadCount);
24758
24769
  let { lastMentionSegment } = cachedUnreadCount;
24759
24770
  if (message.mentionedUsers && message.mentionedUsers.length > 0) {
24760
24771
  message.mentionedUsers.forEach(mention => {
@@ -24766,6 +24777,7 @@ const updateSubChannelUnreadFromMessage = (message) => {
24766
24777
  }
24767
24778
  const updatedCachedUnreadCount = Object.assign(Object.assign({}, cachedUnreadCount), { lastMentionSegment,
24768
24779
  lastSegment, isMentioned: !(cachedUnreadCount.readToSegment >= lastMentionSegment), unreadCount: Math.max(unreadCount, 0) });
24780
+ console.log('[updateSubChannelUnreadFromMessage] updatedCachedUnreadCount => key', cacheKeyUnreadCount, 'value =>', updatedCachedUnreadCount);
24769
24781
  pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
24770
24782
  };
24771
24783
 
@@ -24826,6 +24838,7 @@ const onMessageCreatedMqtt = (callback) => {
24826
24838
  const user = getActiveUser();
24827
24839
  const filter = async (rawPayload) => {
24828
24840
  const payload = await prepareMessagePayload(rawPayload);
24841
+ console.log('onMessageCreatedMqtt', payload);
24829
24842
  // update unreadCountInfo in cache
24830
24843
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
24831
24844
  rawPayload.messages.forEach(message => {
@@ -29425,16 +29438,19 @@ function isCurrentUserPartOfCommunity(c, m) {
29425
29438
  }
29426
29439
  /*
29427
29440
  * For mqtt events server will not send user specific data as it's broadcasted
29428
- * to multiple users. Althought this can be calculated, it's not scalable. Hence
29429
- * the client SDK needs to calculate this info
29441
+ * to multiple users and it also does not include communityUser
29442
+ *
29443
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
29444
+ * Althought this can be calculated, it's not scalable.
29430
29445
  */
29431
29446
  function updateMembershipStatus(communities, communityUsers) {
29432
29447
  return communities.map(c => {
29433
- if (c.isJoined == null) {
29434
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
29435
- return Object.assign(Object.assign({}, c), { isJoined });
29448
+ const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
29449
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
29450
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
29436
29451
  }
29437
- return c;
29452
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
29453
+ return Object.assign(Object.assign({}, c), { isJoined });
29438
29454
  });
29439
29455
  }
29440
29456
 
@@ -29782,7 +29798,8 @@ const createPostEventSubscriber = (event, callback) => {
29782
29798
  else {
29783
29799
  const data = preparePostPayload(payload);
29784
29800
  const { communities } = data;
29785
- ingestInCache(data);
29801
+ // NOTE: The event data should be merge with existing cache rather than replace it
29802
+ ingestInCache(data, undefined, false);
29786
29803
  if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
29787
29804
  fireEvent('community.updated', {
29788
29805
  communities,
@@ -30048,7 +30065,8 @@ const createCommentEventSubscriber = (event, callback) => {
30048
30065
  const processed = ['comment.flagged', 'comment.unflagged'].includes(event)
30049
30066
  ? prepareCommentFromFlaggedEvent(payload)
30050
30067
  : payload;
30051
- ingestInCache(processed);
30068
+ // NOTE: The event data should be merge with existing cache rather than replace it
30069
+ ingestInCache(processed, undefined, false);
30052
30070
  const { comments } = processed;
30053
30071
  if (comments.length > 0) {
30054
30072
  const comment = pullFromCache([
@@ -30926,7 +30944,7 @@ const createChannel = async (bundle) => {
30926
30944
  ingestInCache(data, { cachedAt });
30927
30945
  const { channels } = data;
30928
30946
  return {
30929
- data: channels[0],
30947
+ data: constructChannelDynamicValue(channels[0]),
30930
30948
  cachedAt,
30931
30949
  };
30932
30950
  };
@@ -30960,7 +30978,7 @@ const updateChannel = async (channelId, patch) => {
30960
30978
  ingestInCache(data, { cachedAt });
30961
30979
  const { channels } = data;
30962
30980
  return {
30963
- data: channels.find(channel => channel.channelId === channelId),
30981
+ data: constructChannelDynamicValue(channels.find(channel => channel.channelId === channelId)),
30964
30982
  cachedAt,
30965
30983
  };
30966
30984
  };
@@ -31004,7 +31022,7 @@ const getChannel$1 = async (channelId) => {
31004
31022
  ingestInCache(data, { cachedAt });
31005
31023
  const { channels } = data;
31006
31024
  return {
31007
- data: channels.find(channel => channel.channelId === channelId),
31025
+ data: constructChannelDynamicValue(channels.find(channel => channel.channelId === channelId)),
31008
31026
  cachedAt,
31009
31027
  };
31010
31028
  };
@@ -31034,7 +31052,7 @@ getChannel$1.locally = (channelId) => {
31034
31052
  if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
31035
31053
  return;
31036
31054
  return {
31037
- data: cached[0].data,
31055
+ data: constructChannelDynamicValue(cached[0].data),
31038
31056
  cachedAt: cached[0].cachedAt,
31039
31057
  };
31040
31058
  };
@@ -31232,10 +31250,10 @@ const observeChannel = (channelId, callback) => {
31232
31250
  if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
31233
31251
  return;
31234
31252
  if (callback instanceof Function)
31235
- return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
31253
+ return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31236
31254
  if (action !== 'onFetch')
31237
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
31238
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
31255
+ (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31256
+ (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
31239
31257
  };
31240
31258
  const disposers = [];
31241
31259
  disposers.push(onChannelUpdated(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router({ data, loading: false, origin: 'event' }, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router({ data, loading: false, origin: 'event' }, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router({ data, loading: false, origin: 'event' }, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router({ data, loading: false, origin: 'event' }, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router({ data, loading: false, origin: 'event' }, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router({ data, loading: false, origin: 'event' }, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router({ data, loading: false, origin: 'event' }, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
@@ -31269,9 +31287,9 @@ const observeChannels = (callback) => {
31269
31287
  const router = (channel, action) => {
31270
31288
  var _a, _b;
31271
31289
  if (callback instanceof Function)
31272
- return callback(LinkedObject.channel(channel));
31273
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(channel));
31274
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(channel));
31290
+ return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
31291
+ (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
31292
+ (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
31275
31293
  };
31276
31294
  disposers.push(onChannelCreated(data => router(data, "onCreate" /* Amity.ChannelActionType.OnCreate */)), onChannelUpdated(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)), onChannelDeleted(data => router(data, "onDelete" /* Amity.ChannelActionType.OnDelete */)), onChannelJoined(data => router(data, "onJoin" /* Amity.ChannelActionType.OnJoin */)), onChannelLeft(data => router(data, "onLeft" /* Amity.ChannelActionType.OnLeft */)), onChannelMuted(data => router(data, "onMute" /* Amity.ChannelActionType.OnMute */)), onChannelMemberAdded(data => router(data, "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */)), onChannelMemberRemoved(data => router(data, "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */)), convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel')(data => router(data, "onUpdate" /* Amity.ChannelActionType.OnUpdate */)));
31277
31295
  return () => {
@@ -31376,7 +31394,7 @@ const onSubChannelUpdated = (callback) => {
31376
31394
  function updateChannelCache(channel, params) {
31377
31395
  pushToCache(['channel', 'get', channel.channelId],
31378
31396
  // eslint-disable-next-line prefer-object-spread
31379
- Object.assign(shallowClone(channel), params));
31397
+ shallowClone(channel, params));
31380
31398
  }
31381
31399
 
31382
31400
  /**
@@ -33858,6 +33876,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33858
33876
  .filter(Boolean)
33859
33877
  .map(({ data }) => data)
33860
33878
  .map(getChannelMessagePreviewWithUser)
33879
+ .map(constructChannelDynamicValue)
33861
33880
  .map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
33862
33881
  if (this.paginationController instanceof ChannelPaginationController) {
33863
33882
  data = this.applyFilter(data);
@@ -33948,6 +33967,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33948
33967
  'get',
33949
33968
  message.channelId,
33950
33969
  ])) === null || _a === void 0 ? void 0 : _a.data;
33970
+ console.log('channel cache data => ', cacheData);
33951
33971
  if (!cacheData) {
33952
33972
  const objectResolverEngine = ObjectResolverEngine$1.getInstance();
33953
33973
  // channelId from message event payload is channelInternalId
@@ -34400,7 +34420,11 @@ const onUserDeleted$1 = (channelId) => (callback) => {
34400
34420
  channelUserCacheKey,
34401
34421
  ])) === null || _a === void 0 ? void 0 : _a.data;
34402
34422
  upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
34403
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
34423
+ const channel = (_b = pullFromCache([
34424
+ 'channel',
34425
+ 'get',
34426
+ channelId,
34427
+ ])) === null || _b === void 0 ? void 0 : _b.data;
34404
34428
  if (!channel)
34405
34429
  return;
34406
34430
  callback(channel, cacheData);
@@ -35338,7 +35362,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
35338
35362
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
35339
35363
  }
35340
35364
  else {
35341
- ingestInCache(preparedPayload);
35365
+ // NOTE: The event payload should be merge with existing cache data
35366
+ ingestInCache(preparedPayload, undefined, false);
35342
35367
  const community = pullFromCache([
35343
35368
  'community',
35344
35369
  'get',
@@ -35375,7 +35400,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
35375
35400
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
35376
35401
  }
35377
35402
  else {
35378
- ingestInCache(preparedPayload);
35403
+ // NOTE: The event payload should be merge with existing cache data
35404
+ ingestInCache(preparedPayload, undefined, false);
35379
35405
  const community = pullFromCache([
35380
35406
  'community',
35381
35407
  'get',