@amityco/ts-sdk 6.29.2 → 6.29.3-9895419.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +17 -6
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +8 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +5 -4
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +32 -8
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +13 -7
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/pin.d.ts +22 -0
- package/dist/@types/domains/pin.d.ts.map +1 -0
- package/dist/@types/domains/pinnedPost.d.ts +28 -0
- package/dist/@types/domains/pinnedPost.d.ts.map +1 -0
- package/dist/@types/domains/poll.d.ts +3 -1
- package/dist/@types/domains/poll.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +6 -5
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +2 -1
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +34 -6
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts +3 -2
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberPaginationController.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts +14 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/index.d.ts +2 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/index.d.ts.map +1 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts +21 -0
- package/dist/channelRepository/channelMembership/observers/searchMembers/searchMembers.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelPaginationController.d.ts +3 -3
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/channelRepository/utils/tests/prepareChannelPayload.test.d.ts +1 -1
- package/dist/channelRepository/utils/tests/prepareChannelPayload.test.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +2 -6
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/group/utils/withUser.d.ts +13 -0
- package/dist/group/utils/withUser.d.ts.map +1 -1
- package/dist/index.cjs.js +957 -614
- package/dist/index.esm.js +880 -537
- package/dist/index.umd.js +4 -4
- package/dist/pollRepository/observers/observePoll.d.ts +1 -1
- package/dist/pollRepository/observers/observePoll.d.ts.map +1 -1
- package/dist/postRepository/internalApi/index.d.ts +1 -12
- package/dist/postRepository/internalApi/index.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts +14 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.d.ts +13 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +9 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -0
- package/dist/postRepository/observers/getPinnedPosts.d.ts +12 -0
- package/dist/postRepository/observers/getPinnedPosts.d.ts.map +1 -0
- package/dist/postRepository/observers/index.d.ts +1 -0
- package/dist/postRepository/observers/index.d.ts.map +1 -1
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts +1 -2
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts +1 -2
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/report/api/isReportedByMe.d.ts +1 -2
- package/dist/report/api/isReportedByMe.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -1
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUserByIds.d.ts.map +1 -1
- package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/api/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
- package/dist/userRepository/api/updateUser.d.ts.map +1 -1
- package/dist/userRepository/events/utils.d.ts.map +1 -1
- package/dist/userRepository/internalApi/getUser.d.ts.map +1 -1
- package/dist/userRepository/internalApi/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/enums.d.ts +8 -0
- package/dist/userRepository/observers/enums.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/getUsers/UserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getUsers/UserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/getUsers/UserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getUsers.d.ts +0 -1
- package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts +14 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts +5 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts +15 -0
- package/dist/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -1
- package/dist/userRepository/utils/index.d.ts +3 -0
- package/dist/userRepository/utils/index.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +2 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/pinnedPostLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/pinnedPostLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/channel.d.ts +12 -12
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -2
- package/dist/utils/tests/dummy/user.d.ts +10 -2
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/payload.ts +17 -7
- package/src/@types/domains/channel.ts +13 -0
- package/src/@types/domains/comment.ts +6 -4
- package/src/@types/domains/community.ts +40 -12
- package/src/@types/domains/group.ts +14 -6
- package/src/@types/domains/pin.ts +27 -0
- package/src/@types/domains/pinnedPost.ts +35 -0
- package/src/@types/domains/poll.ts +5 -1
- package/src/@types/domains/post.ts +7 -5
- package/src/@types/domains/stream.ts +3 -1
- package/src/@types/domains/user.ts +49 -6
- package/src/channelRepository/channelMembership/observers/getMembers/ChannelMemberLiveCollectionController.ts +6 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberLiveCollectionController.ts +142 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberPaginationController.ts +28 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/SearchChannelMemberQueryStreamController.ts +112 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/index.ts +1 -0
- package/src/channelRepository/channelMembership/observers/searchMembers/searchMembers.ts +111 -0
- package/src/channelRepository/utils/prepareChannelPayload.ts +8 -4
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +6 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +6 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +3 -3
- package/src/communityRepository/utils/payload.ts +23 -58
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/index.ts +3 -0
- package/src/group/utils/withUser.ts +33 -0
- package/src/postRepository/internalApi/index.ts +1 -16
- package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +104 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostPaginationController.ts +23 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +61 -0
- package/src/postRepository/observers/getPinnedPosts.ts +41 -0
- package/src/postRepository/observers/index.ts +1 -0
- package/src/postRepository/utils/payload.ts +23 -7
- package/src/report/api/createReport.ts +100 -31
- package/src/report/api/deleteReport.ts +100 -31
- package/src/report/api/isReportedByMe.ts +72 -11
- package/src/userRepository/api/flagUser.ts +5 -2
- package/src/userRepository/api/getUser.ts +4 -43
- package/src/userRepository/api/getUserByIds.ts +5 -2
- package/src/userRepository/api/queryBlockedUsers.ts +6 -6
- package/src/userRepository/api/queryUsers.ts +11 -87
- package/src/userRepository/api/unflagUser.ts +5 -2
- package/src/userRepository/api/updateUser.ts +5 -11
- package/src/userRepository/events/utils.ts +4 -1
- package/src/userRepository/internalApi/getUser.ts +12 -16
- package/src/userRepository/internalApi/queryUsers.ts +7 -4
- package/src/userRepository/observers/enums.ts +7 -0
- package/src/userRepository/observers/getUsers/UserLiveCollectionController.ts +131 -0
- package/src/userRepository/observers/getUsers/UserPaginationController.ts +25 -0
- package/src/userRepository/observers/getUsers/UserQueryStreamController.ts +82 -0
- package/src/userRepository/observers/getUsers.ts +7 -137
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserLiveCollectionController.ts +116 -0
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserPaginationController.ts +25 -0
- package/src/userRepository/observers/searchUserByDisplayName/SearchUserQueryStreamController.ts +82 -0
- package/src/userRepository/observers/searchUserByDisplayName.ts +25 -1
- package/src/userRepository/utils/index.ts +13 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/pinnedPostLinkedObject.ts +28 -0
package/dist/index.cjs.js
CHANGED
|
@@ -540,6 +540,8 @@ const idResolvers = {
|
|
|
540
540
|
storyTarget: ({ targetId }) => targetId,
|
|
541
541
|
ad: ({ adId }) => adId,
|
|
542
542
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
543
|
+
pin: ({ referenceId }) => referenceId,
|
|
544
|
+
pinTarget: ({ targetId }) => targetId,
|
|
543
545
|
};
|
|
544
546
|
/**
|
|
545
547
|
* Retrieve the id resolver matching a domain name
|
|
@@ -589,6 +591,8 @@ const PAYLOAD2MODEL = {
|
|
|
589
591
|
feeds: 'feed',
|
|
590
592
|
ads: 'ad',
|
|
591
593
|
advertisers: 'advertiser',
|
|
594
|
+
pinTargets: 'pinTarget',
|
|
595
|
+
pins: 'pin',
|
|
592
596
|
};
|
|
593
597
|
/** hidden */
|
|
594
598
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -4715,6 +4719,31 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
4715
4719
|
return kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value), value;
|
|
4716
4720
|
}
|
|
4717
4721
|
|
|
4722
|
+
/**
|
|
4723
|
+
* Attach user object to membership model
|
|
4724
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
4725
|
+
* - If user object is not found in cache, set user to undefined
|
|
4726
|
+
* ({..., user: undefined})
|
|
4727
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
4728
|
+
* ({..., user: { userId, displayName,... }})
|
|
4729
|
+
*
|
|
4730
|
+
* @param member The membership model object
|
|
4731
|
+
* @returns The membership model object that is already mapped to user
|
|
4732
|
+
* @hidden
|
|
4733
|
+
*/
|
|
4734
|
+
const convertRawMembershipToMembership = (member) => {
|
|
4735
|
+
return Object.assign(Object.assign({}, member), { get user() {
|
|
4736
|
+
var _a;
|
|
4737
|
+
const client = getActiveClient();
|
|
4738
|
+
if (!client.cache)
|
|
4739
|
+
return undefined;
|
|
4740
|
+
const userCache = (_a = pullFromCache(['user', 'get', member.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4741
|
+
if (!userCache) {
|
|
4742
|
+
return undefined;
|
|
4743
|
+
}
|
|
4744
|
+
return userCache;
|
|
4745
|
+
} });
|
|
4746
|
+
};
|
|
4718
4747
|
/**
|
|
4719
4748
|
* Attach user object to membership model
|
|
4720
4749
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -5828,6 +5857,31 @@ const adLinkedObject = (ad) => {
|
|
|
5828
5857
|
} });
|
|
5829
5858
|
};
|
|
5830
5859
|
|
|
5860
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
5861
|
+
var _a;
|
|
5862
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
5863
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
5864
|
+
var _a;
|
|
5865
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
5866
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
5867
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
5868
|
+
get post() {
|
|
5869
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
5870
|
+
return;
|
|
5871
|
+
return postLinkedObject(postCached.data);
|
|
5872
|
+
},
|
|
5873
|
+
get target() {
|
|
5874
|
+
const pinTarget = pullFromCache([
|
|
5875
|
+
'pinTarget',
|
|
5876
|
+
'get',
|
|
5877
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
5878
|
+
]);
|
|
5879
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
5880
|
+
return;
|
|
5881
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
5882
|
+
} });
|
|
5883
|
+
};
|
|
5884
|
+
|
|
5831
5885
|
const LinkedObject = {
|
|
5832
5886
|
ad: adLinkedObject,
|
|
5833
5887
|
comment: commentLinkedObject,
|
|
@@ -5840,6 +5894,7 @@ const LinkedObject = {
|
|
|
5840
5894
|
message: messageLinkedObject,
|
|
5841
5895
|
reactor: reactorLinkedObject,
|
|
5842
5896
|
channel: channelLinkedObject,
|
|
5897
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
5843
5898
|
};
|
|
5844
5899
|
|
|
5845
5900
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -6208,6 +6263,16 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
6208
6263
|
: (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
6209
6264
|
};
|
|
6210
6265
|
|
|
6266
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
6267
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: rawUser.isGlobalBan });
|
|
6268
|
+
}
|
|
6269
|
+
function prepareUserPayload(response) {
|
|
6270
|
+
return {
|
|
6271
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
6272
|
+
files: response.files,
|
|
6273
|
+
};
|
|
6274
|
+
}
|
|
6275
|
+
|
|
6211
6276
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
6212
6277
|
const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
6213
6278
|
function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -6265,9 +6330,13 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
6265
6330
|
// attach marker to channel
|
|
6266
6331
|
const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
6267
6332
|
// user marker to channel users
|
|
6268
|
-
const channelUsers =
|
|
6333
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
6334
|
+
return convertRawMembershipToMembership(channelUser);
|
|
6335
|
+
});
|
|
6336
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
6269
6337
|
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
6270
|
-
return Object.assign(Object.assign({}, restRawPayload), {
|
|
6338
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
6339
|
+
channels,
|
|
6271
6340
|
channelUsers });
|
|
6272
6341
|
};
|
|
6273
6342
|
|
|
@@ -7691,7 +7760,8 @@ const onChannelMemberBanned = (callback) => {
|
|
|
7691
7760
|
|
|
7692
7761
|
const createUserEventSubscriber = (event, callback) => {
|
|
7693
7762
|
const client = getActiveClient();
|
|
7694
|
-
const filter = (
|
|
7763
|
+
const filter = (data) => {
|
|
7764
|
+
const payload = prepareUserPayload(data);
|
|
7695
7765
|
if (client.cache) {
|
|
7696
7766
|
ingestInCache(payload);
|
|
7697
7767
|
}
|
|
@@ -9927,18 +9997,17 @@ const queryBlockedUsers = async (query) => {
|
|
|
9927
9997
|
const { data } = await client.http.get('/api/v4/me/user-blocks', {
|
|
9928
9998
|
params,
|
|
9929
9999
|
});
|
|
9930
|
-
const
|
|
9931
|
-
const { users } = blockedUsers;
|
|
10000
|
+
const payload = prepareUserPayload(data);
|
|
9932
10001
|
const cachedAt = client.cache && Date.now();
|
|
9933
10002
|
if (client.cache) {
|
|
9934
|
-
ingestInCache(
|
|
10003
|
+
ingestInCache(payload, { cachedAt });
|
|
9935
10004
|
const cacheKey = ['blockedUsers', 'query', params];
|
|
9936
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
10005
|
+
pushToCache(cacheKey, { users: payload.users.map(getResolver('user')), paging: data.paging });
|
|
9937
10006
|
}
|
|
9938
|
-
const { next, previous, total } = paging;
|
|
10007
|
+
const { next, previous, total } = data.paging;
|
|
9939
10008
|
const nextPage = toPageRaw(next);
|
|
9940
10009
|
const prevPage = toPageRaw(previous);
|
|
9941
|
-
return { data: users, prevPage, nextPage, total, cachedAt };
|
|
10010
|
+
return { data: payload.users, prevPage, nextPage, total, cachedAt };
|
|
9942
10011
|
};
|
|
9943
10012
|
/**
|
|
9944
10013
|
* ```js
|
|
@@ -11018,12 +11087,13 @@ const getUserByIds = async (userIds) => {
|
|
|
11018
11087
|
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
11019
11088
|
params: { userIds: encodedUserIds },
|
|
11020
11089
|
});
|
|
11090
|
+
const payload = prepareUserPayload(data);
|
|
11021
11091
|
const cachedAt = client.cache && Date.now();
|
|
11022
11092
|
if (client.cache)
|
|
11023
|
-
ingestInCache(
|
|
11093
|
+
ingestInCache(payload, { cachedAt });
|
|
11024
11094
|
fireEvent('user.fetched', data);
|
|
11025
11095
|
return {
|
|
11026
|
-
data:
|
|
11096
|
+
data: payload.users.map(user => LinkedObject.user(user)),
|
|
11027
11097
|
cachedAt,
|
|
11028
11098
|
};
|
|
11029
11099
|
};
|
|
@@ -11081,20 +11151,14 @@ getUserByIds.locally = (userIds) => {
|
|
|
11081
11151
|
const updateUser = async (userId, patch) => {
|
|
11082
11152
|
const client = getActiveClient();
|
|
11083
11153
|
client.log('user/updateUser', userId, patch);
|
|
11084
|
-
// API-FIX: Endpoint is malformed, userId should be a url param.
|
|
11085
|
-
/*
|
|
11086
|
-
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
11087
|
-
`/api/v3/users/${userId}`, patch,
|
|
11088
|
-
)
|
|
11089
|
-
*/
|
|
11090
11154
|
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
11155
|
+
const payload = prepareUserPayload(data);
|
|
11091
11156
|
const cachedAt = client.cache && Date.now();
|
|
11092
11157
|
if (client.cache)
|
|
11093
|
-
ingestInCache(
|
|
11094
|
-
const { users } = data;
|
|
11158
|
+
ingestInCache(payload, { cachedAt });
|
|
11095
11159
|
fireEvent('user.updated', data);
|
|
11096
11160
|
return {
|
|
11097
|
-
data: users.find(user => user.userId === userId),
|
|
11161
|
+
data: payload.users.find(user => user.userId === userId),
|
|
11098
11162
|
cachedAt,
|
|
11099
11163
|
};
|
|
11100
11164
|
};
|
|
@@ -11118,11 +11182,12 @@ const updateUser = async (userId, patch) => {
|
|
|
11118
11182
|
const flagUser = async (userId) => {
|
|
11119
11183
|
const client = getActiveClient();
|
|
11120
11184
|
client.log('user/flagUser', userId);
|
|
11121
|
-
const { data
|
|
11185
|
+
const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11186
|
+
const payload = prepareUserPayload(data);
|
|
11122
11187
|
if (client.cache) {
|
|
11123
11188
|
ingestInCache(payload);
|
|
11124
11189
|
}
|
|
11125
|
-
fireEvent('user.flagged',
|
|
11190
|
+
fireEvent('user.flagged', data);
|
|
11126
11191
|
return !!payload;
|
|
11127
11192
|
};
|
|
11128
11193
|
/* end_public_function */
|
|
@@ -11145,11 +11210,12 @@ const flagUser = async (userId) => {
|
|
|
11145
11210
|
const unflagUser = async (userId) => {
|
|
11146
11211
|
const client = getActiveClient();
|
|
11147
11212
|
client.log('user/unflag', userId);
|
|
11148
|
-
const { data
|
|
11213
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
11214
|
+
const payload = prepareUserPayload(data);
|
|
11149
11215
|
if (client.cache) {
|
|
11150
11216
|
ingestInCache(payload);
|
|
11151
11217
|
}
|
|
11152
|
-
fireEvent('user.unflagged',
|
|
11218
|
+
fireEvent('user.unflagged', data);
|
|
11153
11219
|
return !!payload;
|
|
11154
11220
|
};
|
|
11155
11221
|
/* end_public_function */
|
|
@@ -11280,10 +11346,17 @@ const getUser$2 = async (userId) => {
|
|
|
11280
11346
|
const client = getActiveClient();
|
|
11281
11347
|
client.log('user/getUser', userId);
|
|
11282
11348
|
isInTombstone('user', userId);
|
|
11283
|
-
let data;
|
|
11284
11349
|
try {
|
|
11285
|
-
const
|
|
11286
|
-
|
|
11350
|
+
const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
11351
|
+
const cachedAt = client.cache && Date.now();
|
|
11352
|
+
const payload = prepareUserPayload(data);
|
|
11353
|
+
if (client.cache)
|
|
11354
|
+
ingestInCache(payload, { cachedAt });
|
|
11355
|
+
fireEvent('user.fetched', data);
|
|
11356
|
+
return {
|
|
11357
|
+
data: payload.users.find(user => user.userId === userId),
|
|
11358
|
+
cachedAt,
|
|
11359
|
+
};
|
|
11287
11360
|
}
|
|
11288
11361
|
catch (error) {
|
|
11289
11362
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -11291,15 +11364,6 @@ const getUser$2 = async (userId) => {
|
|
|
11291
11364
|
}
|
|
11292
11365
|
throw error;
|
|
11293
11366
|
}
|
|
11294
|
-
const cachedAt = client.cache && Date.now();
|
|
11295
|
-
if (client.cache)
|
|
11296
|
-
ingestInCache(data, { cachedAt });
|
|
11297
|
-
const { users } = data;
|
|
11298
|
-
fireEvent('user.fetched', data);
|
|
11299
|
-
return {
|
|
11300
|
-
data: users.find(user => user.userId === userId),
|
|
11301
|
-
cachedAt,
|
|
11302
|
-
};
|
|
11303
11367
|
};
|
|
11304
11368
|
/**
|
|
11305
11369
|
* ```js
|
|
@@ -11365,198 +11429,343 @@ const getUser$1 = (userId, callback) => {
|
|
|
11365
11429
|
};
|
|
11366
11430
|
/* end_public_function */
|
|
11367
11431
|
|
|
11368
|
-
|
|
11369
|
-
|
|
11370
|
-
|
|
11371
|
-
|
|
11372
|
-
|
|
11373
|
-
*
|
|
11374
|
-
* Queries a paginable list of {@link Amity.InternalUser} objects
|
|
11375
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
11376
|
-
*
|
|
11377
|
-
* @param query The query parameters
|
|
11378
|
-
* @returns A page of {@link Amity.InternalUser} objects
|
|
11379
|
-
*
|
|
11380
|
-
* @category User API
|
|
11381
|
-
* @async
|
|
11382
|
-
*/
|
|
11383
|
-
const queryUsers = async (query = {}) => {
|
|
11384
|
-
const client = getActiveClient();
|
|
11385
|
-
client.log('user/queryUsers', query);
|
|
11386
|
-
const { page, limit = 10, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "limit", "displayName", "filter", "sortBy"]);
|
|
11387
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
11388
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
11389
|
-
sortBy, options: page ? { token: page } : { limit } }),
|
|
11390
|
-
});
|
|
11391
|
-
// unpacking
|
|
11392
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
11393
|
-
const { users } = payload;
|
|
11394
|
-
const cachedAt = client.cache && Date.now();
|
|
11395
|
-
if (client.cache) {
|
|
11396
|
-
ingestInCache(payload, { cachedAt });
|
|
11397
|
-
/*
|
|
11398
|
-
* using a query as a cache key over params because if the keyword, filter, sort
|
|
11399
|
-
* change the API will NOT cache results, when it should
|
|
11400
|
-
*/
|
|
11401
|
-
const cacheKey = [
|
|
11402
|
-
'user',
|
|
11403
|
-
'query',
|
|
11404
|
-
Object.assign(Object.assign({}, query), { options: { limit, token: page } }),
|
|
11405
|
-
];
|
|
11406
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
11432
|
+
class PaginationController {
|
|
11433
|
+
constructor(queryParams) {
|
|
11434
|
+
const { http } = getActiveClient();
|
|
11435
|
+
this.queryParams = queryParams;
|
|
11436
|
+
this.http = http;
|
|
11407
11437
|
}
|
|
11408
|
-
|
|
11409
|
-
|
|
11410
|
-
|
|
11411
|
-
|
|
11412
|
-
|
|
11413
|
-
}
|
|
11414
|
-
|
|
11415
|
-
|
|
11416
|
-
|
|
11417
|
-
|
|
11418
|
-
|
|
11419
|
-
|
|
11420
|
-
|
|
11421
|
-
|
|
11422
|
-
|
|
11423
|
-
|
|
11424
|
-
|
|
11425
|
-
|
|
11426
|
-
|
|
11427
|
-
|
|
11428
|
-
|
|
11429
|
-
|
|
11430
|
-
|
|
11431
|
-
|
|
11432
|
-
client.log('user/queryUsers.locally', query);
|
|
11433
|
-
if (!client.cache)
|
|
11434
|
-
return;
|
|
11435
|
-
const { limit = 10, page } = query !== null && query !== void 0 ? query : {};
|
|
11436
|
-
const cacheKey = [
|
|
11437
|
-
'user',
|
|
11438
|
-
'query',
|
|
11439
|
-
Object.assign(Object.assign({}, query), { options: {
|
|
11440
|
-
limit,
|
|
11441
|
-
token: page,
|
|
11442
|
-
} }),
|
|
11443
|
-
];
|
|
11444
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
11445
|
-
const users = (_b = data === null || data === void 0 ? void 0 : data.users.map(userId => pullFromCache(['user', 'get', userId])).filter(Boolean).map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
11446
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
11447
|
-
? {
|
|
11448
|
-
data: users,
|
|
11449
|
-
cachedAt,
|
|
11450
|
-
paging: data === null || data === void 0 ? void 0 : data.paging,
|
|
11438
|
+
loadFirstPage() {
|
|
11439
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
11440
|
+
}
|
|
11441
|
+
loadNextPage() {
|
|
11442
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
11443
|
+
}
|
|
11444
|
+
loadPreviousPage() {
|
|
11445
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
11446
|
+
}
|
|
11447
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
11448
|
+
var _a, _b, _c, _d;
|
|
11449
|
+
if (direction === 'prev' && !this.previousToken)
|
|
11450
|
+
return;
|
|
11451
|
+
if (direction === 'next' && !this.nextToken)
|
|
11452
|
+
return;
|
|
11453
|
+
let token;
|
|
11454
|
+
if (direction === 'prev')
|
|
11455
|
+
token = this.previousToken;
|
|
11456
|
+
if (direction === 'next')
|
|
11457
|
+
token = this.nextToken;
|
|
11458
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
11459
|
+
if (direction === 'first') {
|
|
11460
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
11461
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
11451
11462
|
}
|
|
11452
|
-
|
|
11453
|
-
|
|
11463
|
+
if (direction === 'prev')
|
|
11464
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
11465
|
+
if (direction === 'next')
|
|
11466
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
11467
|
+
return queryResponse;
|
|
11468
|
+
}
|
|
11469
|
+
getNextToken() {
|
|
11470
|
+
return this.nextToken;
|
|
11471
|
+
}
|
|
11472
|
+
getPrevToken() {
|
|
11473
|
+
return this.previousToken;
|
|
11474
|
+
}
|
|
11475
|
+
}
|
|
11454
11476
|
|
|
11455
|
-
|
|
11456
|
-
|
|
11457
|
-
|
|
11458
|
-
|
|
11459
|
-
const
|
|
11460
|
-
|
|
11461
|
-
|
|
11462
|
-
|
|
11463
|
-
users = users.sort(sortByFirstCreated);
|
|
11464
|
-
break;
|
|
11465
|
-
case 'lastCreated':
|
|
11466
|
-
users = users.sort(sortByLastCreated);
|
|
11467
|
-
break;
|
|
11468
|
-
default:
|
|
11469
|
-
users = users
|
|
11470
|
-
// this needs to be aligned with the backend data type
|
|
11471
|
-
.map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
|
|
11472
|
-
.sort(sortByDisplayName);
|
|
11477
|
+
class UserPaginationController extends PaginationController {
|
|
11478
|
+
async getRequest(queryParams, token) {
|
|
11479
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
11480
|
+
const options = token ? { token } : { limit };
|
|
11481
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
11482
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
11483
|
+
});
|
|
11484
|
+
return queryResponse;
|
|
11473
11485
|
}
|
|
11474
|
-
|
|
11475
|
-
|
|
11476
|
-
|
|
11477
|
-
|
|
11478
|
-
|
|
11479
|
-
|
|
11480
|
-
* ```js
|
|
11481
|
-
* import { liveUsers } from '@amityco/ts-sdk'
|
|
11482
|
-
*
|
|
11483
|
-
* let users = []
|
|
11484
|
-
* const unsub = liveUsers({}, response => merge(users, response.data))
|
|
11485
|
-
* ```
|
|
11486
|
-
*
|
|
11487
|
-
* Observe all mutations on a list of {@link Amity.User}s
|
|
11488
|
-
*
|
|
11489
|
-
* @param params for querying users
|
|
11490
|
-
* @param callback the function to call when new data are available
|
|
11491
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
11492
|
-
*
|
|
11493
|
-
* @category Category Live Collection
|
|
11494
|
-
*/
|
|
11495
|
-
const getUsers = (params, callback, config) => {
|
|
11496
|
-
const { log, cache } = getActiveClient();
|
|
11497
|
-
if (!cache) {
|
|
11498
|
-
// eslint-disable-next-line no-console
|
|
11499
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
11486
|
+
}
|
|
11487
|
+
|
|
11488
|
+
class QueryStreamController {
|
|
11489
|
+
constructor(query, cacheKey) {
|
|
11490
|
+
this.query = query;
|
|
11491
|
+
this.cacheKey = cacheKey;
|
|
11500
11492
|
}
|
|
11501
|
-
|
|
11502
|
-
|
|
11503
|
-
|
|
11504
|
-
|
|
11505
|
-
|
|
11506
|
-
|
|
11507
|
-
|
|
11508
|
-
|
|
11493
|
+
}
|
|
11494
|
+
|
|
11495
|
+
class UserQueryStreamController extends QueryStreamController {
|
|
11496
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11497
|
+
super(query, cacheKey);
|
|
11498
|
+
this.notifyChange = notifyChange;
|
|
11499
|
+
this.preparePayload = preparePayload;
|
|
11500
|
+
}
|
|
11501
|
+
async saveToMainDB(response) {
|
|
11502
|
+
const processedPayload = await this.preparePayload(response);
|
|
11503
|
+
const client = getActiveClient();
|
|
11504
|
+
const cachedAt = client.cache && Date.now();
|
|
11505
|
+
if (client.cache) {
|
|
11506
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11507
|
+
}
|
|
11508
|
+
}
|
|
11509
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
11509
11510
|
var _a, _b;
|
|
11510
|
-
|
|
11511
|
-
.
|
|
11512
|
-
|
|
11513
|
-
|
|
11514
|
-
|
|
11515
|
-
|
|
11511
|
+
if (refresh) {
|
|
11512
|
+
pushToCache(this.cacheKey, {
|
|
11513
|
+
data: response.users.map(getResolver('user')),
|
|
11514
|
+
});
|
|
11515
|
+
}
|
|
11516
|
+
else {
|
|
11517
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11518
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11519
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
11520
|
+
}
|
|
11521
|
+
}
|
|
11522
|
+
reactor(action) {
|
|
11523
|
+
return (user) => {
|
|
11524
|
+
var _a;
|
|
11525
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11526
|
+
if (!collection)
|
|
11527
|
+
return;
|
|
11516
11528
|
/*
|
|
11517
|
-
*
|
|
11529
|
+
* Simply update a collection and let responder decide what to do with data
|
|
11518
11530
|
*/
|
|
11519
|
-
data
|
|
11520
|
-
|
|
11521
|
-
|
|
11522
|
-
|
|
11523
|
-
|
|
11524
|
-
|
|
11525
|
-
|
|
11526
|
-
|
|
11527
|
-
|
|
11528
|
-
|
|
11529
|
-
|
|
11530
|
-
|
|
11531
|
-
|
|
11532
|
-
|
|
11533
|
-
|
|
11534
|
-
|
|
11535
|
-
|
|
11536
|
-
const
|
|
11537
|
-
|
|
11538
|
-
|
|
11539
|
-
|
|
11540
|
-
|
|
11541
|
-
|
|
11542
|
-
|
|
11543
|
-
|
|
11544
|
-
|
|
11545
|
-
|
|
11546
|
-
|
|
11547
|
-
|
|
11548
|
-
|
|
11549
|
-
|
|
11550
|
-
|
|
11551
|
-
|
|
11552
|
-
|
|
11531
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
11532
|
+
pushToCache(this.cacheKey, collection);
|
|
11533
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11534
|
+
};
|
|
11535
|
+
}
|
|
11536
|
+
subscribeRTE(createSubscriber) {
|
|
11537
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11538
|
+
}
|
|
11539
|
+
}
|
|
11540
|
+
|
|
11541
|
+
class PaginationNoPageController {
|
|
11542
|
+
constructor(queryParams) {
|
|
11543
|
+
const { http } = getActiveClient();
|
|
11544
|
+
this.queryParams = queryParams;
|
|
11545
|
+
this.http = http;
|
|
11546
|
+
}
|
|
11547
|
+
async onFetch() {
|
|
11548
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
11549
|
+
return queryResponse;
|
|
11550
|
+
}
|
|
11551
|
+
}
|
|
11552
|
+
|
|
11553
|
+
class LiveCollectionController {
|
|
11554
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
11555
|
+
this.paginationController = paginationController;
|
|
11556
|
+
this.queryStreamId = queryStreamId;
|
|
11557
|
+
this.cacheKey = cacheKey;
|
|
11558
|
+
this.callback = callback;
|
|
11559
|
+
}
|
|
11560
|
+
async refresh() {
|
|
11561
|
+
try {
|
|
11562
|
+
let result;
|
|
11563
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
11564
|
+
result = await this.paginationController.onFetch();
|
|
11553
11565
|
}
|
|
11554
|
-
|
|
11555
|
-
|
|
11556
|
-
|
|
11557
|
-
|
|
11558
|
-
|
|
11559
|
-
|
|
11566
|
+
else {
|
|
11567
|
+
result = await this.paginationController.loadFirstPage();
|
|
11568
|
+
}
|
|
11569
|
+
if (!result)
|
|
11570
|
+
return;
|
|
11571
|
+
await this.persistModel(result);
|
|
11572
|
+
this.persistQueryStream({
|
|
11573
|
+
response: result,
|
|
11574
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
11575
|
+
refresh: true,
|
|
11576
|
+
});
|
|
11577
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
11578
|
+
}
|
|
11579
|
+
catch (e) {
|
|
11580
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
11581
|
+
}
|
|
11582
|
+
}
|
|
11583
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
11584
|
+
this.setup();
|
|
11585
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
11586
|
+
if (initial) {
|
|
11587
|
+
this.refresh();
|
|
11588
|
+
}
|
|
11589
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
11590
|
+
this.loadPrevPage();
|
|
11591
|
+
}
|
|
11592
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
11593
|
+
this.loadNextPage();
|
|
11594
|
+
}
|
|
11595
|
+
}
|
|
11596
|
+
async loadNextPage() {
|
|
11597
|
+
try {
|
|
11598
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
11599
|
+
return;
|
|
11600
|
+
const result = await this.paginationController.loadNextPage();
|
|
11601
|
+
if (!result)
|
|
11602
|
+
return;
|
|
11603
|
+
await this.persistModel(result);
|
|
11604
|
+
this.persistQueryStream({
|
|
11605
|
+
response: result,
|
|
11606
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
11607
|
+
});
|
|
11608
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
11609
|
+
}
|
|
11610
|
+
catch (e) {
|
|
11611
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
11612
|
+
}
|
|
11613
|
+
}
|
|
11614
|
+
async loadPrevPage() {
|
|
11615
|
+
try {
|
|
11616
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
11617
|
+
return;
|
|
11618
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
11619
|
+
if (!result)
|
|
11620
|
+
return;
|
|
11621
|
+
await this.persistModel(result);
|
|
11622
|
+
this.persistQueryStream({
|
|
11623
|
+
response: result,
|
|
11624
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
11625
|
+
});
|
|
11626
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
11627
|
+
}
|
|
11628
|
+
catch (e) {
|
|
11629
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
11630
|
+
}
|
|
11631
|
+
}
|
|
11632
|
+
shouldNotify(data) {
|
|
11633
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
11634
|
+
if (isEqual(this.snapshot, newData))
|
|
11635
|
+
return false;
|
|
11636
|
+
this.snapshot = newData;
|
|
11637
|
+
return true;
|
|
11638
|
+
}
|
|
11639
|
+
getCacheKey() {
|
|
11640
|
+
return this.cacheKey;
|
|
11641
|
+
}
|
|
11642
|
+
}
|
|
11643
|
+
|
|
11644
|
+
var EnumUserActions;
|
|
11645
|
+
(function (EnumUserActions) {
|
|
11646
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
11647
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
11648
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
11649
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
11650
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
11651
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
11652
|
+
|
|
11653
|
+
function isNonNullable(value) {
|
|
11654
|
+
return value != null;
|
|
11655
|
+
}
|
|
11656
|
+
|
|
11657
|
+
class UserLiveCollectionController extends LiveCollectionController {
|
|
11658
|
+
constructor(query, callback) {
|
|
11659
|
+
const queryStreamId = hash__default["default"](query);
|
|
11660
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
11661
|
+
const paginationController = new UserPaginationController(query);
|
|
11662
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11663
|
+
this.query = query;
|
|
11664
|
+
this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
11665
|
+
this.callback = callback.bind(this);
|
|
11666
|
+
this.loadPage({ initial: true });
|
|
11667
|
+
}
|
|
11668
|
+
setup() {
|
|
11669
|
+
var _a;
|
|
11670
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11671
|
+
if (!collection) {
|
|
11672
|
+
pushToCache(this.cacheKey, {
|
|
11673
|
+
data: [],
|
|
11674
|
+
params: {},
|
|
11675
|
+
});
|
|
11676
|
+
}
|
|
11677
|
+
}
|
|
11678
|
+
async persistModel(queryPayload) {
|
|
11679
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11680
|
+
}
|
|
11681
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11682
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11683
|
+
}
|
|
11684
|
+
startSubscription() {
|
|
11685
|
+
return this.queryStreamController.subscribeRTE([
|
|
11686
|
+
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
11687
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
11688
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
11689
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
11690
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
11691
|
+
]);
|
|
11692
|
+
}
|
|
11693
|
+
notifyChange({ origin, loading, error }) {
|
|
11694
|
+
var _a, _b;
|
|
11695
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11696
|
+
if (!collection)
|
|
11697
|
+
return;
|
|
11698
|
+
const data = this.applyFilter((_b = collection.data
|
|
11699
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
11700
|
+
.filter(isNonNullable)
|
|
11701
|
+
.map(({ data }) => data)
|
|
11702
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
11703
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
11704
|
+
return;
|
|
11705
|
+
this.callback({
|
|
11706
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11707
|
+
data,
|
|
11708
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11709
|
+
loading,
|
|
11710
|
+
error,
|
|
11711
|
+
});
|
|
11712
|
+
}
|
|
11713
|
+
applyFilter(data) {
|
|
11714
|
+
let users = data;
|
|
11715
|
+
if (!this.query.displayName) {
|
|
11716
|
+
const sortFn = (() => {
|
|
11717
|
+
switch (this.query.sortBy) {
|
|
11718
|
+
case Amity.UserSortByEnum.FirstCreated:
|
|
11719
|
+
return sortByFirstCreated;
|
|
11720
|
+
case Amity.UserSortByEnum.LastCreated:
|
|
11721
|
+
return sortByLastCreated;
|
|
11722
|
+
case Amity.UserSortByEnum.DisplayName:
|
|
11723
|
+
return sortByDisplayName;
|
|
11724
|
+
default:
|
|
11725
|
+
return sortByLastCreated;
|
|
11726
|
+
}
|
|
11727
|
+
})();
|
|
11728
|
+
users = users.sort(sortFn);
|
|
11729
|
+
}
|
|
11730
|
+
if (this.query.filter === 'flagged') {
|
|
11731
|
+
users = users.filter(user => !!user.hashFlag);
|
|
11732
|
+
}
|
|
11733
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
11734
|
+
return users;
|
|
11735
|
+
}
|
|
11736
|
+
}
|
|
11737
|
+
|
|
11738
|
+
/* begin_public_function
|
|
11739
|
+
id: user.query
|
|
11740
|
+
*/
|
|
11741
|
+
/**
|
|
11742
|
+
* ```js
|
|
11743
|
+
* import { liveUsers } from '@amityco/ts-sdk'
|
|
11744
|
+
*
|
|
11745
|
+
* let users = []
|
|
11746
|
+
* const unsub = liveUsers({}, response => merge(users, response.data))
|
|
11747
|
+
* ```
|
|
11748
|
+
*
|
|
11749
|
+
* Observe all mutations on a list of {@link Amity.User}s
|
|
11750
|
+
*
|
|
11751
|
+
* @param params for querying users
|
|
11752
|
+
* @param callback the function to call when new data are available
|
|
11753
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
11754
|
+
*
|
|
11755
|
+
* @category Category Live Collection
|
|
11756
|
+
*/
|
|
11757
|
+
const getUsers = (params, callback, config) => {
|
|
11758
|
+
const { log, cache } = getActiveClient();
|
|
11759
|
+
if (!cache) {
|
|
11760
|
+
// eslint-disable-next-line no-console
|
|
11761
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
11762
|
+
}
|
|
11763
|
+
const timestamp = Date.now();
|
|
11764
|
+
log(`liveUsers(tmpid: ${timestamp}) > listen`);
|
|
11765
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
11766
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
11767
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
11768
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
11560
11769
|
return () => {
|
|
11561
11770
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
11562
11771
|
disposers.forEach(fn => fn());
|
|
@@ -11579,27 +11788,9 @@ const getUsers = (params, callback, config) => {
|
|
|
11579
11788
|
* @async
|
|
11580
11789
|
*/
|
|
11581
11790
|
const getUser = async (userId) => {
|
|
11582
|
-
const
|
|
11583
|
-
client.log('user/getUser', userId);
|
|
11584
|
-
isInTombstone('user', userId);
|
|
11585
|
-
let data;
|
|
11586
|
-
try {
|
|
11587
|
-
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
11588
|
-
data = response.data;
|
|
11589
|
-
}
|
|
11590
|
-
catch (error) {
|
|
11591
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
11592
|
-
pushToTombstone('user', userId);
|
|
11593
|
-
}
|
|
11594
|
-
throw error;
|
|
11595
|
-
}
|
|
11596
|
-
const cachedAt = client.cache && Date.now();
|
|
11597
|
-
if (client.cache)
|
|
11598
|
-
ingestInCache(data, { cachedAt });
|
|
11599
|
-
const { users } = data;
|
|
11600
|
-
fireEvent('user.fetched', data);
|
|
11791
|
+
const { data, cachedAt } = await getUser$2(userId);
|
|
11601
11792
|
return {
|
|
11602
|
-
data: LinkedObject.user(
|
|
11793
|
+
data: LinkedObject.user(data),
|
|
11603
11794
|
cachedAt,
|
|
11604
11795
|
};
|
|
11605
11796
|
};
|
|
@@ -11617,11 +11808,7 @@ const getUser = async (userId) => {
|
|
|
11617
11808
|
* @category User API
|
|
11618
11809
|
*/
|
|
11619
11810
|
getUser.locally = (userId) => {
|
|
11620
|
-
const
|
|
11621
|
-
client.log('user/getUser.locally', userId);
|
|
11622
|
-
if (!client.cache)
|
|
11623
|
-
return;
|
|
11624
|
-
const cached = pullFromCache(['user', 'get', userId]);
|
|
11811
|
+
const cached = getUser$2.locally(userId);
|
|
11625
11812
|
if (!cached)
|
|
11626
11813
|
return;
|
|
11627
11814
|
return {
|
|
@@ -11671,6 +11858,130 @@ const observeUser = (userId, callback) => {
|
|
|
11671
11858
|
};
|
|
11672
11859
|
};
|
|
11673
11860
|
|
|
11861
|
+
class SearchUserPaginationController extends PaginationController {
|
|
11862
|
+
async getRequest(queryParams, token) {
|
|
11863
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
11864
|
+
const options = token ? { token } : { limit };
|
|
11865
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
11866
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
11867
|
+
});
|
|
11868
|
+
return queryResponse;
|
|
11869
|
+
}
|
|
11870
|
+
}
|
|
11871
|
+
|
|
11872
|
+
class SearchUserQueryStreamController extends QueryStreamController {
|
|
11873
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
11874
|
+
super(query, cacheKey);
|
|
11875
|
+
this.notifyChange = notifyChange;
|
|
11876
|
+
this.preparePayload = preparePayload;
|
|
11877
|
+
}
|
|
11878
|
+
async saveToMainDB(response) {
|
|
11879
|
+
const processedPayload = await this.preparePayload(response);
|
|
11880
|
+
const client = getActiveClient();
|
|
11881
|
+
const cachedAt = client.cache && Date.now();
|
|
11882
|
+
if (client.cache) {
|
|
11883
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
11884
|
+
}
|
|
11885
|
+
}
|
|
11886
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
11887
|
+
var _a, _b;
|
|
11888
|
+
if (refresh) {
|
|
11889
|
+
pushToCache(this.cacheKey, {
|
|
11890
|
+
data: response.users.map(getResolver('user')),
|
|
11891
|
+
});
|
|
11892
|
+
}
|
|
11893
|
+
else {
|
|
11894
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11895
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
11896
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
11897
|
+
}
|
|
11898
|
+
}
|
|
11899
|
+
reactor(action) {
|
|
11900
|
+
return (user) => {
|
|
11901
|
+
var _a;
|
|
11902
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11903
|
+
if (!collection)
|
|
11904
|
+
return;
|
|
11905
|
+
/*
|
|
11906
|
+
* Simply update a collection and let responder decide what to do with data
|
|
11907
|
+
*/
|
|
11908
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
11909
|
+
pushToCache(this.cacheKey, collection);
|
|
11910
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
11911
|
+
};
|
|
11912
|
+
}
|
|
11913
|
+
subscribeRTE(createSubscriber) {
|
|
11914
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
11915
|
+
}
|
|
11916
|
+
}
|
|
11917
|
+
|
|
11918
|
+
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
11919
|
+
constructor(query, callback) {
|
|
11920
|
+
var _a;
|
|
11921
|
+
const queryStreamId = hash__default["default"](query);
|
|
11922
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
11923
|
+
const paginationController = new SearchUserPaginationController(query);
|
|
11924
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
11925
|
+
this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
|
|
11926
|
+
this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
11927
|
+
this.callback = callback.bind(this);
|
|
11928
|
+
this.loadPage({ initial: true });
|
|
11929
|
+
}
|
|
11930
|
+
setup() {
|
|
11931
|
+
var _a;
|
|
11932
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11933
|
+
if (!collection) {
|
|
11934
|
+
pushToCache(this.cacheKey, {
|
|
11935
|
+
data: [],
|
|
11936
|
+
params: {},
|
|
11937
|
+
});
|
|
11938
|
+
}
|
|
11939
|
+
}
|
|
11940
|
+
async persistModel(queryPayload) {
|
|
11941
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
11942
|
+
}
|
|
11943
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
11944
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
11945
|
+
}
|
|
11946
|
+
startSubscription() {
|
|
11947
|
+
return this.queryStreamController.subscribeRTE([
|
|
11948
|
+
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
11949
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
11950
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
11951
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
11952
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
11953
|
+
]);
|
|
11954
|
+
}
|
|
11955
|
+
notifyChange({ origin, loading, error }) {
|
|
11956
|
+
var _a, _b;
|
|
11957
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
11958
|
+
if (!collection)
|
|
11959
|
+
return;
|
|
11960
|
+
const data = this.applyFilter((_b = collection.data
|
|
11961
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
11962
|
+
.filter(isNonNullable)
|
|
11963
|
+
.map(({ data }) => data)
|
|
11964
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
11965
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
11966
|
+
return;
|
|
11967
|
+
this.callback({
|
|
11968
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
11969
|
+
data,
|
|
11970
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
11971
|
+
loading,
|
|
11972
|
+
error,
|
|
11973
|
+
});
|
|
11974
|
+
}
|
|
11975
|
+
applyFilter(data) {
|
|
11976
|
+
let users = data;
|
|
11977
|
+
if (this.query.filter === 'flagged') {
|
|
11978
|
+
users = users.filter(user => !!user.hashFlag);
|
|
11979
|
+
}
|
|
11980
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
11981
|
+
return users;
|
|
11982
|
+
}
|
|
11983
|
+
}
|
|
11984
|
+
|
|
11674
11985
|
/* begin_public_function
|
|
11675
11986
|
id: user.search
|
|
11676
11987
|
*/
|
|
@@ -11692,7 +12003,21 @@ const observeUser = (userId, callback) => {
|
|
|
11692
12003
|
* @category Category Live Collection
|
|
11693
12004
|
*/
|
|
11694
12005
|
const searchUserByDisplayName = (params, callback, config) => {
|
|
11695
|
-
|
|
12006
|
+
const { log, cache } = getActiveClient();
|
|
12007
|
+
if (!cache) {
|
|
12008
|
+
// eslint-disable-next-line no-console
|
|
12009
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
12010
|
+
}
|
|
12011
|
+
const timestamp = Date.now();
|
|
12012
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
|
|
12013
|
+
const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
|
|
12014
|
+
const disposers = searchUsersLiveCollection.startSubscription();
|
|
12015
|
+
const cacheKey = searchUsersLiveCollection.getCacheKey();
|
|
12016
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
12017
|
+
return () => {
|
|
12018
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
|
|
12019
|
+
disposers.forEach(fn => fn());
|
|
12020
|
+
};
|
|
11696
12021
|
};
|
|
11697
12022
|
/* end_public_function */
|
|
11698
12023
|
|
|
@@ -13757,29 +14082,98 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
13757
14082
|
getReactions: getReactions
|
|
13758
14083
|
});
|
|
13759
14084
|
|
|
13760
|
-
|
|
13761
|
-
|
|
13762
|
-
|
|
13763
|
-
|
|
13764
|
-
|
|
13765
|
-
|
|
13766
|
-
|
|
13767
|
-
|
|
13768
|
-
|
|
13769
|
-
|
|
13770
|
-
|
|
13771
|
-
|
|
13772
|
-
|
|
13773
|
-
|
|
13774
|
-
|
|
13775
|
-
|
|
13776
|
-
|
|
13777
|
-
|
|
13778
|
-
|
|
13779
|
-
|
|
13780
|
-
|
|
14085
|
+
const getMatchPostSetting = (value) => {
|
|
14086
|
+
var _a;
|
|
14087
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
14088
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
14089
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
14090
|
+
};
|
|
14091
|
+
function addPostSetting({ communities }) {
|
|
14092
|
+
return communities.map((_a) => {
|
|
14093
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
14094
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
14095
|
+
needApprovalOnPostCreation,
|
|
14096
|
+
onlyAdminCanPost,
|
|
14097
|
+
}) }, restCommunityPayload));
|
|
14098
|
+
});
|
|
14099
|
+
}
|
|
14100
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
14101
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
14102
|
+
// map users with community
|
|
14103
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
14104
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
14105
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
14106
|
+
});
|
|
14107
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
14108
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
14109
|
+
};
|
|
14110
|
+
const prepareCommunityRequest = (params) => {
|
|
14111
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
14112
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
14113
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
14114
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
14115
|
+
};
|
|
14116
|
+
|
|
14117
|
+
const preparePostPayload = (postPayload) => {
|
|
14118
|
+
const { posts } = postPayload;
|
|
14119
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
14120
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
14121
|
+
// map users with community
|
|
14122
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
14123
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
14124
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
14125
|
+
});
|
|
14126
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
14127
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13781
14128
|
};
|
|
13782
14129
|
|
|
14130
|
+
function prepareCommentPayload(commentPayload) {
|
|
14131
|
+
const { comments } = commentPayload;
|
|
14132
|
+
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
14133
|
+
if (comment.hasOwnProperty('myReactions'))
|
|
14134
|
+
return comment;
|
|
14135
|
+
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
14136
|
+
// We need to put it with an empty array manually to make it show up in client side
|
|
14137
|
+
return Object.assign({ myReactions: [] }, comment);
|
|
14138
|
+
}) });
|
|
14139
|
+
}
|
|
14140
|
+
|
|
14141
|
+
const createMessageReport = async ({ client, referenceId, }) => {
|
|
14142
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14143
|
+
if (client.cache) {
|
|
14144
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
14145
|
+
ingestInCache(messagePayload);
|
|
14146
|
+
}
|
|
14147
|
+
fireEvent(`message.flagged`, payload);
|
|
14148
|
+
return !!payload;
|
|
14149
|
+
};
|
|
14150
|
+
const createPostReport = async ({ client, referenceId, }) => {
|
|
14151
|
+
const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
14152
|
+
if (client.cache) {
|
|
14153
|
+
const postPayload = await preparePostPayload(payload);
|
|
14154
|
+
ingestInCache(postPayload);
|
|
14155
|
+
}
|
|
14156
|
+
fireEvent(`post.flagged`, payload);
|
|
14157
|
+
return !!payload;
|
|
14158
|
+
};
|
|
14159
|
+
const createUserReport = async ({ client, referenceId, }) => {
|
|
14160
|
+
const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
14161
|
+
if (client.cache) {
|
|
14162
|
+
const userPayload = await prepareUserPayload(payload);
|
|
14163
|
+
ingestInCache(userPayload);
|
|
14164
|
+
}
|
|
14165
|
+
fireEvent(`user.flagged`, payload);
|
|
14166
|
+
return !!payload;
|
|
14167
|
+
};
|
|
14168
|
+
const createCommentReport = async ({ client, referenceId, }) => {
|
|
14169
|
+
const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
14170
|
+
if (client.cache) {
|
|
14171
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
14172
|
+
ingestInCache(commentPayload);
|
|
14173
|
+
}
|
|
14174
|
+
fireEvent(`comment.flagged`, payload);
|
|
14175
|
+
return !!payload;
|
|
14176
|
+
};
|
|
13783
14177
|
/**
|
|
13784
14178
|
* ```js
|
|
13785
14179
|
* import { createReport } from '@amityco/ts-sdk'
|
|
@@ -13796,33 +14190,57 @@ var REFERENCE_TYPES = {
|
|
|
13796
14190
|
const createReport = async (referenceType, referenceId) => {
|
|
13797
14191
|
const client = getActiveClient();
|
|
13798
14192
|
client.log('report/createReport', { referenceType, referenceId });
|
|
13799
|
-
|
|
13800
|
-
|
|
13801
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
13802
|
-
}
|
|
13803
|
-
if (referenceType === 'message') {
|
|
13804
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
13805
|
-
}
|
|
13806
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
13807
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`;
|
|
13808
|
-
};
|
|
13809
|
-
const { data: payload } = await client.http.post(getAPIUrl());
|
|
13810
|
-
if (client.cache) {
|
|
13811
|
-
if (referenceType === 'message') {
|
|
13812
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
13813
|
-
ingestInCache(messagePayload);
|
|
13814
|
-
}
|
|
13815
|
-
else if (referenceType === 'post') {
|
|
13816
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
13817
|
-
}
|
|
13818
|
-
else {
|
|
13819
|
-
ingestInCache(payload);
|
|
13820
|
-
}
|
|
14193
|
+
if (referenceType === 'user') {
|
|
14194
|
+
return createUserReport({ client, referenceId });
|
|
13821
14195
|
}
|
|
13822
|
-
|
|
13823
|
-
|
|
14196
|
+
if (referenceType === 'message') {
|
|
14197
|
+
return createMessageReport({ client, referenceId });
|
|
14198
|
+
}
|
|
14199
|
+
if (referenceType === 'post') {
|
|
14200
|
+
return createPostReport({ client, referenceId });
|
|
14201
|
+
}
|
|
14202
|
+
if (referenceType === 'comment') {
|
|
14203
|
+
return createCommentReport({ client, referenceId });
|
|
14204
|
+
}
|
|
14205
|
+
return false;
|
|
13824
14206
|
};
|
|
13825
14207
|
|
|
14208
|
+
const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
14209
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14210
|
+
if (client.cache) {
|
|
14211
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
14212
|
+
ingestInCache(messagePayload);
|
|
14213
|
+
}
|
|
14214
|
+
fireEvent(`message.unflagged`, payload);
|
|
14215
|
+
return !!payload;
|
|
14216
|
+
};
|
|
14217
|
+
const deletePostReport = async ({ client, referenceId, }) => {
|
|
14218
|
+
const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
14219
|
+
if (client.cache) {
|
|
14220
|
+
const postPayload = await preparePostPayload(payload);
|
|
14221
|
+
ingestInCache(postPayload);
|
|
14222
|
+
}
|
|
14223
|
+
fireEvent(`post.unflagged`, payload);
|
|
14224
|
+
return !!payload;
|
|
14225
|
+
};
|
|
14226
|
+
const deleteUserReport = async ({ client, referenceId, }) => {
|
|
14227
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
14228
|
+
if (client.cache) {
|
|
14229
|
+
const userPayload = await prepareUserPayload(payload);
|
|
14230
|
+
ingestInCache(userPayload);
|
|
14231
|
+
}
|
|
14232
|
+
fireEvent(`user.unflagged`, payload);
|
|
14233
|
+
return !!payload;
|
|
14234
|
+
};
|
|
14235
|
+
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
14236
|
+
const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
14237
|
+
if (client.cache) {
|
|
14238
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
14239
|
+
ingestInCache(commentPayload);
|
|
14240
|
+
}
|
|
14241
|
+
fireEvent(`comment.unflagged`, payload);
|
|
14242
|
+
return !!payload;
|
|
14243
|
+
};
|
|
13826
14244
|
/**
|
|
13827
14245
|
* ```js
|
|
13828
14246
|
* import { deleteReport } from '@amityco/ts-sdk'
|
|
@@ -13839,34 +14257,45 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
13839
14257
|
const deleteReport = async (referenceType, referenceId) => {
|
|
13840
14258
|
const client = getActiveClient();
|
|
13841
14259
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
13842
|
-
|
|
13843
|
-
|
|
13844
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
13845
|
-
}
|
|
13846
|
-
if (referenceType === 'message') {
|
|
13847
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
13848
|
-
}
|
|
13849
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
13850
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`;
|
|
13851
|
-
};
|
|
13852
|
-
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
13853
|
-
if (client.cache) {
|
|
13854
|
-
if (referenceType === 'message') {
|
|
13855
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
13856
|
-
ingestInCache(messagePayload);
|
|
13857
|
-
}
|
|
13858
|
-
else if (referenceType === 'post') {
|
|
13859
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
13860
|
-
}
|
|
13861
|
-
else {
|
|
13862
|
-
ingestInCache(payload);
|
|
13863
|
-
}
|
|
14260
|
+
if (referenceType === 'user') {
|
|
14261
|
+
return deleteUserReport({ client, referenceId });
|
|
13864
14262
|
}
|
|
13865
|
-
|
|
13866
|
-
|
|
13867
|
-
|
|
14263
|
+
if (referenceType === 'message') {
|
|
14264
|
+
return deleteMessageReport({ client, referenceId });
|
|
14265
|
+
}
|
|
14266
|
+
if (referenceType === 'post') {
|
|
14267
|
+
return deletePostReport({ client, referenceId });
|
|
14268
|
+
}
|
|
14269
|
+
if (referenceType === 'comment') {
|
|
14270
|
+
return deleteCommentReport({ client, referenceId });
|
|
14271
|
+
}
|
|
14272
|
+
return false;
|
|
13868
14273
|
};
|
|
13869
14274
|
|
|
14275
|
+
const getMessageReport = async ({ client, referenceId, }) => {
|
|
14276
|
+
var _a;
|
|
14277
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
14278
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14279
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14280
|
+
};
|
|
14281
|
+
const getPostReport = async ({ client, referenceId, }) => {
|
|
14282
|
+
var _a;
|
|
14283
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
14284
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14285
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14286
|
+
};
|
|
14287
|
+
const getUserReport = async ({ client, referenceId, }) => {
|
|
14288
|
+
var _a;
|
|
14289
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
14290
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14291
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14292
|
+
};
|
|
14293
|
+
const getCommentReport = async ({ client, referenceId, }) => {
|
|
14294
|
+
var _a;
|
|
14295
|
+
const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
|
|
14296
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
14297
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
14298
|
+
};
|
|
13870
14299
|
/**
|
|
13871
14300
|
* ```js
|
|
13872
14301
|
* import { isReportedByMe } from '@amityco/ts-sdk'
|
|
@@ -13881,17 +14310,21 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
13881
14310
|
* @async
|
|
13882
14311
|
* */
|
|
13883
14312
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
13884
|
-
var _a;
|
|
13885
14313
|
const client = getActiveClient();
|
|
13886
14314
|
client.log('report/isReportedByMe', { referenceType, referenceId });
|
|
13887
|
-
|
|
14315
|
+
if (referenceType === 'user') {
|
|
14316
|
+
return getUserReport({ client, referenceId });
|
|
14317
|
+
}
|
|
13888
14318
|
if (referenceType === 'message') {
|
|
13889
|
-
|
|
13890
|
-
return data.result;
|
|
14319
|
+
return getMessageReport({ client, referenceId });
|
|
13891
14320
|
}
|
|
13892
|
-
|
|
13893
|
-
|
|
13894
|
-
|
|
14321
|
+
if (referenceType === 'post') {
|
|
14322
|
+
return getPostReport({ client, referenceId });
|
|
14323
|
+
}
|
|
14324
|
+
if (referenceType === 'comment') {
|
|
14325
|
+
return getCommentReport({ client, referenceId });
|
|
14326
|
+
}
|
|
14327
|
+
return false;
|
|
13895
14328
|
};
|
|
13896
14329
|
|
|
13897
14330
|
/* begin_public_function
|
|
@@ -15355,172 +15788,62 @@ const onMessageReactionRemoved = (callback) => {
|
|
|
15355
15788
|
* ```
|
|
15356
15789
|
*
|
|
15357
15790
|
* Fired when an {@link Amity.Message} has been fetched
|
|
15358
|
-
*
|
|
15359
|
-
* @param callback The function to call when the event was fired
|
|
15360
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15361
|
-
*
|
|
15362
|
-
* @category Message Events
|
|
15363
|
-
*/
|
|
15364
|
-
const onMessageFetched = (callback) => {
|
|
15365
|
-
const client = getActiveClient();
|
|
15366
|
-
const filter = (payload) => {
|
|
15367
|
-
ingestInCache(payload);
|
|
15368
|
-
callback(payload.messages[0]);
|
|
15369
|
-
};
|
|
15370
|
-
return createEventSubscriber(client, 'message/onMessageFetched', 'local.message.fetched', filter);
|
|
15371
|
-
};
|
|
15372
|
-
|
|
15373
|
-
/* begin_public_function
|
|
15374
|
-
id: message.get
|
|
15375
|
-
*/
|
|
15376
|
-
/**
|
|
15377
|
-
* ```js
|
|
15378
|
-
* import { getMessage } from '@amityco/ts-sdk';
|
|
15379
|
-
*
|
|
15380
|
-
* let message;
|
|
15381
|
-
*
|
|
15382
|
-
* const unsubscribe = getMessage(messageId, response => {
|
|
15383
|
-
* message = response.data;
|
|
15384
|
-
* });
|
|
15385
|
-
* ```
|
|
15386
|
-
*
|
|
15387
|
-
* Observe all mutation on a given {@link Amity.Message}
|
|
15388
|
-
*
|
|
15389
|
-
* @param messageId the ID of the message to observe
|
|
15390
|
-
* @param callback the function to call when new data are available
|
|
15391
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
15392
|
-
*
|
|
15393
|
-
* @category Message Live Object
|
|
15394
|
-
*/
|
|
15395
|
-
const getMessage$1 = (messageId, callback) => {
|
|
15396
|
-
const responder = (snapshot) => {
|
|
15397
|
-
const { data } = snapshot;
|
|
15398
|
-
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
|
|
15399
|
-
};
|
|
15400
|
-
return liveObject(messageId, responder, 'messageId', getMessage$2, [
|
|
15401
|
-
onMessageFetched,
|
|
15402
|
-
onMessageUpdated,
|
|
15403
|
-
onMessageDeleted,
|
|
15404
|
-
onMessageFlagged,
|
|
15405
|
-
onMessageUnflagged,
|
|
15406
|
-
onMessageFlagCleared,
|
|
15407
|
-
onMessageReactionAdded,
|
|
15408
|
-
onMessageReactionRemoved,
|
|
15409
|
-
convertEventPayload(onMessageMarkerFetched, 'contentId', 'message'),
|
|
15410
|
-
convertEventPayload(onMessageMarked, 'contentId', 'message'),
|
|
15411
|
-
]);
|
|
15412
|
-
};
|
|
15413
|
-
/* end_public_function */
|
|
15414
|
-
|
|
15415
|
-
class PaginationNoPageController {
|
|
15416
|
-
constructor(queryParams) {
|
|
15417
|
-
const { http } = getActiveClient();
|
|
15418
|
-
this.queryParams = queryParams;
|
|
15419
|
-
this.http = http;
|
|
15420
|
-
}
|
|
15421
|
-
async onFetch() {
|
|
15422
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
15423
|
-
return queryResponse;
|
|
15424
|
-
}
|
|
15425
|
-
}
|
|
15426
|
-
|
|
15427
|
-
class LiveCollectionController {
|
|
15428
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
15429
|
-
this.paginationController = paginationController;
|
|
15430
|
-
this.queryStreamId = queryStreamId;
|
|
15431
|
-
this.cacheKey = cacheKey;
|
|
15432
|
-
this.callback = callback;
|
|
15433
|
-
}
|
|
15434
|
-
async refresh() {
|
|
15435
|
-
try {
|
|
15436
|
-
let result;
|
|
15437
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
15438
|
-
result = await this.paginationController.onFetch();
|
|
15439
|
-
}
|
|
15440
|
-
else {
|
|
15441
|
-
result = await this.paginationController.loadFirstPage();
|
|
15442
|
-
}
|
|
15443
|
-
if (!result)
|
|
15444
|
-
return;
|
|
15445
|
-
await this.persistModel(result);
|
|
15446
|
-
this.persistQueryStream({
|
|
15447
|
-
response: result,
|
|
15448
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
15449
|
-
refresh: true,
|
|
15450
|
-
});
|
|
15451
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15452
|
-
}
|
|
15453
|
-
catch (e) {
|
|
15454
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15455
|
-
}
|
|
15456
|
-
}
|
|
15457
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
15458
|
-
this.setup();
|
|
15459
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
15460
|
-
if (initial) {
|
|
15461
|
-
this.refresh();
|
|
15462
|
-
}
|
|
15463
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
15464
|
-
this.loadPrevPage();
|
|
15465
|
-
}
|
|
15466
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
15467
|
-
this.loadNextPage();
|
|
15468
|
-
}
|
|
15469
|
-
}
|
|
15470
|
-
async loadNextPage() {
|
|
15471
|
-
try {
|
|
15472
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
15473
|
-
return;
|
|
15474
|
-
const result = await this.paginationController.loadNextPage();
|
|
15475
|
-
if (!result)
|
|
15476
|
-
return;
|
|
15477
|
-
await this.persistModel(result);
|
|
15478
|
-
this.persistQueryStream({
|
|
15479
|
-
response: result,
|
|
15480
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
15481
|
-
});
|
|
15482
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15483
|
-
}
|
|
15484
|
-
catch (e) {
|
|
15485
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15486
|
-
}
|
|
15487
|
-
}
|
|
15488
|
-
async loadPrevPage() {
|
|
15489
|
-
try {
|
|
15490
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
15491
|
-
return;
|
|
15492
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
15493
|
-
if (!result)
|
|
15494
|
-
return;
|
|
15495
|
-
await this.persistModel(result);
|
|
15496
|
-
this.persistQueryStream({
|
|
15497
|
-
response: result,
|
|
15498
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
15499
|
-
});
|
|
15500
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
15501
|
-
}
|
|
15502
|
-
catch (e) {
|
|
15503
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
15504
|
-
}
|
|
15505
|
-
}
|
|
15506
|
-
shouldNotify(data) {
|
|
15507
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
15508
|
-
if (isEqual(this.snapshot, newData))
|
|
15509
|
-
return false;
|
|
15510
|
-
this.snapshot = newData;
|
|
15511
|
-
return true;
|
|
15512
|
-
}
|
|
15513
|
-
getCacheKey() {
|
|
15514
|
-
return this.cacheKey;
|
|
15515
|
-
}
|
|
15516
|
-
}
|
|
15791
|
+
*
|
|
15792
|
+
* @param callback The function to call when the event was fired
|
|
15793
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15794
|
+
*
|
|
15795
|
+
* @category Message Events
|
|
15796
|
+
*/
|
|
15797
|
+
const onMessageFetched = (callback) => {
|
|
15798
|
+
const client = getActiveClient();
|
|
15799
|
+
const filter = (payload) => {
|
|
15800
|
+
ingestInCache(payload);
|
|
15801
|
+
callback(payload.messages[0]);
|
|
15802
|
+
};
|
|
15803
|
+
return createEventSubscriber(client, 'message/onMessageFetched', 'local.message.fetched', filter);
|
|
15804
|
+
};
|
|
15517
15805
|
|
|
15518
|
-
|
|
15519
|
-
|
|
15520
|
-
|
|
15521
|
-
|
|
15522
|
-
|
|
15523
|
-
}
|
|
15806
|
+
/* begin_public_function
|
|
15807
|
+
id: message.get
|
|
15808
|
+
*/
|
|
15809
|
+
/**
|
|
15810
|
+
* ```js
|
|
15811
|
+
* import { getMessage } from '@amityco/ts-sdk';
|
|
15812
|
+
*
|
|
15813
|
+
* let message;
|
|
15814
|
+
*
|
|
15815
|
+
* const unsubscribe = getMessage(messageId, response => {
|
|
15816
|
+
* message = response.data;
|
|
15817
|
+
* });
|
|
15818
|
+
* ```
|
|
15819
|
+
*
|
|
15820
|
+
* Observe all mutation on a given {@link Amity.Message}
|
|
15821
|
+
*
|
|
15822
|
+
* @param messageId the ID of the message to observe
|
|
15823
|
+
* @param callback the function to call when new data are available
|
|
15824
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the message
|
|
15825
|
+
*
|
|
15826
|
+
* @category Message Live Object
|
|
15827
|
+
*/
|
|
15828
|
+
const getMessage$1 = (messageId, callback) => {
|
|
15829
|
+
const responder = (snapshot) => {
|
|
15830
|
+
const { data } = snapshot;
|
|
15831
|
+
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.message(snapshot.data) : data }));
|
|
15832
|
+
};
|
|
15833
|
+
return liveObject(messageId, responder, 'messageId', getMessage$2, [
|
|
15834
|
+
onMessageFetched,
|
|
15835
|
+
onMessageUpdated,
|
|
15836
|
+
onMessageDeleted,
|
|
15837
|
+
onMessageFlagged,
|
|
15838
|
+
onMessageUnflagged,
|
|
15839
|
+
onMessageFlagCleared,
|
|
15840
|
+
onMessageReactionAdded,
|
|
15841
|
+
onMessageReactionRemoved,
|
|
15842
|
+
convertEventPayload(onMessageMarkerFetched, 'contentId', 'message'),
|
|
15843
|
+
convertEventPayload(onMessageMarked, 'contentId', 'message'),
|
|
15844
|
+
]);
|
|
15845
|
+
};
|
|
15846
|
+
/* end_public_function */
|
|
15524
15847
|
|
|
15525
15848
|
/* eslint-disable no-use-before-define */
|
|
15526
15849
|
class MessageQueryStreamController extends QueryStreamController {
|
|
@@ -15604,51 +15927,6 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
15604
15927
|
}
|
|
15605
15928
|
}
|
|
15606
15929
|
|
|
15607
|
-
class PaginationController {
|
|
15608
|
-
constructor(queryParams) {
|
|
15609
|
-
const { http } = getActiveClient();
|
|
15610
|
-
this.queryParams = queryParams;
|
|
15611
|
-
this.http = http;
|
|
15612
|
-
}
|
|
15613
|
-
loadFirstPage() {
|
|
15614
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
15615
|
-
}
|
|
15616
|
-
loadNextPage() {
|
|
15617
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
15618
|
-
}
|
|
15619
|
-
loadPreviousPage() {
|
|
15620
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
15621
|
-
}
|
|
15622
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
15623
|
-
var _a, _b, _c, _d;
|
|
15624
|
-
if (direction === 'prev' && !this.previousToken)
|
|
15625
|
-
return;
|
|
15626
|
-
if (direction === 'next' && !this.nextToken)
|
|
15627
|
-
return;
|
|
15628
|
-
let token;
|
|
15629
|
-
if (direction === 'prev')
|
|
15630
|
-
token = this.previousToken;
|
|
15631
|
-
if (direction === 'next')
|
|
15632
|
-
token = this.nextToken;
|
|
15633
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
15634
|
-
if (direction === 'first') {
|
|
15635
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
15636
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
15637
|
-
}
|
|
15638
|
-
if (direction === 'prev')
|
|
15639
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
15640
|
-
if (direction === 'next')
|
|
15641
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
15642
|
-
return queryResponse;
|
|
15643
|
-
}
|
|
15644
|
-
getNextToken() {
|
|
15645
|
-
return this.nextToken;
|
|
15646
|
-
}
|
|
15647
|
-
getPrevToken() {
|
|
15648
|
-
return this.previousToken;
|
|
15649
|
-
}
|
|
15650
|
-
}
|
|
15651
|
-
|
|
15652
15930
|
/* eslint-disable no-use-before-define */
|
|
15653
15931
|
/**
|
|
15654
15932
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -17593,6 +17871,9 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
17593
17871
|
console.warn('`search` param will be deprecated in the next major release. If you want to search channel members by displayName, Please use `searchMembers()` instead.');
|
|
17594
17872
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
17595
17873
|
}
|
|
17874
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
17875
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) === this.query.includeDeleted; });
|
|
17876
|
+
}
|
|
17596
17877
|
// sort, 'lastCreated' is the default sort order
|
|
17597
17878
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
17598
17879
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -17960,57 +18241,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
17960
18241
|
});
|
|
17961
18242
|
};
|
|
17962
18243
|
|
|
17963
|
-
const getMatchPostSetting = (value) => {
|
|
17964
|
-
var _a;
|
|
17965
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
17966
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
17967
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
17968
|
-
};
|
|
17969
|
-
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
17970
|
-
if (!communityUsers)
|
|
17971
|
-
return communityUsers;
|
|
17972
|
-
const result = {};
|
|
17973
|
-
communityUsers.forEach(user => {
|
|
17974
|
-
result[`${user.userId}#${user.communityId}`] = user;
|
|
17975
|
-
});
|
|
17976
|
-
return result;
|
|
17977
|
-
};
|
|
17978
|
-
const convertCommunityPayload = (rawPayload) => {
|
|
17979
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
17980
|
-
const communities = rawPayload.communities.map((_a) => {
|
|
17981
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
17982
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
17983
|
-
needApprovalOnPostCreation,
|
|
17984
|
-
onlyAdminCanPost,
|
|
17985
|
-
}) }, restCommunityPayload));
|
|
17986
|
-
});
|
|
17987
|
-
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
17988
|
-
var _a;
|
|
17989
|
-
const users = (_a = pullFromCache([
|
|
17990
|
-
'communityUsers',
|
|
17991
|
-
'collection',
|
|
17992
|
-
communityId,
|
|
17993
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17994
|
-
if (!users)
|
|
17995
|
-
return acc;
|
|
17996
|
-
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
17997
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
17998
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
17999
|
-
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
18000
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
18001
|
-
};
|
|
18002
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
18003
|
-
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
18004
|
-
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
18005
|
-
communityUsers });
|
|
18006
|
-
};
|
|
18007
|
-
const prepareCommunityRequest = (params) => {
|
|
18008
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
18009
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
18010
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
18011
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
18012
|
-
};
|
|
18013
|
-
|
|
18014
18244
|
/**
|
|
18015
18245
|
* ```js
|
|
18016
18246
|
* import { getCommunities } from '@amityco/ts-sdk'
|
|
@@ -18446,10 +18676,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
18446
18676
|
*/
|
|
18447
18677
|
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
18448
18678
|
|
|
18449
|
-
function isNonNullable(value) {
|
|
18450
|
-
return value != null;
|
|
18451
|
-
}
|
|
18452
|
-
|
|
18453
18679
|
function hasPermission(member, payload, permission) {
|
|
18454
18680
|
if (member.permissions.some(x => x === permission)) {
|
|
18455
18681
|
return true;
|
|
@@ -18998,6 +19224,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
18998
19224
|
if (this.query.search) {
|
|
18999
19225
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19000
19226
|
}
|
|
19227
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
19228
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
|
|
19229
|
+
}
|
|
19001
19230
|
switch (this.query.sortBy) {
|
|
19002
19231
|
case 'firstCreated':
|
|
19003
19232
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
@@ -19235,6 +19464,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
19235
19464
|
if (this.query.search) {
|
|
19236
19465
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19237
19466
|
}
|
|
19467
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
19468
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
|
|
19469
|
+
}
|
|
19238
19470
|
return communityMembers;
|
|
19239
19471
|
}
|
|
19240
19472
|
}
|
|
@@ -19559,11 +19791,11 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
19559
19791
|
if (!this.query.displayName) {
|
|
19560
19792
|
const sortFn = (() => {
|
|
19561
19793
|
switch (this.query.sortBy) {
|
|
19562
|
-
case
|
|
19794
|
+
case "firstCreated" /* Amity.CommunitySortByEnum.FirstCreated */:
|
|
19563
19795
|
return sortByFirstCreated;
|
|
19564
|
-
case
|
|
19796
|
+
case "lastCreated" /* Amity.CommunitySortByEnum.LastCreated */:
|
|
19565
19797
|
return sortByLastCreated;
|
|
19566
|
-
case
|
|
19798
|
+
case "displayName" /* Amity.CommunitySortByEnum.DisplayName */:
|
|
19567
19799
|
return sortByDisplayName;
|
|
19568
19800
|
default:
|
|
19569
19801
|
return sortByLastCreated;
|
|
@@ -21788,17 +22020,6 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
21788
22020
|
}
|
|
21789
22021
|
}
|
|
21790
22022
|
|
|
21791
|
-
function prepareCommentPayload(commentPayload) {
|
|
21792
|
-
const { comments } = commentPayload;
|
|
21793
|
-
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
21794
|
-
if (comment.hasOwnProperty('myReactions'))
|
|
21795
|
-
return comment;
|
|
21796
|
-
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
21797
|
-
// We need to put it with an empty array manually to make it show up in client side
|
|
21798
|
-
return Object.assign({ myReactions: [] }, comment);
|
|
21799
|
-
}) });
|
|
21800
|
-
}
|
|
21801
|
-
|
|
21802
22023
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
21803
22024
|
constructor(query, callback) {
|
|
21804
22025
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -22151,17 +22372,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
22151
22372
|
}
|
|
22152
22373
|
}
|
|
22153
22374
|
|
|
22154
|
-
const preparePostPayload = (postPayload) => {
|
|
22155
|
-
const { posts } = postPayload;
|
|
22156
|
-
const { communities, communityUsers } = convertCommunityPayload({
|
|
22157
|
-
communities: postPayload.communities,
|
|
22158
|
-
communityUsers: postPayload.communityUsers,
|
|
22159
|
-
});
|
|
22160
|
-
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
22161
|
-
communities,
|
|
22162
|
-
communityUsers });
|
|
22163
|
-
};
|
|
22164
|
-
|
|
22165
22375
|
const getPost = async (postId) => {
|
|
22166
22376
|
const client = getActiveClient();
|
|
22167
22377
|
client.log('post/getPost', postId);
|
|
@@ -22358,6 +22568,138 @@ const getPosts = (params, callback, config) => {
|
|
|
22358
22568
|
};
|
|
22359
22569
|
/* end_public_function */
|
|
22360
22570
|
|
|
22571
|
+
class PinnedPostPaginationController extends PaginationController {
|
|
22572
|
+
async getRequest(queryParams, token) {
|
|
22573
|
+
const params = __rest(queryParams, ["limit"]);
|
|
22574
|
+
const { communityId, placement } = params;
|
|
22575
|
+
const path = placement
|
|
22576
|
+
? `/api/v1/pinned-posts/communities/${communityId}/${placement}`
|
|
22577
|
+
: `/api/v1/pinned-posts/communities/${communityId}`;
|
|
22578
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
22579
|
+
return queryResponse;
|
|
22580
|
+
}
|
|
22581
|
+
}
|
|
22582
|
+
|
|
22583
|
+
class PinnedPostQueryStreamController extends QueryStreamController {
|
|
22584
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
22585
|
+
super(query, cacheKey);
|
|
22586
|
+
this.notifyChange = notifyChange;
|
|
22587
|
+
this.preparePayload = preparePayload;
|
|
22588
|
+
}
|
|
22589
|
+
// eslint-disable-next-line class-methods-use-this
|
|
22590
|
+
async saveToMainDB(response) {
|
|
22591
|
+
const client = getActiveClient();
|
|
22592
|
+
const cachedAt = client.cache && Date.now();
|
|
22593
|
+
if (client.cache) {
|
|
22594
|
+
ingestInCache(response, { cachedAt });
|
|
22595
|
+
}
|
|
22596
|
+
}
|
|
22597
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
22598
|
+
var _a, _b;
|
|
22599
|
+
if (refresh) {
|
|
22600
|
+
pushToCache(this.cacheKey, {
|
|
22601
|
+
data: response.pins.map(getResolver('pin')),
|
|
22602
|
+
});
|
|
22603
|
+
}
|
|
22604
|
+
else {
|
|
22605
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22606
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22607
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
22608
|
+
this.notifyChange({
|
|
22609
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
22610
|
+
loading: false,
|
|
22611
|
+
});
|
|
22612
|
+
}
|
|
22613
|
+
}
|
|
22614
|
+
}
|
|
22615
|
+
|
|
22616
|
+
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
22617
|
+
constructor(query, callback) {
|
|
22618
|
+
const queryStreamId = hash__default["default"](query);
|
|
22619
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
22620
|
+
const paginationController = new PinnedPostPaginationController(query);
|
|
22621
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22622
|
+
this.query = query;
|
|
22623
|
+
this.queryStreamController = new PinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
22624
|
+
this.callback = callback.bind(this);
|
|
22625
|
+
this.loadPage({ initial: true });
|
|
22626
|
+
}
|
|
22627
|
+
setup() {
|
|
22628
|
+
var _a;
|
|
22629
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22630
|
+
if (!collection) {
|
|
22631
|
+
pushToCache(this.cacheKey, {
|
|
22632
|
+
data: [],
|
|
22633
|
+
params: {},
|
|
22634
|
+
});
|
|
22635
|
+
}
|
|
22636
|
+
}
|
|
22637
|
+
async persistModel(queryPayload) {
|
|
22638
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
22639
|
+
}
|
|
22640
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22641
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22642
|
+
}
|
|
22643
|
+
// eslint-disable-next-line class-methods-use-this
|
|
22644
|
+
startSubscription() {
|
|
22645
|
+
return [];
|
|
22646
|
+
}
|
|
22647
|
+
notifyChange({ origin, loading, error }) {
|
|
22648
|
+
var _a, _b;
|
|
22649
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22650
|
+
if (!collection)
|
|
22651
|
+
return;
|
|
22652
|
+
let data = ((_b = collection.data
|
|
22653
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
22654
|
+
.filter(isNonNullable)
|
|
22655
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
22656
|
+
data = this.applyFilter(data);
|
|
22657
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22658
|
+
return;
|
|
22659
|
+
this.callback({
|
|
22660
|
+
data,
|
|
22661
|
+
loading,
|
|
22662
|
+
error,
|
|
22663
|
+
});
|
|
22664
|
+
}
|
|
22665
|
+
applyFilter(data) {
|
|
22666
|
+
let pinnedPost = data;
|
|
22667
|
+
switch (this.query.sortBy) {
|
|
22668
|
+
case 'lastCreated':
|
|
22669
|
+
pinnedPost = pinnedPost.sort(({ post: postA }, { post: postB }) => sortByLastCreated({ createdAt: postA === null || postA === void 0 ? void 0 : postA.createdAt }, { createdAt: postB === null || postB === void 0 ? void 0 : postB.createdAt }));
|
|
22670
|
+
break;
|
|
22671
|
+
}
|
|
22672
|
+
return pinnedPost;
|
|
22673
|
+
}
|
|
22674
|
+
}
|
|
22675
|
+
|
|
22676
|
+
/**
|
|
22677
|
+
* Get pinned posts for a community
|
|
22678
|
+
*
|
|
22679
|
+
* @param communityId the ID of the community
|
|
22680
|
+
* @param placement the placement of the pinned post ('announcement' or 'default'), or null to fetch all pinned posts
|
|
22681
|
+
* @returns the associated pinned post(s)
|
|
22682
|
+
*
|
|
22683
|
+
* @category Pined Posts Live Collection
|
|
22684
|
+
*
|
|
22685
|
+
*/
|
|
22686
|
+
const getPinnedPosts = (params, callback, config) => {
|
|
22687
|
+
const { log, cache } = getActiveClient();
|
|
22688
|
+
if (!cache) {
|
|
22689
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
22690
|
+
}
|
|
22691
|
+
const timestamp = Date.now();
|
|
22692
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
22693
|
+
const pinnedPostLiveCollection = new PinnedPostLiveCollectionController(params, callback);
|
|
22694
|
+
const disposers = pinnedPostLiveCollection.startSubscription();
|
|
22695
|
+
const cacheKey = pinnedPostLiveCollection.getCacheKey();
|
|
22696
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
22697
|
+
return () => {
|
|
22698
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
22699
|
+
disposers.forEach(fn => fn());
|
|
22700
|
+
};
|
|
22701
|
+
};
|
|
22702
|
+
|
|
22361
22703
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
22362
22704
|
__proto__: null,
|
|
22363
22705
|
getPostByIds: getPostByIds,
|
|
@@ -22384,7 +22726,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
22384
22726
|
observePosts: observePosts,
|
|
22385
22727
|
observePost: observePost,
|
|
22386
22728
|
getPost: getPost$1,
|
|
22387
|
-
getPosts: getPosts
|
|
22729
|
+
getPosts: getPosts,
|
|
22730
|
+
getPinnedPosts: getPinnedPosts
|
|
22388
22731
|
});
|
|
22389
22732
|
|
|
22390
22733
|
/* begin_public_function
|
|
@@ -23278,7 +23621,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
23278
23621
|
getPoll: getPoll
|
|
23279
23622
|
});
|
|
23280
23623
|
|
|
23281
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
23624
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
23282
23625
|
/*
|
|
23283
23626
|
* The crypto algorithm used for importing key and signing string
|
|
23284
23627
|
*/
|