@amityco/ts-sdk 7.1.1-53d7c83.0 → 7.1.1-611ceb49.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +5 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +18 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/readReceipt.d.ts +1 -12
- package/dist/@types/core/readReceipt.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +0 -10
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +81 -0
- package/dist/@types/domains/notification.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +0 -1
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/enableUnreadCount.d.ts.map +1 -1
- package/dist/client/api/login.d.ts.map +1 -1
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +4 -2
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +475 -586
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +451 -563
- package/dist/index.umd.js +4 -4
- package/dist/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.d.ts +2 -2
- package/dist/marker/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessage.d.ts.map +1 -1
- package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
- package/dist/notificationTrayRepository/api/index.d.ts +3 -0
- package/dist/notificationTrayRepository/api/index.d.ts.map +1 -0
- package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts +16 -0
- package/dist/notificationTrayRepository/api/markNotificationItemsSeen.d.ts.map +1 -0
- package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts +19 -0
- package/dist/notificationTrayRepository/api/markNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTrayRepository/events/index.d.ts +2 -0
- package/dist/notificationTrayRepository/events/index.d.ts.map +1 -0
- package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts +17 -0
- package/dist/notificationTrayRepository/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
- package/dist/notificationTrayRepository/index.d.ts +4 -0
- package/dist/notificationTrayRepository/index.d.ts.map +1 -0
- package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts +30 -0
- package/dist/notificationTrayRepository/internalApi/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts +12 -0
- package/dist/notificationTrayRepository/observers/getNotificationTrayItems.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts +21 -0
- package/dist/notificationTrayRepository/observers/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTrayRepository/observers/index.d.ts +3 -0
- package/dist/notificationTrayRepository/observers/index.d.ts.map +1 -0
- package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
- package/dist/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/notificationTrayLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/events.ts +6 -2
- package/src/@types/core/model.ts +6 -4
- package/src/@types/core/payload.ts +25 -0
- package/src/@types/core/readReceipt.ts +1 -14
- package/src/@types/domains/channel.ts +0 -13
- package/src/@types/domains/client.ts +0 -2
- package/src/@types/domains/notification.ts +90 -0
- package/src/channelRepository/events/onChannelDeleted.ts +4 -17
- package/src/channelRepository/events/onChannelLeft.ts +3 -11
- package/src/channelRepository/observers/getChannel.ts +1 -3
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +1 -6
- package/src/channelRepository/observers/index.ts +0 -1
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +2 -12
- package/src/channelRepository/utils/prepareChannelPayload.ts +17 -66
- package/src/client/api/createClient.ts +0 -3
- package/src/client/api/enableUnreadCount.ts +0 -1
- package/src/client/api/login.ts +1 -5
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +99 -74
- package/src/core/model/idResolvers.ts +3 -2
- package/src/core/model/index.ts +2 -0
- package/src/index.ts +2 -0
- package/src/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.ts +3 -3
- package/src/messageRepository/events/onMessageCreated.ts +1 -45
- package/src/messageRepository/observers/getMessage.ts +1 -0
- package/src/messageRepository/utils/markReadMessage.ts +3 -10
- package/src/notificationTrayRepository/api/index.ts +2 -0
- package/src/notificationTrayRepository/api/markNotificationItemsSeen.ts +59 -0
- package/src/notificationTrayRepository/api/markNotificationTraySeen.ts +65 -0
- package/src/notificationTrayRepository/events/index.ts +1 -0
- package/src/notificationTrayRepository/events/onNotificationTraySeenUpdated.ts +36 -0
- package/src/notificationTrayRepository/index.ts +3 -0
- package/src/notificationTrayRepository/internalApi/getNotificationTraySeen.ts +81 -0
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
- package/src/notificationTrayRepository/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
- package/src/notificationTrayRepository/observers/getNotificationTrayItems.ts +44 -0
- package/src/notificationTrayRepository/observers/getNotificationTraySeen.ts +43 -0
- package/src/notificationTrayRepository/observers/index.ts +2 -0
- package/src/notificationTrayRepository/utils/prepareNotificationTrayItemsPayload.ts +12 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/notificationTrayLinkedObject.ts +28 -0
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +0 -16
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +0 -1
- package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +0 -1
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts +0 -11
- package/dist/channelRepository/internalApi/getTotalChannelsUnread.d.ts.map +0 -1
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts +0 -20
- package/dist/channelRepository/observers/getTotalChannelsUnread.d.ts.map +0 -1
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +0 -2
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +0 -1
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts +0 -33
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +0 -1
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +0 -3
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +0 -1
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +0 -12
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +0 -1
- package/src/channelRepository/api/markChannelsAsReadBySegment.ts +0 -29
- package/src/channelRepository/internalApi/getTotalChannelsUnread.ts +0 -38
- package/src/channelRepository/observers/getTotalChannelsUnread.ts +0 -129
- package/src/channelRepository/utils/getLegacyChannelUnread.ts +0 -5
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +0 -267
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +0 -21
- package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +0 -29
package/dist/index.cjs.js
CHANGED
|
@@ -121,6 +121,7 @@ const SECOND$1 = 1000;
|
|
|
121
121
|
const MINUTE = 60 * SECOND$1;
|
|
122
122
|
const HOUR = 60 * MINUTE;
|
|
123
123
|
const DAY = 24 * HOUR;
|
|
124
|
+
const WEEK = 7 * DAY;
|
|
124
125
|
const YEAR = 365 * DAY;
|
|
125
126
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
126
127
|
|
|
@@ -516,7 +517,6 @@ const idResolvers = {
|
|
|
516
517
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
517
518
|
channelUnreadInfo: ({ channelId }) => channelId,
|
|
518
519
|
subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
|
|
519
|
-
channelUnread: ({ channelId }) => channelId,
|
|
520
520
|
channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
|
|
521
521
|
subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
|
|
522
522
|
messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
|
|
@@ -543,6 +543,8 @@ const idResolvers = {
|
|
|
543
543
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
544
544
|
pin: ({ placement, referenceId }) => `${placement}#${referenceId}`,
|
|
545
545
|
pinTarget: ({ targetId }) => targetId,
|
|
546
|
+
notificationTrayItem: ({ _id }) => _id,
|
|
547
|
+
notificationTraySeen: ({ userId }) => userId,
|
|
546
548
|
};
|
|
547
549
|
/**
|
|
548
550
|
* Retrieve the id resolver matching a domain name
|
|
@@ -594,6 +596,7 @@ const PAYLOAD2MODEL = {
|
|
|
594
596
|
advertisers: 'advertiser',
|
|
595
597
|
pinTargets: 'pinTarget',
|
|
596
598
|
pins: 'pin',
|
|
599
|
+
notificationTrayItems: 'notificationTrayItem',
|
|
597
600
|
};
|
|
598
601
|
/** hidden */
|
|
599
602
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -1610,13 +1613,13 @@ class NetworkActivitiesWatcher {
|
|
|
1610
1613
|
this._listener.clear();
|
|
1611
1614
|
}
|
|
1612
1615
|
}
|
|
1613
|
-
let instance$
|
|
1616
|
+
let instance$5;
|
|
1614
1617
|
var NetworkActivitiesWatcher$1 = {
|
|
1615
1618
|
getInstance: () => {
|
|
1616
|
-
if (!instance$
|
|
1617
|
-
instance$
|
|
1619
|
+
if (!instance$5) {
|
|
1620
|
+
instance$5 = new NetworkActivitiesWatcher();
|
|
1618
1621
|
}
|
|
1619
|
-
return instance$
|
|
1622
|
+
return instance$5;
|
|
1620
1623
|
},
|
|
1621
1624
|
};
|
|
1622
1625
|
|
|
@@ -5149,13 +5152,13 @@ class AnalyticsEngine {
|
|
|
5149
5152
|
this._eventCapturer.resetAllBuckets();
|
|
5150
5153
|
}
|
|
5151
5154
|
}
|
|
5152
|
-
let instance$
|
|
5155
|
+
let instance$4;
|
|
5153
5156
|
var AnalyticsEngine$1 = {
|
|
5154
5157
|
getInstance: () => {
|
|
5155
|
-
if (!instance$
|
|
5156
|
-
instance$
|
|
5158
|
+
if (!instance$4) {
|
|
5159
|
+
instance$4 = new AnalyticsEngine();
|
|
5157
5160
|
}
|
|
5158
|
-
return instance$
|
|
5161
|
+
return instance$4;
|
|
5159
5162
|
},
|
|
5160
5163
|
};
|
|
5161
5164
|
|
|
@@ -5581,223 +5584,6 @@ const getMessageReadCount = (message, marker) => {
|
|
|
5581
5584
|
getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
5582
5585
|
}; // and if not found in cache use default value `0`
|
|
5583
5586
|
|
|
5584
|
-
/**
|
|
5585
|
-
*
|
|
5586
|
-
* Mark subChannel as read by readToSegment
|
|
5587
|
-
*
|
|
5588
|
-
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
5589
|
-
* @param readToSegment the segment to mark as read
|
|
5590
|
-
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
5591
|
-
*
|
|
5592
|
-
* @category Channel API
|
|
5593
|
-
* @async
|
|
5594
|
-
*/
|
|
5595
|
-
const markChannelsAsReadBySegment = async (readings) => {
|
|
5596
|
-
const client = getActiveClient();
|
|
5597
|
-
try {
|
|
5598
|
-
await client.http.post('api/v3/channels/seen', { channels: readings });
|
|
5599
|
-
return true;
|
|
5600
|
-
}
|
|
5601
|
-
catch (e) {
|
|
5602
|
-
return false;
|
|
5603
|
-
}
|
|
5604
|
-
};
|
|
5605
|
-
|
|
5606
|
-
class MessageReadReceiptSyncEngine {
|
|
5607
|
-
constructor() {
|
|
5608
|
-
this.isActive = true;
|
|
5609
|
-
this.MAX_RETRY = 3;
|
|
5610
|
-
this.JOB_QUEUE_SIZE = 120;
|
|
5611
|
-
this.jobQueue = [];
|
|
5612
|
-
// Interval for message read receipt sync in seconds
|
|
5613
|
-
this.RECEIPT_SYNC_INTERVAL = 1;
|
|
5614
|
-
this.client = getActiveClient();
|
|
5615
|
-
// Get remaining unsync read receipts from cache
|
|
5616
|
-
this.getUnsyncJobs();
|
|
5617
|
-
}
|
|
5618
|
-
// Call this when client call client.login
|
|
5619
|
-
startSyncReadReceipt() {
|
|
5620
|
-
// Start timer when start receipt sync
|
|
5621
|
-
this.timer = setInterval(() => {
|
|
5622
|
-
this.syncReadReceipts();
|
|
5623
|
-
}, this.RECEIPT_SYNC_INTERVAL * 1000);
|
|
5624
|
-
}
|
|
5625
|
-
// Read receipt observer handling
|
|
5626
|
-
syncReadReceipts() {
|
|
5627
|
-
if (this.jobQueue.length === 0 || this.isActive === false)
|
|
5628
|
-
return;
|
|
5629
|
-
const readReceipts = this.getReadReceipts();
|
|
5630
|
-
if (readReceipts) {
|
|
5631
|
-
this.markReadApi(readReceipts);
|
|
5632
|
-
}
|
|
5633
|
-
}
|
|
5634
|
-
getUnsyncJobs() {
|
|
5635
|
-
var _a;
|
|
5636
|
-
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
5637
|
-
const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
5638
|
-
return data.latestSyncSegment < data.latestSegment;
|
|
5639
|
-
});
|
|
5640
|
-
// Enqueue unsync read receipts to the job queue
|
|
5641
|
-
readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
|
|
5642
|
-
this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
|
|
5643
|
-
});
|
|
5644
|
-
}
|
|
5645
|
-
getReadReceipts() {
|
|
5646
|
-
// get all read receipts from queue, now the queue is empty
|
|
5647
|
-
const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
|
|
5648
|
-
if (syncJob.length === 0)
|
|
5649
|
-
return;
|
|
5650
|
-
return syncJob.filter(job => {
|
|
5651
|
-
var _a;
|
|
5652
|
-
const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5653
|
-
if (!readReceipt)
|
|
5654
|
-
return false;
|
|
5655
|
-
if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
|
|
5656
|
-
return true;
|
|
5657
|
-
return false;
|
|
5658
|
-
});
|
|
5659
|
-
}
|
|
5660
|
-
async markReadApi(syncJobs) {
|
|
5661
|
-
var _a;
|
|
5662
|
-
// constuct payload
|
|
5663
|
-
// example: [{ channelId: 'channelId', readToSegment: 2 }]
|
|
5664
|
-
const syncJobsPayload = syncJobs.map(job => {
|
|
5665
|
-
return {
|
|
5666
|
-
channelId: job.channelId,
|
|
5667
|
-
readToSegment: job.segment,
|
|
5668
|
-
};
|
|
5669
|
-
});
|
|
5670
|
-
const response = await markChannelsAsReadBySegment(syncJobsPayload);
|
|
5671
|
-
if (response) {
|
|
5672
|
-
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
5673
|
-
// update lastestSyncSegment in read receipt cache
|
|
5674
|
-
const cacheKey = ['readReceipt', syncJobs[i].channelId];
|
|
5675
|
-
const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5676
|
-
pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
|
|
5677
|
-
}
|
|
5678
|
-
}
|
|
5679
|
-
else {
|
|
5680
|
-
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
5681
|
-
// push them back to queue if the syncing is failed and retry count is less than max retry
|
|
5682
|
-
if (syncJobs[i].retryCount >= this.MAX_RETRY)
|
|
5683
|
-
return;
|
|
5684
|
-
const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
|
|
5685
|
-
this.enqueueJob(updatedJob);
|
|
5686
|
-
}
|
|
5687
|
-
}
|
|
5688
|
-
}
|
|
5689
|
-
startObservingReadReceiptQueue() {
|
|
5690
|
-
if (this.client.useLegacyUnreadCount) {
|
|
5691
|
-
this.isActive = true;
|
|
5692
|
-
this.startSyncReadReceipt();
|
|
5693
|
-
}
|
|
5694
|
-
}
|
|
5695
|
-
stopObservingReadReceiptQueue() {
|
|
5696
|
-
this.isActive = false;
|
|
5697
|
-
this.jobQueue.map(job => {
|
|
5698
|
-
if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
5699
|
-
return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
|
|
5700
|
-
}
|
|
5701
|
-
return job;
|
|
5702
|
-
});
|
|
5703
|
-
if (this.timer)
|
|
5704
|
-
clearInterval(this.timer);
|
|
5705
|
-
}
|
|
5706
|
-
// Session Management
|
|
5707
|
-
onSessionEstablished() {
|
|
5708
|
-
this.startObservingReadReceiptQueue();
|
|
5709
|
-
}
|
|
5710
|
-
onSessionDestroyed() {
|
|
5711
|
-
this.stopObservingReadReceiptQueue();
|
|
5712
|
-
this.jobQueue = [];
|
|
5713
|
-
}
|
|
5714
|
-
onTokenExpired() {
|
|
5715
|
-
this.stopObservingReadReceiptQueue();
|
|
5716
|
-
}
|
|
5717
|
-
// Network Connection Management
|
|
5718
|
-
onNetworkOffline() {
|
|
5719
|
-
// Stop observing to the read receipt queue.
|
|
5720
|
-
this.stopObservingReadReceiptQueue();
|
|
5721
|
-
}
|
|
5722
|
-
onNetworkOnline() {
|
|
5723
|
-
// Resume observing to the read receipt queue.
|
|
5724
|
-
this.startObservingReadReceiptQueue();
|
|
5725
|
-
}
|
|
5726
|
-
markRead(channelId, segment) {
|
|
5727
|
-
var _a;
|
|
5728
|
-
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
5729
|
-
const cacheKey = ['channelUnread', 'get', channelId];
|
|
5730
|
-
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5731
|
-
if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
|
|
5732
|
-
channelUnread &&
|
|
5733
|
-
segment > channelUnread.readToSegment) {
|
|
5734
|
-
channelUnread.readToSegment = segment;
|
|
5735
|
-
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
5736
|
-
pushToCache(cacheKey, channelUnread);
|
|
5737
|
-
fireEvent('local.channelUnread.updated', channelUnread);
|
|
5738
|
-
}
|
|
5739
|
-
// Step 2: Enqueue the read receipt
|
|
5740
|
-
this.enqueueReadReceipt(channelId, segment);
|
|
5741
|
-
}
|
|
5742
|
-
enqueueReadReceipt(channelId, segment) {
|
|
5743
|
-
var _a;
|
|
5744
|
-
const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5745
|
-
// Create new read receipt if it's not exists and add the job to queue
|
|
5746
|
-
if (!readReceipt) {
|
|
5747
|
-
const readReceiptChannel = {
|
|
5748
|
-
channelId,
|
|
5749
|
-
latestSegment: segment,
|
|
5750
|
-
latestSyncSegment: 0,
|
|
5751
|
-
};
|
|
5752
|
-
pushToCache(['readReceipt', channelId], readReceiptChannel);
|
|
5753
|
-
}
|
|
5754
|
-
else if (readReceipt.latestSegment < segment) {
|
|
5755
|
-
// Update latestSegment in read receipt cache
|
|
5756
|
-
pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
5757
|
-
}
|
|
5758
|
-
else if (readReceipt.latestSyncSegment >= segment) {
|
|
5759
|
-
// Skip the job when lastSyncSegment > = segment
|
|
5760
|
-
return;
|
|
5761
|
-
}
|
|
5762
|
-
let syncJob = this.getSyncJob(channelId);
|
|
5763
|
-
if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
5764
|
-
syncJob = {
|
|
5765
|
-
channelId,
|
|
5766
|
-
segment,
|
|
5767
|
-
syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
|
|
5768
|
-
retryCount: 0,
|
|
5769
|
-
};
|
|
5770
|
-
this.enqueueJob(syncJob);
|
|
5771
|
-
}
|
|
5772
|
-
else if (syncJob.segment < segment) {
|
|
5773
|
-
syncJob.segment = segment;
|
|
5774
|
-
}
|
|
5775
|
-
}
|
|
5776
|
-
getSyncJob(channelId) {
|
|
5777
|
-
const { jobQueue } = this;
|
|
5778
|
-
const targetJob = jobQueue.find(job => job.channelId === channelId);
|
|
5779
|
-
return targetJob || null;
|
|
5780
|
-
}
|
|
5781
|
-
enqueueJob(syncJob) {
|
|
5782
|
-
if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
|
|
5783
|
-
this.jobQueue.push(syncJob);
|
|
5784
|
-
}
|
|
5785
|
-
else {
|
|
5786
|
-
// Remove oldest job when queue reach maximum capacity
|
|
5787
|
-
this.jobQueue.shift();
|
|
5788
|
-
this.jobQueue.push(syncJob);
|
|
5789
|
-
}
|
|
5790
|
-
}
|
|
5791
|
-
}
|
|
5792
|
-
let instance$4 = null;
|
|
5793
|
-
var ReadReceiptSyncEngine = {
|
|
5794
|
-
getInstance: () => {
|
|
5795
|
-
if (!instance$4)
|
|
5796
|
-
instance$4 = new MessageReadReceiptSyncEngine();
|
|
5797
|
-
return instance$4;
|
|
5798
|
-
},
|
|
5799
|
-
};
|
|
5800
|
-
|
|
5801
5587
|
/**
|
|
5802
5588
|
*
|
|
5803
5589
|
* Mark subChannel as read by readToSegment
|
|
@@ -5846,7 +5632,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
|
|
|
5846
5632
|
return channelUnreadInfo;
|
|
5847
5633
|
};
|
|
5848
5634
|
|
|
5849
|
-
class
|
|
5635
|
+
class MessageReadReceiptSyncEngine {
|
|
5850
5636
|
constructor() {
|
|
5851
5637
|
this.isActive = true;
|
|
5852
5638
|
this.MAX_RETRY = 3;
|
|
@@ -5877,7 +5663,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5877
5663
|
getUnsyncJobs() {
|
|
5878
5664
|
var _a;
|
|
5879
5665
|
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
5880
|
-
const readReceipts = (_a = queryCache(['
|
|
5666
|
+
const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
5881
5667
|
return data.latestSyncSegment < data.latestSegment;
|
|
5882
5668
|
});
|
|
5883
5669
|
// Enqueue unsync read receipts to the job queue
|
|
@@ -5896,7 +5682,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5896
5682
|
return;
|
|
5897
5683
|
// Get readReceipt from cache by subChannelId
|
|
5898
5684
|
const readReceipt = (_a = pullFromCache([
|
|
5899
|
-
'
|
|
5685
|
+
'readReceipt',
|
|
5900
5686
|
syncJob.subChannelId,
|
|
5901
5687
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5902
5688
|
if (!readReceipt)
|
|
@@ -5919,10 +5705,10 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5919
5705
|
if (response) {
|
|
5920
5706
|
this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
|
|
5921
5707
|
const readReceiptCache = (_a = pullFromCache([
|
|
5922
|
-
'
|
|
5708
|
+
'readReceipt',
|
|
5923
5709
|
subChannelId,
|
|
5924
5710
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5925
|
-
pushToCache(['
|
|
5711
|
+
pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
|
|
5926
5712
|
}
|
|
5927
5713
|
else if (!response) {
|
|
5928
5714
|
if (newSyncJob.retryCount > this.MAX_RETRY) {
|
|
@@ -5989,7 +5775,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5989
5775
|
subChannelUnreadInfo.readToSegment = segment;
|
|
5990
5776
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
5991
5777
|
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
5992
|
-
fireEvent('local.
|
|
5778
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
5993
5779
|
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
5994
5780
|
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
5995
5781
|
}
|
|
@@ -5998,10 +5784,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5998
5784
|
}
|
|
5999
5785
|
enqueueReadReceipt(subChannelId, segment) {
|
|
6000
5786
|
var _a;
|
|
6001
|
-
const readReceipt = (_a = pullFromCache([
|
|
6002
|
-
'legacyReadReceipt',
|
|
6003
|
-
subChannelId,
|
|
6004
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5787
|
+
const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6005
5788
|
// Create new read receipt if it's not exists and add job to queue
|
|
6006
5789
|
if (!readReceipt) {
|
|
6007
5790
|
const readReceiptSubChannel = {
|
|
@@ -6009,10 +5792,10 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
6009
5792
|
latestSegment: segment,
|
|
6010
5793
|
latestSyncSegment: 0,
|
|
6011
5794
|
};
|
|
6012
|
-
pushToCache(['
|
|
5795
|
+
pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
|
|
6013
5796
|
}
|
|
6014
5797
|
else if (readReceipt.latestSegment < segment) {
|
|
6015
|
-
pushToCache(['
|
|
5798
|
+
pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
6016
5799
|
}
|
|
6017
5800
|
else if (readReceipt.latestSyncSegment >= segment) {
|
|
6018
5801
|
// Skip the job when lastSyncSegment > = segment
|
|
@@ -6055,24 +5838,18 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
6055
5838
|
}
|
|
6056
5839
|
}
|
|
6057
5840
|
let instance$3 = null;
|
|
6058
|
-
var
|
|
5841
|
+
var ReadReceiptSyncEngine = {
|
|
6059
5842
|
getInstance: () => {
|
|
6060
5843
|
if (!instance$3)
|
|
6061
|
-
instance$3 = new
|
|
5844
|
+
instance$3 = new MessageReadReceiptSyncEngine();
|
|
6062
5845
|
return instance$3;
|
|
6063
5846
|
},
|
|
6064
5847
|
};
|
|
6065
5848
|
|
|
6066
5849
|
const markReadMessage = (message) => {
|
|
6067
|
-
const
|
|
6068
|
-
|
|
6069
|
-
|
|
6070
|
-
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
6071
|
-
}
|
|
6072
|
-
else {
|
|
6073
|
-
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
6074
|
-
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
6075
|
-
}
|
|
5850
|
+
const { subChannelId, channelSegment } = message;
|
|
5851
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
5852
|
+
markReadReceiptEngine.markRead(subChannelId, channelSegment);
|
|
6076
5853
|
};
|
|
6077
5854
|
|
|
6078
5855
|
const messageLinkedObject = (message) => {
|
|
@@ -6220,6 +5997,65 @@ const pinnedPostLinkedObject = (pinnedPost) => {
|
|
|
6220
5997
|
} });
|
|
6221
5998
|
};
|
|
6222
5999
|
|
|
6000
|
+
/* begin_public_function
|
|
6001
|
+
id: notificationTrayItem.markSeen
|
|
6002
|
+
*/
|
|
6003
|
+
/**
|
|
6004
|
+
* ```js
|
|
6005
|
+
* import { NotificationTrayRepository } from '@amityco/ts-sdk'
|
|
6006
|
+
* const updated = await NotificationTrayRepository.markNotificationItemsSeen()
|
|
6007
|
+
* ```
|
|
6008
|
+
*
|
|
6009
|
+
* Updates an {@link Amity.NotificationItemSeen}
|
|
6010
|
+
*
|
|
6011
|
+
* @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
|
|
6012
|
+
* @returns the updated {@link Amity.NotificationItemSeen} object
|
|
6013
|
+
*
|
|
6014
|
+
* @category NotificationItemSeen API
|
|
6015
|
+
* @async
|
|
6016
|
+
*/
|
|
6017
|
+
const markNotificationItemsSeen = async (patch) => {
|
|
6018
|
+
const client = getActiveClient();
|
|
6019
|
+
client.log('notificationTray/markNotificationItemsSeen', {});
|
|
6020
|
+
const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
|
|
6021
|
+
patch,
|
|
6022
|
+
});
|
|
6023
|
+
const updatedData = patch.trayItems
|
|
6024
|
+
.map(patchItem => {
|
|
6025
|
+
var _a;
|
|
6026
|
+
const cacheData = (_a = pullFromCache([
|
|
6027
|
+
'notificationTraySeen',
|
|
6028
|
+
'get',
|
|
6029
|
+
patchItem.id,
|
|
6030
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6031
|
+
if (!cacheData)
|
|
6032
|
+
return;
|
|
6033
|
+
const data = Object.assign(Object.assign({}, cacheData), payload);
|
|
6034
|
+
if (client.cache) {
|
|
6035
|
+
const cachedAt = Date.now();
|
|
6036
|
+
pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
|
|
6037
|
+
}
|
|
6038
|
+
return data;
|
|
6039
|
+
})
|
|
6040
|
+
.filter(Boolean);
|
|
6041
|
+
fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
|
|
6042
|
+
};
|
|
6043
|
+
/* end_public_function */
|
|
6044
|
+
|
|
6045
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
6046
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccuredAt, isRecent: new Date(noti.lastOccuredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
6047
|
+
.map(userId => { var _a; return (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
6048
|
+
.filter(isNonNullable)
|
|
6049
|
+
.map(user => userLinkedObject(user)), markRead: () => markNotificationItemsSeen({
|
|
6050
|
+
trayItems: [
|
|
6051
|
+
{
|
|
6052
|
+
id: noti._id,
|
|
6053
|
+
lastSeenAt: noti.lastSeenAt,
|
|
6054
|
+
},
|
|
6055
|
+
],
|
|
6056
|
+
}) });
|
|
6057
|
+
};
|
|
6058
|
+
|
|
6223
6059
|
const LinkedObject = {
|
|
6224
6060
|
ad: adLinkedObject,
|
|
6225
6061
|
comment: commentLinkedObject,
|
|
@@ -6233,6 +6069,7 @@ const LinkedObject = {
|
|
|
6233
6069
|
reactor: reactorLinkedObject,
|
|
6234
6070
|
channel: channelLinkedObject,
|
|
6235
6071
|
pinnedPost: pinnedPostLinkedObject,
|
|
6072
|
+
notificationTray: notificationTrayLinkedObject,
|
|
6236
6073
|
};
|
|
6237
6074
|
|
|
6238
6075
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -7060,31 +6897,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
7060
6897
|
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
7061
6898
|
});
|
|
7062
6899
|
};
|
|
7063
|
-
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
7064
|
-
for (let i = 0; i < channels.length; i += 1) {
|
|
7065
|
-
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
7066
|
-
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
7067
|
-
let unreadCount = 0;
|
|
7068
|
-
let readToSegment = null;
|
|
7069
|
-
let lastMentionedSegment = null;
|
|
7070
|
-
let isMentioned = false;
|
|
7071
|
-
if (channelUser) {
|
|
7072
|
-
readToSegment = channelUser.readToSegment;
|
|
7073
|
-
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
7074
|
-
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
7075
|
-
isMentioned = lastMentionedSegment > readToSegment;
|
|
7076
|
-
}
|
|
7077
|
-
pushToCache(cacheKey, {
|
|
7078
|
-
channelId: channels[i].channelId,
|
|
7079
|
-
lastSegment: channels[i].messageCount,
|
|
7080
|
-
readToSegment,
|
|
7081
|
-
lastMentionedSegment,
|
|
7082
|
-
unreadCount,
|
|
7083
|
-
isMentioned,
|
|
7084
|
-
isDeleted: channels[i].isDeleted,
|
|
7085
|
-
});
|
|
7086
|
-
}
|
|
7087
|
-
};
|
|
7088
6900
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
7089
6901
|
const client = getActiveClient();
|
|
7090
6902
|
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
@@ -7094,34 +6906,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
7094
6906
|
rawPayload.messagePreviews.length > 0) {
|
|
7095
6907
|
updateChannelMessagePreviewCache(rawPayload);
|
|
7096
6908
|
}
|
|
7097
|
-
|
|
7098
|
-
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
if (markerIds.length > 0) {
|
|
7110
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
7111
|
-
preUpdateChannelCache(rawPayload, {
|
|
7112
|
-
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
7113
|
-
});
|
|
7114
|
-
try {
|
|
7115
|
-
await getChannelMarkers(markerIds);
|
|
7116
|
-
}
|
|
7117
|
-
catch (e) {
|
|
7118
|
-
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
7119
|
-
}
|
|
6909
|
+
const markerIds = rawPayload.channels
|
|
6910
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
6911
|
+
.filter(isUnreadCountSupport)
|
|
6912
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
6913
|
+
if (markerIds.length > 0) {
|
|
6914
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
6915
|
+
preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
|
|
6916
|
+
try {
|
|
6917
|
+
await getChannelMarkers(markerIds);
|
|
6918
|
+
}
|
|
6919
|
+
catch (e) {
|
|
6920
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
7120
6921
|
}
|
|
7121
6922
|
}
|
|
7122
|
-
//
|
|
6923
|
+
// attach marker to channel
|
|
7123
6924
|
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
7124
|
-
//
|
|
6925
|
+
// user marker to channel users
|
|
7125
6926
|
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
7126
6927
|
return convertRawMembershipToMembership(channelUser);
|
|
7127
6928
|
});
|
|
@@ -7248,28 +7049,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
7248
7049
|
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
7249
7050
|
};
|
|
7250
7051
|
|
|
7251
|
-
const getLegacyChannelUnread = (channelId) => {
|
|
7252
|
-
var _a;
|
|
7253
|
-
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7254
|
-
};
|
|
7255
|
-
|
|
7256
7052
|
const constructChannelDynamicValue = (channel) => {
|
|
7257
|
-
const client = getActiveClient();
|
|
7258
7053
|
const rest = __rest(channel, ["messageCount"]);
|
|
7259
7054
|
return shallowClone(rest, {
|
|
7260
|
-
get
|
|
7261
|
-
|
|
7262
|
-
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
7055
|
+
get isMentioned() {
|
|
7056
|
+
return getChannelIsMentioned(rest);
|
|
7263
7057
|
},
|
|
7264
7058
|
get subChannelsUnreadCount() {
|
|
7265
7059
|
return getSubChannelsUnreadCount(rest);
|
|
7266
7060
|
},
|
|
7267
|
-
get isMentioned() {
|
|
7268
|
-
var _a, _b;
|
|
7269
|
-
if (client.useLegacyUnreadCount)
|
|
7270
|
-
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
7271
|
-
return getChannelIsMentioned(rest);
|
|
7272
|
-
},
|
|
7273
7061
|
});
|
|
7274
7062
|
};
|
|
7275
7063
|
|
|
@@ -7926,21 +7714,12 @@ const onChannelDeleted = (callback) => {
|
|
|
7926
7714
|
const client = getActiveClient();
|
|
7927
7715
|
const filter = async (payload) => {
|
|
7928
7716
|
const data = await prepareChannelPayload(payload);
|
|
7929
|
-
|
|
7930
|
-
|
|
7931
|
-
data.channels.forEach(channel => {
|
|
7932
|
-
if (isConsistentMode) {
|
|
7717
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
7718
|
+
data.channels.forEach(channel => {
|
|
7933
7719
|
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
7934
7720
|
deleteChannelUnreadByChannelId(channel.channelId);
|
|
7935
|
-
}
|
|
7936
|
-
|
|
7937
|
-
const cacheKey = ['channelUnread', 'get', channel.channelId];
|
|
7938
|
-
const cache = pullFromCache(cacheKey);
|
|
7939
|
-
if (cache) {
|
|
7940
|
-
pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
|
|
7941
|
-
}
|
|
7942
|
-
}
|
|
7943
|
-
});
|
|
7721
|
+
});
|
|
7722
|
+
}
|
|
7944
7723
|
ingestInCache(data);
|
|
7945
7724
|
callbacks$b.forEach(cb => cb(data.channels[0]));
|
|
7946
7725
|
};
|
|
@@ -8054,25 +7833,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
|
|
|
8054
7833
|
};
|
|
8055
7834
|
};
|
|
8056
7835
|
|
|
8057
|
-
var legacyReadReceiptSyncEngineOnLoginHandler = () => {
|
|
8058
|
-
const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
8059
|
-
readReceiptSyncEngine.startSyncReadReceipt();
|
|
8060
|
-
onSessionStateChange(state => {
|
|
8061
|
-
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
8062
|
-
readReceiptSyncEngine.onSessionEstablished();
|
|
8063
|
-
}
|
|
8064
|
-
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8065
|
-
readReceiptSyncEngine.onTokenExpired();
|
|
8066
|
-
}
|
|
8067
|
-
else {
|
|
8068
|
-
readReceiptSyncEngine.onSessionDestroyed();
|
|
8069
|
-
}
|
|
8070
|
-
});
|
|
8071
|
-
return () => {
|
|
8072
|
-
readReceiptSyncEngine.onSessionDestroyed();
|
|
8073
|
-
};
|
|
8074
|
-
};
|
|
8075
|
-
|
|
8076
7836
|
const onOnline = (callback) => {
|
|
8077
7837
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
8078
7838
|
window.addEventListener('online', callback);
|
|
@@ -8639,17 +8399,10 @@ const onChannelLeft = (callback) => {
|
|
|
8639
8399
|
const preparedPayload = await prepareChannelPayload(payload, {
|
|
8640
8400
|
isMessagePreviewUpdated: isLeftByMe,
|
|
8641
8401
|
});
|
|
8642
|
-
|
|
8643
|
-
const isLegacyUnreadCount = client.useLegacyUnreadCount;
|
|
8644
|
-
if (isLeftByMe) {
|
|
8402
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
|
|
8645
8403
|
preparedPayload.channels.forEach(channel => {
|
|
8646
|
-
|
|
8647
|
-
|
|
8648
|
-
deleteChannelUnreadByChannelId(channel.channelId);
|
|
8649
|
-
}
|
|
8650
|
-
else if (isLegacyUnreadCount) {
|
|
8651
|
-
dropFromCache(['channelUnread', 'get', channel.channelId]);
|
|
8652
|
-
}
|
|
8404
|
+
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
8405
|
+
deleteChannelUnreadByChannelId(channel.channelId);
|
|
8653
8406
|
});
|
|
8654
8407
|
}
|
|
8655
8408
|
const { channels, channelUsers } = preparedPayload;
|
|
@@ -8917,34 +8670,6 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
8917
8670
|
reCalculateChannelUnreadInfo(message.channelId);
|
|
8918
8671
|
});
|
|
8919
8672
|
}
|
|
8920
|
-
if (client.useLegacyUnreadCount) {
|
|
8921
|
-
rawPayload.messages.forEach(message => {
|
|
8922
|
-
var _a, _b;
|
|
8923
|
-
const channelUnread = (_a = pullFromCache([
|
|
8924
|
-
'channelUnread',
|
|
8925
|
-
'get',
|
|
8926
|
-
message.channelId,
|
|
8927
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8928
|
-
if (!channelUnread ||
|
|
8929
|
-
channelUnread.lastSegment >= message.segment ||
|
|
8930
|
-
typeof channelUnread.readToSegment !== 'number' ||
|
|
8931
|
-
typeof channelUnread.lastMentionSegment !== 'number')
|
|
8932
|
-
return;
|
|
8933
|
-
const lastSegment = message.segment;
|
|
8934
|
-
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
8935
|
-
return (mention.type === 'channel' ||
|
|
8936
|
-
(mention.type === 'user' &&
|
|
8937
|
-
client.userId &&
|
|
8938
|
-
mention.userPublicIds.includes(client.userId)));
|
|
8939
|
-
});
|
|
8940
|
-
const lastMentionSegment = isMentionedInMessage
|
|
8941
|
-
? message.segment
|
|
8942
|
-
: channelUnread.lastMentionSegment;
|
|
8943
|
-
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionSegment) });
|
|
8944
|
-
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
8945
|
-
fireEvent('local.channelUnread.updated', updatedChannelUnread);
|
|
8946
|
-
});
|
|
8947
|
-
}
|
|
8948
8673
|
// Update in cache
|
|
8949
8674
|
ingestInCache(payload);
|
|
8950
8675
|
payload.messages.forEach(message => {
|
|
@@ -9120,7 +8845,6 @@ const enableUnreadCount = () => {
|
|
|
9120
8845
|
if (client.isUnreadCountEnabled)
|
|
9121
8846
|
return false;
|
|
9122
8847
|
client.isUnreadCountEnabled = true;
|
|
9123
|
-
client.useLegacyUnreadCount = false;
|
|
9124
8848
|
client.emitter.emit('unreadCountEnabled', true);
|
|
9125
8849
|
return true;
|
|
9126
8850
|
};
|
|
@@ -9436,12 +9160,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
9436
9160
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9437
9161
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9438
9162
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9439
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9440
|
-
if (client.useLegacyUnreadCount) {
|
|
9441
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9442
|
-
}
|
|
9443
|
-
else
|
|
9444
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
9163
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9445
9164
|
const markerSyncUnsubscriber = await startMarkerSync();
|
|
9446
9165
|
subscriptions.push(markerSyncUnsubscriber);
|
|
9447
9166
|
}
|
|
@@ -9622,8 +9341,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9622
9341
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
9623
9342
|
const sessionHandler = undefined;
|
|
9624
9343
|
const isUnreadCountEnabled = false;
|
|
9625
|
-
// Legacy unread count is true by default
|
|
9626
|
-
const useLegacyUnreadCount = true;
|
|
9627
9344
|
const client = {
|
|
9628
9345
|
version: `${VERSION}`,
|
|
9629
9346
|
apiKey,
|
|
@@ -9653,7 +9370,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9653
9370
|
getMessagePreviewSetting,
|
|
9654
9371
|
use: () => setActiveClient(client),
|
|
9655
9372
|
isUnreadCountEnabled,
|
|
9656
|
-
useLegacyUnreadCount,
|
|
9657
9373
|
getMarkerSyncConsistentMode,
|
|
9658
9374
|
/**
|
|
9659
9375
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
@@ -10124,7 +9840,7 @@ const getUserUnread = (callback) => {
|
|
|
10124
9840
|
};
|
|
10125
9841
|
};
|
|
10126
9842
|
|
|
10127
|
-
var index$
|
|
9843
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
10128
9844
|
__proto__: null,
|
|
10129
9845
|
getActiveClient: getActiveClient,
|
|
10130
9846
|
getActiveUser: getActiveUser,
|
|
@@ -11331,7 +11047,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
11331
11047
|
};
|
|
11332
11048
|
/* end_public_function */
|
|
11333
11049
|
|
|
11334
|
-
var index$
|
|
11050
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
11335
11051
|
__proto__: null,
|
|
11336
11052
|
blockUser: blockUser,
|
|
11337
11053
|
unBlockUser: unBlockUser,
|
|
@@ -12346,9 +12062,9 @@ var AmityUserSearchMatchType;
|
|
|
12346
12062
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
12347
12063
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
12348
12064
|
|
|
12349
|
-
var index$
|
|
12065
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
12350
12066
|
__proto__: null,
|
|
12351
|
-
Relationship: index$
|
|
12067
|
+
Relationship: index$l,
|
|
12352
12068
|
getUserByIds: getUserByIds,
|
|
12353
12069
|
updateUser: updateUser,
|
|
12354
12070
|
flagUser: flagUser,
|
|
@@ -12612,7 +12328,7 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
12612
12328
|
};
|
|
12613
12329
|
/* end_public_function */
|
|
12614
12330
|
|
|
12615
|
-
var index$
|
|
12331
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
12616
12332
|
__proto__: null,
|
|
12617
12333
|
getFile: getFile,
|
|
12618
12334
|
uploadFile: uploadFile,
|
|
@@ -14424,7 +14140,7 @@ const getReactions = (params, callback, config) => {
|
|
|
14424
14140
|
};
|
|
14425
14141
|
/* end_public_function */
|
|
14426
14142
|
|
|
14427
|
-
var index$
|
|
14143
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
14428
14144
|
__proto__: null,
|
|
14429
14145
|
addReaction: addReaction,
|
|
14430
14146
|
removeReaction: removeReaction,
|
|
@@ -16240,7 +15956,7 @@ const getMessages = (params, callback, config) => {
|
|
|
16240
15956
|
};
|
|
16241
15957
|
/* end_public_function */
|
|
16242
15958
|
|
|
16243
|
-
var index$
|
|
15959
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
16244
15960
|
__proto__: null,
|
|
16245
15961
|
createMessage: createMessage,
|
|
16246
15962
|
updateMessage: updateMessage,
|
|
@@ -16766,7 +16482,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
16766
16482
|
};
|
|
16767
16483
|
/* end_public_function */
|
|
16768
16484
|
|
|
16769
|
-
var index$
|
|
16485
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
16770
16486
|
__proto__: null,
|
|
16771
16487
|
getSubChannelByIds: getSubChannels$1,
|
|
16772
16488
|
createSubChannel: createSubChannel,
|
|
@@ -16787,37 +16503,19 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
16787
16503
|
/**
|
|
16788
16504
|
* Internal used only
|
|
16789
16505
|
*
|
|
16790
|
-
* Fired when an {@link Amity.
|
|
16791
|
-
*
|
|
16792
|
-
* @param callback The function to call when the event was fired
|
|
16793
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16794
|
-
*
|
|
16795
|
-
* @category ChannelMarker Events
|
|
16796
|
-
*/
|
|
16797
|
-
const onChannelUnreadInfoUpdatedLocal = (callback) => {
|
|
16798
|
-
const client = getActiveClient();
|
|
16799
|
-
const filter = (payload) => {
|
|
16800
|
-
callback(payload);
|
|
16801
|
-
};
|
|
16802
|
-
return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
|
|
16803
|
-
};
|
|
16804
|
-
|
|
16805
|
-
/**
|
|
16806
|
-
* Internal used only
|
|
16807
|
-
*
|
|
16808
|
-
* Fired when an {@link Amity.ChannelUnread} has been updated.
|
|
16506
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
16809
16507
|
*
|
|
16810
16508
|
* @param callback The function to call when the event was fired
|
|
16811
16509
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16812
16510
|
*
|
|
16813
|
-
* @category
|
|
16511
|
+
* @category MessageMarker Events
|
|
16814
16512
|
*/
|
|
16815
16513
|
const onChannelUnreadUpdatedLocal = (callback) => {
|
|
16816
16514
|
const client = getActiveClient();
|
|
16817
16515
|
const filter = (payload) => {
|
|
16818
16516
|
callback(payload);
|
|
16819
16517
|
};
|
|
16820
|
-
return createEventSubscriber(client, '
|
|
16518
|
+
return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
|
|
16821
16519
|
};
|
|
16822
16520
|
|
|
16823
16521
|
/* begin_public_function
|
|
@@ -17019,7 +16717,6 @@ const getChannel = (channelId, callback) => {
|
|
|
17019
16717
|
return onSubChannelUpdated(updateMessagePreview);
|
|
17020
16718
|
}, 'channelId', 'channel'),
|
|
17021
16719
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
17022
|
-
convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
17023
16720
|
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
17024
16721
|
], {
|
|
17025
16722
|
forceDispatch: true,
|
|
@@ -17533,10 +17230,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
17533
17230
|
},
|
|
17534
17231
|
action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
|
|
17535
17232
|
},
|
|
17536
|
-
{
|
|
17537
|
-
fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
17538
|
-
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
17539
|
-
},
|
|
17540
17233
|
{
|
|
17541
17234
|
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
17542
17235
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -17591,130 +17284,16 @@ const getChannels = (params, callback, config) => {
|
|
|
17591
17284
|
log(`getChannels(tmpid: ${timestamp}) > listen`);
|
|
17592
17285
|
const channelLiveCollection = new ChannelLiveCollectionController(params, callback);
|
|
17593
17286
|
const disposers = channelLiveCollection.startSubscription();
|
|
17594
|
-
const cacheKey = channelLiveCollection.getCacheKey();
|
|
17595
|
-
disposers.push(() => {
|
|
17596
|
-
dropFromCache(cacheKey);
|
|
17597
|
-
});
|
|
17598
|
-
return () => {
|
|
17599
|
-
log(`getChannels(tmpid: ${timestamp}) > dispose`);
|
|
17600
|
-
disposers.forEach(fn => fn());
|
|
17601
|
-
};
|
|
17602
|
-
};
|
|
17603
|
-
/* end_public_function */
|
|
17604
|
-
|
|
17605
|
-
/**
|
|
17606
|
-
*
|
|
17607
|
-
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
17608
|
-
*
|
|
17609
|
-
* @returns the {@link Amity.UserUnread} objects
|
|
17610
|
-
*
|
|
17611
|
-
* @category Channel API
|
|
17612
|
-
* @async
|
|
17613
|
-
*/
|
|
17614
|
-
const getTotalChannelsUnread$1 = () => {
|
|
17615
|
-
var _a;
|
|
17616
|
-
const client = getActiveClient();
|
|
17617
|
-
client.log('channel/getTotalChannelsUnread.locally');
|
|
17618
|
-
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
17619
|
-
return !data.isDeleted;
|
|
17620
|
-
})) || [];
|
|
17621
|
-
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
17622
|
-
acc.unreadCount += data.unreadCount;
|
|
17623
|
-
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
17624
|
-
return acc;
|
|
17625
|
-
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
17626
|
-
const cachedAt = client.cache && Date.now();
|
|
17627
|
-
return {
|
|
17628
|
-
data: totalChannelsUnread,
|
|
17629
|
-
cachedAt,
|
|
17630
|
-
};
|
|
17631
|
-
};
|
|
17632
|
-
|
|
17633
|
-
/* begin_public_function
|
|
17634
|
-
id: totalChannelsUnread.get
|
|
17635
|
-
*/
|
|
17636
|
-
/**
|
|
17637
|
-
* ```js
|
|
17638
|
-
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
17639
|
-
*
|
|
17640
|
-
* let totalChannelsUnread;
|
|
17641
|
-
*
|
|
17642
|
-
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
17643
|
-
* unread = response.data;
|
|
17644
|
-
* });
|
|
17645
|
-
* ```
|
|
17646
|
-
*
|
|
17647
|
-
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
17648
|
-
*
|
|
17649
|
-
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
17650
|
-
*
|
|
17651
|
-
* @category User Unread Live Object
|
|
17652
|
-
*
|
|
17653
|
-
*/
|
|
17654
|
-
const getTotalChannelsUnread = (callback) => {
|
|
17655
|
-
const { _id: userId } = getActiveUser();
|
|
17656
|
-
if (!userId)
|
|
17657
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
17658
|
-
const { log, cache } = getActiveClient();
|
|
17659
|
-
if (!cache) {
|
|
17660
|
-
console.log('For using Live Object feature you need to enable Cache!');
|
|
17661
|
-
}
|
|
17662
|
-
const timestamp = Date.now();
|
|
17663
|
-
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
17664
|
-
const disposers = [];
|
|
17665
|
-
let isUnsyncedModel = false; // for messages
|
|
17666
|
-
let model;
|
|
17667
|
-
const dispatcher = (data) => {
|
|
17668
|
-
const { data: userUnread } = data;
|
|
17669
|
-
const callbackModel = userUnread
|
|
17670
|
-
? {
|
|
17671
|
-
unreadCount: userUnread.unreadCount,
|
|
17672
|
-
isMentioned: userUnread.isMentioned,
|
|
17673
|
-
}
|
|
17674
|
-
: undefined;
|
|
17675
|
-
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
17676
|
-
callback({
|
|
17677
|
-
data: callbackModel
|
|
17678
|
-
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
17679
|
-
loading: data.loading,
|
|
17680
|
-
error: data.error,
|
|
17681
|
-
});
|
|
17682
|
-
};
|
|
17683
|
-
const realtimeRouter = (userUnread) => {
|
|
17684
|
-
if (isEqual(model, userUnread))
|
|
17685
|
-
return;
|
|
17686
|
-
dispatcher({
|
|
17687
|
-
loading: false,
|
|
17688
|
-
data: userUnread,
|
|
17689
|
-
});
|
|
17690
|
-
};
|
|
17691
|
-
const onFetch = () => {
|
|
17692
|
-
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
17693
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
17694
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
17695
|
-
dispatcher({
|
|
17696
|
-
data,
|
|
17697
|
-
origin,
|
|
17698
|
-
loading: false,
|
|
17699
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
17700
|
-
});
|
|
17701
|
-
isUnsyncedModel = true;
|
|
17702
|
-
disposers.forEach(fn => fn());
|
|
17703
|
-
}
|
|
17704
|
-
else if (!isUnsyncedModel) {
|
|
17705
|
-
dispatcher({ loading, data, origin, error });
|
|
17706
|
-
}
|
|
17707
|
-
if (error) {
|
|
17708
|
-
disposers.forEach(fn => fn());
|
|
17709
|
-
}
|
|
17710
|
-
});
|
|
17711
|
-
};
|
|
17712
|
-
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
17713
|
-
onFetch();
|
|
17287
|
+
const cacheKey = channelLiveCollection.getCacheKey();
|
|
17288
|
+
disposers.push(() => {
|
|
17289
|
+
dropFromCache(cacheKey);
|
|
17290
|
+
});
|
|
17714
17291
|
return () => {
|
|
17292
|
+
log(`getChannels(tmpid: ${timestamp}) > dispose`);
|
|
17715
17293
|
disposers.forEach(fn => fn());
|
|
17716
17294
|
};
|
|
17717
|
-
};
|
|
17295
|
+
};
|
|
17296
|
+
/* end_public_function */
|
|
17718
17297
|
|
|
17719
17298
|
/* begin_public_function
|
|
17720
17299
|
id: channel.member.add
|
|
@@ -18080,7 +17659,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
18080
17659
|
};
|
|
18081
17660
|
/* end_public_function */
|
|
18082
17661
|
|
|
18083
|
-
var index$
|
|
17662
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
18084
17663
|
__proto__: null,
|
|
18085
17664
|
addMembers: addMembers$1,
|
|
18086
17665
|
removeMembers: removeMembers$1,
|
|
@@ -18283,7 +17862,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
18283
17862
|
};
|
|
18284
17863
|
/* end_public_function */
|
|
18285
17864
|
|
|
18286
|
-
var index$
|
|
17865
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
18287
17866
|
__proto__: null,
|
|
18288
17867
|
addRole: addRole,
|
|
18289
17868
|
removeRole: removeRole,
|
|
@@ -18293,10 +17872,10 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
18293
17872
|
unmuteMembers: unmuteMembers
|
|
18294
17873
|
});
|
|
18295
17874
|
|
|
18296
|
-
var index$
|
|
17875
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
18297
17876
|
__proto__: null,
|
|
18298
|
-
Membership: index$
|
|
18299
|
-
Moderation: index$
|
|
17877
|
+
Membership: index$f,
|
|
17878
|
+
Moderation: index$e,
|
|
18300
17879
|
getChannelByIds: getChannelByIds$1,
|
|
18301
17880
|
createChannel: createChannel,
|
|
18302
17881
|
updateChannel: updateChannel,
|
|
@@ -18319,7 +17898,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
18319
17898
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
18320
17899
|
getChannel: getChannel,
|
|
18321
17900
|
getChannels: getChannels,
|
|
18322
|
-
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
18323
17901
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
18324
17902
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
18325
17903
|
convertFromRaw: convertFromRaw,
|
|
@@ -19676,7 +19254,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
19676
19254
|
};
|
|
19677
19255
|
/* end_public_function */
|
|
19678
19256
|
|
|
19679
|
-
var index$
|
|
19257
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
19680
19258
|
__proto__: null,
|
|
19681
19259
|
addMembers: addMembers,
|
|
19682
19260
|
removeMembers: removeMembers,
|
|
@@ -20701,7 +20279,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
20701
20279
|
};
|
|
20702
20280
|
/* end_public_function */
|
|
20703
20281
|
|
|
20704
|
-
var index$
|
|
20282
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
20705
20283
|
__proto__: null,
|
|
20706
20284
|
addRoles: addRoles,
|
|
20707
20285
|
removeRoles: removeRoles,
|
|
@@ -20709,10 +20287,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
20709
20287
|
unbanMembers: unbanMembers
|
|
20710
20288
|
});
|
|
20711
20289
|
|
|
20712
|
-
var index$
|
|
20290
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
20713
20291
|
__proto__: null,
|
|
20714
|
-
Moderation: index$
|
|
20715
|
-
Membership: index$
|
|
20292
|
+
Moderation: index$b,
|
|
20293
|
+
Membership: index$c,
|
|
20716
20294
|
getCommunityByIds: getCommunities$1,
|
|
20717
20295
|
createCommunity: createCommunity,
|
|
20718
20296
|
updateCommunity: updateCommunity,
|
|
@@ -20945,7 +20523,7 @@ const getCategories = (params, callback, config) => {
|
|
|
20945
20523
|
};
|
|
20946
20524
|
/* end_public_function */
|
|
20947
20525
|
|
|
20948
|
-
var index$
|
|
20526
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
20949
20527
|
__proto__: null,
|
|
20950
20528
|
getCategory: getCategory,
|
|
20951
20529
|
getCategories: getCategories
|
|
@@ -21113,7 +20691,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
21113
20691
|
: undefined;
|
|
21114
20692
|
};
|
|
21115
20693
|
|
|
21116
|
-
var index$
|
|
20694
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
21117
20695
|
__proto__: null,
|
|
21118
20696
|
queryGlobalFeed: queryGlobalFeed,
|
|
21119
20697
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -22428,7 +22006,7 @@ const getComments = (params, callback, config) => {
|
|
|
22428
22006
|
};
|
|
22429
22007
|
/* end_public_function */
|
|
22430
22008
|
|
|
22431
|
-
var index$
|
|
22009
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
22432
22010
|
__proto__: null,
|
|
22433
22011
|
getCommentByIds: getCommentByIds,
|
|
22434
22012
|
createComment: createComment,
|
|
@@ -23435,7 +23013,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
23435
23013
|
};
|
|
23436
23014
|
};
|
|
23437
23015
|
|
|
23438
|
-
var index$
|
|
23016
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
23439
23017
|
__proto__: null,
|
|
23440
23018
|
getPostByIds: getPostByIds,
|
|
23441
23019
|
createPost: createPost,
|
|
@@ -23969,7 +23547,7 @@ const getStreams = (params, callback, config) => {
|
|
|
23969
23547
|
};
|
|
23970
23548
|
};
|
|
23971
23549
|
|
|
23972
|
-
var index$
|
|
23550
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
23973
23551
|
__proto__: null,
|
|
23974
23552
|
createStream: createStream,
|
|
23975
23553
|
updateStream: updateStream,
|
|
@@ -24256,7 +23834,7 @@ const getPoll = (pollId, callback) => {
|
|
|
24256
23834
|
};
|
|
24257
23835
|
/* end_public_function */
|
|
24258
23836
|
|
|
24259
|
-
var index$
|
|
23837
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
24260
23838
|
__proto__: null,
|
|
24261
23839
|
createPoll: createPoll,
|
|
24262
23840
|
closePoll: closePoll,
|
|
@@ -24627,7 +24205,7 @@ const getPlayer = async (parameters) => {
|
|
|
24627
24205
|
return video;
|
|
24628
24206
|
};
|
|
24629
24207
|
|
|
24630
|
-
var index$
|
|
24208
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
24631
24209
|
__proto__: null,
|
|
24632
24210
|
getPlayer: getPlayer
|
|
24633
24211
|
});
|
|
@@ -25800,7 +25378,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
25800
25378
|
};
|
|
25801
25379
|
};
|
|
25802
25380
|
|
|
25803
|
-
var index$
|
|
25381
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
25804
25382
|
__proto__: null,
|
|
25805
25383
|
createImageStory: createImageStory,
|
|
25806
25384
|
createVideoStory: createVideoStory,
|
|
@@ -25837,7 +25415,7 @@ const getNetworkAds = async () => {
|
|
|
25837
25415
|
};
|
|
25838
25416
|
};
|
|
25839
25417
|
|
|
25840
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
25418
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
25841
25419
|
__proto__: null,
|
|
25842
25420
|
getNetworkAds: getNetworkAds
|
|
25843
25421
|
});
|
|
@@ -25864,31 +25442,342 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
25864
25442
|
return { accessToken: data.accessToken };
|
|
25865
25443
|
};
|
|
25866
25444
|
|
|
25445
|
+
/* begin_public_function
|
|
25446
|
+
id: notificationTray.getNotificationTraySeen
|
|
25447
|
+
*/
|
|
25448
|
+
/**
|
|
25449
|
+
* ```js
|
|
25450
|
+
* import { NotificationTrayRepository } from '@amityco/ts-sdk'
|
|
25451
|
+
* const notificationTraySeen = await NotificationTrayRepository.getNotificationTraySeen()
|
|
25452
|
+
* ```
|
|
25453
|
+
*
|
|
25454
|
+
*
|
|
25455
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
25456
|
+
*
|
|
25457
|
+
* @category NotificationTray API
|
|
25458
|
+
* @async
|
|
25459
|
+
* */
|
|
25460
|
+
const getNotificationTraySeen$1 = async () => {
|
|
25461
|
+
const client = getActiveClient();
|
|
25462
|
+
client.log('notificationTray/getNotificationTraySeen', {});
|
|
25463
|
+
const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
|
|
25464
|
+
const cachedAt = client.cache && Date.now();
|
|
25465
|
+
if (client.cache) {
|
|
25466
|
+
const cacheKey = ['notificationTraySeen', 'get', client.userId];
|
|
25467
|
+
pushToCache(cacheKey, {
|
|
25468
|
+
userId: client.userId,
|
|
25469
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
25470
|
+
lastTrayOccuredAt: payload.lastTrayOccuredAt,
|
|
25471
|
+
});
|
|
25472
|
+
}
|
|
25473
|
+
return {
|
|
25474
|
+
data: {
|
|
25475
|
+
userId: client.userId,
|
|
25476
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
25477
|
+
lastTrayOccuredAt: payload.lastTrayOccuredAt,
|
|
25478
|
+
isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
|
|
25479
|
+
},
|
|
25480
|
+
cachedAt,
|
|
25481
|
+
};
|
|
25482
|
+
};
|
|
25483
|
+
/* end_public_function */
|
|
25484
|
+
/**
|
|
25485
|
+
* ```js
|
|
25486
|
+
* import { NotificationTrayRepository } from '@amityco/ts-sdk'
|
|
25487
|
+
* const notificationTraySeen = await NotificationTrayRepository.getNotificationTraySeen.locally()
|
|
25488
|
+
* ```
|
|
25489
|
+
*
|
|
25490
|
+
* Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
|
|
25491
|
+
*
|
|
25492
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
25493
|
+
*
|
|
25494
|
+
* @category NotificationTray API
|
|
25495
|
+
* @async
|
|
25496
|
+
* */
|
|
25497
|
+
getNotificationTraySeen$1.locally = () => {
|
|
25498
|
+
var _a;
|
|
25499
|
+
const client = getActiveClient();
|
|
25500
|
+
client.log('notificationTray/getNotificationTraySeen.locally', {});
|
|
25501
|
+
if (!client.cache)
|
|
25502
|
+
return;
|
|
25503
|
+
const queryKey = ['notificationTraySeen', 'get'];
|
|
25504
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
25505
|
+
if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
|
|
25506
|
+
return;
|
|
25507
|
+
return { data: data.notificationTraySeen, cachedAt };
|
|
25508
|
+
};
|
|
25509
|
+
|
|
25510
|
+
/**
|
|
25511
|
+
* ```js
|
|
25512
|
+
* import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
|
|
25513
|
+
* const dispose = onNotificationTraySeenUpdated(data => {
|
|
25514
|
+
* // ...
|
|
25515
|
+
* })
|
|
25516
|
+
* ```
|
|
25517
|
+
*
|
|
25518
|
+
* Fired when an {@link Amity.NotificationTraySeen} has been updated
|
|
25519
|
+
*
|
|
25520
|
+
* @param callback The function to call when the event was fired
|
|
25521
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25522
|
+
*
|
|
25523
|
+
* @category NotificationTraySeen Events
|
|
25524
|
+
*/
|
|
25525
|
+
const onNotificationTraySeenUpdated = (callback) => {
|
|
25526
|
+
const client = getActiveClient();
|
|
25527
|
+
const disposers = [
|
|
25528
|
+
createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
|
|
25529
|
+
];
|
|
25530
|
+
return () => {
|
|
25531
|
+
disposers.forEach(fn => fn());
|
|
25532
|
+
};
|
|
25533
|
+
};
|
|
25534
|
+
|
|
25535
|
+
/* begin_public_function
|
|
25536
|
+
id: notificationTraySeen.get
|
|
25537
|
+
*/
|
|
25538
|
+
/**
|
|
25539
|
+
* ```js
|
|
25540
|
+
* import { getNotificationTraySeen } from '@amityco/ts-sdk';
|
|
25541
|
+
*
|
|
25542
|
+
* let notificationTraySeen;
|
|
25543
|
+
*
|
|
25544
|
+
* const unsubscribe = getNotificationTraySeen(userId, response => {
|
|
25545
|
+
* notificationTraySeen = response.data;
|
|
25546
|
+
* });
|
|
25547
|
+
* ```
|
|
25548
|
+
*
|
|
25549
|
+
* Observe all mutation on a given {@link Amity.NotificationTraySeen}
|
|
25550
|
+
*
|
|
25551
|
+
* @param userId the ID of the user to observe
|
|
25552
|
+
* @param callback the function to call when new data are available
|
|
25553
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
25554
|
+
*
|
|
25555
|
+
* @category NotificationTraySeen Live Object
|
|
25556
|
+
*/
|
|
25557
|
+
const getNotificationTraySeen = (callback) => {
|
|
25558
|
+
const responder = (snapshot) => {
|
|
25559
|
+
const { data } = snapshot;
|
|
25560
|
+
callback(Object.assign(Object.assign({}, snapshot), { data }));
|
|
25561
|
+
};
|
|
25562
|
+
const { userId } = getActiveUser();
|
|
25563
|
+
return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
|
|
25564
|
+
onNotificationTraySeenUpdated,
|
|
25565
|
+
]);
|
|
25566
|
+
};
|
|
25567
|
+
/* end_public_function */
|
|
25568
|
+
|
|
25569
|
+
/**
|
|
25570
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
25571
|
+
* TODO: check if querybyIds is supported
|
|
25572
|
+
*/
|
|
25573
|
+
class NotificationTrayItemsPaginationController extends PaginationController {
|
|
25574
|
+
async getRequest(queryParams, token) {
|
|
25575
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
25576
|
+
const options = token ? { token } : { limit };
|
|
25577
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
|
|
25578
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
25579
|
+
});
|
|
25580
|
+
return queryResponse;
|
|
25581
|
+
}
|
|
25582
|
+
}
|
|
25583
|
+
|
|
25584
|
+
class NotificationTrayItemsQuerystreamController extends QueryStreamController {
|
|
25585
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
25586
|
+
super(query, cacheKey);
|
|
25587
|
+
this.notifyChange = notifyChange;
|
|
25588
|
+
this.preparePayload = preparePayload;
|
|
25589
|
+
}
|
|
25590
|
+
async saveToMainDB(response) {
|
|
25591
|
+
const processedPayload = await this.preparePayload(response);
|
|
25592
|
+
const client = getActiveClient();
|
|
25593
|
+
const cachedAt = client.cache && Date.now();
|
|
25594
|
+
if (client.cache) {
|
|
25595
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
25596
|
+
}
|
|
25597
|
+
}
|
|
25598
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
25599
|
+
var _a, _b;
|
|
25600
|
+
if (refresh) {
|
|
25601
|
+
pushToCache(this.cacheKey, {
|
|
25602
|
+
data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
25603
|
+
});
|
|
25604
|
+
}
|
|
25605
|
+
else {
|
|
25606
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25607
|
+
const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25608
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
25609
|
+
...new Set([
|
|
25610
|
+
...notifications,
|
|
25611
|
+
...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
25612
|
+
]),
|
|
25613
|
+
] }));
|
|
25614
|
+
}
|
|
25615
|
+
}
|
|
25616
|
+
}
|
|
25617
|
+
|
|
25618
|
+
const prepareNotificationTrayItemsPayload = (rawPayload) => {
|
|
25619
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
25620
|
+
return Object.assign(Object.assign({}, rawPayload), { users });
|
|
25621
|
+
};
|
|
25622
|
+
|
|
25623
|
+
class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
|
|
25624
|
+
constructor(query, callback) {
|
|
25625
|
+
const queryStreamId = hash__default["default"](query);
|
|
25626
|
+
const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
|
|
25627
|
+
const paginationController = new NotificationTrayItemsPaginationController(query);
|
|
25628
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
25629
|
+
this.query = query;
|
|
25630
|
+
this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
|
|
25631
|
+
this.callback = callback.bind(this);
|
|
25632
|
+
this.loadPage({ initial: true });
|
|
25633
|
+
}
|
|
25634
|
+
setup() {
|
|
25635
|
+
var _a;
|
|
25636
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25637
|
+
if (!collection) {
|
|
25638
|
+
pushToCache(this.cacheKey, {
|
|
25639
|
+
data: [],
|
|
25640
|
+
params: {},
|
|
25641
|
+
});
|
|
25642
|
+
}
|
|
25643
|
+
}
|
|
25644
|
+
async persistModel(queryPayload) {
|
|
25645
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
25646
|
+
}
|
|
25647
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
25648
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
25649
|
+
}
|
|
25650
|
+
// eslint-disable-next-line class-methods-use-this
|
|
25651
|
+
startSubscription() {
|
|
25652
|
+
return [];
|
|
25653
|
+
}
|
|
25654
|
+
notifyChange({ origin, loading, error }) {
|
|
25655
|
+
var _a, _b;
|
|
25656
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25657
|
+
if (!collection)
|
|
25658
|
+
return;
|
|
25659
|
+
const data = ((_b = collection.data
|
|
25660
|
+
.map(id => pullFromCache(['notificationTrayItem', 'get', id]))
|
|
25661
|
+
.filter(isNonNullable)
|
|
25662
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
|
|
25663
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
25664
|
+
return;
|
|
25665
|
+
this.callback({
|
|
25666
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
25667
|
+
data,
|
|
25668
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
25669
|
+
loading,
|
|
25670
|
+
error,
|
|
25671
|
+
});
|
|
25672
|
+
}
|
|
25673
|
+
}
|
|
25674
|
+
|
|
25675
|
+
/**
|
|
25676
|
+
* Get notification tray items for a notification tray page
|
|
25677
|
+
*
|
|
25678
|
+
* @param params the limit query parameters
|
|
25679
|
+
* @param callback the callback to be called when the notification tray items are updated
|
|
25680
|
+
* @returns items in the notification tray
|
|
25681
|
+
*
|
|
25682
|
+
* @category Notification tray items Live Collection
|
|
25683
|
+
*
|
|
25684
|
+
*/
|
|
25685
|
+
const getNotificationTrayItems = (params, callback, config) => {
|
|
25686
|
+
const { log, cache } = getActiveClient();
|
|
25687
|
+
if (!cache) {
|
|
25688
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25689
|
+
}
|
|
25690
|
+
const timestamp = Date.now();
|
|
25691
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
|
|
25692
|
+
const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
|
|
25693
|
+
const disposers = notiTrayItemsLiveCollection.startSubscription();
|
|
25694
|
+
const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
|
|
25695
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
25696
|
+
return () => {
|
|
25697
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
|
|
25698
|
+
disposers.forEach(fn => fn());
|
|
25699
|
+
};
|
|
25700
|
+
};
|
|
25701
|
+
|
|
25702
|
+
/* begin_public_function
|
|
25703
|
+
id: notificationTray.markSeen
|
|
25704
|
+
*/
|
|
25705
|
+
/**
|
|
25706
|
+
* ```js
|
|
25707
|
+
* import { NotificationTrayRepository } from '@amityco/ts-sdk'
|
|
25708
|
+
* const updated = await NotificationTrayRepository.markNotificationTraySeen({
|
|
25709
|
+
* lastSeenAt: Amity.timestamp,
|
|
25710
|
+
* })
|
|
25711
|
+
* ```
|
|
25712
|
+
*
|
|
25713
|
+
* Updates an {@link Amity.NotificationTraySeen}
|
|
25714
|
+
*
|
|
25715
|
+
* @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
|
|
25716
|
+
* @param lastSeenAt The patch data to apply
|
|
25717
|
+
* @returns the updated {@link Amity.NotificationTraySeen} object
|
|
25718
|
+
*
|
|
25719
|
+
* @category Post API
|
|
25720
|
+
* @async
|
|
25721
|
+
*/
|
|
25722
|
+
const markNotificationTraySeen = async (lastSeenAt) => {
|
|
25723
|
+
var _a;
|
|
25724
|
+
const client = getActiveClient();
|
|
25725
|
+
client.log('notificationTray/markNotificationTraySeen', {});
|
|
25726
|
+
const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
|
|
25727
|
+
lastSeenAt,
|
|
25728
|
+
});
|
|
25729
|
+
const cacheData = (_a = pullFromCache([
|
|
25730
|
+
'notificationTraySeen',
|
|
25731
|
+
'get',
|
|
25732
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25733
|
+
const data = Object.assign({ userId: client.userId }, payload);
|
|
25734
|
+
const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
|
|
25735
|
+
const cachedAt = client.cache && Date.now();
|
|
25736
|
+
if (client.cache)
|
|
25737
|
+
pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
|
|
25738
|
+
fireEvent('local.notificationTraySeen.updated', data);
|
|
25739
|
+
return {
|
|
25740
|
+
data: payload,
|
|
25741
|
+
cachedAt,
|
|
25742
|
+
};
|
|
25743
|
+
};
|
|
25744
|
+
/* end_public_function */
|
|
25745
|
+
|
|
25746
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
25747
|
+
__proto__: null,
|
|
25748
|
+
getNotificationTraySeen: getNotificationTraySeen,
|
|
25749
|
+
getNotificationTrayItems: getNotificationTrayItems,
|
|
25750
|
+
markNotificationItemsSeen: markNotificationItemsSeen,
|
|
25751
|
+
markNotificationTraySeen: markNotificationTraySeen,
|
|
25752
|
+
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
25753
|
+
});
|
|
25754
|
+
|
|
25867
25755
|
exports.API_REGIONS = API_REGIONS;
|
|
25868
|
-
exports.AdRepository = index;
|
|
25869
|
-
exports.CategoryRepository = index$
|
|
25870
|
-
exports.ChannelRepository = index$
|
|
25871
|
-
exports.Client = index$
|
|
25872
|
-
exports.CommentRepository = index$
|
|
25756
|
+
exports.AdRepository = index$1;
|
|
25757
|
+
exports.CategoryRepository = index$9;
|
|
25758
|
+
exports.ChannelRepository = index$d;
|
|
25759
|
+
exports.Client = index$m;
|
|
25760
|
+
exports.CommentRepository = index$7;
|
|
25873
25761
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
25874
25762
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
25875
|
-
exports.CommunityRepository = index$
|
|
25763
|
+
exports.CommunityRepository = index$a;
|
|
25876
25764
|
exports.ContentFeedType = ContentFeedType;
|
|
25877
25765
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
25878
|
-
exports.FeedRepository = index$
|
|
25879
|
-
exports.FileRepository = index$
|
|
25766
|
+
exports.FeedRepository = index$8;
|
|
25767
|
+
exports.FileRepository = index$j;
|
|
25880
25768
|
exports.FileType = FileType;
|
|
25881
|
-
exports.LiveStreamPlayer = index$
|
|
25769
|
+
exports.LiveStreamPlayer = index$3;
|
|
25882
25770
|
exports.MessageContentType = MessageContentType;
|
|
25883
|
-
exports.MessageRepository = index$
|
|
25884
|
-
exports.
|
|
25771
|
+
exports.MessageRepository = index$h;
|
|
25772
|
+
exports.NotificationTrayRepository = index;
|
|
25773
|
+
exports.PollRepository = index$4;
|
|
25885
25774
|
exports.PostContentType = PostContentType;
|
|
25886
|
-
exports.PostRepository = index$
|
|
25887
|
-
exports.ReactionRepository = index$
|
|
25888
|
-
exports.StoryRepository = index$
|
|
25889
|
-
exports.StreamRepository = index$
|
|
25890
|
-
exports.SubChannelRepository = index$
|
|
25891
|
-
exports.UserRepository = index$
|
|
25775
|
+
exports.PostRepository = index$6;
|
|
25776
|
+
exports.ReactionRepository = index$i;
|
|
25777
|
+
exports.StoryRepository = index$2;
|
|
25778
|
+
exports.StreamRepository = index$5;
|
|
25779
|
+
exports.SubChannelRepository = index$g;
|
|
25780
|
+
exports.UserRepository = index$k;
|
|
25892
25781
|
exports.VERSION = VERSION;
|
|
25893
25782
|
exports.VideoResolution = VideoResolution;
|
|
25894
25783
|
exports.VideoSize = VideoSize;
|