@amityco/ts-sdk 7.1.1-ce25d503.0 → 7.1.1-e23f973a.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 (140) hide show
  1. package/dist/@types/core/events.d.ts +5 -2
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +4 -2
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +18 -0
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/core/readReceipt.d.ts +1 -12
  8. package/dist/@types/core/readReceipt.d.ts.map +1 -1
  9. package/dist/@types/domains/channel.d.ts +0 -10
  10. package/dist/@types/domains/channel.d.ts.map +1 -1
  11. package/dist/@types/domains/client.d.ts +0 -1
  12. package/dist/@types/domains/client.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +82 -0
  14. package/dist/@types/domains/notification.d.ts.map +1 -0
  15. package/dist/@types/index.d.ts +1 -0
  16. package/dist/@types/index.d.ts.map +1 -1
  17. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  18. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  19. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  20. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  21. package/dist/channelRepository/observers/index.d.ts +0 -1
  22. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  23. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
  24. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  25. package/dist/client/api/createClient.d.ts.map +1 -1
  26. package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
  27. package/dist/client/api/login.d.ts.map +1 -1
  28. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +4 -2
  29. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  30. package/dist/core/events.d.ts +3 -3
  31. package/dist/core/events.d.ts.map +1 -1
  32. package/dist/core/model/idResolvers.d.ts.map +1 -1
  33. package/dist/core/model/index.d.ts.map +1 -1
  34. package/dist/index.cjs.js +462 -567
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.esm.js +445 -551
  38. package/dist/index.umd.js +4 -4
  39. package/dist/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
  40. package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
  41. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  42. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  43. package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
  44. package/dist/notificationTray/api/index.d.ts +3 -0
  45. package/dist/notificationTray/api/index.d.ts.map +1 -0
  46. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  47. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  48. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  49. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  50. package/dist/notificationTray/events/index.d.ts +2 -0
  51. package/dist/notificationTray/events/index.d.ts.map +1 -0
  52. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  53. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  54. package/dist/notificationTray/index.d.ts +4 -0
  55. package/dist/notificationTray/index.d.ts.map +1 -0
  56. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  57. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  58. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  59. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  60. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  61. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  62. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  63. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  64. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  65. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  66. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
  67. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  68. package/dist/notificationTray/observers/index.d.ts +3 -0
  69. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  70. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  71. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  72. package/dist/utils/linkedObject/index.d.ts +1 -0
  73. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  74. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  75. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  76. package/package.json +1 -1
  77. package/src/@types/core/events.ts +6 -2
  78. package/src/@types/core/model.ts +6 -4
  79. package/src/@types/core/payload.ts +25 -0
  80. package/src/@types/core/readReceipt.ts +1 -14
  81. package/src/@types/domains/channel.ts +0 -13
  82. package/src/@types/domains/client.ts +0 -2
  83. package/src/@types/domains/notification.ts +91 -0
  84. package/src/@types/index.ts +1 -0
  85. package/src/channelRepository/events/onChannelDeleted.ts +4 -17
  86. package/src/channelRepository/events/onChannelLeft.ts +3 -11
  87. package/src/channelRepository/observers/getChannel.ts +1 -3
  88. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +1 -6
  89. package/src/channelRepository/observers/index.ts +0 -1
  90. package/src/channelRepository/utils/constructChannelDynamicValue.ts +2 -12
  91. package/src/channelRepository/utils/prepareChannelPayload.ts +17 -57
  92. package/src/client/api/createClient.ts +0 -3
  93. package/src/client/api/enableUnreadCount.ts +0 -1
  94. package/src/client/api/login.ts +1 -5
  95. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +99 -70
  96. package/src/core/model/idResolvers.ts +3 -2
  97. package/src/core/model/index.ts +2 -0
  98. package/src/index.ts +2 -0
  99. package/src/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.ts +3 -3
  100. package/src/messageRepository/events/onMessageCreated.ts +1 -38
  101. package/src/messageRepository/observers/getMessage.ts +1 -0
  102. package/src/messageRepository/utils/markReadMessage.ts +3 -10
  103. package/src/notificationTray/api/index.ts +2 -0
  104. package/src/notificationTray/api/markItemsSeen.ts +59 -0
  105. package/src/notificationTray/api/markTraySeen.ts +65 -0
  106. package/src/notificationTray/events/index.ts +1 -0
  107. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  108. package/src/notificationTray/index.ts +3 -0
  109. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +81 -0
  110. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  111. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  112. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  113. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  114. package/src/notificationTray/observers/getNotificationTraySeen.ts +43 -0
  115. package/src/notificationTray/observers/index.ts +2 -0
  116. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  117. package/src/utils/linkedObject/index.ts +2 -0
  118. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
  119. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +0 -16
  120. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +0 -1
  121. package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
  122. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +0 -11
  123. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +0 -1
  124. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +0 -20
  125. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +0 -1
  126. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +0 -2
  127. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +0 -1
  128. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -33
  129. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
  130. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -3
  131. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  132. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +0 -12
  133. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +0 -1
  134. package/src/channelRepository/api/markChannelsAsReadBySegment.ts +0 -29
  135. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +0 -38
  136. package/src/channelRepository/observers/getTotalChannelsUnread.ts +0 -129
  137. package/src/channelRepository/utils/getLegacyChannelUnread.ts +0 -5
  138. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +0 -267
  139. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +0 -21
  140. package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +0 -29
package/dist/index.esm.js CHANGED
@@ -106,6 +106,7 @@ 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;
109
110
  const YEAR = 365 * DAY;
110
111
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
111
112
 
@@ -501,7 +502,6 @@ const idResolvers = {
501
502
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
502
503
  channelUnreadInfo: ({ channelId }) => channelId,
503
504
  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,6 +528,8 @@ 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,
531
533
  };
532
534
  /**
533
535
  * Retrieve the id resolver matching a domain name
@@ -579,6 +581,7 @@ const PAYLOAD2MODEL = {
579
581
  advertisers: 'advertiser',
580
582
  pinTargets: 'pinTarget',
581
583
  pins: 'pin',
584
+ notificationTrayItems: 'notificationTrayItem',
582
585
  };
583
586
  /** hidden */
584
587
  const isOutdated = (prevData, nextData) => {
@@ -1595,13 +1598,13 @@ class NetworkActivitiesWatcher {
1595
1598
  this._listener.clear();
1596
1599
  }
1597
1600
  }
1598
- let instance$6;
1601
+ let instance$5;
1599
1602
  var NetworkActivitiesWatcher$1 = {
1600
1603
  getInstance: () => {
1601
- if (!instance$6) {
1602
- instance$6 = new NetworkActivitiesWatcher();
1604
+ if (!instance$5) {
1605
+ instance$5 = new NetworkActivitiesWatcher();
1603
1606
  }
1604
- return instance$6;
1607
+ return instance$5;
1605
1608
  },
1606
1609
  };
1607
1610
 
@@ -21241,13 +21244,13 @@ class AnalyticsEngine {
21241
21244
  this._eventCapturer.resetAllBuckets();
21242
21245
  }
21243
21246
  }
21244
- let instance$5;
21247
+ let instance$4;
21245
21248
  var AnalyticsEngine$1 = {
21246
21249
  getInstance: () => {
21247
- if (!instance$5) {
21248
- instance$5 = new AnalyticsEngine();
21250
+ if (!instance$4) {
21251
+ instance$4 = new AnalyticsEngine();
21249
21252
  }
21250
- return instance$5;
21253
+ return instance$4;
21251
21254
  },
21252
21255
  };
21253
21256
 
@@ -21673,221 +21676,6 @@ const getMessageReadCount = (message, marker) => {
21673
21676
  getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
21674
21677
  }; // and if not found in cache use default value `0`
21675
21678
 
21676
- /**
21677
- *
21678
- * Mark subChannel as read by readToSegment
21679
- *
21680
- * @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
21681
- * @param readToSegment the segment to mark as read
21682
- * @returns a success boolean if the {@link Amity.SubChannel} was updated
21683
- *
21684
- * @category Channel API
21685
- * @async
21686
- */
21687
- const markChannelsAsReadBySegment = async (readings) => {
21688
- const client = getActiveClient();
21689
- try {
21690
- await client.http.post('api/v3/channels/seen', { channels: readings });
21691
- return true;
21692
- }
21693
- catch (e) {
21694
- return false;
21695
- }
21696
- };
21697
-
21698
- class MessageReadReceiptSyncEngine {
21699
- constructor() {
21700
- this.isActive = true;
21701
- this.MAX_RETRY = 3;
21702
- this.JOB_QUEUE_SIZE = 120;
21703
- this.jobQueue = [];
21704
- // Interval for message read receipt sync in seconds
21705
- this.RECEIPT_SYNC_INTERVAL = 1;
21706
- this.client = getActiveClient();
21707
- // Get remaining unsync read receipts from cache
21708
- this.getUnsyncJobs();
21709
- }
21710
- // Call this when client call client.login
21711
- startSyncReadReceipt() {
21712
- // Start timer when start receipt sync
21713
- this.timer = setInterval(() => {
21714
- this.syncReadReceipts();
21715
- }, this.RECEIPT_SYNC_INTERVAL * 1000);
21716
- }
21717
- // Read receipt observer handling
21718
- syncReadReceipts() {
21719
- if (this.jobQueue.length === 0 || this.isActive === false)
21720
- return;
21721
- const readReceipts = this.getReadReceipts();
21722
- if (readReceipts) {
21723
- this.markReadApi(readReceipts);
21724
- }
21725
- }
21726
- getUnsyncJobs() {
21727
- var _a;
21728
- // Get all read receipts that has latestSyncSegment < latestSegment
21729
- const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21730
- return data.latestSyncSegment < data.latestSegment;
21731
- });
21732
- // Enqueue unsync read receipts to the job queue
21733
- readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
21734
- this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
21735
- });
21736
- }
21737
- getReadReceipts() {
21738
- // get all read receipts from queue, now the queue is empty
21739
- const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
21740
- if (syncJob.length === 0)
21741
- return;
21742
- return syncJob.filter(job => {
21743
- var _a;
21744
- const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
21745
- if (!readReceipt)
21746
- return false;
21747
- if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
21748
- return true;
21749
- return false;
21750
- });
21751
- }
21752
- async markReadApi(syncJobs) {
21753
- var _a;
21754
- // constuct payload
21755
- // example: [{ channelId: 'channelId', readToSegment: 2 }]
21756
- const syncJobsPayload = syncJobs.map(job => {
21757
- return {
21758
- channelId: job.channelId,
21759
- readToSegment: job.segment,
21760
- };
21761
- });
21762
- const response = await markChannelsAsReadBySegment(syncJobsPayload);
21763
- if (response) {
21764
- for (let i = 0; i < syncJobs.length; i += 1) {
21765
- // update lastestSyncSegment in read receipt cache
21766
- const cacheKey = ['readReceipt', syncJobs[i].channelId];
21767
- const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21768
- pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
21769
- }
21770
- }
21771
- else {
21772
- for (let i = 0; i < syncJobs.length; i += 1) {
21773
- // push them back to queue if the syncing is failed and retry count is less than max retry
21774
- if (syncJobs[i].retryCount >= this.MAX_RETRY)
21775
- return;
21776
- const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
21777
- this.enqueueJob(updatedJob);
21778
- }
21779
- }
21780
- }
21781
- startObservingReadReceiptQueue() {
21782
- if (this.client.useLegacyUnreadCount) {
21783
- this.isActive = true;
21784
- this.startSyncReadReceipt();
21785
- }
21786
- }
21787
- stopObservingReadReceiptQueue() {
21788
- this.isActive = false;
21789
- this.jobQueue.map(job => {
21790
- if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21791
- return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
21792
- }
21793
- return job;
21794
- });
21795
- if (this.timer)
21796
- clearInterval(this.timer);
21797
- }
21798
- // Session Management
21799
- onSessionEstablished() {
21800
- this.startObservingReadReceiptQueue();
21801
- }
21802
- onSessionDestroyed() {
21803
- this.stopObservingReadReceiptQueue();
21804
- this.jobQueue = [];
21805
- }
21806
- onTokenExpired() {
21807
- this.stopObservingReadReceiptQueue();
21808
- }
21809
- // Network Connection Management
21810
- onNetworkOffline() {
21811
- // Stop observing to the read receipt queue.
21812
- this.stopObservingReadReceiptQueue();
21813
- }
21814
- onNetworkOnline() {
21815
- // Resume observing to the read receipt queue.
21816
- this.startObservingReadReceiptQueue();
21817
- }
21818
- markRead(channelId, segment) {
21819
- var _a;
21820
- // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
21821
- const cacheKey = ['channelUnread', 'get', channelId];
21822
- const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21823
- if (channelUnread && segment > channelUnread.readToSegment) {
21824
- channelUnread.readToSegment = segment;
21825
- channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
21826
- pushToCache(cacheKey, channelUnread);
21827
- fireEvent('local.channelUnread.updated', channelUnread);
21828
- }
21829
- // Step 2: Enqueue the read receipt
21830
- this.enqueueReadReceipt(channelId, segment);
21831
- }
21832
- enqueueReadReceipt(channelId, segment) {
21833
- var _a;
21834
- const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
21835
- // Create new read receipt if it's not exists and add the job to queue
21836
- if (!readReceipt) {
21837
- const readReceiptChannel = {
21838
- channelId,
21839
- latestSegment: segment,
21840
- latestSyncSegment: 0,
21841
- };
21842
- pushToCache(['readReceipt', channelId], readReceiptChannel);
21843
- }
21844
- else if (readReceipt.latestSegment < segment) {
21845
- // Update latestSegment in read receipt cache
21846
- pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21847
- }
21848
- else if (readReceipt.latestSyncSegment >= segment) {
21849
- // Skip the job when lastSyncSegment > = segment
21850
- return;
21851
- }
21852
- let syncJob = this.getSyncJob(channelId);
21853
- if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21854
- syncJob = {
21855
- channelId,
21856
- segment,
21857
- syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
21858
- retryCount: 0,
21859
- };
21860
- this.enqueueJob(syncJob);
21861
- }
21862
- else if (syncJob.segment < segment) {
21863
- syncJob.segment = segment;
21864
- }
21865
- }
21866
- getSyncJob(channelId) {
21867
- const { jobQueue } = this;
21868
- const targetJob = jobQueue.find(job => job.channelId === channelId);
21869
- return targetJob || null;
21870
- }
21871
- enqueueJob(syncJob) {
21872
- if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
21873
- this.jobQueue.push(syncJob);
21874
- }
21875
- else {
21876
- // Remove oldest job when queue reach maximum capacity
21877
- this.jobQueue.shift();
21878
- this.jobQueue.push(syncJob);
21879
- }
21880
- }
21881
- }
21882
- let instance$4 = null;
21883
- var ReadReceiptSyncEngine = {
21884
- getInstance: () => {
21885
- if (!instance$4)
21886
- instance$4 = new MessageReadReceiptSyncEngine();
21887
- return instance$4;
21888
- },
21889
- };
21890
-
21891
21679
  /**
21892
21680
  *
21893
21681
  * Mark subChannel as read by readToSegment
@@ -21936,7 +21724,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21936
21724
  return channelUnreadInfo;
21937
21725
  };
21938
21726
 
21939
- class LegacyMessageReadReceiptSyncEngine {
21727
+ class MessageReadReceiptSyncEngine {
21940
21728
  constructor() {
21941
21729
  this.isActive = true;
21942
21730
  this.MAX_RETRY = 3;
@@ -21967,7 +21755,7 @@ class LegacyMessageReadReceiptSyncEngine {
21967
21755
  getUnsyncJobs() {
21968
21756
  var _a;
21969
21757
  // Get all read receipts that has latestSyncSegment < latestSegment
21970
- const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21758
+ const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21971
21759
  return data.latestSyncSegment < data.latestSegment;
21972
21760
  });
21973
21761
  // Enqueue unsync read receipts to the job queue
@@ -21986,7 +21774,7 @@ class LegacyMessageReadReceiptSyncEngine {
21986
21774
  return;
21987
21775
  // Get readReceipt from cache by subChannelId
21988
21776
  const readReceipt = (_a = pullFromCache([
21989
- 'legacyReadReceipt',
21777
+ 'readReceipt',
21990
21778
  syncJob.subChannelId,
21991
21779
  ])) === null || _a === void 0 ? void 0 : _a.data;
21992
21780
  if (!readReceipt)
@@ -22009,10 +21797,10 @@ class LegacyMessageReadReceiptSyncEngine {
22009
21797
  if (response) {
22010
21798
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
22011
21799
  const readReceiptCache = (_a = pullFromCache([
22012
- 'legacyReadReceipt',
21800
+ 'readReceipt',
22013
21801
  subChannelId,
22014
21802
  ])) === null || _a === void 0 ? void 0 : _a.data;
22015
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
21803
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
22016
21804
  }
22017
21805
  else if (!response) {
22018
21806
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -22079,7 +21867,7 @@ class LegacyMessageReadReceiptSyncEngine {
22079
21867
  subChannelUnreadInfo.readToSegment = segment;
22080
21868
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
22081
21869
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
22082
- fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
21870
+ fireEvent('local.channelUnread.updated', channelUnreadInfo);
22083
21871
  pushToCache(cacheKey, subChannelUnreadInfo);
22084
21872
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
22085
21873
  }
@@ -22088,10 +21876,7 @@ class LegacyMessageReadReceiptSyncEngine {
22088
21876
  }
22089
21877
  enqueueReadReceipt(subChannelId, segment) {
22090
21878
  var _a;
22091
- const readReceipt = (_a = pullFromCache([
22092
- 'legacyReadReceipt',
22093
- subChannelId,
22094
- ])) === null || _a === void 0 ? void 0 : _a.data;
21879
+ const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
22095
21880
  // Create new read receipt if it's not exists and add job to queue
22096
21881
  if (!readReceipt) {
22097
21882
  const readReceiptSubChannel = {
@@ -22099,10 +21884,10 @@ class LegacyMessageReadReceiptSyncEngine {
22099
21884
  latestSegment: segment,
22100
21885
  latestSyncSegment: 0,
22101
21886
  };
22102
- pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
21887
+ pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
22103
21888
  }
22104
21889
  else if (readReceipt.latestSegment < segment) {
22105
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21890
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
22106
21891
  }
22107
21892
  else if (readReceipt.latestSyncSegment >= segment) {
22108
21893
  // Skip the job when lastSyncSegment > = segment
@@ -22145,24 +21930,18 @@ class LegacyMessageReadReceiptSyncEngine {
22145
21930
  }
22146
21931
  }
22147
21932
  let instance$3 = null;
22148
- var LegacyReadReceiptSyncEngine = {
21933
+ var ReadReceiptSyncEngine = {
22149
21934
  getInstance: () => {
22150
21935
  if (!instance$3)
22151
- instance$3 = new LegacyMessageReadReceiptSyncEngine();
21936
+ instance$3 = new MessageReadReceiptSyncEngine();
22152
21937
  return instance$3;
22153
21938
  },
22154
21939
  };
22155
21940
 
22156
21941
  const markReadMessage = (message) => {
22157
- const client = getActiveClient();
22158
- if (client.useLegacyUnreadCount) {
22159
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
22160
- markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
22161
- }
22162
- else {
22163
- const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
22164
- markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
22165
- }
21942
+ const { subChannelId, channelSegment } = message;
21943
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
21944
+ markReadReceiptEngine.markRead(subChannelId, channelSegment);
22166
21945
  };
22167
21946
 
22168
21947
  const messageLinkedObject = (message) => {
@@ -22310,6 +22089,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22310
22089
  } });
22311
22090
  };
22312
22091
 
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
+
22313
22100
  const LinkedObject = {
22314
22101
  ad: adLinkedObject,
22315
22102
  comment: commentLinkedObject,
@@ -22323,6 +22110,7 @@ const LinkedObject = {
22323
22110
  reactor: reactorLinkedObject,
22324
22111
  channel: channelLinkedObject,
22325
22112
  pinnedPost: pinnedPostLinkedObject,
22113
+ notificationTray: notificationTrayLinkedObject,
22326
22114
  };
22327
22115
 
22328
22116
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -23150,24 +22938,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
23150
22938
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
23151
22939
  });
23152
22940
  };
23153
- const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
23154
- for (let i = 0; i < channels.length; i += 1) {
23155
- const cacheKey = ['channelUnread', 'get', channels[i].channelId];
23156
- const { readToSegment, lastMentionedSegment } = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId) || {
23157
- readToSegment: 0,
23158
- lastMentionedSegment: 0,
23159
- };
23160
- pushToCache(cacheKey, {
23161
- channelId: channels[i].channelId,
23162
- lastSegment: channels[i].messageCount,
23163
- readToSegment,
23164
- lastMentionedSegment,
23165
- unreadCount: Math.max(channels[i].messageCount - readToSegment, 0),
23166
- isMentioned: lastMentionedSegment > readToSegment,
23167
- isDeleted: channels[i].isDeleted,
23168
- });
23169
- }
23170
- };
23171
22941
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
23172
22942
  const client = getActiveClient();
23173
22943
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -23177,34 +22947,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
23177
22947
  rawPayload.messagePreviews.length > 0) {
23178
22948
  updateChannelMessagePreviewCache(rawPayload);
23179
22949
  }
23180
- if (client.useLegacyUnreadCount) {
23181
- updateChannelUnread({
23182
- channels: rawPayload.channels,
23183
- channelUsers: rawPayload.channelUsers,
23184
- currentUserId: client.userId,
23185
- });
23186
- }
23187
- else {
23188
- const markerIds = rawPayload.channels
23189
- // filter channel by type. Only conversation, community and broadcast type are included.
23190
- .filter(isUnreadCountSupport)
23191
- .map(({ channelInternalId }) => channelInternalId);
23192
- if (markerIds.length > 0) {
23193
- // since the get markers method requires a channel cache to function with the reducer.
23194
- preUpdateChannelCache(rawPayload, {
23195
- isMessagePreviewUpdated: options.isMessagePreviewUpdated,
23196
- });
23197
- try {
23198
- await getChannelMarkers(markerIds);
23199
- }
23200
- catch (e) {
23201
- // empty block (from the spec, allow marker fetch to fail without having to do anything)
23202
- }
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)
23203
22962
  }
23204
22963
  }
23205
- // convert raw channel to internal channel
22964
+ // attach marker to channel
23206
22965
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
23207
- // convert raw channel user to membership (add user object)
22966
+ // user marker to channel users
23208
22967
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
23209
22968
  return convertRawMembershipToMembership(channelUser);
23210
22969
  });
@@ -23331,28 +23090,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23331
23090
  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;
23332
23091
  };
23333
23092
 
23334
- const getLegacyChannelUnread = (channelId) => {
23335
- var _a;
23336
- return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
23337
- };
23338
-
23339
23093
  const constructChannelDynamicValue = (channel) => {
23340
- const client = getActiveClient();
23341
23094
  const rest = __rest(channel, ["messageCount"]);
23342
23095
  return shallowClone(rest, {
23343
- get unreadCount() {
23344
- var _a, _b;
23345
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
23096
+ get isMentioned() {
23097
+ return getChannelIsMentioned(rest);
23346
23098
  },
23347
23099
  get subChannelsUnreadCount() {
23348
23100
  return getSubChannelsUnreadCount(rest);
23349
23101
  },
23350
- get isMentioned() {
23351
- var _a, _b;
23352
- if (client.useLegacyUnreadCount)
23353
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
23354
- return getChannelIsMentioned(rest);
23355
- },
23356
23102
  });
23357
23103
  };
23358
23104
 
@@ -24009,21 +23755,12 @@ const onChannelDeleted = (callback) => {
24009
23755
  const client = getActiveClient();
24010
23756
  const filter = async (payload) => {
24011
23757
  const data = await prepareChannelPayload(payload);
24012
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24013
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24014
- data.channels.forEach(channel => {
24015
- if (isConsistentMode) {
23758
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23759
+ data.channels.forEach(channel => {
24016
23760
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24017
23761
  deleteChannelUnreadByChannelId(channel.channelId);
24018
- }
24019
- else if (isLegacyUnreadCount) {
24020
- const cacheKey = ['channelUnread', 'get', channel.channelId];
24021
- const cache = pullFromCache(cacheKey);
24022
- if (cache) {
24023
- pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
24024
- }
24025
- }
24026
- });
23762
+ });
23763
+ }
24027
23764
  ingestInCache(data);
24028
23765
  callbacks$b.forEach(cb => cb(data.channels[0]));
24029
23766
  };
@@ -24137,25 +23874,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
24137
23874
  };
24138
23875
  };
24139
23876
 
24140
- var legacyReadReceiptSyncEngineOnLoginHandler = () => {
24141
- const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
24142
- readReceiptSyncEngine.startSyncReadReceipt();
24143
- onSessionStateChange(state => {
24144
- if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
24145
- readReceiptSyncEngine.onSessionEstablished();
24146
- }
24147
- else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
24148
- readReceiptSyncEngine.onTokenExpired();
24149
- }
24150
- else {
24151
- readReceiptSyncEngine.onSessionDestroyed();
24152
- }
24153
- });
24154
- return () => {
24155
- readReceiptSyncEngine.onSessionDestroyed();
24156
- };
24157
- };
24158
-
24159
23877
  const onOnline = (callback) => {
24160
23878
  if (typeof window !== 'undefined' && window.addEventListener) {
24161
23879
  window.addEventListener('online', callback);
@@ -24722,17 +24440,10 @@ const onChannelLeft = (callback) => {
24722
24440
  const preparedPayload = await prepareChannelPayload(payload, {
24723
24441
  isMessagePreviewUpdated: isLeftByMe,
24724
24442
  });
24725
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24726
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24727
- if (isLeftByMe) {
24443
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
24728
24444
  preparedPayload.channels.forEach(channel => {
24729
- if (isConsistentMode) {
24730
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24731
- deleteChannelUnreadByChannelId(channel.channelId);
24732
- }
24733
- else if (isLegacyUnreadCount) {
24734
- dropFromCache(['channelUnread', 'get', channel.channelId]);
24735
- }
24445
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24446
+ deleteChannelUnreadByChannelId(channel.channelId);
24736
24447
  });
24737
24448
  }
24738
24449
  const { channels, channelUsers } = preparedPayload;
@@ -25000,31 +24711,6 @@ const onMessageCreatedMqtt = (callback) => {
25000
24711
  reCalculateChannelUnreadInfo(message.channelId);
25001
24712
  });
25002
24713
  }
25003
- if (client.useLegacyUnreadCount) {
25004
- rawPayload.messages.forEach(message => {
25005
- var _a, _b;
25006
- const channelUnread = (_a = pullFromCache([
25007
- 'channelUnread',
25008
- 'get',
25009
- message.channelId,
25010
- ])) === null || _a === void 0 ? void 0 : _a.data;
25011
- if (!channelUnread || channelUnread.lastSegment >= message.segment)
25012
- return;
25013
- const lastSegment = message.segment;
25014
- const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
25015
- return (mention.type === 'channel' ||
25016
- (mention.type === 'user' &&
25017
- client.userId &&
25018
- mention.userPublicIds.includes(client.userId)));
25019
- });
25020
- const lastMentionSegment = isMentionedInMessage
25021
- ? message.segment
25022
- : channelUnread.lastMentionSegment;
25023
- const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionSegment) });
25024
- pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
25025
- fireEvent('local.channelUnread.updated', updatedChannelUnread);
25026
- });
25027
- }
25028
24714
  // Update in cache
25029
24715
  ingestInCache(payload);
25030
24716
  payload.messages.forEach(message => {
@@ -25200,7 +24886,6 @@ const enableUnreadCount = () => {
25200
24886
  if (client.isUnreadCountEnabled)
25201
24887
  return false;
25202
24888
  client.isUnreadCountEnabled = true;
25203
- client.useLegacyUnreadCount = false;
25204
24889
  client.emitter.emit('unreadCountEnabled', true);
25205
24890
  return true;
25206
24891
  };
@@ -25516,12 +25201,7 @@ const login = async (params, sessionHandler, config) => {
25516
25201
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
25517
25202
  // the channel because currently backend can't handle this, so every time a user is banned from
25518
25203
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
25519
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25520
- if (client.useLegacyUnreadCount) {
25521
- subscriptions.push(readReceiptSyncEngineOnLoginHandler());
25522
- }
25523
- else
25524
- subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
25204
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25525
25205
  const markerSyncUnsubscriber = await startMarkerSync();
25526
25206
  subscriptions.push(markerSyncUnsubscriber);
25527
25207
  }
@@ -25702,8 +25382,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25702
25382
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25703
25383
  const sessionHandler = undefined;
25704
25384
  const isUnreadCountEnabled = false;
25705
- // Legacy unread count is true by default
25706
- const useLegacyUnreadCount = true;
25707
25385
  const client = {
25708
25386
  version: `${VERSION}`,
25709
25387
  apiKey,
@@ -25733,7 +25411,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25733
25411
  getMessagePreviewSetting,
25734
25412
  use: () => setActiveClient(client),
25735
25413
  isUnreadCountEnabled,
25736
- useLegacyUnreadCount,
25737
25414
  getMarkerSyncConsistentMode,
25738
25415
  /**
25739
25416
  * Prefix for the deviceId key in the local storage or async storage.
@@ -26204,7 +25881,7 @@ const getUserUnread = (callback) => {
26204
25881
  };
26205
25882
  };
26206
25883
 
26207
- var index$l = /*#__PURE__*/Object.freeze({
25884
+ var index$m = /*#__PURE__*/Object.freeze({
26208
25885
  __proto__: null,
26209
25886
  getActiveClient: getActiveClient,
26210
25887
  getActiveUser: getActiveUser,
@@ -27411,7 +27088,7 @@ const getMyFollowInfo = (callback) => {
27411
27088
  };
27412
27089
  /* end_public_function */
27413
27090
 
27414
- var index$k = /*#__PURE__*/Object.freeze({
27091
+ var index$l = /*#__PURE__*/Object.freeze({
27415
27092
  __proto__: null,
27416
27093
  blockUser: blockUser,
27417
27094
  unBlockUser: unBlockUser,
@@ -28426,9 +28103,9 @@ var AmityUserSearchMatchType;
28426
28103
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28427
28104
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28428
28105
 
28429
- var index$j = /*#__PURE__*/Object.freeze({
28106
+ var index$k = /*#__PURE__*/Object.freeze({
28430
28107
  __proto__: null,
28431
- Relationship: index$k,
28108
+ Relationship: index$l,
28432
28109
  getUserByIds: getUserByIds,
28433
28110
  updateUser: updateUser,
28434
28111
  flagUser: flagUser,
@@ -28692,7 +28369,7 @@ const uploadImage = async (formData, onProgress) => {
28692
28369
  };
28693
28370
  /* end_public_function */
28694
28371
 
28695
- var index$i = /*#__PURE__*/Object.freeze({
28372
+ var index$j = /*#__PURE__*/Object.freeze({
28696
28373
  __proto__: null,
28697
28374
  getFile: getFile,
28698
28375
  uploadFile: uploadFile,
@@ -30504,7 +30181,7 @@ const getReactions = (params, callback, config) => {
30504
30181
  };
30505
30182
  /* end_public_function */
30506
30183
 
30507
- var index$h = /*#__PURE__*/Object.freeze({
30184
+ var index$i = /*#__PURE__*/Object.freeze({
30508
30185
  __proto__: null,
30509
30186
  addReaction: addReaction,
30510
30187
  removeReaction: removeReaction,
@@ -32320,7 +31997,7 @@ const getMessages = (params, callback, config) => {
32320
31997
  };
32321
31998
  /* end_public_function */
32322
31999
 
32323
- var index$g = /*#__PURE__*/Object.freeze({
32000
+ var index$h = /*#__PURE__*/Object.freeze({
32324
32001
  __proto__: null,
32325
32002
  createMessage: createMessage,
32326
32003
  updateMessage: updateMessage,
@@ -32846,7 +32523,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32846
32523
  };
32847
32524
  /* end_public_function */
32848
32525
 
32849
- var index$f = /*#__PURE__*/Object.freeze({
32526
+ var index$g = /*#__PURE__*/Object.freeze({
32850
32527
  __proto__: null,
32851
32528
  getSubChannelByIds: getSubChannels$1,
32852
32529
  createSubChannel: createSubChannel,
@@ -32867,37 +32544,19 @@ var index$f = /*#__PURE__*/Object.freeze({
32867
32544
  /**
32868
32545
  * Internal used only
32869
32546
  *
32870
- * Fired when an {@link Amity.channelUnreadInfo} has been updated.
32871
- *
32872
- * @param callback The function to call when the event was fired
32873
- * @returns an {@link Amity.Unsubscriber} function to stop listening
32874
- *
32875
- * @category ChannelMarker Events
32876
- */
32877
- const onChannelUnreadInfoUpdatedLocal = (callback) => {
32878
- const client = getActiveClient();
32879
- const filter = (payload) => {
32880
- callback(payload);
32881
- };
32882
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
32883
- };
32884
-
32885
- /**
32886
- * Internal used only
32887
- *
32888
- * Fired when an {@link Amity.ChannelUnread} has been updated.
32547
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32889
32548
  *
32890
32549
  * @param callback The function to call when the event was fired
32891
32550
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32892
32551
  *
32893
- * @category Channel Events
32552
+ * @category MessageMarker Events
32894
32553
  */
32895
32554
  const onChannelUnreadUpdatedLocal = (callback) => {
32896
32555
  const client = getActiveClient();
32897
32556
  const filter = (payload) => {
32898
32557
  callback(payload);
32899
32558
  };
32900
- return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32559
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32901
32560
  };
32902
32561
 
32903
32562
  /* begin_public_function
@@ -33099,7 +32758,6 @@ const getChannel = (channelId, callback) => {
33099
32758
  return onSubChannelUpdated(updateMessagePreview);
33100
32759
  }, 'channelId', 'channel'),
33101
32760
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
33102
- convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33103
32761
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33104
32762
  ], {
33105
32763
  forceDispatch: true,
@@ -33613,10 +33271,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33613
33271
  },
33614
33272
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
33615
33273
  },
33616
- {
33617
- fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33618
- action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33619
- },
33620
33274
  {
33621
33275
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33622
33276
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -33682,120 +33336,6 @@ const getChannels = (params, callback, config) => {
33682
33336
  };
33683
33337
  /* end_public_function */
33684
33338
 
33685
- /**
33686
- *
33687
- * Calculate user unread from {@link Amity.ChannelUnread} objects
33688
- *
33689
- * @returns the {@link Amity.UserUnread} objects
33690
- *
33691
- * @category Channel API
33692
- * @async
33693
- */
33694
- const getTotalChannelsUnread$1 = () => {
33695
- var _a;
33696
- const client = getActiveClient();
33697
- client.log('channel/getTotalChannelsUnread.locally');
33698
- const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
33699
- return !data.isDeleted;
33700
- })) || [];
33701
- const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
33702
- acc.unreadCount += data.unreadCount;
33703
- acc.isMentioned = acc.isMentioned || data.isMentioned;
33704
- return acc;
33705
- }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
33706
- const cachedAt = client.cache && Date.now();
33707
- return {
33708
- data: totalChannelsUnread,
33709
- cachedAt,
33710
- };
33711
- };
33712
-
33713
- /* begin_public_function
33714
- id: totalChannelsUnread.get
33715
- */
33716
- /**
33717
- * ```js
33718
- * import { ChannelRepository } from '@amityco/ts-sdk';
33719
- *
33720
- * let totalChannelsUnread;
33721
- *
33722
- * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
33723
- * unread = response.data;
33724
- * });
33725
- * ```
33726
- *
33727
- * Observe all mutation on a given {@link Amity.UserUnread}
33728
- *
33729
- * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
33730
- *
33731
- * @category User Unread Live Object
33732
- *
33733
- */
33734
- const getTotalChannelsUnread = (callback) => {
33735
- const { _id: userId } = getActiveUser();
33736
- if (!userId)
33737
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
33738
- const { log, cache } = getActiveClient();
33739
- if (!cache) {
33740
- console.log('For using Live Object feature you need to enable Cache!');
33741
- }
33742
- const timestamp = Date.now();
33743
- log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
33744
- const disposers = [];
33745
- let isUnsyncedModel = false; // for messages
33746
- let model;
33747
- const dispatcher = (data) => {
33748
- const { data: userUnread } = data;
33749
- const callbackModel = userUnread
33750
- ? {
33751
- unreadCount: userUnread.unreadCount,
33752
- isMentioned: userUnread.isMentioned,
33753
- }
33754
- : undefined;
33755
- model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
33756
- callback({
33757
- data: callbackModel
33758
- ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
33759
- loading: data.loading,
33760
- error: data.error,
33761
- });
33762
- };
33763
- const realtimeRouter = (userUnread) => {
33764
- if (isEqual(model, userUnread))
33765
- return;
33766
- dispatcher({
33767
- loading: false,
33768
- data: userUnread,
33769
- });
33770
- };
33771
- const onFetch = () => {
33772
- const query = createQuery(async () => getTotalChannelsUnread$1());
33773
- runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
33774
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
33775
- dispatcher({
33776
- data,
33777
- origin,
33778
- loading: false,
33779
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
33780
- });
33781
- isUnsyncedModel = true;
33782
- disposers.forEach(fn => fn());
33783
- }
33784
- else if (!isUnsyncedModel) {
33785
- dispatcher({ loading, data, origin, error });
33786
- }
33787
- if (error) {
33788
- disposers.forEach(fn => fn());
33789
- }
33790
- });
33791
- };
33792
- disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
33793
- onFetch();
33794
- return () => {
33795
- disposers.forEach(fn => fn());
33796
- };
33797
- };
33798
-
33799
33339
  /* begin_public_function
33800
33340
  id: channel.member.add
33801
33341
  */
@@ -34160,7 +33700,7 @@ const searchMembers$1 = (params, callback, config) => {
34160
33700
  };
34161
33701
  /* end_public_function */
34162
33702
 
34163
- var index$e = /*#__PURE__*/Object.freeze({
33703
+ var index$f = /*#__PURE__*/Object.freeze({
34164
33704
  __proto__: null,
34165
33705
  addMembers: addMembers$1,
34166
33706
  removeMembers: removeMembers$1,
@@ -34363,7 +33903,7 @@ const unmuteMembers = async (channelId, userIds) => {
34363
33903
  };
34364
33904
  /* end_public_function */
34365
33905
 
34366
- var index$d = /*#__PURE__*/Object.freeze({
33906
+ var index$e = /*#__PURE__*/Object.freeze({
34367
33907
  __proto__: null,
34368
33908
  addRole: addRole,
34369
33909
  removeRole: removeRole,
@@ -34373,10 +33913,10 @@ var index$d = /*#__PURE__*/Object.freeze({
34373
33913
  unmuteMembers: unmuteMembers
34374
33914
  });
34375
33915
 
34376
- var index$c = /*#__PURE__*/Object.freeze({
33916
+ var index$d = /*#__PURE__*/Object.freeze({
34377
33917
  __proto__: null,
34378
- Membership: index$e,
34379
- Moderation: index$d,
33918
+ Membership: index$f,
33919
+ Moderation: index$e,
34380
33920
  getChannelByIds: getChannelByIds$1,
34381
33921
  createChannel: createChannel,
34382
33922
  updateChannel: updateChannel,
@@ -34399,7 +33939,6 @@ var index$c = /*#__PURE__*/Object.freeze({
34399
33939
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
34400
33940
  getChannel: getChannel,
34401
33941
  getChannels: getChannels,
34402
- getTotalChannelsUnread: getTotalChannelsUnread,
34403
33942
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
34404
33943
  isUnreadCountSupport: isUnreadCountSupport,
34405
33944
  convertFromRaw: convertFromRaw,
@@ -35756,7 +35295,7 @@ const searchMembers = (params, callback, config) => {
35756
35295
  };
35757
35296
  /* end_public_function */
35758
35297
 
35759
- var index$b = /*#__PURE__*/Object.freeze({
35298
+ var index$c = /*#__PURE__*/Object.freeze({
35760
35299
  __proto__: null,
35761
35300
  addMembers: addMembers,
35762
35301
  removeMembers: removeMembers,
@@ -36781,7 +36320,7 @@ const unbanMembers = async (communityId, userIds) => {
36781
36320
  };
36782
36321
  /* end_public_function */
36783
36322
 
36784
- var index$a = /*#__PURE__*/Object.freeze({
36323
+ var index$b = /*#__PURE__*/Object.freeze({
36785
36324
  __proto__: null,
36786
36325
  addRoles: addRoles,
36787
36326
  removeRoles: removeRoles,
@@ -36789,10 +36328,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36789
36328
  unbanMembers: unbanMembers
36790
36329
  });
36791
36330
 
36792
- var index$9 = /*#__PURE__*/Object.freeze({
36331
+ var index$a = /*#__PURE__*/Object.freeze({
36793
36332
  __proto__: null,
36794
- Moderation: index$a,
36795
- Membership: index$b,
36333
+ Moderation: index$b,
36334
+ Membership: index$c,
36796
36335
  getCommunityByIds: getCommunities$1,
36797
36336
  createCommunity: createCommunity,
36798
36337
  updateCommunity: updateCommunity,
@@ -37025,7 +36564,7 @@ const getCategories = (params, callback, config) => {
37025
36564
  };
37026
36565
  /* end_public_function */
37027
36566
 
37028
- var index$8 = /*#__PURE__*/Object.freeze({
36567
+ var index$9 = /*#__PURE__*/Object.freeze({
37029
36568
  __proto__: null,
37030
36569
  getCategory: getCategory,
37031
36570
  getCategories: getCategories
@@ -37193,7 +36732,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
37193
36732
  : undefined;
37194
36733
  };
37195
36734
 
37196
- var index$7 = /*#__PURE__*/Object.freeze({
36735
+ var index$8 = /*#__PURE__*/Object.freeze({
37197
36736
  __proto__: null,
37198
36737
  queryGlobalFeed: queryGlobalFeed,
37199
36738
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38508,7 +38047,7 @@ const getComments = (params, callback, config) => {
38508
38047
  };
38509
38048
  /* end_public_function */
38510
38049
 
38511
- var index$6 = /*#__PURE__*/Object.freeze({
38050
+ var index$7 = /*#__PURE__*/Object.freeze({
38512
38051
  __proto__: null,
38513
38052
  getCommentByIds: getCommentByIds,
38514
38053
  createComment: createComment,
@@ -39515,7 +39054,7 @@ const semanticSearchPosts = (params, callback, config) => {
39515
39054
  };
39516
39055
  };
39517
39056
 
39518
- var index$5 = /*#__PURE__*/Object.freeze({
39057
+ var index$6 = /*#__PURE__*/Object.freeze({
39519
39058
  __proto__: null,
39520
39059
  getPostByIds: getPostByIds,
39521
39060
  createPost: createPost,
@@ -40049,7 +39588,7 @@ const getStreams = (params, callback, config) => {
40049
39588
  };
40050
39589
  };
40051
39590
 
40052
- var index$4 = /*#__PURE__*/Object.freeze({
39591
+ var index$5 = /*#__PURE__*/Object.freeze({
40053
39592
  __proto__: null,
40054
39593
  createStream: createStream,
40055
39594
  updateStream: updateStream,
@@ -40336,7 +39875,7 @@ const getPoll = (pollId, callback) => {
40336
39875
  };
40337
39876
  /* end_public_function */
40338
39877
 
40339
- var index$3 = /*#__PURE__*/Object.freeze({
39878
+ var index$4 = /*#__PURE__*/Object.freeze({
40340
39879
  __proto__: null,
40341
39880
  createPoll: createPoll,
40342
39881
  closePoll: closePoll,
@@ -40707,7 +40246,7 @@ const getPlayer = async (parameters) => {
40707
40246
  return video;
40708
40247
  };
40709
40248
 
40710
- var index$2 = /*#__PURE__*/Object.freeze({
40249
+ var index$3 = /*#__PURE__*/Object.freeze({
40711
40250
  __proto__: null,
40712
40251
  getPlayer: getPlayer
40713
40252
  });
@@ -41880,7 +41419,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41880
41419
  };
41881
41420
  };
41882
41421
 
41883
- var index$1 = /*#__PURE__*/Object.freeze({
41422
+ var index$2 = /*#__PURE__*/Object.freeze({
41884
41423
  __proto__: null,
41885
41424
  createImageStory: createImageStory,
41886
41425
  createVideoStory: createVideoStory,
@@ -41917,7 +41456,7 @@ const getNetworkAds = async () => {
41917
41456
  };
41918
41457
  };
41919
41458
 
41920
- var index = /*#__PURE__*/Object.freeze({
41459
+ var index$1 = /*#__PURE__*/Object.freeze({
41921
41460
  __proto__: null,
41922
41461
  getNetworkAds: getNetworkAds
41923
41462
  });
@@ -41944,4 +41483,359 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41944
41483
  return { accessToken: data.accessToken };
41945
41484
  };
41946
41485
 
41947
- 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 };
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 };