@amityco/ts-sdk 7.1.1-67cf0d9.0 → 7.1.1-6dd179b0.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 (149) 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 -2
  12. package/dist/@types/domains/client.d.ts.map +1 -1
  13. package/dist/@types/domains/notification.d.ts +81 -0
  14. package/dist/@types/domains/notification.d.ts.map +1 -0
  15. package/dist/@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 +0 -1
  26. package/dist/client/api/createClient.d.ts.map +1 -1
  27. package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
  28. package/dist/client/api/login.d.ts.map +1 -1
  29. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +4 -2
  30. package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
  31. package/dist/client/utils/endpoints.d.ts +0 -1
  32. package/dist/client/utils/endpoints.d.ts.map +1 -1
  33. package/dist/client/utils/setClientToken.d.ts.map +1 -1
  34. package/dist/core/events.d.ts +3 -3
  35. package/dist/core/events.d.ts.map +1 -1
  36. package/dist/core/model/idResolvers.d.ts.map +1 -1
  37. package/dist/core/model/index.d.ts.map +1 -1
  38. package/dist/index.cjs.js +468 -596
  39. package/dist/index.d.ts +1 -0
  40. package/dist/index.d.ts.map +1 -1
  41. package/dist/index.esm.js +451 -580
  42. package/dist/index.umd.js +4 -4
  43. package/dist/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
  44. package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
  45. package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
  46. package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
  47. package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
  48. package/dist/notificationTray/api/index.d.ts +3 -0
  49. package/dist/notificationTray/api/index.d.ts.map +1 -0
  50. package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
  51. package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
  52. package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
  53. package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
  54. package/dist/notificationTray/events/index.d.ts +2 -0
  55. package/dist/notificationTray/events/index.d.ts.map +1 -0
  56. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
  57. package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
  58. package/dist/notificationTray/index.d.ts +4 -0
  59. package/dist/notificationTray/index.d.ts.map +1 -0
  60. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
  61. package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
  62. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
  63. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
  64. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
  65. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
  66. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
  67. package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
  68. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
  69. package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
  70. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
  71. package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
  72. package/dist/notificationTray/observers/index.d.ts +3 -0
  73. package/dist/notificationTray/observers/index.d.ts.map +1 -0
  74. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
  75. package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
  76. package/dist/utils/linkedObject/index.d.ts +1 -0
  77. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  78. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
  79. package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
  80. package/package.json +1 -1
  81. package/src/@types/core/events.ts +6 -2
  82. package/src/@types/core/model.ts +6 -4
  83. package/src/@types/core/payload.ts +25 -0
  84. package/src/@types/core/readReceipt.ts +1 -14
  85. package/src/@types/domains/channel.ts +0 -13
  86. package/src/@types/domains/client.ts +0 -3
  87. package/src/@types/domains/notification.ts +90 -0
  88. package/src/@types/index.ts +1 -0
  89. package/src/channelRepository/events/onChannelDeleted.ts +4 -17
  90. package/src/channelRepository/events/onChannelLeft.ts +3 -11
  91. package/src/channelRepository/observers/getChannel.ts +1 -3
  92. package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +1 -6
  93. package/src/channelRepository/observers/index.ts +0 -1
  94. package/src/channelRepository/utils/constructChannelDynamicValue.ts +2 -12
  95. package/src/channelRepository/utils/prepareChannelPayload.ts +17 -68
  96. package/src/client/api/createClient.ts +1 -7
  97. package/src/client/api/enableUnreadCount.ts +0 -1
  98. package/src/client/api/login.ts +1 -5
  99. package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +99 -74
  100. package/src/client/utils/endpoints.ts +0 -1
  101. package/src/client/utils/setClientToken.ts +0 -8
  102. package/src/core/model/idResolvers.ts +3 -2
  103. package/src/core/model/index.ts +2 -0
  104. package/src/fileRepository/api/uploadFile.ts +1 -1
  105. package/src/fileRepository/api/uploadImage.ts +1 -1
  106. package/src/fileRepository/api/uploadVideo.ts +1 -1
  107. package/src/index.ts +2 -0
  108. package/src/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.ts +3 -3
  109. package/src/messageRepository/events/onMessageCreated.ts +1 -45
  110. package/src/messageRepository/observers/getMessage.ts +1 -0
  111. package/src/messageRepository/utils/markReadMessage.ts +3 -10
  112. package/src/notificationTray/api/index.ts +2 -0
  113. package/src/notificationTray/api/markItemsSeen.ts +59 -0
  114. package/src/notificationTray/api/markTraySeen.ts +65 -0
  115. package/src/notificationTray/events/index.ts +1 -0
  116. package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
  117. package/src/notificationTray/index.ts +3 -0
  118. package/src/notificationTray/internalApi/getNotificationTraySeen.ts +81 -0
  119. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
  120. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
  121. package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
  122. package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
  123. package/src/notificationTray/observers/getNotificationTraySeen.ts +43 -0
  124. package/src/notificationTray/observers/index.ts +2 -0
  125. package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
  126. package/src/utils/linkedObject/index.ts +2 -0
  127. package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -0
  128. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +0 -16
  129. package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +0 -1
  130. package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
  131. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +0 -11
  132. package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +0 -1
  133. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +0 -20
  134. package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +0 -1
  135. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +0 -2
  136. package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +0 -1
  137. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -33
  138. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
  139. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -3
  140. package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
  141. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +0 -12
  142. package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +0 -1
  143. package/src/channelRepository/api/markChannelsAsReadBySegment.ts +0 -29
  144. package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +0 -38
  145. package/src/channelRepository/observers/getTotalChannelsUnread.ts +0 -129
  146. package/src/channelRepository/utils/getLegacyChannelUnread.ts +0 -5
  147. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +0 -267
  148. package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +0 -21
  149. package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +0 -29
package/dist/index.esm.js CHANGED
@@ -106,6 +106,7 @@ const SECOND$1 = 1000;
106
106
  const MINUTE = 60 * SECOND$1;
107
107
  const HOUR = 60 * MINUTE;
108
108
  const DAY = 24 * HOUR;
109
+ const WEEK = 7 * DAY;
109
110
  const YEAR = 365 * DAY;
110
111
  const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
111
112
 
@@ -501,7 +502,6 @@ const idResolvers = {
501
502
  messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
502
503
  channelUnreadInfo: ({ channelId }) => channelId,
503
504
  subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
504
- channelUnread: ({ channelId }) => channelId,
505
505
  channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
506
506
  subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
507
507
  messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
@@ -528,6 +528,8 @@ const idResolvers = {
528
528
  advertiser: ({ advertiserId }) => advertiserId,
529
529
  pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
530
530
  pinTarget: ({ targetId }) => targetId,
531
+ notificationTrayItem: ({ _id }) => _id,
532
+ notificationTraySeen: ({ userId }) => userId,
531
533
  };
532
534
  /**
533
535
  * Retrieve the id resolver matching a domain name
@@ -579,6 +581,7 @@ const PAYLOAD2MODEL = {
579
581
  advertisers: 'advertiser',
580
582
  pinTargets: 'pinTarget',
581
583
  pins: 'pin',
584
+ notificationTrayItems: 'notificationTrayItem',
582
585
  };
583
586
  /** hidden */
584
587
  const isOutdated = (prevData, nextData) => {
@@ -1547,7 +1550,6 @@ const API_REGIONS = {
1547
1550
  };
1548
1551
  const URLS = {
1549
1552
  http: 'https://apix.{region}.amity.co',
1550
- upload: 'https://upload.{region}.amity.co',
1551
1553
  mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
1552
1554
  };
1553
1555
  function computeUrl(type, region) {
@@ -1596,13 +1598,13 @@ class NetworkActivitiesWatcher {
1596
1598
  this._listener.clear();
1597
1599
  }
1598
1600
  }
1599
- let instance$6;
1601
+ let instance$5;
1600
1602
  var NetworkActivitiesWatcher$1 = {
1601
1603
  getInstance: () => {
1602
- if (!instance$6) {
1603
- instance$6 = new NetworkActivitiesWatcher();
1604
+ if (!instance$5) {
1605
+ instance$5 = new NetworkActivitiesWatcher();
1604
1606
  }
1605
- return instance$6;
1607
+ return instance$5;
1606
1608
  },
1607
1609
  };
1608
1610
 
@@ -21242,13 +21244,13 @@ class AnalyticsEngine {
21242
21244
  this._eventCapturer.resetAllBuckets();
21243
21245
  }
21244
21246
  }
21245
- let instance$5;
21247
+ let instance$4;
21246
21248
  var AnalyticsEngine$1 = {
21247
21249
  getInstance: () => {
21248
- if (!instance$5) {
21249
- instance$5 = new AnalyticsEngine();
21250
+ if (!instance$4) {
21251
+ instance$4 = new AnalyticsEngine();
21250
21252
  }
21251
- return instance$5;
21253
+ return instance$4;
21252
21254
  },
21253
21255
  };
21254
21256
 
@@ -21674,223 +21676,6 @@ const getMessageReadCount = (message, marker) => {
21674
21676
  getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
21675
21677
  }; // and if not found in cache use default value `0`
21676
21678
 
21677
- /**
21678
- *
21679
- * Mark subChannel as read by readToSegment
21680
- *
21681
- * @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
21682
- * @param readToSegment the segment to mark as read
21683
- * @returns a success boolean if the {@link Amity.SubChannel} was updated
21684
- *
21685
- * @category Channel API
21686
- * @async
21687
- */
21688
- const markChannelsAsReadBySegment = async (readings) => {
21689
- const client = getActiveClient();
21690
- try {
21691
- await client.http.post('api/v3/channels/seen', { channels: readings });
21692
- return true;
21693
- }
21694
- catch (e) {
21695
- return false;
21696
- }
21697
- };
21698
-
21699
- class MessageReadReceiptSyncEngine {
21700
- constructor() {
21701
- this.isActive = true;
21702
- this.MAX_RETRY = 3;
21703
- this.JOB_QUEUE_SIZE = 120;
21704
- this.jobQueue = [];
21705
- // Interval for message read receipt sync in seconds
21706
- this.RECEIPT_SYNC_INTERVAL = 1;
21707
- this.client = getActiveClient();
21708
- // Get remaining unsync read receipts from cache
21709
- this.getUnsyncJobs();
21710
- }
21711
- // Call this when client call client.login
21712
- startSyncReadReceipt() {
21713
- // Start timer when start receipt sync
21714
- this.timer = setInterval(() => {
21715
- this.syncReadReceipts();
21716
- }, this.RECEIPT_SYNC_INTERVAL * 1000);
21717
- }
21718
- // Read receipt observer handling
21719
- syncReadReceipts() {
21720
- if (this.jobQueue.length === 0 || this.isActive === false)
21721
- return;
21722
- const readReceipts = this.getReadReceipts();
21723
- if (readReceipts) {
21724
- this.markReadApi(readReceipts);
21725
- }
21726
- }
21727
- getUnsyncJobs() {
21728
- var _a;
21729
- // Get all read receipts that has latestSyncSegment < latestSegment
21730
- const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21731
- return data.latestSyncSegment < data.latestSegment;
21732
- });
21733
- // Enqueue unsync read receipts to the job queue
21734
- readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
21735
- this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
21736
- });
21737
- }
21738
- getReadReceipts() {
21739
- // get all read receipts from queue, now the queue is empty
21740
- const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
21741
- if (syncJob.length === 0)
21742
- return;
21743
- return syncJob.filter(job => {
21744
- var _a;
21745
- const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
21746
- if (!readReceipt)
21747
- return false;
21748
- if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
21749
- return true;
21750
- return false;
21751
- });
21752
- }
21753
- async markReadApi(syncJobs) {
21754
- var _a;
21755
- // constuct payload
21756
- // example: [{ channelId: 'channelId', readToSegment: 2 }]
21757
- const syncJobsPayload = syncJobs.map(job => {
21758
- return {
21759
- channelId: job.channelId,
21760
- readToSegment: job.segment,
21761
- };
21762
- });
21763
- const response = await markChannelsAsReadBySegment(syncJobsPayload);
21764
- if (response) {
21765
- for (let i = 0; i < syncJobs.length; i += 1) {
21766
- // update lastestSyncSegment in read receipt cache
21767
- const cacheKey = ['readReceipt', syncJobs[i].channelId];
21768
- const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21769
- pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
21770
- }
21771
- }
21772
- else {
21773
- for (let i = 0; i < syncJobs.length; i += 1) {
21774
- // push them back to queue if the syncing is failed and retry count is less than max retry
21775
- if (syncJobs[i].retryCount >= this.MAX_RETRY)
21776
- return;
21777
- const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
21778
- this.enqueueJob(updatedJob);
21779
- }
21780
- }
21781
- }
21782
- startObservingReadReceiptQueue() {
21783
- if (this.client.useLegacyUnreadCount) {
21784
- this.isActive = true;
21785
- this.startSyncReadReceipt();
21786
- }
21787
- }
21788
- stopObservingReadReceiptQueue() {
21789
- this.isActive = false;
21790
- this.jobQueue.map(job => {
21791
- if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21792
- return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
21793
- }
21794
- return job;
21795
- });
21796
- if (this.timer)
21797
- clearInterval(this.timer);
21798
- }
21799
- // Session Management
21800
- onSessionEstablished() {
21801
- this.startObservingReadReceiptQueue();
21802
- }
21803
- onSessionDestroyed() {
21804
- this.stopObservingReadReceiptQueue();
21805
- this.jobQueue = [];
21806
- }
21807
- onTokenExpired() {
21808
- this.stopObservingReadReceiptQueue();
21809
- }
21810
- // Network Connection Management
21811
- onNetworkOffline() {
21812
- // Stop observing to the read receipt queue.
21813
- this.stopObservingReadReceiptQueue();
21814
- }
21815
- onNetworkOnline() {
21816
- // Resume observing to the read receipt queue.
21817
- this.startObservingReadReceiptQueue();
21818
- }
21819
- markRead(channelId, segment) {
21820
- var _a;
21821
- // Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
21822
- const cacheKey = ['channelUnread', 'get', channelId];
21823
- const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21824
- if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
21825
- channelUnread &&
21826
- segment > channelUnread.readToSegment) {
21827
- channelUnread.readToSegment = segment;
21828
- channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
21829
- pushToCache(cacheKey, channelUnread);
21830
- fireEvent('local.channelUnread.updated', channelUnread);
21831
- }
21832
- // Step 2: Enqueue the read receipt
21833
- this.enqueueReadReceipt(channelId, segment);
21834
- }
21835
- enqueueReadReceipt(channelId, segment) {
21836
- var _a;
21837
- const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
21838
- // Create new read receipt if it's not exists and add the job to queue
21839
- if (!readReceipt) {
21840
- const readReceiptChannel = {
21841
- channelId,
21842
- latestSegment: segment,
21843
- latestSyncSegment: 0,
21844
- };
21845
- pushToCache(['readReceipt', channelId], readReceiptChannel);
21846
- }
21847
- else if (readReceipt.latestSegment < segment) {
21848
- // Update latestSegment in read receipt cache
21849
- pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21850
- }
21851
- else if (readReceipt.latestSyncSegment >= segment) {
21852
- // Skip the job when lastSyncSegment > = segment
21853
- return;
21854
- }
21855
- let syncJob = this.getSyncJob(channelId);
21856
- if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
21857
- syncJob = {
21858
- channelId,
21859
- segment,
21860
- syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
21861
- retryCount: 0,
21862
- };
21863
- this.enqueueJob(syncJob);
21864
- }
21865
- else if (syncJob.segment < segment) {
21866
- syncJob.segment = segment;
21867
- }
21868
- }
21869
- getSyncJob(channelId) {
21870
- const { jobQueue } = this;
21871
- const targetJob = jobQueue.find(job => job.channelId === channelId);
21872
- return targetJob || null;
21873
- }
21874
- enqueueJob(syncJob) {
21875
- if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
21876
- this.jobQueue.push(syncJob);
21877
- }
21878
- else {
21879
- // Remove oldest job when queue reach maximum capacity
21880
- this.jobQueue.shift();
21881
- this.jobQueue.push(syncJob);
21882
- }
21883
- }
21884
- }
21885
- let instance$4 = null;
21886
- var ReadReceiptSyncEngine = {
21887
- getInstance: () => {
21888
- if (!instance$4)
21889
- instance$4 = new MessageReadReceiptSyncEngine();
21890
- return instance$4;
21891
- },
21892
- };
21893
-
21894
21679
  /**
21895
21680
  *
21896
21681
  * Mark subChannel as read by readToSegment
@@ -21939,7 +21724,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
21939
21724
  return channelUnreadInfo;
21940
21725
  };
21941
21726
 
21942
- class LegacyMessageReadReceiptSyncEngine {
21727
+ class MessageReadReceiptSyncEngine {
21943
21728
  constructor() {
21944
21729
  this.isActive = true;
21945
21730
  this.MAX_RETRY = 3;
@@ -21970,7 +21755,7 @@ class LegacyMessageReadReceiptSyncEngine {
21970
21755
  getUnsyncJobs() {
21971
21756
  var _a;
21972
21757
  // Get all read receipts that has latestSyncSegment < latestSegment
21973
- const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21758
+ const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
21974
21759
  return data.latestSyncSegment < data.latestSegment;
21975
21760
  });
21976
21761
  // Enqueue unsync read receipts to the job queue
@@ -21989,7 +21774,7 @@ class LegacyMessageReadReceiptSyncEngine {
21989
21774
  return;
21990
21775
  // Get readReceipt from cache by subChannelId
21991
21776
  const readReceipt = (_a = pullFromCache([
21992
- 'legacyReadReceipt',
21777
+ 'readReceipt',
21993
21778
  syncJob.subChannelId,
21994
21779
  ])) === null || _a === void 0 ? void 0 : _a.data;
21995
21780
  if (!readReceipt)
@@ -22012,10 +21797,10 @@ class LegacyMessageReadReceiptSyncEngine {
22012
21797
  if (response) {
22013
21798
  this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
22014
21799
  const readReceiptCache = (_a = pullFromCache([
22015
- 'legacyReadReceipt',
21800
+ 'readReceipt',
22016
21801
  subChannelId,
22017
21802
  ])) === null || _a === void 0 ? void 0 : _a.data;
22018
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
21803
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
22019
21804
  }
22020
21805
  else if (!response) {
22021
21806
  if (newSyncJob.retryCount > this.MAX_RETRY) {
@@ -22082,7 +21867,7 @@ class LegacyMessageReadReceiptSyncEngine {
22082
21867
  subChannelUnreadInfo.readToSegment = segment;
22083
21868
  subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
22084
21869
  const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
22085
- fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
21870
+ fireEvent('local.channelUnread.updated', channelUnreadInfo);
22086
21871
  pushToCache(cacheKey, subChannelUnreadInfo);
22087
21872
  fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
22088
21873
  }
@@ -22091,10 +21876,7 @@ class LegacyMessageReadReceiptSyncEngine {
22091
21876
  }
22092
21877
  enqueueReadReceipt(subChannelId, segment) {
22093
21878
  var _a;
22094
- const readReceipt = (_a = pullFromCache([
22095
- 'legacyReadReceipt',
22096
- subChannelId,
22097
- ])) === null || _a === void 0 ? void 0 : _a.data;
21879
+ const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
22098
21880
  // Create new read receipt if it's not exists and add job to queue
22099
21881
  if (!readReceipt) {
22100
21882
  const readReceiptSubChannel = {
@@ -22102,10 +21884,10 @@ class LegacyMessageReadReceiptSyncEngine {
22102
21884
  latestSegment: segment,
22103
21885
  latestSyncSegment: 0,
22104
21886
  };
22105
- pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
21887
+ pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
22106
21888
  }
22107
21889
  else if (readReceipt.latestSegment < segment) {
22108
- pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
21890
+ pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
22109
21891
  }
22110
21892
  else if (readReceipt.latestSyncSegment >= segment) {
22111
21893
  // Skip the job when lastSyncSegment > = segment
@@ -22148,24 +21930,18 @@ class LegacyMessageReadReceiptSyncEngine {
22148
21930
  }
22149
21931
  }
22150
21932
  let instance$3 = null;
22151
- var LegacyReadReceiptSyncEngine = {
21933
+ var ReadReceiptSyncEngine = {
22152
21934
  getInstance: () => {
22153
21935
  if (!instance$3)
22154
- instance$3 = new LegacyMessageReadReceiptSyncEngine();
21936
+ instance$3 = new MessageReadReceiptSyncEngine();
22155
21937
  return instance$3;
22156
21938
  },
22157
21939
  };
22158
21940
 
22159
21941
  const markReadMessage = (message) => {
22160
- const client = getActiveClient();
22161
- if (client.useLegacyUnreadCount) {
22162
- const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
22163
- markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
22164
- }
22165
- else {
22166
- const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
22167
- markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
22168
- }
21942
+ const { subChannelId, channelSegment } = message;
21943
+ const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
21944
+ markReadReceiptEngine.markRead(subChannelId, channelSegment);
22169
21945
  };
22170
21946
 
22171
21947
  const messageLinkedObject = (message) => {
@@ -22313,6 +22089,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
22313
22089
  } });
22314
22090
  };
22315
22091
 
22092
+ const notificationTrayLinkedObject = (noti) => {
22093
+ return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
22094
+ .map(({ _id }) => pullFromCache(['user', 'get', _id]))
22095
+ .filter(isNonNullable)
22096
+ .map(({ data }) => data)
22097
+ .map(user => userLinkedObject(user)) });
22098
+ };
22099
+
22316
22100
  const LinkedObject = {
22317
22101
  ad: adLinkedObject,
22318
22102
  comment: commentLinkedObject,
@@ -22326,6 +22110,7 @@ const LinkedObject = {
22326
22110
  reactor: reactorLinkedObject,
22327
22111
  channel: channelLinkedObject,
22328
22112
  pinnedPost: pinnedPostLinkedObject,
22113
+ notificationTray: notificationTrayLinkedObject,
22329
22114
  };
22330
22115
 
22331
22116
  const getChannelMessagePreviewWithUser = (channel) => {
@@ -23153,32 +22938,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
23153
22938
  channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
23154
22939
  });
23155
22940
  };
23156
- const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
23157
- for (let i = 0; i < channels.length; i += 1) {
23158
- const cacheKey = ['channelUnread', 'get', channels[i].channelId];
23159
- const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
23160
- let unreadCount = 0;
23161
- let readToSegment = null;
23162
- let lastMentionedSegment = null;
23163
- let isMentioned = false;
23164
- if (channelUser) {
23165
- readToSegment = channelUser.readToSegment;
23166
- lastMentionedSegment = channelUser.lastMentionedSegment;
23167
- unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
23168
- isMentioned = lastMentionedSegment > readToSegment;
23169
- }
23170
- const cacheChannelUnread = {
23171
- channelId: channels[i].channelId,
23172
- lastSegment: channels[i].messageCount,
23173
- readToSegment,
23174
- lastMentionedSegment,
23175
- unreadCount,
23176
- isMentioned,
23177
- isDeleted: channels[i].isDeleted || false,
23178
- };
23179
- pushToCache(cacheKey, cacheChannelUnread);
23180
- }
23181
- };
23182
22941
  const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
23183
22942
  const client = getActiveClient();
23184
22943
  const networkPreviewSetting = await client.getMessagePreviewSetting(false);
@@ -23188,34 +22947,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
23188
22947
  rawPayload.messagePreviews.length > 0) {
23189
22948
  updateChannelMessagePreviewCache(rawPayload);
23190
22949
  }
23191
- if (client.useLegacyUnreadCount) {
23192
- updateChannelUnread({
23193
- channels: rawPayload.channels,
23194
- channelUsers: rawPayload.channelUsers,
23195
- currentUserId: client.userId,
23196
- });
23197
- }
23198
- else {
23199
- const markerIds = rawPayload.channels
23200
- // filter channel by type. Only conversation, community and broadcast type are included.
23201
- .filter(isUnreadCountSupport)
23202
- .map(({ channelInternalId }) => channelInternalId);
23203
- if (markerIds.length > 0) {
23204
- // since the get markers method requires a channel cache to function with the reducer.
23205
- preUpdateChannelCache(rawPayload, {
23206
- isMessagePreviewUpdated: options.isMessagePreviewUpdated,
23207
- });
23208
- try {
23209
- await getChannelMarkers(markerIds);
23210
- }
23211
- catch (e) {
23212
- // empty block (from the spec, allow marker fetch to fail without having to do anything)
23213
- }
22950
+ const markerIds = rawPayload.channels
22951
+ // filter channel by type. Only conversation, community and broadcast type are included.
22952
+ .filter(isUnreadCountSupport)
22953
+ .map(({ channelInternalId }) => channelInternalId);
22954
+ if (markerIds.length > 0) {
22955
+ // since the get markers method requires a channel cache to function with the reducer.
22956
+ preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
22957
+ try {
22958
+ await getChannelMarkers(markerIds);
22959
+ }
22960
+ catch (e) {
22961
+ // empty block (from the spec, allow marker fetch to fail without having to do anything)
23214
22962
  }
23215
22963
  }
23216
- // convert raw channel to internal channel
22964
+ // attach marker to channel
23217
22965
  const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
23218
- // convert raw channel user to membership (add user object)
22966
+ // user marker to channel users
23219
22967
  const channelUsers = rawPayload.channelUsers.map(channelUser => {
23220
22968
  return convertRawMembershipToMembership(channelUser);
23221
22969
  });
@@ -23342,28 +23090,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
23342
23090
  return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
23343
23091
  };
23344
23092
 
23345
- const getLegacyChannelUnread = (channelId) => {
23346
- var _a;
23347
- return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
23348
- };
23349
-
23350
23093
  const constructChannelDynamicValue = (channel) => {
23351
- const client = getActiveClient();
23352
23094
  const rest = __rest(channel, ["messageCount"]);
23353
23095
  return shallowClone(rest, {
23354
- get unreadCount() {
23355
- var _a, _b;
23356
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
23096
+ get isMentioned() {
23097
+ return getChannelIsMentioned(rest);
23357
23098
  },
23358
23099
  get subChannelsUnreadCount() {
23359
23100
  return getSubChannelsUnreadCount(rest);
23360
23101
  },
23361
- get isMentioned() {
23362
- var _a, _b;
23363
- if (client.useLegacyUnreadCount)
23364
- return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
23365
- return getChannelIsMentioned(rest);
23366
- },
23367
23102
  });
23368
23103
  };
23369
23104
 
@@ -23976,12 +23711,6 @@ const setClientToken = async (params) => {
23976
23711
  isGlobalBanned: false,
23977
23712
  isUserDeleted: false,
23978
23713
  };
23979
- client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
23980
- client.upload.defaults.metadata = {
23981
- tokenExpiry: expiresAt,
23982
- isGlobalBanned: false,
23983
- isUserDeleted: false,
23984
- };
23985
23714
  // manually setup the token for ws transport
23986
23715
  if (client.ws)
23987
23716
  client.ws.io.opts.query = { token: accessToken };
@@ -24026,21 +23755,12 @@ const onChannelDeleted = (callback) => {
24026
23755
  const client = getActiveClient();
24027
23756
  const filter = async (payload) => {
24028
23757
  const data = await prepareChannelPayload(payload);
24029
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24030
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24031
- data.channels.forEach(channel => {
24032
- if (isConsistentMode) {
23758
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
23759
+ data.channels.forEach(channel => {
24033
23760
  addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24034
23761
  deleteChannelUnreadByChannelId(channel.channelId);
24035
- }
24036
- else if (isLegacyUnreadCount) {
24037
- const cacheKey = ['channelUnread', 'get', channel.channelId];
24038
- const cache = pullFromCache(cacheKey);
24039
- if (cache) {
24040
- pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
24041
- }
24042
- }
24043
- });
23762
+ });
23763
+ }
24044
23764
  ingestInCache(data);
24045
23765
  callbacks$b.forEach(cb => cb(data.channels[0]));
24046
23766
  };
@@ -24154,25 +23874,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
24154
23874
  };
24155
23875
  };
24156
23876
 
24157
- var legacyReadReceiptSyncEngineOnLoginHandler = () => {
24158
- const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
24159
- readReceiptSyncEngine.startSyncReadReceipt();
24160
- onSessionStateChange(state => {
24161
- if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
24162
- readReceiptSyncEngine.onSessionEstablished();
24163
- }
24164
- else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
24165
- readReceiptSyncEngine.onTokenExpired();
24166
- }
24167
- else {
24168
- readReceiptSyncEngine.onSessionDestroyed();
24169
- }
24170
- });
24171
- return () => {
24172
- readReceiptSyncEngine.onSessionDestroyed();
24173
- };
24174
- };
24175
-
24176
23877
  const onOnline = (callback) => {
24177
23878
  if (typeof window !== 'undefined' && window.addEventListener) {
24178
23879
  window.addEventListener('online', callback);
@@ -24739,17 +24440,10 @@ const onChannelLeft = (callback) => {
24739
24440
  const preparedPayload = await prepareChannelPayload(payload, {
24740
24441
  isMessagePreviewUpdated: isLeftByMe,
24741
24442
  });
24742
- const isConsistentMode = client.getMarkerSyncConsistentMode() && client.isUnreadCountEnabled;
24743
- const isLegacyUnreadCount = client.useLegacyUnreadCount;
24744
- if (isLeftByMe) {
24443
+ if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
24745
24444
  preparedPayload.channels.forEach(channel => {
24746
- if (isConsistentMode) {
24747
- addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24748
- deleteChannelUnreadByChannelId(channel.channelId);
24749
- }
24750
- else if (isLegacyUnreadCount) {
24751
- dropFromCache(['channelUnread', 'get', channel.channelId]);
24752
- }
24445
+ addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
24446
+ deleteChannelUnreadByChannelId(channel.channelId);
24753
24447
  });
24754
24448
  }
24755
24449
  const { channels, channelUsers } = preparedPayload;
@@ -25017,34 +24711,6 @@ const onMessageCreatedMqtt = (callback) => {
25017
24711
  reCalculateChannelUnreadInfo(message.channelId);
25018
24712
  });
25019
24713
  }
25020
- if (client.useLegacyUnreadCount) {
25021
- rawPayload.messages.forEach(message => {
25022
- var _a, _b;
25023
- const channelUnread = (_a = pullFromCache([
25024
- 'channelUnread',
25025
- 'get',
25026
- message.channelId,
25027
- ])) === null || _a === void 0 ? void 0 : _a.data;
25028
- if (!channelUnread ||
25029
- channelUnread.lastSegment >= message.segment ||
25030
- typeof channelUnread.readToSegment !== 'number' ||
25031
- typeof channelUnread.lastMentionedSegment !== 'number')
25032
- return;
25033
- const lastSegment = message.segment;
25034
- const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
25035
- return (mention.type === 'channel' ||
25036
- (mention.type === 'user' &&
25037
- client.userId &&
25038
- mention.userPublicIds.includes(client.userId)));
25039
- });
25040
- const lastMentionedSegment = isMentionedInMessage
25041
- ? message.segment
25042
- : channelUnread.lastMentionedSegment;
25043
- const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
25044
- pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
25045
- fireEvent('local.channelUnread.updated', updatedChannelUnread);
25046
- });
25047
- }
25048
24714
  // Update in cache
25049
24715
  ingestInCache(payload);
25050
24716
  payload.messages.forEach(message => {
@@ -25220,7 +24886,6 @@ const enableUnreadCount = () => {
25220
24886
  if (client.isUnreadCountEnabled)
25221
24887
  return false;
25222
24888
  client.isUnreadCountEnabled = true;
25223
- client.useLegacyUnreadCount = false;
25224
24889
  client.emitter.emit('unreadCountEnabled', true);
25225
24890
  return true;
25226
24891
  };
@@ -25536,12 +25201,7 @@ const login = async (params, sessionHandler, config) => {
25536
25201
  // NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
25537
25202
  // the channel because currently backend can't handle this, so every time a user is banned from
25538
25203
  // a channel or the channel is deleted the channel's unread count will not be reset to zero
25539
- onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25540
- if (client.useLegacyUnreadCount) {
25541
- subscriptions.push(readReceiptSyncEngineOnLoginHandler());
25542
- }
25543
- else
25544
- subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
25204
+ onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
25545
25205
  const markerSyncUnsubscriber = await startMarkerSync();
25546
25206
  subscriptions.push(markerSyncUnsubscriber);
25547
25207
  }
@@ -25699,17 +25359,15 @@ const DEFAULT_DEBUG_SESSION = 'amity';
25699
25359
  * @category Client API
25700
25360
  * */
25701
25361
  const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
25702
- var _a, _b, _c;
25362
+ var _a, _b;
25703
25363
  const log = createLogger(debugSession);
25704
25364
  log('client/api/createClient', {
25705
25365
  apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
25706
25366
  apiRegion,
25707
25367
  });
25708
25368
  const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
25709
- const uploadEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.upload) !== null && _b !== void 0 ? _b : computeUrl('upload', apiRegion);
25710
- const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
25369
+ const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
25711
25370
  const http = createHttpTransport(httpEndpoint);
25712
- const upload = createHttpTransport(uploadEndpoint);
25713
25371
  let ws;
25714
25372
  let mqtt;
25715
25373
  if (rteEnabled) {
@@ -25724,8 +25382,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25724
25382
  const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
25725
25383
  const sessionHandler = undefined;
25726
25384
  const isUnreadCountEnabled = false;
25727
- // Legacy unread count is true by default
25728
- const useLegacyUnreadCount = true;
25729
25385
  const client = {
25730
25386
  version: `${VERSION}`,
25731
25387
  apiKey,
@@ -25740,7 +25396,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25740
25396
  http,
25741
25397
  ws,
25742
25398
  mqtt,
25743
- upload,
25744
25399
  emitter,
25745
25400
  /*
25746
25401
  * Session Components
@@ -25756,7 +25411,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25756
25411
  getMessagePreviewSetting,
25757
25412
  use: () => setActiveClient(client),
25758
25413
  isUnreadCountEnabled,
25759
- useLegacyUnreadCount,
25760
25414
  getMarkerSyncConsistentMode,
25761
25415
  /**
25762
25416
  * Prefix for the deviceId key in the local storage or async storage.
@@ -25770,7 +25424,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
25770
25424
  return activeClient;
25771
25425
  setActiveClient(client);
25772
25426
  }
25773
- catch (_d) {
25427
+ catch (_c) {
25774
25428
  setActiveClient(client);
25775
25429
  }
25776
25430
  return client;
@@ -26227,7 +25881,7 @@ const getUserUnread = (callback) => {
26227
25881
  };
26228
25882
  };
26229
25883
 
26230
- var index$l = /*#__PURE__*/Object.freeze({
25884
+ var index$m = /*#__PURE__*/Object.freeze({
26231
25885
  __proto__: null,
26232
25886
  getActiveClient: getActiveClient,
26233
25887
  getActiveUser: getActiveUser,
@@ -27434,7 +27088,7 @@ const getMyFollowInfo = (callback) => {
27434
27088
  };
27435
27089
  /* end_public_function */
27436
27090
 
27437
- var index$k = /*#__PURE__*/Object.freeze({
27091
+ var index$l = /*#__PURE__*/Object.freeze({
27438
27092
  __proto__: null,
27439
27093
  blockUser: blockUser,
27440
27094
  unBlockUser: unBlockUser,
@@ -28449,9 +28103,9 @@ var AmityUserSearchMatchType;
28449
28103
  AmityUserSearchMatchType["PARTIAL"] = "partial";
28450
28104
  })(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
28451
28105
 
28452
- var index$j = /*#__PURE__*/Object.freeze({
28106
+ var index$k = /*#__PURE__*/Object.freeze({
28453
28107
  __proto__: null,
28454
- Relationship: index$k,
28108
+ Relationship: index$l,
28455
28109
  getUserByIds: getUserByIds,
28456
28110
  updateUser: updateUser,
28457
28111
  flagUser: flagUser,
@@ -28559,7 +28213,7 @@ const uploadFile = async (formData, onProgress) => {
28559
28213
  const headers = 'getHeaders' in formData
28560
28214
  ? formData.getHeaders()
28561
28215
  : { 'content-type': 'multipart/form-data' };
28562
- const { data } = await client.upload.post('/api/v4/files', formData, {
28216
+ const { data } = await client.http.post('/api/v4/files', formData, {
28563
28217
  headers,
28564
28218
  onUploadProgress({ loaded, total = 100 }) {
28565
28219
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28649,7 +28303,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
28649
28303
  const headers = 'getHeaders' in formData
28650
28304
  ? formData.getHeaders()
28651
28305
  : { 'content-type': 'multipart/form-data' };
28652
- const { data } = await client.upload.post('/api/v4/videos', formData, {
28306
+ const { data } = await client.http.post('/api/v4/videos', formData, {
28653
28307
  headers,
28654
28308
  onUploadProgress({ loaded, total = 100 }) {
28655
28309
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28697,7 +28351,7 @@ const uploadImage = async (formData, onProgress) => {
28697
28351
  const headers = 'getHeaders' in formData
28698
28352
  ? formData.getHeaders()
28699
28353
  : { 'content-type': 'multipart/form-data' };
28700
- const { data } = await client.upload.post('/api/v4/images', formData, {
28354
+ const { data } = await client.http.post('/api/v4/images', formData, {
28701
28355
  headers,
28702
28356
  onUploadProgress({ loaded, total = 100 }) {
28703
28357
  onProgress && onProgress(Math.round((loaded * 100) / total));
@@ -28715,7 +28369,7 @@ const uploadImage = async (formData, onProgress) => {
28715
28369
  };
28716
28370
  /* end_public_function */
28717
28371
 
28718
- var index$i = /*#__PURE__*/Object.freeze({
28372
+ var index$j = /*#__PURE__*/Object.freeze({
28719
28373
  __proto__: null,
28720
28374
  getFile: getFile,
28721
28375
  uploadFile: uploadFile,
@@ -30527,7 +30181,7 @@ const getReactions = (params, callback, config) => {
30527
30181
  };
30528
30182
  /* end_public_function */
30529
30183
 
30530
- var index$h = /*#__PURE__*/Object.freeze({
30184
+ var index$i = /*#__PURE__*/Object.freeze({
30531
30185
  __proto__: null,
30532
30186
  addReaction: addReaction,
30533
30187
  removeReaction: removeReaction,
@@ -32343,7 +31997,7 @@ const getMessages = (params, callback, config) => {
32343
31997
  };
32344
31998
  /* end_public_function */
32345
31999
 
32346
- var index$g = /*#__PURE__*/Object.freeze({
32000
+ var index$h = /*#__PURE__*/Object.freeze({
32347
32001
  __proto__: null,
32348
32002
  createMessage: createMessage,
32349
32003
  updateMessage: updateMessage,
@@ -32869,7 +32523,7 @@ const stopMessageReceiptSync = (subChannelId) => {
32869
32523
  };
32870
32524
  /* end_public_function */
32871
32525
 
32872
- var index$f = /*#__PURE__*/Object.freeze({
32526
+ var index$g = /*#__PURE__*/Object.freeze({
32873
32527
  __proto__: null,
32874
32528
  getSubChannelByIds: getSubChannels$1,
32875
32529
  createSubChannel: createSubChannel,
@@ -32890,37 +32544,19 @@ var index$f = /*#__PURE__*/Object.freeze({
32890
32544
  /**
32891
32545
  * Internal used only
32892
32546
  *
32893
- * Fired when an {@link Amity.channelUnreadInfo} has been updated.
32894
- *
32895
- * @param callback The function to call when the event was fired
32896
- * @returns an {@link Amity.Unsubscriber} function to stop listening
32897
- *
32898
- * @category ChannelMarker Events
32899
- */
32900
- const onChannelUnreadInfoUpdatedLocal = (callback) => {
32901
- const client = getActiveClient();
32902
- const filter = (payload) => {
32903
- callback(payload);
32904
- };
32905
- return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
32906
- };
32907
-
32908
- /**
32909
- * Internal used only
32910
- *
32911
- * Fired when an {@link Amity.ChannelUnread} has been updated.
32547
+ * Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
32912
32548
  *
32913
32549
  * @param callback The function to call when the event was fired
32914
32550
  * @returns an {@link Amity.Unsubscriber} function to stop listening
32915
32551
  *
32916
- * @category Channel Events
32552
+ * @category MessageMarker Events
32917
32553
  */
32918
32554
  const onChannelUnreadUpdatedLocal = (callback) => {
32919
32555
  const client = getActiveClient();
32920
32556
  const filter = (payload) => {
32921
32557
  callback(payload);
32922
32558
  };
32923
- return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32559
+ return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
32924
32560
  };
32925
32561
 
32926
32562
  /* begin_public_function
@@ -33122,7 +32758,6 @@ const getChannel = (channelId, callback) => {
33122
32758
  return onSubChannelUpdated(updateMessagePreview);
33123
32759
  }, 'channelId', 'channel'),
33124
32760
  convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
33125
- convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33126
32761
  convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33127
32762
  ], {
33128
32763
  forceDispatch: true,
@@ -33636,10 +33271,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
33636
33271
  },
33637
33272
  action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
33638
33273
  },
33639
- {
33640
- fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
33641
- action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
33642
- },
33643
33274
  {
33644
33275
  fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
33645
33276
  action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
@@ -33705,120 +33336,6 @@ const getChannels = (params, callback, config) => {
33705
33336
  };
33706
33337
  /* end_public_function */
33707
33338
 
33708
- /**
33709
- *
33710
- * Calculate user unread from {@link Amity.ChannelUnread} objects
33711
- *
33712
- * @returns the {@link Amity.UserUnread} objects
33713
- *
33714
- * @category Channel API
33715
- * @async
33716
- */
33717
- const getTotalChannelsUnread$1 = () => {
33718
- var _a;
33719
- const client = getActiveClient();
33720
- client.log('channel/getTotalChannelsUnread.locally');
33721
- const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
33722
- return !data.isDeleted;
33723
- })) || [];
33724
- const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
33725
- acc.unreadCount += data.unreadCount;
33726
- acc.isMentioned = acc.isMentioned || data.isMentioned;
33727
- return acc;
33728
- }, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
33729
- const cachedAt = client.cache && Date.now();
33730
- return {
33731
- data: totalChannelsUnread,
33732
- cachedAt,
33733
- };
33734
- };
33735
-
33736
- /* begin_public_function
33737
- id: totalChannelsUnread.get
33738
- */
33739
- /**
33740
- * ```js
33741
- * import { ChannelRepository } from '@amityco/ts-sdk';
33742
- *
33743
- * let totalChannelsUnread;
33744
- *
33745
- * const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
33746
- * unread = response.data;
33747
- * });
33748
- * ```
33749
- *
33750
- * Observe all mutation on a given {@link Amity.UserUnread}
33751
- *
33752
- * @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
33753
- *
33754
- * @category User Unread Live Object
33755
- *
33756
- */
33757
- const getTotalChannelsUnread = (callback) => {
33758
- const { _id: userId } = getActiveUser();
33759
- if (!userId)
33760
- throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
33761
- const { log, cache } = getActiveClient();
33762
- if (!cache) {
33763
- console.log('For using Live Object feature you need to enable Cache!');
33764
- }
33765
- const timestamp = Date.now();
33766
- log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
33767
- const disposers = [];
33768
- let isUnsyncedModel = false; // for messages
33769
- let model;
33770
- const dispatcher = (data) => {
33771
- const { data: userUnread } = data;
33772
- const callbackModel = userUnread
33773
- ? {
33774
- unreadCount: userUnread.unreadCount,
33775
- isMentioned: userUnread.isMentioned,
33776
- }
33777
- : undefined;
33778
- model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
33779
- callback({
33780
- data: callbackModel
33781
- ? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
33782
- loading: data.loading,
33783
- error: data.error,
33784
- });
33785
- };
33786
- const realtimeRouter = (userUnread) => {
33787
- if (isEqual(model, userUnread))
33788
- return;
33789
- dispatcher({
33790
- loading: false,
33791
- data: userUnread,
33792
- });
33793
- };
33794
- const onFetch = () => {
33795
- const query = createQuery(async () => getTotalChannelsUnread$1());
33796
- runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
33797
- if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
33798
- dispatcher({
33799
- data,
33800
- origin,
33801
- loading: false,
33802
- error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
33803
- });
33804
- isUnsyncedModel = true;
33805
- disposers.forEach(fn => fn());
33806
- }
33807
- else if (!isUnsyncedModel) {
33808
- dispatcher({ loading, data, origin, error });
33809
- }
33810
- if (error) {
33811
- disposers.forEach(fn => fn());
33812
- }
33813
- });
33814
- };
33815
- disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
33816
- onFetch();
33817
- return () => {
33818
- disposers.forEach(fn => fn());
33819
- };
33820
- };
33821
-
33822
33339
  /* begin_public_function
33823
33340
  id: channel.member.add
33824
33341
  */
@@ -34183,7 +33700,7 @@ const searchMembers$1 = (params, callback, config) => {
34183
33700
  };
34184
33701
  /* end_public_function */
34185
33702
 
34186
- var index$e = /*#__PURE__*/Object.freeze({
33703
+ var index$f = /*#__PURE__*/Object.freeze({
34187
33704
  __proto__: null,
34188
33705
  addMembers: addMembers$1,
34189
33706
  removeMembers: removeMembers$1,
@@ -34386,7 +33903,7 @@ const unmuteMembers = async (channelId, userIds) => {
34386
33903
  };
34387
33904
  /* end_public_function */
34388
33905
 
34389
- var index$d = /*#__PURE__*/Object.freeze({
33906
+ var index$e = /*#__PURE__*/Object.freeze({
34390
33907
  __proto__: null,
34391
33908
  addRole: addRole,
34392
33909
  removeRole: removeRole,
@@ -34396,10 +33913,10 @@ var index$d = /*#__PURE__*/Object.freeze({
34396
33913
  unmuteMembers: unmuteMembers
34397
33914
  });
34398
33915
 
34399
- var index$c = /*#__PURE__*/Object.freeze({
33916
+ var index$d = /*#__PURE__*/Object.freeze({
34400
33917
  __proto__: null,
34401
- Membership: index$e,
34402
- Moderation: index$d,
33918
+ Membership: index$f,
33919
+ Moderation: index$e,
34403
33920
  getChannelByIds: getChannelByIds$1,
34404
33921
  createChannel: createChannel,
34405
33922
  updateChannel: updateChannel,
@@ -34422,7 +33939,6 @@ var index$c = /*#__PURE__*/Object.freeze({
34422
33939
  onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
34423
33940
  getChannel: getChannel,
34424
33941
  getChannels: getChannels,
34425
- getTotalChannelsUnread: getTotalChannelsUnread,
34426
33942
  MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
34427
33943
  isUnreadCountSupport: isUnreadCountSupport,
34428
33944
  convertFromRaw: convertFromRaw,
@@ -35779,7 +35295,7 @@ const searchMembers = (params, callback, config) => {
35779
35295
  };
35780
35296
  /* end_public_function */
35781
35297
 
35782
- var index$b = /*#__PURE__*/Object.freeze({
35298
+ var index$c = /*#__PURE__*/Object.freeze({
35783
35299
  __proto__: null,
35784
35300
  addMembers: addMembers,
35785
35301
  removeMembers: removeMembers,
@@ -36804,7 +36320,7 @@ const unbanMembers = async (communityId, userIds) => {
36804
36320
  };
36805
36321
  /* end_public_function */
36806
36322
 
36807
- var index$a = /*#__PURE__*/Object.freeze({
36323
+ var index$b = /*#__PURE__*/Object.freeze({
36808
36324
  __proto__: null,
36809
36325
  addRoles: addRoles,
36810
36326
  removeRoles: removeRoles,
@@ -36812,10 +36328,10 @@ var index$a = /*#__PURE__*/Object.freeze({
36812
36328
  unbanMembers: unbanMembers
36813
36329
  });
36814
36330
 
36815
- var index$9 = /*#__PURE__*/Object.freeze({
36331
+ var index$a = /*#__PURE__*/Object.freeze({
36816
36332
  __proto__: null,
36817
- Moderation: index$a,
36818
- Membership: index$b,
36333
+ Moderation: index$b,
36334
+ Membership: index$c,
36819
36335
  getCommunityByIds: getCommunities$1,
36820
36336
  createCommunity: createCommunity,
36821
36337
  updateCommunity: updateCommunity,
@@ -37048,7 +36564,7 @@ const getCategories = (params, callback, config) => {
37048
36564
  };
37049
36565
  /* end_public_function */
37050
36566
 
37051
- var index$8 = /*#__PURE__*/Object.freeze({
36567
+ var index$9 = /*#__PURE__*/Object.freeze({
37052
36568
  __proto__: null,
37053
36569
  getCategory: getCategory,
37054
36570
  getCategories: getCategories
@@ -37216,7 +36732,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
37216
36732
  : undefined;
37217
36733
  };
37218
36734
 
37219
- var index$7 = /*#__PURE__*/Object.freeze({
36735
+ var index$8 = /*#__PURE__*/Object.freeze({
37220
36736
  __proto__: null,
37221
36737
  queryGlobalFeed: queryGlobalFeed,
37222
36738
  getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
@@ -38531,7 +38047,7 @@ const getComments = (params, callback, config) => {
38531
38047
  };
38532
38048
  /* end_public_function */
38533
38049
 
38534
- var index$6 = /*#__PURE__*/Object.freeze({
38050
+ var index$7 = /*#__PURE__*/Object.freeze({
38535
38051
  __proto__: null,
38536
38052
  getCommentByIds: getCommentByIds,
38537
38053
  createComment: createComment,
@@ -39538,7 +39054,7 @@ const semanticSearchPosts = (params, callback, config) => {
39538
39054
  };
39539
39055
  };
39540
39056
 
39541
- var index$5 = /*#__PURE__*/Object.freeze({
39057
+ var index$6 = /*#__PURE__*/Object.freeze({
39542
39058
  __proto__: null,
39543
39059
  getPostByIds: getPostByIds,
39544
39060
  createPost: createPost,
@@ -40072,7 +39588,7 @@ const getStreams = (params, callback, config) => {
40072
39588
  };
40073
39589
  };
40074
39590
 
40075
- var index$4 = /*#__PURE__*/Object.freeze({
39591
+ var index$5 = /*#__PURE__*/Object.freeze({
40076
39592
  __proto__: null,
40077
39593
  createStream: createStream,
40078
39594
  updateStream: updateStream,
@@ -40359,7 +39875,7 @@ const getPoll = (pollId, callback) => {
40359
39875
  };
40360
39876
  /* end_public_function */
40361
39877
 
40362
- var index$3 = /*#__PURE__*/Object.freeze({
39878
+ var index$4 = /*#__PURE__*/Object.freeze({
40363
39879
  __proto__: null,
40364
39880
  createPoll: createPoll,
40365
39881
  closePoll: closePoll,
@@ -40730,7 +40246,7 @@ const getPlayer = async (parameters) => {
40730
40246
  return video;
40731
40247
  };
40732
40248
 
40733
- var index$2 = /*#__PURE__*/Object.freeze({
40249
+ var index$3 = /*#__PURE__*/Object.freeze({
40734
40250
  __proto__: null,
40735
40251
  getPlayer: getPlayer
40736
40252
  });
@@ -41903,7 +41419,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
41903
41419
  };
41904
41420
  };
41905
41421
 
41906
- var index$1 = /*#__PURE__*/Object.freeze({
41422
+ var index$2 = /*#__PURE__*/Object.freeze({
41907
41423
  __proto__: null,
41908
41424
  createImageStory: createImageStory,
41909
41425
  createVideoStory: createVideoStory,
@@ -41940,7 +41456,7 @@ const getNetworkAds = async () => {
41940
41456
  };
41941
41457
  };
41942
41458
 
41943
- var index = /*#__PURE__*/Object.freeze({
41459
+ var index$1 = /*#__PURE__*/Object.freeze({
41944
41460
  __proto__: null,
41945
41461
  getNetworkAds: getNetworkAds
41946
41462
  });
@@ -41967,4 +41483,359 @@ const createUserToken = async (apiKey, apiRegion, params) => {
41967
41483
  return { accessToken: data.accessToken };
41968
41484
  };
41969
41485
 
41970
- export { API_REGIONS, index as AdRepository, index$8 as CategoryRepository, index$c as ChannelRepository, index$l as Client, index$6 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$9 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$7 as FeedRepository, FileAccessTypeEnum, index$i as FileRepository, FileType, index$2 as LiveStreamPlayer, MessageContentType, index$g as MessageRepository, index$3 as PollRepository, PostContentType, index$5 as PostRepository, index$h as ReactionRepository, index$1 as StoryRepository, index$4 as StreamRepository, index$f as SubChannelRepository, SubscriptionLevels, index$j as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
41486
+ /* begin_public_function
41487
+ id: notificationTray.getNotificationTraySeen
41488
+ */
41489
+ /**
41490
+ * ```js
41491
+ * import { notificationTray } from '@amityco/ts-sdk'
41492
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen()
41493
+ * ```
41494
+ *
41495
+ *
41496
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41497
+ *
41498
+ * @category NotificationTray API
41499
+ * @async
41500
+ * */
41501
+ const getNotificationTraySeen$1 = async () => {
41502
+ const client = getActiveClient();
41503
+ client.log('notificationTray/getNotificationTraySeen', {});
41504
+ const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
41505
+ const cachedAt = client.cache && Date.now();
41506
+ if (client.cache) {
41507
+ const cacheKey = ['notificationTraySeen', 'get', client.userId];
41508
+ pushToCache(cacheKey, {
41509
+ userId: client.userId,
41510
+ lastTraySeenAt: payload.lastTraySeenAt,
41511
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41512
+ });
41513
+ }
41514
+ return {
41515
+ data: {
41516
+ userId: client.userId,
41517
+ lastTraySeenAt: payload.lastTraySeenAt,
41518
+ lastTrayOccuredAt: payload.lastTrayOccuredAt,
41519
+ isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
41520
+ },
41521
+ cachedAt,
41522
+ };
41523
+ };
41524
+ /* end_public_function */
41525
+ /**
41526
+ * ```js
41527
+ * import { notificationTray } from '@amityco/ts-sdk'
41528
+ * const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
41529
+ * ```
41530
+ *
41531
+ * Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
41532
+ *
41533
+ * @returns A page of {@link Amity.NotificationTraySeen} objects
41534
+ *
41535
+ * @category NotificationTray API
41536
+ * @async
41537
+ * */
41538
+ getNotificationTraySeen$1.locally = () => {
41539
+ var _a;
41540
+ const client = getActiveClient();
41541
+ client.log('notificationTray/getNotificationTraySeen.locally', {});
41542
+ if (!client.cache)
41543
+ return;
41544
+ const queryKey = ['notificationTraySeen', 'get'];
41545
+ const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
41546
+ if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
41547
+ return;
41548
+ return { data: data.notificationTraySeen, cachedAt };
41549
+ };
41550
+
41551
+ /**
41552
+ * ```js
41553
+ * import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
41554
+ * const dispose = onNotificationTraySeenUpdated(data => {
41555
+ * // ...
41556
+ * })
41557
+ * ```
41558
+ *
41559
+ * Fired when an {@link Amity.NotificationTraySeen} has been updated
41560
+ *
41561
+ * @param callback The function to call when the event was fired
41562
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
41563
+ *
41564
+ * @category NotificationTraySeen Events
41565
+ */
41566
+ const onNotificationTraySeenUpdated = (callback) => {
41567
+ const client = getActiveClient();
41568
+ const disposers = [
41569
+ createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
41570
+ ];
41571
+ return () => {
41572
+ disposers.forEach(fn => fn());
41573
+ };
41574
+ };
41575
+
41576
+ /* begin_public_function
41577
+ id: notificationTraySeen.get
41578
+ */
41579
+ /**
41580
+ * ```js
41581
+ * import { getNotificationTraySeen } from '@amityco/ts-sdk';
41582
+ *
41583
+ * let notificationTraySeen;
41584
+ *
41585
+ * const unsubscribe = getNotificationTraySeen(userId, response => {
41586
+ * notificationTraySeen = response.data;
41587
+ * });
41588
+ * ```
41589
+ *
41590
+ * Observe all mutation on a given {@link Amity.NotificationTraySeen}
41591
+ *
41592
+ * @param userId the ID of the user to observe
41593
+ * @param callback the function to call when new data are available
41594
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
41595
+ *
41596
+ * @category NotificationTraySeen Live Object
41597
+ */
41598
+ const getNotificationTraySeen = (callback) => {
41599
+ const responder = (snapshot) => {
41600
+ const { data } = snapshot;
41601
+ callback(Object.assign(Object.assign({}, snapshot), { data }));
41602
+ };
41603
+ const { userId } = getActiveUser();
41604
+ return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
41605
+ onNotificationTraySeenUpdated,
41606
+ ]);
41607
+ };
41608
+ /* end_public_function */
41609
+
41610
+ /**
41611
+ * TODO: handle cache receive cache option, and cache policy
41612
+ * TODO: check if querybyIds is supported
41613
+ */
41614
+ class NotificationTrayItemsPaginationController extends PaginationController {
41615
+ async getRequest(queryParams, token) {
41616
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
41617
+ const options = token ? { token } : { limit };
41618
+ const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
41619
+ params: Object.assign(Object.assign({}, params), { options }),
41620
+ });
41621
+ return queryResponse;
41622
+ }
41623
+ }
41624
+
41625
+ class NotificationTrayItemsQuerystreamController extends QueryStreamController {
41626
+ constructor(query, cacheKey, notifyChange, preparePayload) {
41627
+ super(query, cacheKey);
41628
+ this.notifyChange = notifyChange;
41629
+ this.preparePayload = preparePayload;
41630
+ }
41631
+ async saveToMainDB(response) {
41632
+ const processedPayload = await this.preparePayload(response);
41633
+ const client = getActiveClient();
41634
+ const cachedAt = client.cache && Date.now();
41635
+ if (client.cache) {
41636
+ ingestInCache(processedPayload, { cachedAt });
41637
+ }
41638
+ }
41639
+ appendToQueryStream(response, direction, refresh = false) {
41640
+ var _a, _b;
41641
+ if (refresh) {
41642
+ pushToCache(this.cacheKey, {
41643
+ data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41644
+ });
41645
+ }
41646
+ else {
41647
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41648
+ const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
41649
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
41650
+ ...new Set([
41651
+ ...notifications,
41652
+ ...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
41653
+ ]),
41654
+ ] }));
41655
+ }
41656
+ }
41657
+ }
41658
+
41659
+ const prepareNotificationTrayItemsPayload = (rawPayload) => {
41660
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
41661
+ return Object.assign(Object.assign({}, rawPayload), { users });
41662
+ };
41663
+
41664
+ class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
41665
+ constructor(query, callback) {
41666
+ const queryStreamId = hash(query);
41667
+ const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
41668
+ const paginationController = new NotificationTrayItemsPaginationController(query);
41669
+ super(paginationController, queryStreamId, cacheKey, callback);
41670
+ this.query = query;
41671
+ this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
41672
+ this.callback = callback.bind(this);
41673
+ this.loadPage({ initial: true });
41674
+ }
41675
+ setup() {
41676
+ var _a;
41677
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41678
+ if (!collection) {
41679
+ pushToCache(this.cacheKey, {
41680
+ data: [],
41681
+ params: {},
41682
+ });
41683
+ }
41684
+ }
41685
+ async persistModel(queryPayload) {
41686
+ await this.queryStreamController.saveToMainDB(queryPayload);
41687
+ }
41688
+ persistQueryStream({ response, direction, refresh, }) {
41689
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
41690
+ }
41691
+ // eslint-disable-next-line class-methods-use-this
41692
+ startSubscription() {
41693
+ return [];
41694
+ }
41695
+ notifyChange({ origin, loading, error }) {
41696
+ var _a, _b;
41697
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41698
+ if (!collection)
41699
+ return;
41700
+ const data = ((_b = collection.data
41701
+ .map(id => pullFromCache(['notificationTrayItem', 'get', id]))
41702
+ .filter(isNonNullable)
41703
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
41704
+ if (!this.shouldNotify(data) && origin === 'event')
41705
+ return;
41706
+ this.callback({
41707
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
41708
+ data,
41709
+ hasNextPage: !!this.paginationController.getNextToken(),
41710
+ loading,
41711
+ error,
41712
+ });
41713
+ }
41714
+ }
41715
+
41716
+ /**
41717
+ * Get notification tray items for a notification tray page
41718
+ *
41719
+ * @param params the limit query parameters
41720
+ * @param callback the callback to be called when the notification tray items are updated
41721
+ * @returns items in the notification tray
41722
+ *
41723
+ * @category Notification tray items Live Collection
41724
+ *
41725
+ */
41726
+ const getNotificationTrayItems = (params, callback, config) => {
41727
+ const { log, cache } = getActiveClient();
41728
+ if (!cache) {
41729
+ console.log(ENABLE_CACHE_MESSAGE);
41730
+ }
41731
+ const timestamp = Date.now();
41732
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
41733
+ const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
41734
+ const disposers = notiTrayItemsLiveCollection.startSubscription();
41735
+ const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
41736
+ disposers.push(() => dropFromCache(cacheKey));
41737
+ return () => {
41738
+ log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
41739
+ disposers.forEach(fn => fn());
41740
+ };
41741
+ };
41742
+
41743
+ /* begin_public_function
41744
+ id: notificationTrayItem.markSeen
41745
+ */
41746
+ /**
41747
+ * ```js
41748
+ * import { notificationTray } from '@amityco/ts-sdk'
41749
+ * const updated = await notificationTray.markItemsSeen()
41750
+ * ```
41751
+ *
41752
+ * Updates an {@link Amity.NotificationItemSeen}
41753
+ *
41754
+ * @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
41755
+ * @returns the updated {@link Amity.NotificationItemSeen} object
41756
+ *
41757
+ * @category NotificationItemSeen API
41758
+ * @async
41759
+ */
41760
+ const markItemsSeen = async (patch) => {
41761
+ const client = getActiveClient();
41762
+ client.log('notificationTray/markItemsSeen', {});
41763
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
41764
+ patch,
41765
+ });
41766
+ const updatedData = patch.trayItems
41767
+ .map(patchItem => {
41768
+ var _a;
41769
+ const cacheData = (_a = pullFromCache([
41770
+ 'notificationTraySeen',
41771
+ 'get',
41772
+ patchItem.id,
41773
+ ])) === null || _a === void 0 ? void 0 : _a.data;
41774
+ if (!cacheData)
41775
+ return;
41776
+ const data = Object.assign(Object.assign({}, cacheData), payload);
41777
+ if (client.cache) {
41778
+ const cachedAt = Date.now();
41779
+ pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
41780
+ }
41781
+ return data;
41782
+ })
41783
+ .filter(Boolean);
41784
+ fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
41785
+ };
41786
+ /* end_public_function */
41787
+
41788
+ /* begin_public_function
41789
+ id: notificationTray.markSeen
41790
+ */
41791
+ /**
41792
+ * ```js
41793
+ * import { notificationTray } from '@amityco/ts-sdk'
41794
+ * const updated = await notificationTray.markTraySeen({
41795
+ * lastSeenAt: Amity.timestamp,
41796
+ * })
41797
+ * ```
41798
+ *
41799
+ * Updates an {@link Amity.NotificationTraySeen}
41800
+ *
41801
+ * @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
41802
+ * @param lastSeenAt The patch data to apply
41803
+ * @returns the updated {@link Amity.NotificationTraySeen} object
41804
+ *
41805
+ * @category Post API
41806
+ * @async
41807
+ */
41808
+ const markTraySeen = async (lastSeenAt) => {
41809
+ var _a;
41810
+ const client = getActiveClient();
41811
+ client.log('notificationTray/markTraySeen', {});
41812
+ const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
41813
+ lastSeenAt,
41814
+ });
41815
+ const cacheData = (_a = pullFromCache([
41816
+ 'notificationTraySeen',
41817
+ 'get',
41818
+ ])) === null || _a === void 0 ? void 0 : _a.data;
41819
+ const data = Object.assign({ userId: client.userId }, payload);
41820
+ const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
41821
+ const cachedAt = client.cache && Date.now();
41822
+ if (client.cache)
41823
+ pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
41824
+ fireEvent('local.notificationTraySeen.updated', data);
41825
+ return {
41826
+ data: payload,
41827
+ cachedAt,
41828
+ };
41829
+ };
41830
+ /* end_public_function */
41831
+
41832
+ var index = /*#__PURE__*/Object.freeze({
41833
+ __proto__: null,
41834
+ getNotificationTraySeen: getNotificationTraySeen,
41835
+ getNotificationTrayItems: getNotificationTrayItems,
41836
+ markItemsSeen: markItemsSeen,
41837
+ markTraySeen: markTraySeen,
41838
+ onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
41839
+ });
41840
+
41841
+ export { API_REGIONS, index$1 as AdRepository, index$9 as CategoryRepository, index$d as ChannelRepository, index$m as Client, index$7 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$a as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$8 as FeedRepository, FileAccessTypeEnum, index$j as FileRepository, FileType, index$3 as LiveStreamPlayer, MessageContentType, index$h as MessageRepository, index$4 as PollRepository, PostContentType, index$6 as PostRepository, index$i as ReactionRepository, index$2 as StoryRepository, index$5 as StreamRepository, index$g as SubChannelRepository, SubscriptionLevels, index$k as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };