@amityco/ts-sdk 7.1.1-207e990f.0 → 7.1.1-5d7c3fd0.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 +1 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +0 -2
- package/dist/@types/core/model.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 +1 -1
- package/dist/@types/domains/client.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/utils/constructChannelDynamicValue.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +1 -0
- 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 +1 -0
- 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/index.cjs.js +65 -412
- package/dist/index.esm.js +65 -412
- 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/utils/markReadMessage.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +1 -2
- package/src/@types/core/model.ts +0 -4
- package/src/@types/core/readReceipt.ts +1 -14
- package/src/@types/domains/channel.ts +0 -13
- package/src/@types/domains/client.ts +1 -2
- 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/utils/constructChannelDynamicValue.ts +2 -12
- package/src/channelRepository/utils/prepareChannelPayload.ts +17 -57
- package/src/client/api/createClient.ts +4 -4
- package/src/client/api/enableUnreadCount.ts +0 -1
- package/src/client/api/login.ts +1 -5
- package/src/client/utils/ReadReceiptSync/readReceiptSyncEngine.ts +99 -70
- package/src/client/utils/endpoints.ts +1 -0
- package/src/client/utils/setClientToken.ts +8 -0
- package/src/core/model/idResolvers.ts +0 -2
- 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/{channelRepository → marker}/events/onChannelUnreadUpdatedLocal.ts +3 -3
- package/src/messageRepository/events/onMessageCreated.ts +0 -34
- package/src/messageRepository/utils/markReadMessage.ts +3 -10
- 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/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/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
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { pullFromCache, pushToCache, queryCache } from '~/cache/api';
|
|
2
2
|
import { getActiveClient } from '../../api/activeClient';
|
|
3
|
+
import { markAsReadBySegment } from '~/subChannelRepository/api/markAsReadBySegment';
|
|
4
|
+
import { reCalculateChannelUnreadInfo } from '~/marker/utils/reCalculateChannelUnreadInfo';
|
|
3
5
|
import { fireEvent } from '~/core/events';
|
|
4
|
-
import { markChannelsAsReadBySegment } from '~/channelRepository/api/markChannelsAsReadBySegment';
|
|
5
6
|
|
|
6
7
|
export class MessageReadReceiptSyncEngine {
|
|
7
8
|
private client: Amity.Client;
|
|
@@ -37,9 +38,9 @@ export class MessageReadReceiptSyncEngine {
|
|
|
37
38
|
syncReadReceipts(): void {
|
|
38
39
|
if (this.jobQueue.length === 0 || this.isActive === false) return;
|
|
39
40
|
|
|
40
|
-
const
|
|
41
|
-
if (
|
|
42
|
-
this.markReadApi(
|
|
41
|
+
const readReceipt = this.getReadReceipt();
|
|
42
|
+
if (readReceipt) {
|
|
43
|
+
this.markReadApi(readReceipt);
|
|
43
44
|
}
|
|
44
45
|
}
|
|
45
46
|
|
|
@@ -51,64 +52,79 @@ export class MessageReadReceiptSyncEngine {
|
|
|
51
52
|
|
|
52
53
|
// Enqueue unsync read receipts to the job queue
|
|
53
54
|
readReceipts?.forEach(({ data: readReceipt }) => {
|
|
54
|
-
this.enqueueReadReceipt(readReceipt.
|
|
55
|
+
this.enqueueReadReceipt(readReceipt.subChannelId, readReceipt.latestSegment);
|
|
55
56
|
});
|
|
56
57
|
}
|
|
57
58
|
|
|
58
|
-
private
|
|
59
|
-
//
|
|
60
|
-
const syncJob = this.jobQueue
|
|
61
|
-
if (syncJob.length === 0) return;
|
|
59
|
+
private getReadReceipt(): Amity.ReadReceiptSyncJob | undefined {
|
|
60
|
+
// Get first read receipt in queue
|
|
61
|
+
const syncJob = this.jobQueue[0];
|
|
62
62
|
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
63
|
+
if (!syncJob) return;
|
|
64
|
+
// Skip when it's syncing
|
|
65
|
+
if (syncJob.syncState === Amity.ReadReceiptSyncState.SYNCING) return;
|
|
66
|
+
|
|
67
|
+
// Get readReceipt from cache by subChannelId
|
|
68
|
+
const readReceipt = pullFromCache<Amity.ReadReceipt>([
|
|
69
|
+
'readReceipt',
|
|
70
|
+
syncJob.subChannelId,
|
|
71
|
+
])?.data;
|
|
72
|
+
|
|
73
|
+
if (!readReceipt) return;
|
|
74
|
+
|
|
75
|
+
if (readReceipt?.latestSegment > readReceipt?.latestSyncSegment) {
|
|
76
|
+
syncJob.segment = readReceipt.latestSegment;
|
|
77
|
+
return syncJob;
|
|
78
|
+
}
|
|
79
|
+
// Clear all synced job in job queue
|
|
80
|
+
this.removeSynedReceipt(readReceipt.subChannelId, readReceipt.latestSegment);
|
|
81
|
+
|
|
82
|
+
// Recursion getReadReceipt() until get unsync read receipt or job queue is empty
|
|
83
|
+
return this.getReadReceipt();
|
|
69
84
|
}
|
|
70
85
|
|
|
71
|
-
private async markReadApi(
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
channelId: job.channelId,
|
|
77
|
-
readToSegment: job.segment,
|
|
78
|
-
};
|
|
79
|
-
});
|
|
86
|
+
private async markReadApi(syncJob: Amity.ReadReceiptSyncJob): Promise<void> {
|
|
87
|
+
const newSyncJob = syncJob;
|
|
88
|
+
newSyncJob.syncState = Amity.ReadReceiptSyncState.SYNCING;
|
|
89
|
+
|
|
90
|
+
const { subChannelId, segment } = newSyncJob;
|
|
80
91
|
|
|
81
|
-
const response = await
|
|
92
|
+
const response = await markAsReadBySegment({ subChannelId, readToSegment: segment });
|
|
82
93
|
|
|
83
94
|
if (response) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
95
|
+
this.removeSynedReceipt(syncJob.subChannelId, syncJob.segment);
|
|
96
|
+
|
|
97
|
+
const readReceiptCache = pullFromCache<Amity.ReadReceipt>([
|
|
98
|
+
'readReceipt',
|
|
99
|
+
subChannelId,
|
|
100
|
+
])?.data;
|
|
101
|
+
|
|
102
|
+
pushToCache(['readReceipt', subChannelId], {
|
|
103
|
+
...readReceiptCache,
|
|
104
|
+
latestSyncSegment: segment,
|
|
105
|
+
});
|
|
106
|
+
} else if (!response) {
|
|
107
|
+
if (newSyncJob.retryCount > this.MAX_RETRY) {
|
|
108
|
+
this.removeJobFromQueue(newSyncJob);
|
|
109
|
+
} else {
|
|
110
|
+
newSyncJob.retryCount += 1;
|
|
111
|
+
newSyncJob.syncState = Amity.ReadReceiptSyncState.CREATED;
|
|
93
112
|
}
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
// push them back to queue if the syncing is failed and retry count is less than max retry
|
|
97
|
-
if (syncJobs[i].retryCount >= this.MAX_RETRY) return;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
98
115
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
syncState: Amity.ReadReceiptSyncState.CREATED,
|
|
102
|
-
retryCount: syncJobs[i].retryCount + 1,
|
|
103
|
-
};
|
|
116
|
+
private removeSynedReceipt(subChannelId: string, segment: number) {
|
|
117
|
+
const syncJobs = this.jobQueue;
|
|
104
118
|
|
|
105
|
-
|
|
119
|
+
syncJobs.forEach(job => {
|
|
120
|
+
if (job.subChannelId === subChannelId && job.segment <= segment) {
|
|
121
|
+
this.removeJobFromQueue(job);
|
|
106
122
|
}
|
|
107
|
-
}
|
|
123
|
+
});
|
|
108
124
|
}
|
|
109
125
|
|
|
110
126
|
private startObservingReadReceiptQueue(): void {
|
|
111
|
-
if (this.client.
|
|
127
|
+
if (this.client.isUnreadCountEnabled) {
|
|
112
128
|
this.isActive = true;
|
|
113
129
|
this.startSyncReadReceipt();
|
|
114
130
|
}
|
|
@@ -117,7 +133,8 @@ export class MessageReadReceiptSyncEngine {
|
|
|
117
133
|
private stopObservingReadReceiptQueue(): void {
|
|
118
134
|
this.isActive = false;
|
|
119
135
|
|
|
120
|
-
this.jobQueue
|
|
136
|
+
const syncJobs = this.jobQueue;
|
|
137
|
+
syncJobs.map(job => {
|
|
121
138
|
if (job.syncState === Amity.ReadReceiptSyncState.SYNCING) {
|
|
122
139
|
return { ...job, syncState: Amity.ReadReceiptSyncState.CREATED };
|
|
123
140
|
}
|
|
@@ -153,47 +170,50 @@ export class MessageReadReceiptSyncEngine {
|
|
|
153
170
|
this.startObservingReadReceiptQueue();
|
|
154
171
|
}
|
|
155
172
|
|
|
156
|
-
markRead(
|
|
157
|
-
// Step 1: Optimistic update of
|
|
158
|
-
const cacheKey = ['
|
|
159
|
-
const
|
|
173
|
+
markRead(subChannelId: string, segment: number): void {
|
|
174
|
+
// Step 1: Optimistic update of subChannelUnreadInfo.readToSegment to message.segment
|
|
175
|
+
const cacheKey = ['subChannelUnreadInfo', 'get', subChannelId];
|
|
176
|
+
const subChannelUnreadInfo = pullFromCache<Amity.SubChannelUnreadInfo>(cacheKey)?.data;
|
|
160
177
|
|
|
161
|
-
if (
|
|
162
|
-
|
|
163
|
-
|
|
178
|
+
if (subChannelUnreadInfo && segment > subChannelUnreadInfo.readToSegment) {
|
|
179
|
+
subChannelUnreadInfo.readToSegment = segment;
|
|
180
|
+
subChannelUnreadInfo.unreadCount = Math.max(subChannelUnreadInfo.lastSegment - segment, 0);
|
|
164
181
|
|
|
165
|
-
|
|
166
|
-
fireEvent('local.channelUnread.updated',
|
|
182
|
+
const channelUnreadInfo = reCalculateChannelUnreadInfo(subChannelUnreadInfo.channelId);
|
|
183
|
+
fireEvent('local.channelUnread.updated', channelUnreadInfo);
|
|
184
|
+
|
|
185
|
+
pushToCache(cacheKey, subChannelUnreadInfo);
|
|
186
|
+
fireEvent('local.subChannelUnread.updated', subChannelUnreadInfo);
|
|
167
187
|
}
|
|
168
188
|
|
|
169
189
|
// Step 2: Enqueue the read receipt
|
|
170
|
-
this.enqueueReadReceipt(
|
|
190
|
+
this.enqueueReadReceipt(subChannelId, segment);
|
|
171
191
|
}
|
|
172
192
|
|
|
173
|
-
private enqueueReadReceipt(
|
|
174
|
-
const readReceipt = pullFromCache<Amity.ReadReceipt>(['readReceipt',
|
|
193
|
+
private enqueueReadReceipt(subChannelId: string, segment: number): void {
|
|
194
|
+
const readReceipt = pullFromCache<Amity.ReadReceipt>(['readReceipt', subChannelId])?.data;
|
|
175
195
|
|
|
176
|
-
// Create new read receipt if it's not exists and add
|
|
196
|
+
// Create new read receipt if it's not exists and add job to queue
|
|
177
197
|
if (!readReceipt) {
|
|
178
|
-
const
|
|
179
|
-
|
|
198
|
+
const readReceiptSubChannel: Amity.ReadReceipt = {
|
|
199
|
+
subChannelId,
|
|
180
200
|
latestSegment: segment,
|
|
181
201
|
latestSyncSegment: 0,
|
|
182
202
|
};
|
|
183
|
-
|
|
203
|
+
|
|
204
|
+
pushToCache(['readReceipt', subChannelId], readReceiptSubChannel);
|
|
184
205
|
} else if (readReceipt.latestSegment < segment) {
|
|
185
|
-
|
|
186
|
-
pushToCache(['readReceipt', channelId], { ...readReceipt, latestSegment: segment });
|
|
206
|
+
pushToCache(['readReceipt', subChannelId], { ...readReceipt, latestSegment: segment });
|
|
187
207
|
} else if (readReceipt.latestSyncSegment >= segment) {
|
|
188
208
|
// Skip the job when lastSyncSegment > = segment
|
|
189
209
|
return;
|
|
190
210
|
}
|
|
191
211
|
|
|
192
|
-
let syncJob: Amity.ReadReceiptSyncJob | null = this.getSyncJob(
|
|
212
|
+
let syncJob: Amity.ReadReceiptSyncJob | null = this.getSyncJob(subChannelId);
|
|
193
213
|
|
|
194
214
|
if (syncJob === null || syncJob.syncState === Amity.ReadReceiptSyncState.SYNCING) {
|
|
195
215
|
syncJob = {
|
|
196
|
-
|
|
216
|
+
subChannelId,
|
|
197
217
|
segment,
|
|
198
218
|
syncState: Amity.ReadReceiptSyncState.CREATED,
|
|
199
219
|
retryCount: 0,
|
|
@@ -205,9 +225,11 @@ export class MessageReadReceiptSyncEngine {
|
|
|
205
225
|
}
|
|
206
226
|
}
|
|
207
227
|
|
|
208
|
-
private getSyncJob(
|
|
209
|
-
const
|
|
210
|
-
|
|
228
|
+
private getSyncJob(subChannelId: string): Amity.ReadReceiptSyncJob | null {
|
|
229
|
+
const syncJobs = this.jobQueue;
|
|
230
|
+
|
|
231
|
+
const targetJob = syncJobs.find(job => job.subChannelId === subChannelId);
|
|
232
|
+
|
|
211
233
|
return targetJob || null;
|
|
212
234
|
}
|
|
213
235
|
|
|
@@ -220,6 +242,13 @@ export class MessageReadReceiptSyncEngine {
|
|
|
220
242
|
this.jobQueue.push(syncJob);
|
|
221
243
|
}
|
|
222
244
|
}
|
|
245
|
+
|
|
246
|
+
private removeJobFromQueue(item: Amity.ReadReceiptSyncJob) {
|
|
247
|
+
const index = this.jobQueue.indexOf(item);
|
|
248
|
+
if (index > -1) {
|
|
249
|
+
this.jobQueue.splice(index, 1);
|
|
250
|
+
}
|
|
251
|
+
}
|
|
223
252
|
}
|
|
224
253
|
|
|
225
254
|
let instance: MessageReadReceiptSyncEngine | null = null;
|
|
@@ -30,6 +30,14 @@ export const setClientToken = async (params: Parameters<typeof getToken>[0]) =>
|
|
|
30
30
|
isUserDeleted: false,
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
+
client.upload.defaults.headers.common.Authorization = `Bearer ${accessToken}`;
|
|
34
|
+
|
|
35
|
+
client.upload.defaults.metadata = {
|
|
36
|
+
tokenExpiry: expiresAt,
|
|
37
|
+
isGlobalBanned: false,
|
|
38
|
+
isUserDeleted: false,
|
|
39
|
+
};
|
|
40
|
+
|
|
33
41
|
// manually setup the token for ws transport
|
|
34
42
|
if (client.ws) client.ws.io.opts.query = { token: accessToken };
|
|
35
43
|
|
|
@@ -26,8 +26,6 @@ const idResolvers: Resolvers = {
|
|
|
26
26
|
channelUnreadInfo: ({ channelId }) => channelId,
|
|
27
27
|
subChannelUnreadInfo: ({ subChannelId }) => subChannelId,
|
|
28
28
|
|
|
29
|
-
channelUnread: ({ channelId }) => channelId,
|
|
30
|
-
|
|
31
29
|
channelMarker: ({ entityId, userId }) => `${entityId}#${userId}`,
|
|
32
30
|
subChannelMarker: ({ entityId, feedId, userId }) => `${entityId}#${feedId}#${userId}`,
|
|
33
31
|
messageMarker: ({ feedId, contentId, creatorId }) => `${feedId}#${contentId}#${creatorId}`,
|
|
@@ -42,7 +42,7 @@ export const uploadFile = async <T extends Amity.FileType = any>(
|
|
|
42
42
|
? (formData as any).getHeaders()
|
|
43
43
|
: { 'content-type': 'multipart/form-data' };
|
|
44
44
|
|
|
45
|
-
const { data } = await client.
|
|
45
|
+
const { data } = await client.upload.post<Amity.CreateFilePayload<T>>('/api/v4/files', formData, {
|
|
46
46
|
headers,
|
|
47
47
|
onUploadProgress({ loaded, total = 100 }) {
|
|
48
48
|
onProgress && onProgress(Math.round((loaded * 100) / total));
|
|
@@ -42,7 +42,7 @@ export const uploadImage = async (
|
|
|
42
42
|
? (formData as any).getHeaders()
|
|
43
43
|
: { 'content-type': 'multipart/form-data' };
|
|
44
44
|
|
|
45
|
-
const { data } = await client.
|
|
45
|
+
const { data } = await client.upload.post<Amity.CreateFilePayload<'image'>>(
|
|
46
46
|
'/api/v4/images',
|
|
47
47
|
formData,
|
|
48
48
|
{
|
|
@@ -48,7 +48,7 @@ export const uploadVideo = async (
|
|
|
48
48
|
? (formData as any).getHeaders()
|
|
49
49
|
: { 'content-type': 'multipart/form-data' };
|
|
50
50
|
|
|
51
|
-
const { data } = await client.
|
|
51
|
+
const { data } = await client.upload.post<Amity.CreateFilePayload<'video'>>(
|
|
52
52
|
'/api/v4/videos',
|
|
53
53
|
formData,
|
|
54
54
|
{
|
|
@@ -4,12 +4,12 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
4
4
|
/**
|
|
5
5
|
* Internal used only
|
|
6
6
|
*
|
|
7
|
-
* Fired when an {@link Amity.
|
|
7
|
+
* Fired when an {@link Amity.userMessageFeedMarkers} has been resolved by Object Rsesolver
|
|
8
8
|
*
|
|
9
9
|
* @param callback The function to call when the event was fired
|
|
10
10
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11
11
|
*
|
|
12
|
-
* @category
|
|
12
|
+
* @category MessageMarker Events
|
|
13
13
|
*/
|
|
14
14
|
export const onChannelUnreadUpdatedLocal = (
|
|
15
15
|
callback: Amity.Listener<Amity.Events['local.channelUnread.updated']>,
|
|
@@ -22,7 +22,7 @@ export const onChannelUnreadUpdatedLocal = (
|
|
|
22
22
|
|
|
23
23
|
return createEventSubscriber(
|
|
24
24
|
client,
|
|
25
|
-
'
|
|
25
|
+
'channelMarker/onChannelUnreadUpdatedLocal',
|
|
26
26
|
'local.channelUnread.updated',
|
|
27
27
|
filter,
|
|
28
28
|
);
|
|
@@ -6,7 +6,6 @@ import { reCalculateChannelUnreadInfo } from '~/marker/utils/reCalculateChannelU
|
|
|
6
6
|
import { getActiveUser } from '~/client/api/activeUser';
|
|
7
7
|
import { markReadMessage } from '../utils/markReadMessage';
|
|
8
8
|
import { prepareMessagePayload } from '../utils';
|
|
9
|
-
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
10
9
|
|
|
11
10
|
/**
|
|
12
11
|
* ```js
|
|
@@ -41,39 +40,6 @@ export const onMessageCreatedMqtt = (
|
|
|
41
40
|
});
|
|
42
41
|
}
|
|
43
42
|
|
|
44
|
-
if (client.useLegacyUnreadCount) {
|
|
45
|
-
rawPayload.messages.forEach(message => {
|
|
46
|
-
const channelUnread = pullFromCache<Amity.ChannelUnread>([
|
|
47
|
-
'channelUnread',
|
|
48
|
-
'get',
|
|
49
|
-
message.channelId,
|
|
50
|
-
])?.data;
|
|
51
|
-
if (!channelUnread || channelUnread.lastSegment >= message.segment) return;
|
|
52
|
-
|
|
53
|
-
const lastSegment = message.segment;
|
|
54
|
-
const isMentionedInMessage = message.mentionedUsers?.some(mention => {
|
|
55
|
-
return (
|
|
56
|
-
mention.type === 'channel' ||
|
|
57
|
-
(mention.type === 'user' &&
|
|
58
|
-
client.userId &&
|
|
59
|
-
mention.userPublicIds.includes(client.userId))
|
|
60
|
-
);
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
const lastMentionSegment = isMentionedInMessage
|
|
64
|
-
? message.segment
|
|
65
|
-
: channelUnread.lastMentionSegment;
|
|
66
|
-
|
|
67
|
-
pushToCache(['channelUnread', 'get', message.channelId], {
|
|
68
|
-
...channelUnread,
|
|
69
|
-
lastSegment,
|
|
70
|
-
unreadCount: lastSegment - channelUnread.readToSegment,
|
|
71
|
-
lastMentionSegment,
|
|
72
|
-
isMentioned: !(channelUnread.readToSegment >= lastMentionSegment),
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
43
|
// Update in cache
|
|
78
44
|
ingestInCache(payload);
|
|
79
45
|
|
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
1
|
import ReadReceiptSyncEngine from '~/client/utils/ReadReceiptSync/readReceiptSyncEngine';
|
|
3
|
-
import LegacyReadReceiptSyncEngine from '~/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine';
|
|
4
2
|
|
|
5
3
|
export const markReadMessage = (message: Amity.InternalMessage) => {
|
|
6
|
-
const
|
|
4
|
+
const { subChannelId, channelSegment } = message;
|
|
5
|
+
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
7
6
|
|
|
8
|
-
|
|
9
|
-
const markReadReceiptEngine = ReadReceiptSyncEngine.getInstance();
|
|
10
|
-
markReadReceiptEngine.markRead(message.channelId, message.channelSegment);
|
|
11
|
-
} else {
|
|
12
|
-
const markReadReceiptEngine = LegacyReadReceiptSyncEngine.getInstance();
|
|
13
|
-
markReadReceiptEngine.markRead(message.subChannelId, message.channelSegment);
|
|
14
|
-
}
|
|
7
|
+
markReadReceiptEngine.markRead(subChannelId, channelSegment);
|
|
15
8
|
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
*
|
|
3
|
-
* Mark subChannel as read by readToSegment
|
|
4
|
-
*
|
|
5
|
-
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
6
|
-
* @param readToSegment the segment to mark as read
|
|
7
|
-
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
8
|
-
*
|
|
9
|
-
* @category Channel API
|
|
10
|
-
* @async
|
|
11
|
-
*/
|
|
12
|
-
export declare const markChannelsAsReadBySegment: (readings: {
|
|
13
|
-
channelId: Amity.Channel['channelId'];
|
|
14
|
-
readToSegment: number;
|
|
15
|
-
}[]) => Promise<boolean>;
|
|
16
|
-
//# sourceMappingURL=markChannelsAsReadBySegment.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"markChannelsAsReadBySegment.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/api/markChannelsAsReadBySegment.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,2BAA2B,aAC5B;IACR,SAAS,EAAE,MAAM,OAAO,CAAC,WAAW,CAAC,CAAC;IACtC,aAAa,EAAE,MAAM,CAAC;CACvB,EAAE,KACF,QAAQ,OAAO,CASjB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onChannelUnreadUpdatedLocal.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/events/onChannelUnreadUpdatedLocal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,2BAA2B,aAC5B,MAAM,QAAQ,CAAC,MAAM,MAAM,CAAC,6BAA6B,CAAC,CAAC,KACpE,MAAM,YAaR,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"getLegacyChannelUnread.d.ts","sourceRoot":"","sources":["../../../src/channelRepository/utils/getLegacyChannelUnread.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,sBAAsB,cAAe,MAAM,wCAEvD,CAAC"}
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
export declare class LegacyMessageReadReceiptSyncEngine {
|
|
2
|
-
private client;
|
|
3
|
-
private isActive;
|
|
4
|
-
private MAX_RETRY;
|
|
5
|
-
private JOB_QUEUE_SIZE;
|
|
6
|
-
private jobQueue;
|
|
7
|
-
private timer;
|
|
8
|
-
private RECEIPT_SYNC_INTERVAL;
|
|
9
|
-
constructor();
|
|
10
|
-
startSyncReadReceipt(): void;
|
|
11
|
-
syncReadReceipts(): void;
|
|
12
|
-
private getUnsyncJobs;
|
|
13
|
-
private getReadReceipt;
|
|
14
|
-
private markReadApi;
|
|
15
|
-
private removeSynedReceipt;
|
|
16
|
-
private startObservingReadReceiptQueue;
|
|
17
|
-
private stopObservingReadReceiptQueue;
|
|
18
|
-
onSessionEstablished(): void;
|
|
19
|
-
onSessionDestroyed(): void;
|
|
20
|
-
onTokenExpired(): void;
|
|
21
|
-
onNetworkOffline(): void;
|
|
22
|
-
onNetworkOnline(): void;
|
|
23
|
-
markRead(subChannelId: string, segment: number): void;
|
|
24
|
-
private enqueueReadReceipt;
|
|
25
|
-
private getSyncJob;
|
|
26
|
-
private enqueueJob;
|
|
27
|
-
private removeJobFromQueue;
|
|
28
|
-
}
|
|
29
|
-
declare const _default: {
|
|
30
|
-
getInstance: () => LegacyMessageReadReceiptSyncEngine;
|
|
31
|
-
};
|
|
32
|
-
export default _default;
|
|
33
|
-
//# sourceMappingURL=legacyReadReceiptSyncEngine.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacyReadReceiptSyncEngine.d.ts","sourceRoot":"","sources":["../../../../src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngine.ts"],"names":[],"mappings":"AAMA,qBAAa,kCAAkC;IAC7C,OAAO,CAAC,MAAM,CAAe;IAE7B,OAAO,CAAC,QAAQ,CAAQ;IAExB,OAAO,CAAC,SAAS,CAAK;IAEtB,OAAO,CAAC,cAAc,CAAO;IAE7B,OAAO,CAAC,QAAQ,CAAwC;IAExD,OAAO,CAAC,KAAK,CAA2B;IAGxC,OAAO,CAAC,qBAAqB,CAAK;;IASlC,oBAAoB;IAQpB,gBAAgB,IAAI,IAAI;IASxB,OAAO,CAAC,aAAa;IAcrB,OAAO,CAAC,cAAc;YA2BR,WAAW;IA8BzB,OAAO,CAAC,kBAAkB;IAU1B,OAAO,CAAC,8BAA8B;IAOtC,OAAO,CAAC,6BAA6B;IAgBrC,oBAAoB,IAAI,IAAI;IAI5B,kBAAkB,IAAI,IAAI;IAK1B,cAAc,IAAI,IAAI;IAKtB,gBAAgB,IAAI,IAAI;IAKxB,eAAe,IAAI,IAAI;IAKvB,QAAQ,CAAC,YAAY,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI;IAoBrD,OAAO,CAAC,kBAAkB;IAsC1B,OAAO,CAAC,UAAU;IAQlB,OAAO,CAAC,UAAU;IAUlB,OAAO,CAAC,kBAAkB;CAM3B;;;;AAID,wBAME"}
|
package/dist/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"legacyReadReceiptSyncEngineOnLoginHandler.d.ts","sourceRoot":"","sources":["../../../../src/client/utils/ReadReceiptSync/legacyReadReceiptSyncEngineOnLoginHandler.ts"],"names":[],"mappings":";AAGA,wBAiBE"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Internal used only
|
|
3
|
-
*
|
|
4
|
-
* Fired when an {@link Amity.channelUnreadInfo} has been updated.
|
|
5
|
-
*
|
|
6
|
-
* @param callback The function to call when the event was fired
|
|
7
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8
|
-
*
|
|
9
|
-
* @category ChannelMarker Events
|
|
10
|
-
*/
|
|
11
|
-
export declare const onChannelUnreadInfoUpdatedLocal: (callback: Amity.Listener<Amity.Events['local.channelUnreadInfo.updated']>) => Amity.Unsubscriber;
|
|
12
|
-
//# sourceMappingURL=onChannelUnreadInfoUpdatedLocal.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"onChannelUnreadInfoUpdatedLocal.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onChannelUnreadInfoUpdatedLocal.ts"],"names":[],"mappings":"AAGA;;;;;;;;;GASG;AACH,eAAO,MAAM,+BAA+B,aAChC,MAAM,QAAQ,CAAC,MAAM,MAAM,CAAC,iCAAiC,CAAC,CAAC,KACxE,MAAM,YAaR,CAAC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* Mark subChannel as read by readToSegment
|
|
6
|
-
*
|
|
7
|
-
* @param subChannelIds the IDs of the {@link Amity.SubChannel} to update
|
|
8
|
-
* @param readToSegment the segment to mark as read
|
|
9
|
-
* @returns a success boolean if the {@link Amity.SubChannel} was updated
|
|
10
|
-
*
|
|
11
|
-
* @category Channel API
|
|
12
|
-
* @async
|
|
13
|
-
*/
|
|
14
|
-
|
|
15
|
-
export const markChannelsAsReadBySegment = async (
|
|
16
|
-
readings: {
|
|
17
|
-
channelId: Amity.Channel['channelId'];
|
|
18
|
-
readToSegment: number;
|
|
19
|
-
}[],
|
|
20
|
-
): Promise<boolean> => {
|
|
21
|
-
const client = getActiveClient();
|
|
22
|
-
|
|
23
|
-
try {
|
|
24
|
-
await client.http.post<Amity.MarkAsReadPayload>('api/v3/channels/seen', { channels: readings });
|
|
25
|
-
return true;
|
|
26
|
-
} catch (e) {
|
|
27
|
-
return false;
|
|
28
|
-
}
|
|
29
|
-
};
|