@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
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
|
|
3
|
+
type GlobalStoryFeedResult = Amity.GlobalStoryFeedPayload & Amity.Pagination;
|
|
4
|
+
|
|
5
|
+
const mergeResult = (
|
|
6
|
+
resultA: GlobalStoryFeedResult,
|
|
7
|
+
resultB: GlobalStoryFeedResult,
|
|
8
|
+
): GlobalStoryFeedResult => {
|
|
9
|
+
return {
|
|
10
|
+
categories: resultA.categories.concat(resultB.categories),
|
|
11
|
+
communities: resultA.communities.concat(resultB.communities),
|
|
12
|
+
communityUsers: resultA.communityUsers.concat(resultB.communityUsers),
|
|
13
|
+
files: resultA.files.concat(resultB.files),
|
|
14
|
+
storyTargets: resultA.storyTargets.concat(resultB.storyTargets),
|
|
15
|
+
users: resultA.users.concat(resultB.users),
|
|
16
|
+
paging: resultB.paging,
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const addFlagLocalFilter = (
|
|
21
|
+
payload: GlobalStoryFeedResult,
|
|
22
|
+
filter: Amity.StorySeenQuery,
|
|
23
|
+
): GlobalStoryFeedResult => {
|
|
24
|
+
return {
|
|
25
|
+
...payload,
|
|
26
|
+
storyTargets: payload.storyTargets.map(item => ({ ...item, localFilter: filter })) || [],
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
export class GlobalStoryPageController extends PaginationController<
|
|
31
|
+
'globalStoryFeed',
|
|
32
|
+
Amity.LiveCollectionParams<Amity.StoryGlobalQuery>
|
|
33
|
+
> {
|
|
34
|
+
private smartFilterState = Amity.StorySeenQuery.UNSEEN;
|
|
35
|
+
|
|
36
|
+
async getRequest(
|
|
37
|
+
queryParams: Amity.LiveCollectionParams<Amity.StoryGlobalQuery>,
|
|
38
|
+
token: string | undefined,
|
|
39
|
+
) {
|
|
40
|
+
// Apply default values for parameters
|
|
41
|
+
const { limit = 10, seenState = Amity.StorySeenQuery.UNSEEN } = queryParams;
|
|
42
|
+
|
|
43
|
+
const result = await this.createRequest({
|
|
44
|
+
seenState: seenState === Amity.StorySeenQuery.SMART ? this.smartFilterState : seenState,
|
|
45
|
+
limit,
|
|
46
|
+
token,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
// Use Early return to reduce condition complexity
|
|
50
|
+
if (result.paging?.next) return result;
|
|
51
|
+
if (seenState !== Amity.StorySeenQuery.SMART) return result;
|
|
52
|
+
if (this.smartFilterState === Amity.StorySeenQuery.SEEN) return result;
|
|
53
|
+
|
|
54
|
+
this.smartFilterState = Amity.StorySeenQuery.SEEN;
|
|
55
|
+
const additionalResult = await this.createRequest({
|
|
56
|
+
seenState: this.smartFilterState,
|
|
57
|
+
limit,
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
return mergeResult(result, additionalResult);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
async createRequest(params: { seenState: Amity.StorySeenQuery; limit: number; token?: string }) {
|
|
64
|
+
const { data: queryResponse } = await this.http.get<GlobalStoryFeedResult>(
|
|
65
|
+
'/api/v5/me/global-story-targets',
|
|
66
|
+
{
|
|
67
|
+
params,
|
|
68
|
+
},
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
return addFlagLocalFilter(queryResponse, params.seenState);
|
|
72
|
+
}
|
|
73
|
+
}
|
package/src/storyRepository/observers/getGlobalStoryTargets/GlobalStoryQueryStreamController.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { getActiveClient } from '~/client';
|
|
3
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
import { GlobalStoryPageController } from './GlobalStoryPageController';
|
|
6
|
+
|
|
7
|
+
const updateLocalList = (cacheKey: string[], targetIds: Amity.StoryTarget['targetId'][]) => {
|
|
8
|
+
const collection = pullFromCache<Amity.StoryLiveCollectionCache>(cacheKey)?.data;
|
|
9
|
+
const storyTargets = collection?.data ?? [];
|
|
10
|
+
|
|
11
|
+
pushToCache(cacheKey, {
|
|
12
|
+
...collection,
|
|
13
|
+
data: [...new Set([...storyTargets, ...targetIds])],
|
|
14
|
+
});
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
export class GlobalStoryQueryStreamController extends QueryStreamController<
|
|
18
|
+
Amity.GlobalStoryFeedPayload,
|
|
19
|
+
Amity.LiveCollectionParams<Amity.StoryGlobalQuery>
|
|
20
|
+
> {
|
|
21
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
22
|
+
|
|
23
|
+
private preparePayload: (response: Amity.GlobalStoryFeedPayload) => Amity.GlobalStoryFeedPayload;
|
|
24
|
+
|
|
25
|
+
private paginationController: GlobalStoryPageController;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
query: Amity.LiveCollectionParams<Amity.StoryGlobalQuery>,
|
|
29
|
+
cacheKey: string[],
|
|
30
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
31
|
+
paginationController: GlobalStoryPageController,
|
|
32
|
+
) {
|
|
33
|
+
super(query, cacheKey);
|
|
34
|
+
this.notifyChange = notifyChange;
|
|
35
|
+
this.paginationController = paginationController;
|
|
36
|
+
|
|
37
|
+
// Fix ESLint, "Expected 'this' to be used by class method"
|
|
38
|
+
this.preparePayload = payload => payload;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
saveToMainDB(response: Amity.GlobalStoryFeedPayload) {
|
|
42
|
+
const client = getActiveClient();
|
|
43
|
+
const cachedAt = client.cache && Date.now();
|
|
44
|
+
|
|
45
|
+
// Fix Eslint error for "Expected 'this' to be used by class method"
|
|
46
|
+
const data = this.preparePayload(response);
|
|
47
|
+
|
|
48
|
+
if (client.cache) {
|
|
49
|
+
ingestInCache(data, { cachedAt });
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
appendToQueryStream(
|
|
54
|
+
response: Amity.GlobalStoryFeedPayload,
|
|
55
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
56
|
+
refresh = false,
|
|
57
|
+
) {
|
|
58
|
+
if (refresh) {
|
|
59
|
+
pushToCache(this.cacheKey, {
|
|
60
|
+
data: response.storyTargets.map(({ targetId }) => targetId),
|
|
61
|
+
});
|
|
62
|
+
} else {
|
|
63
|
+
updateLocalList(
|
|
64
|
+
this.cacheKey,
|
|
65
|
+
response.storyTargets.map(({ targetId }) => targetId),
|
|
66
|
+
);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
reactor(actionType: Amity.StoryActionType) {
|
|
71
|
+
return (payload: Amity.InternalStory[]) => {
|
|
72
|
+
if (
|
|
73
|
+
actionType === Amity.StoryActionType.OnCreate &&
|
|
74
|
+
this.query.seenState !== Amity.StorySeenQuery.SEEN
|
|
75
|
+
) {
|
|
76
|
+
updateLocalList(
|
|
77
|
+
this.cacheKey,
|
|
78
|
+
payload.map(({ targetId }) => targetId),
|
|
79
|
+
);
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
83
|
+
};
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
subscribeRTE(
|
|
87
|
+
createSubscriber: {
|
|
88
|
+
fn: (reactor: Amity.Listener<Amity.InternalStory[]>) => Amity.Unsubscriber;
|
|
89
|
+
action: Amity.StoryActionType;
|
|
90
|
+
}[],
|
|
91
|
+
) {
|
|
92
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client';
|
|
2
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
3
|
+
import { dropFromCache } from '~/cache/api';
|
|
4
|
+
import { GlobalStoryLiveCollectionController } from './GlobalStoryLiveCollectionController';
|
|
5
|
+
|
|
6
|
+
export const getGlobalStoryTargets = (
|
|
7
|
+
params: Amity.LiveCollectionParams<Amity.StoryGlobalQuery>,
|
|
8
|
+
callback: Amity.LiveCollectionCallback<Amity.StoryTarget>,
|
|
9
|
+
config?: Amity.LiveCollectionConfig,
|
|
10
|
+
) => {
|
|
11
|
+
const { log, cache, userId } = getActiveClient();
|
|
12
|
+
|
|
13
|
+
if (!cache) {
|
|
14
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
const timestamp = Date.now();
|
|
18
|
+
log(`getGlobalStoryTarget(tmpid: ${timestamp}) > listen`);
|
|
19
|
+
|
|
20
|
+
const storyLiveCollection = new GlobalStoryLiveCollectionController(params, callback);
|
|
21
|
+
const disposers = storyLiveCollection.startSubscription();
|
|
22
|
+
const cacheKey = storyLiveCollection.getCacheKey();
|
|
23
|
+
|
|
24
|
+
disposers.push(() => {
|
|
25
|
+
dropFromCache(cacheKey);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
return () => {
|
|
29
|
+
log(`getGlobalStoryTarget(tmpid: ${timestamp}) > dispose`);
|
|
30
|
+
disposers.forEach(fn => fn());
|
|
31
|
+
};
|
|
32
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './getGlobalStoryTargets';
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
import { pullFromCache, queryCache } from '~/cache/api';
|
|
2
|
+
import { STORY_KEY_CACHE } from '~/storyRepository/constants';
|
|
3
|
+
|
|
4
|
+
export class StoryComputedValue {
|
|
5
|
+
private readonly _targetId: string;
|
|
6
|
+
|
|
7
|
+
private readonly _lastStoryExpiresAt?: Amity.timestamp;
|
|
8
|
+
|
|
9
|
+
private readonly _lastStorySeenExpiresAt?: Amity.timestamp;
|
|
10
|
+
|
|
11
|
+
private cacheStoryExpireTime?: Amity.Cached<Amity.timestamp>;
|
|
12
|
+
|
|
13
|
+
private cacheStoreSeenTime?: Amity.Cached<Amity.timestamp>;
|
|
14
|
+
|
|
15
|
+
private _syncingStoriesCount = 0;
|
|
16
|
+
|
|
17
|
+
private _syncedStoriesCount = 0;
|
|
18
|
+
|
|
19
|
+
private _errorStoriesCount = 0;
|
|
20
|
+
|
|
21
|
+
constructor(
|
|
22
|
+
targetId: string,
|
|
23
|
+
lastStoryExpiresAt?: Amity.timestamp,
|
|
24
|
+
lastStorySeenExpiresAt?: Amity.timestamp,
|
|
25
|
+
) {
|
|
26
|
+
this._targetId = targetId;
|
|
27
|
+
|
|
28
|
+
this._lastStoryExpiresAt = lastStoryExpiresAt;
|
|
29
|
+
|
|
30
|
+
this._lastStorySeenExpiresAt = lastStorySeenExpiresAt;
|
|
31
|
+
|
|
32
|
+
this.cacheStoryExpireTime = pullFromCache<Amity.timestamp>([
|
|
33
|
+
STORY_KEY_CACHE.EXPIRE,
|
|
34
|
+
this._targetId,
|
|
35
|
+
]);
|
|
36
|
+
|
|
37
|
+
this.cacheStoreSeenTime = pullFromCache<Amity.timestamp>([
|
|
38
|
+
STORY_KEY_CACHE.LAST_SEEN,
|
|
39
|
+
this._targetId,
|
|
40
|
+
]);
|
|
41
|
+
|
|
42
|
+
this.getTotalStoryByStatus();
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
get lastStoryExpiresAt(): number {
|
|
46
|
+
return this._lastStoryExpiresAt ? new Date(this._lastStoryExpiresAt).getTime() : 0;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get lastStorySeenExpiresAt(): number {
|
|
50
|
+
return this._lastStorySeenExpiresAt ? new Date(this._lastStorySeenExpiresAt).getTime() : 0;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
get localLastStoryExpires(): number {
|
|
54
|
+
return this.cacheStoryExpireTime?.data
|
|
55
|
+
? new Date(this.cacheStoryExpireTime?.data).getTime()
|
|
56
|
+
: 0;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
get localLastStorySeenExpiresAt(): number {
|
|
60
|
+
return this.cacheStoreSeenTime?.data ? new Date(this.cacheStoreSeenTime?.data).getTime() : 0;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
get isContainUnSyncedStory(): boolean {
|
|
64
|
+
const currentSyncingState = pullFromCache<Amity.SyncState>([
|
|
65
|
+
STORY_KEY_CACHE.SYNC_STATE,
|
|
66
|
+
this._targetId,
|
|
67
|
+
]);
|
|
68
|
+
|
|
69
|
+
if (!currentSyncingState?.data) return false;
|
|
70
|
+
|
|
71
|
+
return [Amity.SyncState.Syncing, Amity.SyncState.Error].includes(currentSyncingState.data);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
getLocalLastSortingDate(): number {
|
|
75
|
+
if (this.isContainUnSyncedStory) {
|
|
76
|
+
return this.localLastStoryExpires;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return this.lastStoryExpiresAt;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
getHasUnseenFlag(): boolean {
|
|
83
|
+
const now = new Date().getTime();
|
|
84
|
+
|
|
85
|
+
const highestSeen = Math.max(this.lastStorySeenExpiresAt, this.localLastStorySeenExpiresAt);
|
|
86
|
+
|
|
87
|
+
const currentSyncingState = pullFromCache<Amity.SyncState>([
|
|
88
|
+
STORY_KEY_CACHE.SYNC_STATE,
|
|
89
|
+
this._targetId,
|
|
90
|
+
]);
|
|
91
|
+
|
|
92
|
+
if (this.isContainUnSyncedStory) {
|
|
93
|
+
return this.localLastStoryExpires > now && this.localLastStoryExpires > highestSeen;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
return this.lastStoryExpiresAt > now && this.lastStoryExpiresAt > highestSeen;
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
getTotalStoryByStatus(): void {
|
|
100
|
+
const stories = queryCache<Amity.InternalStory>([STORY_KEY_CACHE.STORY, 'get']);
|
|
101
|
+
|
|
102
|
+
if (!stories) {
|
|
103
|
+
this._errorStoriesCount = 0;
|
|
104
|
+
this._syncedStoriesCount = 0;
|
|
105
|
+
this._syncingStoriesCount = 0;
|
|
106
|
+
return;
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const groupByType = stories.reduce(
|
|
110
|
+
(acc, story) => {
|
|
111
|
+
const {
|
|
112
|
+
data: { targetId, syncState },
|
|
113
|
+
} = story;
|
|
114
|
+
|
|
115
|
+
if (targetId === this._targetId) {
|
|
116
|
+
acc[syncState!] += 1;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return acc;
|
|
120
|
+
},
|
|
121
|
+
{
|
|
122
|
+
syncing: 0,
|
|
123
|
+
error: 0,
|
|
124
|
+
synced: 0,
|
|
125
|
+
},
|
|
126
|
+
);
|
|
127
|
+
|
|
128
|
+
this._errorStoriesCount = groupByType.error;
|
|
129
|
+
this._syncedStoriesCount = groupByType.synced;
|
|
130
|
+
this._syncingStoriesCount = groupByType.syncing;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
get syncedStoriesCount(): number {
|
|
134
|
+
return this._syncedStoriesCount;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
get syncingStoriesCount(): number {
|
|
138
|
+
return this._syncingStoriesCount;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
get failedStoriesCount(): number {
|
|
142
|
+
return this._errorStoriesCount;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
@@ -8,10 +8,11 @@ export const storyLinkedObject = (story: Amity.InternalStory): Amity.Story => {
|
|
|
8
8
|
const analyticsEngineInstance = AnalyticsEngine.getInstance();
|
|
9
9
|
|
|
10
10
|
const storyTargetCache = pullFromCache<Amity.RawStoryTarget>([
|
|
11
|
-
|
|
11
|
+
STORY_KEY_CACHE.STORY_TARGET,
|
|
12
12
|
'get',
|
|
13
13
|
story.targetId,
|
|
14
14
|
]);
|
|
15
|
+
|
|
15
16
|
const communityCacheData = pullFromCache<Amity.Community>(['community', 'get', story.targetId]);
|
|
16
17
|
|
|
17
18
|
return {
|
|
@@ -1,13 +1,36 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { StoryComputedValue } from '~/storyRepository/utils/StoryComputedValue';
|
|
2
2
|
|
|
3
3
|
export const storyTargetLinkedObject = (storyTarget: Amity.RawStoryTarget): Amity.StoryTarget => {
|
|
4
|
-
const {
|
|
5
|
-
|
|
4
|
+
const {
|
|
5
|
+
targetType,
|
|
6
|
+
targetId,
|
|
7
|
+
lastStoryExpiresAt,
|
|
8
|
+
lastStorySeenExpiresAt,
|
|
9
|
+
targetUpdatedAt,
|
|
10
|
+
localFilter,
|
|
11
|
+
} = storyTarget;
|
|
12
|
+
|
|
13
|
+
const computedValue = new StoryComputedValue(
|
|
14
|
+
targetId,
|
|
15
|
+
lastStoryExpiresAt,
|
|
16
|
+
lastStorySeenExpiresAt,
|
|
17
|
+
);
|
|
6
18
|
|
|
7
19
|
return {
|
|
8
20
|
targetType,
|
|
9
21
|
targetId,
|
|
22
|
+
lastStoryExpiresAt,
|
|
10
23
|
updatedAt: targetUpdatedAt,
|
|
11
|
-
|
|
24
|
+
|
|
25
|
+
// Additional data
|
|
26
|
+
hasUnseen: computedValue.getHasUnseenFlag(),
|
|
27
|
+
syncedStoriesCount: computedValue.syncedStoriesCount,
|
|
28
|
+
syncingStoriesCount: computedValue.syncingStoriesCount,
|
|
29
|
+
failedStoriesCount: computedValue.failedStoriesCount,
|
|
30
|
+
|
|
31
|
+
localFilter,
|
|
32
|
+
localLastExpires: computedValue.localLastStoryExpires,
|
|
33
|
+
localLastSeen: computedValue.localLastStorySeenExpiresAt,
|
|
34
|
+
localSortingDate: computedValue.getLocalLastSortingDate(),
|
|
12
35
|
};
|
|
13
36
|
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export declare const calculateHasUnseenFlag: (params: {
|
|
2
|
-
targetId: Amity.Story['targetId'];
|
|
3
|
-
lastStoryExpiresAt: Amity.RawStoryTarget['lastStoryExpiresAt'];
|
|
4
|
-
lastStorySeenExpiresAt: Amity.RawStoryTarget['lastStorySeenExpiresAt'];
|
|
5
|
-
}) => boolean;
|
|
6
|
-
//# sourceMappingURL=calculateHasUnseenFlag.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"calculateHasUnseenFlag.d.ts","sourceRoot":"","sources":["../../../src/storyRepository/utils/calculateHasUnseenFlag.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,sBAAsB,WAAY;IAC7C,QAAQ,EAAE,MAAM,KAAK,CAAC,UAAU,CAAC,CAAC;IAClC,kBAAkB,EAAE,MAAM,cAAc,CAAC,oBAAoB,CAAC,CAAC;IAC/D,sBAAsB,EAAE,MAAM,cAAc,CAAC,wBAAwB,CAAC,CAAC;CACxE,KAAG,OAuCH,CAAC"}
|
|
@@ -1,47 +0,0 @@
|
|
|
1
|
-
import { pullFromCache } from '~/cache/api';
|
|
2
|
-
import { STORY_KEY_CACHE } from '~/storyRepository/constants';
|
|
3
|
-
|
|
4
|
-
export const calculateHasUnseenFlag = (params: {
|
|
5
|
-
targetId: Amity.Story['targetId'];
|
|
6
|
-
lastStoryExpiresAt: Amity.RawStoryTarget['lastStoryExpiresAt'];
|
|
7
|
-
lastStorySeenExpiresAt: Amity.RawStoryTarget['lastStorySeenExpiresAt'];
|
|
8
|
-
}): boolean => {
|
|
9
|
-
const cacheStoryExpireTime = pullFromCache<Amity.timestamp>([
|
|
10
|
-
STORY_KEY_CACHE.EXPIRE,
|
|
11
|
-
params.targetId,
|
|
12
|
-
]);
|
|
13
|
-
|
|
14
|
-
const cacheStoreSeenTime = pullFromCache<Amity.timestamp>([
|
|
15
|
-
STORY_KEY_CACHE.LAST_SEEN,
|
|
16
|
-
params.targetId,
|
|
17
|
-
]);
|
|
18
|
-
|
|
19
|
-
const now = new Date().getTime();
|
|
20
|
-
const lastStoryExpiresAt = params.lastStoryExpiresAt
|
|
21
|
-
? new Date(params.lastStoryExpiresAt).getTime()
|
|
22
|
-
: 0;
|
|
23
|
-
const lastStorySeenExpiresAt = params.lastStorySeenExpiresAt
|
|
24
|
-
? new Date(params.lastStorySeenExpiresAt).getTime()
|
|
25
|
-
: 0;
|
|
26
|
-
const localLastStoryExpires = cacheStoryExpireTime?.data
|
|
27
|
-
? new Date(cacheStoryExpireTime?.data).getTime()
|
|
28
|
-
: 0;
|
|
29
|
-
const localLastStorySeenExpiresAt = cacheStoreSeenTime?.data
|
|
30
|
-
? new Date(cacheStoreSeenTime?.data).getTime()
|
|
31
|
-
: 0;
|
|
32
|
-
|
|
33
|
-
const highestSeen = Math.max(lastStorySeenExpiresAt, localLastStorySeenExpiresAt);
|
|
34
|
-
|
|
35
|
-
const currentSyncingState = pullFromCache<Amity.SyncState>([
|
|
36
|
-
STORY_KEY_CACHE.SYNC_STATE,
|
|
37
|
-
params.targetId,
|
|
38
|
-
]);
|
|
39
|
-
|
|
40
|
-
if (currentSyncingState?.data) {
|
|
41
|
-
if ([Amity.SyncState.Syncing, Amity.SyncState.Error].includes(currentSyncingState.data)) {
|
|
42
|
-
return localLastStoryExpires > now && localLastStoryExpires > highestSeen;
|
|
43
|
-
}
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
return lastStoryExpiresAt > now && lastStoryExpiresAt > highestSeen;
|
|
47
|
-
};
|