@amityco/ts-sdk 7.1.1-e23f973a.0 → 7.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (152) hide show
  1. package/.env +26 -26
  2. package/dist/@types/core/events.d.ts +2 -5
  3. package/dist/@types/core/events.d.ts.map +1 -1
  4. package/dist/@types/core/model.d.ts +2 -4
  5. package/dist/@types/core/model.d.ts.map +1 -1
  6. package/dist/@types/core/payload.d.ts +0 -18
  7. package/dist/@types/core/payload.d.ts.map +1 -1
  8. package/dist/@types/core/readReceipt.d.ts +12 -1
  9. package/dist/@types/core/readReceipt.d.ts.map +1 -1
  10. package/dist/@types/domains/channel.d.ts +10 -0
  11. package/dist/@types/domains/channel.d.ts.map +1 -1
  12. package/dist/@types/domains/client.d.ts +2 -0
  13. package/dist/@types/domains/client.d.ts.map +1 -1
  14. package/dist/@types/index.d.ts +0 -1
  15. package/dist/@types/index.d.ts.map +1 -1
  16. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +16 -0
  17. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +1 -0
  18. package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
  19. package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
  20. package/dist/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
  21. package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
  22. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +11 -0
  23. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +1 -0
  24. package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
  25. package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
  26. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +20 -0
  27. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +1 -0
  28. package/dist/channelRepository/observers/index.d.ts +1 -0
  29. package/dist/channelRepository/observers/index.d.ts.map +1 -1
  30. package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
  31. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +2 -0
  32. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +1 -0
  33. package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
  34. package/dist/client/api/createClient.d.ts +1 -0
  35. package/dist/client/api/createClient.d.ts.map +1 -1
  36. package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
  37. package/dist/client/api/login.d.ts.map +1 -1
  38. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +33 -0
  39. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
  40. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +3 -0
  41. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
  42. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +2 -4
  43. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  44. package/dist/client/utils/endpoints.d.ts +1 -0
  45. package/dist/client/utils/endpoints.d.ts.map +1 -1
  46. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  47. package/dist/commentRepository/events/utils.d.ts.map +1 -1
  48. package/dist/core/events.d.ts +3 -3
  49. package/dist/core/events.d.ts.map +1 -1
  50. package/dist/core/model/idResolvers.d.ts.map +1 -1
  51. package/dist/core/model/index.d.ts.map +1 -1
  52. package/dist/index.cjs.js +657 -474
  53. package/dist/index.d.ts +0 -1
  54. package/dist/index.d.ts.map +1 -1
  55. package/dist/index.esm.js +639 -455
  56. package/dist/index.umd.js +4 -4
  57. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +12 -0
  58. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +1 -0
  59. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  60. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  61. package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
  62. package/dist/utils/linkedObject/index.d.ts +0 -1
  63. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  64. package/package.json +1 -1
  65. package/src/@types/core/events.ts +2 -6
  66. package/src/@types/core/model.ts +4 -6
  67. package/src/@types/core/payload.ts +0 -25
  68. package/src/@types/core/readReceipt.ts +14 -1
  69. package/src/@types/domains/channel.ts +13 -0
  70. package/src/@types/domains/client.ts +3 -0
  71. package/src/@types/index.ts +0 -1
  72. package/src/channelRepository/api/markChannelsAsReadBySegment.ts +29 -0
  73. package/src/channelRepository/events/onChannelDeleted.ts +17 -4
  74. package/src/channelRepository/events/onChannelLeft.ts +11 -3
  75. package/src/{marker → channelRepository}/events/onChannelUnreadUpdatedLocal.ts +3 -3
  76. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +38 -0
  77. package/src/channelRepository/observers/getChannel.ts +3 -1
  78. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -1
  79. package/src/channelRepository/observers/getTotalChannelsUnread.ts +129 -0
  80. package/src/channelRepository/observers/index.ts +1 -0
  81. package/src/channelRepository/utils/constructChannelDynamicValue.ts +12 -2
  82. package/src/channelRepository/utils/getLegacyChannelUnread.ts +5 -0
  83. package/src/channelRepository/utils/prepareChannelPayload.ts +68 -17
  84. package/src/client/api/createClient.ts +7 -1
  85. package/src/client/api/enableUnreadCount.ts +1 -0
  86. package/src/client/api/login.ts +5 -1
  87. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +267 -0
  88. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +21 -0
  89. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +74 -99
  90. package/src/client/utils/endpoints.ts +1 -0
  91. package/src/client/utils/setClientToken.ts +8 -0
  92. package/src/commentRepository/events/utils.ts +73 -0
  93. package/src/core/model/idResolvers.ts +2 -3
  94. package/src/core/model/index.ts +0 -2
  95. package/src/fileRepository/api/uploadFile.ts +1 -1
  96. package/src/fileRepository/api/uploadImage.ts +1 -1
  97. package/src/fileRepository/api/uploadVideo.ts +1 -1
  98. package/src/index.ts +0 -2
  99. package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +29 -0
  100. package/src/messageRepository/events/onMessageCreated.ts +45 -1
  101. package/src/messageRepository/observers/getMessage.ts +0 -1
  102. package/src/messageRepository/utils/markReadMessage.ts +10 -3
  103. package/src/utils/linkedObject/index.ts +0 -2
  104. package/dist/@types/domains/notification.d.ts +0 -82
  105. package/dist/@types/domains/notification.d.ts.map +0 -1
  106. package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
  107. package/dist/notificationTray/api/index.d.ts +0 -3
  108. package/dist/notificationTray/api/index.d.ts.map +0 -1
  109. package/dist/notificationTray/api/markItemsSeen.d.ts +0 -16
  110. package/dist/notificationTray/api/markItemsSeen.d.ts.map +0 -1
  111. package/dist/notificationTray/api/markTraySeen.d.ts +0 -19
  112. package/dist/notificationTray/api/markTraySeen.d.ts.map +0 -1
  113. package/dist/notificationTray/events/index.d.ts +0 -2
  114. package/dist/notificationTray/events/index.d.ts.map +0 -1
  115. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +0 -17
  116. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +0 -1
  117. package/dist/notificationTray/index.d.ts +0 -4
  118. package/dist/notificationTray/index.d.ts.map +0 -1
  119. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +0 -30
  120. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +0 -1
  121. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +0 -13
  122. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +0 -1
  123. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +0 -9
  124. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +0 -1
  125. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +0 -9
  126. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +0 -1
  127. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +0 -12
  128. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +0 -1
  129. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +0 -21
  130. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +0 -1
  131. package/dist/notificationTray/observers/index.d.ts +0 -3
  132. package/dist/notificationTray/observers/index.d.ts.map +0 -1
  133. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +0 -2
  134. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +0 -1
  135. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +0 -2
  136. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +0 -1
  137. package/src/@types/domains/notification.ts +0 -91
  138. package/src/notificationTray/api/index.ts +0 -2
  139. package/src/notificationTray/api/markItemsSeen.ts +0 -59
  140. package/src/notificationTray/api/markTraySeen.ts +0 -65
  141. package/src/notificationTray/events/index.ts +0 -1
  142. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +0 -36
  143. package/src/notificationTray/index.ts +0 -3
  144. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +0 -81
  145. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +0 -96
  146. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +0 -31
  147. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +0 -68
  148. package/src/notificationTray/observers/getNotificationTrayItems.ts +0 -44
  149. package/src/notificationTray/observers/getNotificationTraySeen.ts +0 -43
  150. package/src/notificationTray/observers/index.ts +0 -2
  151. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +0 -12
  152. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +0 -19
package/dist/index.cjs.js CHANGED
@@ -102,8 +102,8 @@ const PostContentType = Object.freeze({
102
102
 
103
103
  function getVersion() {
104
104
  try {
105
- // the string ''v7.1.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
- return 'v7.1.0-cjs';
105
+ // the string ''v7.2.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
106
+ return 'v7.2.0-cjs';
107
107
  }
108
108
  catch (error) {
109
109
  return '__dev__';
@@ -121,7 +121,6 @@ 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;
125
124
  const YEAR = 365 * DAY;
126
125
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
127
126
 
@@ -517,6 +516,7 @@ const idResolvers = {
517
516
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
518
517
  channelUnreadInfo: ({ channelId }) => channelId,
519
518
  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,8 +543,6 @@ 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,
548
546
  };
549
547
  /**
550
548
  * Retrieve the id resolver matching a domain name
@@ -596,7 +594,6 @@ const PAYLOAD2MODEL = {
596
594
  advertisers: 'advertiser',
597
595
  pinTargets: 'pinTarget',
598
596
  pins: 'pin',
599
- notificationTrayItems: 'notificationTrayItem',
600
597
  };
601
598
  /** hidden */
602
599
  const isOutdated = (prevData, nextData) => {
@@ -1565,6 +1562,7 @@ const API_REGIONS = {
1565
1562
  };
1566
1563
  const URLS = {
1567
1564
  http: 'https://apix.{region}.amity.co',
1565
+ upload: 'https://upload.{region}.amity.co',
1568
1566
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1569
1567
  };
1570
1568
  function computeUrl(type, region) {
@@ -1613,13 +1611,13 @@ class NetworkActivitiesWatcher {
1613
1611
  this._listener.clear();
1614
1612
  }
1615
1613
  }
1616
- let instance$5;
1614
+ let instance$6;
1617
1615
  var NetworkActivitiesWatcher$1 = {
1618
1616
  getInstance: () => {
1619
- if (!instance$5) {
1620
- instance$5 = new NetworkActivitiesWatcher();
1617
+ if (!instance$6) {
1618
+ instance$6 = new NetworkActivitiesWatcher();
1621
1619
  }
1622
- return instance$5;
1620
+ return instance$6;
1623
1621
  },
1624
1622
  };
1625
1623
 
@@ -5152,13 +5150,13 @@ class AnalyticsEngine {
5152
5150
  this._eventCapturer.resetAllBuckets();
5153
5151
  }
5154
5152
  }
5155
- let instance$4;
5153
+ let instance$5;
5156
5154
  var AnalyticsEngine$1 = {
5157
5155
  getInstance: () => {
5158
- if (!instance$4) {
5159
- instance$4 = new AnalyticsEngine();
5156
+ if (!instance$5) {
5157
+ instance$5 = new AnalyticsEngine();
5160
5158
  }
5161
- return instance$4;
5159
+ return instance$5;
5162
5160
  },
5163
5161
  };
5164
5162
 
@@ -5584,6 +5582,223 @@ const getMessageReadCount = (message, marker) => {
5584
5582
  getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
5585
5583
  }; // and if not found in cache use default value `0`
5586
5584
 
5585
+ /**
5586
+ *
5587
+ * Mark subChannel as read by readToSegment
5588
+ *
5589
+ * @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
5590
+ * @param readToSegment the segment to mark as read
5591
+ * @returns a success boolean if the {@link Amity.SubChannel} was updated
5592
+ *
5593
+ * @category Channel API
5594
+ * @async
5595
+ */
5596
+ const markChannelsAsReadBySegment = async (readings) => {
5597
+ const client = getActiveClient();
5598
+ try {
5599
+ await client.http.post('api/v3/channels/seen', { channels: readings });
5600
+ return true;
5601
+ }
5602
+ catch (e) {
5603
+ return false;
5604
+ }
5605
+ };
5606
+
5607
+ class MessageReadReceiptSyncEngine {
5608
+ constructor() {
5609
+ this.isActive = true;
5610
+ this.MAX_RETRY = 3;
5611
+ this.JOB_QUEUE_SIZE = 120;
5612
+ this.jobQueue = [];
5613
+ // Interval for message read receipt sync in seconds
5614
+ this.RECEIPT_SYNC_INTERVAL = 1;
5615
+ this.client = getActiveClient();
5616
+ // Get remaining unsync read receipts from cache
5617
+ this.getUnsyncJobs();
5618
+ }
5619
+ // Call this when client call client.login
5620
+ startSyncReadReceipt() {
5621
+ // Start timer when start receipt sync
5622
+ this.timer = setInterval(() => {
5623
+ this.syncReadReceipts();
5624
+ }, this.RECEIPT_SYNC_INTERVAL * 1000);
5625
+ }
5626
+ // Read receipt observer handling
5627
+ syncReadReceipts() {
5628
+ if (this.jobQueue.length === 0 || this.isActive === false)
5629
+ return;
5630
+ const readReceipts = this.getReadReceipts();
5631
+ if (readReceipts) {
5632
+ this.markReadApi(readReceipts);
5633
+ }
5634
+ }
5635
+ getUnsyncJobs() {
5636
+ var _a;
5637
+ // Get all read receipts that has latestSyncSegment < latestSegment
5638
+ const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5639
+ return data.latestSyncSegment < data.latestSegment;
5640
+ });
5641
+ // Enqueue unsync read receipts to the job queue
5642
+ readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
5643
+ this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
5644
+ });
5645
+ }
5646
+ getReadReceipts() {
5647
+ // get all read receipts from queue, now the queue is empty
5648
+ const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
5649
+ if (syncJob.length === 0)
5650
+ return;
5651
+ return syncJob.filter(job => {
5652
+ var _a;
5653
+ const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
5654
+ if (!readReceipt)
5655
+ return false;
5656
+ if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
5657
+ return true;
5658
+ return false;
5659
+ });
5660
+ }
5661
+ async markReadApi(syncJobs) {
5662
+ var _a;
5663
+ // constuct payload
5664
+ // example: [{ channelId: 'channelId', readToSegment: 2 }]
5665
+ const syncJobsPayload = syncJobs.map(job => {
5666
+ return {
5667
+ channelId: job.channelId,
5668
+ readToSegment: job.segment,
5669
+ };
5670
+ });
5671
+ const response = await markChannelsAsReadBySegment(syncJobsPayload);
5672
+ if (response) {
5673
+ for (let i = 0; i < syncJobs.length; i += 1) {
5674
+ // update lastestSyncSegment in read receipt cache
5675
+ const cacheKey = ['readReceipt', syncJobs[i].channelId];
5676
+ const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
5677
+ pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
5678
+ }
5679
+ }
5680
+ else {
5681
+ for (let i = 0; i < syncJobs.length; i += 1) {
5682
+ // push them back to queue if the syncing is failed and retry count is less than max retry
5683
+ if (syncJobs[i].retryCount >= this.MAX_RETRY)
5684
+ return;
5685
+ const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
5686
+ this.enqueueJob(updatedJob);
5687
+ }
5688
+ }
5689
+ }
5690
+ startObservingReadReceiptQueue() {
5691
+ if (this.client.useLegacyUnreadCount) {
5692
+ this.isActive = true;
5693
+ this.startSyncReadReceipt();
5694
+ }
5695
+ }
5696
+ stopObservingReadReceiptQueue() {
5697
+ this.isActive = false;
5698
+ this.jobQueue.map(job => {
5699
+ if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
5700
+ return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
5701
+ }
5702
+ return job;
5703
+ });
5704
+ if (this.timer)
5705
+ clearInterval(this.timer);
5706
+ }
5707
+ // Session Management
5708
+ onSessionEstablished() {
5709
+ this.startObservingReadReceiptQueue();
5710
+ }
5711
+ onSessionDestroyed() {
5712
+ this.stopObservingReadReceiptQueue();
5713
+ this.jobQueue = [];
5714
+ }
5715
+ onTokenExpired() {
5716
+ this.stopObservingReadReceiptQueue();
5717
+ }
5718
+ // Network Connection Management
5719
+ onNetworkOffline() {
5720
+ // Stop observing to the read receipt queue.
5721
+ this.stopObservingReadReceiptQueue();
5722
+ }
5723
+ onNetworkOnline() {
5724
+ // Resume observing to the read receipt queue.
5725
+ this.startObservingReadReceiptQueue();
5726
+ }
5727
+ markRead(channelId, segment) {
5728
+ var _a;
5729
+ // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
5730
+ const cacheKey = ['channelUnread', 'get', channelId];
5731
+ const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
5732
+ if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
5733
+ channelUnread &&
5734
+ segment > channelUnread.readToSegment) {
5735
+ channelUnread.readToSegment = segment;
5736
+ channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
5737
+ pushToCache(cacheKey, channelUnread);
5738
+ fireEvent('local.channelUnread.updated', channelUnread);
5739
+ }
5740
+ // Step 2: Enqueue the read receipt
5741
+ this.enqueueReadReceipt(channelId, segment);
5742
+ }
5743
+ enqueueReadReceipt(channelId, segment) {
5744
+ var _a;
5745
+ const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
5746
+ // Create new read receipt if it's not exists and add the job to queue
5747
+ if (!readReceipt) {
5748
+ const readReceiptChannel = {
5749
+ channelId,
5750
+ latestSegment: segment,
5751
+ latestSyncSegment: 0,
5752
+ };
5753
+ pushToCache(['readReceipt', channelId], readReceiptChannel);
5754
+ }
5755
+ else if (readReceipt.latestSegment < segment) {
5756
+ // Update latestSegment in read receipt cache
5757
+ pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
5758
+ }
5759
+ else if (readReceipt.latestSyncSegment >= segment) {
5760
+ // Skip the job when lastSyncSegment > = segment
5761
+ return;
5762
+ }
5763
+ let syncJob = this.getSyncJob(channelId);
5764
+ if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
5765
+ syncJob = {
5766
+ channelId,
5767
+ segment,
5768
+ syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
5769
+ retryCount: 0,
5770
+ };
5771
+ this.enqueueJob(syncJob);
5772
+ }
5773
+ else if (syncJob.segment < segment) {
5774
+ syncJob.segment = segment;
5775
+ }
5776
+ }
5777
+ getSyncJob(channelId) {
5778
+ const { jobQueue } = this;
5779
+ const targetJob = jobQueue.find(job => job.channelId === channelId);
5780
+ return targetJob || null;
5781
+ }
5782
+ enqueueJob(syncJob) {
5783
+ if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
5784
+ this.jobQueue.push(syncJob);
5785
+ }
5786
+ else {
5787
+ // Remove oldest job when queue reach maximum capacity
5788
+ this.jobQueue.shift();
5789
+ this.jobQueue.push(syncJob);
5790
+ }
5791
+ }
5792
+ }
5793
+ let instance$4 = null;
5794
+ var ReadReceiptSyncEngine = {
5795
+ getInstance: () => {
5796
+ if (!instance$4)
5797
+ instance$4 = new MessageReadReceiptSyncEngine();
5798
+ return instance$4;
5799
+ },
5800
+ };
5801
+
5587
5802
  /**
5588
5803
  *
5589
5804
  * Mark subChannel as read by readToSegment
@@ -5632,7 +5847,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
5632
5847
  return channelUnreadInfo;
5633
5848
  };
5634
5849
 
5635
- class MessageReadReceiptSyncEngine {
5850
+ class LegacyMessageReadReceiptSyncEngine {
5636
5851
  constructor() {
5637
5852
  this.isActive = true;
5638
5853
  this.MAX_RETRY = 3;
@@ -5663,7 +5878,7 @@ class MessageReadReceiptSyncEngine {
5663
5878
  getUnsyncJobs() {
5664
5879
  var _a;
5665
5880
  // Get all read receipts that has latestSyncSegment < latestSegment
5666
- const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5881
+ const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
5667
5882
  return data.latestSyncSegment < data.latestSegment;
5668
5883
  });
5669
5884
  // Enqueue unsync read receipts to the job queue
@@ -5682,7 +5897,7 @@ class MessageReadReceiptSyncEngine {
5682
5897
  return;
5683
5898
  // Get readReceipt from cache by subChannelId
5684
5899
  const readReceipt = (_a = pullFromCache([
5685
- 'readReceipt',
5900
+ 'legacyReadReceipt',
5686
5901
  syncJob.subChannelId,
5687
5902
  ])) === null || _a === void 0 ? void 0 : _a.data;
5688
5903
  if (!readReceipt)
@@ -5705,10 +5920,10 @@ class MessageReadReceiptSyncEngine {
5705
5920
  if (response) {
5706
5921
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
5707
5922
  const readReceiptCache = (_a = pullFromCache([
5708
- 'readReceipt',
5923
+ 'legacyReadReceipt',
5709
5924
  subChannelId,
5710
5925
  ])) === null || _a === void 0 ? void 0 : _a.data;
5711
- pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
5926
+ pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
5712
5927
  }
5713
5928
  else if (!response) {
5714
5929
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -5775,7 +5990,7 @@ class MessageReadReceiptSyncEngine {
5775
5990
  subChannelUnreadInfo.readToSegment = segment;
5776
5991
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
5777
5992
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
5778
- fireEvent('local.channelUnread.updated', channelUnreadInfo);
5993
+ fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
5779
5994
  pushToCache(cacheKey, subChannelUnreadInfo);
5780
5995
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
5781
5996
  }
@@ -5784,7 +5999,10 @@ class MessageReadReceiptSyncEngine {
5784
5999
  }
5785
6000
  enqueueReadReceipt(subChannelId, segment) {
5786
6001
  var _a;
5787
- const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
6002
+ const readReceipt = (_a = pullFromCache([
6003
+ 'legacyReadReceipt',
6004
+ subChannelId,
6005
+ ])) === null || _a === void 0 ? void 0 : _a.data;
5788
6006
  // Create new read receipt if it's not exists and add job to queue
5789
6007
  if (!readReceipt) {
5790
6008
  const readReceiptSubChannel = {
@@ -5792,10 +6010,10 @@ class MessageReadReceiptSyncEngine {
5792
6010
  latestSegment: segment,
5793
6011
  latestSyncSegment: 0,
5794
6012
  };
5795
- pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
6013
+ pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
5796
6014
  }
5797
6015
  else if (readReceipt.latestSegment < segment) {
5798
- pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
6016
+ pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
5799
6017
  }
5800
6018
  else if (readReceipt.latestSyncSegment >= segment) {
5801
6019
  // Skip the job when lastSyncSegment > = segment
@@ -5838,18 +6056,24 @@ class MessageReadReceiptSyncEngine {
5838
6056
  }
5839
6057
  }
5840
6058
  let instance$3 = null;
5841
- var ReadReceiptSyncEngine = {
6059
+ var LegacyReadReceiptSyncEngine = {
5842
6060
  getInstance: () => {
5843
6061
  if (!instance$3)
5844
- instance$3 = new MessageReadReceiptSyncEngine();
6062
+ instance$3 = new LegacyMessageReadReceiptSyncEngine();
5845
6063
  return instance$3;
5846
6064
  },
5847
6065
  };
5848
6066
 
5849
6067
  const markReadMessage = (message) => {
5850
- const { subChannelId, channelSegment } = message;
5851
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
5852
- markReadReceiptEngine.markRead(subChannelId, channelSegment);
6068
+ const client = getActiveClient();
6069
+ if (client.useLegacyUnreadCount) {
6070
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
6071
+ markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
6072
+ }
6073
+ else {
6074
+ const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
6075
+ markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
6076
+ }
5853
6077
  };
5854
6078
 
5855
6079
  const messageLinkedObject = (message) => {
@@ -5997,14 +6221,6 @@ const pinnedPostLinkedObject = (pinnedPost) => {
5997
6221
  } });
5998
6222
  };
5999
6223
 
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
-
6008
6224
  const LinkedObject = {
6009
6225
  ad: adLinkedObject,
6010
6226
  comment: commentLinkedObject,
@@ -6018,7 +6234,6 @@ const LinkedObject = {
6018
6234
  reactor: reactorLinkedObject,
6019
6235
  channel: channelLinkedObject,
6020
6236
  pinnedPost: pinnedPostLinkedObject,
6021
- notificationTray: notificationTrayLinkedObject,
6022
6237
  };
6023
6238
 
6024
6239
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -6846,6 +7061,32 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
6846
7061
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
6847
7062
  });
6848
7063
  };
7064
+ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
7065
+ for (let i = 0; i < channels.length; i += 1) {
7066
+ const cacheKey = ['channelUnread', 'get', channels[i].channelId];
7067
+ const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
7068
+ let unreadCount = 0;
7069
+ let readToSegment = null;
7070
+ let lastMentionedSegment = null;
7071
+ let isMentioned = false;
7072
+ if (channelUser) {
7073
+ readToSegment = channelUser.readToSegment;
7074
+ lastMentionedSegment = channelUser.lastMentionedSegment;
7075
+ unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
7076
+ isMentioned = lastMentionedSegment > readToSegment;
7077
+ }
7078
+ const cacheChannelUnread = {
7079
+ channelId: channels[i].channelId,
7080
+ lastSegment: channels[i].messageCount,
7081
+ readToSegment,
7082
+ lastMentionedSegment,
7083
+ unreadCount,
7084
+ isMentioned,
7085
+ isDeleted: channels[i].isDeleted || false,
7086
+ };
7087
+ pushToCache(cacheKey, cacheChannelUnread);
7088
+ }
7089
+ };
6849
7090
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
6850
7091
  const client = getActiveClient();
6851
7092
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -6855,23 +7096,34 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
6855
7096
  rawPayload.messagePreviews.length > 0) {
6856
7097
  updateChannelMessagePreviewCache(rawPayload);
6857
7098
  }
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)
7099
+ if (client.useLegacyUnreadCount) {
7100
+ updateChannelUnread({
7101
+ channels: rawPayload.channels,
7102
+ channelUsers: rawPayload.channelUsers,
7103
+ currentUserId: client.userId,
7104
+ });
7105
+ }
7106
+ else {
7107
+ const markerIds = rawPayload.channels
7108
+ // filter channel by type. Only conversation, community and broadcast type are included.
7109
+ .filter(isUnreadCountSupport)
7110
+ .map(({ channelInternalId }) => channelInternalId);
7111
+ if (markerIds.length > 0) {
7112
+ // since the get markers method requires a channel cache to function with the reducer.
7113
+ preUpdateChannelCache(rawPayload, {
7114
+ isMessagePreviewUpdated: options.isMessagePreviewUpdated,
7115
+ });
7116
+ try {
7117
+ await getChannelMarkers(markerIds);
7118
+ }
7119
+ catch (e) {
7120
+ // empty block (from the spec, allow marker fetch to fail without having to do anything)
7121
+ }
6870
7122
  }
6871
7123
  }
6872
- // attach marker to channel
7124
+ // convert raw channel to internal channel
6873
7125
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
6874
- // user marker to channel users
7126
+ // convert raw channel user to membership (add user object)
6875
7127
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
6876
7128
  return convertRawMembershipToMembership(channelUser);
6877
7129
  });
@@ -6998,15 +7250,28 @@ const getSubChannelsUnreadCount = (channel, marker) => {
6998
7250
  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;
6999
7251
  };
7000
7252
 
7253
+ const getLegacyChannelUnread = (channelId) => {
7254
+ var _a;
7255
+ return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
7256
+ };
7257
+
7001
7258
  const constructChannelDynamicValue = (channel) => {
7259
+ const client = getActiveClient();
7002
7260
  const rest = __rest(channel, ["messageCount"]);
7003
7261
  return shallowClone(rest, {
7004
- get isMentioned() {
7005
- return getChannelIsMentioned(rest);
7262
+ get unreadCount() {
7263
+ var _a, _b;
7264
+ return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
7006
7265
  },
7007
7266
  get subChannelsUnreadCount() {
7008
7267
  return getSubChannelsUnreadCount(rest);
7009
7268
  },
7269
+ get isMentioned() {
7270
+ var _a, _b;
7271
+ if (client.useLegacyUnreadCount)
7272
+ return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
7273
+ return getChannelIsMentioned(rest);
7274
+ },
7010
7275
  });
7011
7276
  };
7012
7277
 
@@ -7619,6 +7884,12 @@ const setClientToken = async (params) => {
7619
7884
  isGlobalBanned: false,
7620
7885
  isUserDeleted: false,
7621
7886
  };
7887
+ client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
7888
+ client.upload.defaults.metadata = {
7889
+ tokenExpiry: expiresAt,
7890
+ isGlobalBanned: false,
7891
+ isUserDeleted: false,
7892
+ };
7622
7893
  // manually setup the token for ws transport
7623
7894
  if (client.ws)
7624
7895
  client.ws.io.opts.query = { token: accessToken };
@@ -7663,12 +7934,21 @@ const onChannelDeleted = (callback) => {
7663
7934
  const client = getActiveClient();
7664
7935
  const filter = async (payload) => {
7665
7936
  const data = await prepareChannelPayload(payload);
7666
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
7667
- data.channels.forEach(channel => {
7937
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
7938
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
7939
+ data.channels.forEach(channel => {
7940
+ if (isConsistentMode) {
7668
7941
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
7669
7942
  deleteChannelUnreadByChannelId(channel.channelId);
7670
- });
7671
- }
7943
+ }
7944
+ else if (isLegacyUnreadCount) {
7945
+ const cacheKey = ['channelUnread', 'get', channel.channelId];
7946
+ const cache = pullFromCache(cacheKey);
7947
+ if (cache) {
7948
+ pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
7949
+ }
7950
+ }
7951
+ });
7672
7952
  ingestInCache(data);
7673
7953
  callbacks$b.forEach(cb => cb(data.channels[0]));
7674
7954
  };
@@ -7782,6 +8062,25 @@ var readReceiptSyncEngineOnLoginHandler = () => {
7782
8062
  };
7783
8063
  };
7784
8064
 
8065
+ var legacyReadReceiptSyncEngineOnLoginHandler = () => {
8066
+ const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
8067
+ readReceiptSyncEngine.startSyncReadReceipt();
8068
+ onSessionStateChange(state => {
8069
+ if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
8070
+ readReceiptSyncEngine.onSessionEstablished();
8071
+ }
8072
+ else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
8073
+ readReceiptSyncEngine.onTokenExpired();
8074
+ }
8075
+ else {
8076
+ readReceiptSyncEngine.onSessionDestroyed();
8077
+ }
8078
+ });
8079
+ return () => {
8080
+ readReceiptSyncEngine.onSessionDestroyed();
8081
+ };
8082
+ };
8083
+
7785
8084
  const onOnline = (callback) => {
7786
8085
  if (typeof window !== 'undefined' && window.addEventListener) {
7787
8086
  window.addEventListener('online', callback);
@@ -8348,10 +8647,17 @@ const onChannelLeft = (callback) => {
8348
8647
  const preparedPayload = await prepareChannelPayload(payload, {
8349
8648
  isMessagePreviewUpdated: isLeftByMe,
8350
8649
  });
8351
- if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
8650
+ const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
8651
+ const isLegacyUnreadCount = client.useLegacyUnreadCount;
8652
+ if (isLeftByMe) {
8352
8653
  preparedPayload.channels.forEach(channel => {
8353
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
8354
- deleteChannelUnreadByChannelId(channel.channelId);
8654
+ if (isConsistentMode) {
8655
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
8656
+ deleteChannelUnreadByChannelId(channel.channelId);
8657
+ }
8658
+ else if (isLegacyUnreadCount) {
8659
+ dropFromCache(['channelUnread', 'get', channel.channelId]);
8660
+ }
8355
8661
  });
8356
8662
  }
8357
8663
  const { channels, channelUsers } = preparedPayload;
@@ -8619,6 +8925,34 @@ const onMessageCreatedMqtt = (callback) => {
8619
8925
  reCalculateChannelUnreadInfo(message.channelId);
8620
8926
  });
8621
8927
  }
8928
+ if (client.useLegacyUnreadCount) {
8929
+ rawPayload.messages.forEach(message => {
8930
+ var _a, _b;
8931
+ const channelUnread = (_a = pullFromCache([
8932
+ 'channelUnread',
8933
+ 'get',
8934
+ message.channelId,
8935
+ ])) === null || _a === void 0 ? void 0 : _a.data;
8936
+ if (!channelUnread ||
8937
+ channelUnread.lastSegment >= message.segment ||
8938
+ typeof channelUnread.readToSegment !== 'number' ||
8939
+ typeof channelUnread.lastMentionedSegment !== 'number')
8940
+ return;
8941
+ const lastSegment = message.segment;
8942
+ const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
8943
+ return (mention.type === 'channel' ||
8944
+ (mention.type === 'user' &&
8945
+ client.userId &&
8946
+ mention.userPublicIds.includes(client.userId)));
8947
+ });
8948
+ const lastMentionedSegment = isMentionedInMessage
8949
+ ? message.segment
8950
+ : channelUnread.lastMentionedSegment;
8951
+ const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
8952
+ pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
8953
+ fireEvent('local.channelUnread.updated', updatedChannelUnread);
8954
+ });
8955
+ }
8622
8956
  // Update in cache
8623
8957
  ingestInCache(payload);
8624
8958
  payload.messages.forEach(message => {
@@ -8794,6 +9128,7 @@ const enableUnreadCount = () => {
8794
9128
  if (client.isUnreadCountEnabled)
8795
9129
  return false;
8796
9130
  client.isUnreadCountEnabled = true;
9131
+ client.useLegacyUnreadCount = false;
8797
9132
  client.emitter.emit('unreadCountEnabled', true);
8798
9133
  return true;
8799
9134
  };
@@ -9109,7 +9444,12 @@ const login = async (params, sessionHandler, config) => {
9109
9444
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
9110
9445
  // the channel because currently backend can't handle this, so every time a user is banned from
9111
9446
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
9112
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
9447
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
9448
+ if (client.useLegacyUnreadCount) {
9449
+ subscriptions.push(readReceiptSyncEngineOnLoginHandler());
9450
+ }
9451
+ else
9452
+ subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
9113
9453
  const markerSyncUnsubscriber = await startMarkerSync();
9114
9454
  subscriptions.push(markerSyncUnsubscriber);
9115
9455
  }
@@ -9267,15 +9607,17 @@ const DEFAULT_DEBUG_SESSION = 'amity';
9267
9607
  * @category Client API
9268
9608
  * */
9269
9609
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
9270
- var _a, _b;
9610
+ var _a, _b, _c;
9271
9611
  const log = createLogger(debugSession);
9272
9612
  log('client/api/createClient', {
9273
9613
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
9274
9614
  apiRegion,
9275
9615
  });
9276
9616
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
9277
- const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
9617
+ const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
9618
+ const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
9278
9619
  const http = createHttpTransport(httpEndpoint);
9620
+ const upload = createHttpTransport(uploadEndpoint);
9279
9621
  let ws;
9280
9622
  let mqtt;
9281
9623
  if (rteEnabled) {
@@ -9290,6 +9632,8 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9290
9632
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
9291
9633
  const sessionHandler = undefined;
9292
9634
  const isUnreadCountEnabled = false;
9635
+ // Legacy unread count is true by default
9636
+ const useLegacyUnreadCount = true;
9293
9637
  const client = {
9294
9638
  version: `${VERSION}`,
9295
9639
  apiKey,
@@ -9304,6 +9648,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9304
9648
  http,
9305
9649
  ws,
9306
9650
  mqtt,
9651
+ upload,
9307
9652
  emitter,
9308
9653
  /*
9309
9654
  * Session Components
@@ -9319,6 +9664,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9319
9664
  getMessagePreviewSetting,
9320
9665
  use: () => setActiveClient(client),
9321
9666
  isUnreadCountEnabled,
9667
+ useLegacyUnreadCount,
9322
9668
  getMarkerSyncConsistentMode,
9323
9669
  /**
9324
9670
  * Prefix for the deviceId key in the local storage or async storage.
@@ -9332,7 +9678,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
9332
9678
  return activeClient;
9333
9679
  setActiveClient(client);
9334
9680
  }
9335
- catch (_c) {
9681
+ catch (_d) {
9336
9682
  setActiveClient(client);
9337
9683
  }
9338
9684
  return client;
@@ -9789,7 +10135,7 @@ const getUserUnread = (callback) => {
9789
10135
  };
9790
10136
  };
9791
10137
 
9792
- var index$m = /*#__PURE__*/Object.freeze({
10138
+ var index$l = /*#__PURE__*/Object.freeze({
9793
10139
  __proto__: null,
9794
10140
  getActiveClient: getActiveClient,
9795
10141
  getActiveUser: getActiveUser,
@@ -10996,7 +11342,7 @@ const getMyFollowInfo = (callback) => {
10996
11342
  };
10997
11343
  /* end_public_function */
10998
11344
 
10999
- var index$l = /*#__PURE__*/Object.freeze({
11345
+ var index$k = /*#__PURE__*/Object.freeze({
11000
11346
  __proto__: null,
11001
11347
  blockUser: blockUser,
11002
11348
  unBlockUser: unBlockUser,
@@ -12011,9 +12357,9 @@ var AmityUserSearchMatchType;
12011
12357
  AmityUserSearchMatchType["PARTIAL"] = "partial";
12012
12358
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
12013
12359
 
12014
- var index$k = /*#__PURE__*/Object.freeze({
12360
+ var index$j = /*#__PURE__*/Object.freeze({
12015
12361
  __proto__: null,
12016
- Relationship: index$l,
12362
+ Relationship: index$k,
12017
12363
  getUserByIds: getUserByIds,
12018
12364
  updateUser: updateUser,
12019
12365
  flagUser: flagUser,
@@ -12121,7 +12467,7 @@ const uploadFile = async (formData, onProgress) => {
12121
12467
  const headers = 'getHeaders' in formData
12122
12468
  ? formData.getHeaders()
12123
12469
  : { 'content-type': 'multipart/form-data' };
12124
- const { data } = await client.http.post('/api/v4/files', formData, {
12470
+ const { data } = await client.upload.post('/api/v4/files', formData, {
12125
12471
  headers,
12126
12472
  onUploadProgress({ loaded, total = 100 }) {
12127
12473
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12211,7 +12557,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
12211
12557
  const headers = 'getHeaders' in formData
12212
12558
  ? formData.getHeaders()
12213
12559
  : { 'content-type': 'multipart/form-data' };
12214
- const { data } = await client.http.post('/api/v4/videos', formData, {
12560
+ const { data } = await client.upload.post('/api/v4/videos', formData, {
12215
12561
  headers,
12216
12562
  onUploadProgress({ loaded, total = 100 }) {
12217
12563
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12259,7 +12605,7 @@ const uploadImage = async (formData, onProgress) => {
12259
12605
  const headers = 'getHeaders' in formData
12260
12606
  ? formData.getHeaders()
12261
12607
  : { 'content-type': 'multipart/form-data' };
12262
- const { data } = await client.http.post('/api/v4/images', formData, {
12608
+ const { data } = await client.upload.post('/api/v4/images', formData, {
12263
12609
  headers,
12264
12610
  onUploadProgress({ loaded, total = 100 }) {
12265
12611
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -12277,7 +12623,7 @@ const uploadImage = async (formData, onProgress) => {
12277
12623
  };
12278
12624
  /* end_public_function */
12279
12625
 
12280
- var index$j = /*#__PURE__*/Object.freeze({
12626
+ var index$i = /*#__PURE__*/Object.freeze({
12281
12627
  __proto__: null,
12282
12628
  getFile: getFile,
12283
12629
  uploadFile: uploadFile,
@@ -13344,8 +13690,31 @@ const createCommentEventSubscriber = (event, callback) => {
13344
13690
  }
13345
13691
  }
13346
13692
  }
13347
- const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13348
- queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13693
+ }
13694
+ if (['comment.deleted'].includes(event)) {
13695
+ // NOTE: skip deleting comment to parent comment children if it's the same user since we use the local event to update instead.
13696
+ if (event === 'comment.deleted' && comment.data.userId === client.userId)
13697
+ return;
13698
+ if (comments[0].parentId) {
13699
+ const parentComment = pullFromCache([
13700
+ 'comment',
13701
+ 'get',
13702
+ comments[0].parentId,
13703
+ ]);
13704
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
13705
+ // Remove deleted comment in parent childComment if still exists
13706
+ if (parentComment.data.children.includes(comments[0].commentId)) {
13707
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
13708
+ ...new Set([
13709
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
13710
+ ]),
13711
+ ] });
13712
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
13713
+ }
13714
+ }
13715
+ }
13716
+ const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13717
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13349
13718
  }
13350
13719
  callback(LinkedObject.comment(comment.data));
13351
13720
  }
@@ -13356,7 +13725,7 @@ const createCommentEventSubscriber = (event, callback) => {
13356
13725
  const createLocalCommentEventSubscriber = (event, callback) => {
13357
13726
  const client = getActiveClient();
13358
13727
  const filter = (payload) => {
13359
- var _a;
13728
+ var _a, _b;
13360
13729
  if (!client.cache) {
13361
13730
  // TODO: here we are missing specific properties here!
13362
13731
  callback(LinkedObject.comment(payload.comments[0]));
@@ -13399,6 +13768,38 @@ const createLocalCommentEventSubscriber = (event, callback) => {
13399
13768
  const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13400
13769
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13401
13770
  }
13771
+ if (['local.comment.deleted'].includes(event)) {
13772
+ if (comments[0].parentId) {
13773
+ const parentComment = pullFromCache([
13774
+ 'comment',
13775
+ 'get',
13776
+ comments[0].parentId,
13777
+ ]);
13778
+ if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
13779
+ // Remove deleted comment in parent childComment if still exists
13780
+ if (parentComment.data.children.includes(comments[0].commentId)) {
13781
+ const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
13782
+ ...new Set([
13783
+ ...parentComment.data.children.filter(id => id !== comments[0].commentId),
13784
+ ]),
13785
+ ] });
13786
+ pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
13787
+ setTimeout(() => {
13788
+ // NOTE: This is workaround solution for emitting event not work properly.
13789
+ fireEvent('comment.updated', {
13790
+ comments: [newParentComment],
13791
+ commentChildren: [],
13792
+ files: [],
13793
+ users: [],
13794
+ communityUsers: [],
13795
+ });
13796
+ }, 200);
13797
+ }
13798
+ }
13799
+ }
13800
+ const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
13801
+ queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
13802
+ }
13402
13803
  callback(LinkedObject.comment(comment.data));
13403
13804
  }
13404
13805
  }
@@ -14089,7 +14490,7 @@ const getReactions = (params, callback, config) => {
14089
14490
  };
14090
14491
  /* end_public_function */
14091
14492
 
14092
- var index$i = /*#__PURE__*/Object.freeze({
14493
+ var index$h = /*#__PURE__*/Object.freeze({
14093
14494
  __proto__: null,
14094
14495
  addReaction: addReaction,
14095
14496
  removeReaction: removeReaction,
@@ -15905,7 +16306,7 @@ const getMessages = (params, callback, config) => {
15905
16306
  };
15906
16307
  /* end_public_function */
15907
16308
 
15908
- var index$h = /*#__PURE__*/Object.freeze({
16309
+ var index$g = /*#__PURE__*/Object.freeze({
15909
16310
  __proto__: null,
15910
16311
  createMessage: createMessage,
15911
16312
  updateMessage: updateMessage,
@@ -16431,7 +16832,7 @@ const stopMessageReceiptSync = (subChannelId) => {
16431
16832
  };
16432
16833
  /* end_public_function */
16433
16834
 
16434
- var index$g = /*#__PURE__*/Object.freeze({
16835
+ var index$f = /*#__PURE__*/Object.freeze({
16435
16836
  __proto__: null,
16436
16837
  getSubChannelByIds: getSubChannels$1,
16437
16838
  createSubChannel: createSubChannel,
@@ -16452,19 +16853,37 @@ var index$g = /*#__PURE__*/Object.freeze({
16452
16853
  /**
16453
16854
  * Internal used only
16454
16855
  *
16455
- * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
16856
+ * Fired when an {@link Amity.channelUnreadInfo} has been updated.
16456
16857
  *
16457
16858
  * @param callback The function to call when the event was fired
16458
16859
  * @returns an {@link Amity.Unsubscriber} function to stop listening
16459
16860
  *
16460
- * @category MessageMarker Events
16861
+ * @category ChannelMarker Events
16862
+ */
16863
+ const onChannelUnreadInfoUpdatedLocal = (callback) => {
16864
+ const client = getActiveClient();
16865
+ const filter = (payload) => {
16866
+ callback(payload);
16867
+ };
16868
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
16869
+ };
16870
+
16871
+ /**
16872
+ * Internal used only
16873
+ *
16874
+ * Fired when an {@link Amity.ChannelUnread} has been updated.
16875
+ *
16876
+ * @param callback The function to call when the event was fired
16877
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
16878
+ *
16879
+ * @category Channel Events
16461
16880
  */
16462
16881
  const onChannelUnreadUpdatedLocal = (callback) => {
16463
16882
  const client = getActiveClient();
16464
16883
  const filter = (payload) => {
16465
16884
  callback(payload);
16466
16885
  };
16467
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
16886
+ return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
16468
16887
  };
16469
16888
 
16470
16889
  /* begin_public_function
@@ -16666,6 +17085,7 @@ const getChannel = (channelId, callback) => {
16666
17085
  return onSubChannelUpdated(updateMessagePreview);
16667
17086
  }, 'channelId', 'channel'),
16668
17087
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
17088
+ convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
16669
17089
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
16670
17090
  ], {
16671
17091
  forceDispatch: true,
@@ -17179,6 +17599,10 @@ class ChannelLiveCollectionController extends LiveCollectionController {
17179
17599
  },
17180
17600
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
17181
17601
  },
17602
+ {
17603
+ fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
17604
+ action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
17605
+ },
17182
17606
  {
17183
17607
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
17184
17608
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -17244,6 +17668,120 @@ const getChannels = (params, callback, config) => {
17244
17668
  };
17245
17669
  /* end_public_function */
17246
17670
 
17671
+ /**
17672
+ *
17673
+ * Calculate user unread from {@link Amity.ChannelUnread} objects
17674
+ *
17675
+ * @returns the {@link Amity.UserUnread} objects
17676
+ *
17677
+ * @category Channel API
17678
+ * @async
17679
+ */
17680
+ const getTotalChannelsUnread$1 = () => {
17681
+ var _a;
17682
+ const client = getActiveClient();
17683
+ client.log('channel/getTotalChannelsUnread.locally');
17684
+ const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
17685
+ return !data.isDeleted;
17686
+ })) || [];
17687
+ const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
17688
+ acc.unreadCount += data.unreadCount;
17689
+ acc.isMentioned = acc.isMentioned || data.isMentioned;
17690
+ return acc;
17691
+ }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
17692
+ const cachedAt = client.cache && Date.now();
17693
+ return {
17694
+ data: totalChannelsUnread,
17695
+ cachedAt,
17696
+ };
17697
+ };
17698
+
17699
+ /* begin_public_function
17700
+ id: totalChannelsUnread.get
17701
+ */
17702
+ /**
17703
+ * ```js
17704
+ * import { ChannelRepository } from '@amityco/ts-sdk';
17705
+ *
17706
+ * let totalChannelsUnread;
17707
+ *
17708
+ * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
17709
+ * unread = response.data;
17710
+ * });
17711
+ * ```
17712
+ *
17713
+ * Observe all mutation on a given {@link Amity.UserUnread}
17714
+ *
17715
+ * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
17716
+ *
17717
+ * @category User Unread Live Object
17718
+ *
17719
+ */
17720
+ const getTotalChannelsUnread = (callback) => {
17721
+ const { _id: userId } = getActiveUser();
17722
+ if (!userId)
17723
+ throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
17724
+ const { log, cache } = getActiveClient();
17725
+ if (!cache) {
17726
+ console.log('For using Live Object feature you need to enable Cache!');
17727
+ }
17728
+ const timestamp = Date.now();
17729
+ log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
17730
+ const disposers = [];
17731
+ let isUnsyncedModel = false; // for messages
17732
+ let model;
17733
+ const dispatcher = (data) => {
17734
+ const { data: userUnread } = data;
17735
+ const callbackModel = userUnread
17736
+ ? {
17737
+ unreadCount: userUnread.unreadCount,
17738
+ isMentioned: userUnread.isMentioned,
17739
+ }
17740
+ : undefined;
17741
+ model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
17742
+ callback({
17743
+ data: callbackModel
17744
+ ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
17745
+ loading: data.loading,
17746
+ error: data.error,
17747
+ });
17748
+ };
17749
+ const realtimeRouter = (userUnread) => {
17750
+ if (isEqual(model, userUnread))
17751
+ return;
17752
+ dispatcher({
17753
+ loading: false,
17754
+ data: userUnread,
17755
+ });
17756
+ };
17757
+ const onFetch = () => {
17758
+ const query = createQuery(async () => getTotalChannelsUnread$1());
17759
+ runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
17760
+ if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
17761
+ dispatcher({
17762
+ data,
17763
+ origin,
17764
+ loading: false,
17765
+ error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
17766
+ });
17767
+ isUnsyncedModel = true;
17768
+ disposers.forEach(fn => fn());
17769
+ }
17770
+ else if (!isUnsyncedModel) {
17771
+ dispatcher({ loading, data, origin, error });
17772
+ }
17773
+ if (error) {
17774
+ disposers.forEach(fn => fn());
17775
+ }
17776
+ });
17777
+ };
17778
+ disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
17779
+ onFetch();
17780
+ return () => {
17781
+ disposers.forEach(fn => fn());
17782
+ };
17783
+ };
17784
+
17247
17785
  /* begin_public_function
17248
17786
  id: channel.member.add
17249
17787
  */
@@ -17608,7 +18146,7 @@ const searchMembers$1 = (params, callback, config) => {
17608
18146
  };
17609
18147
  /* end_public_function */
17610
18148
 
17611
- var index$f = /*#__PURE__*/Object.freeze({
18149
+ var index$e = /*#__PURE__*/Object.freeze({
17612
18150
  __proto__: null,
17613
18151
  addMembers: addMembers$1,
17614
18152
  removeMembers: removeMembers$1,
@@ -17811,7 +18349,7 @@ const unmuteMembers = async (channelId, userIds) => {
17811
18349
  };
17812
18350
  /* end_public_function */
17813
18351
 
17814
- var index$e = /*#__PURE__*/Object.freeze({
18352
+ var index$d = /*#__PURE__*/Object.freeze({
17815
18353
  __proto__: null,
17816
18354
  addRole: addRole,
17817
18355
  removeRole: removeRole,
@@ -17821,10 +18359,10 @@ var index$e = /*#__PURE__*/Object.freeze({
17821
18359
  unmuteMembers: unmuteMembers
17822
18360
  });
17823
18361
 
17824
- var index$d = /*#__PURE__*/Object.freeze({
18362
+ var index$c = /*#__PURE__*/Object.freeze({
17825
18363
  __proto__: null,
17826
- Membership: index$f,
17827
- Moderation: index$e,
18364
+ Membership: index$e,
18365
+ Moderation: index$d,
17828
18366
  getChannelByIds: getChannelByIds$1,
17829
18367
  createChannel: createChannel,
17830
18368
  updateChannel: updateChannel,
@@ -17847,6 +18385,7 @@ var index$d = /*#__PURE__*/Object.freeze({
17847
18385
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
17848
18386
  getChannel: getChannel,
17849
18387
  getChannels: getChannels,
18388
+ getTotalChannelsUnread: getTotalChannelsUnread,
17850
18389
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
17851
18390
  isUnreadCountSupport: isUnreadCountSupport,
17852
18391
  convertFromRaw: convertFromRaw,
@@ -19203,7 +19742,7 @@ const searchMembers = (params, callback, config) => {
19203
19742
  };
19204
19743
  /* end_public_function */
19205
19744
 
19206
- var index$c = /*#__PURE__*/Object.freeze({
19745
+ var index$b = /*#__PURE__*/Object.freeze({
19207
19746
  __proto__: null,
19208
19747
  addMembers: addMembers,
19209
19748
  removeMembers: removeMembers,
@@ -20228,7 +20767,7 @@ const unbanMembers = async (communityId, userIds) => {
20228
20767
  };
20229
20768
  /* end_public_function */
20230
20769
 
20231
- var index$b = /*#__PURE__*/Object.freeze({
20770
+ var index$a = /*#__PURE__*/Object.freeze({
20232
20771
  __proto__: null,
20233
20772
  addRoles: addRoles,
20234
20773
  removeRoles: removeRoles,
@@ -20236,10 +20775,10 @@ var index$b = /*#__PURE__*/Object.freeze({
20236
20775
  unbanMembers: unbanMembers
20237
20776
  });
20238
20777
 
20239
- var index$a = /*#__PURE__*/Object.freeze({
20778
+ var index$9 = /*#__PURE__*/Object.freeze({
20240
20779
  __proto__: null,
20241
- Moderation: index$b,
20242
- Membership: index$c,
20780
+ Moderation: index$a,
20781
+ Membership: index$b,
20243
20782
  getCommunityByIds: getCommunities$1,
20244
20783
  createCommunity: createCommunity,
20245
20784
  updateCommunity: updateCommunity,
@@ -20472,7 +21011,7 @@ const getCategories = (params, callback, config) => {
20472
21011
  };
20473
21012
  /* end_public_function */
20474
21013
 
20475
- var index$9 = /*#__PURE__*/Object.freeze({
21014
+ var index$8 = /*#__PURE__*/Object.freeze({
20476
21015
  __proto__: null,
20477
21016
  getCategory: getCategory,
20478
21017
  getCategories: getCategories
@@ -20640,7 +21179,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
20640
21179
  : undefined;
20641
21180
  };
20642
21181
 
20643
- var index$8 = /*#__PURE__*/Object.freeze({
21182
+ var index$7 = /*#__PURE__*/Object.freeze({
20644
21183
  __proto__: null,
20645
21184
  queryGlobalFeed: queryGlobalFeed,
20646
21185
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -21955,7 +22494,7 @@ const getComments = (params, callback, config) => {
21955
22494
  };
21956
22495
  /* end_public_function */
21957
22496
 
21958
- var index$7 = /*#__PURE__*/Object.freeze({
22497
+ var index$6 = /*#__PURE__*/Object.freeze({
21959
22498
  __proto__: null,
21960
22499
  getCommentByIds: getCommentByIds,
21961
22500
  createComment: createComment,
@@ -22962,7 +23501,7 @@ const semanticSearchPosts = (params, callback, config) => {
22962
23501
  };
22963
23502
  };
22964
23503
 
22965
- var index$6 = /*#__PURE__*/Object.freeze({
23504
+ var index$5 = /*#__PURE__*/Object.freeze({
22966
23505
  __proto__: null,
22967
23506
  getPostByIds: getPostByIds,
22968
23507
  createPost: createPost,
@@ -23496,7 +24035,7 @@ const getStreams = (params, callback, config) => {
23496
24035
  };
23497
24036
  };
23498
24037
 
23499
- var index$5 = /*#__PURE__*/Object.freeze({
24038
+ var index$4 = /*#__PURE__*/Object.freeze({
23500
24039
  __proto__: null,
23501
24040
  createStream: createStream,
23502
24041
  updateStream: updateStream,
@@ -23783,7 +24322,7 @@ const getPoll = (pollId, callback) => {
23783
24322
  };
23784
24323
  /* end_public_function */
23785
24324
 
23786
- var index$4 = /*#__PURE__*/Object.freeze({
24325
+ var index$3 = /*#__PURE__*/Object.freeze({
23787
24326
  __proto__: null,
23788
24327
  createPoll: createPoll,
23789
24328
  closePoll: closePoll,
@@ -23794,7 +24333,7 @@ var index$4 = /*#__PURE__*/Object.freeze({
23794
24333
  getPoll: getPoll
23795
24334
  });
23796
24335
 
23797
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
24336
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
23798
24337
  /*
23799
24338
  * The crypto algorithm used for importing key and signing string
23800
24339
  */
@@ -24154,7 +24693,7 @@ const getPlayer = async (parameters) => {
24154
24693
  return video;
24155
24694
  };
24156
24695
 
24157
- var index$3 = /*#__PURE__*/Object.freeze({
24696
+ var index$2 = /*#__PURE__*/Object.freeze({
24158
24697
  __proto__: null,
24159
24698
  getPlayer: getPlayer
24160
24699
  });
@@ -25327,7 +25866,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
25327
25866
  };
25328
25867
  };
25329
25868
 
25330
- var index$2 = /*#__PURE__*/Object.freeze({
25869
+ var index$1 = /*#__PURE__*/Object.freeze({
25331
25870
  __proto__: null,
25332
25871
  createImageStory: createImageStory,
25333
25872
  createVideoStory: createVideoStory,
@@ -25364,7 +25903,7 @@ const getNetworkAds = async () => {
25364
25903
  };
25365
25904
  };
25366
25905
 
25367
- var index$1 = /*#__PURE__*/Object.freeze({
25906
+ var index = /*#__PURE__*/Object.freeze({
25368
25907
  __proto__: null,
25369
25908
  getNetworkAds: getNetworkAds
25370
25909
  });
@@ -25391,386 +25930,31 @@ const createUserToken = async (apiKey, apiRegion, params) => {
25391
25930
  return { accessToken: data.accessToken };
25392
25931
  };
25393
25932
 
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
-
25749
25933
  exports.API_REGIONS = API_REGIONS;
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;
25934
+ exports.AdRepository = index;
25935
+ exports.CategoryRepository = index$8;
25936
+ exports.ChannelRepository = index$c;
25937
+ exports.Client = index$l;
25938
+ exports.CommentRepository = index$6;
25755
25939
  exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
25756
25940
  exports.CommunityPostSettings = CommunityPostSettings;
25757
- exports.CommunityRepository = index$a;
25941
+ exports.CommunityRepository = index$9;
25758
25942
  exports.ContentFeedType = ContentFeedType;
25759
25943
  exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
25760
- exports.FeedRepository = index$8;
25761
- exports.FileRepository = index$j;
25944
+ exports.FeedRepository = index$7;
25945
+ exports.FileRepository = index$i;
25762
25946
  exports.FileType = FileType;
25763
- exports.LiveStreamPlayer = index$3;
25947
+ exports.LiveStreamPlayer = index$2;
25764
25948
  exports.MessageContentType = MessageContentType;
25765
- exports.MessageRepository = index$h;
25766
- exports.PollRepository = index$4;
25949
+ exports.MessageRepository = index$g;
25950
+ exports.PollRepository = index$3;
25767
25951
  exports.PostContentType = PostContentType;
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;
25952
+ exports.PostRepository = index$5;
25953
+ exports.ReactionRepository = index$h;
25954
+ exports.StoryRepository = index$1;
25955
+ exports.StreamRepository = index$4;
25956
+ exports.SubChannelRepository = index$f;
25957
+ exports.UserRepository = index$j;
25774
25958
  exports.VERSION = VERSION;
25775
25959
  exports.VideoResolution = VideoResolution;
25776
25960
  exports.VideoSize = VideoSize;
@@ -25823,7 +26007,6 @@ exports.isPaged = isPaged;
25823
26007
  exports.isReportedByMe = isReportedByMe;
25824
26008
  exports.isSkip = isSkip;
25825
26009
  exports.mergeInCache = mergeInCache;
25826
- exports.notificationTray = index;
25827
26010
  exports.onChannelMarkerFetched = onChannelMarkerFetched;
25828
26011
  exports.onFeedMarkerFetched = onFeedMarkerFetched;
25829
26012
  exports.onFeedMarkerUpdated = onFeedMarkerUpdated;