@amityco/ts-sdk 6.17.1-e9b6af1.0 → 6.17.2-ea577e1.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 +1 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +5 -0
- package/dist/@types/core/permissions.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +1 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/story.d.ts +4 -0
- package/dist/@types/domains/story.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/client/api/createClient.d.ts.map +1 -1
- package/dist/client/observers/getTotalUnreadCount.d.ts.map +1 -1
- package/dist/client/observers/getUserUnread.d.ts.map +1 -1
- package/dist/client/utils/hasPermission/checkChannelPermission.d.ts +2 -0
- package/dist/client/utils/hasPermission/checkChannelPermission.d.ts.map +1 -0
- package/dist/client/utils/hasPermission/checkCommunityPermission.d.ts +2 -0
- package/dist/client/utils/hasPermission/checkCommunityPermission.d.ts.map +1 -0
- package/dist/client/utils/hasPermission/checkUserPermission.d.ts +2 -0
- package/dist/client/utils/hasPermission/checkUserPermission.d.ts.map +1 -0
- package/dist/client/utils/hasPermission/hasPermission.d.ts +6 -0
- package/dist/client/utils/hasPermission/hasPermission.d.ts.map +1 -0
- package/dist/client/utils/hasPermission/index.d.ts +2 -0
- package/dist/client/utils/hasPermission/index.d.ts.map +1 -0
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/index.cjs.js +510 -70
- package/dist/index.esm.js +510 -71
- package/dist/index.umd.js +4 -4
- package/dist/marker/api/getUserMarker.d.ts +1 -1
- package/dist/marker/api/getUserMarker.d.ts.map +1 -1
- package/dist/marker/events/onChannelMarkerFetched.d.ts.map +1 -1
- package/dist/marker/events/onUserMarkerFetched.d.ts +2 -1
- package/dist/marker/events/onUserMarkerFetched.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts +2 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/observeMessages.d.ts.map +1 -1
- package/dist/messageRepository/utils/prepareMessagePayload.d.ts.map +1 -1
- package/dist/storyRepository/constants.d.ts +1 -0
- package/dist/storyRepository/constants.d.ts.map +1 -1
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.d.ts +14 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryPaginationNoPageController.d.ts +5 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryPaginationNoPageController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryQueryStreamController.d.ts +16 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/StoryQueryStreamController.d.ts.map +1 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/getStoriesByTargetIds.d.ts +5 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/getStoriesByTargetIds.d.ts.map +1 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/index.d.ts +2 -0
- package/dist/storyRepository/observers/getStoriesByTargetIds/index.d.ts.map +1 -0
- package/dist/storyRepository/observers/index.d.ts +1 -0
- package/dist/storyRepository/observers/index.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannel.d.ts.map +1 -1
- package/dist/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +1 -0
- package/src/@types/core/permissions.ts +6 -0
- package/src/@types/domains/client.ts +2 -0
- package/src/@types/domains/story.ts +5 -0
- package/src/channelRepository/observers/getChannel.ts +30 -2
- package/src/channelRepository/observers/getChannels/ChannelLiveCollectionController.ts +65 -3
- package/src/client/api/createClient.ts +3 -1
- package/src/client/observers/getTotalUnreadCount.ts +14 -4
- package/src/client/observers/getUserUnread.ts +95 -11
- package/src/client/utils/hasPermission/checkChannelPermission.ts +22 -0
- package/src/client/utils/hasPermission/checkCommunityPermission.ts +22 -0
- package/src/client/utils/hasPermission/checkUserPermission.ts +12 -0
- package/src/client/utils/hasPermission/hasPermission.ts +18 -0
- package/src/client/utils/hasPermission/index.ts +1 -0
- package/src/client/utils/markerSyncEngine.ts +46 -32
- package/src/marker/api/getUserMarker.ts +15 -4
- package/src/marker/events/onChannelMarkerFetched.ts +3 -1
- package/src/marker/events/onUserMarkerFetched.ts +17 -0
- package/src/messageRepository/api/tests/createMessage.test.ts +4 -4
- package/src/messageRepository/events/onMessageCreated.ts +20 -8
- package/src/messageRepository/events/tests/events.test.ts +2 -2
- package/src/messageRepository/observers/getMessages/MessageLiveCollectionController.ts +2 -2
- package/src/messageRepository/observers/observeMessages.ts +8 -2
- package/src/messageRepository/utils/prepareMessagePayload.ts +14 -4
- package/src/storyRepository/constants.ts +1 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryLiveCollectionController.ts +113 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryPaginationNoPageController.ts +18 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/StoryQueryStreamController.ts +97 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/getStoriesByTargetIds.ts +32 -0
- package/src/storyRepository/observers/getStoriesByTargetIds/index.ts +1 -0
- package/src/storyRepository/observers/index.ts +1 -0
- package/src/subChannelRepository/observers/getSubChannel.ts +35 -2
- package/src/subChannelRepository/observers/getSubChannels/SubChannelLiveCollectionController.ts +53 -2
package/dist/index.esm.js
CHANGED
|
@@ -83,8 +83,8 @@ const PostContentType = Object.freeze({
|
|
|
83
83
|
|
|
84
84
|
function getVersion() {
|
|
85
85
|
try {
|
|
86
|
-
// the string ''v6.17.
|
|
87
|
-
return 'v6.17.
|
|
86
|
+
// the string ''v6.17.1-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
87
|
+
return 'v6.17.1-esm';
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
return '__dev__';
|
|
@@ -21916,7 +21916,14 @@ const getUserMarker = async () => {
|
|
|
21916
21916
|
if (client.cache)
|
|
21917
21917
|
ingestInCache({ userMarkers }, { cachedAt });
|
|
21918
21918
|
fireEvent('local.userMarker.fetched', { userMarkers });
|
|
21919
|
-
|
|
21919
|
+
const latestUserMarker = userMarkers.reduce((maxUserMarker, userMarker) => {
|
|
21920
|
+
if (maxUserMarker == null ||
|
|
21921
|
+
new Date(maxUserMarker.lastSyncAt).getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
21922
|
+
return userMarker;
|
|
21923
|
+
}
|
|
21924
|
+
return maxUserMarker;
|
|
21925
|
+
}, null);
|
|
21926
|
+
return { data: latestUserMarker, cachedAt };
|
|
21920
21927
|
};
|
|
21921
21928
|
|
|
21922
21929
|
/** @hidden */
|
|
@@ -22091,17 +22098,25 @@ const preUpdateMessageCache = (rawPayload) => {
|
|
|
22091
22098
|
messages: rawPayload.messages.map(message => convertFromRaw(message, rawPayload.reactions)),
|
|
22092
22099
|
});
|
|
22093
22100
|
};
|
|
22101
|
+
const DEBOUNCE_TIME = 2000;
|
|
22102
|
+
const currentDebounceMap = {};
|
|
22094
22103
|
const prepareMessagePayload = async (payload, event) => {
|
|
22095
22104
|
const markerIds = payload.messages.map(({ messageId }) => messageId);
|
|
22096
22105
|
if (markerIds.length > 0) {
|
|
22097
22106
|
// since the get markers method requires a channel cache to function with the reducer.
|
|
22098
22107
|
preUpdateMessageCache(payload);
|
|
22099
|
-
|
|
22100
|
-
|
|
22101
|
-
|
|
22102
|
-
catch (e) {
|
|
22103
|
-
// empty block (from the spec, allow marker fetch to fail without having to do anything)
|
|
22108
|
+
const markerIdsKey = markerIds.join('');
|
|
22109
|
+
if (currentDebounceMap[markerIdsKey]) {
|
|
22110
|
+
clearTimeout(currentDebounceMap[markerIdsKey]);
|
|
22104
22111
|
}
|
|
22112
|
+
currentDebounceMap[markerIdsKey] = setTimeout(() => {
|
|
22113
|
+
try {
|
|
22114
|
+
getMessageMarkers(markerIds);
|
|
22115
|
+
}
|
|
22116
|
+
catch (_error) {
|
|
22117
|
+
// do nothing
|
|
22118
|
+
}
|
|
22119
|
+
}, DEBOUNCE_TIME);
|
|
22105
22120
|
}
|
|
22106
22121
|
const { messageFeeds } = payload, restPayload = __rest(payload, ["messageFeeds"]);
|
|
22107
22122
|
// upsert messageFeeds to subchannel cache because messageFeeds from event payload not include messagePreviewId
|
|
@@ -22707,43 +22722,92 @@ const initializeMessagePreviewSetting = async () => {
|
|
|
22707
22722
|
|
|
22708
22723
|
/**
|
|
22709
22724
|
* ```js
|
|
22710
|
-
* import {
|
|
22711
|
-
* const
|
|
22712
|
-
* const postFeedSetting = feedSettings.post
|
|
22725
|
+
* import { getSocialSettings } from '@amityco/ts-sdk'
|
|
22726
|
+
* const socialSettings = await getSocialSettings()
|
|
22713
22727
|
* ```
|
|
22714
22728
|
*
|
|
22715
|
-
* Fetches a {@link Amity.
|
|
22729
|
+
* Fetches a {@link Amity.SocialSettings} object
|
|
22716
22730
|
*
|
|
22717
|
-
* @returns A Promise of {@link Amity.
|
|
22731
|
+
* @returns A Promise of {@link Amity.SocialSettings} object
|
|
22718
22732
|
*
|
|
22719
22733
|
* @category Client API
|
|
22720
22734
|
* @async
|
|
22721
22735
|
*/
|
|
22722
|
-
const
|
|
22736
|
+
const getSocialSettings = async () => {
|
|
22723
22737
|
const client = getActiveClient();
|
|
22724
|
-
const { data } = await client.http.get(`/api/v3/network-settings/
|
|
22725
|
-
return
|
|
22726
|
-
|
|
22727
|
-
|
|
22738
|
+
const { data } = await client.http.get(`/api/v3/network-settings/social`);
|
|
22739
|
+
return data.socialNetworkSetting;
|
|
22740
|
+
};
|
|
22741
|
+
|
|
22742
|
+
const checkUserPermission = (userId, permission) => {
|
|
22743
|
+
var _a;
|
|
22744
|
+
const user = (_a = pullFromCache(['users', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22745
|
+
if (!user)
|
|
22746
|
+
return false;
|
|
22747
|
+
return user.permissions.some(x => x === permission);
|
|
22748
|
+
};
|
|
22749
|
+
|
|
22750
|
+
const checkCommunityPermission = (userId, permission, communityId) => {
|
|
22751
|
+
var _a;
|
|
22752
|
+
if (!userId)
|
|
22753
|
+
return false;
|
|
22754
|
+
const member = (_a = pullFromCache([
|
|
22755
|
+
'communityUsers',
|
|
22756
|
+
'get',
|
|
22757
|
+
`${communityId}#${userId}`,
|
|
22758
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22759
|
+
if (!member)
|
|
22760
|
+
return false;
|
|
22761
|
+
if (member.permissions.some(x => x === permission))
|
|
22762
|
+
return true;
|
|
22763
|
+
return checkUserPermission(userId, permission);
|
|
22764
|
+
};
|
|
22765
|
+
|
|
22766
|
+
const checkChannelPermission = (userId, permission, channelId) => {
|
|
22767
|
+
var _a;
|
|
22768
|
+
if (!userId)
|
|
22769
|
+
return false;
|
|
22770
|
+
const member = (_a = pullFromCache([
|
|
22771
|
+
'channelUsers',
|
|
22772
|
+
'get',
|
|
22773
|
+
`${channelId}#${userId}`,
|
|
22774
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
22775
|
+
if (!member)
|
|
22776
|
+
return false;
|
|
22777
|
+
if (member.permissions.some(x => x === permission))
|
|
22778
|
+
return true;
|
|
22779
|
+
return checkUserPermission(userId, permission);
|
|
22780
|
+
};
|
|
22781
|
+
|
|
22782
|
+
const hasPermission$1 = (permission) => {
|
|
22783
|
+
const { userId } = getActiveClient();
|
|
22784
|
+
return {
|
|
22785
|
+
currentUser: () => checkUserPermission(userId, permission),
|
|
22786
|
+
community: (communityId) => checkCommunityPermission(userId, permission, communityId),
|
|
22787
|
+
channel: (channelId) => checkChannelPermission(userId, permission, channelId),
|
|
22788
|
+
};
|
|
22728
22789
|
};
|
|
22729
22790
|
|
|
22730
22791
|
/**
|
|
22731
22792
|
* ```js
|
|
22732
|
-
* import {
|
|
22733
|
-
* const
|
|
22793
|
+
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
22794
|
+
* const feedSettings = await getFeedSettings()
|
|
22795
|
+
* const postFeedSetting = feedSettings.post
|
|
22734
22796
|
* ```
|
|
22735
22797
|
*
|
|
22736
|
-
* Fetches a {@link Amity.
|
|
22798
|
+
* Fetches a {@link Amity.FeedSettings} object
|
|
22737
22799
|
*
|
|
22738
|
-
* @returns A Promise of {@link Amity.
|
|
22800
|
+
* @returns A Promise of {@link Amity.FeedSettings} object
|
|
22739
22801
|
*
|
|
22740
22802
|
* @category Client API
|
|
22741
22803
|
* @async
|
|
22742
22804
|
*/
|
|
22743
|
-
const
|
|
22805
|
+
const getFeedSettings = async () => {
|
|
22744
22806
|
const client = getActiveClient();
|
|
22745
|
-
const { data } = await client.http.get(`/api/v3/network-settings/
|
|
22746
|
-
return data.
|
|
22807
|
+
const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
|
|
22808
|
+
return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
|
|
22809
|
+
return [feedType, contentSettings];
|
|
22810
|
+
}));
|
|
22747
22811
|
};
|
|
22748
22812
|
|
|
22749
22813
|
/*
|
|
@@ -23448,6 +23512,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
23448
23512
|
sessionState,
|
|
23449
23513
|
accessTokenExpiryWatcher,
|
|
23450
23514
|
sessionHandler,
|
|
23515
|
+
hasPermission: hasPermission$1,
|
|
23451
23516
|
getFeedSettings,
|
|
23452
23517
|
getSocialSettings,
|
|
23453
23518
|
getMessagePreviewSetting,
|
|
@@ -23542,7 +23607,9 @@ const markerSync = async (deviceLastSyncAt) => {
|
|
|
23542
23607
|
const onChannelMarkerFetched = (callback) => {
|
|
23543
23608
|
const client = getActiveClient();
|
|
23544
23609
|
const filter = (payload) => {
|
|
23545
|
-
|
|
23610
|
+
payload.userEntityMarkers.forEach(marker => {
|
|
23611
|
+
callback(marker);
|
|
23612
|
+
});
|
|
23546
23613
|
};
|
|
23547
23614
|
return createEventSubscriber(client, 'channelMarker/onChannelMarkerFetched', 'local.channelMarker.fetched', filter);
|
|
23548
23615
|
};
|
|
@@ -23656,6 +23723,13 @@ const onFeedMarkerUpdated = (callback) => {
|
|
|
23656
23723
|
* @category UserMarker Events
|
|
23657
23724
|
*/
|
|
23658
23725
|
const onUserMarkerFetched = (callback) => {
|
|
23726
|
+
const client = getActiveClient();
|
|
23727
|
+
const filter = (payload) => {
|
|
23728
|
+
callback(payload.userMarkers);
|
|
23729
|
+
};
|
|
23730
|
+
return createEventSubscriber(client, 'userMarker/onUserMarkerFetched', 'local.userMarker.fetched', filter);
|
|
23731
|
+
};
|
|
23732
|
+
const onUserMarkerFetchedLegacy = (callback) => {
|
|
23659
23733
|
const client = getActiveClient();
|
|
23660
23734
|
const filter = (payload) => {
|
|
23661
23735
|
callback(payload.userMarkers[0]);
|
|
@@ -23911,7 +23985,10 @@ const getTotalUnreadCount = (callback) => {
|
|
|
23911
23985
|
if (!userId)
|
|
23912
23986
|
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
23913
23987
|
const callbackDataSelector = (data) => { var _a; return (_a = data === null || data === void 0 ? void 0 : data.unreadCount) !== null && _a !== void 0 ? _a : 0; };
|
|
23914
|
-
return liveObject(userId, callback, 'userId',
|
|
23988
|
+
return liveObject(userId, callback, 'userId', async () => {
|
|
23989
|
+
const { data: userMarker, cachedAt } = await getUserMarker();
|
|
23990
|
+
return { data: userMarker, cachedAt };
|
|
23991
|
+
}, [onUserMarkerFetchedLegacy], {
|
|
23915
23992
|
callbackDataSelector,
|
|
23916
23993
|
});
|
|
23917
23994
|
};
|
|
@@ -23937,16 +24014,77 @@ const getUserUnread = (callback) => {
|
|
|
23937
24014
|
const { _id: userId } = getActiveUser();
|
|
23938
24015
|
if (!userId)
|
|
23939
24016
|
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
23940
|
-
const
|
|
24017
|
+
const { log, cache } = getActiveClient();
|
|
24018
|
+
if (!cache) {
|
|
24019
|
+
console.log('For using Live Object feature you need to enable Cache!');
|
|
24020
|
+
}
|
|
24021
|
+
const timestamp = Date.now();
|
|
24022
|
+
log(`liveUserUnread(tmpid: ${timestamp}) > listen`);
|
|
24023
|
+
const disposers = [];
|
|
24024
|
+
let isUnsyncedModel = false; // for messages
|
|
24025
|
+
const dispatcher = (data) => {
|
|
24026
|
+
const userUnread = data.data;
|
|
24027
|
+
callback({
|
|
24028
|
+
data: {
|
|
24029
|
+
hasMentioned: userUnread.hasMentioned,
|
|
24030
|
+
unreadCount: userUnread.unreadCount,
|
|
24031
|
+
},
|
|
24032
|
+
loading: data.loading,
|
|
24033
|
+
error: data.error,
|
|
24034
|
+
});
|
|
24035
|
+
};
|
|
24036
|
+
const realtimeRouter = (userMarkers) => {
|
|
23941
24037
|
var _a;
|
|
23942
|
-
|
|
23943
|
-
|
|
23944
|
-
|
|
23945
|
-
|
|
24038
|
+
const filterUserMarkers = userMarkers.filter(userMarker => userId === userMarker.userId);
|
|
24039
|
+
const latestUserMarker = filterUserMarkers.reduce((currentMaxUserMarker, userMarker) => {
|
|
24040
|
+
if (currentMaxUserMarker == null ||
|
|
24041
|
+
new Date(userMarker.lastSyncAt).getTime() >
|
|
24042
|
+
new Date(currentMaxUserMarker.lastSyncAt).getTime()) {
|
|
24043
|
+
return userMarker;
|
|
24044
|
+
}
|
|
24045
|
+
return currentMaxUserMarker;
|
|
24046
|
+
}, null);
|
|
24047
|
+
dispatcher({
|
|
24048
|
+
loading: false,
|
|
24049
|
+
data: {
|
|
24050
|
+
unreadCount: (_a = latestUserMarker === null || latestUserMarker === void 0 ? void 0 : latestUserMarker.unreadCount) !== null && _a !== void 0 ? _a : 0,
|
|
24051
|
+
hasMentioned: filterUserMarkers.some(userMarker => !!userMarker.hasMentioned),
|
|
24052
|
+
},
|
|
24053
|
+
});
|
|
24054
|
+
};
|
|
24055
|
+
function isAmityUserMarkerData(data) {
|
|
24056
|
+
if (data == null)
|
|
24057
|
+
return false;
|
|
24058
|
+
return data.data != null;
|
|
24059
|
+
}
|
|
24060
|
+
const onFetch = () => {
|
|
24061
|
+
const query = createQuery(getUserMarker);
|
|
24062
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
24063
|
+
if (!isAmityUserMarkerData(data))
|
|
24064
|
+
return;
|
|
24065
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
24066
|
+
dispatcher({
|
|
24067
|
+
data,
|
|
24068
|
+
origin,
|
|
24069
|
+
loading: false,
|
|
24070
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
24071
|
+
});
|
|
24072
|
+
isUnsyncedModel = true;
|
|
24073
|
+
disposers.forEach(fn => fn());
|
|
24074
|
+
}
|
|
24075
|
+
else if (!isUnsyncedModel) {
|
|
24076
|
+
dispatcher({ loading, data, origin, error });
|
|
24077
|
+
}
|
|
24078
|
+
if (error) {
|
|
24079
|
+
disposers.forEach(fn => fn());
|
|
24080
|
+
}
|
|
24081
|
+
});
|
|
24082
|
+
};
|
|
24083
|
+
disposers.push(onUserMarkerFetched(userMarkers => realtimeRouter(userMarkers)));
|
|
24084
|
+
onFetch();
|
|
24085
|
+
return () => {
|
|
24086
|
+
disposers.forEach(fn => fn());
|
|
23946
24087
|
};
|
|
23947
|
-
return liveObject(userId, callback, 'userId', getUserMarker, [onUserMarkerFetched], {
|
|
23948
|
-
callbackDataSelector,
|
|
23949
|
-
});
|
|
23950
24088
|
};
|
|
23951
24089
|
|
|
23952
24090
|
/**
|
|
@@ -24257,21 +24395,30 @@ const onUserMarkerSync = (callback) => {
|
|
|
24257
24395
|
*
|
|
24258
24396
|
* @category Message Events
|
|
24259
24397
|
*/
|
|
24260
|
-
const
|
|
24398
|
+
const onMessageCreatedMqtt = (callback) => {
|
|
24261
24399
|
const client = getActiveClient();
|
|
24262
24400
|
const filter = async (rawPayload) => {
|
|
24263
24401
|
const payload = await prepareMessagePayload(rawPayload);
|
|
24264
|
-
const message = payload.messages[0];
|
|
24265
24402
|
// Update in cache
|
|
24266
24403
|
ingestInCache(payload);
|
|
24267
|
-
|
|
24404
|
+
payload.messages.forEach(message => {
|
|
24405
|
+
callback(message);
|
|
24406
|
+
});
|
|
24268
24407
|
};
|
|
24269
24408
|
const disposers = [
|
|
24270
24409
|
createEventSubscriber(client, 'message/onMessageCreated', 'message.created', filter),
|
|
24271
24410
|
];
|
|
24272
|
-
|
|
24273
|
-
|
|
24274
|
-
}
|
|
24411
|
+
return () => {
|
|
24412
|
+
disposers.forEach(fn => fn());
|
|
24413
|
+
};
|
|
24414
|
+
};
|
|
24415
|
+
const onMessageCreatedLocal = (callback) => {
|
|
24416
|
+
const client = getActiveClient();
|
|
24417
|
+
const disposers = [
|
|
24418
|
+
createEventSubscriber(client, 'message/onMessageCreated', 'local.message.created', payload => payload.messages.forEach(message => {
|
|
24419
|
+
callback(message);
|
|
24420
|
+
})),
|
|
24421
|
+
];
|
|
24275
24422
|
return () => {
|
|
24276
24423
|
disposers.forEach(fn => fn());
|
|
24277
24424
|
};
|
|
@@ -24585,18 +24732,22 @@ let isWaitingForResponse = false;
|
|
|
24585
24732
|
let deviceLastSyncAt = null;
|
|
24586
24733
|
const getDeviceLastSyncAt = () => {
|
|
24587
24734
|
if (deviceLastSyncAt == null) {
|
|
24588
|
-
return new Date()
|
|
24735
|
+
return new Date();
|
|
24589
24736
|
}
|
|
24590
24737
|
return deviceLastSyncAt;
|
|
24591
24738
|
};
|
|
24592
24739
|
const saveDeviceLastSyncAt = (lastSyncAt) => {
|
|
24593
|
-
if (
|
|
24740
|
+
if (lastSyncAt == null)
|
|
24741
|
+
return;
|
|
24742
|
+
if (!deviceLastSyncAt || lastSyncAt.getTime() > deviceLastSyncAt.getTime()) {
|
|
24594
24743
|
deviceLastSyncAt = lastSyncAt;
|
|
24595
24744
|
}
|
|
24596
24745
|
};
|
|
24597
24746
|
const fetchDeviceLastSyncAt = async () => {
|
|
24598
24747
|
const { data: userMarker } = await getUserMarker();
|
|
24599
|
-
|
|
24748
|
+
if (userMarker == null)
|
|
24749
|
+
return;
|
|
24750
|
+
saveDeviceLastSyncAt(new Date(userMarker.lastSyncAt));
|
|
24600
24751
|
};
|
|
24601
24752
|
/**
|
|
24602
24753
|
* list of conditions that make timer still trigger the syncing process.
|
|
@@ -24634,18 +24785,33 @@ const markerSyncTrigger = async () => {
|
|
|
24634
24785
|
// no event that require to call marker sync API
|
|
24635
24786
|
return;
|
|
24636
24787
|
}
|
|
24637
|
-
|
|
24638
|
-
|
|
24639
|
-
|
|
24640
|
-
|
|
24641
|
-
|
|
24642
|
-
|
|
24643
|
-
|
|
24644
|
-
|
|
24645
|
-
|
|
24646
|
-
|
|
24647
|
-
|
|
24648
|
-
|
|
24788
|
+
try {
|
|
24789
|
+
isWaitingForResponse = true;
|
|
24790
|
+
// any past events are considered processed here.
|
|
24791
|
+
// however during waiting for the response, RTE could add the new message event;
|
|
24792
|
+
// which will make the engine trigger another call next round.
|
|
24793
|
+
events = [];
|
|
24794
|
+
const response = await markerSync(getDeviceLastSyncAt().toISOString());
|
|
24795
|
+
const latestLastSyncAt = response.data.userMarkers.reduce((maxLastSyncAt, userMarker) => {
|
|
24796
|
+
if (maxLastSyncAt == null ||
|
|
24797
|
+
maxLastSyncAt.getTime() < new Date(userMarker.lastSyncAt).getTime()) {
|
|
24798
|
+
return new Date(userMarker.lastSyncAt);
|
|
24799
|
+
}
|
|
24800
|
+
return maxLastSyncAt;
|
|
24801
|
+
}, null);
|
|
24802
|
+
saveDeviceLastSyncAt(latestLastSyncAt);
|
|
24803
|
+
if (response.hasMore) {
|
|
24804
|
+
events.push("has_more" /* Amity.MarkerSyncEvent.HAS_MORE */);
|
|
24805
|
+
}
|
|
24806
|
+
}
|
|
24807
|
+
catch (_a) {
|
|
24808
|
+
// prevent sync from stopping
|
|
24809
|
+
}
|
|
24810
|
+
finally {
|
|
24811
|
+
if (isWaitingForResponse) {
|
|
24812
|
+
isWaitingForResponse = false;
|
|
24813
|
+
}
|
|
24814
|
+
}
|
|
24649
24815
|
};
|
|
24650
24816
|
const registerEventListeners = () => {
|
|
24651
24817
|
if (disposers.length > 0) {
|
|
@@ -24659,14 +24825,11 @@ const registerEventListeners = () => {
|
|
|
24659
24825
|
disposers.push(onOnline(() => {
|
|
24660
24826
|
// should add RESUME to the event to trigger marker syncing again
|
|
24661
24827
|
events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
|
|
24662
|
-
}),
|
|
24828
|
+
}), onMessageCreatedMqtt(message => {
|
|
24663
24829
|
// only conversation, community and broadcast types can sync
|
|
24664
24830
|
if (isUnreadCountSupport(message))
|
|
24665
24831
|
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
24666
|
-
},
|
|
24667
|
-
// only trigger sync from remote events to prevent an unread count equal `-1`
|
|
24668
|
-
// when an optimistic message creation is performed.
|
|
24669
|
-
false), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
24832
|
+
}), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
24670
24833
|
/*
|
|
24671
24834
|
workaround: when receiving the event for sub-channel deletion,
|
|
24672
24835
|
before triggering marker update, the SDK will have to add a 2-second delay.
|
|
@@ -29207,7 +29370,26 @@ const getChannel = (channelId, callback) => {
|
|
|
29207
29370
|
});
|
|
29208
29371
|
callback(message);
|
|
29209
29372
|
};
|
|
29210
|
-
return
|
|
29373
|
+
return onMessageCreatedMqtt(updateMessagePreview);
|
|
29374
|
+
}, 'channelId', 'channel'),
|
|
29375
|
+
convertEventPayload((callback) => {
|
|
29376
|
+
const updateMessagePreview = async (message) => {
|
|
29377
|
+
var _a;
|
|
29378
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
29379
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
29380
|
+
return;
|
|
29381
|
+
await handleMessageCreated(message);
|
|
29382
|
+
if (message.channelId !== channelId)
|
|
29383
|
+
return;
|
|
29384
|
+
const channel = (_a = pullFromCache(['channel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29385
|
+
if (!channel)
|
|
29386
|
+
return;
|
|
29387
|
+
updateChannelCache(channel, {
|
|
29388
|
+
messagePreviewId: message.messageId,
|
|
29389
|
+
});
|
|
29390
|
+
callback(message);
|
|
29391
|
+
};
|
|
29392
|
+
return onMessageCreatedLocal(updateMessagePreview);
|
|
29211
29393
|
}, 'channelId', 'channel'),
|
|
29212
29394
|
convertEventPayload((callback) => {
|
|
29213
29395
|
const updateMessagePreview = async (message) => {
|
|
@@ -29646,7 +29828,27 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
29646
29828
|
{
|
|
29647
29829
|
// TODO: merge this code to another onMessageCreated in this file
|
|
29648
29830
|
fn: convertEventPayload((callback) => {
|
|
29649
|
-
return
|
|
29831
|
+
return onMessageCreatedMqtt(message => {
|
|
29832
|
+
var _a;
|
|
29833
|
+
const cacheData = (_a = pullFromCache([
|
|
29834
|
+
'channel',
|
|
29835
|
+
'get',
|
|
29836
|
+
message.channelId,
|
|
29837
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29838
|
+
if (!cacheData)
|
|
29839
|
+
return;
|
|
29840
|
+
updateChannelCache(cacheData, {
|
|
29841
|
+
lastActivity: message.createdAt,
|
|
29842
|
+
});
|
|
29843
|
+
callback(message);
|
|
29844
|
+
});
|
|
29845
|
+
}, 'messageId', 'channel'),
|
|
29846
|
+
action: 'onUpdate',
|
|
29847
|
+
},
|
|
29848
|
+
{
|
|
29849
|
+
// TODO: merge this code to another onMessageCreated in this file
|
|
29850
|
+
fn: convertEventPayload((callback) => {
|
|
29851
|
+
return onMessageCreatedLocal(message => {
|
|
29650
29852
|
var _a;
|
|
29651
29853
|
const cacheData = (_a = pullFromCache([
|
|
29652
29854
|
'channel',
|
|
@@ -29700,7 +29902,33 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
29700
29902
|
});
|
|
29701
29903
|
callback(message);
|
|
29702
29904
|
};
|
|
29703
|
-
return
|
|
29905
|
+
return onMessageCreatedMqtt(updateMessagePreview);
|
|
29906
|
+
}, 'channelId', 'channel'),
|
|
29907
|
+
action: 'onUpdate',
|
|
29908
|
+
},
|
|
29909
|
+
{
|
|
29910
|
+
fn: convertEventPayload((callback) => {
|
|
29911
|
+
const updateMessagePreview = async (message) => {
|
|
29912
|
+
var _a;
|
|
29913
|
+
const messagePreviewSetting = await ChannelLiveCollectionController.getMessagePreviewSetting();
|
|
29914
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
29915
|
+
return;
|
|
29916
|
+
handleMessageCreated(message);
|
|
29917
|
+
if (this.shouldAbort(message.channelId))
|
|
29918
|
+
return;
|
|
29919
|
+
const channel = (_a = pullFromCache([
|
|
29920
|
+
'channel',
|
|
29921
|
+
'get',
|
|
29922
|
+
message.channelId,
|
|
29923
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
29924
|
+
if (!channel)
|
|
29925
|
+
return;
|
|
29926
|
+
updateChannelCache(channel, {
|
|
29927
|
+
messagePreviewId: message.messageId,
|
|
29928
|
+
});
|
|
29929
|
+
callback(message);
|
|
29930
|
+
};
|
|
29931
|
+
return onMessageCreatedLocal(updateMessagePreview);
|
|
29704
29932
|
}, 'channelId', 'channel'),
|
|
29705
29933
|
action: 'onUpdate',
|
|
29706
29934
|
},
|
|
@@ -31202,7 +31430,7 @@ class MessageLiveCollectionController extends LiveCollectionController {
|
|
|
31202
31430
|
}
|
|
31203
31431
|
startSubscription() {
|
|
31204
31432
|
return this.queryStreamController.subscribeRTE([
|
|
31205
|
-
{ fn:
|
|
31433
|
+
{ fn: onMessageCreatedMqtt, action: 'onCreate' },
|
|
31206
31434
|
{ fn: onMessageDeleted, action: 'onDelete' },
|
|
31207
31435
|
{ fn: onMessageUpdated, action: 'onUpdate' },
|
|
31208
31436
|
{ fn: onMessageFlagged, action: 'onFlagged' },
|
|
@@ -31401,7 +31629,7 @@ const observeMessages = (subChannelId, callback) => {
|
|
|
31401
31629
|
(_b = callback.onEvent) === null || _b === void 0 ? void 0 : _b.call(callback, action, message);
|
|
31402
31630
|
(_c = callback[action]) === null || _c === void 0 ? void 0 : _c.call(callback, message);
|
|
31403
31631
|
};
|
|
31404
|
-
disposers.push(
|
|
31632
|
+
disposers.push(onMessageCreatedMqtt(data => router({ data, loading: false, origin: 'event' }, 'onCreate')), onMessageCreatedLocal(data => router({ data, loading: false, origin: 'event' }, 'onCreate')), onMessageUpdated(data => router({ data, loading: false, origin: 'event' }, 'onUpdate')), onMessageDeleted(data => router({ data, loading: false, origin: 'event' }, 'onDelete')), convertEventPayload(onMessageMarkerFetched, 'contentId', 'message')(data => router({ data, loading: false, origin: 'event' }, 'onCreate')), convertEventPayload(onMessageMarked, 'contentId', 'message')(data => router({ data, loading: false, origin: 'event' }, 'onCreate')));
|
|
31405
31633
|
return () => {
|
|
31406
31634
|
log(`observeMessages(tmpid: ${timestamp}) > dispose`);
|
|
31407
31635
|
disposers.forEach(fn => fn());
|
|
@@ -31422,7 +31650,8 @@ var index$c = /*#__PURE__*/Object.freeze({
|
|
|
31422
31650
|
flagMessage: flagMessage,
|
|
31423
31651
|
unflagMessage: unflagMessage,
|
|
31424
31652
|
isMessageFlaggedByMe: isMessageFlaggedByMe,
|
|
31425
|
-
|
|
31653
|
+
onMessageCreatedMqtt: onMessageCreatedMqtt,
|
|
31654
|
+
onMessageCreatedLocal: onMessageCreatedLocal,
|
|
31426
31655
|
onMessageUpdated: onMessageUpdated,
|
|
31427
31656
|
onMessageDeleted: onMessageDeleted,
|
|
31428
31657
|
onMessageFlagged: onMessageFlagged,
|
|
@@ -31690,7 +31919,30 @@ const getSubChannel = (subChannelId, callback) => {
|
|
|
31690
31919
|
});
|
|
31691
31920
|
callback(message);
|
|
31692
31921
|
};
|
|
31693
|
-
return
|
|
31922
|
+
return onMessageCreatedMqtt(updateMessagePreview);
|
|
31923
|
+
}, 'subChannelId', 'subChannel'),
|
|
31924
|
+
convertEventPayload((callback) => {
|
|
31925
|
+
const updateMessagePreview = async (message) => {
|
|
31926
|
+
var _a;
|
|
31927
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
31928
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
31929
|
+
return;
|
|
31930
|
+
await handleMessageCreated(message);
|
|
31931
|
+
if (message.subChannelId !== subChannelId)
|
|
31932
|
+
return;
|
|
31933
|
+
const subChannel = (_a = pullFromCache([
|
|
31934
|
+
'subChannel',
|
|
31935
|
+
'get',
|
|
31936
|
+
subChannelId,
|
|
31937
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
31938
|
+
if (!subChannel)
|
|
31939
|
+
return;
|
|
31940
|
+
updateSubChannelCache(message.subChannelId, subChannel, {
|
|
31941
|
+
messagePreviewId: message.messageId,
|
|
31942
|
+
});
|
|
31943
|
+
callback(message);
|
|
31944
|
+
};
|
|
31945
|
+
return onMessageCreatedLocal(updateMessagePreview);
|
|
31694
31946
|
}, 'subChannelId', 'subChannel'),
|
|
31695
31947
|
convertEventPayload((callback) => {
|
|
31696
31948
|
const updateMessagePreview = async (message) => {
|
|
@@ -31855,7 +32107,42 @@ class SubChannelLiveCollectionController extends LiveCollectionController {
|
|
|
31855
32107
|
},
|
|
31856
32108
|
{
|
|
31857
32109
|
fn: callback => {
|
|
31858
|
-
return
|
|
32110
|
+
return onMessageCreatedMqtt(async (message) => {
|
|
32111
|
+
var _a, _b;
|
|
32112
|
+
const cacheData = pullFromCache([
|
|
32113
|
+
'subChannel',
|
|
32114
|
+
'get',
|
|
32115
|
+
message.subChannelId,
|
|
32116
|
+
]);
|
|
32117
|
+
if (!cacheData)
|
|
32118
|
+
return;
|
|
32119
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32120
|
+
if (!collection || !collection.data.includes(message.subChannelId))
|
|
32121
|
+
return;
|
|
32122
|
+
const client = getActiveClient();
|
|
32123
|
+
const messagePreviewSetting = await client.getMessagePreviewSetting(false);
|
|
32124
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
32125
|
+
return;
|
|
32126
|
+
handleMessageCreated(message);
|
|
32127
|
+
const subChannelCache = (_b = pullFromCache([
|
|
32128
|
+
'subChannel',
|
|
32129
|
+
'get',
|
|
32130
|
+
message.subChannelId,
|
|
32131
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
32132
|
+
if (!subChannelCache)
|
|
32133
|
+
return;
|
|
32134
|
+
updateSubChannelCache(message.subChannelId, subChannelCache, {
|
|
32135
|
+
lastActivity: message.createdAt,
|
|
32136
|
+
messagePreviewId: message.messageId,
|
|
32137
|
+
});
|
|
32138
|
+
callback(Object.assign(Object.assign({}, cacheData.data), { messagePreviewId: message.messageId, subChannelId: message.subChannelId, lastActivity: message.createdAt }));
|
|
32139
|
+
});
|
|
32140
|
+
},
|
|
32141
|
+
action: 'onUpdate',
|
|
32142
|
+
},
|
|
32143
|
+
{
|
|
32144
|
+
fn: callback => {
|
|
32145
|
+
return onMessageCreatedLocal(async (message) => {
|
|
31859
32146
|
var _a, _b;
|
|
31860
32147
|
const cacheData = pullFromCache([
|
|
31861
32148
|
'subChannel',
|
|
@@ -37494,6 +37781,157 @@ const getTargetsByTargetIds = (params, callback) => {
|
|
|
37494
37781
|
};
|
|
37495
37782
|
};
|
|
37496
37783
|
|
|
37784
|
+
class StoryQueryStreamController extends QueryStreamController {
|
|
37785
|
+
constructor(query, cacheKey, notifyChange, paginationController) {
|
|
37786
|
+
super(query, cacheKey);
|
|
37787
|
+
this.notifyChange = notifyChange;
|
|
37788
|
+
this.paginationController = paginationController;
|
|
37789
|
+
}
|
|
37790
|
+
// eslint-disable-next-line class-methods-use-this
|
|
37791
|
+
saveToMainDB(response) {
|
|
37792
|
+
const client = getActiveClient();
|
|
37793
|
+
const cachedAt = client.cache && Date.now();
|
|
37794
|
+
const convertedData = convertStoryRawToInternal(response);
|
|
37795
|
+
if (client.cache) {
|
|
37796
|
+
ingestInCache(convertedData, { cachedAt });
|
|
37797
|
+
// Update local last story expires
|
|
37798
|
+
updateLocalLastStoryExpires(convertedData.stories);
|
|
37799
|
+
// Map storyId to referenceId
|
|
37800
|
+
mappingStoryIdToReferenceId(convertedData.stories);
|
|
37801
|
+
}
|
|
37802
|
+
}
|
|
37803
|
+
// eslint-disable-next-line class-methods-use-this
|
|
37804
|
+
getStoryReferenceIds(story) {
|
|
37805
|
+
if (story === null || story === void 0 ? void 0 : story.referenceId) {
|
|
37806
|
+
return story.referenceId;
|
|
37807
|
+
}
|
|
37808
|
+
return story.storyId;
|
|
37809
|
+
}
|
|
37810
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37811
|
+
var _a, _b;
|
|
37812
|
+
if (refresh) {
|
|
37813
|
+
pushToCache(this.cacheKey, {
|
|
37814
|
+
data: response.stories.map(this.getStoryReferenceIds),
|
|
37815
|
+
});
|
|
37816
|
+
}
|
|
37817
|
+
else {
|
|
37818
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37819
|
+
const stories = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37820
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...stories, ...response.stories.map(this.getStoryReferenceIds)])] }));
|
|
37821
|
+
}
|
|
37822
|
+
}
|
|
37823
|
+
reactor(action) {
|
|
37824
|
+
return (payload) => {
|
|
37825
|
+
var _a;
|
|
37826
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37827
|
+
if (!collection)
|
|
37828
|
+
return;
|
|
37829
|
+
const newReferenceIds = payload.map(({ referenceId }) => referenceId);
|
|
37830
|
+
collection.data = [...new Set([...newReferenceIds, ...collection.data])];
|
|
37831
|
+
pushToCache(this.cacheKey, collection);
|
|
37832
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37833
|
+
};
|
|
37834
|
+
}
|
|
37835
|
+
subscribeRTE(createSubscriber) {
|
|
37836
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37837
|
+
}
|
|
37838
|
+
}
|
|
37839
|
+
|
|
37840
|
+
/* eslint-disable no-use-before-define */
|
|
37841
|
+
class StoryPaginationNoPageController extends PaginationNoPageController {
|
|
37842
|
+
async getRequest(queryParams) {
|
|
37843
|
+
const { data: queryResponse } = await this.http.get('/api/v4/stories-by-targets', {
|
|
37844
|
+
params: Object.assign({}, queryParams),
|
|
37845
|
+
});
|
|
37846
|
+
return queryResponse;
|
|
37847
|
+
}
|
|
37848
|
+
}
|
|
37849
|
+
|
|
37850
|
+
class StoryLiveCollectionController extends LiveCollectionController {
|
|
37851
|
+
constructor(query, callback) {
|
|
37852
|
+
const queryStreamId = hash(query);
|
|
37853
|
+
const cacheKey = ["story-target-ids" /* STORY_KEY_CACHE.STORY_TARGET_IDS */, 'collection', queryStreamId];
|
|
37854
|
+
const paginationController = new StoryPaginationNoPageController(query);
|
|
37855
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37856
|
+
this.query = query;
|
|
37857
|
+
this.queryStreamController = new StoryQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
37858
|
+
this.paginationController = paginationController;
|
|
37859
|
+
this.callback = callback.bind(this);
|
|
37860
|
+
this.loadPage(true);
|
|
37861
|
+
}
|
|
37862
|
+
setup() {
|
|
37863
|
+
var _a;
|
|
37864
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37865
|
+
if (!collection) {
|
|
37866
|
+
pushToCache(this.cacheKey, {
|
|
37867
|
+
data: [],
|
|
37868
|
+
params: {},
|
|
37869
|
+
});
|
|
37870
|
+
}
|
|
37871
|
+
}
|
|
37872
|
+
persistModel(response) {
|
|
37873
|
+
this.queryStreamController.saveToMainDB(response);
|
|
37874
|
+
}
|
|
37875
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37876
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37877
|
+
}
|
|
37878
|
+
notifyChange({ origin, loading, error }) {
|
|
37879
|
+
var _a;
|
|
37880
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37881
|
+
if (!collection)
|
|
37882
|
+
return;
|
|
37883
|
+
let data = collection.data
|
|
37884
|
+
.map(referenceId => pullFromCache(["story" /* STORY_KEY_CACHE.STORY */, 'get', referenceId]))
|
|
37885
|
+
.filter(Boolean)
|
|
37886
|
+
.map(internStory => LinkedObject.story(internStory.data));
|
|
37887
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37888
|
+
return;
|
|
37889
|
+
data = this.applyFilter(data);
|
|
37890
|
+
this.callback({
|
|
37891
|
+
onNextPage: undefined,
|
|
37892
|
+
data,
|
|
37893
|
+
hasNextPage: false,
|
|
37894
|
+
loading,
|
|
37895
|
+
error,
|
|
37896
|
+
});
|
|
37897
|
+
}
|
|
37898
|
+
applyFilter(data) {
|
|
37899
|
+
var _a, _b;
|
|
37900
|
+
const internalStories = data;
|
|
37901
|
+
const orderBy = ((_b = (_a = this.query) === null || _a === void 0 ? void 0 : _a.options) === null || _b === void 0 ? void 0 : _b.orderBy) || 'desc';
|
|
37902
|
+
return orderBy === 'asc'
|
|
37903
|
+
? internalStories.sort(sortByFirstCreated)
|
|
37904
|
+
: internalStories.sort(sortByLastCreated);
|
|
37905
|
+
}
|
|
37906
|
+
startSubscription() {
|
|
37907
|
+
return this.queryStreamController.subscribeRTE([
|
|
37908
|
+
{ fn: onStoryCreated, action: "onCreate" /* Amity.StoryActionType.OnCreate */ },
|
|
37909
|
+
{ fn: onStoryUpdated, action: "onUpdate" /* Amity.StoryActionType.OnUpdate */ },
|
|
37910
|
+
{ fn: onStoryDeleted, action: "onDelete" /* Amity.StoryActionType.OnDelete */ },
|
|
37911
|
+
{ fn: onStoryError, action: "onError" /* Amity.StoryActionType.OnError */ },
|
|
37912
|
+
]);
|
|
37913
|
+
}
|
|
37914
|
+
}
|
|
37915
|
+
|
|
37916
|
+
const getStoriesByTargetIds = (params, callback, config) => {
|
|
37917
|
+
const { log, cache, userId } = getActiveClient();
|
|
37918
|
+
if (!cache) {
|
|
37919
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37920
|
+
}
|
|
37921
|
+
const timestamp = Date.now();
|
|
37922
|
+
log(`getStoriesByTargetIds(tmpid: ${timestamp}) > listen`);
|
|
37923
|
+
const storyLiveCollection = new StoryLiveCollectionController(params, callback);
|
|
37924
|
+
const disposers = storyLiveCollection.startSubscription();
|
|
37925
|
+
const cacheKey = storyLiveCollection.getCacheKey();
|
|
37926
|
+
disposers.push(() => {
|
|
37927
|
+
dropFromCache(cacheKey);
|
|
37928
|
+
});
|
|
37929
|
+
return () => {
|
|
37930
|
+
log(`getStoriesByTargetIds(tmpid: ${timestamp}) > dispose`);
|
|
37931
|
+
disposers.forEach(fn => fn());
|
|
37932
|
+
};
|
|
37933
|
+
};
|
|
37934
|
+
|
|
37497
37935
|
var index = /*#__PURE__*/Object.freeze({
|
|
37498
37936
|
__proto__: null,
|
|
37499
37937
|
createImageStory: createImageStory,
|
|
@@ -37503,7 +37941,8 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
37503
37941
|
getActiveStoriesByTarget: getActiveStoriesByTarget,
|
|
37504
37942
|
getStoryByStoryId: getStoryByStoryId,
|
|
37505
37943
|
getTargetById: getTargetById,
|
|
37506
|
-
getTargetsByTargetIds: getTargetsByTargetIds
|
|
37944
|
+
getTargetsByTargetIds: getTargetsByTargetIds,
|
|
37945
|
+
getStoriesByTargetIds: getStoriesByTargetIds
|
|
37507
37946
|
});
|
|
37508
37947
|
|
|
37509
37948
|
/**
|
|
@@ -37528,4 +37967,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
37528
37967
|
return { accessToken: data.accessToken };
|
|
37529
37968
|
};
|
|
37530
37969
|
|
|
37531
|
-
export { API_REGIONS, index$7 as CategoryRepository, index$d as ChannelRepository, index$k as Client, index$4 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$8 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$6 as FeedRepository, index$h as FileRepository, FileType, index$1 as LiveStreamPlayer, MessageContentType, index$c as MessageRepository, index$2 as PollRepository, PostContentType, index$5 as PostRepository, index$g as ReactionRepository, index as StoryRepository, index$3 as StreamRepository, index$b as SubChannelRepository, SubscriptionLevels, index$i as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityTopic, getMarkedMessageTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
37970
|
+
export { API_REGIONS, index$7 as CategoryRepository, index$d as ChannelRepository, index$k as Client, index$4 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$8 as CommunityRepository, ContentFeedType, DefaultCommunityPostSetting, index$6 as FeedRepository, index$h as FileRepository, FileType, index$1 as LiveStreamPlayer, MessageContentType, index$c as MessageRepository, index$2 as PollRepository, PostContentType, index$5 as PostRepository, index$g as ReactionRepository, index as StoryRepository, index$3 as StreamRepository, index$b as SubChannelRepository, SubscriptionLevels, index$i as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityTopic, getMarkedMessageTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|