@amityco/ts-sdk 6.34.0 → 6.34.1-7808d99.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/.env +26 -26
- package/dist/@types/domains/client.d.ts +2 -2
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +2 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/isConnected.d.ts.map +1 -1
- package/dist/client/api/logout.d.ts.map +1 -1
- package/dist/client/utils/modifyMqttConnection.d.ts.map +1 -1
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/index.cjs.js +128 -17
- package/dist/index.esm.js +128 -17
- package/dist/index.umd.js +2 -2
- package/dist/storyRepository/api/createImageStory.d.ts.map +1 -1
- package/dist/storyRepository/api/createVideoStory.d.ts.map +1 -1
- package/dist/storyRepository/internalApi/deleteStory.d.ts.map +1 -1
- package/dist/storyRepository/observers/getActiveStoriesByTarget.d.ts.map +1 -1
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts.map +1 -1
- package/dist/storyRepository/utils/createOptimisticTarget.d.ts +5 -0
- package/dist/storyRepository/utils/createOptimisticTarget.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/domains/client.ts +2 -2
- package/src/client/api/createClient.ts +10 -2
- package/src/client/api/isConnected.ts +4 -1
- package/src/client/api/login.ts +1 -1
- package/src/client/api/logout.ts +6 -5
- package/src/client/utils/modifyMqttConnection.ts +2 -0
- package/src/client/utils/setClientToken.ts +1 -1
- package/src/core/events.ts +2 -2
- package/src/core/subscription.ts +2 -0
- package/src/core/transports/ws.ts +1 -1
- package/src/storyRepository/api/createImageStory.ts +3 -0
- package/src/storyRepository/api/createVideoStory.ts +3 -0
- package/src/storyRepository/internalApi/deleteStory.ts +74 -0
- package/src/storyRepository/observers/getActiveStoriesByTarget.ts +16 -1
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +14 -2
- package/src/storyRepository/utils/StoryComputedValue.ts +2 -2
- package/src/storyRepository/utils/createOptimisticTarget.ts +46 -0
package/dist/index.esm.js
CHANGED
|
@@ -1334,14 +1334,14 @@ const createEventEmitter = () => {
|
|
|
1334
1334
|
*/
|
|
1335
1335
|
const proxyWebsocketEvents = (ws, emitter) => {
|
|
1336
1336
|
WS_EVENTS.forEach(event => {
|
|
1337
|
-
ws.on(event, (param) => {
|
|
1337
|
+
ws === null || ws === void 0 ? void 0 : ws.on(event, (param) => {
|
|
1338
1338
|
emitter.emit(event, param);
|
|
1339
1339
|
});
|
|
1340
1340
|
});
|
|
1341
1341
|
};
|
|
1342
1342
|
const proxyMqttEvents = (mqttClient, emitter) => {
|
|
1343
1343
|
MQTT_EVENTS.forEach(event => {
|
|
1344
|
-
mqttClient.on(event, (...params) => {
|
|
1344
|
+
mqttClient === null || mqttClient === void 0 ? void 0 : mqttClient.on(event, (...params) => {
|
|
1345
1345
|
emitter.emit(event, params.length === 1 ? params[0] : params);
|
|
1346
1346
|
});
|
|
1347
1347
|
});
|
|
@@ -1399,6 +1399,8 @@ let mqttUserId;
|
|
|
1399
1399
|
async function modifyMqttConnection() {
|
|
1400
1400
|
var _a;
|
|
1401
1401
|
const { mqtt, emitter, token } = getActiveClient();
|
|
1402
|
+
if (!mqtt)
|
|
1403
|
+
return;
|
|
1402
1404
|
const accessToken = (_a = token === null || token === void 0 ? void 0 : token.accessToken) !== null && _a !== void 0 ? _a : '';
|
|
1403
1405
|
const user = getActiveUser();
|
|
1404
1406
|
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
@@ -1509,6 +1511,8 @@ const getSmartFeedMessageTopic = () => {
|
|
|
1509
1511
|
};
|
|
1510
1512
|
function subscribeTopic(topic, callback) {
|
|
1511
1513
|
const { mqtt } = getActiveClient();
|
|
1514
|
+
if (!mqtt)
|
|
1515
|
+
return () => null;
|
|
1512
1516
|
modifyMqttConnection();
|
|
1513
1517
|
return mqtt.subscribe(topic, callback);
|
|
1514
1518
|
}
|
|
@@ -21331,8 +21335,8 @@ class StoryComputedValue {
|
|
|
21331
21335
|
return;
|
|
21332
21336
|
}
|
|
21333
21337
|
const groupByType = stories.reduce((acc, story) => {
|
|
21334
|
-
const { data: { targetId, syncState }, } = story;
|
|
21335
|
-
if (targetId === this._targetId) {
|
|
21338
|
+
const { data: { targetId, syncState, isDeleted }, } = story;
|
|
21339
|
+
if (targetId === this._targetId && !isDeleted) {
|
|
21336
21340
|
acc[syncState] += 1;
|
|
21337
21341
|
}
|
|
21338
21342
|
return acc;
|
|
@@ -23855,7 +23859,8 @@ const setClientToken = async (params) => {
|
|
|
23855
23859
|
isUserDeleted: false,
|
|
23856
23860
|
};
|
|
23857
23861
|
// manually setup the token for ws transport
|
|
23858
|
-
client.ws
|
|
23862
|
+
if (client.ws)
|
|
23863
|
+
client.ws.io.opts.query = { token: accessToken };
|
|
23859
23864
|
client.token = { accessToken, issuedAt, expiresAt };
|
|
23860
23865
|
setSessionState("established" /* Amity.SessionStates.ESTABLISHED */);
|
|
23861
23866
|
return { accessToken, users };
|
|
@@ -24188,12 +24193,13 @@ var objectResolverEngineOnLoginHandler = () => {
|
|
|
24188
24193
|
* @async
|
|
24189
24194
|
*/
|
|
24190
24195
|
const logout = async () => {
|
|
24196
|
+
var _a, _b;
|
|
24191
24197
|
const client = getActiveClient();
|
|
24192
24198
|
client.log('client/api/disconnectClient');
|
|
24193
|
-
if (client.mqtt.connected) {
|
|
24199
|
+
if (client.mqtt && client.mqtt.connected) {
|
|
24194
24200
|
client.mqtt.disconnect();
|
|
24195
24201
|
}
|
|
24196
|
-
if (client.ws.connected) {
|
|
24202
|
+
if (client.ws && client.ws.connected) {
|
|
24197
24203
|
client.ws.disconnect();
|
|
24198
24204
|
}
|
|
24199
24205
|
/*
|
|
@@ -24212,8 +24218,8 @@ const logout = async () => {
|
|
|
24212
24218
|
setSessionState("notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */);
|
|
24213
24219
|
client.emitter.all.clear();
|
|
24214
24220
|
// FIXME: it removes listener in ws.ts, it breaks global ban event
|
|
24215
|
-
client.ws.removeAllListeners();
|
|
24216
|
-
client.mqtt.removeAllListeners();
|
|
24221
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.removeAllListeners();
|
|
24222
|
+
(_b = client.mqtt) === null || _b === void 0 ? void 0 : _b.removeAllListeners();
|
|
24217
24223
|
client.userId = undefined;
|
|
24218
24224
|
client.token = undefined;
|
|
24219
24225
|
client.http.defaults.headers.common.Authorization = '';
|
|
@@ -24222,7 +24228,8 @@ const logout = async () => {
|
|
|
24222
24228
|
isGlobalBanned: false,
|
|
24223
24229
|
isUserDeleted: false,
|
|
24224
24230
|
};
|
|
24225
|
-
client.ws
|
|
24231
|
+
if (client.ws)
|
|
24232
|
+
client.ws.io.opts.query = { token: '' };
|
|
24226
24233
|
if (typeof document !== 'undefined') {
|
|
24227
24234
|
document.cookie = '_ascSession=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;';
|
|
24228
24235
|
}
|
|
@@ -25205,6 +25212,7 @@ async function runMqtt() {
|
|
|
25205
25212
|
* @async
|
|
25206
25213
|
*/
|
|
25207
25214
|
const login = async (params, sessionHandler, config) => {
|
|
25215
|
+
var _a;
|
|
25208
25216
|
const client = getActiveClient();
|
|
25209
25217
|
let unsubWatcher;
|
|
25210
25218
|
client.log('client/api/connectClient', Object.assign({ apiKey: client.apiKey, sessionState: client.sessionState }, params));
|
|
@@ -25239,7 +25247,7 @@ const login = async (params, sessionHandler, config) => {
|
|
|
25239
25247
|
// FIXME: events are duplicated if connectClient is called few times without disconnectClient
|
|
25240
25248
|
// wire websocket events to our event emitter
|
|
25241
25249
|
proxyWebsocketEvents(client.ws, client.emitter);
|
|
25242
|
-
client.ws.open();
|
|
25250
|
+
(_a = client.ws) === null || _a === void 0 ? void 0 : _a.open();
|
|
25243
25251
|
client.userId = user.userId;
|
|
25244
25252
|
client.sessionHandler = sessionHandler;
|
|
25245
25253
|
/*
|
|
@@ -25444,7 +25452,7 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
25444
25452
|
*
|
|
25445
25453
|
* @category Client API
|
|
25446
25454
|
* */
|
|
25447
|
-
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, } = {}) => {
|
|
25455
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
25448
25456
|
var _a, _b;
|
|
25449
25457
|
const log = createLogger(debugSession);
|
|
25450
25458
|
log('client/api/createClient', {
|
|
@@ -25454,8 +25462,12 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25454
25462
|
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
25455
25463
|
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
25456
25464
|
const http = createHttpTransport(httpEndpoint);
|
|
25457
|
-
|
|
25458
|
-
|
|
25465
|
+
let ws;
|
|
25466
|
+
let mqtt;
|
|
25467
|
+
if (rteEnabled) {
|
|
25468
|
+
ws = createWebsocketTransport(httpEndpoint);
|
|
25469
|
+
mqtt = createMqttTransport(mqttEndpoint);
|
|
25470
|
+
}
|
|
25459
25471
|
const emitter = createEventEmitter();
|
|
25460
25472
|
/*
|
|
25461
25473
|
* Since v6 cache is enabled by default
|
|
@@ -25579,9 +25591,11 @@ const isConnected = () => {
|
|
|
25579
25591
|
var _a, _b;
|
|
25580
25592
|
const client = getActiveClient();
|
|
25581
25593
|
client.log('client/api/isConnected', client);
|
|
25594
|
+
// if client is connected to ws, it means client is connected. If ws is undefined, it means ws is not used.
|
|
25595
|
+
const isWsConnected = (client.ws && client.ws.connected) || !!client.ws;
|
|
25582
25596
|
return !!(client.userId &&
|
|
25583
25597
|
((_b = String((_a = client.http.defaults.headers.common) === null || _a === void 0 ? void 0 : _a.Authorization)) === null || _b === void 0 ? void 0 : _b.length) &&
|
|
25584
|
-
|
|
25598
|
+
isWsConnected);
|
|
25585
25599
|
};
|
|
25586
25600
|
|
|
25587
25601
|
var _GlobalFileAccessType_fileAccessType;
|
|
@@ -41419,7 +41433,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
41419
41433
|
getPoll: getPoll
|
|
41420
41434
|
});
|
|
41421
41435
|
|
|
41422
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
41436
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
41423
41437
|
/*
|
|
41424
41438
|
* The crypto algorithm used for importing key and signing string
|
|
41425
41439
|
*/
|
|
@@ -41856,6 +41870,30 @@ const createStory = async (payload) => {
|
|
|
41856
41870
|
};
|
|
41857
41871
|
};
|
|
41858
41872
|
|
|
41873
|
+
const createOptimisticTarget = async ({ targetId, targetType, }) => {
|
|
41874
|
+
var _a, _b;
|
|
41875
|
+
const targetCache = pullFromCache([
|
|
41876
|
+
"storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */,
|
|
41877
|
+
'get',
|
|
41878
|
+
targetId,
|
|
41879
|
+
]);
|
|
41880
|
+
if (!targetCache) {
|
|
41881
|
+
let optimisticTarget = {
|
|
41882
|
+
targetId,
|
|
41883
|
+
targetType,
|
|
41884
|
+
};
|
|
41885
|
+
if (targetType === 'community') {
|
|
41886
|
+
const community = await getCommunity$1(targetId);
|
|
41887
|
+
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: community.data.communityId, targetUpdatedAt: (_a = community.data.updatedAt) !== null && _a !== void 0 ? _a : new Date().toISOString() });
|
|
41888
|
+
}
|
|
41889
|
+
if (targetType === 'user') {
|
|
41890
|
+
const user = await getUser$2(targetId);
|
|
41891
|
+
optimisticTarget = Object.assign(Object.assign({}, optimisticTarget), { targetPublicId: user.data.userPublicId, targetUpdatedAt: (_b = user.data.updatedAt) !== null && _b !== void 0 ? _b : new Date().toISOString() });
|
|
41892
|
+
}
|
|
41893
|
+
pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId], optimisticTarget);
|
|
41894
|
+
}
|
|
41895
|
+
};
|
|
41896
|
+
|
|
41859
41897
|
/**
|
|
41860
41898
|
* ```js
|
|
41861
41899
|
* import { StoryRepository } from '@amityco/ts-sdk'
|
|
@@ -41905,6 +41943,7 @@ const createImageStory = async (targetType, targetId, formData, metadata = {}, i
|
|
|
41905
41943
|
throw new Error('Failed to upload image');
|
|
41906
41944
|
const { fileId } = data[0];
|
|
41907
41945
|
payload = Object.assign(Object.assign({}, payload), { data: Object.assign(Object.assign({}, payload.data), { fileId }) });
|
|
41946
|
+
createOptimisticTarget({ targetId, targetType });
|
|
41908
41947
|
// Fire optimistic event - update fileId
|
|
41909
41948
|
createOptimisticEvent({ payload, formData }, optimisticData => {
|
|
41910
41949
|
fireEvent('local.story.created', optimisticData);
|
|
@@ -41958,6 +41997,7 @@ const createVideoStory = async (targetType, targetId, formData, metadata = {}, i
|
|
|
41958
41997
|
pushToCache(["story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */, targetId], "syncing" /* Amity.SyncState.Syncing */);
|
|
41959
41998
|
// Update local story expires time
|
|
41960
41999
|
pushToCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, targetId], new Date(date.setFullYear(date.getFullYear() + 1)));
|
|
42000
|
+
createOptimisticTarget({ targetId, targetType });
|
|
41961
42001
|
// Fire optimistic event
|
|
41962
42002
|
createOptimisticEvent({ payload, formData, isVideo: true }, optimisticData => {
|
|
41963
42003
|
fireEvent('local.story.created', optimisticData);
|
|
@@ -41995,6 +42035,7 @@ const getStoryCache = (storyId) => {
|
|
|
41995
42035
|
};
|
|
41996
42036
|
|
|
41997
42037
|
const deleteStory = async (storyId, permanent = false) => {
|
|
42038
|
+
var _a, _b, _c;
|
|
41998
42039
|
const client = getActiveClient();
|
|
41999
42040
|
client.log('story/deleteStory', storyId);
|
|
42000
42041
|
let cached;
|
|
@@ -42011,6 +42052,57 @@ const deleteStory = async (storyId, permanent = false) => {
|
|
|
42011
42052
|
users: [],
|
|
42012
42053
|
stories: [Object.assign(Object.assign({}, data), { isDeleted: true })],
|
|
42013
42054
|
});
|
|
42055
|
+
/* ------ Unsynced story case ------ */
|
|
42056
|
+
if (data.syncState !== "synced" /* Amity.SyncState.Synced */) {
|
|
42057
|
+
if (permanent) {
|
|
42058
|
+
dropFromCache(["story" /* STORY_KEY_CACHE.STORY */, 'get', storyId]);
|
|
42059
|
+
}
|
|
42060
|
+
else {
|
|
42061
|
+
pushToCache(["story" /* STORY_KEY_CACHE.STORY */, 'get', storyId], Object.assign(Object.assign({}, cached.data), { isDeleted: true }));
|
|
42062
|
+
}
|
|
42063
|
+
const unsyncedStoriesCache = (_a = queryCache([
|
|
42064
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
42065
|
+
'get',
|
|
42066
|
+
])) === null || _a === void 0 ? void 0 : _a.filter(story => story.data.syncState !== "synced" /* Amity.SyncState.Synced */ &&
|
|
42067
|
+
story.data.targetId === data.targetId &&
|
|
42068
|
+
story.data.isDeleted !== true);
|
|
42069
|
+
// update localLastStoryExpiresAt to be the last story expires
|
|
42070
|
+
if (unsyncedStoriesCache && unsyncedStoriesCache.length > 0) {
|
|
42071
|
+
const lastStoryExpires = unsyncedStoriesCache.reduce((acc, story) => {
|
|
42072
|
+
const expireAt = new Date(story.data.expiresAt || 0);
|
|
42073
|
+
return expireAt > acc ? expireAt : acc;
|
|
42074
|
+
}, new Date(0));
|
|
42075
|
+
pushToCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, cached.data.targetId], lastStoryExpires.toISOString());
|
|
42076
|
+
}
|
|
42077
|
+
else {
|
|
42078
|
+
// if no unsynced stories, remove last story expires since there is no more story
|
|
42079
|
+
dropFromCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, cached.data.targetId]);
|
|
42080
|
+
}
|
|
42081
|
+
return true;
|
|
42082
|
+
}
|
|
42083
|
+
/* ------ Synced story case ------ */
|
|
42084
|
+
const targetCache = (_b = pullFromCache([
|
|
42085
|
+
"storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */,
|
|
42086
|
+
'get',
|
|
42087
|
+
data.targetId,
|
|
42088
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
42089
|
+
const syncedStoriesCache = (_c = queryCache([
|
|
42090
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
42091
|
+
'get',
|
|
42092
|
+
])) === null || _c === void 0 ? void 0 : _c.filter(story => story.data.syncState === "synced" /* Amity.SyncState.Synced */ &&
|
|
42093
|
+
story.data.targetId === data.targetId &&
|
|
42094
|
+
story.data.isDeleted !== true);
|
|
42095
|
+
let lastStoryExpiresAt;
|
|
42096
|
+
if (syncedStoriesCache && syncedStoriesCache.length > 0) {
|
|
42097
|
+
lastStoryExpiresAt = syncedStoriesCache === null || syncedStoriesCache === void 0 ? void 0 : syncedStoriesCache.reduce((acc, story) => {
|
|
42098
|
+
const expireAt = new Date(story.data.expiresAt || 0);
|
|
42099
|
+
return expireAt > acc ? expireAt : acc;
|
|
42100
|
+
}, new Date(0));
|
|
42101
|
+
}
|
|
42102
|
+
// update lastStoryExpiresAt from lastest synced story
|
|
42103
|
+
if (targetCache) {
|
|
42104
|
+
pushToCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', data.targetId], Object.assign(Object.assign({}, targetCache), { lastStoryExpiresAt }));
|
|
42105
|
+
}
|
|
42014
42106
|
}
|
|
42015
42107
|
}
|
|
42016
42108
|
const response = await client.http.delete(`/api/v4/stories/${storyId}`, {
|
|
@@ -42323,6 +42415,7 @@ const getActiveStoriesByTarget = (params, callback) => {
|
|
|
42323
42415
|
});
|
|
42324
42416
|
};
|
|
42325
42417
|
const processNewData = (result, event, initial = false, loading = false, error = false) => {
|
|
42418
|
+
var _a;
|
|
42326
42419
|
const cached = pullFromCache(cacheKey);
|
|
42327
42420
|
const data = {
|
|
42328
42421
|
loading,
|
|
@@ -42341,6 +42434,14 @@ const getActiveStoriesByTarget = (params, callback) => {
|
|
|
42341
42434
|
: [...new Set([...data.data, ...result.map(getResolver('story'))])];
|
|
42342
42435
|
}
|
|
42343
42436
|
}
|
|
42437
|
+
const unSyncedStories = (_a = queryCache(["story" /* STORY_KEY_CACHE.STORY */, 'get'])) === null || _a === void 0 ? void 0 : _a.filter(story => story.data.targetId === params.targetId &&
|
|
42438
|
+
story.data.syncState !== "synced" /* Amity.SyncState.Synced */).map(story => getResolver('story')(story.data));
|
|
42439
|
+
if (unSyncedStories && (unSyncedStories === null || unSyncedStories === void 0 ? void 0 : unSyncedStories.length) > 0) {
|
|
42440
|
+
unSyncedStories.forEach(referenceId => {
|
|
42441
|
+
if (!data.data.includes(referenceId))
|
|
42442
|
+
data.data.push(referenceId);
|
|
42443
|
+
});
|
|
42444
|
+
}
|
|
42344
42445
|
pushToCache(cacheKey, data.data);
|
|
42345
42446
|
responder(data);
|
|
42346
42447
|
};
|
|
@@ -42772,13 +42873,23 @@ class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
|
42772
42873
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
42773
42874
|
if (!collection)
|
|
42774
42875
|
return;
|
|
42775
|
-
|
|
42876
|
+
const targetIds = collection.data;
|
|
42877
|
+
const cachedTargets = queryCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */]);
|
|
42878
|
+
if (cachedTargets && (cachedTargets === null || cachedTargets === void 0 ? void 0 : cachedTargets.length) > 0) {
|
|
42879
|
+
cachedTargets === null || cachedTargets === void 0 ? void 0 : cachedTargets.forEach(({ key }) => {
|
|
42880
|
+
if (!collection.data.includes(key[2]))
|
|
42881
|
+
targetIds.push(key[2]);
|
|
42882
|
+
});
|
|
42883
|
+
}
|
|
42884
|
+
let data = targetIds
|
|
42776
42885
|
.map(targetId => pullFromCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId]))
|
|
42777
42886
|
.filter(Boolean)
|
|
42778
42887
|
.map(storyTarget => LinkedObject.storyTarget(storyTarget.data));
|
|
42779
42888
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
42780
42889
|
return;
|
|
42781
42890
|
data = this.applyFilter(data)
|
|
42891
|
+
// exclude story targets with invalid stories
|
|
42892
|
+
.filter(({ localSortingDate }) => !!localSortingDate)
|
|
42782
42893
|
// Remove internal fields
|
|
42783
42894
|
.map((_a) => {
|
|
42784
42895
|
var rest = __rest(_a, ["localFilter", "localLastExpires", "localLastSeen", "localSortingDate"]);
|