@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.cjs.js CHANGED
@@ -123,8 +123,8 @@ const PostContentType = Object.freeze({
123
123
 
124
124
  function getVersion() {
125
125
  try {
126
- // the string ''v6.32.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
- return 'v6.32.1-cjs';
126
+ // the string ''v6.32.3-cjs'' should be replaced by actual value by @rollup/plugin-replace
127
+ return 'v6.32.3-cjs';
128
128
  }
129
129
  catch (error) {
130
130
  return '__dev__';
@@ -1736,6 +1736,7 @@ const createHttpTransport = (endpoint) => {
1736
1736
  * https://github.com/axios/axios#request-config
1737
1737
  */
1738
1738
  });
1739
+ instance.defaults.withCredentials = false;
1739
1740
  instance.interceptors.request.use(config => {
1740
1741
  // do not check expiration for token creation url
1741
1742
  if (config.url === '/api/v5/sessions') {
@@ -5646,6 +5647,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
5646
5647
  var _a;
5647
5648
  const cacheKeyChannelUnread = ['channelUnreadInfo', 'get', channelId];
5648
5649
  const cacheChannelUnreadInfo = (_a = pullFromCache(cacheKeyChannelUnread)) === null || _a === void 0 ? void 0 : _a.data;
5650
+ console.log('[reCalculateChannelUnreadInfo] cacheChannelUnreadInfo => ', cacheChannelUnreadInfo);
5649
5651
  const cacheKeySubChannelUnread = ['subChannelUnreadInfo', 'get'];
5650
5652
  const cachedSubChannelUnreadInfo = queryCache(cacheKeySubChannelUnread);
5651
5653
  let channelUnreads = 0;
@@ -5654,9 +5656,11 @@ const reCalculateChannelUnreadInfo = (channelId) => {
5654
5656
  const subChannelUnreadsInfo = cachedSubChannelUnreadInfo === null || cachedSubChannelUnreadInfo === void 0 ? void 0 : cachedSubChannelUnreadInfo.filter(({ data }) => {
5655
5657
  return data.channelId === channelId && !data.isDeleted;
5656
5658
  });
5659
+ console.log('[reCalculateChannelUnreadInfo] subChannelUnreadsInfo => ', subChannelUnreadsInfo);
5657
5660
  channelUnreads = subChannelUnreadsInfo
5658
5661
  .map(({ data }) => data.unreadCount)
5659
5662
  .reduce((acc, cur) => acc + cur, 0);
5663
+ console.log('[reCalculateChannelUnreadInfo] channelUnreads => ', channelUnreads);
5660
5664
  isMentioned = subChannelUnreadsInfo.some(({ data }) => data.isMentioned);
5661
5665
  }
5662
5666
  const channelUnreadInfo = Object.assign(Object.assign({}, (cacheChannelUnreadInfo !== null && cacheChannelUnreadInfo !== void 0 ? cacheChannelUnreadInfo : {
@@ -5942,8 +5946,28 @@ const markAsRead = async (channelId) => {
5942
5946
  return true;
5943
5947
  };
5944
5948
 
5949
+ /**
5950
+ * ```js
5951
+ * import { shallowClone } from '~/utils/shallowClone'
5952
+ * const newObj = shallowClone(obj)
5953
+ * ```
5954
+ *
5955
+ * Clone an object with same prototype and properties
5956
+ *
5957
+ * @param obj the object to clone
5958
+ * @returns new object with same prototype and properties
5959
+ *
5960
+ * @category utility
5961
+ * @private
5962
+ */
5963
+ function shallowClone(source, target) {
5964
+ return Object.create(Object.getPrototypeOf(source), Object.assign(Object.assign({}, Object.getOwnPropertyDescriptors(source)), Object.getOwnPropertyDescriptors(target)));
5965
+ }
5966
+
5945
5967
  const channelLinkedObject = (channel) => {
5946
- return Object.assign(Object.assign({}, channel), { markAsRead: () => markAsRead(channel.channelInternalId) });
5968
+ return shallowClone(channel, {
5969
+ markAsRead: () => markAsRead(channel.channelInternalId),
5970
+ });
5947
5971
  };
5948
5972
 
5949
5973
  const adLinkedObject = (ad) => {
@@ -6114,31 +6138,10 @@ const updateSubChannelMessagePreviewCache = (rawPayload) => {
6114
6138
  ingestInCache(newData);
6115
6139
  };
6116
6140
 
6117
- /**
6118
- * ```js
6119
- * import { shallowClone } from '~/utils/shallowClone'
6120
- * const newObj = shallowClone(obj)
6121
- * ```
6122
- *
6123
- * Clone an object with same prototype and properties
6124
- *
6125
- * @param obj the object to clone
6126
- * @returns new object with same prototype and properties
6127
- *
6128
- * @category utility
6129
- * @private
6130
- */
6131
- function shallowClone(obj) {
6132
- const clone = Object.create(Object.getPrototypeOf(obj));
6133
- const descriptors = Object.getOwnPropertyDescriptors(obj);
6134
- Object.defineProperties(clone, descriptors);
6135
- return clone;
6136
- }
6137
-
6138
6141
  function updateSubChannelCache(subChannelId, subChannel, params) {
6139
6142
  pushToCache(['subChannel', 'get', subChannelId],
6140
6143
  // eslint-disable-next-line prefer-object-spread
6141
- Object.assign(shallowClone(subChannel), params));
6144
+ shallowClone(subChannel, params));
6142
6145
  }
6143
6146
 
6144
6147
  const handleMessageCreated = async (message) => {
@@ -6317,81 +6320,6 @@ const handleSubChannelUpdated = async (subChannel) => {
6317
6320
  }
6318
6321
  };
6319
6322
 
6320
- const getCachedMarker$1 = (entityId) => {
6321
- var _a;
6322
- const key = {
6323
- entityId,
6324
- userId: getActiveUser()._id,
6325
- };
6326
- return (_a = pullFromCache([
6327
- 'channelMarker',
6328
- 'get',
6329
- getResolver('channelMarker')(key),
6330
- ])) === null || _a === void 0 ? void 0 : _a.data;
6331
- };
6332
- const getUnreadInfoCached$1 = (channelId) => {
6333
- var _a;
6334
- return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
6335
- };
6336
- /**
6337
- * The function use to get value of unreadCount field.
6338
- * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
6339
- *
6340
- * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
6341
- * If not, the function will return the value from the channelMarker cache.
6342
- * If not found in the both cache, use `0` as defaul value.
6343
- */
6344
- const getSubChannelsUnreadCount = (channel, marker) => {
6345
- var _a, _b, _c, _d, _e;
6346
- const client = getActiveClient();
6347
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6348
- // Marker service API uses channelInternalId as channelId
6349
- return (_b = (_a = getUnreadInfoCached$1(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
6350
- }
6351
- if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
6352
- // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
6353
- // leave the channel because currently backend can't handle this, so every time a user is banned
6354
- // from a channel or the channel is deleted the channel's unread count will reset to zero
6355
- return 0;
6356
- }
6357
- 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;
6358
- };
6359
-
6360
- const getCachedMarker = (entityId) => {
6361
- var _a;
6362
- const key = {
6363
- entityId,
6364
- userId: getActiveUser()._id,
6365
- };
6366
- return (_a = pullFromCache([
6367
- 'channelMarker',
6368
- 'get',
6369
- getResolver('channelMarker')(key),
6370
- ])) === null || _a === void 0 ? void 0 : _a.data;
6371
- };
6372
- const getUnreadInfoCached = (channelId) => {
6373
- var _a;
6374
- return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
6375
- };
6376
- /**
6377
- * The function use to get value of hasMentioned or isMentioned field.
6378
- * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
6379
- *
6380
- * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
6381
- * If not, the function will return the value from the channelMarker cache.
6382
- * If not found in the both cache, use `false` as defaul value.
6383
- */
6384
- const getChannelIsMentioned = (channel, marker) => {
6385
- var _a, _b, _c, _d;
6386
- const client = getActiveClient();
6387
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6388
- return (_b = (_a = getUnreadInfoCached(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
6389
- }
6390
- return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
6391
- ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
6392
- : (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
6393
- };
6394
-
6395
6323
  function convertRawUserToInternalUser(rawUser) {
6396
6324
  return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
6397
6325
  }
@@ -6409,18 +6337,7 @@ function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true })
6409
6337
  if ((messagePreviewChannelCache === null || messagePreviewChannelCache === void 0 ? void 0 : messagePreviewChannelCache.messagePreviewId) && !options.isMessagePreviewUpdated) {
6410
6338
  messagePreviewId = messagePreviewChannelCache.messagePreviewId;
6411
6339
  }
6412
- return Object.assign(Object.assign({ get unreadCount() {
6413
- return getSubChannelsUnreadCount(channel);
6414
- },
6415
- get hasMentioned() {
6416
- return getChannelIsMentioned(channel);
6417
- },
6418
- get isMentioned() {
6419
- return getChannelIsMentioned(channel);
6420
- },
6421
- get subChannelsUnreadCount() {
6422
- return getSubChannelsUnreadCount(channel);
6423
- } }, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
6340
+ return Object.assign(Object.assign({}, channel), { defaultSubChannelId: channel.channelInternalId, isUnreadCountSupport: isUnreadCountSupport$2(channel), messagePreviewId });
6424
6341
  }
6425
6342
  const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated: true }) => {
6426
6343
  ingestInCache({
@@ -6542,6 +6459,98 @@ const prepareUnreadCountInfo = async (rawPayload) => {
6542
6459
  client.log('channel/prepareUnreadCountInfo', rawPayload.channels);
6543
6460
  };
6544
6461
 
6462
+ const getCachedMarker$1 = (entityId) => {
6463
+ var _a;
6464
+ const key = {
6465
+ entityId,
6466
+ userId: getActiveUser()._id,
6467
+ };
6468
+ return (_a = pullFromCache([
6469
+ 'channelMarker',
6470
+ 'get',
6471
+ getResolver('channelMarker')(key),
6472
+ ])) === null || _a === void 0 ? void 0 : _a.data;
6473
+ };
6474
+ const getUnreadInfoCached$1 = (channelId) => {
6475
+ var _a;
6476
+ return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
6477
+ };
6478
+ /**
6479
+ * The function use to get value of hasMentioned or isMentioned field.
6480
+ * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
6481
+ *
6482
+ * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
6483
+ * If not, the function will return the value from the channelMarker cache.
6484
+ * If not found in the both cache, use `false` as defaul value.
6485
+ */
6486
+ const getChannelIsMentioned = (channel, marker) => {
6487
+ var _a, _b, _c, _d;
6488
+ const client = getActiveClient();
6489
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6490
+ return (_b = (_a = getUnreadInfoCached$1(channel.channelPublicId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
6491
+ }
6492
+ return (marker === null || marker === void 0 ? void 0 : marker.hasMentioned) !== undefined
6493
+ ? marker === null || marker === void 0 ? void 0 : marker.hasMentioned
6494
+ : (_d = (_c = getCachedMarker$1(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
6495
+ };
6496
+
6497
+ const getCachedMarker = (entityId) => {
6498
+ var _a;
6499
+ const key = {
6500
+ entityId,
6501
+ userId: getActiveUser()._id,
6502
+ };
6503
+ return (_a = pullFromCache([
6504
+ 'channelMarker',
6505
+ 'get',
6506
+ getResolver('channelMarker')(key),
6507
+ ])) === null || _a === void 0 ? void 0 : _a.data;
6508
+ };
6509
+ const getUnreadInfoCached = (channelId) => {
6510
+ var _a;
6511
+ return (_a = pullFromCache(['channelUnreadInfo', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
6512
+ };
6513
+ /**
6514
+ * The function use to get value of unreadCount field.
6515
+ * function will get the value from marker params first, if there is no hasMentioned field, will look in to the cache.
6516
+ *
6517
+ * If consistent mode is enabled, the function will return the value from the channelUnreadCountInfo cache.
6518
+ * If not, the function will return the value from the channelMarker cache.
6519
+ * If not found in the both cache, use `0` as defaul value.
6520
+ */
6521
+ const getSubChannelsUnreadCount = (channel, marker) => {
6522
+ var _a, _b, _c, _d, _e;
6523
+ const client = getActiveClient();
6524
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
6525
+ // Marker service API uses channelInternalId as channelId
6526
+ return (_b = (_a = getUnreadInfoCached(channel.channelInternalId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
6527
+ }
6528
+ if (marker === null || marker === void 0 ? void 0 : marker.isDeleted) {
6529
+ // NOTE: This is a temporary solution to handle the channel marker when the user is forced to
6530
+ // leave the channel because currently backend can't handle this, so every time a user is banned
6531
+ // from a channel or the channel is deleted the channel's unread count will reset to zero
6532
+ return 0;
6533
+ }
6534
+ 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;
6535
+ };
6536
+
6537
+ const constructChannelDynamicValue = (channel) => {
6538
+ return shallowClone(channel, {
6539
+ get unreadCount() {
6540
+ return getSubChannelsUnreadCount(channel);
6541
+ },
6542
+ get hasMentioned() {
6543
+ return getChannelIsMentioned(channel);
6544
+ },
6545
+ get isMentioned() {
6546
+ return getChannelIsMentioned(channel);
6547
+ },
6548
+ get subChannelsUnreadCount() {
6549
+ return getSubChannelsUnreadCount(channel);
6550
+ },
6551
+ });
6552
+ };
6553
+
6545
6554
  /**
6546
6555
  * ```js
6547
6556
  * import { getChannelByIds } from '@amityco/ts-sdk-react-native'
@@ -6586,7 +6595,7 @@ const getChannelByIds = async (channelIds) => {
6586
6595
  ingestInCache(data, { cachedAt });
6587
6596
  fireEvent('local.channel.fetched', data.channels);
6588
6597
  return {
6589
- data: data.channels.map(channel => LinkedObject.channel(channel)),
6598
+ data: data.channels.map(channel => LinkedObject.channel(constructChannelDynamicValue(channel))),
6590
6599
  cachedAt,
6591
6600
  };
6592
6601
  };
@@ -8676,12 +8685,14 @@ const updateSubChannelUnreadFromMessage = (message) => {
8676
8685
  const client = getActiveClient();
8677
8686
  const cacheKeyUnreadCount = ['subChannelUnreadInfo', 'get', message.messageFeedId];
8678
8687
  const cachedUnreadCount = (_a = pullFromCache(cacheKeyUnreadCount)) === null || _a === void 0 ? void 0 : _a.data;
8688
+ console.log('[updateSubChannelUnreadFromMessage] cachedUnreadCount => ', cachedUnreadCount);
8679
8689
  if (!cachedUnreadCount)
8680
8690
  return;
8681
8691
  const lastSegment = cachedUnreadCount.lastSegment < message.segment
8682
8692
  ? message.segment
8683
8693
  : cachedUnreadCount.lastSegment;
8684
8694
  const unreadCount = lastSegment - cachedUnreadCount.readToSegment;
8695
+ console.log('[updateSubChannelUnreadFromMessage] unreadCount => ', unreadCount);
8685
8696
  let { lastMentionSegment } = cachedUnreadCount;
8686
8697
  if (message.mentionedUsers && message.mentionedUsers.length > 0) {
8687
8698
  message.mentionedUsers.forEach(mention => {
@@ -8693,6 +8704,7 @@ const updateSubChannelUnreadFromMessage = (message) => {
8693
8704
  }
8694
8705
  const updatedCachedUnreadCount = Object.assign(Object.assign({}, cachedUnreadCount), { lastMentionSegment,
8695
8706
  lastSegment, isMentioned: !(cachedUnreadCount.readToSegment >= lastMentionSegment), unreadCount: Math.max(unreadCount, 0) });
8707
+ console.log('[updateSubChannelUnreadFromMessage] updatedCachedUnreadCount => key', cacheKeyUnreadCount, 'value =>', updatedCachedUnreadCount);
8696
8708
  pushToCache(cacheKeyUnreadCount, updatedCachedUnreadCount);
8697
8709
  };
8698
8710
 
@@ -8753,6 +8765,7 @@ const onMessageCreatedMqtt = (callback) => {
8753
8765
  const user = getActiveUser();
8754
8766
  const filter = async (rawPayload) => {
8755
8767
  const payload = await prepareMessagePayload(rawPayload);
8768
+ console.log('onMessageCreatedMqtt', payload);
8756
8769
  // update unreadCountInfo in cache
8757
8770
  if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
8758
8771
  rawPayload.messages.forEach(message => {
@@ -13352,16 +13365,19 @@ function isCurrentUserPartOfCommunity(c, m) {
13352
13365
  }
13353
13366
  /*
13354
13367
  * For mqtt events server will not send user specific data as it's broadcasted
13355
- * to multiple users. Althought this can be calculated, it's not scalable. Hence
13356
- * the client SDK needs to calculate this info
13368
+ * to multiple users and it also does not include communityUser
13369
+ *
13370
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
13371
+ * Althought this can be calculated, it's not scalable.
13357
13372
  */
13358
13373
  function updateMembershipStatus(communities, communityUsers) {
13359
13374
  return communities.map(c => {
13360
- if (c.isJoined == null) {
13361
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13362
- return Object.assign(Object.assign({}, c), { isJoined });
13375
+ const cachedCommunity = pullFromCache(['community', 'get', c.communityId]);
13376
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
13377
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
13363
13378
  }
13364
- return c;
13379
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13380
+ return Object.assign(Object.assign({}, c), { isJoined });
13365
13381
  });
13366
13382
  }
13367
13383
 
@@ -13709,7 +13725,8 @@ const createPostEventSubscriber = (event, callback) => {
13709
13725
  else {
13710
13726
  const data = preparePostPayload(payload);
13711
13727
  const { communities } = data;
13712
- ingestInCache(data);
13728
+ // NOTE: The event data should be merge with existing cache rather than replace it
13729
+ ingestInCache(data, undefined, false);
13713
13730
  if ((communities === null || communities === void 0 ? void 0 : communities[0]) && !['post.updated'].includes(event)) {
13714
13731
  fireEvent('community.updated', {
13715
13732
  communities,
@@ -13975,7 +13992,8 @@ const createCommentEventSubscriber = (event, callback) => {
13975
13992
  const processed = ['comment.flagged', 'comment.unflagged'].includes(event)
13976
13993
  ? prepareCommentFromFlaggedEvent(payload)
13977
13994
  : payload;
13978
- ingestInCache(processed);
13995
+ // NOTE: The event data should be merge with existing cache rather than replace it
13996
+ ingestInCache(processed, undefined, false);
13979
13997
  const { comments } = processed;
13980
13998
  if (comments.length > 0) {
13981
13999
  const comment = pullFromCache([
@@ -14853,7 +14871,7 @@ const createChannel = async (bundle) => {
14853
14871
  ingestInCache(data, { cachedAt });
14854
14872
  const { channels } = data;
14855
14873
  return {
14856
- data: channels[0],
14874
+ data: constructChannelDynamicValue(channels[0]),
14857
14875
  cachedAt,
14858
14876
  };
14859
14877
  };
@@ -14887,7 +14905,7 @@ const updateChannel = async (channelId, patch) => {
14887
14905
  ingestInCache(data, { cachedAt });
14888
14906
  const { channels } = data;
14889
14907
  return {
14890
- data: channels.find(channel => channel.channelId === channelId),
14908
+ data: constructChannelDynamicValue(channels.find(channel => channel.channelId === channelId)),
14891
14909
  cachedAt,
14892
14910
  };
14893
14911
  };
@@ -14931,7 +14949,7 @@ const getChannel$1 = async (channelId) => {
14931
14949
  ingestInCache(data, { cachedAt });
14932
14950
  const { channels } = data;
14933
14951
  return {
14934
- data: channels.find(channel => channel.channelId === channelId),
14952
+ data: constructChannelDynamicValue(channels.find(channel => channel.channelId === channelId)),
14935
14953
  cachedAt,
14936
14954
  };
14937
14955
  };
@@ -14961,7 +14979,7 @@ getChannel$1.locally = (channelId) => {
14961
14979
  if (!cached || (cached === null || cached === void 0 ? void 0 : cached.length) === 0)
14962
14980
  return;
14963
14981
  return {
14964
- data: cached[0].data,
14982
+ data: constructChannelDynamicValue(cached[0].data),
14965
14983
  cachedAt: cached[0].cachedAt,
14966
14984
  };
14967
14985
  };
@@ -15159,10 +15177,10 @@ const observeChannel = (channelId, callback) => {
15159
15177
  if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.channelId) !== channelId)
15160
15178
  return;
15161
15179
  if (callback instanceof Function)
15162
- return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
15180
+ return callback(Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
15163
15181
  if (action !== 'onFetch')
15164
- (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
15165
- (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(result.data) }));
15182
+ (_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
15183
+ (_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, Object.assign(Object.assign({}, result), { data: LinkedObject.channel(constructChannelDynamicValue(result.data)) }));
15166
15184
  };
15167
15185
  const disposers = [];
15168
15186
  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 */)));
@@ -15196,9 +15214,9 @@ const observeChannels = (callback) => {
15196
15214
  const router = (channel, action) => {
15197
15215
  var _a, _b;
15198
15216
  if (callback instanceof Function)
15199
- return callback(LinkedObject.channel(channel));
15200
- (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(channel));
15201
- (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(channel));
15217
+ return callback(LinkedObject.channel(constructChannelDynamicValue(channel)));
15218
+ (_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, LinkedObject.channel(constructChannelDynamicValue(channel)));
15219
+ (_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, LinkedObject.channel(constructChannelDynamicValue(channel)));
15202
15220
  };
15203
15221
  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 */)));
15204
15222
  return () => {
@@ -15303,7 +15321,7 @@ const onSubChannelUpdated = (callback) => {
15303
15321
  function updateChannelCache(channel, params) {
15304
15322
  pushToCache(['channel', 'get', channel.channelId],
15305
15323
  // eslint-disable-next-line prefer-object-spread
15306
- Object.assign(shallowClone(channel), params));
15324
+ shallowClone(channel, params));
15307
15325
  }
15308
15326
 
15309
15327
  /**
@@ -17785,6 +17803,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
17785
17803
  .filter(Boolean)
17786
17804
  .map(({ data }) => data)
17787
17805
  .map(getChannelMessagePreviewWithUser)
17806
+ .map(constructChannelDynamicValue)
17788
17807
  .map(LinkedObject.channel)) !== null && _b !== void 0 ? _b : [];
17789
17808
  if (this.paginationController instanceof ChannelPaginationController) {
17790
17809
  data = this.applyFilter(data);
@@ -17875,6 +17894,7 @@ class ChannelLiveCollectionController extends LiveCollectionController {
17875
17894
  'get',
17876
17895
  message.channelId,
17877
17896
  ])) === null || _a === void 0 ? void 0 : _a.data;
17897
+ console.log('channel cache data => ', cacheData);
17878
17898
  if (!cacheData) {
17879
17899
  const objectResolverEngine = ObjectResolverEngine$1.getInstance();
17880
17900
  // channelId from message event payload is channelInternalId
@@ -18327,7 +18347,11 @@ const onUserDeleted$1 = (channelId) => (callback) => {
18327
18347
  channelUserCacheKey,
18328
18348
  ])) === null || _a === void 0 ? void 0 : _a.data;
18329
18349
  upsertInCache(['channelUsers', 'get', channelUserCacheKey], Object.assign(Object.assign({}, cacheData), { user }));
18330
- const channel = (_b = pullFromCache(['channel', 'get', channelId])) === null || _b === void 0 ? void 0 : _b.data;
18350
+ const channel = (_b = pullFromCache([
18351
+ 'channel',
18352
+ 'get',
18353
+ channelId,
18354
+ ])) === null || _b === void 0 ? void 0 : _b.data;
18331
18355
  if (!channel)
18332
18356
  return;
18333
18357
  callback(channel, cacheData);
@@ -19265,7 +19289,8 @@ const createCommunityMemberEventSubscriber = (event, callback) => {
19265
19289
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19266
19290
  }
19267
19291
  else {
19268
- ingestInCache(preparedPayload);
19292
+ // NOTE: The event payload should be merge with existing cache data
19293
+ ingestInCache(preparedPayload, undefined, false);
19269
19294
  const community = pullFromCache([
19270
19295
  'community',
19271
19296
  'get',
@@ -19302,7 +19327,8 @@ const createLocalCommunityMemberEventSubscriber = (event, callback) => {
19302
19327
  callback(preparedPayload.communities[0], getEventRelatedMember(event, preparedPayload));
19303
19328
  }
19304
19329
  else {
19305
- ingestInCache(preparedPayload);
19330
+ // NOTE: The event payload should be merge with existing cache data
19331
+ ingestInCache(preparedPayload, undefined, false);
19306
19332
  const community = pullFromCache([
19307
19333
  'community',
19308
19334
  'get',