@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.cjs.js CHANGED
@@ -121,6 +121,7 @@ const SECOND$1 = 1000;
121
121
  const MINUTE = 60 * SECOND$1;
122
122
  const HOUR = 60 * MINUTE;
123
123
  const DAY = 24 * HOUR;
124
+ const WEEK = 7 * DAY;
124
125
  const YEAR = 365 * DAY;
125
126
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
126
127
 
@@ -516,7 +517,6 @@ const idResolvers = {
516
517
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
517
518
  channelUnreadInfo: ({ channelId }) => channelId,
518
519
  subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
519
- channelUnread: ({ channelId }) => channelId,
520
520
  channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
521
521
  subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
522
522
  messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
@@ -543,6 +543,8 @@ const idResolvers = {
543
543
  advertiser: ({ advertiserId }) => advertiserId,
544
544
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
545
545
  pinTarget: ({ targetId }) => targetId,
546
+ notificationTrayItem: ({ _id }) => _id,
547
+ notificationTraySeen: ({ userId }) => userId,
546
548
  };
547
549
  /**
548
550
  * Retrieve the id resolver matching a domain name
@@ -594,6 +596,7 @@ const PAYLOAD2MODEL = {
594
596
  advertisers: 'advertiser',
595
597
  pinTargets: 'pinTarget',
596
598
  pins: 'pin',
599
+ notificationTrayItems: 'notificationTrayItem',
597
600
  };
598
601
  /** hidden */
599
602
  const isOutdated = (prevData, nextData) => {
@@ -1610,13 +1613,13 @@ class NetworkActivitiesWatcher {
1610
1613
  this._listener.clear();
1611
1614
  }
1612
1615
  }
1613
- let instance$6;
1616
+ let instance$5;
1614
1617
  var NetworkActivitiesWatcher$1 = {
1615
1618
  getInstance: () => {
1616
- if (!instance$6) {
1617
- instance$6 = new NetworkActivitiesWatcher();
1619
+ if (!instance$5) {
1620
+ instance$5 = new NetworkActivitiesWatcher();
1618
1621
  }
1619
- return instance$6;
1622
+ return instance$5;
1620
1623
  },
1621
1624
  };
1622
1625
 
@@ -5149,13 +5152,13 @@ class AnalyticsEngine {
5149
5152
  this._eventCapturer.resetAllBuckets();
5150
5153
  }
5151
5154
  }
5152
- let instance$5;
5155
+ let instance$4;
5153
5156
  var AnalyticsEngine$1 = {
5154
5157
  getInstance: () => {
5155
- if (!instance$5) {
5156
- instance$5 = new AnalyticsEngine();
5158
+ if (!instance$4) {
5159
+ instance$4 = new AnalyticsEngine();
5157
5160
  }
5158
- return instance$5;
5161
+ return instance$4;
5159
5162
  },
5160
5163
  };
5161
5164
 
@@ -5581,223 +5584,6 @@ const getMessageReadCount = (message, marker) => {
5581
5584
  getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
5582
5585
  }; // and if not found in cache use default value `0`
5583
5586
 
5584
- /**
5585
- *
5586
- * Mark subChannel as read by readToSegment
5587
- *
5588
- * @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
5589
- * @param readToSegment the segment to mark as read
5590
- * @returns a success boolean if the {@link Amity.SubChannel} was updated
5591
- *
5592
- * @category Channel API
5593
- * @async
5594
- */
5595
- const markChannelsAsReadBySegment = async (readings) => {
5596
- const client = getActiveClient();
5597
- try {
5598
- await client.http.post('api/v3/channels/seen', { channels: readings });
5599
- return true;
5600
- }
5601
- catch (e) {
5602
- return false;
5603
- }
5604
- };
5605
-
5606
- class MessageReadReceiptSyncEngine {
5607
- constructor() {
5608
- this.isActive = true;
5609
- this.MAX_RETRY = 3;
5610
- this.JOB_QUEUE_SIZE = 120;
5611
- this.jobQueue = [];
5612
- // Interval for message read receipt sync in seconds
5613
- this.RECEIPT_SYNC_INTERVAL = 1;
5614
- this.client = getActiveClient();
5615
- // Get remaining unsync read receipts from cache
5616
- this.getUnsyncJobs();
5617
- }
5618
- // Call this when client call client.login
5619
- startSyncReadReceipt() {
5620
- // Start timer when start receipt sync
5621
- this.timer = setInterval(() => {
5622
- this.syncReadReceipts();
5623
- }, this.RECEIPT_SYNC_INTERVAL * 1000);
5624
- }
5625
- // Read receipt observer handling
5626
- syncReadReceipts() {
5627
- if (this.jobQueue.length === 0 || this.isActive === false)
5628
- return;
5629
- const readReceipts = this.getReadReceipts();
5630
- if (readReceipts) {
5631
- this.markReadApi(readReceipts);
5632
- }
5633
- }
5634
- getUnsyncJobs() {
5635
- var _a;
5636
- // Get all read receipts that has latestSyncSegment < latestSegment
5637
- const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5638
- return data.latestSyncSegment < data.latestSegment;
5639
- });
5640
- // Enqueue unsync read receipts to the job queue
5641
- readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
5642
- this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
5643
- });
5644
- }
5645
- getReadReceipts() {
5646
- // get all read receipts from queue, now the queue is empty
5647
- const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
5648
- if (syncJob.length === 0)
5649
- return;
5650
- return syncJob.filter(job => {
5651
- var _a;
5652
- const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
5653
- if (!readReceipt)
5654
- return false;
5655
- if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
5656
- return true;
5657
- return false;
5658
- });
5659
- }
5660
- async markReadApi(syncJobs) {
5661
- var _a;
5662
- // constuct payload
5663
- // example: [{ channelId: 'channelId', readToSegment: 2 }]
5664
- const syncJobsPayload = syncJobs.map(job => {
5665
- return {
5666
- channelId: job.channelId,
5667
- readToSegment: job.segment,
5668
- };
5669
- });
5670
- const response = await markChannelsAsReadBySegment(syncJobsPayload);
5671
- if (response) {
5672
- for (let i = 0; i < syncJobs.length; i += 1) {
5673
- // update lastestSyncSegment in read receipt cache
5674
- const cacheKey = ['readReceipt', syncJobs[i].channelId];
5675
- const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
5676
- pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
5677
- }
5678
- }
5679
- else {
5680
- for (let i = 0; i < syncJobs.length; i += 1) {
5681
- // push them back to queue if the syncing is failed and retry count is less than max retry
5682
- if (syncJobs[i].retryCount >= this.MAX_RETRY)
5683
- return;
5684
- const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
5685
- this.enqueueJob(updatedJob);
5686
- }
5687
- }
5688
- }
5689
- startObservingReadReceiptQueue() {
5690
- if (this.client.useLegacyUnreadCount) {
5691
- this.isActive = true;
5692
- this.startSyncReadReceipt();
5693
- }
5694
- }
5695
- stopObservingReadReceiptQueue() {
5696
- this.isActive = false;
5697
- this.jobQueue.map(job => {
5698
- if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
5699
- return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
5700
- }
5701
- return job;
5702
- });
5703
- if (this.timer)
5704
- clearInterval(this.timer);
5705
- }
5706
- // Session Management
5707
- onSessionEstablished() {
5708
- this.startObservingReadReceiptQueue();
5709
- }
5710
- onSessionDestroyed() {
5711
- this.stopObservingReadReceiptQueue();
5712
- this.jobQueue = [];
5713
- }
5714
- onTokenExpired() {
5715
- this.stopObservingReadReceiptQueue();
5716
- }
5717
- // Network Connection Management
5718
- onNetworkOffline() {
5719
- // Stop observing to the read receipt queue.
5720
- this.stopObservingReadReceiptQueue();
5721
- }
5722
- onNetworkOnline() {
5723
- // Resume observing to the read receipt queue.
5724
- this.startObservingReadReceiptQueue();
5725
- }
5726
- markRead(channelId, segment) {
5727
- var _a;
5728
- // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
5729
- const cacheKey = ['channelUnread', 'get', channelId];
5730
- const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
5731
- if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
5732
- channelUnread &&
5733
- segment > channelUnread.readToSegment) {
5734
- channelUnread.readToSegment = segment;
5735
- channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
5736
- pushToCache(cacheKey, channelUnread);
5737
- fireEvent('local.channelUnread.updated', channelUnread);
5738
- }
5739
- // Step 2: Enqueue the read receipt
5740
- this.enqueueReadReceipt(channelId, segment);
5741
- }
5742
- enqueueReadReceipt(channelId, segment) {
5743
- var _a;
5744
- const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
5745
- // Create new read receipt if it's not exists and add the job to queue
5746
- if (!readReceipt) {
5747
- const readReceiptChannel = {
5748
- channelId,
5749
- latestSegment: segment,
5750
- latestSyncSegment: 0,
5751
- };
5752
- pushToCache(['readReceipt', channelId], readReceiptChannel);
5753
- }
5754
- else if (readReceipt.latestSegment < segment) {
5755
- // Update latestSegment in read receipt cache
5756
- pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
5757
- }
5758
- else if (readReceipt.latestSyncSegment >= segment) {
5759
- // Skip the job when lastSyncSegment > = segment
5760
- return;
5761
- }
5762
- let syncJob = this.getSyncJob(channelId);
5763
- if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
5764
- syncJob = {
5765
- channelId,
5766
- segment,
5767
- syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
5768
- retryCount: 0,
5769
- };
5770
- this.enqueueJob(syncJob);
5771
- }
5772
- else if (syncJob.segment < segment) {
5773
- syncJob.segment = segment;
5774
- }
5775
- }
5776
- getSyncJob(channelId) {
5777
- const { jobQueue } = this;
5778
- const targetJob = jobQueue.find(job => job.channelId === channelId);
5779
- return targetJob || null;
5780
- }
5781
- enqueueJob(syncJob) {
5782
- if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
5783
- this.jobQueue.push(syncJob);
5784
- }
5785
- else {
5786
- // Remove oldest job when queue reach maximum capacity
5787
- this.jobQueue.shift();
5788
- this.jobQueue.push(syncJob);
5789
- }
5790
- }
5791
- }
5792
- let instance$4 = null;
5793
- var ReadReceiptSyncEngine = {
5794
- getInstance: () => {
5795
- if (!instance$4)
5796
- instance$4 = new MessageReadReceiptSyncEngine();
5797
- return instance$4;
5798
- },
5799
- };
5800
-
5801
5587
  /**
5802
5588
  *
5803
5589
  * Mark subChannel as read by readToSegment
@@ -5846,7 +5632,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
5846
5632
  return channelUnreadInfo;
5847
5633
  };
5848
5634
 
5849
- class LegacyMessageReadReceiptSyncEngine {
5635
+ class MessageReadReceiptSyncEngine {
5850
5636
  constructor() {
5851
5637
  this.isActive = true;
5852
5638
  this.MAX_RETRY = 3;
@@ -5877,7 +5663,7 @@ class LegacyMessageReadReceiptSyncEngine {
5877
5663
  getUnsyncJobs() {
5878
5664
  var _a;
5879
5665
  // Get all read receipts that has latestSyncSegment < latestSegment
5880
- const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5666
+ const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5881
5667
  return data.latestSyncSegment < data.latestSegment;
5882
5668
  });
5883
5669
  // Enqueue unsync read receipts to the job queue
@@ -5896,7 +5682,7 @@ class LegacyMessageReadReceiptSyncEngine {
5896
5682
  return;
5897
5683
  // Get readReceipt from cache by subChannelId
5898
5684
  const readReceipt = (_a = pullFromCache([
5899
- 'legacyReadReceipt',
5685
+ 'readReceipt',
5900
5686
  syncJob.subChannelId,
5901
5687
  ])) === null || _a === void 0 ? void 0 : _a.data;
5902
5688
  if (!readReceipt)
@@ -5919,10 +5705,10 @@ class LegacyMessageReadReceiptSyncEngine {
5919
5705
  if (response) {
5920
5706
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
5921
5707
  const readReceiptCache = (_a = pullFromCache([
5922
- 'legacyReadReceipt',
5708
+ 'readReceipt',
5923
5709
  subChannelId,
5924
5710
  ])) === null || _a === void 0 ? void 0 : _a.data;
5925
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
5711
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
5926
5712
  }
5927
5713
  else if (!response) {
5928
5714
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -5989,7 +5775,7 @@ class LegacyMessageReadReceiptSyncEngine {
5989
5775
  subChannelUnreadInfo.readToSegment = segment;
5990
5776
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
5991
5777
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
5992
- fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
5778
+ fireEvent('local.channelUnread.updated', channelUnreadInfo);
5993
5779
  pushToCache(cacheKey, subChannelUnreadInfo);
5994
5780
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
5995
5781
  }
@@ -5998,10 +5784,7 @@ class LegacyMessageReadReceiptSyncEngine {
5998
5784
  }
5999
5785
  enqueueReadReceipt(subChannelId, segment) {
6000
5786
  var _a;
6001
- const readReceipt = (_a = pullFromCache([
6002
- 'legacyReadReceipt',
6003
- subChannelId,
6004
- ])) === null || _a === void 0 ? void 0 : _a.data;
5787
+ const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
6005
5788
  // Create new read receipt if it's not exists and add job to queue
6006
5789
  if (!readReceipt) {
6007
5790
  const readReceiptSubChannel = {
@@ -6009,10 +5792,10 @@ class LegacyMessageReadReceiptSyncEngine {
6009
5792
  latestSegment: segment,
6010
5793
  latestSyncSegment: 0,
6011
5794
  };
6012
- pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
5795
+ pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
6013
5796
  }
6014
5797
  else if (readReceipt.latestSegment < segment) {
6015
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
5798
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
6016
5799
  }
6017
5800
  else if (readReceipt.latestSyncSegment >= segment) {
6018
5801
  // Skip the job when lastSyncSegment > = segment
@@ -6055,24 +5838,18 @@ class LegacyMessageReadReceiptSyncEngine {
6055
5838
  }
6056
5839
  }
6057
5840
  let instance$3 = null;
6058
- var LegacyReadReceiptSyncEngine = {
5841
+ var ReadReceiptSyncEngine = {
6059
5842
  getInstance: () => {
6060
5843
  if (!instance$3)
6061
- instance$3 = new LegacyMessageReadReceiptSyncEngine();
5844
+ instance$3 = new MessageReadReceiptSyncEngine();
6062
5845
  return instance$3;
6063
5846
  },
6064
5847
  };
6065
5848
 
6066
5849
  const markReadMessage = (message) => {
6067
- const client = getActiveClient();
6068
- if (client.useLegacyUnreadCount) {
6069
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
6070
- markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
6071
- }
6072
- else {
6073
- const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
6074
- markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
6075
- }
5850
+ const { subChannelId, channelSegment } = message;
5851
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
5852
+ markReadReceiptEngine.markRead(subChannelId, channelSegment);
6076
5853
  };
6077
5854
 
6078
5855
  const messageLinkedObject = (message) => {
@@ -6220,6 +5997,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
6220
5997
  } });
6221
5998
  };
6222
5999
 
6000
+ const notificationTrayLinkedObject = (noti) => {
6001
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
6002
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
6003
+ .filter(isNonNullable)
6004
+ .map(({ data }) => data)
6005
+ .map(user => userLinkedObject(user)) });
6006
+ };
6007
+
6223
6008
  const LinkedObject = {
6224
6009
  ad: adLinkedObject,
6225
6010
  comment: commentLinkedObject,
@@ -6233,6 +6018,7 @@ const LinkedObject = {
6233
6018
  reactor: reactorLinkedObject,
6234
6019
  channel: channelLinkedObject,
6235
6020
  pinnedPost: pinnedPostLinkedObject,
6021
+ notificationTray: notificationTrayLinkedObject,
6236
6022
  };
6237
6023
 
6238
6024
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -7060,31 +6846,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
7060
6846
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
7061
6847
  });
7062
6848
  };
7063
- const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
7064
- for (let i = 0; i < channels.length; i += 1) {
7065
- const cacheKey = ['channelUnread', 'get', channels[i].channelId];
7066
- const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
7067
- let unreadCount = 0;
7068
- let readToSegment = null;
7069
- let lastMentionedSegment = null;
7070
- let isMentioned = false;
7071
- if (channelUser) {
7072
- readToSegment = channelUser.readToSegment;
7073
- lastMentionedSegment = channelUser.lastMentionedSegment;
7074
- unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
7075
- isMentioned = lastMentionedSegment > readToSegment;
7076
- }
7077
- pushToCache(cacheKey, {
7078
- channelId: channels[i].channelId,
7079
- lastSegment: channels[i].messageCount,
7080
- readToSegment,
7081
- lastMentionedSegment,
7082
- unreadCount,
7083
- isMentioned,
7084
- isDeleted: channels[i].isDeleted,
7085
- });
7086
- }
7087
- };
7088
6849
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
7089
6850
  const client = getActiveClient();
7090
6851
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -7094,34 +6855,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
7094
6855
  rawPayload.messagePreviews.length > 0) {
7095
6856
  updateChannelMessagePreviewCache(rawPayload);
7096
6857
  }
7097
- if (client.useLegacyUnreadCount) {
7098
- updateChannelUnread({
7099
- channels: rawPayload.channels,
7100
- channelUsers: rawPayload.channelUsers,
7101
- currentUserId: client.userId,
7102
- });
7103
- }
7104
- else {
7105
- const markerIds = rawPayload.channels
7106
- // filter channel by type. Only conversation, community and broadcast type are included.
7107
- .filter(isUnreadCountSupport)
7108
- .map(({ channelInternalId }) => channelInternalId);
7109
- if (markerIds.length > 0) {
7110
- // since the get markers method requires a channel cache to function with the reducer.
7111
- preUpdateChannelCache(rawPayload, {
7112
- isMessagePreviewUpdated: options.isMessagePreviewUpdated,
7113
- });
7114
- try {
7115
- await getChannelMarkers(markerIds);
7116
- }
7117
- catch (e) {
7118
- // empty block (from the spec, allow marker fetch to fail without having to do anything)
7119
- }
6858
+ const markerIds = rawPayload.channels
6859
+ // filter channel by type. Only conversation, community and broadcast type are included.
6860
+ .filter(isUnreadCountSupport)
6861
+ .map(({ channelInternalId }) => channelInternalId);
6862
+ if (markerIds.length > 0) {
6863
+ // since the get markers method requires a channel cache to function with the reducer.
6864
+ preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
6865
+ try {
6866
+ await getChannelMarkers(markerIds);
6867
+ }
6868
+ catch (e) {
6869
+ // empty block (from the spec, allow marker fetch to fail without having to do anything)
7120
6870
  }
7121
6871
  }
7122
- // convert raw channel to internal channel
6872
+ // attach marker to channel
7123
6873
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
7124
- // convert raw channel user to membership (add user object)
6874
+ // user marker to channel users
7125
6875
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
7126
6876
  return convertRawMembershipToMembership(channelUser);
7127
6877
  });
@@ -7248,28 +6998,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
7248
6998
  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;
7249
6999
  };
7250
7000
 
7251
- const getLegacyChannelUnread = (channelId) => {
7252
- var _a;
7253
- return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
7254
- };
7255
-
7256
7001
  const constructChannelDynamicValue = (channel) => {
7257
- const client = getActiveClient();
7258
7002
  const rest = __rest(channel, ["messageCount"]);
7259
7003
  return shallowClone(rest, {
7260
- get unreadCount() {
7261
- var _a, _b;
7262
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
7004
+ get isMentioned() {
7005
+ return getChannelIsMentioned(rest);
7263
7006
  },
7264
7007
  get subChannelsUnreadCount() {
7265
7008
  return getSubChannelsUnreadCount(rest);
7266
7009
  },
7267
- get isMentioned() {
7268
- var _a, _b;
7269
- if (client.useLegacyUnreadCount)
7270
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
7271
- return getChannelIsMentioned(rest);
7272
- },
7273
7010
  });
7274
7011
  };
7275
7012
 
@@ -7926,21 +7663,12 @@ const onChannelDeleted = (callback) => {
7926
7663
  const client = getActiveClient();
7927
7664
  const filter = async (payload) => {
7928
7665
  const data = await prepareChannelPayload(payload);
7929
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
7930
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
7931
- data.channels.forEach(channel => {
7932
- if (isConsistentMode) {
7666
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
7667
+ data.channels.forEach(channel => {
7933
7668
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
7934
7669
  deleteChannelUnreadByChannelId(channel.channelId);
7935
- }
7936
- else if (isLegacyUnreadCount) {
7937
- const cacheKey = ['channelUnread', 'get', channel.channelId];
7938
- const cache = pullFromCache(cacheKey);
7939
- if (cache) {
7940
- pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
7941
- }
7942
- }
7943
- });
7670
+ });
7671
+ }
7944
7672
  ingestInCache(data);
7945
7673
  callbacks$b.forEach(cb => cb(data.channels[0]));
7946
7674
  };
@@ -8054,25 +7782,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
8054
7782
  };
8055
7783
  };
8056
7784
 
8057
- var legacyReadReceiptSyncEngineOnLoginHandler = () => {
8058
- const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
8059
- readReceiptSyncEngine.startSyncReadReceipt();
8060
- onSessionStateChange(state => {
8061
- if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
8062
- readReceiptSyncEngine.onSessionEstablished();
8063
- }
8064
- else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
8065
- readReceiptSyncEngine.onTokenExpired();
8066
- }
8067
- else {
8068
- readReceiptSyncEngine.onSessionDestroyed();
8069
- }
8070
- });
8071
- return () => {
8072
- readReceiptSyncEngine.onSessionDestroyed();
8073
- };
8074
- };
8075
-
8076
7785
  const onOnline = (callback) => {
8077
7786
  if (typeof window !== 'undefined' && window.addEventListener) {
8078
7787
  window.addEventListener('online', callback);
@@ -8639,17 +8348,10 @@ const onChannelLeft = (callback) => {
8639
8348
  const preparedPayload = await prepareChannelPayload(payload, {
8640
8349
  isMessagePreviewUpdated: isLeftByMe,
8641
8350
  });
8642
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
8643
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
8644
- if (isLeftByMe) {
8351
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
8645
8352
  preparedPayload.channels.forEach(channel => {
8646
- if (isConsistentMode) {
8647
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
8648
- deleteChannelUnreadByChannelId(channel.channelId);
8649
- }
8650
- else if (isLegacyUnreadCount) {
8651
- dropFromCache(['channelUnread', 'get', channel.channelId]);
8652
- }
8353
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
8354
+ deleteChannelUnreadByChannelId(channel.channelId);
8653
8355
  });
8654
8356
  }
8655
8357
  const { channels, channelUsers } = preparedPayload;
@@ -8917,34 +8619,6 @@ const onMessageCreatedMqtt = (callback) => {
8917
8619
  reCalculateChannelUnreadInfo(message.channelId);
8918
8620
  });
8919
8621
  }
8920
- if (client.useLegacyUnreadCount) {
8921
- rawPayload.messages.forEach(message => {
8922
- var _a, _b;
8923
- const channelUnread = (_a = pullFromCache([
8924
- 'channelUnread',
8925
- 'get',
8926
- message.channelId,
8927
- ])) === null || _a === void 0 ? void 0 : _a.data;
8928
- if (!channelUnread ||
8929
- channelUnread.lastSegment >= message.segment ||
8930
- typeof channelUnread.readToSegment !== 'number' ||
8931
- typeof channelUnread.lastMentionSegment !== 'number')
8932
- return;
8933
- const lastSegment = message.segment;
8934
- const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
8935
- return (mention.type === 'channel' ||
8936
- (mention.type === 'user' &&
8937
- client.userId &&
8938
- mention.userPublicIds.includes(client.userId)));
8939
- });
8940
- const lastMentionSegment = isMentionedInMessage
8941
- ? message.segment
8942
- : channelUnread.lastMentionSegment;
8943
- const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionSegment) });
8944
- pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
8945
- fireEvent('local.channelUnread.updated', updatedChannelUnread);
8946
- });
8947
- }
8948
8622
  // Update in cache
8949
8623
  ingestInCache(payload);
8950
8624
  payload.messages.forEach(message => {
@@ -9120,7 +8794,6 @@ const enableUnreadCount = () => {
9120
8794
  if (client.isUnreadCountEnabled)
9121
8795
  return false;
9122
8796
  client.isUnreadCountEnabled = true;
9123
- client.useLegacyUnreadCount = false;
9124
8797
  client.emitter.emit('unreadCountEnabled', true);
9125
8798
  return true;
9126
8799
  };
@@ -9436,12 +9109,7 @@ const login = async (params, sessionHandler, config) => {
9436
9109
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
9437
9110
  // the channel because currently backend can't handle this, so every time a user is banned from
9438
9111
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
9439
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
9440
- if (client.useLegacyUnreadCount) {
9441
- subscriptions.push(readReceiptSyncEngineOnLoginHandler());
9442
- }
9443
- else
9444
- subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
9112
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
9445
9113
  const markerSyncUnsubscriber = await startMarkerSync();
9446
9114
  subscriptions.push(markerSyncUnsubscriber);
9447
9115
  }
@@ -9622,8 +9290,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9622
9290
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
9623
9291
  const sessionHandler = undefined;
9624
9292
  const isUnreadCountEnabled = false;
9625
- // Legacy unread count is true by default
9626
- const useLegacyUnreadCount = true;
9627
9293
  const client = {
9628
9294
  version: `${VERSION}`,
9629
9295
  apiKey,
@@ -9653,7 +9319,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9653
9319
  getMessagePreviewSetting,
9654
9320
  use: () => setActiveClient(client),
9655
9321
  isUnreadCountEnabled,
9656
- useLegacyUnreadCount,
9657
9322
  getMarkerSyncConsistentMode,
9658
9323
  /**
9659
9324
  * Prefix for the deviceId key in the local storage or async storage.
@@ -10124,7 +9789,7 @@ const getUserUnread = (callback) => {
10124
9789
  };
10125
9790
  };
10126
9791
 
10127
- var index$l = /*#__PURE__*/Object.freeze({
9792
+ var index$m = /*#__PURE__*/Object.freeze({
10128
9793
  __proto__: null,
10129
9794
  getActiveClient: getActiveClient,
10130
9795
  getActiveUser: getActiveUser,
@@ -11331,7 +10996,7 @@ const getMyFollowInfo = (callback) => {
11331
10996
  };
11332
10997
  /* end_public_function */
11333
10998
 
11334
- var index$k = /*#__PURE__*/Object.freeze({
10999
+ var index$l = /*#__PURE__*/Object.freeze({
11335
11000
  __proto__: null,
11336
11001
  blockUser: blockUser,
11337
11002
  unBlockUser: unBlockUser,
@@ -12346,9 +12011,9 @@ var AmityUserSearchMatchType;
12346
12011
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12347
12012
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12348
12013
 
12349
- var index$j = /*#__PURE__*/Object.freeze({
12014
+ var index$k = /*#__PURE__*/Object.freeze({
12350
12015
  __proto__: null,
12351
- Relationship: index$k,
12016
+ Relationship: index$l,
12352
12017
  getUserByIds: getUserByIds,
12353
12018
  updateUser: updateUser,
12354
12019
  flagUser: flagUser,
@@ -12612,7 +12277,7 @@ const uploadImage = async (formData, onProgress) => {
12612
12277
  };
12613
12278
  /* end_public_function */
12614
12279
 
12615
- var index$i = /*#__PURE__*/Object.freeze({
12280
+ var index$j = /*#__PURE__*/Object.freeze({
12616
12281
  __proto__: null,
12617
12282
  getFile: getFile,
12618
12283
  uploadFile: uploadFile,
@@ -14424,7 +14089,7 @@ const getReactions = (params, callback, config) => {
14424
14089
  };
14425
14090
  /* end_public_function */
14426
14091
 
14427
- var index$h = /*#__PURE__*/Object.freeze({
14092
+ var index$i = /*#__PURE__*/Object.freeze({
14428
14093
  __proto__: null,
14429
14094
  addReaction: addReaction,
14430
14095
  removeReaction: removeReaction,
@@ -16240,7 +15905,7 @@ const getMessages = (params, callback, config) => {
16240
15905
  };
16241
15906
  /* end_public_function */
16242
15907
 
16243
- var index$g = /*#__PURE__*/Object.freeze({
15908
+ var index$h = /*#__PURE__*/Object.freeze({
16244
15909
  __proto__: null,
16245
15910
  createMessage: createMessage,
16246
15911
  updateMessage: updateMessage,
@@ -16766,7 +16431,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16766
16431
  };
16767
16432
  /* end_public_function */
16768
16433
 
16769
- var index$f = /*#__PURE__*/Object.freeze({
16434
+ var index$g = /*#__PURE__*/Object.freeze({
16770
16435
  __proto__: null,
16771
16436
  getSubChannelByIds: getSubChannels$1,
16772
16437
  createSubChannel: createSubChannel,
@@ -16787,37 +16452,19 @@ var index$f = /*#__PURE__*/Object.freeze({
16787
16452
  /**
16788
16453
  * Internal used only
16789
16454
  *
16790
- * Fired when an {@link Amity.channelUnreadInfo} has been updated.
16791
- *
16792
- * @param callback The function to call when the event was fired
16793
- * @returns an {@link Amity.Unsubscriber} function to stop listening
16794
- *
16795
- * @category ChannelMarker Events
16796
- */
16797
- const onChannelUnreadInfoUpdatedLocal = (callback) => {
16798
- const client = getActiveClient();
16799
- const filter = (payload) => {
16800
- callback(payload);
16801
- };
16802
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
16803
- };
16804
-
16805
- /**
16806
- * Internal used only
16807
- *
16808
- * Fired when an {@link Amity.ChannelUnread} has been updated.
16455
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
16809
16456
  *
16810
16457
  * @param callback The function to call when the event was fired
16811
16458
  * @returns an {@link Amity.Unsubscriber} function to stop listening
16812
16459
  *
16813
- * @category Channel Events
16460
+ * @category MessageMarker Events
16814
16461
  */
16815
16462
  const onChannelUnreadUpdatedLocal = (callback) => {
16816
16463
  const client = getActiveClient();
16817
16464
  const filter = (payload) => {
16818
16465
  callback(payload);
16819
16466
  };
16820
- return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
16467
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
16821
16468
  };
16822
16469
 
16823
16470
  /* begin_public_function
@@ -17019,7 +16666,6 @@ const getChannel = (channelId, callback) => {
17019
16666
  return onSubChannelUpdated(updateMessagePreview);
17020
16667
  }, 'channelId', 'channel'),
17021
16668
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
17022
- convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
17023
16669
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
17024
16670
  ], {
17025
16671
  forceDispatch: true,
@@ -17533,10 +17179,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
17533
17179
  },
17534
17180
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
17535
17181
  },
17536
- {
17537
- fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
17538
- action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
17539
- },
17540
17182
  {
17541
17183
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
17542
17184
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -17602,120 +17244,6 @@ const getChannels = (params, callback, config) => {
17602
17244
  };
17603
17245
  /* end_public_function */
17604
17246
 
17605
- /**
17606
- *
17607
- * Calculate user unread from {@link Amity.ChannelUnread} objects
17608
- *
17609
- * @returns the {@link Amity.UserUnread} objects
17610
- *
17611
- * @category Channel API
17612
- * @async
17613
- */
17614
- const getTotalChannelsUnread$1 = () => {
17615
- var _a;
17616
- const client = getActiveClient();
17617
- client.log('channel/getTotalChannelsUnread.locally');
17618
- const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
17619
- return !data.isDeleted;
17620
- })) || [];
17621
- const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
17622
- acc.unreadCount += data.unreadCount;
17623
- acc.isMentioned = acc.isMentioned || data.isMentioned;
17624
- return acc;
17625
- }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
17626
- const cachedAt = client.cache && Date.now();
17627
- return {
17628
- data: totalChannelsUnread,
17629
- cachedAt,
17630
- };
17631
- };
17632
-
17633
- /* begin_public_function
17634
- id: totalChannelsUnread.get
17635
- */
17636
- /**
17637
- * ```js
17638
- * import { ChannelRepository } from '@amityco/ts-sdk';
17639
- *
17640
- * let totalChannelsUnread;
17641
- *
17642
- * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
17643
- * unread = response.data;
17644
- * });
17645
- * ```
17646
- *
17647
- * Observe all mutation on a given {@link Amity.UserUnread}
17648
- *
17649
- * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
17650
- *
17651
- * @category User Unread Live Object
17652
- *
17653
- */
17654
- const getTotalChannelsUnread = (callback) => {
17655
- const { _id: userId } = getActiveUser();
17656
- if (!userId)
17657
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
17658
- const { log, cache } = getActiveClient();
17659
- if (!cache) {
17660
- console.log('For using Live Object feature you need to enable Cache!');
17661
- }
17662
- const timestamp = Date.now();
17663
- log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
17664
- const disposers = [];
17665
- let isUnsyncedModel = false; // for messages
17666
- let model;
17667
- const dispatcher = (data) => {
17668
- const { data: userUnread } = data;
17669
- const callbackModel = userUnread
17670
- ? {
17671
- unreadCount: userUnread.unreadCount,
17672
- isMentioned: userUnread.isMentioned,
17673
- }
17674
- : undefined;
17675
- model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
17676
- callback({
17677
- data: callbackModel
17678
- ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
17679
- loading: data.loading,
17680
- error: data.error,
17681
- });
17682
- };
17683
- const realtimeRouter = (userUnread) => {
17684
- if (isEqual(model, userUnread))
17685
- return;
17686
- dispatcher({
17687
- loading: false,
17688
- data: userUnread,
17689
- });
17690
- };
17691
- const onFetch = () => {
17692
- const query = createQuery(async () => getTotalChannelsUnread$1());
17693
- runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
17694
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
17695
- dispatcher({
17696
- data,
17697
- origin,
17698
- loading: false,
17699
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
17700
- });
17701
- isUnsyncedModel = true;
17702
- disposers.forEach(fn => fn());
17703
- }
17704
- else if (!isUnsyncedModel) {
17705
- dispatcher({ loading, data, origin, error });
17706
- }
17707
- if (error) {
17708
- disposers.forEach(fn => fn());
17709
- }
17710
- });
17711
- };
17712
- disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
17713
- onFetch();
17714
- return () => {
17715
- disposers.forEach(fn => fn());
17716
- };
17717
- };
17718
-
17719
17247
  /* begin_public_function
17720
17248
  id: channel.member.add
17721
17249
  */
@@ -18080,7 +17608,7 @@ const searchMembers$1 = (params, callback, config) => {
18080
17608
  };
18081
17609
  /* end_public_function */
18082
17610
 
18083
- var index$e = /*#__PURE__*/Object.freeze({
17611
+ var index$f = /*#__PURE__*/Object.freeze({
18084
17612
  __proto__: null,
18085
17613
  addMembers: addMembers$1,
18086
17614
  removeMembers: removeMembers$1,
@@ -18283,7 +17811,7 @@ const unmuteMembers = async (channelId, userIds) => {
18283
17811
  };
18284
17812
  /* end_public_function */
18285
17813
 
18286
- var index$d = /*#__PURE__*/Object.freeze({
17814
+ var index$e = /*#__PURE__*/Object.freeze({
18287
17815
  __proto__: null,
18288
17816
  addRole: addRole,
18289
17817
  removeRole: removeRole,
@@ -18293,10 +17821,10 @@ var index$d = /*#__PURE__*/Object.freeze({
18293
17821
  unmuteMembers: unmuteMembers
18294
17822
  });
18295
17823
 
18296
- var index$c = /*#__PURE__*/Object.freeze({
17824
+ var index$d = /*#__PURE__*/Object.freeze({
18297
17825
  __proto__: null,
18298
- Membership: index$e,
18299
- Moderation: index$d,
17826
+ Membership: index$f,
17827
+ Moderation: index$e,
18300
17828
  getChannelByIds: getChannelByIds$1,
18301
17829
  createChannel: createChannel,
18302
17830
  updateChannel: updateChannel,
@@ -18319,7 +17847,6 @@ var index$c = /*#__PURE__*/Object.freeze({
18319
17847
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
18320
17848
  getChannel: getChannel,
18321
17849
  getChannels: getChannels,
18322
- getTotalChannelsUnread: getTotalChannelsUnread,
18323
17850
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
18324
17851
  isUnreadCountSupport: isUnreadCountSupport,
18325
17852
  convertFromRaw: convertFromRaw,
@@ -19676,7 +19203,7 @@ const searchMembers = (params, callback, config) => {
19676
19203
  };
19677
19204
  /* end_public_function */
19678
19205
 
19679
- var index$b = /*#__PURE__*/Object.freeze({
19206
+ var index$c = /*#__PURE__*/Object.freeze({
19680
19207
  __proto__: null,
19681
19208
  addMembers: addMembers,
19682
19209
  removeMembers: removeMembers,
@@ -20701,7 +20228,7 @@ const unbanMembers = async (communityId, userIds) => {
20701
20228
  };
20702
20229
  /* end_public_function */
20703
20230
 
20704
- var index$a = /*#__PURE__*/Object.freeze({
20231
+ var index$b = /*#__PURE__*/Object.freeze({
20705
20232
  __proto__: null,
20706
20233
  addRoles: addRoles,
20707
20234
  removeRoles: removeRoles,
@@ -20709,10 +20236,10 @@ var index$a = /*#__PURE__*/Object.freeze({
20709
20236
  unbanMembers: unbanMembers
20710
20237
  });
20711
20238
 
20712
- var index$9 = /*#__PURE__*/Object.freeze({
20239
+ var index$a = /*#__PURE__*/Object.freeze({
20713
20240
  __proto__: null,
20714
- Moderation: index$a,
20715
- Membership: index$b,
20241
+ Moderation: index$b,
20242
+ Membership: index$c,
20716
20243
  getCommunityByIds: getCommunities$1,
20717
20244
  createCommunity: createCommunity,
20718
20245
  updateCommunity: updateCommunity,
@@ -20945,7 +20472,7 @@ const getCategories = (params, callback, config) => {
20945
20472
  };
20946
20473
  /* end_public_function */
20947
20474
 
20948
- var index$8 = /*#__PURE__*/Object.freeze({
20475
+ var index$9 = /*#__PURE__*/Object.freeze({
20949
20476
  __proto__: null,
20950
20477
  getCategory: getCategory,
20951
20478
  getCategories: getCategories
@@ -21113,7 +20640,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
21113
20640
  : undefined;
21114
20641
  };
21115
20642
 
21116
- var index$7 = /*#__PURE__*/Object.freeze({
20643
+ var index$8 = /*#__PURE__*/Object.freeze({
21117
20644
  __proto__: null,
21118
20645
  queryGlobalFeed: queryGlobalFeed,
21119
20646
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -22428,7 +21955,7 @@ const getComments = (params, callback, config) => {
22428
21955
  };
22429
21956
  /* end_public_function */
22430
21957
 
22431
- var index$6 = /*#__PURE__*/Object.freeze({
21958
+ var index$7 = /*#__PURE__*/Object.freeze({
22432
21959
  __proto__: null,
22433
21960
  getCommentByIds: getCommentByIds,
22434
21961
  createComment: createComment,
@@ -23435,7 +22962,7 @@ const semanticSearchPosts = (params, callback, config) => {
23435
22962
  };
23436
22963
  };
23437
22964
 
23438
- var index$5 = /*#__PURE__*/Object.freeze({
22965
+ var index$6 = /*#__PURE__*/Object.freeze({
23439
22966
  __proto__: null,
23440
22967
  getPostByIds: getPostByIds,
23441
22968
  createPost: createPost,
@@ -23969,7 +23496,7 @@ const getStreams = (params, callback, config) => {
23969
23496
  };
23970
23497
  };
23971
23498
 
23972
- var index$4 = /*#__PURE__*/Object.freeze({
23499
+ var index$5 = /*#__PURE__*/Object.freeze({
23973
23500
  __proto__: null,
23974
23501
  createStream: createStream,
23975
23502
  updateStream: updateStream,
@@ -24256,7 +23783,7 @@ const getPoll = (pollId, callback) => {
24256
23783
  };
24257
23784
  /* end_public_function */
24258
23785
 
24259
- var index$3 = /*#__PURE__*/Object.freeze({
23786
+ var index$4 = /*#__PURE__*/Object.freeze({
24260
23787
  __proto__: null,
24261
23788
  createPoll: createPoll,
24262
23789
  closePoll: closePoll,
@@ -24627,7 +24154,7 @@ const getPlayer = async (parameters) => {
24627
24154
  return video;
24628
24155
  };
24629
24156
 
24630
- var index$2 = /*#__PURE__*/Object.freeze({
24157
+ var index$3 = /*#__PURE__*/Object.freeze({
24631
24158
  __proto__: null,
24632
24159
  getPlayer: getPlayer
24633
24160
  });
@@ -25800,7 +25327,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25800
25327
  };
25801
25328
  };
25802
25329
 
25803
- var index$1 = /*#__PURE__*/Object.freeze({
25330
+ var index$2 = /*#__PURE__*/Object.freeze({
25804
25331
  __proto__: null,
25805
25332
  createImageStory: createImageStory,
25806
25333
  createVideoStory: createVideoStory,
@@ -25837,7 +25364,7 @@ const getNetworkAds = async () => {
25837
25364
  };
25838
25365
  };
25839
25366
 
25840
- var index = /*#__PURE__*/Object.freeze({
25367
+ var index$1 = /*#__PURE__*/Object.freeze({
25841
25368
  __proto__: null,
25842
25369
  getNetworkAds: getNetworkAds
25843
25370
  });
@@ -25864,31 +25391,386 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25864
25391
  return { accessToken: data.accessToken };
25865
25392
  };
25866
25393
 
25394
+ /* begin_public_function
25395
+ id: notificationTray.getNotificationTraySeen
25396
+ */
25397
+ /**
25398
+ * ```js
25399
+ * import { notificationTray } from '@amityco/ts-sdk'
25400
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
25401
+ * ```
25402
+ *
25403
+ *
25404
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25405
+ *
25406
+ * @category NotificationTray API
25407
+ * @async
25408
+ * */
25409
+ const getNotificationTraySeen$1 = async () => {
25410
+ const client = getActiveClient();
25411
+ client.log('notificationTray/getNotificationTraySeen', {});
25412
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
25413
+ const cachedAt = client.cache && Date.now();
25414
+ if (client.cache) {
25415
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
25416
+ pushToCache(cacheKey, {
25417
+ userId: client.userId,
25418
+ lastTraySeenAt: payload.lastTraySeenAt,
25419
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25420
+ });
25421
+ }
25422
+ return {
25423
+ data: {
25424
+ userId: client.userId,
25425
+ lastTraySeenAt: payload.lastTraySeenAt,
25426
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
25427
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
25428
+ },
25429
+ cachedAt,
25430
+ };
25431
+ };
25432
+ /* end_public_function */
25433
+ /**
25434
+ * ```js
25435
+ * import { notificationTray } from '@amityco/ts-sdk'
25436
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
25437
+ * ```
25438
+ *
25439
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
25440
+ *
25441
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
25442
+ *
25443
+ * @category NotificationTray API
25444
+ * @async
25445
+ * */
25446
+ getNotificationTraySeen$1.locally = () => {
25447
+ var _a;
25448
+ const client = getActiveClient();
25449
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
25450
+ if (!client.cache)
25451
+ return;
25452
+ const queryKey = ['notificationTraySeen', 'get'];
25453
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
25454
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
25455
+ return;
25456
+ return { data: data.notificationTraySeen, cachedAt };
25457
+ };
25458
+
25459
+ /**
25460
+ * ```js
25461
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
25462
+ * const dispose = onNotificationTraySeenUpdated(data => {
25463
+ * // ...
25464
+ * })
25465
+ * ```
25466
+ *
25467
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
25468
+ *
25469
+ * @param callback The function to call when the event was fired
25470
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
25471
+ *
25472
+ * @category NotificationTraySeen Events
25473
+ */
25474
+ const onNotificationTraySeenUpdated = (callback) => {
25475
+ const client = getActiveClient();
25476
+ const disposers = [
25477
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
25478
+ ];
25479
+ return () => {
25480
+ disposers.forEach(fn => fn());
25481
+ };
25482
+ };
25483
+
25484
+ /* begin_public_function
25485
+ id: notificationTraySeen.get
25486
+ */
25487
+ /**
25488
+ * ```js
25489
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
25490
+ *
25491
+ * let notificationTraySeen;
25492
+ *
25493
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
25494
+ * notificationTraySeen = response.data;
25495
+ * });
25496
+ * ```
25497
+ *
25498
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
25499
+ *
25500
+ * @param userId the ID of the user to observe
25501
+ * @param callback the function to call when new data are available
25502
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
25503
+ *
25504
+ * @category NotificationTraySeen Live Object
25505
+ */
25506
+ const getNotificationTraySeen = (callback) => {
25507
+ const responder = (snapshot) => {
25508
+ const { data } = snapshot;
25509
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
25510
+ };
25511
+ const { userId } = getActiveUser();
25512
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
25513
+ onNotificationTraySeenUpdated,
25514
+ ]);
25515
+ };
25516
+ /* end_public_function */
25517
+
25518
+ /**
25519
+ * TODO: handle cache receive cache option, and cache policy
25520
+ * TODO: check if querybyIds is supported
25521
+ */
25522
+ class NotificationTrayItemsPaginationController extends PaginationController {
25523
+ async getRequest(queryParams, token) {
25524
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
25525
+ const options = token ? { token } : { limit };
25526
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
25527
+ params: Object.assign(Object.assign({}, params), { options }),
25528
+ });
25529
+ return queryResponse;
25530
+ }
25531
+ }
25532
+
25533
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
25534
+ constructor(query, cacheKey, notifyChange, preparePayload) {
25535
+ super(query, cacheKey);
25536
+ this.notifyChange = notifyChange;
25537
+ this.preparePayload = preparePayload;
25538
+ }
25539
+ async saveToMainDB(response) {
25540
+ const processedPayload = await this.preparePayload(response);
25541
+ const client = getActiveClient();
25542
+ const cachedAt = client.cache && Date.now();
25543
+ if (client.cache) {
25544
+ ingestInCache(processedPayload, { cachedAt });
25545
+ }
25546
+ }
25547
+ appendToQueryStream(response, direction, refresh = false) {
25548
+ var _a, _b;
25549
+ if (refresh) {
25550
+ pushToCache(this.cacheKey, {
25551
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25552
+ });
25553
+ }
25554
+ else {
25555
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25556
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
25557
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
25558
+ ...new Set([
25559
+ ...notifications,
25560
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
25561
+ ]),
25562
+ ] }));
25563
+ }
25564
+ }
25565
+ }
25566
+
25567
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
25568
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
25569
+ return Object.assign(Object.assign({}, rawPayload), { users });
25570
+ };
25571
+
25572
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
25573
+ constructor(query, callback) {
25574
+ const queryStreamId = hash__default["default"](query);
25575
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
25576
+ const paginationController = new NotificationTrayItemsPaginationController(query);
25577
+ super(paginationController, queryStreamId, cacheKey, callback);
25578
+ this.query = query;
25579
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
25580
+ this.callback = callback.bind(this);
25581
+ this.loadPage({ initial: true });
25582
+ }
25583
+ setup() {
25584
+ var _a;
25585
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25586
+ if (!collection) {
25587
+ pushToCache(this.cacheKey, {
25588
+ data: [],
25589
+ params: {},
25590
+ });
25591
+ }
25592
+ }
25593
+ async persistModel(queryPayload) {
25594
+ await this.queryStreamController.saveToMainDB(queryPayload);
25595
+ }
25596
+ persistQueryStream({ response, direction, refresh, }) {
25597
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
25598
+ }
25599
+ // eslint-disable-next-line class-methods-use-this
25600
+ startSubscription() {
25601
+ return [];
25602
+ }
25603
+ notifyChange({ origin, loading, error }) {
25604
+ var _a, _b;
25605
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
25606
+ if (!collection)
25607
+ return;
25608
+ const data = ((_b = collection.data
25609
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
25610
+ .filter(isNonNullable)
25611
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
25612
+ if (!this.shouldNotify(data) && origin === 'event')
25613
+ return;
25614
+ this.callback({
25615
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
25616
+ data,
25617
+ hasNextPage: !!this.paginationController.getNextToken(),
25618
+ loading,
25619
+ error,
25620
+ });
25621
+ }
25622
+ }
25623
+
25624
+ /**
25625
+ * Get notification tray items for a notification tray page
25626
+ *
25627
+ * @param params the limit query parameters
25628
+ * @param callback the callback to be called when the notification tray items are updated
25629
+ * @returns items in the notification tray
25630
+ *
25631
+ * @category Notification tray items Live Collection
25632
+ *
25633
+ */
25634
+ const getNotificationTrayItems = (params, callback, config) => {
25635
+ const { log, cache } = getActiveClient();
25636
+ if (!cache) {
25637
+ console.log(ENABLE_CACHE_MESSAGE);
25638
+ }
25639
+ const timestamp = Date.now();
25640
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
25641
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
25642
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
25643
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
25644
+ disposers.push(() => dropFromCache(cacheKey));
25645
+ return () => {
25646
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
25647
+ disposers.forEach(fn => fn());
25648
+ };
25649
+ };
25650
+
25651
+ /* begin_public_function
25652
+ id: notificationTrayItem.markSeen
25653
+ */
25654
+ /**
25655
+ * ```js
25656
+ * import { notificationTray } from '@amityco/ts-sdk'
25657
+ * const updated = await notificationTray.markItemsSeen()
25658
+ * ```
25659
+ *
25660
+ * Updates an {@link Amity.NotificationItemSeen}
25661
+ *
25662
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
25663
+ * @returns the updated {@link Amity.NotificationItemSeen} object
25664
+ *
25665
+ * @category NotificationItemSeen API
25666
+ * @async
25667
+ */
25668
+ const markItemsSeen = async (patch) => {
25669
+ const client = getActiveClient();
25670
+ client.log('notificationTray/markItemsSeen', {});
25671
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
25672
+ patch,
25673
+ });
25674
+ const updatedData = patch.trayItems
25675
+ .map(patchItem => {
25676
+ var _a;
25677
+ const cacheData = (_a = pullFromCache([
25678
+ 'notificationTraySeen',
25679
+ 'get',
25680
+ patchItem.id,
25681
+ ])) === null || _a === void 0 ? void 0 : _a.data;
25682
+ if (!cacheData)
25683
+ return;
25684
+ const data = Object.assign(Object.assign({}, cacheData), payload);
25685
+ if (client.cache) {
25686
+ const cachedAt = Date.now();
25687
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
25688
+ }
25689
+ return data;
25690
+ })
25691
+ .filter(Boolean);
25692
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
25693
+ };
25694
+ /* end_public_function */
25695
+
25696
+ /* begin_public_function
25697
+ id: notificationTray.markSeen
25698
+ */
25699
+ /**
25700
+ * ```js
25701
+ * import { notificationTray } from '@amityco/ts-sdk'
25702
+ * const updated = await notificationTray.markTraySeen({
25703
+ * lastSeenAt: Amity.timestamp,
25704
+ * })
25705
+ * ```
25706
+ *
25707
+ * Updates an {@link Amity.NotificationTraySeen}
25708
+ *
25709
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
25710
+ * @param lastSeenAt The patch data to apply
25711
+ * @returns the updated {@link Amity.NotificationTraySeen} object
25712
+ *
25713
+ * @category Post API
25714
+ * @async
25715
+ */
25716
+ const markTraySeen = async (lastSeenAt) => {
25717
+ var _a;
25718
+ const client = getActiveClient();
25719
+ client.log('notificationTray/markTraySeen', {});
25720
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
25721
+ lastSeenAt,
25722
+ });
25723
+ const cacheData = (_a = pullFromCache([
25724
+ 'notificationTraySeen',
25725
+ 'get',
25726
+ ])) === null || _a === void 0 ? void 0 : _a.data;
25727
+ const data = Object.assign({ userId: client.userId }, payload);
25728
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
25729
+ const cachedAt = client.cache && Date.now();
25730
+ if (client.cache)
25731
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
25732
+ fireEvent('local.notificationTraySeen.updated', data);
25733
+ return {
25734
+ data: payload,
25735
+ cachedAt,
25736
+ };
25737
+ };
25738
+ /* end_public_function */
25739
+
25740
+ var index = /*#__PURE__*/Object.freeze({
25741
+ __proto__: null,
25742
+ getNotificationTraySeen: getNotificationTraySeen,
25743
+ getNotificationTrayItems: getNotificationTrayItems,
25744
+ markItemsSeen: markItemsSeen,
25745
+ markTraySeen: markTraySeen,
25746
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
25747
+ });
25748
+
25867
25749
  exports.API_REGIONS = API_REGIONS;
25868
- exports.AdRepository = index;
25869
- exports.CategoryRepository = index$8;
25870
- exports.ChannelRepository = index$c;
25871
- exports.Client = index$l;
25872
- exports.CommentRepository = index$6;
25750
+ exports.AdRepository = index$1;
25751
+ exports.CategoryRepository = index$9;
25752
+ exports.ChannelRepository = index$d;
25753
+ exports.Client = index$m;
25754
+ exports.CommentRepository = index$7;
25873
25755
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25874
25756
  exports.CommunityPostSettings = CommunityPostSettings;
25875
- exports.CommunityRepository = index$9;
25757
+ exports.CommunityRepository = index$a;
25876
25758
  exports.ContentFeedType = ContentFeedType;
25877
25759
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25878
- exports.FeedRepository = index$7;
25879
- exports.FileRepository = index$i;
25760
+ exports.FeedRepository = index$8;
25761
+ exports.FileRepository = index$j;
25880
25762
  exports.FileType = FileType;
25881
- exports.LiveStreamPlayer = index$2;
25763
+ exports.LiveStreamPlayer = index$3;
25882
25764
  exports.MessageContentType = MessageContentType;
25883
- exports.MessageRepository = index$g;
25884
- exports.PollRepository = index$3;
25765
+ exports.MessageRepository = index$h;
25766
+ exports.PollRepository = index$4;
25885
25767
  exports.PostContentType = PostContentType;
25886
- exports.PostRepository = index$5;
25887
- exports.ReactionRepository = index$h;
25888
- exports.StoryRepository = index$1;
25889
- exports.StreamRepository = index$4;
25890
- exports.SubChannelRepository = index$f;
25891
- exports.UserRepository = index$j;
25768
+ exports.PostRepository = index$6;
25769
+ exports.ReactionRepository = index$i;
25770
+ exports.StoryRepository = index$2;
25771
+ exports.StreamRepository = index$5;
25772
+ exports.SubChannelRepository = index$g;
25773
+ exports.UserRepository = index$k;
25892
25774
  exports.VERSION = VERSION;
25893
25775
  exports.VideoResolution = VideoResolution;
25894
25776
  exports.VideoSize = VideoSize;
@@ -25941,6 +25823,7 @@ exports.isPaged = isPaged;
25941
25823
  exports.isReportedByMe = isReportedByMe;
25942
25824
  exports.isSkip = isSkip;
25943
25825
  exports.mergeInCache = mergeInCache;
25826
+ exports.notificationTray = index;
25944
25827
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
25945
25828
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
25946
25829
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;