@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.
- 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 -2
- 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/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- 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 +0 -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/client/utils/endpoints.d.ts +0 -1
- package/dist/client/utils/endpoints.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.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 +468 -596
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +451 -580
- 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/notificationTray/api/index.d.ts +3 -0
- package/dist/notificationTray/api/index.d.ts.map +1 -0
- package/dist/notificationTray/api/markItemsSeen.d.ts +16 -0
- package/dist/notificationTray/api/markItemsSeen.d.ts.map +1 -0
- package/dist/notificationTray/api/markTraySeen.d.ts +19 -0
- package/dist/notificationTray/api/markTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/events/index.d.ts +2 -0
- package/dist/notificationTray/events/index.d.ts.map +1 -0
- package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts +17 -0
- package/dist/notificationTray/events/onNotificationTraySeenUpdated.d.ts.map +1 -0
- package/dist/notificationTray/index.d.ts +4 -0
- package/dist/notificationTray/index.d.ts.map +1 -0
- package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts +30 -0
- package/dist/notificationTray/internalApi/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts +13 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts +9 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts +9 -0
- package/dist/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTrayItems.d.ts +12 -0
- package/dist/notificationTray/observers/getNotificationTrayItems.d.ts.map +1 -0
- package/dist/notificationTray/observers/getNotificationTraySeen.d.ts +21 -0
- package/dist/notificationTray/observers/getNotificationTraySeen.d.ts.map +1 -0
- package/dist/notificationTray/observers/index.d.ts +3 -0
- package/dist/notificationTray/observers/index.d.ts.map +1 -0
- package/dist/notificationTray/utils/prepareNotificationTrayItemsPayload.d.ts +2 -0
- package/dist/notificationTray/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 -3
- package/src/@types/domains/notification.ts +90 -0
- package/src/@types/index.ts +1 -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 -68
- package/src/client/api/createClient.ts +1 -7
- 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/client/utils/endpoints.ts +0 -1
- package/src/client/utils/setClientToken.ts +0 -8
- package/src/core/model/idResolvers.ts +3 -2
- package/src/core/model/index.ts +2 -0
- package/src/fileRepository/api/uploadFile.ts +1 -1
- package/src/fileRepository/api/uploadImage.ts +1 -1
- package/src/fileRepository/api/uploadVideo.ts +1 -1
- 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/notificationTray/api/index.ts +2 -0
- package/src/notificationTray/api/markItemsSeen.ts +59 -0
- package/src/notificationTray/api/markTraySeen.ts +65 -0
- package/src/notificationTray/events/index.ts +1 -0
- package/src/notificationTray/events/onNotificationTraySeenUpdated.ts +36 -0
- package/src/notificationTray/index.ts +3 -0
- package/src/notificationTray/internalApi/getNotificationTraySeen.ts +81 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsLiveCollectionController.ts +96 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsPaginationController.ts +31 -0
- package/src/notificationTray/observers/getNotificationTrayItems/NotificationTrayItemsQuerystreamController.ts +68 -0
- package/src/notificationTray/observers/getNotificationTrayItems.ts +44 -0
- package/src/notificationTray/observers/getNotificationTraySeen.ts +43 -0
- package/src/notificationTray/observers/index.ts +2 -0
- package/src/notificationTray/utils/prepareNotificationTrayItemsPayload.ts +12 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/notificationTrayLinkedObject.ts +19 -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) => {
|
|
@@ -1562,7 +1565,6 @@ const API_REGIONS = {
|
|
|
1562
1565
|
};
|
|
1563
1566
|
const URLS = {
|
|
1564
1567
|
http: 'https://apix.{region}.amity.co',
|
|
1565
|
-
upload: 'https://upload.{region}.amity.co',
|
|
1566
1568
|
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
1567
1569
|
};
|
|
1568
1570
|
function computeUrl(type, region) {
|
|
@@ -1611,13 +1613,13 @@ class NetworkActivitiesWatcher {
|
|
|
1611
1613
|
this._listener.clear();
|
|
1612
1614
|
}
|
|
1613
1615
|
}
|
|
1614
|
-
let instance$
|
|
1616
|
+
let instance$5;
|
|
1615
1617
|
var NetworkActivitiesWatcher$1 = {
|
|
1616
1618
|
getInstance: () => {
|
|
1617
|
-
if (!instance$
|
|
1618
|
-
instance$
|
|
1619
|
+
if (!instance$5) {
|
|
1620
|
+
instance$5 = new NetworkActivitiesWatcher();
|
|
1619
1621
|
}
|
|
1620
|
-
return instance$
|
|
1622
|
+
return instance$5;
|
|
1621
1623
|
},
|
|
1622
1624
|
};
|
|
1623
1625
|
|
|
@@ -5150,13 +5152,13 @@ class AnalyticsEngine {
|
|
|
5150
5152
|
this._eventCapturer.resetAllBuckets();
|
|
5151
5153
|
}
|
|
5152
5154
|
}
|
|
5153
|
-
let instance$
|
|
5155
|
+
let instance$4;
|
|
5154
5156
|
var AnalyticsEngine$1 = {
|
|
5155
5157
|
getInstance: () => {
|
|
5156
|
-
if (!instance$
|
|
5157
|
-
instance$
|
|
5158
|
+
if (!instance$4) {
|
|
5159
|
+
instance$4 = new AnalyticsEngine();
|
|
5158
5160
|
}
|
|
5159
|
-
return instance$
|
|
5161
|
+
return instance$4;
|
|
5160
5162
|
},
|
|
5161
5163
|
};
|
|
5162
5164
|
|
|
@@ -5582,223 +5584,6 @@ const getMessageReadCount = (message, marker) => {
|
|
|
5582
5584
|
getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
5583
5585
|
}; // and if not found in cache use default value `0`
|
|
5584
5586
|
|
|
5585
|
-
/**
|
|
5586
|
-
*
|
|
5587
|
-
* Mark subChannel as read by readToSegment
|
|
5588
|
-
*
|
|
5589
|
-
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
5590
|
-
* @param readToSegment the segment to mark as read
|
|
5591
|
-
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
5592
|
-
*
|
|
5593
|
-
* @category Channel API
|
|
5594
|
-
* @async
|
|
5595
|
-
*/
|
|
5596
|
-
const markChannelsAsReadBySegment = async (readings) => {
|
|
5597
|
-
const client = getActiveClient();
|
|
5598
|
-
try {
|
|
5599
|
-
await client.http.post('api/v3/channels/seen', { channels: readings });
|
|
5600
|
-
return true;
|
|
5601
|
-
}
|
|
5602
|
-
catch (e) {
|
|
5603
|
-
return false;
|
|
5604
|
-
}
|
|
5605
|
-
};
|
|
5606
|
-
|
|
5607
|
-
class MessageReadReceiptSyncEngine {
|
|
5608
|
-
constructor() {
|
|
5609
|
-
this.isActive = true;
|
|
5610
|
-
this.MAX_RETRY = 3;
|
|
5611
|
-
this.JOB_QUEUE_SIZE = 120;
|
|
5612
|
-
this.jobQueue = [];
|
|
5613
|
-
// Interval for message read receipt sync in seconds
|
|
5614
|
-
this.RECEIPT_SYNC_INTERVAL = 1;
|
|
5615
|
-
this.client = getActiveClient();
|
|
5616
|
-
// Get remaining unsync read receipts from cache
|
|
5617
|
-
this.getUnsyncJobs();
|
|
5618
|
-
}
|
|
5619
|
-
// Call this when client call client.login
|
|
5620
|
-
startSyncReadReceipt() {
|
|
5621
|
-
// Start timer when start receipt sync
|
|
5622
|
-
this.timer = setInterval(() => {
|
|
5623
|
-
this.syncReadReceipts();
|
|
5624
|
-
}, this.RECEIPT_SYNC_INTERVAL * 1000);
|
|
5625
|
-
}
|
|
5626
|
-
// Read receipt observer handling
|
|
5627
|
-
syncReadReceipts() {
|
|
5628
|
-
if (this.jobQueue.length === 0 || this.isActive === false)
|
|
5629
|
-
return;
|
|
5630
|
-
const readReceipts = this.getReadReceipts();
|
|
5631
|
-
if (readReceipts) {
|
|
5632
|
-
this.markReadApi(readReceipts);
|
|
5633
|
-
}
|
|
5634
|
-
}
|
|
5635
|
-
getUnsyncJobs() {
|
|
5636
|
-
var _a;
|
|
5637
|
-
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
5638
|
-
const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
5639
|
-
return data.latestSyncSegment < data.latestSegment;
|
|
5640
|
-
});
|
|
5641
|
-
// Enqueue unsync read receipts to the job queue
|
|
5642
|
-
readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
|
|
5643
|
-
this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
|
|
5644
|
-
});
|
|
5645
|
-
}
|
|
5646
|
-
getReadReceipts() {
|
|
5647
|
-
// get all read receipts from queue, now the queue is empty
|
|
5648
|
-
const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
|
|
5649
|
-
if (syncJob.length === 0)
|
|
5650
|
-
return;
|
|
5651
|
-
return syncJob.filter(job => {
|
|
5652
|
-
var _a;
|
|
5653
|
-
const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5654
|
-
if (!readReceipt)
|
|
5655
|
-
return false;
|
|
5656
|
-
if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
|
|
5657
|
-
return true;
|
|
5658
|
-
return false;
|
|
5659
|
-
});
|
|
5660
|
-
}
|
|
5661
|
-
async markReadApi(syncJobs) {
|
|
5662
|
-
var _a;
|
|
5663
|
-
// constuct payload
|
|
5664
|
-
// example: [{ channelId: 'channelId', readToSegment: 2 }]
|
|
5665
|
-
const syncJobsPayload = syncJobs.map(job => {
|
|
5666
|
-
return {
|
|
5667
|
-
channelId: job.channelId,
|
|
5668
|
-
readToSegment: job.segment,
|
|
5669
|
-
};
|
|
5670
|
-
});
|
|
5671
|
-
const response = await markChannelsAsReadBySegment(syncJobsPayload);
|
|
5672
|
-
if (response) {
|
|
5673
|
-
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
5674
|
-
// update lastestSyncSegment in read receipt cache
|
|
5675
|
-
const cacheKey = ['readReceipt', syncJobs[i].channelId];
|
|
5676
|
-
const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5677
|
-
pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
|
|
5678
|
-
}
|
|
5679
|
-
}
|
|
5680
|
-
else {
|
|
5681
|
-
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
5682
|
-
// push them back to queue if the syncing is failed and retry count is less than max retry
|
|
5683
|
-
if (syncJobs[i].retryCount >= this.MAX_RETRY)
|
|
5684
|
-
return;
|
|
5685
|
-
const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
|
|
5686
|
-
this.enqueueJob(updatedJob);
|
|
5687
|
-
}
|
|
5688
|
-
}
|
|
5689
|
-
}
|
|
5690
|
-
startObservingReadReceiptQueue() {
|
|
5691
|
-
if (this.client.useLegacyUnreadCount) {
|
|
5692
|
-
this.isActive = true;
|
|
5693
|
-
this.startSyncReadReceipt();
|
|
5694
|
-
}
|
|
5695
|
-
}
|
|
5696
|
-
stopObservingReadReceiptQueue() {
|
|
5697
|
-
this.isActive = false;
|
|
5698
|
-
this.jobQueue.map(job => {
|
|
5699
|
-
if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
5700
|
-
return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
|
|
5701
|
-
}
|
|
5702
|
-
return job;
|
|
5703
|
-
});
|
|
5704
|
-
if (this.timer)
|
|
5705
|
-
clearInterval(this.timer);
|
|
5706
|
-
}
|
|
5707
|
-
// Session Management
|
|
5708
|
-
onSessionEstablished() {
|
|
5709
|
-
this.startObservingReadReceiptQueue();
|
|
5710
|
-
}
|
|
5711
|
-
onSessionDestroyed() {
|
|
5712
|
-
this.stopObservingReadReceiptQueue();
|
|
5713
|
-
this.jobQueue = [];
|
|
5714
|
-
}
|
|
5715
|
-
onTokenExpired() {
|
|
5716
|
-
this.stopObservingReadReceiptQueue();
|
|
5717
|
-
}
|
|
5718
|
-
// Network Connection Management
|
|
5719
|
-
onNetworkOffline() {
|
|
5720
|
-
// Stop observing to the read receipt queue.
|
|
5721
|
-
this.stopObservingReadReceiptQueue();
|
|
5722
|
-
}
|
|
5723
|
-
onNetworkOnline() {
|
|
5724
|
-
// Resume observing to the read receipt queue.
|
|
5725
|
-
this.startObservingReadReceiptQueue();
|
|
5726
|
-
}
|
|
5727
|
-
markRead(channelId, segment) {
|
|
5728
|
-
var _a;
|
|
5729
|
-
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
5730
|
-
const cacheKey = ['channelUnread', 'get', channelId];
|
|
5731
|
-
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
5732
|
-
if (typeof (channelUnread === null || channelUnread === void 0 ? void 0 : channelUnread.readToSegment) === 'number' &&
|
|
5733
|
-
channelUnread &&
|
|
5734
|
-
segment > channelUnread.readToSegment) {
|
|
5735
|
-
channelUnread.readToSegment = segment;
|
|
5736
|
-
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
5737
|
-
pushToCache(cacheKey, channelUnread);
|
|
5738
|
-
fireEvent('local.channelUnread.updated', channelUnread);
|
|
5739
|
-
}
|
|
5740
|
-
// Step 2: Enqueue the read receipt
|
|
5741
|
-
this.enqueueReadReceipt(channelId, segment);
|
|
5742
|
-
}
|
|
5743
|
-
enqueueReadReceipt(channelId, segment) {
|
|
5744
|
-
var _a;
|
|
5745
|
-
const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5746
|
-
// Create new read receipt if it's not exists and add the job to queue
|
|
5747
|
-
if (!readReceipt) {
|
|
5748
|
-
const readReceiptChannel = {
|
|
5749
|
-
channelId,
|
|
5750
|
-
latestSegment: segment,
|
|
5751
|
-
latestSyncSegment: 0,
|
|
5752
|
-
};
|
|
5753
|
-
pushToCache(['readReceipt', channelId], readReceiptChannel);
|
|
5754
|
-
}
|
|
5755
|
-
else if (readReceipt.latestSegment < segment) {
|
|
5756
|
-
// Update latestSegment in read receipt cache
|
|
5757
|
-
pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
5758
|
-
}
|
|
5759
|
-
else if (readReceipt.latestSyncSegment >= segment) {
|
|
5760
|
-
// Skip the job when lastSyncSegment > = segment
|
|
5761
|
-
return;
|
|
5762
|
-
}
|
|
5763
|
-
let syncJob = this.getSyncJob(channelId);
|
|
5764
|
-
if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
5765
|
-
syncJob = {
|
|
5766
|
-
channelId,
|
|
5767
|
-
segment,
|
|
5768
|
-
syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
|
|
5769
|
-
retryCount: 0,
|
|
5770
|
-
};
|
|
5771
|
-
this.enqueueJob(syncJob);
|
|
5772
|
-
}
|
|
5773
|
-
else if (syncJob.segment < segment) {
|
|
5774
|
-
syncJob.segment = segment;
|
|
5775
|
-
}
|
|
5776
|
-
}
|
|
5777
|
-
getSyncJob(channelId) {
|
|
5778
|
-
const { jobQueue } = this;
|
|
5779
|
-
const targetJob = jobQueue.find(job => job.channelId === channelId);
|
|
5780
|
-
return targetJob || null;
|
|
5781
|
-
}
|
|
5782
|
-
enqueueJob(syncJob) {
|
|
5783
|
-
if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
|
|
5784
|
-
this.jobQueue.push(syncJob);
|
|
5785
|
-
}
|
|
5786
|
-
else {
|
|
5787
|
-
// Remove oldest job when queue reach maximum capacity
|
|
5788
|
-
this.jobQueue.shift();
|
|
5789
|
-
this.jobQueue.push(syncJob);
|
|
5790
|
-
}
|
|
5791
|
-
}
|
|
5792
|
-
}
|
|
5793
|
-
let instance$4 = null;
|
|
5794
|
-
var ReadReceiptSyncEngine = {
|
|
5795
|
-
getInstance: () => {
|
|
5796
|
-
if (!instance$4)
|
|
5797
|
-
instance$4 = new MessageReadReceiptSyncEngine();
|
|
5798
|
-
return instance$4;
|
|
5799
|
-
},
|
|
5800
|
-
};
|
|
5801
|
-
|
|
5802
5587
|
/**
|
|
5803
5588
|
*
|
|
5804
5589
|
* Mark subChannel as read by readToSegment
|
|
@@ -5847,7 +5632,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
|
|
|
5847
5632
|
return channelUnreadInfo;
|
|
5848
5633
|
};
|
|
5849
5634
|
|
|
5850
|
-
class
|
|
5635
|
+
class MessageReadReceiptSyncEngine {
|
|
5851
5636
|
constructor() {
|
|
5852
5637
|
this.isActive = true;
|
|
5853
5638
|
this.MAX_RETRY = 3;
|
|
@@ -5878,7 +5663,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5878
5663
|
getUnsyncJobs() {
|
|
5879
5664
|
var _a;
|
|
5880
5665
|
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
5881
|
-
const readReceipts = (_a = queryCache(['
|
|
5666
|
+
const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
5882
5667
|
return data.latestSyncSegment < data.latestSegment;
|
|
5883
5668
|
});
|
|
5884
5669
|
// Enqueue unsync read receipts to the job queue
|
|
@@ -5897,7 +5682,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5897
5682
|
return;
|
|
5898
5683
|
// Get readReceipt from cache by subChannelId
|
|
5899
5684
|
const readReceipt = (_a = pullFromCache([
|
|
5900
|
-
'
|
|
5685
|
+
'readReceipt',
|
|
5901
5686
|
syncJob.subChannelId,
|
|
5902
5687
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5903
5688
|
if (!readReceipt)
|
|
@@ -5920,10 +5705,10 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5920
5705
|
if (response) {
|
|
5921
5706
|
this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
|
|
5922
5707
|
const readReceiptCache = (_a = pullFromCache([
|
|
5923
|
-
'
|
|
5708
|
+
'readReceipt',
|
|
5924
5709
|
subChannelId,
|
|
5925
5710
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5926
|
-
pushToCache(['
|
|
5711
|
+
pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
|
|
5927
5712
|
}
|
|
5928
5713
|
else if (!response) {
|
|
5929
5714
|
if (newSyncJob.retryCount > this.MAX_RETRY) {
|
|
@@ -5990,7 +5775,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5990
5775
|
subChannelUnreadInfo.readToSegment = segment;
|
|
5991
5776
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
5992
5777
|
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
5993
|
-
fireEvent('local.
|
|
5778
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
5994
5779
|
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
5995
5780
|
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
5996
5781
|
}
|
|
@@ -5999,10 +5784,7 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
5999
5784
|
}
|
|
6000
5785
|
enqueueReadReceipt(subChannelId, segment) {
|
|
6001
5786
|
var _a;
|
|
6002
|
-
const readReceipt = (_a = pullFromCache([
|
|
6003
|
-
'legacyReadReceipt',
|
|
6004
|
-
subChannelId,
|
|
6005
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5787
|
+
const readReceipt = (_a = pullFromCache(['readReceipt', subChannelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
6006
5788
|
// Create new read receipt if it's not exists and add job to queue
|
|
6007
5789
|
if (!readReceipt) {
|
|
6008
5790
|
const readReceiptSubChannel = {
|
|
@@ -6010,10 +5792,10 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
6010
5792
|
latestSegment: segment,
|
|
6011
5793
|
latestSyncSegment: 0,
|
|
6012
5794
|
};
|
|
6013
|
-
pushToCache(['
|
|
5795
|
+
pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
|
|
6014
5796
|
}
|
|
6015
5797
|
else if (readReceipt.latestSegment < segment) {
|
|
6016
|
-
pushToCache(['
|
|
5798
|
+
pushToCache(['readReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
6017
5799
|
}
|
|
6018
5800
|
else if (readReceipt.latestSyncSegment >= segment) {
|
|
6019
5801
|
// Skip the job when lastSyncSegment > = segment
|
|
@@ -6056,24 +5838,18 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
6056
5838
|
}
|
|
6057
5839
|
}
|
|
6058
5840
|
let instance$3 = null;
|
|
6059
|
-
var
|
|
5841
|
+
var ReadReceiptSyncEngine = {
|
|
6060
5842
|
getInstance: () => {
|
|
6061
5843
|
if (!instance$3)
|
|
6062
|
-
instance$3 = new
|
|
5844
|
+
instance$3 = new MessageReadReceiptSyncEngine();
|
|
6063
5845
|
return instance$3;
|
|
6064
5846
|
},
|
|
6065
5847
|
};
|
|
6066
5848
|
|
|
6067
5849
|
const markReadMessage = (message) => {
|
|
6068
|
-
const
|
|
6069
|
-
|
|
6070
|
-
|
|
6071
|
-
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
6072
|
-
}
|
|
6073
|
-
else {
|
|
6074
|
-
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
6075
|
-
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
6076
|
-
}
|
|
5850
|
+
const { subChannelId, channelSegment } = message;
|
|
5851
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
5852
|
+
markReadReceiptEngine.markRead(subChannelId, channelSegment);
|
|
6077
5853
|
};
|
|
6078
5854
|
|
|
6079
5855
|
const messageLinkedObject = (message) => {
|
|
@@ -6221,6 +5997,14 @@ const pinnedPostLinkedObject = (pinnedPost) => {
|
|
|
6221
5997
|
} });
|
|
6222
5998
|
};
|
|
6223
5999
|
|
|
6000
|
+
const notificationTrayLinkedObject = (noti) => {
|
|
6001
|
+
return Object.assign(Object.assign({}, noti), { isSeen: noti.lastSeenAt > noti.lastOccurredAt, isRecent: new Date(noti.lastOccurredAt).getTime() >= Date.now() - WEEK, users: noti.actors
|
|
6002
|
+
.map(({ _id }) => pullFromCache(['user', 'get', _id]))
|
|
6003
|
+
.filter(isNonNullable)
|
|
6004
|
+
.map(({ data }) => data)
|
|
6005
|
+
.map(user => userLinkedObject(user)) });
|
|
6006
|
+
};
|
|
6007
|
+
|
|
6224
6008
|
const LinkedObject = {
|
|
6225
6009
|
ad: adLinkedObject,
|
|
6226
6010
|
comment: commentLinkedObject,
|
|
@@ -6234,6 +6018,7 @@ const LinkedObject = {
|
|
|
6234
6018
|
reactor: reactorLinkedObject,
|
|
6235
6019
|
channel: channelLinkedObject,
|
|
6236
6020
|
pinnedPost: pinnedPostLinkedObject,
|
|
6021
|
+
notificationTray: notificationTrayLinkedObject,
|
|
6237
6022
|
};
|
|
6238
6023
|
|
|
6239
6024
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -7061,32 +6846,6 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
7061
6846
|
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
7062
6847
|
});
|
|
7063
6848
|
};
|
|
7064
|
-
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
7065
|
-
for (let i = 0; i < channels.length; i += 1) {
|
|
7066
|
-
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
7067
|
-
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
7068
|
-
let unreadCount = 0;
|
|
7069
|
-
let readToSegment = null;
|
|
7070
|
-
let lastMentionedSegment = null;
|
|
7071
|
-
let isMentioned = false;
|
|
7072
|
-
if (channelUser) {
|
|
7073
|
-
readToSegment = channelUser.readToSegment;
|
|
7074
|
-
lastMentionedSegment = channelUser.lastMentionedSegment;
|
|
7075
|
-
unreadCount = Math.max(channels[i].messageCount - readToSegment, 0);
|
|
7076
|
-
isMentioned = lastMentionedSegment > readToSegment;
|
|
7077
|
-
}
|
|
7078
|
-
const cacheChannelUnread = {
|
|
7079
|
-
channelId: channels[i].channelId,
|
|
7080
|
-
lastSegment: channels[i].messageCount,
|
|
7081
|
-
readToSegment,
|
|
7082
|
-
lastMentionedSegment,
|
|
7083
|
-
unreadCount,
|
|
7084
|
-
isMentioned,
|
|
7085
|
-
isDeleted: channels[i].isDeleted || false,
|
|
7086
|
-
};
|
|
7087
|
-
pushToCache(cacheKey, cacheChannelUnread);
|
|
7088
|
-
}
|
|
7089
|
-
};
|
|
7090
6849
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
7091
6850
|
const client = getActiveClient();
|
|
7092
6851
|
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
@@ -7096,34 +6855,23 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
7096
6855
|
rawPayload.messagePreviews.length > 0) {
|
|
7097
6856
|
updateChannelMessagePreviewCache(rawPayload);
|
|
7098
6857
|
}
|
|
7099
|
-
|
|
7100
|
-
|
|
7101
|
-
|
|
7102
|
-
|
|
7103
|
-
|
|
7104
|
-
|
|
7105
|
-
|
|
7106
|
-
|
|
7107
|
-
|
|
7108
|
-
|
|
7109
|
-
|
|
7110
|
-
|
|
7111
|
-
if (markerIds.length > 0) {
|
|
7112
|
-
// since the get markers method requires a channel cache to function with the reducer.
|
|
7113
|
-
preUpdateChannelCache(rawPayload, {
|
|
7114
|
-
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
7115
|
-
});
|
|
7116
|
-
try {
|
|
7117
|
-
await getChannelMarkers(markerIds);
|
|
7118
|
-
}
|
|
7119
|
-
catch (e) {
|
|
7120
|
-
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
7121
|
-
}
|
|
6858
|
+
const markerIds = rawPayload.channels
|
|
6859
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
6860
|
+
.filter(isUnreadCountSupport)
|
|
6861
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
6862
|
+
if (markerIds.length > 0) {
|
|
6863
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
6864
|
+
preUpdateChannelCache(rawPayload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated });
|
|
6865
|
+
try {
|
|
6866
|
+
await getChannelMarkers(markerIds);
|
|
6867
|
+
}
|
|
6868
|
+
catch (e) {
|
|
6869
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
7122
6870
|
}
|
|
7123
6871
|
}
|
|
7124
|
-
//
|
|
6872
|
+
// attach marker to channel
|
|
7125
6873
|
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
7126
|
-
//
|
|
6874
|
+
// user marker to channel users
|
|
7127
6875
|
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
7128
6876
|
return convertRawMembershipToMembership(channelUser);
|
|
7129
6877
|
});
|
|
@@ -7250,28 +6998,15 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
7250
6998
|
return (_e = (_c = marker === null || marker === void 0 ? void 0 : marker.unreadCount) !== null && _c !== void 0 ? _c : (_d = getCachedMarker(channel.channelInternalId)) === null || _d === void 0 ? void 0 : _d.unreadCount) !== null && _e !== void 0 ? _e : 0;
|
|
7251
6999
|
};
|
|
7252
7000
|
|
|
7253
|
-
const getLegacyChannelUnread = (channelId) => {
|
|
7254
|
-
var _a;
|
|
7255
|
-
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7256
|
-
};
|
|
7257
|
-
|
|
7258
7001
|
const constructChannelDynamicValue = (channel) => {
|
|
7259
|
-
const client = getActiveClient();
|
|
7260
7002
|
const rest = __rest(channel, ["messageCount"]);
|
|
7261
7003
|
return shallowClone(rest, {
|
|
7262
|
-
get
|
|
7263
|
-
|
|
7264
|
-
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
7004
|
+
get isMentioned() {
|
|
7005
|
+
return getChannelIsMentioned(rest);
|
|
7265
7006
|
},
|
|
7266
7007
|
get subChannelsUnreadCount() {
|
|
7267
7008
|
return getSubChannelsUnreadCount(rest);
|
|
7268
7009
|
},
|
|
7269
|
-
get isMentioned() {
|
|
7270
|
-
var _a, _b;
|
|
7271
|
-
if (client.useLegacyUnreadCount)
|
|
7272
|
-
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
7273
|
-
return getChannelIsMentioned(rest);
|
|
7274
|
-
},
|
|
7275
7010
|
});
|
|
7276
7011
|
};
|
|
7277
7012
|
|
|
@@ -7884,12 +7619,6 @@ const setClientToken = async (params) => {
|
|
|
7884
7619
|
isGlobalBanned: false,
|
|
7885
7620
|
isUserDeleted: false,
|
|
7886
7621
|
};
|
|
7887
|
-
client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
7888
|
-
client.upload.defaults.metadata = {
|
|
7889
|
-
tokenExpiry: expiresAt,
|
|
7890
|
-
isGlobalBanned: false,
|
|
7891
|
-
isUserDeleted: false,
|
|
7892
|
-
};
|
|
7893
7622
|
// manually setup the token for ws transport
|
|
7894
7623
|
if (client.ws)
|
|
7895
7624
|
client.ws.io.opts.query = { token: accessToken };
|
|
@@ -7934,21 +7663,12 @@ const onChannelDeleted = (callback) => {
|
|
|
7934
7663
|
const client = getActiveClient();
|
|
7935
7664
|
const filter = async (payload) => {
|
|
7936
7665
|
const data = await prepareChannelPayload(payload);
|
|
7937
|
-
|
|
7938
|
-
|
|
7939
|
-
data.channels.forEach(channel => {
|
|
7940
|
-
if (isConsistentMode) {
|
|
7666
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode()) {
|
|
7667
|
+
data.channels.forEach(channel => {
|
|
7941
7668
|
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
7942
7669
|
deleteChannelUnreadByChannelId(channel.channelId);
|
|
7943
|
-
}
|
|
7944
|
-
|
|
7945
|
-
const cacheKey = ['channelUnread', 'get', channel.channelId];
|
|
7946
|
-
const cache = pullFromCache(cacheKey);
|
|
7947
|
-
if (cache) {
|
|
7948
|
-
pushToCache(cacheKey, Object.assign(Object.assign({}, cache), { isDeleted: true }));
|
|
7949
|
-
}
|
|
7950
|
-
}
|
|
7951
|
-
});
|
|
7670
|
+
});
|
|
7671
|
+
}
|
|
7952
7672
|
ingestInCache(data);
|
|
7953
7673
|
callbacks$b.forEach(cb => cb(data.channels[0]));
|
|
7954
7674
|
};
|
|
@@ -8062,25 +7782,6 @@ var readReceiptSyncEngineOnLoginHandler = () => {
|
|
|
8062
7782
|
};
|
|
8063
7783
|
};
|
|
8064
7784
|
|
|
8065
|
-
var legacyReadReceiptSyncEngineOnLoginHandler = () => {
|
|
8066
|
-
const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
8067
|
-
readReceiptSyncEngine.startSyncReadReceipt();
|
|
8068
|
-
onSessionStateChange(state => {
|
|
8069
|
-
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
8070
|
-
readReceiptSyncEngine.onSessionEstablished();
|
|
8071
|
-
}
|
|
8072
|
-
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8073
|
-
readReceiptSyncEngine.onTokenExpired();
|
|
8074
|
-
}
|
|
8075
|
-
else {
|
|
8076
|
-
readReceiptSyncEngine.onSessionDestroyed();
|
|
8077
|
-
}
|
|
8078
|
-
});
|
|
8079
|
-
return () => {
|
|
8080
|
-
readReceiptSyncEngine.onSessionDestroyed();
|
|
8081
|
-
};
|
|
8082
|
-
};
|
|
8083
|
-
|
|
8084
7785
|
const onOnline = (callback) => {
|
|
8085
7786
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
8086
7787
|
window.addEventListener('online', callback);
|
|
@@ -8647,17 +8348,10 @@ const onChannelLeft = (callback) => {
|
|
|
8647
8348
|
const preparedPayload = await prepareChannelPayload(payload, {
|
|
8648
8349
|
isMessagePreviewUpdated: isLeftByMe,
|
|
8649
8350
|
});
|
|
8650
|
-
|
|
8651
|
-
const isLegacyUnreadCount = client.useLegacyUnreadCount;
|
|
8652
|
-
if (isLeftByMe) {
|
|
8351
|
+
if (client.isUnreadCountEnabled && client.getMarkerSyncConsistentMode() && isLeftByMe) {
|
|
8653
8352
|
preparedPayload.channels.forEach(channel => {
|
|
8654
|
-
|
|
8655
|
-
|
|
8656
|
-
deleteChannelUnreadByChannelId(channel.channelId);
|
|
8657
|
-
}
|
|
8658
|
-
else if (isLegacyUnreadCount) {
|
|
8659
|
-
dropFromCache(['channelUnread', 'get', channel.channelId]);
|
|
8660
|
-
}
|
|
8353
|
+
addFlagIsDeletedSubChannelUnreadByChannelId(channel.channelId);
|
|
8354
|
+
deleteChannelUnreadByChannelId(channel.channelId);
|
|
8661
8355
|
});
|
|
8662
8356
|
}
|
|
8663
8357
|
const { channels, channelUsers } = preparedPayload;
|
|
@@ -8925,34 +8619,6 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
8925
8619
|
reCalculateChannelUnreadInfo(message.channelId);
|
|
8926
8620
|
});
|
|
8927
8621
|
}
|
|
8928
|
-
if (client.useLegacyUnreadCount) {
|
|
8929
|
-
rawPayload.messages.forEach(message => {
|
|
8930
|
-
var _a, _b;
|
|
8931
|
-
const channelUnread = (_a = pullFromCache([
|
|
8932
|
-
'channelUnread',
|
|
8933
|
-
'get',
|
|
8934
|
-
message.channelId,
|
|
8935
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8936
|
-
if (!channelUnread ||
|
|
8937
|
-
channelUnread.lastSegment >= message.segment ||
|
|
8938
|
-
typeof channelUnread.readToSegment !== 'number' ||
|
|
8939
|
-
typeof channelUnread.lastMentionedSegment !== 'number')
|
|
8940
|
-
return;
|
|
8941
|
-
const lastSegment = message.segment;
|
|
8942
|
-
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
8943
|
-
return (mention.type === 'channel' ||
|
|
8944
|
-
(mention.type === 'user' &&
|
|
8945
|
-
client.userId &&
|
|
8946
|
-
mention.userPublicIds.includes(client.userId)));
|
|
8947
|
-
});
|
|
8948
|
-
const lastMentionedSegment = isMentionedInMessage
|
|
8949
|
-
? message.segment
|
|
8950
|
-
: channelUnread.lastMentionedSegment;
|
|
8951
|
-
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - channelUnread.readToSegment, 0), lastMentionedSegment, isMentioned: !(channelUnread.readToSegment >= lastMentionedSegment) });
|
|
8952
|
-
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
8953
|
-
fireEvent('local.channelUnread.updated', updatedChannelUnread);
|
|
8954
|
-
});
|
|
8955
|
-
}
|
|
8956
8622
|
// Update in cache
|
|
8957
8623
|
ingestInCache(payload);
|
|
8958
8624
|
payload.messages.forEach(message => {
|
|
@@ -9128,7 +8794,6 @@ const enableUnreadCount = () => {
|
|
|
9128
8794
|
if (client.isUnreadCountEnabled)
|
|
9129
8795
|
return false;
|
|
9130
8796
|
client.isUnreadCountEnabled = true;
|
|
9131
|
-
client.useLegacyUnreadCount = false;
|
|
9132
8797
|
client.emitter.emit('unreadCountEnabled', true);
|
|
9133
8798
|
return true;
|
|
9134
8799
|
};
|
|
@@ -9444,12 +9109,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
9444
9109
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9445
9110
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9446
9111
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9447
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9448
|
-
if (client.useLegacyUnreadCount) {
|
|
9449
|
-
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9450
|
-
}
|
|
9451
|
-
else
|
|
9452
|
-
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
9112
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), readReceiptSyncEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
9453
9113
|
const markerSyncUnsubscriber = await startMarkerSync();
|
|
9454
9114
|
subscriptions.push(markerSyncUnsubscriber);
|
|
9455
9115
|
}
|
|
@@ -9607,17 +9267,15 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
9607
9267
|
* @category Client API
|
|
9608
9268
|
* */
|
|
9609
9269
|
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
9610
|
-
var _a, _b
|
|
9270
|
+
var _a, _b;
|
|
9611
9271
|
const log = createLogger(debugSession);
|
|
9612
9272
|
log('client/api/createClient', {
|
|
9613
9273
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
9614
9274
|
apiRegion,
|
|
9615
9275
|
});
|
|
9616
9276
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
9617
|
-
const
|
|
9618
|
-
const mqttEndpoint = (_c = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _c !== void 0 ? _c : computeUrl('mqtt', apiRegion);
|
|
9277
|
+
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
9619
9278
|
const http = createHttpTransport(httpEndpoint);
|
|
9620
|
-
const upload = createHttpTransport(uploadEndpoint);
|
|
9621
9279
|
let ws;
|
|
9622
9280
|
let mqtt;
|
|
9623
9281
|
if (rteEnabled) {
|
|
@@ -9632,8 +9290,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9632
9290
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
9633
9291
|
const sessionHandler = undefined;
|
|
9634
9292
|
const isUnreadCountEnabled = false;
|
|
9635
|
-
// Legacy unread count is true by default
|
|
9636
|
-
const useLegacyUnreadCount = true;
|
|
9637
9293
|
const client = {
|
|
9638
9294
|
version: `${VERSION}`,
|
|
9639
9295
|
apiKey,
|
|
@@ -9648,7 +9304,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9648
9304
|
http,
|
|
9649
9305
|
ws,
|
|
9650
9306
|
mqtt,
|
|
9651
|
-
upload,
|
|
9652
9307
|
emitter,
|
|
9653
9308
|
/*
|
|
9654
9309
|
* Session Components
|
|
@@ -9664,7 +9319,6 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9664
9319
|
getMessagePreviewSetting,
|
|
9665
9320
|
use: () => setActiveClient(client),
|
|
9666
9321
|
isUnreadCountEnabled,
|
|
9667
|
-
useLegacyUnreadCount,
|
|
9668
9322
|
getMarkerSyncConsistentMode,
|
|
9669
9323
|
/**
|
|
9670
9324
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
@@ -9678,7 +9332,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9678
9332
|
return activeClient;
|
|
9679
9333
|
setActiveClient(client);
|
|
9680
9334
|
}
|
|
9681
|
-
catch (
|
|
9335
|
+
catch (_c) {
|
|
9682
9336
|
setActiveClient(client);
|
|
9683
9337
|
}
|
|
9684
9338
|
return client;
|
|
@@ -10135,7 +9789,7 @@ const getUserUnread = (callback) => {
|
|
|
10135
9789
|
};
|
|
10136
9790
|
};
|
|
10137
9791
|
|
|
10138
|
-
var index$
|
|
9792
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
10139
9793
|
__proto__: null,
|
|
10140
9794
|
getActiveClient: getActiveClient,
|
|
10141
9795
|
getActiveUser: getActiveUser,
|
|
@@ -11342,7 +10996,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
11342
10996
|
};
|
|
11343
10997
|
/* end_public_function */
|
|
11344
10998
|
|
|
11345
|
-
var index$
|
|
10999
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
11346
11000
|
__proto__: null,
|
|
11347
11001
|
blockUser: blockUser,
|
|
11348
11002
|
unBlockUser: unBlockUser,
|
|
@@ -12357,9 +12011,9 @@ var AmityUserSearchMatchType;
|
|
|
12357
12011
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
12358
12012
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
12359
12013
|
|
|
12360
|
-
var index$
|
|
12014
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
12361
12015
|
__proto__: null,
|
|
12362
|
-
Relationship: index$
|
|
12016
|
+
Relationship: index$l,
|
|
12363
12017
|
getUserByIds: getUserByIds,
|
|
12364
12018
|
updateUser: updateUser,
|
|
12365
12019
|
flagUser: flagUser,
|
|
@@ -12467,7 +12121,7 @@ const uploadFile = async (formData, onProgress) => {
|
|
|
12467
12121
|
const headers = 'getHeaders' in formData
|
|
12468
12122
|
? formData.getHeaders()
|
|
12469
12123
|
: { 'content-type': 'multipart/form-data' };
|
|
12470
|
-
const { data } = await client.
|
|
12124
|
+
const { data } = await client.http.post('/api/v4/files', formData, {
|
|
12471
12125
|
headers,
|
|
12472
12126
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12473
12127
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12557,7 +12211,7 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
12557
12211
|
const headers = 'getHeaders' in formData
|
|
12558
12212
|
? formData.getHeaders()
|
|
12559
12213
|
: { 'content-type': 'multipart/form-data' };
|
|
12560
|
-
const { data } = await client.
|
|
12214
|
+
const { data } = await client.http.post('/api/v4/videos', formData, {
|
|
12561
12215
|
headers,
|
|
12562
12216
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12563
12217
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12605,7 +12259,7 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
12605
12259
|
const headers = 'getHeaders' in formData
|
|
12606
12260
|
? formData.getHeaders()
|
|
12607
12261
|
: { 'content-type': 'multipart/form-data' };
|
|
12608
|
-
const { data } = await client.
|
|
12262
|
+
const { data } = await client.http.post('/api/v4/images', formData, {
|
|
12609
12263
|
headers,
|
|
12610
12264
|
onUploadProgress({ loaded, total = 100 }) {
|
|
12611
12265
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -12623,7 +12277,7 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
12623
12277
|
};
|
|
12624
12278
|
/* end_public_function */
|
|
12625
12279
|
|
|
12626
|
-
var index$
|
|
12280
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
12627
12281
|
__proto__: null,
|
|
12628
12282
|
getFile: getFile,
|
|
12629
12283
|
uploadFile: uploadFile,
|
|
@@ -14435,7 +14089,7 @@ const getReactions = (params, callback, config) => {
|
|
|
14435
14089
|
};
|
|
14436
14090
|
/* end_public_function */
|
|
14437
14091
|
|
|
14438
|
-
var index$
|
|
14092
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
14439
14093
|
__proto__: null,
|
|
14440
14094
|
addReaction: addReaction,
|
|
14441
14095
|
removeReaction: removeReaction,
|
|
@@ -16251,7 +15905,7 @@ const getMessages = (params, callback, config) => {
|
|
|
16251
15905
|
};
|
|
16252
15906
|
/* end_public_function */
|
|
16253
15907
|
|
|
16254
|
-
var index$
|
|
15908
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
16255
15909
|
__proto__: null,
|
|
16256
15910
|
createMessage: createMessage,
|
|
16257
15911
|
updateMessage: updateMessage,
|
|
@@ -16777,7 +16431,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
16777
16431
|
};
|
|
16778
16432
|
/* end_public_function */
|
|
16779
16433
|
|
|
16780
|
-
var index$
|
|
16434
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
16781
16435
|
__proto__: null,
|
|
16782
16436
|
getSubChannelByIds: getSubChannels$1,
|
|
16783
16437
|
createSubChannel: createSubChannel,
|
|
@@ -16798,37 +16452,19 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
16798
16452
|
/**
|
|
16799
16453
|
* Internal used only
|
|
16800
16454
|
*
|
|
16801
|
-
* Fired when an {@link Amity.
|
|
16802
|
-
*
|
|
16803
|
-
* @param callback The function to call when the event was fired
|
|
16804
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16805
|
-
*
|
|
16806
|
-
* @category ChannelMarker Events
|
|
16807
|
-
*/
|
|
16808
|
-
const onChannelUnreadInfoUpdatedLocal = (callback) => {
|
|
16809
|
-
const client = getActiveClient();
|
|
16810
|
-
const filter = (payload) => {
|
|
16811
|
-
callback(payload);
|
|
16812
|
-
};
|
|
16813
|
-
return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
|
|
16814
|
-
};
|
|
16815
|
-
|
|
16816
|
-
/**
|
|
16817
|
-
* Internal used only
|
|
16818
|
-
*
|
|
16819
|
-
* Fired when an {@link Amity.ChannelUnread} has been updated.
|
|
16455
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
16820
16456
|
*
|
|
16821
16457
|
* @param callback The function to call when the event was fired
|
|
16822
16458
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16823
16459
|
*
|
|
16824
|
-
* @category
|
|
16460
|
+
* @category MessageMarker Events
|
|
16825
16461
|
*/
|
|
16826
16462
|
const onChannelUnreadUpdatedLocal = (callback) => {
|
|
16827
16463
|
const client = getActiveClient();
|
|
16828
16464
|
const filter = (payload) => {
|
|
16829
16465
|
callback(payload);
|
|
16830
16466
|
};
|
|
16831
|
-
return createEventSubscriber(client, '
|
|
16467
|
+
return createEventSubscriber(client, 'channelMarker/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
|
|
16832
16468
|
};
|
|
16833
16469
|
|
|
16834
16470
|
/* begin_public_function
|
|
@@ -17030,7 +16666,6 @@ const getChannel = (channelId, callback) => {
|
|
|
17030
16666
|
return onSubChannelUpdated(updateMessagePreview);
|
|
17031
16667
|
}, 'channelId', 'channel'),
|
|
17032
16668
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
17033
|
-
convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
17034
16669
|
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
17035
16670
|
], {
|
|
17036
16671
|
forceDispatch: true,
|
|
@@ -17544,10 +17179,6 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
17544
17179
|
},
|
|
17545
17180
|
action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
|
|
17546
17181
|
},
|
|
17547
|
-
{
|
|
17548
|
-
fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
17549
|
-
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
17550
|
-
},
|
|
17551
17182
|
{
|
|
17552
17183
|
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
17553
17184
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -17613,120 +17244,6 @@ const getChannels = (params, callback, config) => {
|
|
|
17613
17244
|
};
|
|
17614
17245
|
/* end_public_function */
|
|
17615
17246
|
|
|
17616
|
-
/**
|
|
17617
|
-
*
|
|
17618
|
-
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
17619
|
-
*
|
|
17620
|
-
* @returns the {@link Amity.UserUnread} objects
|
|
17621
|
-
*
|
|
17622
|
-
* @category Channel API
|
|
17623
|
-
* @async
|
|
17624
|
-
*/
|
|
17625
|
-
const getTotalChannelsUnread$1 = () => {
|
|
17626
|
-
var _a;
|
|
17627
|
-
const client = getActiveClient();
|
|
17628
|
-
client.log('channel/getTotalChannelsUnread.locally');
|
|
17629
|
-
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
17630
|
-
return !data.isDeleted;
|
|
17631
|
-
})) || [];
|
|
17632
|
-
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
17633
|
-
acc.unreadCount += data.unreadCount;
|
|
17634
|
-
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
17635
|
-
return acc;
|
|
17636
|
-
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
17637
|
-
const cachedAt = client.cache && Date.now();
|
|
17638
|
-
return {
|
|
17639
|
-
data: totalChannelsUnread,
|
|
17640
|
-
cachedAt,
|
|
17641
|
-
};
|
|
17642
|
-
};
|
|
17643
|
-
|
|
17644
|
-
/* begin_public_function
|
|
17645
|
-
id: totalChannelsUnread.get
|
|
17646
|
-
*/
|
|
17647
|
-
/**
|
|
17648
|
-
* ```js
|
|
17649
|
-
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
17650
|
-
*
|
|
17651
|
-
* let totalChannelsUnread;
|
|
17652
|
-
*
|
|
17653
|
-
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
17654
|
-
* unread = response.data;
|
|
17655
|
-
* });
|
|
17656
|
-
* ```
|
|
17657
|
-
*
|
|
17658
|
-
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
17659
|
-
*
|
|
17660
|
-
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
17661
|
-
*
|
|
17662
|
-
* @category User Unread Live Object
|
|
17663
|
-
*
|
|
17664
|
-
*/
|
|
17665
|
-
const getTotalChannelsUnread = (callback) => {
|
|
17666
|
-
const { _id: userId } = getActiveUser();
|
|
17667
|
-
if (!userId)
|
|
17668
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
17669
|
-
const { log, cache } = getActiveClient();
|
|
17670
|
-
if (!cache) {
|
|
17671
|
-
console.log('For using Live Object feature you need to enable Cache!');
|
|
17672
|
-
}
|
|
17673
|
-
const timestamp = Date.now();
|
|
17674
|
-
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
17675
|
-
const disposers = [];
|
|
17676
|
-
let isUnsyncedModel = false; // for messages
|
|
17677
|
-
let model;
|
|
17678
|
-
const dispatcher = (data) => {
|
|
17679
|
-
const { data: userUnread } = data;
|
|
17680
|
-
const callbackModel = userUnread
|
|
17681
|
-
? {
|
|
17682
|
-
unreadCount: userUnread.unreadCount,
|
|
17683
|
-
isMentioned: userUnread.isMentioned,
|
|
17684
|
-
}
|
|
17685
|
-
: undefined;
|
|
17686
|
-
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
17687
|
-
callback({
|
|
17688
|
-
data: callbackModel
|
|
17689
|
-
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
17690
|
-
loading: data.loading,
|
|
17691
|
-
error: data.error,
|
|
17692
|
-
});
|
|
17693
|
-
};
|
|
17694
|
-
const realtimeRouter = (userUnread) => {
|
|
17695
|
-
if (isEqual(model, userUnread))
|
|
17696
|
-
return;
|
|
17697
|
-
dispatcher({
|
|
17698
|
-
loading: false,
|
|
17699
|
-
data: userUnread,
|
|
17700
|
-
});
|
|
17701
|
-
};
|
|
17702
|
-
const onFetch = () => {
|
|
17703
|
-
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
17704
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
17705
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
17706
|
-
dispatcher({
|
|
17707
|
-
data,
|
|
17708
|
-
origin,
|
|
17709
|
-
loading: false,
|
|
17710
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
17711
|
-
});
|
|
17712
|
-
isUnsyncedModel = true;
|
|
17713
|
-
disposers.forEach(fn => fn());
|
|
17714
|
-
}
|
|
17715
|
-
else if (!isUnsyncedModel) {
|
|
17716
|
-
dispatcher({ loading, data, origin, error });
|
|
17717
|
-
}
|
|
17718
|
-
if (error) {
|
|
17719
|
-
disposers.forEach(fn => fn());
|
|
17720
|
-
}
|
|
17721
|
-
});
|
|
17722
|
-
};
|
|
17723
|
-
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
17724
|
-
onFetch();
|
|
17725
|
-
return () => {
|
|
17726
|
-
disposers.forEach(fn => fn());
|
|
17727
|
-
};
|
|
17728
|
-
};
|
|
17729
|
-
|
|
17730
17247
|
/* begin_public_function
|
|
17731
17248
|
id: channel.member.add
|
|
17732
17249
|
*/
|
|
@@ -18091,7 +17608,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
18091
17608
|
};
|
|
18092
17609
|
/* end_public_function */
|
|
18093
17610
|
|
|
18094
|
-
var index$
|
|
17611
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
18095
17612
|
__proto__: null,
|
|
18096
17613
|
addMembers: addMembers$1,
|
|
18097
17614
|
removeMembers: removeMembers$1,
|
|
@@ -18294,7 +17811,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
18294
17811
|
};
|
|
18295
17812
|
/* end_public_function */
|
|
18296
17813
|
|
|
18297
|
-
var index$
|
|
17814
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
18298
17815
|
__proto__: null,
|
|
18299
17816
|
addRole: addRole,
|
|
18300
17817
|
removeRole: removeRole,
|
|
@@ -18304,10 +17821,10 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
18304
17821
|
unmuteMembers: unmuteMembers
|
|
18305
17822
|
});
|
|
18306
17823
|
|
|
18307
|
-
var index$
|
|
17824
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
18308
17825
|
__proto__: null,
|
|
18309
|
-
Membership: index$
|
|
18310
|
-
Moderation: index$
|
|
17826
|
+
Membership: index$f,
|
|
17827
|
+
Moderation: index$e,
|
|
18311
17828
|
getChannelByIds: getChannelByIds$1,
|
|
18312
17829
|
createChannel: createChannel,
|
|
18313
17830
|
updateChannel: updateChannel,
|
|
@@ -18330,7 +17847,6 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
18330
17847
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
18331
17848
|
getChannel: getChannel,
|
|
18332
17849
|
getChannels: getChannels,
|
|
18333
|
-
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
18334
17850
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
18335
17851
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
18336
17852
|
convertFromRaw: convertFromRaw,
|
|
@@ -19687,7 +19203,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
19687
19203
|
};
|
|
19688
19204
|
/* end_public_function */
|
|
19689
19205
|
|
|
19690
|
-
var index$
|
|
19206
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
19691
19207
|
__proto__: null,
|
|
19692
19208
|
addMembers: addMembers,
|
|
19693
19209
|
removeMembers: removeMembers,
|
|
@@ -20712,7 +20228,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
20712
20228
|
};
|
|
20713
20229
|
/* end_public_function */
|
|
20714
20230
|
|
|
20715
|
-
var index$
|
|
20231
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
20716
20232
|
__proto__: null,
|
|
20717
20233
|
addRoles: addRoles,
|
|
20718
20234
|
removeRoles: removeRoles,
|
|
@@ -20720,10 +20236,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
20720
20236
|
unbanMembers: unbanMembers
|
|
20721
20237
|
});
|
|
20722
20238
|
|
|
20723
|
-
var index$
|
|
20239
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
20724
20240
|
__proto__: null,
|
|
20725
|
-
Moderation: index$
|
|
20726
|
-
Membership: index$
|
|
20241
|
+
Moderation: index$b,
|
|
20242
|
+
Membership: index$c,
|
|
20727
20243
|
getCommunityByIds: getCommunities$1,
|
|
20728
20244
|
createCommunity: createCommunity,
|
|
20729
20245
|
updateCommunity: updateCommunity,
|
|
@@ -20956,7 +20472,7 @@ const getCategories = (params, callback, config) => {
|
|
|
20956
20472
|
};
|
|
20957
20473
|
/* end_public_function */
|
|
20958
20474
|
|
|
20959
|
-
var index$
|
|
20475
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
20960
20476
|
__proto__: null,
|
|
20961
20477
|
getCategory: getCategory,
|
|
20962
20478
|
getCategories: getCategories
|
|
@@ -21124,7 +20640,7 @@ getCustomRankingGlobalFeed.locally = (query) => {
|
|
|
21124
20640
|
: undefined;
|
|
21125
20641
|
};
|
|
21126
20642
|
|
|
21127
|
-
var index$
|
|
20643
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
21128
20644
|
__proto__: null,
|
|
21129
20645
|
queryGlobalFeed: queryGlobalFeed,
|
|
21130
20646
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
|
|
@@ -22439,7 +21955,7 @@ const getComments = (params, callback, config) => {
|
|
|
22439
21955
|
};
|
|
22440
21956
|
/* end_public_function */
|
|
22441
21957
|
|
|
22442
|
-
var index$
|
|
21958
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
22443
21959
|
__proto__: null,
|
|
22444
21960
|
getCommentByIds: getCommentByIds,
|
|
22445
21961
|
createComment: createComment,
|
|
@@ -23446,7 +22962,7 @@ const semanticSearchPosts = (params, callback, config) => {
|
|
|
23446
22962
|
};
|
|
23447
22963
|
};
|
|
23448
22964
|
|
|
23449
|
-
var index$
|
|
22965
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
23450
22966
|
__proto__: null,
|
|
23451
22967
|
getPostByIds: getPostByIds,
|
|
23452
22968
|
createPost: createPost,
|
|
@@ -23980,7 +23496,7 @@ const getStreams = (params, callback, config) => {
|
|
|
23980
23496
|
};
|
|
23981
23497
|
};
|
|
23982
23498
|
|
|
23983
|
-
var index$
|
|
23499
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
23984
23500
|
__proto__: null,
|
|
23985
23501
|
createStream: createStream,
|
|
23986
23502
|
updateStream: updateStream,
|
|
@@ -24267,7 +23783,7 @@ const getPoll = (pollId, callback) => {
|
|
|
24267
23783
|
};
|
|
24268
23784
|
/* end_public_function */
|
|
24269
23785
|
|
|
24270
|
-
var index$
|
|
23786
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
24271
23787
|
__proto__: null,
|
|
24272
23788
|
createPoll: createPoll,
|
|
24273
23789
|
closePoll: closePoll,
|
|
@@ -24638,7 +24154,7 @@ const getPlayer = async (parameters) => {
|
|
|
24638
24154
|
return video;
|
|
24639
24155
|
};
|
|
24640
24156
|
|
|
24641
|
-
var index$
|
|
24157
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
24642
24158
|
__proto__: null,
|
|
24643
24159
|
getPlayer: getPlayer
|
|
24644
24160
|
});
|
|
@@ -25811,7 +25327,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
25811
25327
|
};
|
|
25812
25328
|
};
|
|
25813
25329
|
|
|
25814
|
-
var index$
|
|
25330
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
25815
25331
|
__proto__: null,
|
|
25816
25332
|
createImageStory: createImageStory,
|
|
25817
25333
|
createVideoStory: createVideoStory,
|
|
@@ -25848,7 +25364,7 @@ const getNetworkAds = async () => {
|
|
|
25848
25364
|
};
|
|
25849
25365
|
};
|
|
25850
25366
|
|
|
25851
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
25367
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
25852
25368
|
__proto__: null,
|
|
25853
25369
|
getNetworkAds: getNetworkAds
|
|
25854
25370
|
});
|
|
@@ -25875,31 +25391,386 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
25875
25391
|
return { accessToken: data.accessToken };
|
|
25876
25392
|
};
|
|
25877
25393
|
|
|
25394
|
+
/* begin_public_function
|
|
25395
|
+
id: notificationTray.getNotificationTraySeen
|
|
25396
|
+
*/
|
|
25397
|
+
/**
|
|
25398
|
+
* ```js
|
|
25399
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
25400
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen()
|
|
25401
|
+
* ```
|
|
25402
|
+
*
|
|
25403
|
+
*
|
|
25404
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
25405
|
+
*
|
|
25406
|
+
* @category NotificationTray API
|
|
25407
|
+
* @async
|
|
25408
|
+
* */
|
|
25409
|
+
const getNotificationTraySeen$1 = async () => {
|
|
25410
|
+
const client = getActiveClient();
|
|
25411
|
+
client.log('notificationTray/getNotificationTraySeen', {});
|
|
25412
|
+
const { data: payload } = await client.http.get(`api/v1/notification-tray/tray/seen`);
|
|
25413
|
+
const cachedAt = client.cache && Date.now();
|
|
25414
|
+
if (client.cache) {
|
|
25415
|
+
const cacheKey = ['notificationTraySeen', 'get', client.userId];
|
|
25416
|
+
pushToCache(cacheKey, {
|
|
25417
|
+
userId: client.userId,
|
|
25418
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
25419
|
+
lastTrayOccuredAt: payload.lastTrayOccuredAt,
|
|
25420
|
+
});
|
|
25421
|
+
}
|
|
25422
|
+
return {
|
|
25423
|
+
data: {
|
|
25424
|
+
userId: client.userId,
|
|
25425
|
+
lastTraySeenAt: payload.lastTraySeenAt,
|
|
25426
|
+
lastTrayOccuredAt: payload.lastTrayOccuredAt,
|
|
25427
|
+
isSeen: payload.lastTraySeenAt > payload.lastTrayOccuredAt,
|
|
25428
|
+
},
|
|
25429
|
+
cachedAt,
|
|
25430
|
+
};
|
|
25431
|
+
};
|
|
25432
|
+
/* end_public_function */
|
|
25433
|
+
/**
|
|
25434
|
+
* ```js
|
|
25435
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
25436
|
+
* const notificationTraySeen = await notificationTray.getNotificationTraySeen.locally()
|
|
25437
|
+
* ```
|
|
25438
|
+
*
|
|
25439
|
+
* Queries a paginable list of {@link Amity.NotificationTraySeen} objects from cache
|
|
25440
|
+
*
|
|
25441
|
+
* @returns A page of {@link Amity.NotificationTraySeen} objects
|
|
25442
|
+
*
|
|
25443
|
+
* @category NotificationTray API
|
|
25444
|
+
* @async
|
|
25445
|
+
* */
|
|
25446
|
+
getNotificationTraySeen$1.locally = () => {
|
|
25447
|
+
var _a;
|
|
25448
|
+
const client = getActiveClient();
|
|
25449
|
+
client.log('notificationTray/getNotificationTraySeen.locally', {});
|
|
25450
|
+
if (!client.cache)
|
|
25451
|
+
return;
|
|
25452
|
+
const queryKey = ['notificationTraySeen', 'get'];
|
|
25453
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
25454
|
+
if (!(data === null || data === void 0 ? void 0 : data.notificationTraySeen))
|
|
25455
|
+
return;
|
|
25456
|
+
return { data: data.notificationTraySeen, cachedAt };
|
|
25457
|
+
};
|
|
25458
|
+
|
|
25459
|
+
/**
|
|
25460
|
+
* ```js
|
|
25461
|
+
* import { onNotificationTraySeenUpdated } from '@amityco/ts-sdk'
|
|
25462
|
+
* const dispose = onNotificationTraySeenUpdated(data => {
|
|
25463
|
+
* // ...
|
|
25464
|
+
* })
|
|
25465
|
+
* ```
|
|
25466
|
+
*
|
|
25467
|
+
* Fired when an {@link Amity.NotificationTraySeen} has been updated
|
|
25468
|
+
*
|
|
25469
|
+
* @param callback The function to call when the event was fired
|
|
25470
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
25471
|
+
*
|
|
25472
|
+
* @category NotificationTraySeen Events
|
|
25473
|
+
*/
|
|
25474
|
+
const onNotificationTraySeenUpdated = (callback) => {
|
|
25475
|
+
const client = getActiveClient();
|
|
25476
|
+
const disposers = [
|
|
25477
|
+
createEventSubscriber(client, 'onNotificationTraySeenUpdated', 'local.notificationTraySeen.updated', payload => callback(payload)),
|
|
25478
|
+
];
|
|
25479
|
+
return () => {
|
|
25480
|
+
disposers.forEach(fn => fn());
|
|
25481
|
+
};
|
|
25482
|
+
};
|
|
25483
|
+
|
|
25484
|
+
/* begin_public_function
|
|
25485
|
+
id: notificationTraySeen.get
|
|
25486
|
+
*/
|
|
25487
|
+
/**
|
|
25488
|
+
* ```js
|
|
25489
|
+
* import { getNotificationTraySeen } from '@amityco/ts-sdk';
|
|
25490
|
+
*
|
|
25491
|
+
* let notificationTraySeen;
|
|
25492
|
+
*
|
|
25493
|
+
* const unsubscribe = getNotificationTraySeen(userId, response => {
|
|
25494
|
+
* notificationTraySeen = response.data;
|
|
25495
|
+
* });
|
|
25496
|
+
* ```
|
|
25497
|
+
*
|
|
25498
|
+
* Observe all mutation on a given {@link Amity.NotificationTraySeen}
|
|
25499
|
+
*
|
|
25500
|
+
* @param userId the ID of the user to observe
|
|
25501
|
+
* @param callback the function to call when new data are available
|
|
25502
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
25503
|
+
*
|
|
25504
|
+
* @category NotificationTraySeen Live Object
|
|
25505
|
+
*/
|
|
25506
|
+
const getNotificationTraySeen = (callback) => {
|
|
25507
|
+
const responder = (snapshot) => {
|
|
25508
|
+
const { data } = snapshot;
|
|
25509
|
+
callback(Object.assign(Object.assign({}, snapshot), { data }));
|
|
25510
|
+
};
|
|
25511
|
+
const { userId } = getActiveUser();
|
|
25512
|
+
return liveObject(userId, responder, 'userId', getNotificationTraySeen$1, [
|
|
25513
|
+
onNotificationTraySeenUpdated,
|
|
25514
|
+
]);
|
|
25515
|
+
};
|
|
25516
|
+
/* end_public_function */
|
|
25517
|
+
|
|
25518
|
+
/**
|
|
25519
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
25520
|
+
* TODO: check if querybyIds is supported
|
|
25521
|
+
*/
|
|
25522
|
+
class NotificationTrayItemsPaginationController extends PaginationController {
|
|
25523
|
+
async getRequest(queryParams, token) {
|
|
25524
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
25525
|
+
const options = token ? { token } : { limit };
|
|
25526
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/notification-tray`, {
|
|
25527
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
25528
|
+
});
|
|
25529
|
+
return queryResponse;
|
|
25530
|
+
}
|
|
25531
|
+
}
|
|
25532
|
+
|
|
25533
|
+
class NotificationTrayItemsQuerystreamController extends QueryStreamController {
|
|
25534
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
25535
|
+
super(query, cacheKey);
|
|
25536
|
+
this.notifyChange = notifyChange;
|
|
25537
|
+
this.preparePayload = preparePayload;
|
|
25538
|
+
}
|
|
25539
|
+
async saveToMainDB(response) {
|
|
25540
|
+
const processedPayload = await this.preparePayload(response);
|
|
25541
|
+
const client = getActiveClient();
|
|
25542
|
+
const cachedAt = client.cache && Date.now();
|
|
25543
|
+
if (client.cache) {
|
|
25544
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
25545
|
+
}
|
|
25546
|
+
}
|
|
25547
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
25548
|
+
var _a, _b;
|
|
25549
|
+
if (refresh) {
|
|
25550
|
+
pushToCache(this.cacheKey, {
|
|
25551
|
+
data: response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
25552
|
+
});
|
|
25553
|
+
}
|
|
25554
|
+
else {
|
|
25555
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25556
|
+
const notifications = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25557
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
25558
|
+
...new Set([
|
|
25559
|
+
...notifications,
|
|
25560
|
+
...response.notificationTrayItems.map(getResolver('notificationTrayItem')),
|
|
25561
|
+
]),
|
|
25562
|
+
] }));
|
|
25563
|
+
}
|
|
25564
|
+
}
|
|
25565
|
+
}
|
|
25566
|
+
|
|
25567
|
+
const prepareNotificationTrayItemsPayload = (rawPayload) => {
|
|
25568
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
25569
|
+
return Object.assign(Object.assign({}, rawPayload), { users });
|
|
25570
|
+
};
|
|
25571
|
+
|
|
25572
|
+
class NotificationTrayItemsLiveCollectionController extends LiveCollectionController {
|
|
25573
|
+
constructor(query, callback) {
|
|
25574
|
+
const queryStreamId = hash__default["default"](query);
|
|
25575
|
+
const cacheKey = ['notificationTrayItem', 'collection', queryStreamId];
|
|
25576
|
+
const paginationController = new NotificationTrayItemsPaginationController(query);
|
|
25577
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
25578
|
+
this.query = query;
|
|
25579
|
+
this.queryStreamController = new NotificationTrayItemsQuerystreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareNotificationTrayItemsPayload);
|
|
25580
|
+
this.callback = callback.bind(this);
|
|
25581
|
+
this.loadPage({ initial: true });
|
|
25582
|
+
}
|
|
25583
|
+
setup() {
|
|
25584
|
+
var _a;
|
|
25585
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25586
|
+
if (!collection) {
|
|
25587
|
+
pushToCache(this.cacheKey, {
|
|
25588
|
+
data: [],
|
|
25589
|
+
params: {},
|
|
25590
|
+
});
|
|
25591
|
+
}
|
|
25592
|
+
}
|
|
25593
|
+
async persistModel(queryPayload) {
|
|
25594
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
25595
|
+
}
|
|
25596
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
25597
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
25598
|
+
}
|
|
25599
|
+
// eslint-disable-next-line class-methods-use-this
|
|
25600
|
+
startSubscription() {
|
|
25601
|
+
return [];
|
|
25602
|
+
}
|
|
25603
|
+
notifyChange({ origin, loading, error }) {
|
|
25604
|
+
var _a, _b;
|
|
25605
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25606
|
+
if (!collection)
|
|
25607
|
+
return;
|
|
25608
|
+
const data = ((_b = collection.data
|
|
25609
|
+
.map(id => pullFromCache(['notificationTrayItem', 'get', id]))
|
|
25610
|
+
.filter(isNonNullable)
|
|
25611
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.notificationTray);
|
|
25612
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
25613
|
+
return;
|
|
25614
|
+
this.callback({
|
|
25615
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
25616
|
+
data,
|
|
25617
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
25618
|
+
loading,
|
|
25619
|
+
error,
|
|
25620
|
+
});
|
|
25621
|
+
}
|
|
25622
|
+
}
|
|
25623
|
+
|
|
25624
|
+
/**
|
|
25625
|
+
* Get notification tray items for a notification tray page
|
|
25626
|
+
*
|
|
25627
|
+
* @param params the limit query parameters
|
|
25628
|
+
* @param callback the callback to be called when the notification tray items are updated
|
|
25629
|
+
* @returns items in the notification tray
|
|
25630
|
+
*
|
|
25631
|
+
* @category Notification tray items Live Collection
|
|
25632
|
+
*
|
|
25633
|
+
*/
|
|
25634
|
+
const getNotificationTrayItems = (params, callback, config) => {
|
|
25635
|
+
const { log, cache } = getActiveClient();
|
|
25636
|
+
if (!cache) {
|
|
25637
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25638
|
+
}
|
|
25639
|
+
const timestamp = Date.now();
|
|
25640
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > listen`);
|
|
25641
|
+
const notiTrayItemsLiveCollection = new NotificationTrayItemsLiveCollectionController(params, callback);
|
|
25642
|
+
const disposers = notiTrayItemsLiveCollection.startSubscription();
|
|
25643
|
+
const cacheKey = notiTrayItemsLiveCollection.getCacheKey();
|
|
25644
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
25645
|
+
return () => {
|
|
25646
|
+
log(`getNotificationTrayItems(tmpid: ${timestamp}) > dispose`);
|
|
25647
|
+
disposers.forEach(fn => fn());
|
|
25648
|
+
};
|
|
25649
|
+
};
|
|
25650
|
+
|
|
25651
|
+
/* begin_public_function
|
|
25652
|
+
id: notificationTrayItem.markSeen
|
|
25653
|
+
*/
|
|
25654
|
+
/**
|
|
25655
|
+
* ```js
|
|
25656
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
25657
|
+
* const updated = await notificationTray.markItemsSeen()
|
|
25658
|
+
* ```
|
|
25659
|
+
*
|
|
25660
|
+
* Updates an {@link Amity.NotificationItemSeen}
|
|
25661
|
+
*
|
|
25662
|
+
* @param trayItems[] that include id and lastTraySeenAt, The ID of the {@link Amity.NotificationItemSeen} to edit
|
|
25663
|
+
* @returns the updated {@link Amity.NotificationItemSeen} object
|
|
25664
|
+
*
|
|
25665
|
+
* @category NotificationItemSeen API
|
|
25666
|
+
* @async
|
|
25667
|
+
*/
|
|
25668
|
+
const markItemsSeen = async (patch) => {
|
|
25669
|
+
const client = getActiveClient();
|
|
25670
|
+
client.log('notificationTray/markItemsSeen', {});
|
|
25671
|
+
const { data: payload } = await client.http.put(`api/v1/notification-tray/items/seen`, {
|
|
25672
|
+
patch,
|
|
25673
|
+
});
|
|
25674
|
+
const updatedData = patch.trayItems
|
|
25675
|
+
.map(patchItem => {
|
|
25676
|
+
var _a;
|
|
25677
|
+
const cacheData = (_a = pullFromCache([
|
|
25678
|
+
'notificationTraySeen',
|
|
25679
|
+
'get',
|
|
25680
|
+
patchItem.id,
|
|
25681
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25682
|
+
if (!cacheData)
|
|
25683
|
+
return;
|
|
25684
|
+
const data = Object.assign(Object.assign({}, cacheData), payload);
|
|
25685
|
+
if (client.cache) {
|
|
25686
|
+
const cachedAt = Date.now();
|
|
25687
|
+
pushToCache(['notificationTrayItem', 'get'], data, { cachedAt });
|
|
25688
|
+
}
|
|
25689
|
+
return data;
|
|
25690
|
+
})
|
|
25691
|
+
.filter(Boolean);
|
|
25692
|
+
fireEvent('local.notificationTrayItem.updated', { notificationTrayItems: updatedData });
|
|
25693
|
+
};
|
|
25694
|
+
/* end_public_function */
|
|
25695
|
+
|
|
25696
|
+
/* begin_public_function
|
|
25697
|
+
id: notificationTray.markSeen
|
|
25698
|
+
*/
|
|
25699
|
+
/**
|
|
25700
|
+
* ```js
|
|
25701
|
+
* import { notificationTray } from '@amityco/ts-sdk'
|
|
25702
|
+
* const updated = await notificationTray.markTraySeen({
|
|
25703
|
+
* lastSeenAt: Amity.timestamp,
|
|
25704
|
+
* })
|
|
25705
|
+
* ```
|
|
25706
|
+
*
|
|
25707
|
+
* Updates an {@link Amity.NotificationTraySeen}
|
|
25708
|
+
*
|
|
25709
|
+
* @param userId The ID of the {@link Amity.NotificationTraySeen} to edit
|
|
25710
|
+
* @param lastSeenAt The patch data to apply
|
|
25711
|
+
* @returns the updated {@link Amity.NotificationTraySeen} object
|
|
25712
|
+
*
|
|
25713
|
+
* @category Post API
|
|
25714
|
+
* @async
|
|
25715
|
+
*/
|
|
25716
|
+
const markTraySeen = async (lastSeenAt) => {
|
|
25717
|
+
var _a;
|
|
25718
|
+
const client = getActiveClient();
|
|
25719
|
+
client.log('notificationTray/markTraySeen', {});
|
|
25720
|
+
const { data: payload } = await client.http.put(`api/v1/notification-tray/tray/seen`, {
|
|
25721
|
+
lastSeenAt,
|
|
25722
|
+
});
|
|
25723
|
+
const cacheData = (_a = pullFromCache([
|
|
25724
|
+
'notificationTraySeen',
|
|
25725
|
+
'get',
|
|
25726
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
25727
|
+
const data = Object.assign({ userId: client.userId }, payload);
|
|
25728
|
+
const updateCacheData = Object.assign(Object.assign({}, cacheData), data);
|
|
25729
|
+
const cachedAt = client.cache && Date.now();
|
|
25730
|
+
if (client.cache)
|
|
25731
|
+
pushToCache(['notificationTraySeen', 'get', client.userId], updateCacheData, { cachedAt });
|
|
25732
|
+
fireEvent('local.notificationTraySeen.updated', data);
|
|
25733
|
+
return {
|
|
25734
|
+
data: payload,
|
|
25735
|
+
cachedAt,
|
|
25736
|
+
};
|
|
25737
|
+
};
|
|
25738
|
+
/* end_public_function */
|
|
25739
|
+
|
|
25740
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
25741
|
+
__proto__: null,
|
|
25742
|
+
getNotificationTraySeen: getNotificationTraySeen,
|
|
25743
|
+
getNotificationTrayItems: getNotificationTrayItems,
|
|
25744
|
+
markItemsSeen: markItemsSeen,
|
|
25745
|
+
markTraySeen: markTraySeen,
|
|
25746
|
+
onNotificationTraySeenUpdated: onNotificationTraySeenUpdated
|
|
25747
|
+
});
|
|
25748
|
+
|
|
25878
25749
|
exports.API_REGIONS = API_REGIONS;
|
|
25879
|
-
exports.AdRepository = index;
|
|
25880
|
-
exports.CategoryRepository = index$
|
|
25881
|
-
exports.ChannelRepository = index$
|
|
25882
|
-
exports.Client = index$
|
|
25883
|
-
exports.CommentRepository = index$
|
|
25750
|
+
exports.AdRepository = index$1;
|
|
25751
|
+
exports.CategoryRepository = index$9;
|
|
25752
|
+
exports.ChannelRepository = index$d;
|
|
25753
|
+
exports.Client = index$m;
|
|
25754
|
+
exports.CommentRepository = index$7;
|
|
25884
25755
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
25885
25756
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
25886
|
-
exports.CommunityRepository = index$
|
|
25757
|
+
exports.CommunityRepository = index$a;
|
|
25887
25758
|
exports.ContentFeedType = ContentFeedType;
|
|
25888
25759
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
25889
|
-
exports.FeedRepository = index$
|
|
25890
|
-
exports.FileRepository = index$
|
|
25760
|
+
exports.FeedRepository = index$8;
|
|
25761
|
+
exports.FileRepository = index$j;
|
|
25891
25762
|
exports.FileType = FileType;
|
|
25892
|
-
exports.LiveStreamPlayer = index$
|
|
25763
|
+
exports.LiveStreamPlayer = index$3;
|
|
25893
25764
|
exports.MessageContentType = MessageContentType;
|
|
25894
|
-
exports.MessageRepository = index$
|
|
25895
|
-
exports.PollRepository = index$
|
|
25765
|
+
exports.MessageRepository = index$h;
|
|
25766
|
+
exports.PollRepository = index$4;
|
|
25896
25767
|
exports.PostContentType = PostContentType;
|
|
25897
|
-
exports.PostRepository = index$
|
|
25898
|
-
exports.ReactionRepository = index$
|
|
25899
|
-
exports.StoryRepository = index$
|
|
25900
|
-
exports.StreamRepository = index$
|
|
25901
|
-
exports.SubChannelRepository = index$
|
|
25902
|
-
exports.UserRepository = index$
|
|
25768
|
+
exports.PostRepository = index$6;
|
|
25769
|
+
exports.ReactionRepository = index$i;
|
|
25770
|
+
exports.StoryRepository = index$2;
|
|
25771
|
+
exports.StreamRepository = index$5;
|
|
25772
|
+
exports.SubChannelRepository = index$g;
|
|
25773
|
+
exports.UserRepository = index$k;
|
|
25903
25774
|
exports.VERSION = VERSION;
|
|
25904
25775
|
exports.VideoResolution = VideoResolution;
|
|
25905
25776
|
exports.VideoSize = VideoSize;
|
|
@@ -25952,6 +25823,7 @@ exports.isPaged = isPaged;
|
|
|
25952
25823
|
exports.isReportedByMe = isReportedByMe;
|
|
25953
25824
|
exports.isSkip = isSkip;
|
|
25954
25825
|
exports.mergeInCache = mergeInCache;
|
|
25826
|
+
exports.notificationTray = index;
|
|
25955
25827
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
25956
25828
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
25957
25829
|
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|