@amityco/ts-sdk 6.17.3-beac0a2.0 → 6.17.3-e382dbe.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/payload.d.ts +2 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +2 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/story.d.ts +18 -1
- package/dist/@types/domains/story.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/validateTexts.d.ts +8 -0
- package/dist/client/api/validateTexts.d.ts.map +1 -0
- package/dist/client/api/validateUrls.d.ts +8 -0
- package/dist/client/api/validateUrls.d.ts.map +1 -0
- package/dist/core/query/sorting.d.ts +6 -0
- package/dist/core/query/sorting.d.ts.map +1 -1
- package/dist/index.cjs.js +385 -39
- package/dist/index.esm.js +385 -40
- package/dist/index.umd.js +4 -4
- package/dist/storyRepository/api/createImageStory.d.ts.map +1 -1
- package/dist/storyRepository/api/createVideoStory.d.ts.map +1 -1
- package/dist/storyRepository/constants.d.ts +2 -0
- package/dist/storyRepository/constants.d.ts.map +1 -1
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts +14 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryPageController.d.ts +13 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryPageController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts +16 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/getGlobalStoryTargets.d.ts +2 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/getGlobalStoryTargets.d.ts.map +1 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/index.d.ts +2 -0
- package/dist/storyRepository/observers/getGlobalStoryTargets/index.d.ts.map +1 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryPaginationNoPageController.d.ts.map +1 -1
- package/dist/storyRepository/observers/index.d.ts +1 -0
- package/dist/storyRepository/observers/index.d.ts.map +1 -1
- package/dist/storyRepository/utils/StoryComputedValue.d.ts +23 -0
- package/dist/storyRepository/utils/StoryComputedValue.d.ts.map +1 -0
- package/dist/utils/linkedObject/storyLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/storyTargetLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +4 -0
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/story.ts +22 -2
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +24 -1
- package/src/channelRepository/observers/getChannels/ChannelQueryStreamController.ts +4 -1
- package/src/client/api/createClient.ts +4 -0
- package/src/client/api/validateTexts.ts +23 -0
- package/src/client/api/validateUrls.ts +23 -0
- package/src/core/query/sorting.ts +8 -0
- package/src/storyRepository/api/createImageStory.ts +7 -0
- package/src/storyRepository/api/createVideoStory.ts +7 -0
- package/src/storyRepository/constants.ts +2 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryLiveCollectionController.ts +153 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryPageController.ts +73 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.ts +94 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/getGlobalStoryTargets.ts +32 -0
- package/src/storyRepository/observers/getGlobalStoryTargets/index.ts +1 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryPaginationNoPageController.ts +0 -2
- package/src/storyRepository/observers/index.ts +1 -0
- package/src/storyRepository/utils/StoryComputedValue.ts +144 -0
- package/src/utils/linkedObject/storyLinkedObject.ts +2 -1
- package/src/utils/linkedObject/storyTargetLinkedObject.ts +27 -4
- package/dist/storyRepository/utils/calculateHasUnseenFlag.d.ts +0 -6
- package/dist/storyRepository/utils/calculateHasUnseenFlag.d.ts.map +0 -1
- package/src/storyRepository/utils/calculateHasUnseenFlag.ts +0 -47
package/dist/index.cjs.js
CHANGED
|
@@ -1233,6 +1233,10 @@ const sortBySegmentNumber = ({ segmentNumber: a }, { segmentNumber: b }) => a -
|
|
|
1233
1233
|
* Sorting a collection by its oldest items
|
|
1234
1234
|
*/
|
|
1235
1235
|
const sortByFirstCreated = ({ createdAt: a }, { createdAt: b }) => new Date(a).valueOf() - new Date(b).valueOf();
|
|
1236
|
+
/**
|
|
1237
|
+
* Sorting a story-collection by its localSortingDate
|
|
1238
|
+
*/
|
|
1239
|
+
const sortByLocalSortingDate = ({ localSortingDate: a }, { localSortingDate: b }) => new Date(b).getTime() - new Date(a).getTime();
|
|
1236
1240
|
/**
|
|
1237
1241
|
* Sorting a collection by its newest items
|
|
1238
1242
|
*/
|
|
@@ -5021,55 +5025,125 @@ const userLinkedObject = (user) => {
|
|
|
5021
5025
|
} });
|
|
5022
5026
|
};
|
|
5023
5027
|
|
|
5024
|
-
|
|
5025
|
-
|
|
5026
|
-
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
|
|
5037
|
-
|
|
5038
|
-
|
|
5039
|
-
|
|
5040
|
-
|
|
5041
|
-
|
|
5042
|
-
|
|
5043
|
-
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5028
|
+
class StoryComputedValue {
|
|
5029
|
+
constructor(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt) {
|
|
5030
|
+
this._syncingStoriesCount = 0;
|
|
5031
|
+
this._syncedStoriesCount = 0;
|
|
5032
|
+
this._errorStoriesCount = 0;
|
|
5033
|
+
this._targetId = targetId;
|
|
5034
|
+
this._lastStoryExpiresAt = lastStoryExpiresAt;
|
|
5035
|
+
this._lastStorySeenExpiresAt = lastStorySeenExpiresAt;
|
|
5036
|
+
this.cacheStoryExpireTime = pullFromCache([
|
|
5037
|
+
"story-expire" /* STORY_KEY_CACHE.EXPIRE */,
|
|
5038
|
+
this._targetId,
|
|
5039
|
+
]);
|
|
5040
|
+
this.cacheStoreSeenTime = pullFromCache([
|
|
5041
|
+
"story-last-seen" /* STORY_KEY_CACHE.LAST_SEEN */,
|
|
5042
|
+
this._targetId,
|
|
5043
|
+
]);
|
|
5044
|
+
this.getTotalStoryByStatus();
|
|
5045
|
+
}
|
|
5046
|
+
get lastStoryExpiresAt() {
|
|
5047
|
+
return this._lastStoryExpiresAt ? new Date(this._lastStoryExpiresAt).getTime() : 0;
|
|
5048
|
+
}
|
|
5049
|
+
get lastStorySeenExpiresAt() {
|
|
5050
|
+
return this._lastStorySeenExpiresAt ? new Date(this._lastStorySeenExpiresAt).getTime() : 0;
|
|
5051
|
+
}
|
|
5052
|
+
get localLastStoryExpires() {
|
|
5053
|
+
var _a, _b;
|
|
5054
|
+
return ((_a = this.cacheStoryExpireTime) === null || _a === void 0 ? void 0 : _a.data)
|
|
5055
|
+
? new Date((_b = this.cacheStoryExpireTime) === null || _b === void 0 ? void 0 : _b.data).getTime()
|
|
5056
|
+
: 0;
|
|
5057
|
+
}
|
|
5058
|
+
get localLastStorySeenExpiresAt() {
|
|
5059
|
+
var _a, _b;
|
|
5060
|
+
return ((_a = this.cacheStoreSeenTime) === null || _a === void 0 ? void 0 : _a.data) ? new Date((_b = this.cacheStoreSeenTime) === null || _b === void 0 ? void 0 : _b.data).getTime() : 0;
|
|
5061
|
+
}
|
|
5062
|
+
get isContainUnSyncedStory() {
|
|
5063
|
+
const currentSyncingState = pullFromCache([
|
|
5064
|
+
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
5065
|
+
this._targetId,
|
|
5066
|
+
]);
|
|
5067
|
+
if (!(currentSyncingState === null || currentSyncingState === void 0 ? void 0 : currentSyncingState.data))
|
|
5068
|
+
return false;
|
|
5069
|
+
return ["syncing" /* Amity.SyncState.Syncing */, "error" /* Amity.SyncState.Error */].includes(currentSyncingState.data);
|
|
5070
|
+
}
|
|
5071
|
+
getLocalLastSortingDate() {
|
|
5072
|
+
if (this.isContainUnSyncedStory) {
|
|
5073
|
+
return this.localLastStoryExpires;
|
|
5054
5074
|
}
|
|
5075
|
+
return this.lastStoryExpiresAt;
|
|
5076
|
+
}
|
|
5077
|
+
getHasUnseenFlag() {
|
|
5078
|
+
const now = new Date().getTime();
|
|
5079
|
+
const highestSeen = Math.max(this.lastStorySeenExpiresAt, this.localLastStorySeenExpiresAt);
|
|
5080
|
+
pullFromCache([
|
|
5081
|
+
"story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */,
|
|
5082
|
+
this._targetId,
|
|
5083
|
+
]);
|
|
5084
|
+
if (this.isContainUnSyncedStory) {
|
|
5085
|
+
return this.localLastStoryExpires > now && this.localLastStoryExpires > highestSeen;
|
|
5086
|
+
}
|
|
5087
|
+
return this.lastStoryExpiresAt > now && this.lastStoryExpiresAt > highestSeen;
|
|
5088
|
+
}
|
|
5089
|
+
getTotalStoryByStatus() {
|
|
5090
|
+
const stories = queryCache(["story" /* STORY_KEY_CACHE.STORY */, 'get']);
|
|
5091
|
+
if (!stories) {
|
|
5092
|
+
this._errorStoriesCount = 0;
|
|
5093
|
+
this._syncedStoriesCount = 0;
|
|
5094
|
+
this._syncingStoriesCount = 0;
|
|
5095
|
+
return;
|
|
5096
|
+
}
|
|
5097
|
+
const groupByType = stories.reduce((acc, story) => {
|
|
5098
|
+
const { data: { targetId, syncState }, } = story;
|
|
5099
|
+
if (targetId === this._targetId) {
|
|
5100
|
+
acc[syncState] += 1;
|
|
5101
|
+
}
|
|
5102
|
+
return acc;
|
|
5103
|
+
}, {
|
|
5104
|
+
syncing: 0,
|
|
5105
|
+
error: 0,
|
|
5106
|
+
synced: 0,
|
|
5107
|
+
});
|
|
5108
|
+
this._errorStoriesCount = groupByType.error;
|
|
5109
|
+
this._syncedStoriesCount = groupByType.synced;
|
|
5110
|
+
this._syncingStoriesCount = groupByType.syncing;
|
|
5055
5111
|
}
|
|
5056
|
-
|
|
5057
|
-
|
|
5112
|
+
get syncedStoriesCount() {
|
|
5113
|
+
return this._syncedStoriesCount;
|
|
5114
|
+
}
|
|
5115
|
+
get syncingStoriesCount() {
|
|
5116
|
+
return this._syncingStoriesCount;
|
|
5117
|
+
}
|
|
5118
|
+
get failedStoriesCount() {
|
|
5119
|
+
return this._errorStoriesCount;
|
|
5120
|
+
}
|
|
5121
|
+
}
|
|
5058
5122
|
|
|
5059
5123
|
const storyTargetLinkedObject = (storyTarget) => {
|
|
5060
|
-
const { targetType, targetId, lastStoryExpiresAt, lastStorySeenExpiresAt, targetUpdatedAt } = storyTarget;
|
|
5124
|
+
const { targetType, targetId, lastStoryExpiresAt, lastStorySeenExpiresAt, targetUpdatedAt, localFilter, } = storyTarget;
|
|
5125
|
+
const computedValue = new StoryComputedValue(targetId, lastStoryExpiresAt, lastStorySeenExpiresAt);
|
|
5061
5126
|
return {
|
|
5062
5127
|
targetType,
|
|
5063
5128
|
targetId,
|
|
5129
|
+
lastStoryExpiresAt,
|
|
5064
5130
|
updatedAt: targetUpdatedAt,
|
|
5065
|
-
|
|
5131
|
+
// Additional data
|
|
5132
|
+
hasUnseen: computedValue.getHasUnseenFlag(),
|
|
5133
|
+
syncedStoriesCount: computedValue.syncedStoriesCount,
|
|
5134
|
+
syncingStoriesCount: computedValue.syncingStoriesCount,
|
|
5135
|
+
failedStoriesCount: computedValue.failedStoriesCount,
|
|
5136
|
+
localFilter,
|
|
5137
|
+
localLastExpires: computedValue.localLastStoryExpires,
|
|
5138
|
+
localLastSeen: computedValue.localLastStorySeenExpiresAt,
|
|
5139
|
+
localSortingDate: computedValue.getLocalLastSortingDate(),
|
|
5066
5140
|
};
|
|
5067
5141
|
};
|
|
5068
5142
|
|
|
5069
5143
|
const storyLinkedObject = (story) => {
|
|
5070
5144
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
5071
5145
|
const storyTargetCache = pullFromCache([
|
|
5072
|
-
|
|
5146
|
+
"storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */,
|
|
5073
5147
|
'get',
|
|
5074
5148
|
story.targetId,
|
|
5075
5149
|
]);
|
|
@@ -7117,6 +7191,40 @@ const hasPermission$1 = (permission) => {
|
|
|
7117
7191
|
};
|
|
7118
7192
|
};
|
|
7119
7193
|
|
|
7194
|
+
/**
|
|
7195
|
+
* Validate a list of urls
|
|
7196
|
+
* @param urls array of strings to validate (max 10 items)
|
|
7197
|
+
*
|
|
7198
|
+
* @category Client API
|
|
7199
|
+
*/
|
|
7200
|
+
const validateUrls = async (urls) => {
|
|
7201
|
+
const client = getActiveClient();
|
|
7202
|
+
client.log('channel/markerSync');
|
|
7203
|
+
if (urls.length === 0)
|
|
7204
|
+
return false;
|
|
7205
|
+
const { data: payload } = await client.http.post('/api/v3/allowlists/verify', {
|
|
7206
|
+
data: urls,
|
|
7207
|
+
});
|
|
7208
|
+
return payload.success;
|
|
7209
|
+
};
|
|
7210
|
+
|
|
7211
|
+
/**
|
|
7212
|
+
* Validate a list of texts
|
|
7213
|
+
* @param texts array of strings to validate (max 10 items)
|
|
7214
|
+
*
|
|
7215
|
+
* @category Client API
|
|
7216
|
+
*/
|
|
7217
|
+
const validateTexts = async (texts) => {
|
|
7218
|
+
const client = getActiveClient();
|
|
7219
|
+
client.log('channel/markerSync');
|
|
7220
|
+
if (texts.length === 0)
|
|
7221
|
+
return false;
|
|
7222
|
+
const { data: payload } = await client.http.post('/api/v3/blocklists/verify', {
|
|
7223
|
+
data: texts,
|
|
7224
|
+
});
|
|
7225
|
+
return payload.success;
|
|
7226
|
+
};
|
|
7227
|
+
|
|
7120
7228
|
/**
|
|
7121
7229
|
* ```js
|
|
7122
7230
|
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
@@ -8654,6 +8762,8 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
8654
8762
|
accessTokenExpiryWatcher,
|
|
8655
8763
|
sessionHandler,
|
|
8656
8764
|
hasPermission: hasPermission$1,
|
|
8765
|
+
validateUrls,
|
|
8766
|
+
validateTexts,
|
|
8657
8767
|
getFeedSettings,
|
|
8658
8768
|
getSocialSettings,
|
|
8659
8769
|
getMessagePreviewSetting,
|
|
@@ -16169,7 +16279,8 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
16169
16279
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16170
16280
|
if (!collection)
|
|
16171
16281
|
return;
|
|
16172
|
-
if (this.paginationController instanceof ChannelPaginationController
|
|
16282
|
+
if (this.paginationController instanceof ChannelPaginationController &&
|
|
16283
|
+
action === 'onCreate') {
|
|
16173
16284
|
collection.data = [...new Set([payload.channelId, ...collection.data])];
|
|
16174
16285
|
pushToCache(this.cacheKey, collection);
|
|
16175
16286
|
}
|
|
@@ -16357,7 +16468,22 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
16357
16468
|
{ fn: onChannelUpdated, action: 'onUpdate' },
|
|
16358
16469
|
{ fn: onChannelMuted, action: 'onMute' },
|
|
16359
16470
|
{ fn: onChannelJoined, action: 'onJoin' },
|
|
16360
|
-
{
|
|
16471
|
+
{
|
|
16472
|
+
fn: (reactor) => {
|
|
16473
|
+
const callback = (channel, member) => {
|
|
16474
|
+
var _a, _b;
|
|
16475
|
+
const { userId } = getActiveClient();
|
|
16476
|
+
// if query for channel member and user is not a member, remove channelId from curren collection
|
|
16477
|
+
if (this.query.membership === 'member' && userId === member.userId) {
|
|
16478
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16479
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: (_b = collection === null || collection === void 0 ? void 0 : collection.data.filter(c => c !== channel.channelId)) !== null && _b !== void 0 ? _b : [] }));
|
|
16480
|
+
}
|
|
16481
|
+
return reactor(channel);
|
|
16482
|
+
};
|
|
16483
|
+
return onChannelLeft(callback);
|
|
16484
|
+
},
|
|
16485
|
+
action: 'onLeft',
|
|
16486
|
+
},
|
|
16361
16487
|
{ fn: onChannelMemberAdded, action: 'onMemberAdded' },
|
|
16362
16488
|
{ fn: onChannelMemberRemoved, action: 'onMemberRemoved' },
|
|
16363
16489
|
{
|
|
@@ -22175,7 +22301,10 @@ const createImageStory = async (targetType, targetId, formData, metadata = {}, i
|
|
|
22175
22301
|
targetId,
|
|
22176
22302
|
metadata,
|
|
22177
22303
|
};
|
|
22304
|
+
const date = new Date();
|
|
22178
22305
|
pushToCache(["story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */, targetId], "syncing" /* Amity.SyncState.Syncing */);
|
|
22306
|
+
// Update local story expires time
|
|
22307
|
+
pushToCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, targetId], new Date(date.setFullYear(date.getFullYear() + 1)));
|
|
22179
22308
|
// Fire optimistic event
|
|
22180
22309
|
createOptimisticEvent({ payload, formData }, optimisticData => {
|
|
22181
22310
|
fireEvent('local.story.created', optimisticData);
|
|
@@ -22236,7 +22365,10 @@ const createVideoStory = async (targetType, targetId, formData, metadata = {}, i
|
|
|
22236
22365
|
targetId,
|
|
22237
22366
|
metadata,
|
|
22238
22367
|
};
|
|
22368
|
+
const date = new Date();
|
|
22239
22369
|
pushToCache(["story-sync-state" /* STORY_KEY_CACHE.SYNC_STATE */, targetId], "syncing" /* Amity.SyncState.Syncing */);
|
|
22370
|
+
// Update local story expires time
|
|
22371
|
+
pushToCache(["story-expire" /* STORY_KEY_CACHE.EXPIRE */, targetId], new Date(date.setFullYear(date.getFullYear() + 1)));
|
|
22240
22372
|
// Fire optimistic event
|
|
22241
22373
|
createOptimisticEvent({ payload, formData, isVideo: true }, optimisticData => {
|
|
22242
22374
|
fireEvent('local.story.created', optimisticData);
|
|
@@ -22824,7 +22956,6 @@ class StoryQueryStreamController extends QueryStreamController {
|
|
|
22824
22956
|
}
|
|
22825
22957
|
}
|
|
22826
22958
|
|
|
22827
|
-
/* eslint-disable no-use-before-define */
|
|
22828
22959
|
class StoryPaginationNoPageController extends PaginationNoPageController {
|
|
22829
22960
|
async getRequest(queryParams) {
|
|
22830
22961
|
const { data: queryResponse } = await this.http.get('/api/v4/stories-by-targets', {
|
|
@@ -22919,6 +23050,219 @@ const getStoriesByTargetIds = (params, callback, config) => {
|
|
|
22919
23050
|
};
|
|
22920
23051
|
};
|
|
22921
23052
|
|
|
23053
|
+
const updateLocalList = (cacheKey, targetIds) => {
|
|
23054
|
+
var _a, _b;
|
|
23055
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23056
|
+
const storyTargets = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23057
|
+
pushToCache(cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...storyTargets, ...targetIds])] }));
|
|
23058
|
+
};
|
|
23059
|
+
class GlobalStoryQueryStreamController extends QueryStreamController {
|
|
23060
|
+
constructor(query, cacheKey, notifyChange, paginationController) {
|
|
23061
|
+
super(query, cacheKey);
|
|
23062
|
+
this.notifyChange = notifyChange;
|
|
23063
|
+
this.paginationController = paginationController;
|
|
23064
|
+
// Fix ESLint, "Expected 'this' to be used by class method"
|
|
23065
|
+
this.preparePayload = payload => payload;
|
|
23066
|
+
}
|
|
23067
|
+
saveToMainDB(response) {
|
|
23068
|
+
const client = getActiveClient();
|
|
23069
|
+
const cachedAt = client.cache && Date.now();
|
|
23070
|
+
// Fix Eslint error for "Expected 'this' to be used by class method"
|
|
23071
|
+
const data = this.preparePayload(response);
|
|
23072
|
+
if (client.cache) {
|
|
23073
|
+
ingestInCache(data, { cachedAt });
|
|
23074
|
+
}
|
|
23075
|
+
}
|
|
23076
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23077
|
+
if (refresh) {
|
|
23078
|
+
pushToCache(this.cacheKey, {
|
|
23079
|
+
data: response.storyTargets.map(({ targetId }) => targetId),
|
|
23080
|
+
});
|
|
23081
|
+
}
|
|
23082
|
+
else {
|
|
23083
|
+
updateLocalList(this.cacheKey, response.storyTargets.map(({ targetId }) => targetId));
|
|
23084
|
+
}
|
|
23085
|
+
}
|
|
23086
|
+
reactor(actionType) {
|
|
23087
|
+
return (payload) => {
|
|
23088
|
+
if (actionType === "onCreate" /* Amity.StoryActionType.OnCreate */ &&
|
|
23089
|
+
this.query.seenState !== "seen" /* Amity.StorySeenQuery.SEEN */) {
|
|
23090
|
+
updateLocalList(this.cacheKey, payload.map(({ targetId }) => targetId));
|
|
23091
|
+
}
|
|
23092
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23093
|
+
};
|
|
23094
|
+
}
|
|
23095
|
+
subscribeRTE(createSubscriber) {
|
|
23096
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23097
|
+
}
|
|
23098
|
+
}
|
|
23099
|
+
|
|
23100
|
+
const mergeResult = (resultA, resultB) => {
|
|
23101
|
+
return {
|
|
23102
|
+
categories: resultA.categories.concat(resultB.categories),
|
|
23103
|
+
communities: resultA.communities.concat(resultB.communities),
|
|
23104
|
+
communityUsers: resultA.communityUsers.concat(resultB.communityUsers),
|
|
23105
|
+
files: resultA.files.concat(resultB.files),
|
|
23106
|
+
storyTargets: resultA.storyTargets.concat(resultB.storyTargets),
|
|
23107
|
+
users: resultA.users.concat(resultB.users),
|
|
23108
|
+
paging: resultB.paging,
|
|
23109
|
+
};
|
|
23110
|
+
};
|
|
23111
|
+
const addFlagLocalFilter = (payload, filter) => {
|
|
23112
|
+
return Object.assign(Object.assign({}, payload), { storyTargets: payload.storyTargets.map(item => (Object.assign(Object.assign({}, item), { localFilter: filter }))) || [] });
|
|
23113
|
+
};
|
|
23114
|
+
class GlobalStoryPageController extends PaginationController {
|
|
23115
|
+
constructor() {
|
|
23116
|
+
super(...arguments);
|
|
23117
|
+
this.smartFilterState = "unseen" /* Amity.StorySeenQuery.UNSEEN */;
|
|
23118
|
+
}
|
|
23119
|
+
async getRequest(queryParams, token) {
|
|
23120
|
+
var _a;
|
|
23121
|
+
// Apply default values for parameters
|
|
23122
|
+
const { limit = 10, seenState = "unseen" /* Amity.StorySeenQuery.UNSEEN */ } = queryParams;
|
|
23123
|
+
const result = await this.createRequest({
|
|
23124
|
+
seenState: seenState === "smart" /* Amity.StorySeenQuery.SMART */ ? this.smartFilterState : seenState,
|
|
23125
|
+
limit,
|
|
23126
|
+
token,
|
|
23127
|
+
});
|
|
23128
|
+
// Use Early return to reduce condition complexity
|
|
23129
|
+
if ((_a = result.paging) === null || _a === void 0 ? void 0 : _a.next)
|
|
23130
|
+
return result;
|
|
23131
|
+
if (seenState !== "smart" /* Amity.StorySeenQuery.SMART */)
|
|
23132
|
+
return result;
|
|
23133
|
+
if (this.smartFilterState === "seen" /* Amity.StorySeenQuery.SEEN */)
|
|
23134
|
+
return result;
|
|
23135
|
+
this.smartFilterState = "seen" /* Amity.StorySeenQuery.SEEN */;
|
|
23136
|
+
const additionalResult = await this.createRequest({
|
|
23137
|
+
seenState: this.smartFilterState,
|
|
23138
|
+
limit,
|
|
23139
|
+
});
|
|
23140
|
+
return mergeResult(result, additionalResult);
|
|
23141
|
+
}
|
|
23142
|
+
async createRequest(params) {
|
|
23143
|
+
const { data: queryResponse } = await this.http.get('/api/v5/me/global-story-targets', {
|
|
23144
|
+
params,
|
|
23145
|
+
});
|
|
23146
|
+
return addFlagLocalFilter(queryResponse, params.seenState);
|
|
23147
|
+
}
|
|
23148
|
+
}
|
|
23149
|
+
|
|
23150
|
+
class GlobalStoryLiveCollectionController extends LiveCollectionController {
|
|
23151
|
+
constructor(query, callback) {
|
|
23152
|
+
const queryStreamId = hash__default["default"](query);
|
|
23153
|
+
const cacheKey = ["story-global-feed" /* STORY_KEY_CACHE.STORY_GLOBAL_FEED */, 'collection', queryStreamId];
|
|
23154
|
+
const paginationController = new GlobalStoryPageController(query);
|
|
23155
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23156
|
+
this.query = query;
|
|
23157
|
+
this.queryStreamController = new GlobalStoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
23158
|
+
this.paginationController = paginationController;
|
|
23159
|
+
this.callback = callback.bind(this);
|
|
23160
|
+
this.loadPage(true);
|
|
23161
|
+
}
|
|
23162
|
+
setup() {
|
|
23163
|
+
var _a;
|
|
23164
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23165
|
+
if (!collection) {
|
|
23166
|
+
pushToCache(this.cacheKey, {
|
|
23167
|
+
data: [],
|
|
23168
|
+
params: {},
|
|
23169
|
+
});
|
|
23170
|
+
}
|
|
23171
|
+
}
|
|
23172
|
+
persistModel(response) {
|
|
23173
|
+
this.queryStreamController.saveToMainDB(response);
|
|
23174
|
+
}
|
|
23175
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23176
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23177
|
+
}
|
|
23178
|
+
notifyChange({ origin, loading, error }) {
|
|
23179
|
+
var _a;
|
|
23180
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23181
|
+
if (!collection)
|
|
23182
|
+
return;
|
|
23183
|
+
let data = collection.data
|
|
23184
|
+
.map(targetId => pullFromCache(["storyTarget" /* STORY_KEY_CACHE.STORY_TARGET */, 'get', targetId]))
|
|
23185
|
+
.filter(Boolean)
|
|
23186
|
+
.map(storyTarget => LinkedObject.storyTarget(storyTarget.data));
|
|
23187
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23188
|
+
return;
|
|
23189
|
+
data = this.applyFilter(data);
|
|
23190
|
+
this.callback({
|
|
23191
|
+
onNextPage: () => this.loadPage(false, "next" /* Amity.LiveCollectionPageDirection.NEXT */),
|
|
23192
|
+
data,
|
|
23193
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23194
|
+
loading,
|
|
23195
|
+
error,
|
|
23196
|
+
});
|
|
23197
|
+
}
|
|
23198
|
+
applyFilter(data) {
|
|
23199
|
+
if (this.query.seenState !== "smart" /* Amity.StorySeenQuery.SMART */) {
|
|
23200
|
+
return data
|
|
23201
|
+
.filter(({ hasUnseen }) => {
|
|
23202
|
+
if (this.query.seenState === "all" /* Amity.StorySeenQuery.ALL */)
|
|
23203
|
+
return true;
|
|
23204
|
+
if (this.query.seenState === "seen" /* Amity.StorySeenQuery.SEEN */ && !hasUnseen)
|
|
23205
|
+
return true;
|
|
23206
|
+
return this.query.seenState === "unseen" /* Amity.StorySeenQuery.UNSEEN */ && hasUnseen;
|
|
23207
|
+
})
|
|
23208
|
+
.sort(sortByLocalSortingDate);
|
|
23209
|
+
}
|
|
23210
|
+
// Smart Filter - Apply local sorting on each list of data
|
|
23211
|
+
const result = data.reduce((acc, storyTarget) => {
|
|
23212
|
+
if (storyTarget.localFilter === "unseen" /* Amity.StorySeenQuery.UNSEEN */) {
|
|
23213
|
+
acc.unseen.push(storyTarget);
|
|
23214
|
+
}
|
|
23215
|
+
else if (storyTarget.localFilter === "seen" /* Amity.StorySeenQuery.SEEN */) {
|
|
23216
|
+
acc.seen.push(storyTarget);
|
|
23217
|
+
}
|
|
23218
|
+
else {
|
|
23219
|
+
acc.unknown.push(storyTarget);
|
|
23220
|
+
}
|
|
23221
|
+
return acc;
|
|
23222
|
+
}, { unseen: [], seen: [], unknown: [] });
|
|
23223
|
+
const sortedUnknown = result.unknown.sort(sortByLocalSortingDate) || [];
|
|
23224
|
+
const sortedUnseen = result.unseen.sort(sortByLocalSortingDate) || [];
|
|
23225
|
+
const sortedSeen = result.seen.sort(sortByLocalSortingDate) || [];
|
|
23226
|
+
// Merge all status and remove internal fields
|
|
23227
|
+
return sortedUnknown
|
|
23228
|
+
.concat(sortedUnseen, sortedSeen)
|
|
23229
|
+
.map((_a) => {
|
|
23230
|
+
var rest = __rest(_a, ["localFilter", "localLastExpires", "localLastSeen", "localSortingDate"]);
|
|
23231
|
+
return rest;
|
|
23232
|
+
});
|
|
23233
|
+
}
|
|
23234
|
+
startSubscription() {
|
|
23235
|
+
return this.queryStreamController.subscribeRTE([
|
|
23236
|
+
{ fn: onStoryCreated, action: "onCreate" /* Amity.StoryActionType.OnCreate */ },
|
|
23237
|
+
{ fn: onStoryUpdated, action: "onUpdate" /* Amity.StoryActionType.OnUpdate */ },
|
|
23238
|
+
{ fn: onStoryDeleted, action: "onDelete" /* Amity.StoryActionType.OnDelete */ },
|
|
23239
|
+
{ fn: onStoryCreatedLocal, action: "onCreate" /* Amity.StoryActionType.OnCreate */ },
|
|
23240
|
+
{ fn: onStoryUpdatedLocal, action: "onUpdate" /* Amity.StoryActionType.OnUpdate */ },
|
|
23241
|
+
{ fn: onStoryDeletedLocal, action: "onDelete" /* Amity.StoryActionType.OnDelete */ },
|
|
23242
|
+
{ fn: onStoryError, action: "onError" /* Amity.StoryActionType.OnError */ },
|
|
23243
|
+
]);
|
|
23244
|
+
}
|
|
23245
|
+
}
|
|
23246
|
+
|
|
23247
|
+
const getGlobalStoryTargets = (params, callback, config) => {
|
|
23248
|
+
const { log, cache, userId } = getActiveClient();
|
|
23249
|
+
if (!cache) {
|
|
23250
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23251
|
+
}
|
|
23252
|
+
const timestamp = Date.now();
|
|
23253
|
+
log(`getGlobalStoryTarget(tmpid: ${timestamp}) > listen`);
|
|
23254
|
+
const storyLiveCollection = new GlobalStoryLiveCollectionController(params, callback);
|
|
23255
|
+
const disposers = storyLiveCollection.startSubscription();
|
|
23256
|
+
const cacheKey = storyLiveCollection.getCacheKey();
|
|
23257
|
+
disposers.push(() => {
|
|
23258
|
+
dropFromCache(cacheKey);
|
|
23259
|
+
});
|
|
23260
|
+
return () => {
|
|
23261
|
+
log(`getGlobalStoryTarget(tmpid: ${timestamp}) > dispose`);
|
|
23262
|
+
disposers.forEach(fn => fn());
|
|
23263
|
+
};
|
|
23264
|
+
};
|
|
23265
|
+
|
|
22922
23266
|
var index = /*#__PURE__*/Object.freeze({
|
|
22923
23267
|
__proto__: null,
|
|
22924
23268
|
createImageStory: createImageStory,
|
|
@@ -22929,7 +23273,8 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
22929
23273
|
getStoryByStoryId: getStoryByStoryId,
|
|
22930
23274
|
getTargetById: getTargetById,
|
|
22931
23275
|
getTargetsByTargetIds: getTargetsByTargetIds,
|
|
22932
|
-
getStoriesByTargetIds: getStoriesByTargetIds
|
|
23276
|
+
getStoriesByTargetIds: getStoriesByTargetIds,
|
|
23277
|
+
getGlobalStoryTargets: getGlobalStoryTargets
|
|
22933
23278
|
});
|
|
22934
23279
|
|
|
22935
23280
|
/**
|
|
@@ -23052,6 +23397,7 @@ exports.sortByFirstUpdated = sortByFirstUpdated;
|
|
|
23052
23397
|
exports.sortByLastActivity = sortByLastActivity;
|
|
23053
23398
|
exports.sortByLastCreated = sortByLastCreated;
|
|
23054
23399
|
exports.sortByLastUpdated = sortByLastUpdated;
|
|
23400
|
+
exports.sortByLocalSortingDate = sortByLocalSortingDate;
|
|
23055
23401
|
exports.sortByName = sortByName;
|
|
23056
23402
|
exports.sortBySegmentNumber = sortBySegmentNumber;
|
|
23057
23403
|
exports.subscribeTopic = subscribeTopic;
|