@amityco/ts-sdk 6.7.3-cbeeb97.0 → 6.7.3-cc7ca05.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/domains/content.d.ts +1 -0
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/index.cjs.js +55 -38
- package/dist/index.esm.js +55 -38
- package/dist/index.umd.js +1 -1
- package/dist/marker/events/onMessageMarked.d.ts.map +1 -1
- package/dist/messageRepository/observers/getMessages.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/markReadEngine.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/content.ts +1 -0
- package/src/client/utils/markerSyncEngine.ts +12 -16
- package/src/marker/events/onMessageMarked.ts +18 -11
- package/src/messageRepository/observers/getMessages.ts +10 -6
- package/src/messageRepository/utils/prepareMessagePayload.ts +16 -1
- package/src/subChannelRepository/utils/markReadEngine.ts +13 -6
- package/src/utils/tests/dummy/message.ts +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"onMessageMarked.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onMessageMarked.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,aAChB,MAAM,QAAQ,CAAC,MAAM,aAAa,CAAC,KAC5C,MAAM,
|
|
1
|
+
{"version":3,"file":"onMessageMarked.d.ts","sourceRoot":"","sources":["../../../src/marker/events/onMessageMarked.ts"],"names":[],"mappings":"AAMA;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,eAAe,aAChB,MAAM,QAAQ,CAAC,MAAM,aAAa,CAAC,KAC5C,MAAM,YAiDR,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessages.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"getMessages.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/observers/getMessages.ts"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,WAAW,WACd,MAAM,sBAAsB,YAC1B,MAAM,sBAAsB,CAAC,MAAM,OAAO,CAAC,WAC5C,MAAM,oBAAoB,KAClC,MAAM,YAkHR,CAAC"}
|
|
@@ -9,7 +9,7 @@ declare type RawQueryMessages = Omit<Amity.QueryMessages, 'page' | 'sortBy' | 's
|
|
|
9
9
|
token: string;
|
|
10
10
|
};
|
|
11
11
|
};
|
|
12
|
-
export declare function convertParams({ subChannelId, mentionees, ...rest }: Partial<Amity.Message>): Record<string, any>;
|
|
12
|
+
export declare function convertParams({ subChannelId, mentionees, dataType, data, ...rest }: Partial<Amity.Message>): Record<string, any>;
|
|
13
13
|
export declare function convertQueryParams({ page, sortBy, subChannelId, tags, includeDeleted, ...rest }: Amity.QueryMessages): RawQueryMessages;
|
|
14
14
|
export {};
|
|
15
15
|
//# sourceMappingURL=prepareMessagePayload.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"prepareMessagePayload.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/prepareMessagePayload.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"prepareMessagePayload.d.ts","sourceRoot":"","sources":["../../../src/messageRepository/utils/prepareMessagePayload.ts"],"names":[],"mappings":"AAUA,wBAAgB,cAAc,CAC5B,OAAO,EAAE,KAAK,CAAC,UAAU,EACzB,QAAQ,CAAC,EAAE,KAAK,CAAC,OAAO,EAAE,EAC1B,KAAK,CAAC,EAAE,MAAM,KAAK,CAAC,iBAAiB,GACpC,KAAK,CAAC,OAAO,CAsEf;AAQD,eAAO,MAAM,qBAAqB,YACvB,MAAM,cAAc,UACrB,MAAM,MAAM,iBAAiB,KACpC,QAAQ,MAAM,uBAAuB,CAkBvC,CAAC;AAEF,aAAK,gBAAgB,GAAG,IAAI,CAC1B,KAAK,CAAC,aAAa,EAInB,MAAM,GAAG,QAAQ,GAAG,cAAc,GAAG,MAAM,GAAG,gBAAgB,CAC/D,GAAG;IACF,WAAW,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,MAAM,CAAC,CAAC;IAC1C,SAAS,CAAC,EAAE,KAAK,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;IACvC,aAAa,EAAE,KAAK,CAAC,aAAa,CAAC,cAAc,CAAC,CAAC;IACnD,OAAO,EAAE;QACP,MAAM,CAAC,EAAE,KAAK,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC;QACvC,KAAK,EAAE,MAAM,CAAC;KACf,CAAC;CACH,CAAC;AAEF,wBAAgB,aAAa,CAAC,EAC5B,YAAY,EACZ,UAAU,EACV,QAAQ,EACR,IAAI,EACJ,GAAG,IAAI,EACR,EAAE,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAc9C;AAED,wBAAgB,kBAAkB,CAAC,EACjC,IAAI,EACJ,MAAM,EACN,YAAY,EACZ,IAAI,EACJ,cAAc,EACd,GAAG,IAAI,EACR,EAAE,KAAK,CAAC,aAAa,GAAG,gBAAgB,CAiBxC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markReadEngine.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/markReadEngine.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"markReadEngine.d.ts","sourceRoot":"","sources":["../../../src/subChannelRepository/utils/markReadEngine.ts"],"names":[],"mappings":"AAgDA;;;;;GAKG;AACH,eAAO,MAAM,4BAA4B,kBAYxC,CAAC;AA0CF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,YAAY,iBAAwB,MAAM,UAAU,CAAC,cAAc,CAAC,qBAchF,CAAC;AAMF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,WAAW,iBAAkB,MAAM,UAAU,CAAC,cAAc,CAAC,qBAIzE,CAAC"}
|
package/package.json
CHANGED
|
@@ -18,7 +18,7 @@ import { onOnline } from './onOnline';
|
|
|
18
18
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
19
19
|
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
20
20
|
|
|
21
|
-
let
|
|
21
|
+
let isSyncRunning = false;
|
|
22
22
|
let disposers: (() => void)[] = [];
|
|
23
23
|
let isWaitingForResponse = false;
|
|
24
24
|
|
|
@@ -105,6 +105,9 @@ export const markerSyncTrigger = async () => {
|
|
|
105
105
|
};
|
|
106
106
|
|
|
107
107
|
const registerEventListeners = () => {
|
|
108
|
+
if (disposers.length > 0) {
|
|
109
|
+
return;
|
|
110
|
+
}
|
|
108
111
|
// based on the tech spec design, we designed a fetch marker in case of these events
|
|
109
112
|
// - new message
|
|
110
113
|
// - create channel
|
|
@@ -166,19 +169,7 @@ const unRegisterEventListeners = () => {
|
|
|
166
169
|
export const startUnreadSync = async () => {
|
|
167
170
|
await fetchDeviceLastSyncAt();
|
|
168
171
|
pushMarkerSyncEvent(Amity.MarkerSyncEvent.START_SYNCING);
|
|
169
|
-
|
|
170
|
-
if (!clearSyncTrigger) {
|
|
171
|
-
// it is possible to repeatedly call the API when multiple events occur at the same time.
|
|
172
|
-
// This is very burdensome to the BE Server, so we have an interval loop for
|
|
173
|
-
// grouping every event that occurs within 2 seconds into a single API call.
|
|
174
|
-
//
|
|
175
|
-
// interval loop is also useful for fetching large results. Because if the result
|
|
176
|
-
// is more than 20 records, the API will split the result into multiple pages
|
|
177
|
-
// and the SDK will need to fetch it repeatedly until all the results are available.
|
|
178
|
-
// So we need an interval loop for repeat fetch.
|
|
179
|
-
clearSyncTrigger = setIntervalTask(markerSyncTrigger, SYNC_TRIGGER_INTERVAL_TIME);
|
|
180
|
-
}
|
|
181
|
-
|
|
172
|
+
isSyncRunning = true;
|
|
182
173
|
registerEventListeners();
|
|
183
174
|
};
|
|
184
175
|
|
|
@@ -193,8 +184,7 @@ export const startUnreadSync = async () => {
|
|
|
193
184
|
* @category Marker API
|
|
194
185
|
*/
|
|
195
186
|
export const stopUnreadSync = () => {
|
|
196
|
-
|
|
197
|
-
clearSyncTrigger = undefined;
|
|
187
|
+
isSyncRunning = false;
|
|
198
188
|
setMarkerSyncEvents([]);
|
|
199
189
|
unRegisterEventListeners();
|
|
200
190
|
};
|
|
@@ -207,3 +197,9 @@ export const stopUnreadSyncing = () => {
|
|
|
207
197
|
|
|
208
198
|
return stopUnreadSync();
|
|
209
199
|
};
|
|
200
|
+
|
|
201
|
+
setIntervalTask(async () => {
|
|
202
|
+
if (!isSyncRunning) return;
|
|
203
|
+
|
|
204
|
+
await markerSyncTrigger();
|
|
205
|
+
}, SYNC_TRIGGER_INTERVAL_TIME);
|
|
@@ -29,25 +29,32 @@ export const onMessageMarked = (
|
|
|
29
29
|
|
|
30
30
|
const cacheCollection = queryCache<Amity.MessageLiveCollectionCache>(['message', 'collection']);
|
|
31
31
|
|
|
32
|
-
if (cacheCollection) {
|
|
32
|
+
if (cacheCollection && cacheCollection?.length > 0) {
|
|
33
|
+
const contentMarker = payload.contentMarkers[0];
|
|
33
34
|
const currentMessageCollection = cacheCollection.filter(currentMessage => {
|
|
34
35
|
if (!isObject(currentMessage.key[2])) return false;
|
|
35
|
-
return currentMessage.key[2].subChannelId ===
|
|
36
|
+
return currentMessage.key[2].subChannelId === contentMarker.feedId;
|
|
36
37
|
});
|
|
37
38
|
|
|
38
|
-
if (currentMessageCollection) {
|
|
39
|
-
const currentMessages =
|
|
40
|
-
|
|
41
|
-
|
|
39
|
+
if (currentMessageCollection.length > 0) {
|
|
40
|
+
const currentMessages =
|
|
41
|
+
currentMessageCollection[0].data?.data?.map(messageId => {
|
|
42
|
+
return pullFromCache<Amity.Message>(['message', 'get', messageId]);
|
|
43
|
+
}) || [];
|
|
42
44
|
|
|
43
45
|
currentMessages.forEach(message => {
|
|
44
|
-
const isSameSubChannelId =
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
46
|
+
const isSameSubChannelId = contentMarker.feedId === message?.data.subChannelId;
|
|
47
|
+
const isReadCountLatest = contentMarker.readCount > message?.data.readCount!;
|
|
48
|
+
const isDeliveredCountLatest =
|
|
49
|
+
contentMarker.deliveredCount > message?.data.deliveredCount!;
|
|
50
|
+
|
|
51
|
+
if (isSameSubChannelId) {
|
|
48
52
|
pushToCache(['message', 'get', message.data.messageId], {
|
|
49
53
|
...message.data,
|
|
50
|
-
readCount:
|
|
54
|
+
readCount: isReadCountLatest ? contentMarker.readCount : message?.data.readCount!,
|
|
55
|
+
deliveredCount: isDeliveredCountLatest
|
|
56
|
+
? contentMarker.deliveredCount
|
|
57
|
+
: message?.data.deliveredCount!,
|
|
51
58
|
});
|
|
52
59
|
}
|
|
53
60
|
});
|
|
@@ -4,6 +4,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
4
4
|
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
5
5
|
import { createQuery, filterByPropEquality, queryOptions, runQuery } from '~/core/query';
|
|
6
6
|
import { onMessageMarked, onMessageMarkerFetched } from '~/marker/events';
|
|
7
|
+
import { uuid } from '~/core/uuid';
|
|
7
8
|
|
|
8
9
|
import {
|
|
9
10
|
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
@@ -68,13 +69,20 @@ export const getMessages = (
|
|
|
68
69
|
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
69
70
|
|
|
70
71
|
const disposers: Amity.Unsubscriber[] = [];
|
|
71
|
-
const cacheKey = ['message', 'collection', params];
|
|
72
|
+
const cacheKey = ['message', 'collection', params, uuid()];
|
|
72
73
|
|
|
73
74
|
const responder = (data: Amity.MessageLiveCollectionCache) => {
|
|
74
75
|
let messages: Amity.Message[] =
|
|
75
76
|
data.data
|
|
76
77
|
.map(messageId => pullFromCache<Amity.Message>(['message', 'get', messageId])!)
|
|
77
78
|
.filter(Boolean)
|
|
79
|
+
.filter(item => {
|
|
80
|
+
if (!params.tags) return true;
|
|
81
|
+
return params.tags.find(value => {
|
|
82
|
+
if (!item.data?.tags) return false;
|
|
83
|
+
return item.data.tags.includes(value);
|
|
84
|
+
});
|
|
85
|
+
})
|
|
78
86
|
.map(({ data }) => data) ?? [];
|
|
79
87
|
|
|
80
88
|
/*
|
|
@@ -94,15 +102,11 @@ export const getMessages = (
|
|
|
94
102
|
});
|
|
95
103
|
};
|
|
96
104
|
|
|
97
|
-
const realtimeRouter = (
|
|
105
|
+
const realtimeRouter = (action: Amity.MessageActionType) => (message: Amity.Message) => {
|
|
98
106
|
const collection = pullFromCache<Amity.MessageLiveCollectionCache>(cacheKey)?.data;
|
|
99
107
|
|
|
100
108
|
if (params.subChannelId !== message?.subChannelId || !collection) return;
|
|
101
109
|
|
|
102
|
-
if (!collection.data.includes(message.messageId)) {
|
|
103
|
-
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
104
|
-
}
|
|
105
|
-
|
|
106
110
|
pushToCache(cacheKey, collection);
|
|
107
111
|
|
|
108
112
|
responder(collection);
|
|
@@ -6,6 +6,7 @@ import { prepareMessagePayloadForCache } from '~/reactionRepository/utils/prepar
|
|
|
6
6
|
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
7
7
|
|
|
8
8
|
import { getMessageReadCount } from './getMessageReadCount';
|
|
9
|
+
import { MessageContentType } from '~/@types';
|
|
9
10
|
|
|
10
11
|
export function convertFromRaw(
|
|
11
12
|
message: Amity.RawMessage,
|
|
@@ -131,9 +132,23 @@ type RawQueryMessages = Omit<
|
|
|
131
132
|
export function convertParams({
|
|
132
133
|
subChannelId,
|
|
133
134
|
mentionees,
|
|
135
|
+
dataType,
|
|
136
|
+
data,
|
|
134
137
|
...rest
|
|
135
138
|
}: Partial<Amity.Message>): Record<string, any> {
|
|
136
|
-
|
|
139
|
+
if (dataType === MessageContentType.IMAGE || dataType === MessageContentType.FILE) {
|
|
140
|
+
return {
|
|
141
|
+
messageFeedId: subChannelId,
|
|
142
|
+
mentionedUsers: mentionees,
|
|
143
|
+
dataType,
|
|
144
|
+
data: {
|
|
145
|
+
caption: '',
|
|
146
|
+
...(data as Record<string, any>),
|
|
147
|
+
},
|
|
148
|
+
...rest,
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
return { messageFeedId: subChannelId, mentionedUsers: mentionees, dataType, data, ...rest };
|
|
137
152
|
}
|
|
138
153
|
|
|
139
154
|
export function convertQueryParams({
|
|
@@ -10,7 +10,7 @@ import { stopReadingAPI } from '../api/stopReadingAPI';
|
|
|
10
10
|
|
|
11
11
|
const START_READING_INTERVAL_TIME = 30000;
|
|
12
12
|
|
|
13
|
-
let
|
|
13
|
+
let isSyncRunning = false;
|
|
14
14
|
let disposers: (() => void)[] = [];
|
|
15
15
|
|
|
16
16
|
/**
|
|
@@ -39,14 +39,11 @@ const startReadingFromReadingList = async () => {
|
|
|
39
39
|
};
|
|
40
40
|
|
|
41
41
|
const startIntervalTask = () => {
|
|
42
|
-
|
|
43
|
-
clearIntervalTask = setIntervalTask(startReadingFromReadingList, START_READING_INTERVAL_TIME);
|
|
44
|
-
}
|
|
42
|
+
isSyncRunning = true;
|
|
45
43
|
};
|
|
46
44
|
|
|
47
45
|
const stopIntervalTask = () => {
|
|
48
|
-
|
|
49
|
-
clearIntervalTask = null;
|
|
46
|
+
isSyncRunning = false;
|
|
50
47
|
};
|
|
51
48
|
|
|
52
49
|
/**
|
|
@@ -83,6 +80,10 @@ const getParentChannelId = async (
|
|
|
83
80
|
};
|
|
84
81
|
|
|
85
82
|
const registerEventListeners = () => {
|
|
83
|
+
if (disposers.length > 0) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
|
|
86
87
|
disposers.push(
|
|
87
88
|
onOnline(() => {
|
|
88
89
|
// Start reading the reading subChannel again when resume from offline state
|
|
@@ -161,3 +162,9 @@ export const stopReading = (subChannelId: Amity.SubChannel['subChannelId']) => {
|
|
|
161
162
|
return stopReadingAPI(subChannelId);
|
|
162
163
|
};
|
|
163
164
|
/* end_public_function */
|
|
165
|
+
|
|
166
|
+
setIntervalTask(async () => {
|
|
167
|
+
if (!isSyncRunning) return;
|
|
168
|
+
|
|
169
|
+
await startReadingFromReadingList();
|
|
170
|
+
}, START_READING_INTERVAL_TIME);
|
|
@@ -9,7 +9,7 @@ export function generateRawMessage(params?: Partial<Amity.RawMessage>): Amity.Ra
|
|
|
9
9
|
createdAt: new Date().toISOString(),
|
|
10
10
|
creatorId: 'user-id',
|
|
11
11
|
creatorPublicId: 'user-public-id',
|
|
12
|
-
data: { text: 'message text' },
|
|
12
|
+
data: { text: 'message text', caption: '' },
|
|
13
13
|
dataType: 'text',
|
|
14
14
|
editedAt: new Date().toISOString(),
|
|
15
15
|
flagCount: 0,
|