@amityco/ts-sdk 7.1.1-dbdbe662.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 -579
  35. package/dist/index.d.ts +1 -0
  36. package/dist/index.d.ts.map +1 -1
  37. package/dist/index.esm.js +445 -563
  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 -66
  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 -74
  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 -45
  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,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,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22312
22089
  } });
22313
22090
  };
22314
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
+
22315
22100
  const LinkedObject = {
22316
22101
  ad: adLinkedObject,
22317
22102
  comment: commentLinkedObject,
@@ -22325,6 +22110,7 @@ const LinkedObject = {
22325
22110
  reactor: reactorLinkedObject,
22326
22111
  channel: channelLinkedObject,
22327
22112
  pinnedPost: pinnedPostLinkedObject,
22113
+ notificationTray: notificationTrayLinkedObject,
22328
22114
  };
22329
22115
 
22330
22116
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -23152,31 +22938,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
23152
22938
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
23153
22939
  });
23154
22940
  };
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
22941
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
23181
22942
  const client = getActiveClient();
23182
22943
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -23186,34 +22947,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
23186
22947
  rawPayload.messagePreviews.length > 0) {
23187
22948
  updateChannelMessagePreviewCache(rawPayload);
23188
22949
  }
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
- }
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)
23212
22962
  }
23213
22963
  }
23214
- // convert raw channel to internal channel
22964
+ // attach marker to channel
23215
22965
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
23216
- // convert raw channel user to membership (add user object)
22966
+ // user marker to channel users
23217
22967
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
23218
22968
  return convertRawMembershipToMembership(channelUser);
23219
22969
  });
@@ -23340,28 +23090,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23340
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;
23341
23091
  };
23342
23092
 
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
23093
  const constructChannelDynamicValue = (channel) => {
23349
- const client = getActiveClient();
23350
23094
  const rest = __rest(channel, ["messageCount"]);
23351
23095
  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;
23096
+ get isMentioned() {
23097
+ return getChannelIsMentioned(rest);
23355
23098
  },
23356
23099
  get subChannelsUnreadCount() {
23357
23100
  return getSubChannelsUnreadCount(rest);
23358
23101
  },
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
23102
  });
23366
23103
  };
23367
23104
 
@@ -24018,21 +23755,12 @@ const onChannelDeleted = (callback) => {
24018
23755
  const client = getActiveClient();
24019
23756
  const filter = async (payload) => {
24020
23757
  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) {
23758
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23759
+ data.channels.forEach(channel => {
24025
23760
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24026
23761
  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
- });
23762
+ });
23763
+ }
24036
23764
  ingestInCache(data);
24037
23765
  callbacks$b.forEach(cb => cb(data.channels[0]));
24038
23766
  };
@@ -24146,25 +23874,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
24146
23874
  };
24147
23875
  };
24148
23876
 
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
23877
  const onOnline = (callback) => {
24169
23878
  if (typeof window !== 'undefined' && window.addEventListener) {
24170
23879
  window.addEventListener('online', callback);
@@ -24731,17 +24440,10 @@ const onChannelLeft = (callback) => {
24731
24440
  const preparedPayload = await prepareChannelPayload(payload, {
24732
24441
  isMessagePreviewUpdated: isLeftByMe,
24733
24442
  });
24734
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24735
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24736
- if (isLeftByMe) {
24443
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
24737
24444
  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
- }
24445
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24446
+ deleteChannelUnreadByChannelId(channel.channelId);
24745
24447
  });
24746
24448
  }
24747
24449
  const { channels, channelUsers } = preparedPayload;
@@ -25009,34 +24711,6 @@ const onMessageCreatedMqtt = (callback) => {
25009
24711
  reCalculateChannelUnreadInfo(message.channelId);
25010
24712
  });
25011
24713
  }
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
24714
  // Update in cache
25041
24715
  ingestInCache(payload);
25042
24716
  payload.messages.forEach(message => {
@@ -25212,7 +24886,6 @@ const enableUnreadCount = () => {
25212
24886
  if (client.isUnreadCountEnabled)
25213
24887
  return false;
25214
24888
  client.isUnreadCountEnabled = true;
25215
- client.useLegacyUnreadCount = false;
25216
24889
  client.emitter.emit('unreadCountEnabled', true);
25217
24890
  return true;
25218
24891
  };
@@ -25528,12 +25201,7 @@ const login = async (params, sessionHandler, config) => {
25528
25201
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
25529
25202
  // the channel because currently backend can't handle this, so every time a user is banned from
25530
25203
  // 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());
25204
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25537
25205
  const markerSyncUnsubscriber = await startMarkerSync();
25538
25206
  subscriptions.push(markerSyncUnsubscriber);
25539
25207
  }
@@ -25714,8 +25382,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25714
25382
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25715
25383
  const sessionHandler = undefined;
25716
25384
  const isUnreadCountEnabled = false;
25717
- // Legacy unread count is true by default
25718
- const useLegacyUnreadCount = true;
25719
25385
  const client = {
25720
25386
  version: `${VERSION}`,
25721
25387
  apiKey,
@@ -25745,7 +25411,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25745
25411
  getMessagePreviewSetting,
25746
25412
  use: () => setActiveClient(client),
25747
25413
  isUnreadCountEnabled,
25748
- useLegacyUnreadCount,
25749
25414
  getMarkerSyncConsistentMode,
25750
25415
  /**
25751
25416
  * Prefix for the deviceId key in the local storage or async storage.
@@ -26216,7 +25881,7 @@ const getUserUnread = (callback) => {
26216
25881
  };
26217
25882
  };
26218
25883
 
26219
- var index$l = /*#__PURE__*/Object.freeze({
25884
+ var index$m = /*#__PURE__*/Object.freeze({
26220
25885
  __proto__: null,
26221
25886
  getActiveClient: getActiveClient,
26222
25887
  getActiveUser: getActiveUser,
@@ -27423,7 +27088,7 @@ const getMyFollowInfo = (callback) => {
27423
27088
  };
27424
27089
  /* end_public_function */
27425
27090
 
27426
- var index$k = /*#__PURE__*/Object.freeze({
27091
+ var index$l = /*#__PURE__*/Object.freeze({
27427
27092
  __proto__: null,
27428
27093
  blockUser: blockUser,
27429
27094
  unBlockUser: unBlockUser,
@@ -28438,9 +28103,9 @@ var AmityUserSearchMatchType;
28438
28103
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28439
28104
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28440
28105
 
28441
- var index$j = /*#__PURE__*/Object.freeze({
28106
+ var index$k = /*#__PURE__*/Object.freeze({
28442
28107
  __proto__: null,
28443
- Relationship: index$k,
28108
+ Relationship: index$l,
28444
28109
  getUserByIds: getUserByIds,
28445
28110
  updateUser: updateUser,
28446
28111
  flagUser: flagUser,
@@ -28704,7 +28369,7 @@ const uploadImage = async (formData, onProgress) => {
28704
28369
  };
28705
28370
  /* end_public_function */
28706
28371
 
28707
- var index$i = /*#__PURE__*/Object.freeze({
28372
+ var index$j = /*#__PURE__*/Object.freeze({
28708
28373
  __proto__: null,
28709
28374
  getFile: getFile,
28710
28375
  uploadFile: uploadFile,
@@ -30516,7 +30181,7 @@ const getReactions = (params, callback, config) => {
30516
30181
  };
30517
30182
  /* end_public_function */
30518
30183
 
30519
- var index$h = /*#__PURE__*/Object.freeze({
30184
+ var index$i = /*#__PURE__*/Object.freeze({
30520
30185
  __proto__: null,
30521
30186
  addReaction: addReaction,
30522
30187
  removeReaction: removeReaction,
@@ -32332,7 +31997,7 @@ const getMessages = (params, callback, config) => {
32332
31997
  };
32333
31998
  /* end_public_function */
32334
31999
 
32335
- var index$g = /*#__PURE__*/Object.freeze({
32000
+ var index$h = /*#__PURE__*/Object.freeze({
32336
32001
  __proto__: null,
32337
32002
  createMessage: createMessage,
32338
32003
  updateMessage: updateMessage,
@@ -32858,7 +32523,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32858
32523
  };
32859
32524
  /* end_public_function */
32860
32525
 
32861
- var index$f = /*#__PURE__*/Object.freeze({
32526
+ var index$g = /*#__PURE__*/Object.freeze({
32862
32527
  __proto__: null,
32863
32528
  getSubChannelByIds: getSubChannels$1,
32864
32529
  createSubChannel: createSubChannel,
@@ -32879,37 +32544,19 @@ var index$f = /*#__PURE__*/Object.freeze({
32879
32544
  /**
32880
32545
  * Internal used only
32881
32546
  *
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.
32547
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32901
32548
  *
32902
32549
  * @param callback The function to call when the event was fired
32903
32550
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32904
32551
  *
32905
- * @category Channel Events
32552
+ * @category MessageMarker Events
32906
32553
  */
32907
32554
  const onChannelUnreadUpdatedLocal = (callback) => {
32908
32555
  const client = getActiveClient();
32909
32556
  const filter = (payload) => {
32910
32557
  callback(payload);
32911
32558
  };
32912
- return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32559
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32913
32560
  };
32914
32561
 
32915
32562
  /* begin_public_function
@@ -33111,7 +32758,6 @@ const getChannel = (channelId, callback) => {
33111
32758
  return onSubChannelUpdated(updateMessagePreview);
33112
32759
  }, 'channelId', 'channel'),
33113
32760
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
33114
- convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33115
32761
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33116
32762
  ], {
33117
32763
  forceDispatch: true,
@@ -33625,10 +33271,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33625
33271
  },
33626
33272
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
33627
33273
  },
33628
- {
33629
- fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33630
- action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33631
- },
33632
33274
  {
33633
33275
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33634
33276
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -33694,120 +33336,6 @@ const getChannels = (params, callback, config) => {
33694
33336
  };
33695
33337
  /* end_public_function */
33696
33338
 
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
33339
  /* begin_public_function
33812
33340
  id: channel.member.add
33813
33341
  */
@@ -34172,7 +33700,7 @@ const searchMembers$1 = (params, callback, config) => {
34172
33700
  };
34173
33701
  /* end_public_function */
34174
33702
 
34175
- var index$e = /*#__PURE__*/Object.freeze({
33703
+ var index$f = /*#__PURE__*/Object.freeze({
34176
33704
  __proto__: null,
34177
33705
  addMembers: addMembers$1,
34178
33706
  removeMembers: removeMembers$1,
@@ -34375,7 +33903,7 @@ const unmuteMembers = async (channelId, userIds) => {
34375
33903
  };
34376
33904
  /* end_public_function */
34377
33905
 
34378
- var index$d = /*#__PURE__*/Object.freeze({
33906
+ var index$e = /*#__PURE__*/Object.freeze({
34379
33907
  __proto__: null,
34380
33908
  addRole: addRole,
34381
33909
  removeRole: removeRole,
@@ -34385,10 +33913,10 @@ var index$d = /*#__PURE__*/Object.freeze({
34385
33913
  unmuteMembers: unmuteMembers
34386
33914
  });
34387
33915
 
34388
- var index$c = /*#__PURE__*/Object.freeze({
33916
+ var index$d = /*#__PURE__*/Object.freeze({
34389
33917
  __proto__: null,
34390
- Membership: index$e,
34391
- Moderation: index$d,
33918
+ Membership: index$f,
33919
+ Moderation: index$e,
34392
33920
  getChannelByIds: getChannelByIds$1,
34393
33921
  createChannel: createChannel,
34394
33922
  updateChannel: updateChannel,
@@ -34411,7 +33939,6 @@ var index$c = /*#__PURE__*/Object.freeze({
34411
33939
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
34412
33940
  getChannel: getChannel,
34413
33941
  getChannels: getChannels,
34414
- getTotalChannelsUnread: getTotalChannelsUnread,
34415
33942
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
34416
33943
  isUnreadCountSupport: isUnreadCountSupport,
34417
33944
  convertFromRaw: convertFromRaw,
@@ -35768,7 +35295,7 @@ const searchMembers = (params, callback, config) => {
35768
35295
  };
35769
35296
  /* end_public_function */
35770
35297
 
35771
- var index$b = /*#__PURE__*/Object.freeze({
35298
+ var index$c = /*#__PURE__*/Object.freeze({
35772
35299
  __proto__: null,
35773
35300
  addMembers: addMembers,
35774
35301
  removeMembers: removeMembers,
@@ -36793,7 +36320,7 @@ const unbanMembers = async (communityId, userIds) => {
36793
36320
  };
36794
36321
  /* end_public_function */
36795
36322
 
36796
- var index$a = /*#__PURE__*/Object.freeze({
36323
+ var index$b = /*#__PURE__*/Object.freeze({
36797
36324
  __proto__: null,
36798
36325
  addRoles: addRoles,
36799
36326
  removeRoles: removeRoles,
@@ -36801,10 +36328,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36801
36328
  unbanMembers: unbanMembers
36802
36329
  });
36803
36330
 
36804
- var index$9 = /*#__PURE__*/Object.freeze({
36331
+ var index$a = /*#__PURE__*/Object.freeze({
36805
36332
  __proto__: null,
36806
- Moderation: index$a,
36807
- Membership: index$b,
36333
+ Moderation: index$b,
36334
+ Membership: index$c,
36808
36335
  getCommunityByIds: getCommunities$1,
36809
36336
  createCommunity: createCommunity,
36810
36337
  updateCommunity: updateCommunity,
@@ -37037,7 +36564,7 @@ const getCategories = (params, callback, config) => {
37037
36564
  };
37038
36565
  /* end_public_function */
37039
36566
 
37040
- var index$8 = /*#__PURE__*/Object.freeze({
36567
+ var index$9 = /*#__PURE__*/Object.freeze({
37041
36568
  __proto__: null,
37042
36569
  getCategory: getCategory,
37043
36570
  getCategories: getCategories
@@ -37205,7 +36732,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
37205
36732
  : undefined;
37206
36733
  };
37207
36734
 
37208
- var index$7 = /*#__PURE__*/Object.freeze({
36735
+ var index$8 = /*#__PURE__*/Object.freeze({
37209
36736
  __proto__: null,
37210
36737
  queryGlobalFeed: queryGlobalFeed,
37211
36738
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38520,7 +38047,7 @@ const getComments = (params, callback, config) => {
38520
38047
  };
38521
38048
  /* end_public_function */
38522
38049
 
38523
- var index$6 = /*#__PURE__*/Object.freeze({
38050
+ var index$7 = /*#__PURE__*/Object.freeze({
38524
38051
  __proto__: null,
38525
38052
  getCommentByIds: getCommentByIds,
38526
38053
  createComment: createComment,
@@ -39527,7 +39054,7 @@ const semanticSearchPosts = (params, callback, config) => {
39527
39054
  };
39528
39055
  };
39529
39056
 
39530
- var index$5 = /*#__PURE__*/Object.freeze({
39057
+ var index$6 = /*#__PURE__*/Object.freeze({
39531
39058
  __proto__: null,
39532
39059
  getPostByIds: getPostByIds,
39533
39060
  createPost: createPost,
@@ -40061,7 +39588,7 @@ const getStreams = (params, callback, config) => {
40061
39588
  };
40062
39589
  };
40063
39590
 
40064
- var index$4 = /*#__PURE__*/Object.freeze({
39591
+ var index$5 = /*#__PURE__*/Object.freeze({
40065
39592
  __proto__: null,
40066
39593
  createStream: createStream,
40067
39594
  updateStream: updateStream,
@@ -40348,7 +39875,7 @@ const getPoll = (pollId, callback) => {
40348
39875
  };
40349
39876
  /* end_public_function */
40350
39877
 
40351
- var index$3 = /*#__PURE__*/Object.freeze({
39878
+ var index$4 = /*#__PURE__*/Object.freeze({
40352
39879
  __proto__: null,
40353
39880
  createPoll: createPoll,
40354
39881
  closePoll: closePoll,
@@ -40719,7 +40246,7 @@ const getPlayer = async (parameters) => {
40719
40246
  return video;
40720
40247
  };
40721
40248
 
40722
- var index$2 = /*#__PURE__*/Object.freeze({
40249
+ var index$3 = /*#__PURE__*/Object.freeze({
40723
40250
  __proto__: null,
40724
40251
  getPlayer: getPlayer
40725
40252
  });
@@ -41892,7 +41419,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41892
41419
  };
41893
41420
  };
41894
41421
 
41895
- var index$1 = /*#__PURE__*/Object.freeze({
41422
+ var index$2 = /*#__PURE__*/Object.freeze({
41896
41423
  __proto__: null,
41897
41424
  createImageStory: createImageStory,
41898
41425
  createVideoStory: createVideoStory,
@@ -41929,7 +41456,7 @@ const getNetworkAds = async () => {
41929
41456
  };
41930
41457
  };
41931
41458
 
41932
- var index = /*#__PURE__*/Object.freeze({
41459
+ var index$1 = /*#__PURE__*/Object.freeze({
41933
41460
  __proto__: null,
41934
41461
  getNetworkAds: getNetworkAds
41935
41462
  });
@@ -41956,4 +41483,359 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41956
41483
  return { accessToken: data.accessToken };
41957
41484
  };
41958
41485
 
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 };
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 };