@amityco/ts-sdk 7.1.1-e23f973a.0 → 7.2.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 (152) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/events.d.ts +2 -5
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +2 -4
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +0 -18
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/core/readReceipt.d.ts +12 -1
  9. package/dist/@types/core/readReceipt.d.ts.map +1 -1
  10. package/dist/@types/domains/channel.d.ts +10 -0
  11. package/dist/@types/domains/channel.d.ts.map +1 -1
  12. package/dist/@types/domains/client.d.ts +2 -0
  13. package/dist/@types/domains/client.d.ts.map +1 -1
  14. package/dist/@types/index.d.ts +0 -1
  15. package/dist/@types/index.d.ts.map +1 -1
  16. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +16 -0
  17. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +1 -0
  18. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  19. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  20. package/dist/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
  21. package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
  22. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
  23. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
  24. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  25. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  26. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +20 -0
  27. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +1 -0
  28. package/dist/channelRepository/observers/index.d.ts +1 -0
  29. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  30. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
  31. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +2 -0
  32. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +1 -0
  33. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  34. package/dist/client/api/createClient.d.ts +1 -0
  35. package/dist/client/api/createClient.d.ts.map +1 -1
  36. package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
  37. package/dist/client/api/login.d.ts.map +1 -1
  38. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +33 -0
  39. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
  40. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +3 -0
  41. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  42. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +2 -4
  43. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  44. package/dist/client/utils/endpoints.d.ts +1 -0
  45. package/dist/client/utils/endpoints.d.ts.map +1 -1
  46. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  47. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  48. package/dist/core/events.d.ts +3 -3
  49. package/dist/core/events.d.ts.map +1 -1
  50. package/dist/core/model/idResolvers.d.ts.map +1 -1
  51. package/dist/core/model/index.d.ts.map +1 -1
  52. package/dist/index.cjs.js +657 -474
  53. package/dist/index.d.ts +0 -1
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.esm.js +639 -455
  56. package/dist/index.umd.js +4 -4
  57. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +12 -0
  58. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +1 -0
  59. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  60. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  61. package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
  62. package/dist/utils/linkedObject/index.d.ts +0 -1
  63. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  64. package/package.json +1 -1
  65. package/src/@types/core/events.ts +2 -6
  66. package/src/@types/core/model.ts +4 -6
  67. package/src/@types/core/payload.ts +0 -25
  68. package/src/@types/core/readReceipt.ts +14 -1
  69. package/src/@types/domains/channel.ts +13 -0
  70. package/src/@types/domains/client.ts +3 -0
  71. package/src/@types/index.ts +0 -1
  72. package/src/channelRepository/api/markChannelsAsReadBySegment.ts +29 -0
  73. package/src/channelRepository/events/onChannelDeleted.ts +17 -4
  74. package/src/channelRepository/events/onChannelLeft.ts +11 -3
  75. package/src/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.ts +3 -3
  76. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
  77. package/src/channelRepository/observers/getChannel.ts +3 -1
  78. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -1
  79. package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
  80. package/src/channelRepository/observers/index.ts +1 -0
  81. package/src/channelRepository/utils/constructChannelDynamicValue.ts +12 -2
  82. package/src/channelRepository/utils/getLegacyChannelUnread.ts +5 -0
  83. package/src/channelRepository/utils/prepareChannelPayload.ts +68 -17
  84. package/src/client/api/createClient.ts +7 -1
  85. package/src/client/api/enableUnreadCount.ts +1 -0
  86. package/src/client/api/login.ts +5 -1
  87. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +267 -0
  88. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +21 -0
  89. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +74 -99
  90. package/src/client/utils/endpoints.ts +1 -0
  91. package/src/client/utils/setClientToken.ts +8 -0
  92. package/src/commentRepository/events/utils.ts +73 -0
  93. package/src/core/model/idResolvers.ts +2 -3
  94. package/src/core/model/index.ts +0 -2
  95. package/src/fileRepository/api/uploadFile.ts +1 -1
  96. package/src/fileRepository/api/uploadImage.ts +1 -1
  97. package/src/fileRepository/api/uploadVideo.ts +1 -1
  98. package/src/index.ts +0 -2
  99. package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +29 -0
  100. package/src/messageRepository/events/onMessageCreated.ts +45 -1
  101. package/src/messageRepository/observers/getMessage.ts +0 -1
  102. package/src/messageRepository/utils/markReadMessage.ts +10 -3
  103. package/src/utils/linkedObject/index.ts +0 -2
  104. package/dist/@types/domains/notification.d.ts +0 -82
  105. package/dist/@types/domains/notification.d.ts.map +0 -1
  106. package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
  107. package/dist/notificationTray/api/index.d.ts +0 -3
  108. package/dist/notificationTray/api/index.d.ts.map +0 -1
  109. package/dist/notificationTray/api/markItemsSeen.d.ts +0 -16
  110. package/dist/notificationTray/api/markItemsSeen.d.ts.map +0 -1
  111. package/dist/notificationTray/api/markTraySeen.d.ts +0 -19
  112. package/dist/notificationTray/api/markTraySeen.d.ts.map +0 -1
  113. package/dist/notificationTray/events/index.d.ts +0 -2
  114. package/dist/notificationTray/events/index.d.ts.map +0 -1
  115. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +0 -17
  116. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +0 -1
  117. package/dist/notificationTray/index.d.ts +0 -4
  118. package/dist/notificationTray/index.d.ts.map +0 -1
  119. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +0 -30
  120. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +0 -1
  121. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +0 -13
  122. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +0 -1
  123. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +0 -9
  124. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +0 -1
  125. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +0 -9
  126. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +0 -1
  127. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +0 -12
  128. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +0 -1
  129. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +0 -21
  130. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +0 -1
  131. package/dist/notificationTray/observers/index.d.ts +0 -3
  132. package/dist/notificationTray/observers/index.d.ts.map +0 -1
  133. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +0 -2
  134. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +0 -1
  135. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +0 -2
  136. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +0 -1
  137. package/src/@types/domains/notification.ts +0 -91
  138. package/src/notificationTray/api/index.ts +0 -2
  139. package/src/notificationTray/api/markItemsSeen.ts +0 -59
  140. package/src/notificationTray/api/markTraySeen.ts +0 -65
  141. package/src/notificationTray/events/index.ts +0 -1
  142. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +0 -36
  143. package/src/notificationTray/index.ts +0 -3
  144. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +0 -81
  145. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +0 -96
  146. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +0 -31
  147. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +0 -68
  148. package/src/notificationTray/observers/getNotificationTrayItems.ts +0 -44
  149. package/src/notificationTray/observers/getNotificationTraySeen.ts +0 -43
  150. package/src/notificationTray/observers/index.ts +0 -2
  151. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +0 -12
  152. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +0 -19
package/dist/index.esm.js CHANGED
@@ -87,8 +87,8 @@ const PostContentType = Object.freeze({
87
87
 
88
88
  function getVersion() {
89
89
  try {
90
- // the string ''v7.1.0-esm'' should be replaced by actual value by @rollup/plugin-replace
91
- return 'v7.1.0-esm';
90
+ // the string ''v7.2.0-esm'' should be replaced by actual value by @rollup/plugin-replace
91
+ return 'v7.2.0-esm';
92
92
  }
93
93
  catch (error) {
94
94
  return '__dev__';
@@ -106,7 +106,6 @@ const SECOND$1 = 1000;
106
106
  const MINUTE = 60 * SECOND$1;
107
107
  const HOUR = 60 * MINUTE;
108
108
  const DAY = 24 * HOUR;
109
- const WEEK = 7 * DAY;
110
109
  const YEAR = 365 * DAY;
111
110
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
112
111
 
@@ -502,6 +501,7 @@ const idResolvers = {
502
501
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
503
502
  channelUnreadInfo: ({ channelId }) => channelId,
504
503
  subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
504
+ channelUnread: ({ channelId }) => channelId,
505
505
  channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
506
506
  subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
507
507
  messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
@@ -528,8 +528,6 @@ const idResolvers = {
528
528
  advertiser: ({ advertiserId }) => advertiserId,
529
529
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
530
530
  pinTarget: ({ targetId }) => targetId,
531
- notificationTrayItem: ({ _id }) => _id,
532
- notificationTraySeen: ({ userId }) => userId,
533
531
  };
534
532
  /**
535
533
  * Retrieve the id resolver matching a domain name
@@ -581,7 +579,6 @@ const PAYLOAD2MODEL = {
581
579
  advertisers: 'advertiser',
582
580
  pinTargets: 'pinTarget',
583
581
  pins: 'pin',
584
- notificationTrayItems: 'notificationTrayItem',
585
582
  };
586
583
  /** hidden */
587
584
  const isOutdated = (prevData, nextData) => {
@@ -1550,6 +1547,7 @@ const API_REGIONS = {
1550
1547
  };
1551
1548
  const URLS = {
1552
1549
  http: 'https://apix.{region}.amity.co',
1550
+ upload: 'https://upload.{region}.amity.co',
1553
1551
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1554
1552
  };
1555
1553
  function computeUrl(type, region) {
@@ -1598,13 +1596,13 @@ class NetworkActivitiesWatcher {
1598
1596
  this._listener.clear();
1599
1597
  }
1600
1598
  }
1601
- let instance$5;
1599
+ let instance$6;
1602
1600
  var NetworkActivitiesWatcher$1 = {
1603
1601
  getInstance: () => {
1604
- if (!instance$5) {
1605
- instance$5 = new NetworkActivitiesWatcher();
1602
+ if (!instance$6) {
1603
+ instance$6 = new NetworkActivitiesWatcher();
1606
1604
  }
1607
- return instance$5;
1605
+ return instance$6;
1608
1606
  },
1609
1607
  };
1610
1608
 
@@ -21244,13 +21242,13 @@ class AnalyticsEngine {
21244
21242
  this._eventCapturer.resetAllBuckets();
21245
21243
  }
21246
21244
  }
21247
- let instance$4;
21245
+ let instance$5;
21248
21246
  var AnalyticsEngine$1 = {
21249
21247
  getInstance: () => {
21250
- if (!instance$4) {
21251
- instance$4 = new AnalyticsEngine();
21248
+ if (!instance$5) {
21249
+ instance$5 = new AnalyticsEngine();
21252
21250
  }
21253
- return instance$4;
21251
+ return instance$5;
21254
21252
  },
21255
21253
  };
21256
21254
 
@@ -21676,6 +21674,223 @@ const getMessageReadCount = (message, marker) => {
21676
21674
  getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
21677
21675
  }; // and if not found in cache use default value `0`
21678
21676
 
21677
+ /**
21678
+ *
21679
+ * Mark subChannel as read by readToSegment
21680
+ *
21681
+ * @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
21682
+ * @param readToSegment the segment to mark as read
21683
+ * @returns a success boolean if the {@link Amity.SubChannel} was updated
21684
+ *
21685
+ * @category Channel API
21686
+ * @async
21687
+ */
21688
+ const markChannelsAsReadBySegment = async (readings) => {
21689
+ const client = getActiveClient();
21690
+ try {
21691
+ await client.http.post('api/v3/channels/seen', { channels: readings });
21692
+ return true;
21693
+ }
21694
+ catch (e) {
21695
+ return false;
21696
+ }
21697
+ };
21698
+
21699
+ class MessageReadReceiptSyncEngine {
21700
+ constructor() {
21701
+ this.isActive = true;
21702
+ this.MAX_RETRY = 3;
21703
+ this.JOB_QUEUE_SIZE = 120;
21704
+ this.jobQueue = [];
21705
+ // Interval for message read receipt sync in seconds
21706
+ this.RECEIPT_SYNC_INTERVAL = 1;
21707
+ this.client = getActiveClient();
21708
+ // Get remaining unsync read receipts from cache
21709
+ this.getUnsyncJobs();
21710
+ }
21711
+ // Call this when client call client.login
21712
+ startSyncReadReceipt() {
21713
+ // Start timer when start receipt sync
21714
+ this.timer = setInterval(() => {
21715
+ this.syncReadReceipts();
21716
+ }, this.RECEIPT_SYNC_INTERVAL * 1000);
21717
+ }
21718
+ // Read receipt observer handling
21719
+ syncReadReceipts() {
21720
+ if (this.jobQueue.length === 0 || this.isActive === false)
21721
+ return;
21722
+ const readReceipts = this.getReadReceipts();
21723
+ if (readReceipts) {
21724
+ this.markReadApi(readReceipts);
21725
+ }
21726
+ }
21727
+ getUnsyncJobs() {
21728
+ var _a;
21729
+ // Get all read receipts that has latestSyncSegment < latestSegment
21730
+ const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21731
+ return data.latestSyncSegment < data.latestSegment;
21732
+ });
21733
+ // Enqueue unsync read receipts to the job queue
21734
+ readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
21735
+ this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
21736
+ });
21737
+ }
21738
+ getReadReceipts() {
21739
+ // get all read receipts from queue, now the queue is empty
21740
+ const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
21741
+ if (syncJob.length === 0)
21742
+ return;
21743
+ return syncJob.filter(job => {
21744
+ var _a;
21745
+ const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
21746
+ if (!readReceipt)
21747
+ return false;
21748
+ if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
21749
+ return true;
21750
+ return false;
21751
+ });
21752
+ }
21753
+ async markReadApi(syncJobs) {
21754
+ var _a;
21755
+ // constuct payload
21756
+ // example: [{ channelId: 'channelId', readToSegment: 2 }]
21757
+ const syncJobsPayload = syncJobs.map(job => {
21758
+ return {
21759
+ channelId: job.channelId,
21760
+ readToSegment: job.segment,
21761
+ };
21762
+ });
21763
+ const response = await markChannelsAsReadBySegment(syncJobsPayload);
21764
+ if (response) {
21765
+ for (let i = 0; i < syncJobs.length; i += 1) {
21766
+ // update lastestSyncSegment in read receipt cache
21767
+ const cacheKey = ['readReceipt', syncJobs[i].channelId];
21768
+ const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21769
+ pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
21770
+ }
21771
+ }
21772
+ else {
21773
+ for (let i = 0; i < syncJobs.length; i += 1) {
21774
+ // push them back to queue if the syncing is failed and retry count is less than max retry
21775
+ if (syncJobs[i].retryCount >= this.MAX_RETRY)
21776
+ return;
21777
+ const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
21778
+ this.enqueueJob(updatedJob);
21779
+ }
21780
+ }
21781
+ }
21782
+ startObservingReadReceiptQueue() {
21783
+ if (this.client.useLegacyUnreadCount) {
21784
+ this.isActive = true;
21785
+ this.startSyncReadReceipt();
21786
+ }
21787
+ }
21788
+ stopObservingReadReceiptQueue() {
21789
+ this.isActive = false;
21790
+ this.jobQueue.map(job => {
21791
+ if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21792
+ return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
21793
+ }
21794
+ return job;
21795
+ });
21796
+ if (this.timer)
21797
+ clearInterval(this.timer);
21798
+ }
21799
+ // Session Management
21800
+ onSessionEstablished() {
21801
+ this.startObservingReadReceiptQueue();
21802
+ }
21803
+ onSessionDestroyed() {
21804
+ this.stopObservingReadReceiptQueue();
21805
+ this.jobQueue = [];
21806
+ }
21807
+ onTokenExpired() {
21808
+ this.stopObservingReadReceiptQueue();
21809
+ }
21810
+ // Network Connection Management
21811
+ onNetworkOffline() {
21812
+ // Stop observing to the read receipt queue.
21813
+ this.stopObservingReadReceiptQueue();
21814
+ }
21815
+ onNetworkOnline() {
21816
+ // Resume observing to the read receipt queue.
21817
+ this.startObservingReadReceiptQueue();
21818
+ }
21819
+ markRead(channelId, segment) {
21820
+ var _a;
21821
+ // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
21822
+ const cacheKey = ['channelUnread', 'get', channelId];
21823
+ const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21824
+ if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
21825
+ channelUnread &&
21826
+ segment > channelUnread.readToSegment) {
21827
+ channelUnread.readToSegment = segment;
21828
+ channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
21829
+ pushToCache(cacheKey, channelUnread);
21830
+ fireEvent('local.channelUnread.updated', channelUnread);
21831
+ }
21832
+ // Step 2: Enqueue the read receipt
21833
+ this.enqueueReadReceipt(channelId, segment);
21834
+ }
21835
+ enqueueReadReceipt(channelId, segment) {
21836
+ var _a;
21837
+ const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
21838
+ // Create new read receipt if it's not exists and add the job to queue
21839
+ if (!readReceipt) {
21840
+ const readReceiptChannel = {
21841
+ channelId,
21842
+ latestSegment: segment,
21843
+ latestSyncSegment: 0,
21844
+ };
21845
+ pushToCache(['readReceipt', channelId], readReceiptChannel);
21846
+ }
21847
+ else if (readReceipt.latestSegment < segment) {
21848
+ // Update latestSegment in read receipt cache
21849
+ pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21850
+ }
21851
+ else if (readReceipt.latestSyncSegment >= segment) {
21852
+ // Skip the job when lastSyncSegment > = segment
21853
+ return;
21854
+ }
21855
+ let syncJob = this.getSyncJob(channelId);
21856
+ if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21857
+ syncJob = {
21858
+ channelId,
21859
+ segment,
21860
+ syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
21861
+ retryCount: 0,
21862
+ };
21863
+ this.enqueueJob(syncJob);
21864
+ }
21865
+ else if (syncJob.segment < segment) {
21866
+ syncJob.segment = segment;
21867
+ }
21868
+ }
21869
+ getSyncJob(channelId) {
21870
+ const { jobQueue } = this;
21871
+ const targetJob = jobQueue.find(job => job.channelId === channelId);
21872
+ return targetJob || null;
21873
+ }
21874
+ enqueueJob(syncJob) {
21875
+ if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
21876
+ this.jobQueue.push(syncJob);
21877
+ }
21878
+ else {
21879
+ // Remove oldest job when queue reach maximum capacity
21880
+ this.jobQueue.shift();
21881
+ this.jobQueue.push(syncJob);
21882
+ }
21883
+ }
21884
+ }
21885
+ let instance$4 = null;
21886
+ var ReadReceiptSyncEngine = {
21887
+ getInstance: () => {
21888
+ if (!instance$4)
21889
+ instance$4 = new MessageReadReceiptSyncEngine();
21890
+ return instance$4;
21891
+ },
21892
+ };
21893
+
21679
21894
  /**
21680
21895
  *
21681
21896
  * Mark subChannel as read by readToSegment
@@ -21724,7 +21939,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21724
21939
  return channelUnreadInfo;
21725
21940
  };
21726
21941
 
21727
- class MessageReadReceiptSyncEngine {
21942
+ class LegacyMessageReadReceiptSyncEngine {
21728
21943
  constructor() {
21729
21944
  this.isActive = true;
21730
21945
  this.MAX_RETRY = 3;
@@ -21755,7 +21970,7 @@ class MessageReadReceiptSyncEngine {
21755
21970
  getUnsyncJobs() {
21756
21971
  var _a;
21757
21972
  // Get all read receipts that has latestSyncSegment < latestSegment
21758
- const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21973
+ const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21759
21974
  return data.latestSyncSegment < data.latestSegment;
21760
21975
  });
21761
21976
  // Enqueue unsync read receipts to the job queue
@@ -21774,7 +21989,7 @@ class MessageReadReceiptSyncEngine {
21774
21989
  return;
21775
21990
  // Get readReceipt from cache by subChannelId
21776
21991
  const readReceipt = (_a = pullFromCache([
21777
- 'readReceipt',
21992
+ 'legacyReadReceipt',
21778
21993
  syncJob.subChannelId,
21779
21994
  ])) === null || _a === void 0 ? void 0 : _a.data;
21780
21995
  if (!readReceipt)
@@ -21797,10 +22012,10 @@ class MessageReadReceiptSyncEngine {
21797
22012
  if (response) {
21798
22013
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
21799
22014
  const readReceiptCache = (_a = pullFromCache([
21800
- 'readReceipt',
22015
+ 'legacyReadReceipt',
21801
22016
  subChannelId,
21802
22017
  ])) === null || _a === void 0 ? void 0 : _a.data;
21803
- pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
22018
+ pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
21804
22019
  }
21805
22020
  else if (!response) {
21806
22021
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -21867,7 +22082,7 @@ class MessageReadReceiptSyncEngine {
21867
22082
  subChannelUnreadInfo.readToSegment = segment;
21868
22083
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
21869
22084
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
21870
- fireEvent('local.channelUnread.updated', channelUnreadInfo);
22085
+ fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
21871
22086
  pushToCache(cacheKey, subChannelUnreadInfo);
21872
22087
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
21873
22088
  }
@@ -21876,7 +22091,10 @@ class MessageReadReceiptSyncEngine {
21876
22091
  }
21877
22092
  enqueueReadReceipt(subChannelId, segment) {
21878
22093
  var _a;
21879
- const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
22094
+ const readReceipt = (_a = pullFromCache([
22095
+ 'legacyReadReceipt',
22096
+ subChannelId,
22097
+ ])) === null || _a === void 0 ? void 0 : _a.data;
21880
22098
  // Create new read receipt if it's not exists and add job to queue
21881
22099
  if (!readReceipt) {
21882
22100
  const readReceiptSubChannel = {
@@ -21884,10 +22102,10 @@ class MessageReadReceiptSyncEngine {
21884
22102
  latestSegment: segment,
21885
22103
  latestSyncSegment: 0,
21886
22104
  };
21887
- pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
22105
+ pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
21888
22106
  }
21889
22107
  else if (readReceipt.latestSegment < segment) {
21890
- pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
22108
+ pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21891
22109
  }
21892
22110
  else if (readReceipt.latestSyncSegment >= segment) {
21893
22111
  // Skip the job when lastSyncSegment > = segment
@@ -21930,18 +22148,24 @@ class MessageReadReceiptSyncEngine {
21930
22148
  }
21931
22149
  }
21932
22150
  let instance$3 = null;
21933
- var ReadReceiptSyncEngine = {
22151
+ var LegacyReadReceiptSyncEngine = {
21934
22152
  getInstance: () => {
21935
22153
  if (!instance$3)
21936
- instance$3 = new MessageReadReceiptSyncEngine();
22154
+ instance$3 = new LegacyMessageReadReceiptSyncEngine();
21937
22155
  return instance$3;
21938
22156
  },
21939
22157
  };
21940
22158
 
21941
22159
  const markReadMessage = (message) => {
21942
- const { subChannelId, channelSegment } = message;
21943
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
21944
- markReadReceiptEngine.markRead(subChannelId, channelSegment);
22160
+ const client = getActiveClient();
22161
+ if (client.useLegacyUnreadCount) {
22162
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
22163
+ markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
22164
+ }
22165
+ else {
22166
+ const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
22167
+ markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
22168
+ }
21945
22169
  };
21946
22170
 
21947
22171
  const messageLinkedObject = (message) => {
@@ -22089,14 +22313,6 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22089
22313
  } });
22090
22314
  };
22091
22315
 
22092
- const notificationTrayLinkedObject = (noti) => {
22093
- return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
22094
- .map(({ _id }) => pullFromCache(['user', 'get', _id]))
22095
- .filter(isNonNullable)
22096
- .map(({ data }) => data)
22097
- .map(user => userLinkedObject(user)) });
22098
- };
22099
-
22100
22316
  const LinkedObject = {
22101
22317
  ad: adLinkedObject,
22102
22318
  comment: commentLinkedObject,
@@ -22110,7 +22326,6 @@ const LinkedObject = {
22110
22326
  reactor: reactorLinkedObject,
22111
22327
  channel: channelLinkedObject,
22112
22328
  pinnedPost: pinnedPostLinkedObject,
22113
- notificationTray: notificationTrayLinkedObject,
22114
22329
  };
22115
22330
 
22116
22331
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -22938,6 +23153,32 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
22938
23153
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
22939
23154
  });
22940
23155
  };
23156
+ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
23157
+ for (let i = 0; i < channels.length; i += 1) {
23158
+ const cacheKey = ['channelUnread', 'get', channels[i].channelId];
23159
+ const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
23160
+ let unreadCount = 0;
23161
+ let readToSegment = null;
23162
+ let lastMentionedSegment = null;
23163
+ let isMentioned = false;
23164
+ if (channelUser) {
23165
+ readToSegment = channelUser.readToSegment;
23166
+ lastMentionedSegment = channelUser.lastMentionedSegment;
23167
+ unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
23168
+ isMentioned = lastMentionedSegment > readToSegment;
23169
+ }
23170
+ const cacheChannelUnread = {
23171
+ channelId: channels[i].channelId,
23172
+ lastSegment: channels[i].messageCount,
23173
+ readToSegment,
23174
+ lastMentionedSegment,
23175
+ unreadCount,
23176
+ isMentioned,
23177
+ isDeleted: channels[i].isDeleted || false,
23178
+ };
23179
+ pushToCache(cacheKey, cacheChannelUnread);
23180
+ }
23181
+ };
22941
23182
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
22942
23183
  const client = getActiveClient();
22943
23184
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -22947,23 +23188,34 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
22947
23188
  rawPayload.messagePreviews.length > 0) {
22948
23189
  updateChannelMessagePreviewCache(rawPayload);
22949
23190
  }
22950
- const markerIds = rawPayload.channels
22951
- // filter channel by type. Only conversation, community and broadcast type are included.
22952
- .filter(isUnreadCountSupport)
22953
- .map(({ channelInternalId }) => channelInternalId);
22954
- if (markerIds.length > 0) {
22955
- // since the get markers method requires a channel cache to function with the reducer.
22956
- preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
22957
- try {
22958
- await getChannelMarkers(markerIds);
22959
- }
22960
- catch (e) {
22961
- // empty block (from the spec, allow marker fetch to fail without having to do anything)
23191
+ if (client.useLegacyUnreadCount) {
23192
+ updateChannelUnread({
23193
+ channels: rawPayload.channels,
23194
+ channelUsers: rawPayload.channelUsers,
23195
+ currentUserId: client.userId,
23196
+ });
23197
+ }
23198
+ else {
23199
+ const markerIds = rawPayload.channels
23200
+ // filter channel by type. Only conversation, community and broadcast type are included.
23201
+ .filter(isUnreadCountSupport)
23202
+ .map(({ channelInternalId }) => channelInternalId);
23203
+ if (markerIds.length > 0) {
23204
+ // since the get markers method requires a channel cache to function with the reducer.
23205
+ preUpdateChannelCache(rawPayload, {
23206
+ isMessagePreviewUpdated: options.isMessagePreviewUpdated,
23207
+ });
23208
+ try {
23209
+ await getChannelMarkers(markerIds);
23210
+ }
23211
+ catch (e) {
23212
+ // empty block (from the spec, allow marker fetch to fail without having to do anything)
23213
+ }
22962
23214
  }
22963
23215
  }
22964
- // attach marker to channel
23216
+ // convert raw channel to internal channel
22965
23217
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
22966
- // user marker to channel users
23218
+ // convert raw channel user to membership (add user object)
22967
23219
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
22968
23220
  return convertRawMembershipToMembership(channelUser);
22969
23221
  });
@@ -23090,15 +23342,28 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23090
23342
  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;
23091
23343
  };
23092
23344
 
23345
+ const getLegacyChannelUnread = (channelId) => {
23346
+ var _a;
23347
+ return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
23348
+ };
23349
+
23093
23350
  const constructChannelDynamicValue = (channel) => {
23351
+ const client = getActiveClient();
23094
23352
  const rest = __rest(channel, ["messageCount"]);
23095
23353
  return shallowClone(rest, {
23096
- get isMentioned() {
23097
- return getChannelIsMentioned(rest);
23354
+ get unreadCount() {
23355
+ var _a, _b;
23356
+ return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
23098
23357
  },
23099
23358
  get subChannelsUnreadCount() {
23100
23359
  return getSubChannelsUnreadCount(rest);
23101
23360
  },
23361
+ get isMentioned() {
23362
+ var _a, _b;
23363
+ if (client.useLegacyUnreadCount)
23364
+ return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
23365
+ return getChannelIsMentioned(rest);
23366
+ },
23102
23367
  });
23103
23368
  };
23104
23369
 
@@ -23711,6 +23976,12 @@ const setClientToken = async (params) => {
23711
23976
  isGlobalBanned: false,
23712
23977
  isUserDeleted: false,
23713
23978
  };
23979
+ client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
23980
+ client.upload.defaults.metadata = {
23981
+ tokenExpiry: expiresAt,
23982
+ isGlobalBanned: false,
23983
+ isUserDeleted: false,
23984
+ };
23714
23985
  // manually setup the token for ws transport
23715
23986
  if (client.ws)
23716
23987
  client.ws.io.opts.query = { token: accessToken };
@@ -23755,12 +24026,21 @@ const onChannelDeleted = (callback) => {
23755
24026
  const client = getActiveClient();
23756
24027
  const filter = async (payload) => {
23757
24028
  const data = await prepareChannelPayload(payload);
23758
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23759
- data.channels.forEach(channel => {
24029
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24030
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
24031
+ data.channels.forEach(channel => {
24032
+ if (isConsistentMode) {
23760
24033
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
23761
24034
  deleteChannelUnreadByChannelId(channel.channelId);
23762
- });
23763
- }
24035
+ }
24036
+ else if (isLegacyUnreadCount) {
24037
+ const cacheKey = ['channelUnread', 'get', channel.channelId];
24038
+ const cache = pullFromCache(cacheKey);
24039
+ if (cache) {
24040
+ pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
24041
+ }
24042
+ }
24043
+ });
23764
24044
  ingestInCache(data);
23765
24045
  callbacks$b.forEach(cb => cb(data.channels[0]));
23766
24046
  };
@@ -23874,6 +24154,25 @@ var readReceiptSyncEngineOnLoginHandler = () => {
23874
24154
  };
23875
24155
  };
23876
24156
 
24157
+ var legacyReadReceiptSyncEngineOnLoginHandler = () => {
24158
+ const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
24159
+ readReceiptSyncEngine.startSyncReadReceipt();
24160
+ onSessionStateChange(state => {
24161
+ if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
24162
+ readReceiptSyncEngine.onSessionEstablished();
24163
+ }
24164
+ else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
24165
+ readReceiptSyncEngine.onTokenExpired();
24166
+ }
24167
+ else {
24168
+ readReceiptSyncEngine.onSessionDestroyed();
24169
+ }
24170
+ });
24171
+ return () => {
24172
+ readReceiptSyncEngine.onSessionDestroyed();
24173
+ };
24174
+ };
24175
+
23877
24176
  const onOnline = (callback) => {
23878
24177
  if (typeof window !== 'undefined' && window.addEventListener) {
23879
24178
  window.addEventListener('online', callback);
@@ -24440,10 +24739,17 @@ const onChannelLeft = (callback) => {
24440
24739
  const preparedPayload = await prepareChannelPayload(payload, {
24441
24740
  isMessagePreviewUpdated: isLeftByMe,
24442
24741
  });
24443
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
24742
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24743
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
24744
+ if (isLeftByMe) {
24444
24745
  preparedPayload.channels.forEach(channel => {
24445
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24446
- deleteChannelUnreadByChannelId(channel.channelId);
24746
+ if (isConsistentMode) {
24747
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24748
+ deleteChannelUnreadByChannelId(channel.channelId);
24749
+ }
24750
+ else if (isLegacyUnreadCount) {
24751
+ dropFromCache(['channelUnread', 'get', channel.channelId]);
24752
+ }
24447
24753
  });
24448
24754
  }
24449
24755
  const { channels, channelUsers } = preparedPayload;
@@ -24711,6 +25017,34 @@ const onMessageCreatedMqtt = (callback) => {
24711
25017
  reCalculateChannelUnreadInfo(message.channelId);
24712
25018
  });
24713
25019
  }
25020
+ if (client.useLegacyUnreadCount) {
25021
+ rawPayload.messages.forEach(message => {
25022
+ var _a, _b;
25023
+ const channelUnread = (_a = pullFromCache([
25024
+ 'channelUnread',
25025
+ 'get',
25026
+ message.channelId,
25027
+ ])) === null || _a === void 0 ? void 0 : _a.data;
25028
+ if (!channelUnread ||
25029
+ channelUnread.lastSegment >= message.segment ||
25030
+ typeof channelUnread.readToSegment !== 'number' ||
25031
+ typeof channelUnread.lastMentionedSegment !== 'number')
25032
+ return;
25033
+ const lastSegment = message.segment;
25034
+ const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
25035
+ return (mention.type === 'channel' ||
25036
+ (mention.type === 'user' &&
25037
+ client.userId &&
25038
+ mention.userPublicIds.includes(client.userId)));
25039
+ });
25040
+ const lastMentionedSegment = isMentionedInMessage
25041
+ ? message.segment
25042
+ : channelUnread.lastMentionedSegment;
25043
+ const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
25044
+ pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
25045
+ fireEvent('local.channelUnread.updated', updatedChannelUnread);
25046
+ });
25047
+ }
24714
25048
  // Update in cache
24715
25049
  ingestInCache(payload);
24716
25050
  payload.messages.forEach(message => {
@@ -24886,6 +25220,7 @@ const enableUnreadCount = () => {
24886
25220
  if (client.isUnreadCountEnabled)
24887
25221
  return false;
24888
25222
  client.isUnreadCountEnabled = true;
25223
+ client.useLegacyUnreadCount = false;
24889
25224
  client.emitter.emit('unreadCountEnabled', true);
24890
25225
  return true;
24891
25226
  };
@@ -25201,7 +25536,12 @@ const login = async (params, sessionHandler, config) => {
25201
25536
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
25202
25537
  // the channel because currently backend can't handle this, so every time a user is banned from
25203
25538
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
25204
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25539
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25540
+ if (client.useLegacyUnreadCount) {
25541
+ subscriptions.push(readReceiptSyncEngineOnLoginHandler());
25542
+ }
25543
+ else
25544
+ subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
25205
25545
  const markerSyncUnsubscriber = await startMarkerSync();
25206
25546
  subscriptions.push(markerSyncUnsubscriber);
25207
25547
  }
@@ -25359,15 +25699,17 @@ const DEFAULT_DEBUG_SESSION = 'amity';
25359
25699
  * @category Client API
25360
25700
  * */
25361
25701
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
25362
- var _a, _b;
25702
+ var _a, _b, _c;
25363
25703
  const log = createLogger(debugSession);
25364
25704
  log('client/api/createClient', {
25365
25705
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
25366
25706
  apiRegion,
25367
25707
  });
25368
25708
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
25369
- const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
25709
+ const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
25710
+ const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
25370
25711
  const http = createHttpTransport(httpEndpoint);
25712
+ const upload = createHttpTransport(uploadEndpoint);
25371
25713
  let ws;
25372
25714
  let mqtt;
25373
25715
  if (rteEnabled) {
@@ -25382,6 +25724,8 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25382
25724
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25383
25725
  const sessionHandler = undefined;
25384
25726
  const isUnreadCountEnabled = false;
25727
+ // Legacy unread count is true by default
25728
+ const useLegacyUnreadCount = true;
25385
25729
  const client = {
25386
25730
  version: `${VERSION}`,
25387
25731
  apiKey,
@@ -25396,6 +25740,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25396
25740
  http,
25397
25741
  ws,
25398
25742
  mqtt,
25743
+ upload,
25399
25744
  emitter,
25400
25745
  /*
25401
25746
  * Session Components
@@ -25411,6 +25756,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25411
25756
  getMessagePreviewSetting,
25412
25757
  use: () => setActiveClient(client),
25413
25758
  isUnreadCountEnabled,
25759
+ useLegacyUnreadCount,
25414
25760
  getMarkerSyncConsistentMode,
25415
25761
  /**
25416
25762
  * Prefix for the deviceId key in the local storage or async storage.
@@ -25424,7 +25770,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25424
25770
  return activeClient;
25425
25771
  setActiveClient(client);
25426
25772
  }
25427
- catch (_c) {
25773
+ catch (_d) {
25428
25774
  setActiveClient(client);
25429
25775
  }
25430
25776
  return client;
@@ -25881,7 +26227,7 @@ const getUserUnread = (callback) => {
25881
26227
  };
25882
26228
  };
25883
26229
 
25884
- var index$m = /*#__PURE__*/Object.freeze({
26230
+ var index$l = /*#__PURE__*/Object.freeze({
25885
26231
  __proto__: null,
25886
26232
  getActiveClient: getActiveClient,
25887
26233
  getActiveUser: getActiveUser,
@@ -27088,7 +27434,7 @@ const getMyFollowInfo = (callback) => {
27088
27434
  };
27089
27435
  /* end_public_function */
27090
27436
 
27091
- var index$l = /*#__PURE__*/Object.freeze({
27437
+ var index$k = /*#__PURE__*/Object.freeze({
27092
27438
  __proto__: null,
27093
27439
  blockUser: blockUser,
27094
27440
  unBlockUser: unBlockUser,
@@ -28103,9 +28449,9 @@ var AmityUserSearchMatchType;
28103
28449
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28104
28450
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28105
28451
 
28106
- var index$k = /*#__PURE__*/Object.freeze({
28452
+ var index$j = /*#__PURE__*/Object.freeze({
28107
28453
  __proto__: null,
28108
- Relationship: index$l,
28454
+ Relationship: index$k,
28109
28455
  getUserByIds: getUserByIds,
28110
28456
  updateUser: updateUser,
28111
28457
  flagUser: flagUser,
@@ -28213,7 +28559,7 @@ const uploadFile = async (formData, onProgress) => {
28213
28559
  const headers = 'getHeaders' in formData
28214
28560
  ? formData.getHeaders()
28215
28561
  : { 'content-type': 'multipart/form-data' };
28216
- const { data } = await client.http.post('/api/v4/files', formData, {
28562
+ const { data } = await client.upload.post('/api/v4/files', formData, {
28217
28563
  headers,
28218
28564
  onUploadProgress({ loaded, total = 100 }) {
28219
28565
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28303,7 +28649,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28303
28649
  const headers = 'getHeaders' in formData
28304
28650
  ? formData.getHeaders()
28305
28651
  : { 'content-type': 'multipart/form-data' };
28306
- const { data } = await client.http.post('/api/v4/videos', formData, {
28652
+ const { data } = await client.upload.post('/api/v4/videos', formData, {
28307
28653
  headers,
28308
28654
  onUploadProgress({ loaded, total = 100 }) {
28309
28655
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28351,7 +28697,7 @@ const uploadImage = async (formData, onProgress) => {
28351
28697
  const headers = 'getHeaders' in formData
28352
28698
  ? formData.getHeaders()
28353
28699
  : { 'content-type': 'multipart/form-data' };
28354
- const { data } = await client.http.post('/api/v4/images', formData, {
28700
+ const { data } = await client.upload.post('/api/v4/images', formData, {
28355
28701
  headers,
28356
28702
  onUploadProgress({ loaded, total = 100 }) {
28357
28703
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28369,7 +28715,7 @@ const uploadImage = async (formData, onProgress) => {
28369
28715
  };
28370
28716
  /* end_public_function */
28371
28717
 
28372
- var index$j = /*#__PURE__*/Object.freeze({
28718
+ var index$i = /*#__PURE__*/Object.freeze({
28373
28719
  __proto__: null,
28374
28720
  getFile: getFile,
28375
28721
  uploadFile: uploadFile,
@@ -29436,6 +29782,29 @@ const createCommentEventSubscriber = (event, callback) => {
29436
29782
  }
29437
29783
  }
29438
29784
  }
29785
+ }
29786
+ if (['comment.deleted'].includes(event)) {
29787
+ // NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
29788
+ if (event === 'comment.deleted' && comment.data.userId === client.userId)
29789
+ return;
29790
+ if (comments[0].parentId) {
29791
+ const parentComment = pullFromCache([
29792
+ 'comment',
29793
+ 'get',
29794
+ comments[0].parentId,
29795
+ ]);
29796
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
29797
+ // Remove deleted comment in parent childComment if still exists
29798
+ if (parentComment.data.children.includes(comments[0].commentId)) {
29799
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
29800
+ ...new Set([
29801
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
29802
+ ]),
29803
+ ] });
29804
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
29805
+ }
29806
+ }
29807
+ }
29439
29808
  const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
29440
29809
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
29441
29810
  }
@@ -29448,7 +29817,7 @@ const createCommentEventSubscriber = (event, callback) => {
29448
29817
  const createLocalCommentEventSubscriber = (event, callback) => {
29449
29818
  const client = getActiveClient();
29450
29819
  const filter = (payload) => {
29451
- var _a;
29820
+ var _a, _b;
29452
29821
  if (!client.cache) {
29453
29822
  // TODO: here we are missing specific properties here!
29454
29823
  callback(LinkedObject.comment(payload.comments[0]));
@@ -29491,6 +29860,38 @@ const createLocalCommentEventSubscriber = (event, callback) => {
29491
29860
  const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
29492
29861
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
29493
29862
  }
29863
+ if (['local.comment.deleted'].includes(event)) {
29864
+ if (comments[0].parentId) {
29865
+ const parentComment = pullFromCache([
29866
+ 'comment',
29867
+ 'get',
29868
+ comments[0].parentId,
29869
+ ]);
29870
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
29871
+ // Remove deleted comment in parent childComment if still exists
29872
+ if (parentComment.data.children.includes(comments[0].commentId)) {
29873
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
29874
+ ...new Set([
29875
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
29876
+ ]),
29877
+ ] });
29878
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
29879
+ setTimeout(() => {
29880
+ // NOTE: This is workaround solution for emitting event not work properly.
29881
+ fireEvent('comment.updated', {
29882
+ comments: [newParentComment],
29883
+ commentChildren: [],
29884
+ files: [],
29885
+ users: [],
29886
+ communityUsers: [],
29887
+ });
29888
+ }, 200);
29889
+ }
29890
+ }
29891
+ }
29892
+ const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
29893
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
29894
+ }
29494
29895
  callback(LinkedObject.comment(comment.data));
29495
29896
  }
29496
29897
  }
@@ -30181,7 +30582,7 @@ const getReactions = (params, callback, config) => {
30181
30582
  };
30182
30583
  /* end_public_function */
30183
30584
 
30184
- var index$i = /*#__PURE__*/Object.freeze({
30585
+ var index$h = /*#__PURE__*/Object.freeze({
30185
30586
  __proto__: null,
30186
30587
  addReaction: addReaction,
30187
30588
  removeReaction: removeReaction,
@@ -31997,7 +32398,7 @@ const getMessages = (params, callback, config) => {
31997
32398
  };
31998
32399
  /* end_public_function */
31999
32400
 
32000
- var index$h = /*#__PURE__*/Object.freeze({
32401
+ var index$g = /*#__PURE__*/Object.freeze({
32001
32402
  __proto__: null,
32002
32403
  createMessage: createMessage,
32003
32404
  updateMessage: updateMessage,
@@ -32523,7 +32924,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32523
32924
  };
32524
32925
  /* end_public_function */
32525
32926
 
32526
- var index$g = /*#__PURE__*/Object.freeze({
32927
+ var index$f = /*#__PURE__*/Object.freeze({
32527
32928
  __proto__: null,
32528
32929
  getSubChannelByIds: getSubChannels$1,
32529
32930
  createSubChannel: createSubChannel,
@@ -32544,19 +32945,37 @@ var index$g = /*#__PURE__*/Object.freeze({
32544
32945
  /**
32545
32946
  * Internal used only
32546
32947
  *
32547
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32948
+ * Fired when an {@link Amity.channelUnreadInfo} has been updated.
32548
32949
  *
32549
32950
  * @param callback The function to call when the event was fired
32550
32951
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32551
32952
  *
32552
- * @category MessageMarker Events
32953
+ * @category ChannelMarker Events
32954
+ */
32955
+ const onChannelUnreadInfoUpdatedLocal = (callback) => {
32956
+ const client = getActiveClient();
32957
+ const filter = (payload) => {
32958
+ callback(payload);
32959
+ };
32960
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
32961
+ };
32962
+
32963
+ /**
32964
+ * Internal used only
32965
+ *
32966
+ * Fired when an {@link Amity.ChannelUnread} has been updated.
32967
+ *
32968
+ * @param callback The function to call when the event was fired
32969
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
32970
+ *
32971
+ * @category Channel Events
32553
32972
  */
32554
32973
  const onChannelUnreadUpdatedLocal = (callback) => {
32555
32974
  const client = getActiveClient();
32556
32975
  const filter = (payload) => {
32557
32976
  callback(payload);
32558
32977
  };
32559
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32978
+ return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32560
32979
  };
32561
32980
 
32562
32981
  /* begin_public_function
@@ -32758,6 +33177,7 @@ const getChannel = (channelId, callback) => {
32758
33177
  return onSubChannelUpdated(updateMessagePreview);
32759
33178
  }, 'channelId', 'channel'),
32760
33179
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
33180
+ convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
32761
33181
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
32762
33182
  ], {
32763
33183
  forceDispatch: true,
@@ -33271,6 +33691,10 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33271
33691
  },
33272
33692
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
33273
33693
  },
33694
+ {
33695
+ fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33696
+ action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33697
+ },
33274
33698
  {
33275
33699
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33276
33700
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -33336,6 +33760,120 @@ const getChannels = (params, callback, config) => {
33336
33760
  };
33337
33761
  /* end_public_function */
33338
33762
 
33763
+ /**
33764
+ *
33765
+ * Calculate user unread from {@link Amity.ChannelUnread} objects
33766
+ *
33767
+ * @returns the {@link Amity.UserUnread} objects
33768
+ *
33769
+ * @category Channel API
33770
+ * @async
33771
+ */
33772
+ const getTotalChannelsUnread$1 = () => {
33773
+ var _a;
33774
+ const client = getActiveClient();
33775
+ client.log('channel/getTotalChannelsUnread.locally');
33776
+ const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
33777
+ return !data.isDeleted;
33778
+ })) || [];
33779
+ const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
33780
+ acc.unreadCount += data.unreadCount;
33781
+ acc.isMentioned = acc.isMentioned || data.isMentioned;
33782
+ return acc;
33783
+ }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
33784
+ const cachedAt = client.cache && Date.now();
33785
+ return {
33786
+ data: totalChannelsUnread,
33787
+ cachedAt,
33788
+ };
33789
+ };
33790
+
33791
+ /* begin_public_function
33792
+ id: totalChannelsUnread.get
33793
+ */
33794
+ /**
33795
+ * ```js
33796
+ * import { ChannelRepository } from '@amityco/ts-sdk';
33797
+ *
33798
+ * let totalChannelsUnread;
33799
+ *
33800
+ * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
33801
+ * unread = response.data;
33802
+ * });
33803
+ * ```
33804
+ *
33805
+ * Observe all mutation on a given {@link Amity.UserUnread}
33806
+ *
33807
+ * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
33808
+ *
33809
+ * @category User Unread Live Object
33810
+ *
33811
+ */
33812
+ const getTotalChannelsUnread = (callback) => {
33813
+ const { _id: userId } = getActiveUser();
33814
+ if (!userId)
33815
+ throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
33816
+ const { log, cache } = getActiveClient();
33817
+ if (!cache) {
33818
+ console.log('For using Live Object feature you need to enable Cache!');
33819
+ }
33820
+ const timestamp = Date.now();
33821
+ log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
33822
+ const disposers = [];
33823
+ let isUnsyncedModel = false; // for messages
33824
+ let model;
33825
+ const dispatcher = (data) => {
33826
+ const { data: userUnread } = data;
33827
+ const callbackModel = userUnread
33828
+ ? {
33829
+ unreadCount: userUnread.unreadCount,
33830
+ isMentioned: userUnread.isMentioned,
33831
+ }
33832
+ : undefined;
33833
+ model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
33834
+ callback({
33835
+ data: callbackModel
33836
+ ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
33837
+ loading: data.loading,
33838
+ error: data.error,
33839
+ });
33840
+ };
33841
+ const realtimeRouter = (userUnread) => {
33842
+ if (isEqual(model, userUnread))
33843
+ return;
33844
+ dispatcher({
33845
+ loading: false,
33846
+ data: userUnread,
33847
+ });
33848
+ };
33849
+ const onFetch = () => {
33850
+ const query = createQuery(async () => getTotalChannelsUnread$1());
33851
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
33852
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
33853
+ dispatcher({
33854
+ data,
33855
+ origin,
33856
+ loading: false,
33857
+ error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
33858
+ });
33859
+ isUnsyncedModel = true;
33860
+ disposers.forEach(fn => fn());
33861
+ }
33862
+ else if (!isUnsyncedModel) {
33863
+ dispatcher({ loading, data, origin, error });
33864
+ }
33865
+ if (error) {
33866
+ disposers.forEach(fn => fn());
33867
+ }
33868
+ });
33869
+ };
33870
+ disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
33871
+ onFetch();
33872
+ return () => {
33873
+ disposers.forEach(fn => fn());
33874
+ };
33875
+ };
33876
+
33339
33877
  /* begin_public_function
33340
33878
  id: channel.member.add
33341
33879
  */
@@ -33700,7 +34238,7 @@ const searchMembers$1 = (params, callback, config) => {
33700
34238
  };
33701
34239
  /* end_public_function */
33702
34240
 
33703
- var index$f = /*#__PURE__*/Object.freeze({
34241
+ var index$e = /*#__PURE__*/Object.freeze({
33704
34242
  __proto__: null,
33705
34243
  addMembers: addMembers$1,
33706
34244
  removeMembers: removeMembers$1,
@@ -33903,7 +34441,7 @@ const unmuteMembers = async (channelId, userIds) => {
33903
34441
  };
33904
34442
  /* end_public_function */
33905
34443
 
33906
- var index$e = /*#__PURE__*/Object.freeze({
34444
+ var index$d = /*#__PURE__*/Object.freeze({
33907
34445
  __proto__: null,
33908
34446
  addRole: addRole,
33909
34447
  removeRole: removeRole,
@@ -33913,10 +34451,10 @@ var index$e = /*#__PURE__*/Object.freeze({
33913
34451
  unmuteMembers: unmuteMembers
33914
34452
  });
33915
34453
 
33916
- var index$d = /*#__PURE__*/Object.freeze({
34454
+ var index$c = /*#__PURE__*/Object.freeze({
33917
34455
  __proto__: null,
33918
- Membership: index$f,
33919
- Moderation: index$e,
34456
+ Membership: index$e,
34457
+ Moderation: index$d,
33920
34458
  getChannelByIds: getChannelByIds$1,
33921
34459
  createChannel: createChannel,
33922
34460
  updateChannel: updateChannel,
@@ -33939,6 +34477,7 @@ var index$d = /*#__PURE__*/Object.freeze({
33939
34477
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
33940
34478
  getChannel: getChannel,
33941
34479
  getChannels: getChannels,
34480
+ getTotalChannelsUnread: getTotalChannelsUnread,
33942
34481
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
33943
34482
  isUnreadCountSupport: isUnreadCountSupport,
33944
34483
  convertFromRaw: convertFromRaw,
@@ -35295,7 +35834,7 @@ const searchMembers = (params, callback, config) => {
35295
35834
  };
35296
35835
  /* end_public_function */
35297
35836
 
35298
- var index$c = /*#__PURE__*/Object.freeze({
35837
+ var index$b = /*#__PURE__*/Object.freeze({
35299
35838
  __proto__: null,
35300
35839
  addMembers: addMembers,
35301
35840
  removeMembers: removeMembers,
@@ -36320,7 +36859,7 @@ const unbanMembers = async (communityId, userIds) => {
36320
36859
  };
36321
36860
  /* end_public_function */
36322
36861
 
36323
- var index$b = /*#__PURE__*/Object.freeze({
36862
+ var index$a = /*#__PURE__*/Object.freeze({
36324
36863
  __proto__: null,
36325
36864
  addRoles: addRoles,
36326
36865
  removeRoles: removeRoles,
@@ -36328,10 +36867,10 @@ var index$b = /*#__PURE__*/Object.freeze({
36328
36867
  unbanMembers: unbanMembers
36329
36868
  });
36330
36869
 
36331
- var index$a = /*#__PURE__*/Object.freeze({
36870
+ var index$9 = /*#__PURE__*/Object.freeze({
36332
36871
  __proto__: null,
36333
- Moderation: index$b,
36334
- Membership: index$c,
36872
+ Moderation: index$a,
36873
+ Membership: index$b,
36335
36874
  getCommunityByIds: getCommunities$1,
36336
36875
  createCommunity: createCommunity,
36337
36876
  updateCommunity: updateCommunity,
@@ -36564,7 +37103,7 @@ const getCategories = (params, callback, config) => {
36564
37103
  };
36565
37104
  /* end_public_function */
36566
37105
 
36567
- var index$9 = /*#__PURE__*/Object.freeze({
37106
+ var index$8 = /*#__PURE__*/Object.freeze({
36568
37107
  __proto__: null,
36569
37108
  getCategory: getCategory,
36570
37109
  getCategories: getCategories
@@ -36732,7 +37271,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
36732
37271
  : undefined;
36733
37272
  };
36734
37273
 
36735
- var index$8 = /*#__PURE__*/Object.freeze({
37274
+ var index$7 = /*#__PURE__*/Object.freeze({
36736
37275
  __proto__: null,
36737
37276
  queryGlobalFeed: queryGlobalFeed,
36738
37277
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38047,7 +38586,7 @@ const getComments = (params, callback, config) => {
38047
38586
  };
38048
38587
  /* end_public_function */
38049
38588
 
38050
- var index$7 = /*#__PURE__*/Object.freeze({
38589
+ var index$6 = /*#__PURE__*/Object.freeze({
38051
38590
  __proto__: null,
38052
38591
  getCommentByIds: getCommentByIds,
38053
38592
  createComment: createComment,
@@ -39054,7 +39593,7 @@ const semanticSearchPosts = (params, callback, config) => {
39054
39593
  };
39055
39594
  };
39056
39595
 
39057
- var index$6 = /*#__PURE__*/Object.freeze({
39596
+ var index$5 = /*#__PURE__*/Object.freeze({
39058
39597
  __proto__: null,
39059
39598
  getPostByIds: getPostByIds,
39060
39599
  createPost: createPost,
@@ -39588,7 +40127,7 @@ const getStreams = (params, callback, config) => {
39588
40127
  };
39589
40128
  };
39590
40129
 
39591
- var index$5 = /*#__PURE__*/Object.freeze({
40130
+ var index$4 = /*#__PURE__*/Object.freeze({
39592
40131
  __proto__: null,
39593
40132
  createStream: createStream,
39594
40133
  updateStream: updateStream,
@@ -39875,7 +40414,7 @@ const getPoll = (pollId, callback) => {
39875
40414
  };
39876
40415
  /* end_public_function */
39877
40416
 
39878
- var index$4 = /*#__PURE__*/Object.freeze({
40417
+ var index$3 = /*#__PURE__*/Object.freeze({
39879
40418
  __proto__: null,
39880
40419
  createPoll: createPoll,
39881
40420
  closePoll: closePoll,
@@ -39886,7 +40425,7 @@ var index$4 = /*#__PURE__*/Object.freeze({
39886
40425
  getPoll: getPoll
39887
40426
  });
39888
40427
 
39889
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
40428
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
39890
40429
  /*
39891
40430
  * The crypto algorithm used for importing key and signing string
39892
40431
  */
@@ -40246,7 +40785,7 @@ const getPlayer = async (parameters) => {
40246
40785
  return video;
40247
40786
  };
40248
40787
 
40249
- var index$3 = /*#__PURE__*/Object.freeze({
40788
+ var index$2 = /*#__PURE__*/Object.freeze({
40250
40789
  __proto__: null,
40251
40790
  getPlayer: getPlayer
40252
40791
  });
@@ -41419,7 +41958,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41419
41958
  };
41420
41959
  };
41421
41960
 
41422
- var index$2 = /*#__PURE__*/Object.freeze({
41961
+ var index$1 = /*#__PURE__*/Object.freeze({
41423
41962
  __proto__: null,
41424
41963
  createImageStory: createImageStory,
41425
41964
  createVideoStory: createVideoStory,
@@ -41456,7 +41995,7 @@ const getNetworkAds = async () => {
41456
41995
  };
41457
41996
  };
41458
41997
 
41459
- var index$1 = /*#__PURE__*/Object.freeze({
41998
+ var index = /*#__PURE__*/Object.freeze({
41460
41999
  __proto__: null,
41461
42000
  getNetworkAds: getNetworkAds
41462
42001
  });
@@ -41483,359 +42022,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41483
42022
  return { accessToken: data.accessToken };
41484
42023
  };
41485
42024
 
41486
- /* begin_public_function
41487
- id: notificationTray.getNotificationTraySeen
41488
- */
41489
- /**
41490
- * ```js
41491
- * import { notificationTray } from '@amityco/ts-sdk'
41492
- * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
41493
- * ```
41494
- *
41495
- *
41496
- * @returns A page of {@link Amity.NotificationTraySeen} objects
41497
- *
41498
- * @category NotificationTray API
41499
- * @async
41500
- * */
41501
- const getNotificationTraySeen$1 = async () => {
41502
- const client = getActiveClient();
41503
- client.log('notificationTray/getNotificationTraySeen', {});
41504
- const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
41505
- const cachedAt = client.cache && Date.now();
41506
- if (client.cache) {
41507
- const cacheKey = ['notificationTraySeen', 'get', client.userId];
41508
- pushToCache(cacheKey, {
41509
- userId: client.userId,
41510
- lastTraySeenAt: payload.lastTraySeenAt,
41511
- lastTrayOccuredAt: payload.lastTrayOccuredAt,
41512
- });
41513
- }
41514
- return {
41515
- data: {
41516
- userId: client.userId,
41517
- lastTraySeenAt: payload.lastTraySeenAt,
41518
- lastTrayOccuredAt: payload.lastTrayOccuredAt,
41519
- isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
41520
- },
41521
- cachedAt,
41522
- };
41523
- };
41524
- /* end_public_function */
41525
- /**
41526
- * ```js
41527
- * import { notificationTray } from '@amityco/ts-sdk'
41528
- * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
41529
- * ```
41530
- *
41531
- * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
41532
- *
41533
- * @returns A page of {@link Amity.NotificationTraySeen} objects
41534
- *
41535
- * @category NotificationTray API
41536
- * @async
41537
- * */
41538
- getNotificationTraySeen$1.locally = () => {
41539
- var _a;
41540
- const client = getActiveClient();
41541
- client.log('notificationTray/getNotificationTraySeen.locally', {});
41542
- if (!client.cache)
41543
- return;
41544
- const queryKey = ['notificationTraySeen', 'get'];
41545
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
41546
- if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
41547
- return;
41548
- return { data: data.notificationTraySeen, cachedAt };
41549
- };
41550
-
41551
- /**
41552
- * ```js
41553
- * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
41554
- * const dispose = onNotificationTraySeenUpdated(data => {
41555
- * // ...
41556
- * })
41557
- * ```
41558
- *
41559
- * Fired when an {@link Amity.NotificationTraySeen} has been updated
41560
- *
41561
- * @param callback The function to call when the event was fired
41562
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41563
- *
41564
- * @category NotificationTraySeen Events
41565
- */
41566
- const onNotificationTraySeenUpdated = (callback) => {
41567
- const client = getActiveClient();
41568
- const disposers = [
41569
- createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
41570
- ];
41571
- return () => {
41572
- disposers.forEach(fn => fn());
41573
- };
41574
- };
41575
-
41576
- /* begin_public_function
41577
- id: notificationTraySeen.get
41578
- */
41579
- /**
41580
- * ```js
41581
- * import { getNotificationTraySeen } from '@amityco/ts-sdk';
41582
- *
41583
- * let notificationTraySeen;
41584
- *
41585
- * const unsubscribe = getNotificationTraySeen(userId, response => {
41586
- * notificationTraySeen = response.data;
41587
- * });
41588
- * ```
41589
- *
41590
- * Observe all mutation on a given {@link Amity.NotificationTraySeen}
41591
- *
41592
- * @param userId the ID of the user to observe
41593
- * @param callback the function to call when new data are available
41594
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
41595
- *
41596
- * @category NotificationTraySeen Live Object
41597
- */
41598
- const getNotificationTraySeen = (callback) => {
41599
- const responder = (snapshot) => {
41600
- const { data } = snapshot;
41601
- callback(Object.assign(Object.assign({}, snapshot), { data }));
41602
- };
41603
- const { userId } = getActiveUser();
41604
- return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
41605
- onNotificationTraySeenUpdated,
41606
- ]);
41607
- };
41608
- /* end_public_function */
41609
-
41610
- /**
41611
- * TODO: handle cache receive cache option, and cache policy
41612
- * TODO: check if querybyIds is supported
41613
- */
41614
- class NotificationTrayItemsPaginationController extends PaginationController {
41615
- async getRequest(queryParams, token) {
41616
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
41617
- const options = token ? { token } : { limit };
41618
- const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
41619
- params: Object.assign(Object.assign({}, params), { options }),
41620
- });
41621
- return queryResponse;
41622
- }
41623
- }
41624
-
41625
- class NotificationTrayItemsQuerystreamController extends QueryStreamController {
41626
- constructor(query, cacheKey, notifyChange, preparePayload) {
41627
- super(query, cacheKey);
41628
- this.notifyChange = notifyChange;
41629
- this.preparePayload = preparePayload;
41630
- }
41631
- async saveToMainDB(response) {
41632
- const processedPayload = await this.preparePayload(response);
41633
- const client = getActiveClient();
41634
- const cachedAt = client.cache && Date.now();
41635
- if (client.cache) {
41636
- ingestInCache(processedPayload, { cachedAt });
41637
- }
41638
- }
41639
- appendToQueryStream(response, direction, refresh = false) {
41640
- var _a, _b;
41641
- if (refresh) {
41642
- pushToCache(this.cacheKey, {
41643
- data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41644
- });
41645
- }
41646
- else {
41647
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41648
- const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
41649
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
41650
- ...new Set([
41651
- ...notifications,
41652
- ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41653
- ]),
41654
- ] }));
41655
- }
41656
- }
41657
- }
41658
-
41659
- const prepareNotificationTrayItemsPayload = (rawPayload) => {
41660
- const users = rawPayload.users.map(convertRawUserToInternalUser);
41661
- return Object.assign(Object.assign({}, rawPayload), { users });
41662
- };
41663
-
41664
- class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
41665
- constructor(query, callback) {
41666
- const queryStreamId = hash(query);
41667
- const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
41668
- const paginationController = new NotificationTrayItemsPaginationController(query);
41669
- super(paginationController, queryStreamId, cacheKey, callback);
41670
- this.query = query;
41671
- this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
41672
- this.callback = callback.bind(this);
41673
- this.loadPage({ initial: true });
41674
- }
41675
- setup() {
41676
- var _a;
41677
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41678
- if (!collection) {
41679
- pushToCache(this.cacheKey, {
41680
- data: [],
41681
- params: {},
41682
- });
41683
- }
41684
- }
41685
- async persistModel(queryPayload) {
41686
- await this.queryStreamController.saveToMainDB(queryPayload);
41687
- }
41688
- persistQueryStream({ response, direction, refresh, }) {
41689
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
41690
- }
41691
- // eslint-disable-next-line class-methods-use-this
41692
- startSubscription() {
41693
- return [];
41694
- }
41695
- notifyChange({ origin, loading, error }) {
41696
- var _a, _b;
41697
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41698
- if (!collection)
41699
- return;
41700
- const data = ((_b = collection.data
41701
- .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
41702
- .filter(isNonNullable)
41703
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
41704
- if (!this.shouldNotify(data) && origin === 'event')
41705
- return;
41706
- this.callback({
41707
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
41708
- data,
41709
- hasNextPage: !!this.paginationController.getNextToken(),
41710
- loading,
41711
- error,
41712
- });
41713
- }
41714
- }
41715
-
41716
- /**
41717
- * Get notification tray items for a notification tray page
41718
- *
41719
- * @param params the limit query parameters
41720
- * @param callback the callback to be called when the notification tray items are updated
41721
- * @returns items in the notification tray
41722
- *
41723
- * @category Notification tray items Live Collection
41724
- *
41725
- */
41726
- const getNotificationTrayItems = (params, callback, config) => {
41727
- const { log, cache } = getActiveClient();
41728
- if (!cache) {
41729
- console.log(ENABLE_CACHE_MESSAGE);
41730
- }
41731
- const timestamp = Date.now();
41732
- log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
41733
- const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
41734
- const disposers = notiTrayItemsLiveCollection.startSubscription();
41735
- const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
41736
- disposers.push(() => dropFromCache(cacheKey));
41737
- return () => {
41738
- log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
41739
- disposers.forEach(fn => fn());
41740
- };
41741
- };
41742
-
41743
- /* begin_public_function
41744
- id: notificationTrayItem.markSeen
41745
- */
41746
- /**
41747
- * ```js
41748
- * import { notificationTray } from '@amityco/ts-sdk'
41749
- * const updated = await notificationTray.markItemsSeen()
41750
- * ```
41751
- *
41752
- * Updates an {@link Amity.NotificationItemSeen}
41753
- *
41754
- * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
41755
- * @returns the updated {@link Amity.NotificationItemSeen} object
41756
- *
41757
- * @category NotificationItemSeen API
41758
- * @async
41759
- */
41760
- const markItemsSeen = async (patch) => {
41761
- const client = getActiveClient();
41762
- client.log('notificationTray/markItemsSeen', {});
41763
- const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
41764
- patch,
41765
- });
41766
- const updatedData = patch.trayItems
41767
- .map(patchItem => {
41768
- var _a;
41769
- const cacheData = (_a = pullFromCache([
41770
- 'notificationTraySeen',
41771
- 'get',
41772
- patchItem.id,
41773
- ])) === null || _a === void 0 ? void 0 : _a.data;
41774
- if (!cacheData)
41775
- return;
41776
- const data = Object.assign(Object.assign({}, cacheData), payload);
41777
- if (client.cache) {
41778
- const cachedAt = Date.now();
41779
- pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
41780
- }
41781
- return data;
41782
- })
41783
- .filter(Boolean);
41784
- fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
41785
- };
41786
- /* end_public_function */
41787
-
41788
- /* begin_public_function
41789
- id: notificationTray.markSeen
41790
- */
41791
- /**
41792
- * ```js
41793
- * import { notificationTray } from '@amityco/ts-sdk'
41794
- * const updated = await notificationTray.markTraySeen({
41795
- * lastSeenAt: Amity.timestamp,
41796
- * })
41797
- * ```
41798
- *
41799
- * Updates an {@link Amity.NotificationTraySeen}
41800
- *
41801
- * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
41802
- * @param lastSeenAt The patch data to apply
41803
- * @returns the updated {@link Amity.NotificationTraySeen} object
41804
- *
41805
- * @category Post API
41806
- * @async
41807
- */
41808
- const markTraySeen = async (lastSeenAt) => {
41809
- var _a;
41810
- const client = getActiveClient();
41811
- client.log('notificationTray/markTraySeen', {});
41812
- const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
41813
- lastSeenAt,
41814
- });
41815
- const cacheData = (_a = pullFromCache([
41816
- 'notificationTraySeen',
41817
- 'get',
41818
- ])) === null || _a === void 0 ? void 0 : _a.data;
41819
- const data = Object.assign({ userId: client.userId }, payload);
41820
- const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
41821
- const cachedAt = client.cache && Date.now();
41822
- if (client.cache)
41823
- pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
41824
- fireEvent('local.notificationTraySeen.updated', data);
41825
- return {
41826
- data: payload,
41827
- cachedAt,
41828
- };
41829
- };
41830
- /* end_public_function */
41831
-
41832
- var index = /*#__PURE__*/Object.freeze({
41833
- __proto__: null,
41834
- getNotificationTraySeen: getNotificationTraySeen,
41835
- getNotificationTrayItems: getNotificationTrayItems,
41836
- markItemsSeen: markItemsSeen,
41837
- markTraySeen: markTraySeen,
41838
- onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
41839
- });
41840
-
41841
- export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
42025
+ export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };