@amityco/ts-sdk 7.1.1-53d7c83.0 → 7.1.1-611ceb49.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 (137) 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 +81 -0
  14. package/dist/@types/domains/notification.d.ts.map +1 -0
  15. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  16. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  17. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  18. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  19. package/dist/channelRepository/observers/index.d.ts +0 -1
  20. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  21. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
  22. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  23. package/dist/client/api/createClient.d.ts.map +1 -1
  24. package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
  25. package/dist/client/api/login.d.ts.map +1 -1
  26. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +4 -2
  27. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  28. package/dist/core/events.d.ts +3 -3
  29. package/dist/core/events.d.ts.map +1 -1
  30. package/dist/core/model/idResolvers.d.ts.map +1 -1
  31. package/dist/core/model/index.d.ts.map +1 -1
  32. package/dist/index.cjs.js +475 -586
  33. package/dist/index.d.ts +1 -0
  34. package/dist/index.d.ts.map +1 -1
  35. package/dist/index.esm.js +451 -563
  36. package/dist/index.umd.js +4 -4
  37. package/dist/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
  38. package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
  39. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  40. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  41. package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
  42. package/dist/notificationTrayRepository/api/index.d.ts +3 -0
  43. package/dist/notificationTrayRepository/api/index.d.ts.map +1 -0
  44. package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts +16 -0
  45. package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts.map +1 -0
  46. package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts +19 -0
  47. package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts.map +1 -0
  48. package/dist/notificationTrayRepository/events/index.d.ts +2 -0
  49. package/dist/notificationTrayRepository/events/index.d.ts.map +1 -0
  50. package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts +17 -0
  51. package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  52. package/dist/notificationTrayRepository/index.d.ts +4 -0
  53. package/dist/notificationTrayRepository/index.d.ts.map +1 -0
  54. package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts +30 -0
  55. package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  56. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  57. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  58. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  59. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  60. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  61. package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  62. package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts +12 -0
  63. package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts.map +1 -0
  64. package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts +21 -0
  65. package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts.map +1 -0
  66. package/dist/notificationTrayRepository/observers/index.d.ts +3 -0
  67. package/dist/notificationTrayRepository/observers/index.d.ts.map +1 -0
  68. package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  69. package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  70. package/dist/utils/linkedObject/index.d.ts +1 -0
  71. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  72. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  73. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  74. package/package.json +1 -1
  75. package/src/@types/core/events.ts +6 -2
  76. package/src/@types/core/model.ts +6 -4
  77. package/src/@types/core/payload.ts +25 -0
  78. package/src/@types/core/readReceipt.ts +1 -14
  79. package/src/@types/domains/channel.ts +0 -13
  80. package/src/@types/domains/client.ts +0 -2
  81. package/src/@types/domains/notification.ts +90 -0
  82. package/src/channelRepository/events/onChannelDeleted.ts +4 -17
  83. package/src/channelRepository/events/onChannelLeft.ts +3 -11
  84. package/src/channelRepository/observers/getChannel.ts +1 -3
  85. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +1 -6
  86. package/src/channelRepository/observers/index.ts +0 -1
  87. package/src/channelRepository/utils/constructChannelDynamicValue.ts +2 -12
  88. package/src/channelRepository/utils/prepareChannelPayload.ts +17 -66
  89. package/src/client/api/createClient.ts +0 -3
  90. package/src/client/api/enableUnreadCount.ts +0 -1
  91. package/src/client/api/login.ts +1 -5
  92. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +99 -74
  93. package/src/core/model/idResolvers.ts +3 -2
  94. package/src/core/model/index.ts +2 -0
  95. package/src/index.ts +2 -0
  96. package/src/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.ts +3 -3
  97. package/src/messageRepository/events/onMessageCreated.ts +1 -45
  98. package/src/messageRepository/observers/getMessage.ts +1 -0
  99. package/src/messageRepository/utils/markReadMessage.ts +3 -10
  100. package/src/notificationTrayRepository/api/index.ts +2 -0
  101. package/src/notificationTrayRepository/api/markNotificationItemsSeen.ts +59 -0
  102. package/src/notificationTrayRepository/api/markNotificationTraySeen.ts +65 -0
  103. package/src/notificationTrayRepository/events/index.ts +1 -0
  104. package/src/notificationTrayRepository/events/onNotificationTraySeenUpdated.ts +36 -0
  105. package/src/notificationTrayRepository/index.ts +3 -0
  106. package/src/notificationTrayRepository/internalApi/getNotificationTraySeen.ts +81 -0
  107. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  108. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  109. package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  110. package/src/notificationTrayRepository/observers/getNotificationTrayItems.ts +44 -0
  111. package/src/notificationTrayRepository/observers/getNotificationTraySeen.ts +43 -0
  112. package/src/notificationTrayRepository/observers/index.ts +2 -0
  113. package/src/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  114. package/src/utils/linkedObject/index.ts +2 -0
  115. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +28 -0
  116. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +0 -16
  117. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +0 -1
  118. package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
  119. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +0 -11
  120. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +0 -1
  121. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +0 -20
  122. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +0 -1
  123. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +0 -2
  124. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +0 -1
  125. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -33
  126. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
  127. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -3
  128. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  129. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +0 -12
  130. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +0 -1
  131. package/src/channelRepository/api/markChannelsAsReadBySegment.ts +0 -29
  132. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +0 -38
  133. package/src/channelRepository/observers/getTotalChannelsUnread.ts +0 -129
  134. package/src/channelRepository/utils/getLegacyChannelUnread.ts +0 -5
  135. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +0 -267
  136. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +0 -21
  137. 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,223 +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 (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
21824
- channelUnread &&
21825
- segment > channelUnread.readToSegment) {
21826
- channelUnread.readToSegment = segment;
21827
- channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
21828
- pushToCache(cacheKey, channelUnread);
21829
- fireEvent('local.channelUnread.updated', channelUnread);
21830
- }
21831
- // Step 2: Enqueue the read receipt
21832
- this.enqueueReadReceipt(channelId, segment);
21833
- }
21834
- enqueueReadReceipt(channelId, segment) {
21835
- var _a;
21836
- const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
21837
- // Create new read receipt if it's not exists and add the job to queue
21838
- if (!readReceipt) {
21839
- const readReceiptChannel = {
21840
- channelId,
21841
- latestSegment: segment,
21842
- latestSyncSegment: 0,
21843
- };
21844
- pushToCache(['readReceipt', channelId], readReceiptChannel);
21845
- }
21846
- else if (readReceipt.latestSegment < segment) {
21847
- // Update latestSegment in read receipt cache
21848
- pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21849
- }
21850
- else if (readReceipt.latestSyncSegment >= segment) {
21851
- // Skip the job when lastSyncSegment > = segment
21852
- return;
21853
- }
21854
- let syncJob = this.getSyncJob(channelId);
21855
- if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21856
- syncJob = {
21857
- channelId,
21858
- segment,
21859
- syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
21860
- retryCount: 0,
21861
- };
21862
- this.enqueueJob(syncJob);
21863
- }
21864
- else if (syncJob.segment < segment) {
21865
- syncJob.segment = segment;
21866
- }
21867
- }
21868
- getSyncJob(channelId) {
21869
- const { jobQueue } = this;
21870
- const targetJob = jobQueue.find(job => job.channelId === channelId);
21871
- return targetJob || null;
21872
- }
21873
- enqueueJob(syncJob) {
21874
- if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
21875
- this.jobQueue.push(syncJob);
21876
- }
21877
- else {
21878
- // Remove oldest job when queue reach maximum capacity
21879
- this.jobQueue.shift();
21880
- this.jobQueue.push(syncJob);
21881
- }
21882
- }
21883
- }
21884
- let instance$4 = null;
21885
- var ReadReceiptSyncEngine = {
21886
- getInstance: () => {
21887
- if (!instance$4)
21888
- instance$4 = new MessageReadReceiptSyncEngine();
21889
- return instance$4;
21890
- },
21891
- };
21892
-
21893
21679
  /**
21894
21680
  *
21895
21681
  * Mark subChannel as read by readToSegment
@@ -21938,7 +21724,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21938
21724
  return channelUnreadInfo;
21939
21725
  };
21940
21726
 
21941
- class LegacyMessageReadReceiptSyncEngine {
21727
+ class MessageReadReceiptSyncEngine {
21942
21728
  constructor() {
21943
21729
  this.isActive = true;
21944
21730
  this.MAX_RETRY = 3;
@@ -21969,7 +21755,7 @@ class LegacyMessageReadReceiptSyncEngine {
21969
21755
  getUnsyncJobs() {
21970
21756
  var _a;
21971
21757
  // Get all read receipts that has latestSyncSegment < latestSegment
21972
- 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 }) => {
21973
21759
  return data.latestSyncSegment < data.latestSegment;
21974
21760
  });
21975
21761
  // Enqueue unsync read receipts to the job queue
@@ -21988,7 +21774,7 @@ class LegacyMessageReadReceiptSyncEngine {
21988
21774
  return;
21989
21775
  // Get readReceipt from cache by subChannelId
21990
21776
  const readReceipt = (_a = pullFromCache([
21991
- 'legacyReadReceipt',
21777
+ 'readReceipt',
21992
21778
  syncJob.subChannelId,
21993
21779
  ])) === null || _a === void 0 ? void 0 : _a.data;
21994
21780
  if (!readReceipt)
@@ -22011,10 +21797,10 @@ class LegacyMessageReadReceiptSyncEngine {
22011
21797
  if (response) {
22012
21798
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
22013
21799
  const readReceiptCache = (_a = pullFromCache([
22014
- 'legacyReadReceipt',
21800
+ 'readReceipt',
22015
21801
  subChannelId,
22016
21802
  ])) === null || _a === void 0 ? void 0 : _a.data;
22017
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
21803
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
22018
21804
  }
22019
21805
  else if (!response) {
22020
21806
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -22081,7 +21867,7 @@ class LegacyMessageReadReceiptSyncEngine {
22081
21867
  subChannelUnreadInfo.readToSegment = segment;
22082
21868
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
22083
21869
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
22084
- fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
21870
+ fireEvent('local.channelUnread.updated', channelUnreadInfo);
22085
21871
  pushToCache(cacheKey, subChannelUnreadInfo);
22086
21872
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
22087
21873
  }
@@ -22090,10 +21876,7 @@ class LegacyMessageReadReceiptSyncEngine {
22090
21876
  }
22091
21877
  enqueueReadReceipt(subChannelId, segment) {
22092
21878
  var _a;
22093
- const readReceipt = (_a = pullFromCache([
22094
- 'legacyReadReceipt',
22095
- subChannelId,
22096
- ])) === null || _a === void 0 ? void 0 : _a.data;
21879
+ const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
22097
21880
  // Create new read receipt if it's not exists and add job to queue
22098
21881
  if (!readReceipt) {
22099
21882
  const readReceiptSubChannel = {
@@ -22101,10 +21884,10 @@ class LegacyMessageReadReceiptSyncEngine {
22101
21884
  latestSegment: segment,
22102
21885
  latestSyncSegment: 0,
22103
21886
  };
22104
- pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
21887
+ pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
22105
21888
  }
22106
21889
  else if (readReceipt.latestSegment < segment) {
22107
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21890
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
22108
21891
  }
22109
21892
  else if (readReceipt.latestSyncSegment >= segment) {
22110
21893
  // Skip the job when lastSyncSegment > = segment
@@ -22147,24 +21930,18 @@ class LegacyMessageReadReceiptSyncEngine {
22147
21930
  }
22148
21931
  }
22149
21932
  let instance$3 = null;
22150
- var LegacyReadReceiptSyncEngine = {
21933
+ var ReadReceiptSyncEngine = {
22151
21934
  getInstance: () => {
22152
21935
  if (!instance$3)
22153
- instance$3 = new LegacyMessageReadReceiptSyncEngine();
21936
+ instance$3 = new MessageReadReceiptSyncEngine();
22154
21937
  return instance$3;
22155
21938
  },
22156
21939
  };
22157
21940
 
22158
21941
  const markReadMessage = (message) => {
22159
- const client = getActiveClient();
22160
- if (client.useLegacyUnreadCount) {
22161
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
22162
- markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
22163
- }
22164
- else {
22165
- const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
22166
- markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
22167
- }
21942
+ const { subChannelId, channelSegment } = message;
21943
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
21944
+ markReadReceiptEngine.markRead(subChannelId, channelSegment);
22168
21945
  };
22169
21946
 
22170
21947
  const messageLinkedObject = (message) => {
@@ -22312,6 +22089,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22312
22089
  } });
22313
22090
  };
22314
22091
 
22092
+ /* begin_public_function
22093
+ id: notificationTrayItem.markSeen
22094
+ */
22095
+ /**
22096
+ * ```js
22097
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
22098
+ * const updated = await NotificationTrayRepository.markNotificationItemsSeen()
22099
+ * ```
22100
+ *
22101
+ * Updates an {@link Amity.NotificationItemSeen}
22102
+ *
22103
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
22104
+ * @returns the updated {@link Amity.NotificationItemSeen} object
22105
+ *
22106
+ * @category NotificationItemSeen API
22107
+ * @async
22108
+ */
22109
+ const markNotificationItemsSeen = async (patch) => {
22110
+ const client = getActiveClient();
22111
+ client.log('notificationTray/markNotificationItemsSeen', {});
22112
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
22113
+ patch,
22114
+ });
22115
+ const updatedData = patch.trayItems
22116
+ .map(patchItem => {
22117
+ var _a;
22118
+ const cacheData = (_a = pullFromCache([
22119
+ 'notificationTraySeen',
22120
+ 'get',
22121
+ patchItem.id,
22122
+ ])) === null || _a === void 0 ? void 0 : _a.data;
22123
+ if (!cacheData)
22124
+ return;
22125
+ const data = Object.assign(Object.assign({}, cacheData), payload);
22126
+ if (client.cache) {
22127
+ const cachedAt = Date.now();
22128
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
22129
+ }
22130
+ return data;
22131
+ })
22132
+ .filter(Boolean);
22133
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
22134
+ };
22135
+ /* end_public_function */
22136
+
22137
+ const notificationTrayLinkedObject = (noti) => {
22138
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccuredAt, isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK, users: noti.actors
22139
+ .map(userId => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; })
22140
+ .filter(isNonNullable)
22141
+ .map(user => userLinkedObject(user)), markRead: () => markNotificationItemsSeen({
22142
+ trayItems: [
22143
+ {
22144
+ id: noti._id,
22145
+ lastSeenAt: noti.lastSeenAt,
22146
+ },
22147
+ ],
22148
+ }) });
22149
+ };
22150
+
22315
22151
  const LinkedObject = {
22316
22152
  ad: adLinkedObject,
22317
22153
  comment: commentLinkedObject,
@@ -22325,6 +22161,7 @@ const LinkedObject = {
22325
22161
  reactor: reactorLinkedObject,
22326
22162
  channel: channelLinkedObject,
22327
22163
  pinnedPost: pinnedPostLinkedObject,
22164
+ notificationTray: notificationTrayLinkedObject,
22328
22165
  };
22329
22166
 
22330
22167
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -23152,31 +22989,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
23152
22989
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
23153
22990
  });
23154
22991
  };
23155
- const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
23156
- for (let i = 0; i < channels.length; i += 1) {
23157
- const cacheKey = ['channelUnread', 'get', channels[i].channelId];
23158
- const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
23159
- let unreadCount = 0;
23160
- let readToSegment = null;
23161
- let lastMentionedSegment = null;
23162
- let isMentioned = false;
23163
- if (channelUser) {
23164
- readToSegment = channelUser.readToSegment;
23165
- lastMentionedSegment = channelUser.lastMentionedSegment;
23166
- unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
23167
- isMentioned = lastMentionedSegment > readToSegment;
23168
- }
23169
- pushToCache(cacheKey, {
23170
- channelId: channels[i].channelId,
23171
- lastSegment: channels[i].messageCount,
23172
- readToSegment,
23173
- lastMentionedSegment,
23174
- unreadCount,
23175
- isMentioned,
23176
- isDeleted: channels[i].isDeleted,
23177
- });
23178
- }
23179
- };
23180
22992
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
23181
22993
  const client = getActiveClient();
23182
22994
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -23186,34 +22998,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
23186
22998
  rawPayload.messagePreviews.length > 0) {
23187
22999
  updateChannelMessagePreviewCache(rawPayload);
23188
23000
  }
23189
- if (client.useLegacyUnreadCount) {
23190
- updateChannelUnread({
23191
- channels: rawPayload.channels,
23192
- channelUsers: rawPayload.channelUsers,
23193
- currentUserId: client.userId,
23194
- });
23195
- }
23196
- else {
23197
- const markerIds = rawPayload.channels
23198
- // filter channel by type. Only conversation, community and broadcast type are included.
23199
- .filter(isUnreadCountSupport)
23200
- .map(({ channelInternalId }) => channelInternalId);
23201
- if (markerIds.length > 0) {
23202
- // since the get markers method requires a channel cache to function with the reducer.
23203
- preUpdateChannelCache(rawPayload, {
23204
- isMessagePreviewUpdated: options.isMessagePreviewUpdated,
23205
- });
23206
- try {
23207
- await getChannelMarkers(markerIds);
23208
- }
23209
- catch (e) {
23210
- // empty block (from the spec, allow marker fetch to fail without having to do anything)
23211
- }
23001
+ const markerIds = rawPayload.channels
23002
+ // filter channel by type. Only conversation, community and broadcast type are included.
23003
+ .filter(isUnreadCountSupport)
23004
+ .map(({ channelInternalId }) => channelInternalId);
23005
+ if (markerIds.length > 0) {
23006
+ // since the get markers method requires a channel cache to function with the reducer.
23007
+ preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
23008
+ try {
23009
+ await getChannelMarkers(markerIds);
23010
+ }
23011
+ catch (e) {
23012
+ // empty block (from the spec, allow marker fetch to fail without having to do anything)
23212
23013
  }
23213
23014
  }
23214
- // convert raw channel to internal channel
23015
+ // attach marker to channel
23215
23016
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
23216
- // convert raw channel user to membership (add user object)
23017
+ // user marker to channel users
23217
23018
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
23218
23019
  return convertRawMembershipToMembership(channelUser);
23219
23020
  });
@@ -23340,28 +23141,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23340
23141
  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;
23341
23142
  };
23342
23143
 
23343
- const getLegacyChannelUnread = (channelId) => {
23344
- var _a;
23345
- return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
23346
- };
23347
-
23348
23144
  const constructChannelDynamicValue = (channel) => {
23349
- const client = getActiveClient();
23350
23145
  const rest = __rest(channel, ["messageCount"]);
23351
23146
  return shallowClone(rest, {
23352
- get unreadCount() {
23353
- var _a, _b;
23354
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
23147
+ get isMentioned() {
23148
+ return getChannelIsMentioned(rest);
23355
23149
  },
23356
23150
  get subChannelsUnreadCount() {
23357
23151
  return getSubChannelsUnreadCount(rest);
23358
23152
  },
23359
- get isMentioned() {
23360
- var _a, _b;
23361
- if (client.useLegacyUnreadCount)
23362
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
23363
- return getChannelIsMentioned(rest);
23364
- },
23365
23153
  });
23366
23154
  };
23367
23155
 
@@ -24018,21 +23806,12 @@ const onChannelDeleted = (callback) => {
24018
23806
  const client = getActiveClient();
24019
23807
  const filter = async (payload) => {
24020
23808
  const data = await prepareChannelPayload(payload);
24021
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24022
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24023
- data.channels.forEach(channel => {
24024
- if (isConsistentMode) {
23809
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23810
+ data.channels.forEach(channel => {
24025
23811
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24026
23812
  deleteChannelUnreadByChannelId(channel.channelId);
24027
- }
24028
- else if (isLegacyUnreadCount) {
24029
- const cacheKey = ['channelUnread', 'get', channel.channelId];
24030
- const cache = pullFromCache(cacheKey);
24031
- if (cache) {
24032
- pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
24033
- }
24034
- }
24035
- });
23813
+ });
23814
+ }
24036
23815
  ingestInCache(data);
24037
23816
  callbacks$b.forEach(cb => cb(data.channels[0]));
24038
23817
  };
@@ -24146,25 +23925,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
24146
23925
  };
24147
23926
  };
24148
23927
 
24149
- var legacyReadReceiptSyncEngineOnLoginHandler = () => {
24150
- const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
24151
- readReceiptSyncEngine.startSyncReadReceipt();
24152
- onSessionStateChange(state => {
24153
- if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
24154
- readReceiptSyncEngine.onSessionEstablished();
24155
- }
24156
- else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
24157
- readReceiptSyncEngine.onTokenExpired();
24158
- }
24159
- else {
24160
- readReceiptSyncEngine.onSessionDestroyed();
24161
- }
24162
- });
24163
- return () => {
24164
- readReceiptSyncEngine.onSessionDestroyed();
24165
- };
24166
- };
24167
-
24168
23928
  const onOnline = (callback) => {
24169
23929
  if (typeof window !== 'undefined' && window.addEventListener) {
24170
23930
  window.addEventListener('online', callback);
@@ -24731,17 +24491,10 @@ const onChannelLeft = (callback) => {
24731
24491
  const preparedPayload = await prepareChannelPayload(payload, {
24732
24492
  isMessagePreviewUpdated: isLeftByMe,
24733
24493
  });
24734
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24735
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24736
- if (isLeftByMe) {
24494
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
24737
24495
  preparedPayload.channels.forEach(channel => {
24738
- if (isConsistentMode) {
24739
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24740
- deleteChannelUnreadByChannelId(channel.channelId);
24741
- }
24742
- else if (isLegacyUnreadCount) {
24743
- dropFromCache(['channelUnread', 'get', channel.channelId]);
24744
- }
24496
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24497
+ deleteChannelUnreadByChannelId(channel.channelId);
24745
24498
  });
24746
24499
  }
24747
24500
  const { channels, channelUsers } = preparedPayload;
@@ -25009,34 +24762,6 @@ const onMessageCreatedMqtt = (callback) => {
25009
24762
  reCalculateChannelUnreadInfo(message.channelId);
25010
24763
  });
25011
24764
  }
25012
- if (client.useLegacyUnreadCount) {
25013
- rawPayload.messages.forEach(message => {
25014
- var _a, _b;
25015
- const channelUnread = (_a = pullFromCache([
25016
- 'channelUnread',
25017
- 'get',
25018
- message.channelId,
25019
- ])) === null || _a === void 0 ? void 0 : _a.data;
25020
- if (!channelUnread ||
25021
- channelUnread.lastSegment >= message.segment ||
25022
- typeof channelUnread.readToSegment !== 'number' ||
25023
- typeof channelUnread.lastMentionSegment !== 'number')
25024
- return;
25025
- const lastSegment = message.segment;
25026
- const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
25027
- return (mention.type === 'channel' ||
25028
- (mention.type === 'user' &&
25029
- client.userId &&
25030
- mention.userPublicIds.includes(client.userId)));
25031
- });
25032
- const lastMentionSegment = isMentionedInMessage
25033
- ? message.segment
25034
- : channelUnread.lastMentionSegment;
25035
- const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionSegment) });
25036
- pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
25037
- fireEvent('local.channelUnread.updated', updatedChannelUnread);
25038
- });
25039
- }
25040
24765
  // Update in cache
25041
24766
  ingestInCache(payload);
25042
24767
  payload.messages.forEach(message => {
@@ -25212,7 +24937,6 @@ const enableUnreadCount = () => {
25212
24937
  if (client.isUnreadCountEnabled)
25213
24938
  return false;
25214
24939
  client.isUnreadCountEnabled = true;
25215
- client.useLegacyUnreadCount = false;
25216
24940
  client.emitter.emit('unreadCountEnabled', true);
25217
24941
  return true;
25218
24942
  };
@@ -25528,12 +25252,7 @@ const login = async (params, sessionHandler, config) => {
25528
25252
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
25529
25253
  // the channel because currently backend can't handle this, so every time a user is banned from
25530
25254
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
25531
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25532
- if (client.useLegacyUnreadCount) {
25533
- subscriptions.push(readReceiptSyncEngineOnLoginHandler());
25534
- }
25535
- else
25536
- subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
25255
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25537
25256
  const markerSyncUnsubscriber = await startMarkerSync();
25538
25257
  subscriptions.push(markerSyncUnsubscriber);
25539
25258
  }
@@ -25714,8 +25433,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25714
25433
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25715
25434
  const sessionHandler = undefined;
25716
25435
  const isUnreadCountEnabled = false;
25717
- // Legacy unread count is true by default
25718
- const useLegacyUnreadCount = true;
25719
25436
  const client = {
25720
25437
  version: `${VERSION}`,
25721
25438
  apiKey,
@@ -25745,7 +25462,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25745
25462
  getMessagePreviewSetting,
25746
25463
  use: () => setActiveClient(client),
25747
25464
  isUnreadCountEnabled,
25748
- useLegacyUnreadCount,
25749
25465
  getMarkerSyncConsistentMode,
25750
25466
  /**
25751
25467
  * Prefix for the deviceId key in the local storage or async storage.
@@ -26216,7 +25932,7 @@ const getUserUnread = (callback) => {
26216
25932
  };
26217
25933
  };
26218
25934
 
26219
- var index$l = /*#__PURE__*/Object.freeze({
25935
+ var index$m = /*#__PURE__*/Object.freeze({
26220
25936
  __proto__: null,
26221
25937
  getActiveClient: getActiveClient,
26222
25938
  getActiveUser: getActiveUser,
@@ -27423,7 +27139,7 @@ const getMyFollowInfo = (callback) => {
27423
27139
  };
27424
27140
  /* end_public_function */
27425
27141
 
27426
- var index$k = /*#__PURE__*/Object.freeze({
27142
+ var index$l = /*#__PURE__*/Object.freeze({
27427
27143
  __proto__: null,
27428
27144
  blockUser: blockUser,
27429
27145
  unBlockUser: unBlockUser,
@@ -28438,9 +28154,9 @@ var AmityUserSearchMatchType;
28438
28154
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28439
28155
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28440
28156
 
28441
- var index$j = /*#__PURE__*/Object.freeze({
28157
+ var index$k = /*#__PURE__*/Object.freeze({
28442
28158
  __proto__: null,
28443
- Relationship: index$k,
28159
+ Relationship: index$l,
28444
28160
  getUserByIds: getUserByIds,
28445
28161
  updateUser: updateUser,
28446
28162
  flagUser: flagUser,
@@ -28704,7 +28420,7 @@ const uploadImage = async (formData, onProgress) => {
28704
28420
  };
28705
28421
  /* end_public_function */
28706
28422
 
28707
- var index$i = /*#__PURE__*/Object.freeze({
28423
+ var index$j = /*#__PURE__*/Object.freeze({
28708
28424
  __proto__: null,
28709
28425
  getFile: getFile,
28710
28426
  uploadFile: uploadFile,
@@ -30516,7 +30232,7 @@ const getReactions = (params, callback, config) => {
30516
30232
  };
30517
30233
  /* end_public_function */
30518
30234
 
30519
- var index$h = /*#__PURE__*/Object.freeze({
30235
+ var index$i = /*#__PURE__*/Object.freeze({
30520
30236
  __proto__: null,
30521
30237
  addReaction: addReaction,
30522
30238
  removeReaction: removeReaction,
@@ -32332,7 +32048,7 @@ const getMessages = (params, callback, config) => {
32332
32048
  };
32333
32049
  /* end_public_function */
32334
32050
 
32335
- var index$g = /*#__PURE__*/Object.freeze({
32051
+ var index$h = /*#__PURE__*/Object.freeze({
32336
32052
  __proto__: null,
32337
32053
  createMessage: createMessage,
32338
32054
  updateMessage: updateMessage,
@@ -32858,7 +32574,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32858
32574
  };
32859
32575
  /* end_public_function */
32860
32576
 
32861
- var index$f = /*#__PURE__*/Object.freeze({
32577
+ var index$g = /*#__PURE__*/Object.freeze({
32862
32578
  __proto__: null,
32863
32579
  getSubChannelByIds: getSubChannels$1,
32864
32580
  createSubChannel: createSubChannel,
@@ -32879,37 +32595,19 @@ var index$f = /*#__PURE__*/Object.freeze({
32879
32595
  /**
32880
32596
  * Internal used only
32881
32597
  *
32882
- * Fired when an {@link Amity.channelUnreadInfo} has been updated.
32883
- *
32884
- * @param callback The function to call when the event was fired
32885
- * @returns an {@link Amity.Unsubscriber} function to stop listening
32886
- *
32887
- * @category ChannelMarker Events
32888
- */
32889
- const onChannelUnreadInfoUpdatedLocal = (callback) => {
32890
- const client = getActiveClient();
32891
- const filter = (payload) => {
32892
- callback(payload);
32893
- };
32894
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
32895
- };
32896
-
32897
- /**
32898
- * Internal used only
32899
- *
32900
- * Fired when an {@link Amity.ChannelUnread} has been updated.
32598
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32901
32599
  *
32902
32600
  * @param callback The function to call when the event was fired
32903
32601
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32904
32602
  *
32905
- * @category Channel Events
32603
+ * @category MessageMarker Events
32906
32604
  */
32907
32605
  const onChannelUnreadUpdatedLocal = (callback) => {
32908
32606
  const client = getActiveClient();
32909
32607
  const filter = (payload) => {
32910
32608
  callback(payload);
32911
32609
  };
32912
- return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32610
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32913
32611
  };
32914
32612
 
32915
32613
  /* begin_public_function
@@ -33111,7 +32809,6 @@ const getChannel = (channelId, callback) => {
33111
32809
  return onSubChannelUpdated(updateMessagePreview);
33112
32810
  }, 'channelId', 'channel'),
33113
32811
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
33114
- convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33115
32812
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33116
32813
  ], {
33117
32814
  forceDispatch: true,
@@ -33625,10 +33322,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33625
33322
  },
33626
33323
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
33627
33324
  },
33628
- {
33629
- fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33630
- action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33631
- },
33632
33325
  {
33633
33326
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33634
33327
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -33694,120 +33387,6 @@ const getChannels = (params, callback, config) => {
33694
33387
  };
33695
33388
  /* end_public_function */
33696
33389
 
33697
- /**
33698
- *
33699
- * Calculate user unread from {@link Amity.ChannelUnread} objects
33700
- *
33701
- * @returns the {@link Amity.UserUnread} objects
33702
- *
33703
- * @category Channel API
33704
- * @async
33705
- */
33706
- const getTotalChannelsUnread$1 = () => {
33707
- var _a;
33708
- const client = getActiveClient();
33709
- client.log('channel/getTotalChannelsUnread.locally');
33710
- const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
33711
- return !data.isDeleted;
33712
- })) || [];
33713
- const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
33714
- acc.unreadCount += data.unreadCount;
33715
- acc.isMentioned = acc.isMentioned || data.isMentioned;
33716
- return acc;
33717
- }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
33718
- const cachedAt = client.cache && Date.now();
33719
- return {
33720
- data: totalChannelsUnread,
33721
- cachedAt,
33722
- };
33723
- };
33724
-
33725
- /* begin_public_function
33726
- id: totalChannelsUnread.get
33727
- */
33728
- /**
33729
- * ```js
33730
- * import { ChannelRepository } from '@amityco/ts-sdk';
33731
- *
33732
- * let totalChannelsUnread;
33733
- *
33734
- * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
33735
- * unread = response.data;
33736
- * });
33737
- * ```
33738
- *
33739
- * Observe all mutation on a given {@link Amity.UserUnread}
33740
- *
33741
- * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
33742
- *
33743
- * @category User Unread Live Object
33744
- *
33745
- */
33746
- const getTotalChannelsUnread = (callback) => {
33747
- const { _id: userId } = getActiveUser();
33748
- if (!userId)
33749
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
33750
- const { log, cache } = getActiveClient();
33751
- if (!cache) {
33752
- console.log('For using Live Object feature you need to enable Cache!');
33753
- }
33754
- const timestamp = Date.now();
33755
- log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
33756
- const disposers = [];
33757
- let isUnsyncedModel = false; // for messages
33758
- let model;
33759
- const dispatcher = (data) => {
33760
- const { data: userUnread } = data;
33761
- const callbackModel = userUnread
33762
- ? {
33763
- unreadCount: userUnread.unreadCount,
33764
- isMentioned: userUnread.isMentioned,
33765
- }
33766
- : undefined;
33767
- model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
33768
- callback({
33769
- data: callbackModel
33770
- ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
33771
- loading: data.loading,
33772
- error: data.error,
33773
- });
33774
- };
33775
- const realtimeRouter = (userUnread) => {
33776
- if (isEqual(model, userUnread))
33777
- return;
33778
- dispatcher({
33779
- loading: false,
33780
- data: userUnread,
33781
- });
33782
- };
33783
- const onFetch = () => {
33784
- const query = createQuery(async () => getTotalChannelsUnread$1());
33785
- runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
33786
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
33787
- dispatcher({
33788
- data,
33789
- origin,
33790
- loading: false,
33791
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
33792
- });
33793
- isUnsyncedModel = true;
33794
- disposers.forEach(fn => fn());
33795
- }
33796
- else if (!isUnsyncedModel) {
33797
- dispatcher({ loading, data, origin, error });
33798
- }
33799
- if (error) {
33800
- disposers.forEach(fn => fn());
33801
- }
33802
- });
33803
- };
33804
- disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
33805
- onFetch();
33806
- return () => {
33807
- disposers.forEach(fn => fn());
33808
- };
33809
- };
33810
-
33811
33390
  /* begin_public_function
33812
33391
  id: channel.member.add
33813
33392
  */
@@ -34172,7 +33751,7 @@ const searchMembers$1 = (params, callback, config) => {
34172
33751
  };
34173
33752
  /* end_public_function */
34174
33753
 
34175
- var index$e = /*#__PURE__*/Object.freeze({
33754
+ var index$f = /*#__PURE__*/Object.freeze({
34176
33755
  __proto__: null,
34177
33756
  addMembers: addMembers$1,
34178
33757
  removeMembers: removeMembers$1,
@@ -34375,7 +33954,7 @@ const unmuteMembers = async (channelId, userIds) => {
34375
33954
  };
34376
33955
  /* end_public_function */
34377
33956
 
34378
- var index$d = /*#__PURE__*/Object.freeze({
33957
+ var index$e = /*#__PURE__*/Object.freeze({
34379
33958
  __proto__: null,
34380
33959
  addRole: addRole,
34381
33960
  removeRole: removeRole,
@@ -34385,10 +33964,10 @@ var index$d = /*#__PURE__*/Object.freeze({
34385
33964
  unmuteMembers: unmuteMembers
34386
33965
  });
34387
33966
 
34388
- var index$c = /*#__PURE__*/Object.freeze({
33967
+ var index$d = /*#__PURE__*/Object.freeze({
34389
33968
  __proto__: null,
34390
- Membership: index$e,
34391
- Moderation: index$d,
33969
+ Membership: index$f,
33970
+ Moderation: index$e,
34392
33971
  getChannelByIds: getChannelByIds$1,
34393
33972
  createChannel: createChannel,
34394
33973
  updateChannel: updateChannel,
@@ -34411,7 +33990,6 @@ var index$c = /*#__PURE__*/Object.freeze({
34411
33990
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
34412
33991
  getChannel: getChannel,
34413
33992
  getChannels: getChannels,
34414
- getTotalChannelsUnread: getTotalChannelsUnread,
34415
33993
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
34416
33994
  isUnreadCountSupport: isUnreadCountSupport,
34417
33995
  convertFromRaw: convertFromRaw,
@@ -35768,7 +35346,7 @@ const searchMembers = (params, callback, config) => {
35768
35346
  };
35769
35347
  /* end_public_function */
35770
35348
 
35771
- var index$b = /*#__PURE__*/Object.freeze({
35349
+ var index$c = /*#__PURE__*/Object.freeze({
35772
35350
  __proto__: null,
35773
35351
  addMembers: addMembers,
35774
35352
  removeMembers: removeMembers,
@@ -36793,7 +36371,7 @@ const unbanMembers = async (communityId, userIds) => {
36793
36371
  };
36794
36372
  /* end_public_function */
36795
36373
 
36796
- var index$a = /*#__PURE__*/Object.freeze({
36374
+ var index$b = /*#__PURE__*/Object.freeze({
36797
36375
  __proto__: null,
36798
36376
  addRoles: addRoles,
36799
36377
  removeRoles: removeRoles,
@@ -36801,10 +36379,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36801
36379
  unbanMembers: unbanMembers
36802
36380
  });
36803
36381
 
36804
- var index$9 = /*#__PURE__*/Object.freeze({
36382
+ var index$a = /*#__PURE__*/Object.freeze({
36805
36383
  __proto__: null,
36806
- Moderation: index$a,
36807
- Membership: index$b,
36384
+ Moderation: index$b,
36385
+ Membership: index$c,
36808
36386
  getCommunityByIds: getCommunities$1,
36809
36387
  createCommunity: createCommunity,
36810
36388
  updateCommunity: updateCommunity,
@@ -37037,7 +36615,7 @@ const getCategories = (params, callback, config) => {
37037
36615
  };
37038
36616
  /* end_public_function */
37039
36617
 
37040
- var index$8 = /*#__PURE__*/Object.freeze({
36618
+ var index$9 = /*#__PURE__*/Object.freeze({
37041
36619
  __proto__: null,
37042
36620
  getCategory: getCategory,
37043
36621
  getCategories: getCategories
@@ -37205,7 +36783,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
37205
36783
  : undefined;
37206
36784
  };
37207
36785
 
37208
- var index$7 = /*#__PURE__*/Object.freeze({
36786
+ var index$8 = /*#__PURE__*/Object.freeze({
37209
36787
  __proto__: null,
37210
36788
  queryGlobalFeed: queryGlobalFeed,
37211
36789
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38520,7 +38098,7 @@ const getComments = (params, callback, config) => {
38520
38098
  };
38521
38099
  /* end_public_function */
38522
38100
 
38523
- var index$6 = /*#__PURE__*/Object.freeze({
38101
+ var index$7 = /*#__PURE__*/Object.freeze({
38524
38102
  __proto__: null,
38525
38103
  getCommentByIds: getCommentByIds,
38526
38104
  createComment: createComment,
@@ -39527,7 +39105,7 @@ const semanticSearchPosts = (params, callback, config) => {
39527
39105
  };
39528
39106
  };
39529
39107
 
39530
- var index$5 = /*#__PURE__*/Object.freeze({
39108
+ var index$6 = /*#__PURE__*/Object.freeze({
39531
39109
  __proto__: null,
39532
39110
  getPostByIds: getPostByIds,
39533
39111
  createPost: createPost,
@@ -40061,7 +39639,7 @@ const getStreams = (params, callback, config) => {
40061
39639
  };
40062
39640
  };
40063
39641
 
40064
- var index$4 = /*#__PURE__*/Object.freeze({
39642
+ var index$5 = /*#__PURE__*/Object.freeze({
40065
39643
  __proto__: null,
40066
39644
  createStream: createStream,
40067
39645
  updateStream: updateStream,
@@ -40348,7 +39926,7 @@ const getPoll = (pollId, callback) => {
40348
39926
  };
40349
39927
  /* end_public_function */
40350
39928
 
40351
- var index$3 = /*#__PURE__*/Object.freeze({
39929
+ var index$4 = /*#__PURE__*/Object.freeze({
40352
39930
  __proto__: null,
40353
39931
  createPoll: createPoll,
40354
39932
  closePoll: closePoll,
@@ -40719,7 +40297,7 @@ const getPlayer = async (parameters) => {
40719
40297
  return video;
40720
40298
  };
40721
40299
 
40722
- var index$2 = /*#__PURE__*/Object.freeze({
40300
+ var index$3 = /*#__PURE__*/Object.freeze({
40723
40301
  __proto__: null,
40724
40302
  getPlayer: getPlayer
40725
40303
  });
@@ -41892,7 +41470,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41892
41470
  };
41893
41471
  };
41894
41472
 
41895
- var index$1 = /*#__PURE__*/Object.freeze({
41473
+ var index$2 = /*#__PURE__*/Object.freeze({
41896
41474
  __proto__: null,
41897
41475
  createImageStory: createImageStory,
41898
41476
  createVideoStory: createVideoStory,
@@ -41929,7 +41507,7 @@ const getNetworkAds = async () => {
41929
41507
  };
41930
41508
  };
41931
41509
 
41932
- var index = /*#__PURE__*/Object.freeze({
41510
+ var index$1 = /*#__PURE__*/Object.freeze({
41933
41511
  __proto__: null,
41934
41512
  getNetworkAds: getNetworkAds
41935
41513
  });
@@ -41956,4 +41534,314 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41956
41534
  return { accessToken: data.accessToken };
41957
41535
  };
41958
41536
 
41959
- 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 };
41537
+ /* begin_public_function
41538
+ id: notificationTray.getNotificationTraySeen
41539
+ */
41540
+ /**
41541
+ * ```js
41542
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
41543
+ * const notificationTraySeen = await NotificationTrayRepository.getNotificationTraySeen()
41544
+ * ```
41545
+ *
41546
+ *
41547
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41548
+ *
41549
+ * @category NotificationTray API
41550
+ * @async
41551
+ * */
41552
+ const getNotificationTraySeen$1 = async () => {
41553
+ const client = getActiveClient();
41554
+ client.log('notificationTray/getNotificationTraySeen', {});
41555
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
41556
+ const cachedAt = client.cache && Date.now();
41557
+ if (client.cache) {
41558
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
41559
+ pushToCache(cacheKey, {
41560
+ userId: client.userId,
41561
+ lastTraySeenAt: payload.lastTraySeenAt,
41562
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41563
+ });
41564
+ }
41565
+ return {
41566
+ data: {
41567
+ userId: client.userId,
41568
+ lastTraySeenAt: payload.lastTraySeenAt,
41569
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41570
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
41571
+ },
41572
+ cachedAt,
41573
+ };
41574
+ };
41575
+ /* end_public_function */
41576
+ /**
41577
+ * ```js
41578
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
41579
+ * const notificationTraySeen = await NotificationTrayRepository.getNotificationTraySeen.locally()
41580
+ * ```
41581
+ *
41582
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
41583
+ *
41584
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41585
+ *
41586
+ * @category NotificationTray API
41587
+ * @async
41588
+ * */
41589
+ getNotificationTraySeen$1.locally = () => {
41590
+ var _a;
41591
+ const client = getActiveClient();
41592
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
41593
+ if (!client.cache)
41594
+ return;
41595
+ const queryKey = ['notificationTraySeen', 'get'];
41596
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
41597
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
41598
+ return;
41599
+ return { data: data.notificationTraySeen, cachedAt };
41600
+ };
41601
+
41602
+ /**
41603
+ * ```js
41604
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
41605
+ * const dispose = onNotificationTraySeenUpdated(data => {
41606
+ * // ...
41607
+ * })
41608
+ * ```
41609
+ *
41610
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
41611
+ *
41612
+ * @param callback The function to call when the event was fired
41613
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
41614
+ *
41615
+ * @category NotificationTraySeen Events
41616
+ */
41617
+ const onNotificationTraySeenUpdated = (callback) => {
41618
+ const client = getActiveClient();
41619
+ const disposers = [
41620
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
41621
+ ];
41622
+ return () => {
41623
+ disposers.forEach(fn => fn());
41624
+ };
41625
+ };
41626
+
41627
+ /* begin_public_function
41628
+ id: notificationTraySeen.get
41629
+ */
41630
+ /**
41631
+ * ```js
41632
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
41633
+ *
41634
+ * let notificationTraySeen;
41635
+ *
41636
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
41637
+ * notificationTraySeen = response.data;
41638
+ * });
41639
+ * ```
41640
+ *
41641
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
41642
+ *
41643
+ * @param userId the ID of the user to observe
41644
+ * @param callback the function to call when new data are available
41645
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
41646
+ *
41647
+ * @category NotificationTraySeen Live Object
41648
+ */
41649
+ const getNotificationTraySeen = (callback) => {
41650
+ const responder = (snapshot) => {
41651
+ const { data } = snapshot;
41652
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
41653
+ };
41654
+ const { userId } = getActiveUser();
41655
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
41656
+ onNotificationTraySeenUpdated,
41657
+ ]);
41658
+ };
41659
+ /* end_public_function */
41660
+
41661
+ /**
41662
+ * TODO: handle cache receive cache option, and cache policy
41663
+ * TODO: check if querybyIds is supported
41664
+ */
41665
+ class NotificationTrayItemsPaginationController extends PaginationController {
41666
+ async getRequest(queryParams, token) {
41667
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
41668
+ const options = token ? { token } : { limit };
41669
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
41670
+ params: Object.assign(Object.assign({}, params), { options }),
41671
+ });
41672
+ return queryResponse;
41673
+ }
41674
+ }
41675
+
41676
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
41677
+ constructor(query, cacheKey, notifyChange, preparePayload) {
41678
+ super(query, cacheKey);
41679
+ this.notifyChange = notifyChange;
41680
+ this.preparePayload = preparePayload;
41681
+ }
41682
+ async saveToMainDB(response) {
41683
+ const processedPayload = await this.preparePayload(response);
41684
+ const client = getActiveClient();
41685
+ const cachedAt = client.cache && Date.now();
41686
+ if (client.cache) {
41687
+ ingestInCache(processedPayload, { cachedAt });
41688
+ }
41689
+ }
41690
+ appendToQueryStream(response, direction, refresh = false) {
41691
+ var _a, _b;
41692
+ if (refresh) {
41693
+ pushToCache(this.cacheKey, {
41694
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41695
+ });
41696
+ }
41697
+ else {
41698
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41699
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
41700
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
41701
+ ...new Set([
41702
+ ...notifications,
41703
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41704
+ ]),
41705
+ ] }));
41706
+ }
41707
+ }
41708
+ }
41709
+
41710
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
41711
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
41712
+ return Object.assign(Object.assign({}, rawPayload), { users });
41713
+ };
41714
+
41715
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
41716
+ constructor(query, callback) {
41717
+ const queryStreamId = hash(query);
41718
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
41719
+ const paginationController = new NotificationTrayItemsPaginationController(query);
41720
+ super(paginationController, queryStreamId, cacheKey, callback);
41721
+ this.query = query;
41722
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
41723
+ this.callback = callback.bind(this);
41724
+ this.loadPage({ initial: true });
41725
+ }
41726
+ setup() {
41727
+ var _a;
41728
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41729
+ if (!collection) {
41730
+ pushToCache(this.cacheKey, {
41731
+ data: [],
41732
+ params: {},
41733
+ });
41734
+ }
41735
+ }
41736
+ async persistModel(queryPayload) {
41737
+ await this.queryStreamController.saveToMainDB(queryPayload);
41738
+ }
41739
+ persistQueryStream({ response, direction, refresh, }) {
41740
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
41741
+ }
41742
+ // eslint-disable-next-line class-methods-use-this
41743
+ startSubscription() {
41744
+ return [];
41745
+ }
41746
+ notifyChange({ origin, loading, error }) {
41747
+ var _a, _b;
41748
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41749
+ if (!collection)
41750
+ return;
41751
+ const data = ((_b = collection.data
41752
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
41753
+ .filter(isNonNullable)
41754
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
41755
+ if (!this.shouldNotify(data) && origin === 'event')
41756
+ return;
41757
+ this.callback({
41758
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
41759
+ data,
41760
+ hasNextPage: !!this.paginationController.getNextToken(),
41761
+ loading,
41762
+ error,
41763
+ });
41764
+ }
41765
+ }
41766
+
41767
+ /**
41768
+ * Get notification tray items for a notification tray page
41769
+ *
41770
+ * @param params the limit query parameters
41771
+ * @param callback the callback to be called when the notification tray items are updated
41772
+ * @returns items in the notification tray
41773
+ *
41774
+ * @category Notification tray items Live Collection
41775
+ *
41776
+ */
41777
+ const getNotificationTrayItems = (params, callback, config) => {
41778
+ const { log, cache } = getActiveClient();
41779
+ if (!cache) {
41780
+ console.log(ENABLE_CACHE_MESSAGE);
41781
+ }
41782
+ const timestamp = Date.now();
41783
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
41784
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
41785
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
41786
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
41787
+ disposers.push(() => dropFromCache(cacheKey));
41788
+ return () => {
41789
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
41790
+ disposers.forEach(fn => fn());
41791
+ };
41792
+ };
41793
+
41794
+ /* begin_public_function
41795
+ id: notificationTray.markSeen
41796
+ */
41797
+ /**
41798
+ * ```js
41799
+ * import { NotificationTrayRepository } from '@amityco/ts-sdk'
41800
+ * const updated = await NotificationTrayRepository.markNotificationTraySeen({
41801
+ * lastSeenAt: Amity.timestamp,
41802
+ * })
41803
+ * ```
41804
+ *
41805
+ * Updates an {@link Amity.NotificationTraySeen}
41806
+ *
41807
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
41808
+ * @param lastSeenAt The patch data to apply
41809
+ * @returns the updated {@link Amity.NotificationTraySeen} object
41810
+ *
41811
+ * @category Post API
41812
+ * @async
41813
+ */
41814
+ const markNotificationTraySeen = async (lastSeenAt) => {
41815
+ var _a;
41816
+ const client = getActiveClient();
41817
+ client.log('notificationTray/markNotificationTraySeen', {});
41818
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
41819
+ lastSeenAt,
41820
+ });
41821
+ const cacheData = (_a = pullFromCache([
41822
+ 'notificationTraySeen',
41823
+ 'get',
41824
+ ])) === null || _a === void 0 ? void 0 : _a.data;
41825
+ const data = Object.assign({ userId: client.userId }, payload);
41826
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
41827
+ const cachedAt = client.cache && Date.now();
41828
+ if (client.cache)
41829
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
41830
+ fireEvent('local.notificationTraySeen.updated', data);
41831
+ return {
41832
+ data: payload,
41833
+ cachedAt,
41834
+ };
41835
+ };
41836
+ /* end_public_function */
41837
+
41838
+ var index = /*#__PURE__*/Object.freeze({
41839
+ __proto__: null,
41840
+ getNotificationTraySeen: getNotificationTraySeen,
41841
+ getNotificationTrayItems: getNotificationTrayItems,
41842
+ markNotificationItemsSeen: markNotificationItemsSeen,
41843
+ markNotificationTraySeen: markNotificationTraySeen,
41844
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
41845
+ });
41846
+
41847
+ 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 as NotificationTrayRepository, 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, 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 };