@amityco/ts-sdk 7.1.1-1d526d8.0 → 7.1.1-c8d4edca.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 +2 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/readReceipt.d.ts +12 -1
- package/dist/@types/core/readReceipt.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +9 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts +16 -0
- package/dist/channelRepository/api/markChannelsAsReadBySegment.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts +12 -0
- package/dist/channelRepository/events/onChannelUnreadUpdatedLocal.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/utils/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts +2 -0
- package/dist/channelRepository/utils/getLegacyChannelUnread.d.ts.map +1 -0
- 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/legacyReadReceiptSyncEngine.d.ts +33 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/client/utils/ReadReceiptSync/readReceiptSyncEngine.d.ts +2 -4
- 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/index.cjs.js +360 -40
- package/dist/index.esm.js +360 -40
- package/dist/index.umd.js +4 -4
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts +12 -0
- package/dist/marker/events/onChannelUnreadInfoUpdatedLocal.d.ts.map +1 -0
- package/dist/messageRepository/utils/markReadMessage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +2 -1
- package/src/@types/core/model.ts +4 -0
- package/src/@types/core/readReceipt.ts +14 -1
- package/src/@types/domains/channel.ts +11 -0
- package/src/@types/domains/client.ts +2 -0
- package/src/channelRepository/api/markChannelsAsReadBySegment.ts +29 -0
- package/src/channelRepository/events/onChannelUnreadUpdatedLocal.ts +29 -0
- package/src/channelRepository/observers/getChannel.ts +3 -1
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +6 -1
- package/src/channelRepository/utils/constructChannelDynamicValue.ts +12 -2
- package/src/channelRepository/utils/getLegacyChannelUnread.ts +5 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +57 -17
- package/src/client/api/createClient.ts +3 -0
- package/src/client/api/enableUnreadCount.ts +1 -0
- package/src/client/api/login.ts +5 -1
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts +267 -0
- package/src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts +21 -0
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +72 -98
- package/src/core/model/idResolvers.ts +2 -0
- package/src/marker/events/onChannelUnreadInfoUpdatedLocal.ts +29 -0
- package/src/marker/events/onChannelUnreadUpdatedLocal.ts +1 -1
- package/src/messageRepository/utils/markReadMessage.ts +10 -3
package/dist/index.esm.js
CHANGED
|
@@ -501,6 +501,7 @@ const idResolvers = {
|
|
|
501
501
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
502
502
|
channelUnreadInfo: ({ channelId }) => channelId,
|
|
503
503
|
subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
|
|
504
|
+
channelUnread: ({ channelId }) => channelId,
|
|
504
505
|
channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
|
|
505
506
|
subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
|
|
506
507
|
messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
|
|
@@ -1594,13 +1595,13 @@ class NetworkActivitiesWatcher {
|
|
|
1594
1595
|
this._listener.clear();
|
|
1595
1596
|
}
|
|
1596
1597
|
}
|
|
1597
|
-
let instance$
|
|
1598
|
+
let instance$6;
|
|
1598
1599
|
var NetworkActivitiesWatcher$1 = {
|
|
1599
1600
|
getInstance: () => {
|
|
1600
|
-
if (!instance$
|
|
1601
|
-
instance$
|
|
1601
|
+
if (!instance$6) {
|
|
1602
|
+
instance$6 = new NetworkActivitiesWatcher();
|
|
1602
1603
|
}
|
|
1603
|
-
return instance$
|
|
1604
|
+
return instance$6;
|
|
1604
1605
|
},
|
|
1605
1606
|
};
|
|
1606
1607
|
|
|
@@ -21240,13 +21241,13 @@ class AnalyticsEngine {
|
|
|
21240
21241
|
this._eventCapturer.resetAllBuckets();
|
|
21241
21242
|
}
|
|
21242
21243
|
}
|
|
21243
|
-
let instance$
|
|
21244
|
+
let instance$5;
|
|
21244
21245
|
var AnalyticsEngine$1 = {
|
|
21245
21246
|
getInstance: () => {
|
|
21246
|
-
if (!instance$
|
|
21247
|
-
instance$
|
|
21247
|
+
if (!instance$5) {
|
|
21248
|
+
instance$5 = new AnalyticsEngine();
|
|
21248
21249
|
}
|
|
21249
|
-
return instance$
|
|
21250
|
+
return instance$5;
|
|
21250
21251
|
},
|
|
21251
21252
|
};
|
|
21252
21253
|
|
|
@@ -21672,6 +21673,223 @@ const getMessageReadCount = (message, marker) => {
|
|
|
21672
21673
|
getCachedMarker$2(message)) !== null && _a !== void 0 ? _a : { readCount: 0, deliveredCount: 0 };
|
|
21673
21674
|
}; // and if not found in cache use default value `0`
|
|
21674
21675
|
|
|
21676
|
+
/**
|
|
21677
|
+
*
|
|
21678
|
+
* Mark subChannel as read by readToSegment
|
|
21679
|
+
*
|
|
21680
|
+
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
21681
|
+
* @param readToSegment the segment to mark as read
|
|
21682
|
+
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
21683
|
+
*
|
|
21684
|
+
* @category Channel API
|
|
21685
|
+
* @async
|
|
21686
|
+
*/
|
|
21687
|
+
const markChannelsAsReadBySegment = async (readings) => {
|
|
21688
|
+
const client = getActiveClient();
|
|
21689
|
+
try {
|
|
21690
|
+
await client.http.post('api/v3/channels/seen', { channels: readings });
|
|
21691
|
+
return true;
|
|
21692
|
+
}
|
|
21693
|
+
catch (e) {
|
|
21694
|
+
return false;
|
|
21695
|
+
}
|
|
21696
|
+
};
|
|
21697
|
+
|
|
21698
|
+
class MessageReadReceiptSyncEngine {
|
|
21699
|
+
constructor() {
|
|
21700
|
+
this.isActive = true;
|
|
21701
|
+
this.MAX_RETRY = 3;
|
|
21702
|
+
this.JOB_QUEUE_SIZE = 120;
|
|
21703
|
+
this.jobQueue = [];
|
|
21704
|
+
// Interval for message read receipt sync in seconds
|
|
21705
|
+
this.RECEIPT_SYNC_INTERVAL = 1;
|
|
21706
|
+
this.client = getActiveClient();
|
|
21707
|
+
// Get remaining unsync read receipts from cache
|
|
21708
|
+
this.getUnsyncJobs();
|
|
21709
|
+
}
|
|
21710
|
+
// Call this when client call client.login
|
|
21711
|
+
startSyncReadReceipt() {
|
|
21712
|
+
// Start timer when start receipt sync
|
|
21713
|
+
this.timer = setInterval(() => {
|
|
21714
|
+
this.syncReadReceipts();
|
|
21715
|
+
}, this.RECEIPT_SYNC_INTERVAL * 1000);
|
|
21716
|
+
}
|
|
21717
|
+
// Read receipt observer handling
|
|
21718
|
+
syncReadReceipts() {
|
|
21719
|
+
if (this.jobQueue.length === 0 || this.isActive === false)
|
|
21720
|
+
return;
|
|
21721
|
+
const readReceipts = this.getReadReceipts();
|
|
21722
|
+
console.log('[New 🌟 readReceipts] Sync read receipts', readReceipts);
|
|
21723
|
+
if (readReceipts) {
|
|
21724
|
+
this.markReadApi(readReceipts);
|
|
21725
|
+
}
|
|
21726
|
+
}
|
|
21727
|
+
getUnsyncJobs() {
|
|
21728
|
+
var _a;
|
|
21729
|
+
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
21730
|
+
const readReceipts = (_a = queryCache(['readReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
21731
|
+
return data.latestSyncSegment < data.latestSegment;
|
|
21732
|
+
});
|
|
21733
|
+
// Enqueue unsync read receipts to the job queue
|
|
21734
|
+
readReceipts === null || readReceipts === void 0 ? void 0 : readReceipts.forEach(({ data: readReceipt }) => {
|
|
21735
|
+
this.enqueueReadReceipt(readReceipt.channelId, readReceipt.latestSegment);
|
|
21736
|
+
});
|
|
21737
|
+
}
|
|
21738
|
+
getReadReceipts() {
|
|
21739
|
+
// get all read receipts from queue, now the queue is empty
|
|
21740
|
+
const syncJob = this.jobQueue.splice(0, this.jobQueue.length);
|
|
21741
|
+
if (syncJob.length === 0)
|
|
21742
|
+
return;
|
|
21743
|
+
return syncJob.filter(job => {
|
|
21744
|
+
var _a;
|
|
21745
|
+
const readReceipt = (_a = pullFromCache(['readReceipt', job.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21746
|
+
if (!readReceipt)
|
|
21747
|
+
return false;
|
|
21748
|
+
if (readReceipt.latestSegment > readReceipt.latestSyncSegment)
|
|
21749
|
+
return true;
|
|
21750
|
+
return false;
|
|
21751
|
+
});
|
|
21752
|
+
}
|
|
21753
|
+
async markReadApi(syncJobs) {
|
|
21754
|
+
var _a;
|
|
21755
|
+
// constuct payload
|
|
21756
|
+
// example: [{ channelId: 'channelId', readToSegment: 2 }]
|
|
21757
|
+
const syncJobsPayload = syncJobs.map(job => {
|
|
21758
|
+
return {
|
|
21759
|
+
channelId: job.channelId,
|
|
21760
|
+
readToSegment: job.segment,
|
|
21761
|
+
};
|
|
21762
|
+
});
|
|
21763
|
+
const response = await markChannelsAsReadBySegment(syncJobsPayload);
|
|
21764
|
+
if (response) {
|
|
21765
|
+
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
21766
|
+
// update lastestSyncSegment in read receipt cache
|
|
21767
|
+
const cacheKey = ['readReceipt', syncJobs[i].channelId];
|
|
21768
|
+
const readReceiptCache = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21769
|
+
pushToCache(cacheKey, Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: syncJobs[i].segment }));
|
|
21770
|
+
}
|
|
21771
|
+
}
|
|
21772
|
+
else {
|
|
21773
|
+
for (let i = 0; i < syncJobs.length; i += 1) {
|
|
21774
|
+
// push them back to queue if the syncing is failed and retry count is less than max retry
|
|
21775
|
+
if (syncJobs[i].retryCount >= this.MAX_RETRY)
|
|
21776
|
+
return;
|
|
21777
|
+
const updatedJob = Object.assign(Object.assign({}, syncJobs[i]), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */, retryCount: syncJobs[i].retryCount + 1 });
|
|
21778
|
+
this.enqueueJob(updatedJob);
|
|
21779
|
+
}
|
|
21780
|
+
}
|
|
21781
|
+
}
|
|
21782
|
+
startObservingReadReceiptQueue() {
|
|
21783
|
+
if (this.client.useLegacyUnreadCount) {
|
|
21784
|
+
this.isActive = true;
|
|
21785
|
+
this.startSyncReadReceipt();
|
|
21786
|
+
}
|
|
21787
|
+
}
|
|
21788
|
+
stopObservingReadReceiptQueue() {
|
|
21789
|
+
this.isActive = false;
|
|
21790
|
+
this.jobQueue.map(job => {
|
|
21791
|
+
if (job.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
21792
|
+
return Object.assign(Object.assign({}, job), { syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */ });
|
|
21793
|
+
}
|
|
21794
|
+
return job;
|
|
21795
|
+
});
|
|
21796
|
+
if (this.timer)
|
|
21797
|
+
clearInterval(this.timer);
|
|
21798
|
+
}
|
|
21799
|
+
// Session Management
|
|
21800
|
+
onSessionEstablished() {
|
|
21801
|
+
this.startObservingReadReceiptQueue();
|
|
21802
|
+
}
|
|
21803
|
+
onSessionDestroyed() {
|
|
21804
|
+
this.stopObservingReadReceiptQueue();
|
|
21805
|
+
this.jobQueue = [];
|
|
21806
|
+
}
|
|
21807
|
+
onTokenExpired() {
|
|
21808
|
+
this.stopObservingReadReceiptQueue();
|
|
21809
|
+
}
|
|
21810
|
+
// Network Connection Management
|
|
21811
|
+
onNetworkOffline() {
|
|
21812
|
+
// Stop observing to the read receipt queue.
|
|
21813
|
+
this.stopObservingReadReceiptQueue();
|
|
21814
|
+
}
|
|
21815
|
+
onNetworkOnline() {
|
|
21816
|
+
// Resume observing to the read receipt queue.
|
|
21817
|
+
this.startObservingReadReceiptQueue();
|
|
21818
|
+
}
|
|
21819
|
+
markRead(channelId, segment) {
|
|
21820
|
+
var _a;
|
|
21821
|
+
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
21822
|
+
const cacheKey = ['channelUnread', 'get', channelId];
|
|
21823
|
+
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21824
|
+
console.log('[New 🌟] Mark read => channel unread', channelUnread);
|
|
21825
|
+
if (channelUnread && segment > channelUnread.readToSegment) {
|
|
21826
|
+
channelUnread.readToSegment = segment;
|
|
21827
|
+
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
21828
|
+
pushToCache(cacheKey, channelUnread);
|
|
21829
|
+
fireEvent('local.channelUnread.updated', channelUnread);
|
|
21830
|
+
}
|
|
21831
|
+
// Step 2: Enqueue the read receipt
|
|
21832
|
+
this.enqueueReadReceipt(channelId, segment);
|
|
21833
|
+
}
|
|
21834
|
+
enqueueReadReceipt(channelId, segment) {
|
|
21835
|
+
var _a;
|
|
21836
|
+
const readReceipt = (_a = pullFromCache(['readReceipt', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21837
|
+
// Create new read receipt if it's not exists and add the job to queue
|
|
21838
|
+
if (!readReceipt) {
|
|
21839
|
+
const readReceiptChannel = {
|
|
21840
|
+
channelId,
|
|
21841
|
+
latestSegment: segment,
|
|
21842
|
+
latestSyncSegment: 0,
|
|
21843
|
+
};
|
|
21844
|
+
pushToCache(['readReceipt', channelId], readReceiptChannel);
|
|
21845
|
+
}
|
|
21846
|
+
else if (readReceipt.latestSegment < segment) {
|
|
21847
|
+
// Update latestSegment in read receipt cache
|
|
21848
|
+
pushToCache(['readReceipt', channelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
21849
|
+
}
|
|
21850
|
+
else if (readReceipt.latestSyncSegment >= segment) {
|
|
21851
|
+
// Skip the job when lastSyncSegment > = segment
|
|
21852
|
+
return;
|
|
21853
|
+
}
|
|
21854
|
+
let syncJob = this.getSyncJob(channelId);
|
|
21855
|
+
if (syncJob === null || syncJob.syncState === "syncing" /* Amity.ReadReceiptSyncState.SYNCING */) {
|
|
21856
|
+
syncJob = {
|
|
21857
|
+
channelId,
|
|
21858
|
+
segment,
|
|
21859
|
+
syncState: "create" /* Amity.ReadReceiptSyncState.CREATED */,
|
|
21860
|
+
retryCount: 0,
|
|
21861
|
+
};
|
|
21862
|
+
this.enqueueJob(syncJob);
|
|
21863
|
+
}
|
|
21864
|
+
else if (syncJob.segment < segment) {
|
|
21865
|
+
syncJob.segment = segment;
|
|
21866
|
+
}
|
|
21867
|
+
}
|
|
21868
|
+
getSyncJob(channelId) {
|
|
21869
|
+
const { jobQueue } = this;
|
|
21870
|
+
const targetJob = jobQueue.find(job => job.channelId === channelId);
|
|
21871
|
+
return targetJob || null;
|
|
21872
|
+
}
|
|
21873
|
+
enqueueJob(syncJob) {
|
|
21874
|
+
if (this.jobQueue.length < this.JOB_QUEUE_SIZE) {
|
|
21875
|
+
this.jobQueue.push(syncJob);
|
|
21876
|
+
}
|
|
21877
|
+
else {
|
|
21878
|
+
// Remove oldest job when queue reach maximum capacity
|
|
21879
|
+
this.jobQueue.shift();
|
|
21880
|
+
this.jobQueue.push(syncJob);
|
|
21881
|
+
}
|
|
21882
|
+
}
|
|
21883
|
+
}
|
|
21884
|
+
let instance$4 = null;
|
|
21885
|
+
var ReadReceiptSyncEngine = {
|
|
21886
|
+
getInstance: () => {
|
|
21887
|
+
if (!instance$4)
|
|
21888
|
+
instance$4 = new MessageReadReceiptSyncEngine();
|
|
21889
|
+
return instance$4;
|
|
21890
|
+
},
|
|
21891
|
+
};
|
|
21892
|
+
|
|
21675
21893
|
/**
|
|
21676
21894
|
*
|
|
21677
21895
|
* Mark subChannel as read by readToSegment
|
|
@@ -21720,7 +21938,7 @@ const reCalculateChannelUnreadInfo = (channelId) => {
|
|
|
21720
21938
|
return channelUnreadInfo;
|
|
21721
21939
|
};
|
|
21722
21940
|
|
|
21723
|
-
class
|
|
21941
|
+
class LegacyMessageReadReceiptSyncEngine {
|
|
21724
21942
|
constructor() {
|
|
21725
21943
|
this.isActive = true;
|
|
21726
21944
|
this.MAX_RETRY = 3;
|
|
@@ -21751,7 +21969,7 @@ class MessageReadReceiptSyncEngine {
|
|
|
21751
21969
|
getUnsyncJobs() {
|
|
21752
21970
|
var _a;
|
|
21753
21971
|
// Get all read receipts that has latestSyncSegment < latestSegment
|
|
21754
|
-
const readReceipts = (_a = queryCache(['
|
|
21972
|
+
const readReceipts = (_a = queryCache(['legacyReadReceipt'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
21755
21973
|
return data.latestSyncSegment < data.latestSegment;
|
|
21756
21974
|
});
|
|
21757
21975
|
// Enqueue unsync read receipts to the job queue
|
|
@@ -21770,7 +21988,7 @@ class MessageReadReceiptSyncEngine {
|
|
|
21770
21988
|
return;
|
|
21771
21989
|
// Get readReceipt from cache by subChannelId
|
|
21772
21990
|
const readReceipt = (_a = pullFromCache([
|
|
21773
|
-
'
|
|
21991
|
+
'legacyReadReceipt',
|
|
21774
21992
|
syncJob.subChannelId,
|
|
21775
21993
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21776
21994
|
if (!readReceipt)
|
|
@@ -21793,10 +22011,10 @@ class MessageReadReceiptSyncEngine {
|
|
|
21793
22011
|
if (response) {
|
|
21794
22012
|
this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
|
|
21795
22013
|
const readReceiptCache = (_a = pullFromCache([
|
|
21796
|
-
'
|
|
22014
|
+
'legacyReadReceipt',
|
|
21797
22015
|
subChannelId,
|
|
21798
22016
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21799
|
-
pushToCache(['
|
|
22017
|
+
pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceiptCache), { latestSyncSegment: segment }));
|
|
21800
22018
|
}
|
|
21801
22019
|
else if (!response) {
|
|
21802
22020
|
if (newSyncJob.retryCount > this.MAX_RETRY) {
|
|
@@ -21863,7 +22081,7 @@ class MessageReadReceiptSyncEngine {
|
|
|
21863
22081
|
subChannelUnreadInfo.readToSegment = segment;
|
|
21864
22082
|
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
21865
22083
|
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
21866
|
-
fireEvent('local.
|
|
22084
|
+
fireEvent('local.channelUnreadInfo.updated', channelUnreadInfo);
|
|
21867
22085
|
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
21868
22086
|
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
21869
22087
|
}
|
|
@@ -21872,7 +22090,10 @@ class MessageReadReceiptSyncEngine {
|
|
|
21872
22090
|
}
|
|
21873
22091
|
enqueueReadReceipt(subChannelId, segment) {
|
|
21874
22092
|
var _a;
|
|
21875
|
-
const readReceipt = (_a = pullFromCache([
|
|
22093
|
+
const readReceipt = (_a = pullFromCache([
|
|
22094
|
+
'legacyReadReceipt',
|
|
22095
|
+
subChannelId,
|
|
22096
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21876
22097
|
// Create new read receipt if it's not exists and add job to queue
|
|
21877
22098
|
if (!readReceipt) {
|
|
21878
22099
|
const readReceiptSubChannel = {
|
|
@@ -21880,10 +22101,10 @@ class MessageReadReceiptSyncEngine {
|
|
|
21880
22101
|
latestSegment: segment,
|
|
21881
22102
|
latestSyncSegment: 0,
|
|
21882
22103
|
};
|
|
21883
|
-
pushToCache(['
|
|
22104
|
+
pushToCache(['legacyReadReceipt', subChannelId], readReceiptSubChannel);
|
|
21884
22105
|
}
|
|
21885
22106
|
else if (readReceipt.latestSegment < segment) {
|
|
21886
|
-
pushToCache(['
|
|
22107
|
+
pushToCache(['legacyReadReceipt', subChannelId], Object.assign(Object.assign({}, readReceipt), { latestSegment: segment }));
|
|
21887
22108
|
}
|
|
21888
22109
|
else if (readReceipt.latestSyncSegment >= segment) {
|
|
21889
22110
|
// Skip the job when lastSyncSegment > = segment
|
|
@@ -21926,18 +22147,24 @@ class MessageReadReceiptSyncEngine {
|
|
|
21926
22147
|
}
|
|
21927
22148
|
}
|
|
21928
22149
|
let instance$3 = null;
|
|
21929
|
-
var
|
|
22150
|
+
var LegacyReadReceiptSyncEngine = {
|
|
21930
22151
|
getInstance: () => {
|
|
21931
22152
|
if (!instance$3)
|
|
21932
|
-
instance$3 = new
|
|
22153
|
+
instance$3 = new LegacyMessageReadReceiptSyncEngine();
|
|
21933
22154
|
return instance$3;
|
|
21934
22155
|
},
|
|
21935
22156
|
};
|
|
21936
22157
|
|
|
21937
22158
|
const markReadMessage = (message) => {
|
|
21938
|
-
const
|
|
21939
|
-
|
|
21940
|
-
|
|
22159
|
+
const client = getActiveClient();
|
|
22160
|
+
if (client.useLegacyUnreadCount) {
|
|
22161
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
22162
|
+
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
22163
|
+
}
|
|
22164
|
+
else {
|
|
22165
|
+
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
22166
|
+
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
22167
|
+
}
|
|
21941
22168
|
};
|
|
21942
22169
|
|
|
21943
22170
|
const messageLinkedObject = (message) => {
|
|
@@ -22925,6 +23152,24 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
22925
23152
|
channels: rawPayload.channels.map(channel => convertFromRaw(channel, { isMessagePreviewUpdated: options.isMessagePreviewUpdated })),
|
|
22926
23153
|
});
|
|
22927
23154
|
};
|
|
23155
|
+
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
23156
|
+
for (let i = 0; i < channels.length; i += 1) {
|
|
23157
|
+
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
23158
|
+
const { readToSegment, lastMentionedSegment } = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId) || {
|
|
23159
|
+
readToSegment: 0,
|
|
23160
|
+
lastMentionedSegment: 0,
|
|
23161
|
+
};
|
|
23162
|
+
pushToCache(cacheKey, {
|
|
23163
|
+
channelId: channels[i].channelId,
|
|
23164
|
+
lastSegment: channels[i].messageCount,
|
|
23165
|
+
readToSegment,
|
|
23166
|
+
lastMentionedSegment,
|
|
23167
|
+
unreadCount: channels[i].messageCount - readToSegment,
|
|
23168
|
+
isMentioned: lastMentionedSegment > readToSegment,
|
|
23169
|
+
isDeleted: channels[i].isDeleted,
|
|
23170
|
+
});
|
|
23171
|
+
}
|
|
23172
|
+
};
|
|
22928
23173
|
const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpdated: true }) => {
|
|
22929
23174
|
const client = getActiveClient();
|
|
22930
23175
|
const networkPreviewSetting = await client.getMessagePreviewSetting(false);
|
|
@@ -22934,23 +23179,34 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22934
23179
|
rawPayload.messagePreviews.length > 0) {
|
|
22935
23180
|
updateChannelMessagePreviewCache(rawPayload);
|
|
22936
23181
|
}
|
|
22937
|
-
|
|
22938
|
-
|
|
22939
|
-
|
|
22940
|
-
|
|
22941
|
-
|
|
22942
|
-
|
|
22943
|
-
|
|
22944
|
-
|
|
22945
|
-
|
|
22946
|
-
|
|
22947
|
-
|
|
22948
|
-
|
|
23182
|
+
if (client.useLegacyUnreadCount) {
|
|
23183
|
+
updateChannelUnread({
|
|
23184
|
+
channels: rawPayload.channels,
|
|
23185
|
+
channelUsers: rawPayload.channelUsers,
|
|
23186
|
+
currentUserId: client.userId,
|
|
23187
|
+
});
|
|
23188
|
+
}
|
|
23189
|
+
else {
|
|
23190
|
+
const markerIds = rawPayload.channels
|
|
23191
|
+
// filter channel by type. Only conversation, community and broadcast type are included.
|
|
23192
|
+
.filter(isUnreadCountSupport)
|
|
23193
|
+
.map(({ channelInternalId }) => channelInternalId);
|
|
23194
|
+
if (markerIds.length > 0) {
|
|
23195
|
+
// since the get markers method requires a channel cache to function with the reducer.
|
|
23196
|
+
preUpdateChannelCache(rawPayload, {
|
|
23197
|
+
isMessagePreviewUpdated: options.isMessagePreviewUpdated,
|
|
23198
|
+
});
|
|
23199
|
+
try {
|
|
23200
|
+
await getChannelMarkers(markerIds);
|
|
23201
|
+
}
|
|
23202
|
+
catch (e) {
|
|
23203
|
+
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
23204
|
+
}
|
|
22949
23205
|
}
|
|
22950
23206
|
}
|
|
22951
|
-
//
|
|
23207
|
+
// convert raw channel to internal channel
|
|
22952
23208
|
const channels = rawPayload.channels.map(payload => convertFromRaw(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
22953
|
-
// user
|
|
23209
|
+
// convert raw channel user to membership (add user object)
|
|
22954
23210
|
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
22955
23211
|
return convertRawMembershipToMembership(channelUser);
|
|
22956
23212
|
});
|
|
@@ -23077,15 +23333,28 @@ const getSubChannelsUnreadCount = (channel, marker) => {
|
|
|
23077
23333
|
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;
|
|
23078
23334
|
};
|
|
23079
23335
|
|
|
23336
|
+
const getLegacyChannelUnread = (channelId) => {
|
|
23337
|
+
var _a;
|
|
23338
|
+
return (_a = pullFromCache(['channelUnread', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23339
|
+
};
|
|
23340
|
+
|
|
23080
23341
|
const constructChannelDynamicValue = (channel) => {
|
|
23342
|
+
const client = getActiveClient();
|
|
23081
23343
|
const rest = __rest(channel, ["messageCount"]);
|
|
23082
23344
|
return shallowClone(rest, {
|
|
23083
|
-
get
|
|
23084
|
-
|
|
23345
|
+
get unreadCount() {
|
|
23346
|
+
var _a, _b;
|
|
23347
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.unreadCount) !== null && _b !== void 0 ? _b : 0;
|
|
23085
23348
|
},
|
|
23086
23349
|
get subChannelsUnreadCount() {
|
|
23087
23350
|
return getSubChannelsUnreadCount(rest);
|
|
23088
23351
|
},
|
|
23352
|
+
get isMentioned() {
|
|
23353
|
+
var _a, _b;
|
|
23354
|
+
if (client.useLegacyUnreadCount)
|
|
23355
|
+
return (_b = (_a = getLegacyChannelUnread(rest.channelId)) === null || _a === void 0 ? void 0 : _a.isMentioned) !== null && _b !== void 0 ? _b : false;
|
|
23356
|
+
return getChannelIsMentioned(rest);
|
|
23357
|
+
},
|
|
23089
23358
|
});
|
|
23090
23359
|
};
|
|
23091
23360
|
|
|
@@ -23861,6 +24130,25 @@ var readReceiptSyncEngineOnLoginHandler = () => {
|
|
|
23861
24130
|
};
|
|
23862
24131
|
};
|
|
23863
24132
|
|
|
24133
|
+
var legacyReadReceiptSyncEngineOnLoginHandler = () => {
|
|
24134
|
+
const readReceiptSyncEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
24135
|
+
readReceiptSyncEngine.startSyncReadReceipt();
|
|
24136
|
+
onSessionStateChange(state => {
|
|
24137
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
24138
|
+
readReceiptSyncEngine.onSessionEstablished();
|
|
24139
|
+
}
|
|
24140
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
24141
|
+
readReceiptSyncEngine.onTokenExpired();
|
|
24142
|
+
}
|
|
24143
|
+
else {
|
|
24144
|
+
readReceiptSyncEngine.onSessionDestroyed();
|
|
24145
|
+
}
|
|
24146
|
+
});
|
|
24147
|
+
return () => {
|
|
24148
|
+
readReceiptSyncEngine.onSessionDestroyed();
|
|
24149
|
+
};
|
|
24150
|
+
};
|
|
24151
|
+
|
|
23864
24152
|
const onOnline = (callback) => {
|
|
23865
24153
|
if (typeof window !== 'undefined' && window.addEventListener) {
|
|
23866
24154
|
window.addEventListener('online', callback);
|
|
@@ -24873,6 +25161,7 @@ const enableUnreadCount = () => {
|
|
|
24873
25161
|
if (client.isUnreadCountEnabled)
|
|
24874
25162
|
return false;
|
|
24875
25163
|
client.isUnreadCountEnabled = true;
|
|
25164
|
+
client.useLegacyUnreadCount = false;
|
|
24876
25165
|
client.emitter.emit('unreadCountEnabled', true);
|
|
24877
25166
|
return true;
|
|
24878
25167
|
};
|
|
@@ -25188,7 +25477,12 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25188
25477
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25189
25478
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25190
25479
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25191
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(),
|
|
25480
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler());
|
|
25481
|
+
if (client.useLegacyUnreadCount) {
|
|
25482
|
+
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
25483
|
+
}
|
|
25484
|
+
else
|
|
25485
|
+
subscriptions.push(legacyReadReceiptSyncEngineOnLoginHandler());
|
|
25192
25486
|
const markerSyncUnsubscriber = await startMarkerSync();
|
|
25193
25487
|
subscriptions.push(markerSyncUnsubscriber);
|
|
25194
25488
|
}
|
|
@@ -25369,6 +25663,8 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25369
25663
|
const sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
25370
25664
|
const sessionHandler = undefined;
|
|
25371
25665
|
const isUnreadCountEnabled = false;
|
|
25666
|
+
// Legacy unread count is true by default
|
|
25667
|
+
const useLegacyUnreadCount = true;
|
|
25372
25668
|
const client = {
|
|
25373
25669
|
version: `${VERSION}`,
|
|
25374
25670
|
apiKey,
|
|
@@ -25398,6 +25694,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25398
25694
|
getMessagePreviewSetting,
|
|
25399
25695
|
use: () => setActiveClient(client),
|
|
25400
25696
|
isUnreadCountEnabled,
|
|
25697
|
+
useLegacyUnreadCount,
|
|
25401
25698
|
getMarkerSyncConsistentMode,
|
|
25402
25699
|
/**
|
|
25403
25700
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
@@ -32528,6 +32825,24 @@ var index$f = /*#__PURE__*/Object.freeze({
|
|
|
32528
32825
|
stopMessageReceiptSync: stopMessageReceiptSync
|
|
32529
32826
|
});
|
|
32530
32827
|
|
|
32828
|
+
/**
|
|
32829
|
+
* Internal used only
|
|
32830
|
+
*
|
|
32831
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
32832
|
+
*
|
|
32833
|
+
* @param callback The function to call when the event was fired
|
|
32834
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
32835
|
+
*
|
|
32836
|
+
* @category MessageMarker Events
|
|
32837
|
+
*/
|
|
32838
|
+
const onChannelUnreadInfoUpdatedLocal = (callback) => {
|
|
32839
|
+
const client = getActiveClient();
|
|
32840
|
+
const filter = (payload) => {
|
|
32841
|
+
callback(payload);
|
|
32842
|
+
};
|
|
32843
|
+
return createEventSubscriber(client, 'channelMarker/onChannelUnreadInfoUpdatedLocal', 'local.channelUnreadInfo.updated', filter);
|
|
32844
|
+
};
|
|
32845
|
+
|
|
32531
32846
|
/**
|
|
32532
32847
|
* Internal used only
|
|
32533
32848
|
*
|
|
@@ -32543,7 +32858,7 @@ const onChannelUnreadUpdatedLocal = (callback) => {
|
|
|
32543
32858
|
const filter = (payload) => {
|
|
32544
32859
|
callback(payload);
|
|
32545
32860
|
};
|
|
32546
|
-
return createEventSubscriber(client, '
|
|
32861
|
+
return createEventSubscriber(client, 'channel/onChannelUnreadUpdatedLocal', 'local.channelUnread.updated', filter);
|
|
32547
32862
|
};
|
|
32548
32863
|
|
|
32549
32864
|
/* begin_public_function
|
|
@@ -32745,6 +33060,7 @@ const getChannel = (channelId, callback) => {
|
|
|
32745
33060
|
return onSubChannelUpdated(updateMessagePreview);
|
|
32746
33061
|
}, 'channelId', 'channel'),
|
|
32747
33062
|
convertEventPayload(onSubChannelCreated, 'channelId', 'channel'),
|
|
33063
|
+
convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
32748
33064
|
convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
32749
33065
|
], {
|
|
32750
33066
|
forceDispatch: true,
|
|
@@ -33258,6 +33574,10 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
33258
33574
|
},
|
|
33259
33575
|
action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
|
|
33260
33576
|
},
|
|
33577
|
+
{
|
|
33578
|
+
fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
33579
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
33580
|
+
},
|
|
33261
33581
|
{
|
|
33262
33582
|
fn: convertEventPayload(onChannelUnreadUpdatedLocal, 'channelId', 'channel'),
|
|
33263
33583
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|