@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.esm.js
CHANGED
|
@@ -525,6 +525,8 @@ const idResolvers = {
|
|
|
525
525
|
storyTarget: ({ targetId }) => targetId,
|
|
526
526
|
ad: ({ adId }) => adId,
|
|
527
527
|
advertiser: ({ advertiserId }) => advertiserId,
|
|
528
|
+
pin: ({ referenceId }) => referenceId,
|
|
529
|
+
pinTarget: ({ targetId }) => targetId,
|
|
528
530
|
};
|
|
529
531
|
/**
|
|
530
532
|
* Retrieve the id resolver matching a domain name
|
|
@@ -574,6 +576,8 @@ const PAYLOAD2MODEL = {
|
|
|
574
576
|
feeds: 'feed',
|
|
575
577
|
ads: 'ad',
|
|
576
578
|
advertisers: 'advertiser',
|
|
579
|
+
pinTargets: 'pinTarget',
|
|
580
|
+
pins: 'pin',
|
|
577
581
|
};
|
|
578
582
|
/** hidden */
|
|
579
583
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -20807,6 +20811,31 @@ function __classPrivateFieldSet(receiver, state, value, kind, f) {
|
|
|
20807
20811
|
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
20808
20812
|
}
|
|
20809
20813
|
|
|
20814
|
+
/**
|
|
20815
|
+
* Attach user object to membership model
|
|
20816
|
+
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
20817
|
+
* - If user object is not found in cache, set user to undefined
|
|
20818
|
+
* ({..., user: undefined})
|
|
20819
|
+
* - If a user is found in the cache, it attaches the user from the cache
|
|
20820
|
+
* ({..., user: { userId, displayName,... }})
|
|
20821
|
+
*
|
|
20822
|
+
* @param member The membership model object
|
|
20823
|
+
* @returns The membership model object that is already mapped to user
|
|
20824
|
+
* @hidden
|
|
20825
|
+
*/
|
|
20826
|
+
const convertRawMembershipToMembership = (member) => {
|
|
20827
|
+
return Object.assign(Object.assign({}, member), { get user() {
|
|
20828
|
+
var _a;
|
|
20829
|
+
const client = getActiveClient();
|
|
20830
|
+
if (!client.cache)
|
|
20831
|
+
return undefined;
|
|
20832
|
+
const userCache = (_a = pullFromCache(['user', 'get', member.userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20833
|
+
if (!userCache) {
|
|
20834
|
+
return undefined;
|
|
20835
|
+
}
|
|
20836
|
+
return userCache;
|
|
20837
|
+
} });
|
|
20838
|
+
};
|
|
20810
20839
|
/**
|
|
20811
20840
|
* Attach user object to membership model
|
|
20812
20841
|
* - If cache is not enabled, set user to undefined ({..., user: undefined})
|
|
@@ -21920,6 +21949,31 @@ const adLinkedObject = (ad) => {
|
|
|
21920
21949
|
} });
|
|
21921
21950
|
};
|
|
21922
21951
|
|
|
21952
|
+
const pinnedPostLinkedObject = (pinnedPost) => {
|
|
21953
|
+
var _a;
|
|
21954
|
+
const postCached = pullFromCache(['post', 'get', pinnedPost.referenceId]);
|
|
21955
|
+
const pinnedBy = (_a = queryCache(['user', 'get']).find(cache => {
|
|
21956
|
+
var _a;
|
|
21957
|
+
return ((_a = cache.data) === null || _a === void 0 ? void 0 : _a.userInternalId) === pinnedPost.pinnedBy;
|
|
21958
|
+
})) === null || _a === void 0 ? void 0 : _a.data;
|
|
21959
|
+
return Object.assign(Object.assign({}, pinnedPost), { pinnedBy,
|
|
21960
|
+
get post() {
|
|
21961
|
+
if (!(postCached === null || postCached === void 0 ? void 0 : postCached.data))
|
|
21962
|
+
return;
|
|
21963
|
+
return postLinkedObject(postCached.data);
|
|
21964
|
+
},
|
|
21965
|
+
get target() {
|
|
21966
|
+
const pinTarget = pullFromCache([
|
|
21967
|
+
'pinTarget',
|
|
21968
|
+
'get',
|
|
21969
|
+
postCached === null || postCached === void 0 ? void 0 : postCached.data.targetId,
|
|
21970
|
+
]);
|
|
21971
|
+
if (!(pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data))
|
|
21972
|
+
return;
|
|
21973
|
+
return pinTarget === null || pinTarget === void 0 ? void 0 : pinTarget.data;
|
|
21974
|
+
} });
|
|
21975
|
+
};
|
|
21976
|
+
|
|
21923
21977
|
const LinkedObject = {
|
|
21924
21978
|
ad: adLinkedObject,
|
|
21925
21979
|
comment: commentLinkedObject,
|
|
@@ -21932,6 +21986,7 @@ const LinkedObject = {
|
|
|
21932
21986
|
message: messageLinkedObject,
|
|
21933
21987
|
reactor: reactorLinkedObject,
|
|
21934
21988
|
channel: channelLinkedObject,
|
|
21989
|
+
pinnedPost: pinnedPostLinkedObject,
|
|
21935
21990
|
};
|
|
21936
21991
|
|
|
21937
21992
|
const getChannelMessagePreviewWithUser = (channel) => {
|
|
@@ -22300,6 +22355,16 @@ const getChannelIsMentioned = (channel, marker) => {
|
|
|
22300
22355
|
: (_d = (_c = getCachedMarker(channel.channelPublicId)) === null || _c === void 0 ? void 0 : _c.hasMentioned) !== null && _d !== void 0 ? _d : false;
|
|
22301
22356
|
};
|
|
22302
22357
|
|
|
22358
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
22359
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: rawUser.isGlobalBan });
|
|
22360
|
+
}
|
|
22361
|
+
function prepareUserPayload(response) {
|
|
22362
|
+
return {
|
|
22363
|
+
users: response.users.map(convertRawUserToInternalUser),
|
|
22364
|
+
files: response.files,
|
|
22365
|
+
};
|
|
22366
|
+
}
|
|
22367
|
+
|
|
22303
22368
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
22304
22369
|
const isUnreadCountSupport$2 = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
22305
22370
|
function convertFromRaw$2(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -22357,9 +22422,13 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
22357
22422
|
// attach marker to channel
|
|
22358
22423
|
const channels = rawPayload.channels.map(payload => convertFromRaw$2(payload, { isMessagePreviewUpdated: options.isMessagePreviewUpdated }));
|
|
22359
22424
|
// user marker to channel users
|
|
22360
|
-
const channelUsers =
|
|
22425
|
+
const channelUsers = rawPayload.channelUsers.map(channelUser => {
|
|
22426
|
+
return convertRawMembershipToMembership(channelUser);
|
|
22427
|
+
});
|
|
22428
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
22361
22429
|
const restRawPayload = __rest(rawPayload, ["messageFeedsInfo", "messagePreviews"]);
|
|
22362
|
-
return Object.assign(Object.assign({}, restRawPayload), {
|
|
22430
|
+
return Object.assign(Object.assign({}, restRawPayload), { users,
|
|
22431
|
+
channels,
|
|
22363
22432
|
channelUsers });
|
|
22364
22433
|
};
|
|
22365
22434
|
|
|
@@ -23783,7 +23852,8 @@ const onChannelMemberBanned = (callback) => {
|
|
|
23783
23852
|
|
|
23784
23853
|
const createUserEventSubscriber = (event, callback) => {
|
|
23785
23854
|
const client = getActiveClient();
|
|
23786
|
-
const filter = (
|
|
23855
|
+
const filter = (data) => {
|
|
23856
|
+
const payload = prepareUserPayload(data);
|
|
23787
23857
|
if (client.cache) {
|
|
23788
23858
|
ingestInCache(payload);
|
|
23789
23859
|
}
|
|
@@ -26019,18 +26089,17 @@ const queryBlockedUsers = async (query) => {
|
|
|
26019
26089
|
const { data } = await client.http.get('/api/v4/me/user-blocks', {
|
|
26020
26090
|
params,
|
|
26021
26091
|
});
|
|
26022
|
-
const
|
|
26023
|
-
const { users } = blockedUsers;
|
|
26092
|
+
const payload = prepareUserPayload(data);
|
|
26024
26093
|
const cachedAt = client.cache && Date.now();
|
|
26025
26094
|
if (client.cache) {
|
|
26026
|
-
ingestInCache(
|
|
26095
|
+
ingestInCache(payload, { cachedAt });
|
|
26027
26096
|
const cacheKey = ['blockedUsers', 'query', params];
|
|
26028
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
26097
|
+
pushToCache(cacheKey, { users: payload.users.map(getResolver('user')), paging: data.paging });
|
|
26029
26098
|
}
|
|
26030
|
-
const { next, previous, total } = paging;
|
|
26099
|
+
const { next, previous, total } = data.paging;
|
|
26031
26100
|
const nextPage = toPageRaw(next);
|
|
26032
26101
|
const prevPage = toPageRaw(previous);
|
|
26033
|
-
return { data: users, prevPage, nextPage, total, cachedAt };
|
|
26102
|
+
return { data: payload.users, prevPage, nextPage, total, cachedAt };
|
|
26034
26103
|
};
|
|
26035
26104
|
/**
|
|
26036
26105
|
* ```js
|
|
@@ -27110,12 +27179,13 @@ const getUserByIds = async (userIds) => {
|
|
|
27110
27179
|
const { data } = await client.http.get(`/api/v3/users/list`, {
|
|
27111
27180
|
params: { userIds: encodedUserIds },
|
|
27112
27181
|
});
|
|
27182
|
+
const payload = prepareUserPayload(data);
|
|
27113
27183
|
const cachedAt = client.cache && Date.now();
|
|
27114
27184
|
if (client.cache)
|
|
27115
|
-
ingestInCache(
|
|
27185
|
+
ingestInCache(payload, { cachedAt });
|
|
27116
27186
|
fireEvent('user.fetched', data);
|
|
27117
27187
|
return {
|
|
27118
|
-
data:
|
|
27188
|
+
data: payload.users.map(user => LinkedObject.user(user)),
|
|
27119
27189
|
cachedAt,
|
|
27120
27190
|
};
|
|
27121
27191
|
};
|
|
@@ -27173,20 +27243,14 @@ getUserByIds.locally = (userIds) => {
|
|
|
27173
27243
|
const updateUser = async (userId, patch) => {
|
|
27174
27244
|
const client = getActiveClient();
|
|
27175
27245
|
client.log('user/updateUser', userId, patch);
|
|
27176
|
-
// API-FIX: Endpoint is malformed, userId should be a url param.
|
|
27177
|
-
/*
|
|
27178
|
-
const { data } = await client.http.put<Amity.Response<UserPayload>>(
|
|
27179
|
-
`/api/v3/users/${userId}`, patch,
|
|
27180
|
-
)
|
|
27181
|
-
*/
|
|
27182
27246
|
const { data } = await client.http.put(`/api/v3/users/`, Object.assign(Object.assign({ userId }, patch), { createNewUserWhenNotFound: false }));
|
|
27247
|
+
const payload = prepareUserPayload(data);
|
|
27183
27248
|
const cachedAt = client.cache && Date.now();
|
|
27184
27249
|
if (client.cache)
|
|
27185
|
-
ingestInCache(
|
|
27186
|
-
const { users } = data;
|
|
27250
|
+
ingestInCache(payload, { cachedAt });
|
|
27187
27251
|
fireEvent('user.updated', data);
|
|
27188
27252
|
return {
|
|
27189
|
-
data: users.find(user => user.userId === userId),
|
|
27253
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27190
27254
|
cachedAt,
|
|
27191
27255
|
};
|
|
27192
27256
|
};
|
|
@@ -27210,11 +27274,12 @@ const updateUser = async (userId, patch) => {
|
|
|
27210
27274
|
const flagUser = async (userId) => {
|
|
27211
27275
|
const client = getActiveClient();
|
|
27212
27276
|
client.log('user/flagUser', userId);
|
|
27213
|
-
const { data
|
|
27277
|
+
const { data } = await client.http.post(`api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27278
|
+
const payload = prepareUserPayload(data);
|
|
27214
27279
|
if (client.cache) {
|
|
27215
27280
|
ingestInCache(payload);
|
|
27216
27281
|
}
|
|
27217
|
-
fireEvent('user.flagged',
|
|
27282
|
+
fireEvent('user.flagged', data);
|
|
27218
27283
|
return !!payload;
|
|
27219
27284
|
};
|
|
27220
27285
|
/* end_public_function */
|
|
@@ -27237,11 +27302,12 @@ const flagUser = async (userId) => {
|
|
|
27237
27302
|
const unflagUser = async (userId) => {
|
|
27238
27303
|
const client = getActiveClient();
|
|
27239
27304
|
client.log('user/unflag', userId);
|
|
27240
|
-
const { data
|
|
27305
|
+
const { data } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(userId)}`);
|
|
27306
|
+
const payload = prepareUserPayload(data);
|
|
27241
27307
|
if (client.cache) {
|
|
27242
27308
|
ingestInCache(payload);
|
|
27243
27309
|
}
|
|
27244
|
-
fireEvent('user.unflagged',
|
|
27310
|
+
fireEvent('user.unflagged', data);
|
|
27245
27311
|
return !!payload;
|
|
27246
27312
|
};
|
|
27247
27313
|
/* end_public_function */
|
|
@@ -27372,10 +27438,17 @@ const getUser$2 = async (userId) => {
|
|
|
27372
27438
|
const client = getActiveClient();
|
|
27373
27439
|
client.log('user/getUser', userId);
|
|
27374
27440
|
isInTombstone('user', userId);
|
|
27375
|
-
let data;
|
|
27376
27441
|
try {
|
|
27377
|
-
const
|
|
27378
|
-
|
|
27442
|
+
const { data } = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
27443
|
+
const cachedAt = client.cache && Date.now();
|
|
27444
|
+
const payload = prepareUserPayload(data);
|
|
27445
|
+
if (client.cache)
|
|
27446
|
+
ingestInCache(payload, { cachedAt });
|
|
27447
|
+
fireEvent('user.fetched', data);
|
|
27448
|
+
return {
|
|
27449
|
+
data: payload.users.find(user => user.userId === userId),
|
|
27450
|
+
cachedAt,
|
|
27451
|
+
};
|
|
27379
27452
|
}
|
|
27380
27453
|
catch (error) {
|
|
27381
27454
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
@@ -27383,15 +27456,6 @@ const getUser$2 = async (userId) => {
|
|
|
27383
27456
|
}
|
|
27384
27457
|
throw error;
|
|
27385
27458
|
}
|
|
27386
|
-
const cachedAt = client.cache && Date.now();
|
|
27387
|
-
if (client.cache)
|
|
27388
|
-
ingestInCache(data, { cachedAt });
|
|
27389
|
-
const { users } = data;
|
|
27390
|
-
fireEvent('user.fetched', data);
|
|
27391
|
-
return {
|
|
27392
|
-
data: users.find(user => user.userId === userId),
|
|
27393
|
-
cachedAt,
|
|
27394
|
-
};
|
|
27395
27459
|
};
|
|
27396
27460
|
/**
|
|
27397
27461
|
* ```js
|
|
@@ -27457,114 +27521,312 @@ const getUser$1 = (userId, callback) => {
|
|
|
27457
27521
|
};
|
|
27458
27522
|
/* end_public_function */
|
|
27459
27523
|
|
|
27460
|
-
|
|
27461
|
-
|
|
27462
|
-
|
|
27463
|
-
|
|
27464
|
-
|
|
27465
|
-
*
|
|
27466
|
-
* Queries a paginable list of {@link Amity.InternalUser} objects
|
|
27467
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
27468
|
-
*
|
|
27469
|
-
* @param query The query parameters
|
|
27470
|
-
* @returns A page of {@link Amity.InternalUser} objects
|
|
27471
|
-
*
|
|
27472
|
-
* @category User API
|
|
27473
|
-
* @async
|
|
27474
|
-
*/
|
|
27475
|
-
const queryUsers = async (query = {}) => {
|
|
27476
|
-
const client = getActiveClient();
|
|
27477
|
-
client.log('user/queryUsers', query);
|
|
27478
|
-
const { page, limit = 10, displayName, filter = 'all', sortBy = 'displayName' } = query, params = __rest(query, ["page", "limit", "displayName", "filter", "sortBy"]);
|
|
27479
|
-
const { data } = await client.http.get(`/api/v3/users`, {
|
|
27480
|
-
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter,
|
|
27481
|
-
sortBy, options: page ? { token: page } : { limit } }),
|
|
27482
|
-
});
|
|
27483
|
-
// unpacking
|
|
27484
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
27485
|
-
const { users } = payload;
|
|
27486
|
-
const cachedAt = client.cache && Date.now();
|
|
27487
|
-
if (client.cache) {
|
|
27488
|
-
ingestInCache(payload, { cachedAt });
|
|
27489
|
-
/*
|
|
27490
|
-
* using a query as a cache key over params because if the keyword, filter, sort
|
|
27491
|
-
* change the API will NOT cache results, when it should
|
|
27492
|
-
*/
|
|
27493
|
-
const cacheKey = [
|
|
27494
|
-
'user',
|
|
27495
|
-
'query',
|
|
27496
|
-
Object.assign(Object.assign({}, query), { options: { limit, token: page } }),
|
|
27497
|
-
];
|
|
27498
|
-
pushToCache(cacheKey, { users: users.map(getResolver('user')), paging });
|
|
27524
|
+
class PaginationController {
|
|
27525
|
+
constructor(queryParams) {
|
|
27526
|
+
const { http } = getActiveClient();
|
|
27527
|
+
this.queryParams = queryParams;
|
|
27528
|
+
this.http = http;
|
|
27499
27529
|
}
|
|
27500
|
-
|
|
27501
|
-
|
|
27502
|
-
|
|
27503
|
-
|
|
27504
|
-
|
|
27505
|
-
}
|
|
27506
|
-
|
|
27507
|
-
|
|
27508
|
-
|
|
27509
|
-
|
|
27510
|
-
|
|
27511
|
-
|
|
27512
|
-
|
|
27513
|
-
|
|
27514
|
-
|
|
27515
|
-
|
|
27516
|
-
|
|
27517
|
-
|
|
27518
|
-
|
|
27519
|
-
|
|
27520
|
-
|
|
27521
|
-
|
|
27522
|
-
|
|
27523
|
-
|
|
27524
|
-
client.log('user/queryUsers.locally', query);
|
|
27525
|
-
if (!client.cache)
|
|
27526
|
-
return;
|
|
27527
|
-
const { limit = 10, page } = query !== null && query !== void 0 ? query : {};
|
|
27528
|
-
const cacheKey = [
|
|
27529
|
-
'user',
|
|
27530
|
-
'query',
|
|
27531
|
-
Object.assign(Object.assign({}, query), { options: {
|
|
27532
|
-
limit,
|
|
27533
|
-
token: page,
|
|
27534
|
-
} }),
|
|
27535
|
-
];
|
|
27536
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
27537
|
-
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 : [];
|
|
27538
|
-
return users.length > 0 && users.length === ((_c = data === null || data === void 0 ? void 0 : data.users) === null || _c === void 0 ? void 0 : _c.length)
|
|
27539
|
-
? {
|
|
27540
|
-
data: users,
|
|
27541
|
-
cachedAt,
|
|
27542
|
-
paging: data === null || data === void 0 ? void 0 : data.paging,
|
|
27530
|
+
loadFirstPage() {
|
|
27531
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
27532
|
+
}
|
|
27533
|
+
loadNextPage() {
|
|
27534
|
+
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
27535
|
+
}
|
|
27536
|
+
loadPreviousPage() {
|
|
27537
|
+
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
27538
|
+
}
|
|
27539
|
+
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
27540
|
+
var _a, _b, _c, _d;
|
|
27541
|
+
if (direction === 'prev' && !this.previousToken)
|
|
27542
|
+
return;
|
|
27543
|
+
if (direction === 'next' && !this.nextToken)
|
|
27544
|
+
return;
|
|
27545
|
+
let token;
|
|
27546
|
+
if (direction === 'prev')
|
|
27547
|
+
token = this.previousToken;
|
|
27548
|
+
if (direction === 'next')
|
|
27549
|
+
token = this.nextToken;
|
|
27550
|
+
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
27551
|
+
if (direction === 'first') {
|
|
27552
|
+
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
27553
|
+
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
27543
27554
|
}
|
|
27544
|
-
|
|
27545
|
-
|
|
27555
|
+
if (direction === 'prev')
|
|
27556
|
+
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
27557
|
+
if (direction === 'next')
|
|
27558
|
+
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
27559
|
+
return queryResponse;
|
|
27560
|
+
}
|
|
27561
|
+
getNextToken() {
|
|
27562
|
+
return this.nextToken;
|
|
27563
|
+
}
|
|
27564
|
+
getPrevToken() {
|
|
27565
|
+
return this.previousToken;
|
|
27566
|
+
}
|
|
27567
|
+
}
|
|
27546
27568
|
|
|
27547
|
-
|
|
27548
|
-
|
|
27549
|
-
|
|
27550
|
-
|
|
27551
|
-
const
|
|
27552
|
-
|
|
27553
|
-
|
|
27554
|
-
|
|
27555
|
-
users = users.sort(sortByFirstCreated);
|
|
27556
|
-
break;
|
|
27557
|
-
case 'lastCreated':
|
|
27558
|
-
users = users.sort(sortByLastCreated);
|
|
27559
|
-
break;
|
|
27560
|
-
default:
|
|
27561
|
-
users = users
|
|
27562
|
-
// this needs to be aligned with the backend data type
|
|
27563
|
-
.map(u => (u.displayName ? u : Object.assign(Object.assign({}, u), { displayName: '' })))
|
|
27564
|
-
.sort(sortByDisplayName);
|
|
27569
|
+
class UserPaginationController extends PaginationController {
|
|
27570
|
+
async getRequest(queryParams, token) {
|
|
27571
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
27572
|
+
const options = token ? { token } : { limit };
|
|
27573
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
27574
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
27575
|
+
});
|
|
27576
|
+
return queryResponse;
|
|
27565
27577
|
}
|
|
27566
|
-
|
|
27567
|
-
|
|
27578
|
+
}
|
|
27579
|
+
|
|
27580
|
+
class QueryStreamController {
|
|
27581
|
+
constructor(query, cacheKey) {
|
|
27582
|
+
this.query = query;
|
|
27583
|
+
this.cacheKey = cacheKey;
|
|
27584
|
+
}
|
|
27585
|
+
}
|
|
27586
|
+
|
|
27587
|
+
class UserQueryStreamController extends QueryStreamController {
|
|
27588
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27589
|
+
super(query, cacheKey);
|
|
27590
|
+
this.notifyChange = notifyChange;
|
|
27591
|
+
this.preparePayload = preparePayload;
|
|
27592
|
+
}
|
|
27593
|
+
async saveToMainDB(response) {
|
|
27594
|
+
const processedPayload = await this.preparePayload(response);
|
|
27595
|
+
const client = getActiveClient();
|
|
27596
|
+
const cachedAt = client.cache && Date.now();
|
|
27597
|
+
if (client.cache) {
|
|
27598
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27599
|
+
}
|
|
27600
|
+
}
|
|
27601
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27602
|
+
var _a, _b;
|
|
27603
|
+
if (refresh) {
|
|
27604
|
+
pushToCache(this.cacheKey, {
|
|
27605
|
+
data: response.users.map(getResolver('user')),
|
|
27606
|
+
});
|
|
27607
|
+
}
|
|
27608
|
+
else {
|
|
27609
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27610
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27611
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27612
|
+
}
|
|
27613
|
+
}
|
|
27614
|
+
reactor(action) {
|
|
27615
|
+
return (user) => {
|
|
27616
|
+
var _a;
|
|
27617
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27618
|
+
if (!collection)
|
|
27619
|
+
return;
|
|
27620
|
+
/*
|
|
27621
|
+
* Simply update a collection and let responder decide what to do with data
|
|
27622
|
+
*/
|
|
27623
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
27624
|
+
pushToCache(this.cacheKey, collection);
|
|
27625
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
27626
|
+
};
|
|
27627
|
+
}
|
|
27628
|
+
subscribeRTE(createSubscriber) {
|
|
27629
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
27630
|
+
}
|
|
27631
|
+
}
|
|
27632
|
+
|
|
27633
|
+
class PaginationNoPageController {
|
|
27634
|
+
constructor(queryParams) {
|
|
27635
|
+
const { http } = getActiveClient();
|
|
27636
|
+
this.queryParams = queryParams;
|
|
27637
|
+
this.http = http;
|
|
27638
|
+
}
|
|
27639
|
+
async onFetch() {
|
|
27640
|
+
const queryResponse = await this.getRequest(this.queryParams);
|
|
27641
|
+
return queryResponse;
|
|
27642
|
+
}
|
|
27643
|
+
}
|
|
27644
|
+
|
|
27645
|
+
class LiveCollectionController {
|
|
27646
|
+
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
27647
|
+
this.paginationController = paginationController;
|
|
27648
|
+
this.queryStreamId = queryStreamId;
|
|
27649
|
+
this.cacheKey = cacheKey;
|
|
27650
|
+
this.callback = callback;
|
|
27651
|
+
}
|
|
27652
|
+
async refresh() {
|
|
27653
|
+
try {
|
|
27654
|
+
let result;
|
|
27655
|
+
if (this.paginationController instanceof PaginationNoPageController) {
|
|
27656
|
+
result = await this.paginationController.onFetch();
|
|
27657
|
+
}
|
|
27658
|
+
else {
|
|
27659
|
+
result = await this.paginationController.loadFirstPage();
|
|
27660
|
+
}
|
|
27661
|
+
if (!result)
|
|
27662
|
+
return;
|
|
27663
|
+
await this.persistModel(result);
|
|
27664
|
+
this.persistQueryStream({
|
|
27665
|
+
response: result,
|
|
27666
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27667
|
+
refresh: true,
|
|
27668
|
+
});
|
|
27669
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27670
|
+
}
|
|
27671
|
+
catch (e) {
|
|
27672
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27673
|
+
}
|
|
27674
|
+
}
|
|
27675
|
+
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
27676
|
+
this.setup();
|
|
27677
|
+
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
27678
|
+
if (initial) {
|
|
27679
|
+
this.refresh();
|
|
27680
|
+
}
|
|
27681
|
+
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
27682
|
+
this.loadPrevPage();
|
|
27683
|
+
}
|
|
27684
|
+
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
27685
|
+
this.loadNextPage();
|
|
27686
|
+
}
|
|
27687
|
+
}
|
|
27688
|
+
async loadNextPage() {
|
|
27689
|
+
try {
|
|
27690
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
27691
|
+
return;
|
|
27692
|
+
const result = await this.paginationController.loadNextPage();
|
|
27693
|
+
if (!result)
|
|
27694
|
+
return;
|
|
27695
|
+
await this.persistModel(result);
|
|
27696
|
+
this.persistQueryStream({
|
|
27697
|
+
response: result,
|
|
27698
|
+
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
27699
|
+
});
|
|
27700
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27701
|
+
}
|
|
27702
|
+
catch (e) {
|
|
27703
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27704
|
+
}
|
|
27705
|
+
}
|
|
27706
|
+
async loadPrevPage() {
|
|
27707
|
+
try {
|
|
27708
|
+
if (this.paginationController instanceof PaginationNoPageController)
|
|
27709
|
+
return;
|
|
27710
|
+
const result = await this.paginationController.loadPreviousPage();
|
|
27711
|
+
if (!result)
|
|
27712
|
+
return;
|
|
27713
|
+
await this.persistModel(result);
|
|
27714
|
+
this.persistQueryStream({
|
|
27715
|
+
response: result,
|
|
27716
|
+
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
27717
|
+
});
|
|
27718
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
27719
|
+
}
|
|
27720
|
+
catch (e) {
|
|
27721
|
+
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
27722
|
+
}
|
|
27723
|
+
}
|
|
27724
|
+
shouldNotify(data) {
|
|
27725
|
+
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
27726
|
+
if (isEqual(this.snapshot, newData))
|
|
27727
|
+
return false;
|
|
27728
|
+
this.snapshot = newData;
|
|
27729
|
+
return true;
|
|
27730
|
+
}
|
|
27731
|
+
getCacheKey() {
|
|
27732
|
+
return this.cacheKey;
|
|
27733
|
+
}
|
|
27734
|
+
}
|
|
27735
|
+
|
|
27736
|
+
var EnumUserActions;
|
|
27737
|
+
(function (EnumUserActions) {
|
|
27738
|
+
EnumUserActions["OnUserDeleted"] = "onUserDeleted";
|
|
27739
|
+
EnumUserActions["OnUserUpdated"] = "onUserUpdated";
|
|
27740
|
+
EnumUserActions["OnUserFlagged"] = "onUserFlagged";
|
|
27741
|
+
EnumUserActions["OnUserUnflagged"] = "onUserUnflagged";
|
|
27742
|
+
EnumUserActions["OnUserFlagCleared"] = "onUserFlagCleared";
|
|
27743
|
+
})(EnumUserActions || (EnumUserActions = {}));
|
|
27744
|
+
|
|
27745
|
+
function isNonNullable(value) {
|
|
27746
|
+
return value != null;
|
|
27747
|
+
}
|
|
27748
|
+
|
|
27749
|
+
class UserLiveCollectionController extends LiveCollectionController {
|
|
27750
|
+
constructor(query, callback) {
|
|
27751
|
+
const queryStreamId = hash(query);
|
|
27752
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
27753
|
+
const paginationController = new UserPaginationController(query);
|
|
27754
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
27755
|
+
this.query = query;
|
|
27756
|
+
this.queryStreamController = new UserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
27757
|
+
this.callback = callback.bind(this);
|
|
27758
|
+
this.loadPage({ initial: true });
|
|
27759
|
+
}
|
|
27760
|
+
setup() {
|
|
27761
|
+
var _a;
|
|
27762
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27763
|
+
if (!collection) {
|
|
27764
|
+
pushToCache(this.cacheKey, {
|
|
27765
|
+
data: [],
|
|
27766
|
+
params: {},
|
|
27767
|
+
});
|
|
27768
|
+
}
|
|
27769
|
+
}
|
|
27770
|
+
async persistModel(queryPayload) {
|
|
27771
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
27772
|
+
}
|
|
27773
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
27774
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
27775
|
+
}
|
|
27776
|
+
startSubscription() {
|
|
27777
|
+
return this.queryStreamController.subscribeRTE([
|
|
27778
|
+
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
27779
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
27780
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
27781
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
27782
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
27783
|
+
]);
|
|
27784
|
+
}
|
|
27785
|
+
notifyChange({ origin, loading, error }) {
|
|
27786
|
+
var _a, _b;
|
|
27787
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27788
|
+
if (!collection)
|
|
27789
|
+
return;
|
|
27790
|
+
const data = this.applyFilter((_b = collection.data
|
|
27791
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
27792
|
+
.filter(isNonNullable)
|
|
27793
|
+
.map(({ data }) => data)
|
|
27794
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
27795
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
27796
|
+
return;
|
|
27797
|
+
this.callback({
|
|
27798
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
27799
|
+
data,
|
|
27800
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
27801
|
+
loading,
|
|
27802
|
+
error,
|
|
27803
|
+
});
|
|
27804
|
+
}
|
|
27805
|
+
applyFilter(data) {
|
|
27806
|
+
let users = data;
|
|
27807
|
+
if (!this.query.displayName) {
|
|
27808
|
+
const sortFn = (() => {
|
|
27809
|
+
switch (this.query.sortBy) {
|
|
27810
|
+
case Amity.UserSortByEnum.FirstCreated:
|
|
27811
|
+
return sortByFirstCreated;
|
|
27812
|
+
case Amity.UserSortByEnum.LastCreated:
|
|
27813
|
+
return sortByLastCreated;
|
|
27814
|
+
case Amity.UserSortByEnum.DisplayName:
|
|
27815
|
+
return sortByDisplayName;
|
|
27816
|
+
default:
|
|
27817
|
+
return sortByLastCreated;
|
|
27818
|
+
}
|
|
27819
|
+
})();
|
|
27820
|
+
users = users.sort(sortFn);
|
|
27821
|
+
}
|
|
27822
|
+
if (this.query.filter === 'flagged') {
|
|
27823
|
+
users = users.filter(user => !!user.hashFlag);
|
|
27824
|
+
}
|
|
27825
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
27826
|
+
return users;
|
|
27827
|
+
}
|
|
27828
|
+
}
|
|
27829
|
+
|
|
27568
27830
|
/* begin_public_function
|
|
27569
27831
|
id: user.query
|
|
27570
27832
|
*/
|
|
@@ -27592,63 +27854,10 @@ const getUsers = (params, callback, config) => {
|
|
|
27592
27854
|
}
|
|
27593
27855
|
const timestamp = Date.now();
|
|
27594
27856
|
log(`liveUsers(tmpid: ${timestamp}) > listen`);
|
|
27595
|
-
const
|
|
27596
|
-
const
|
|
27597
|
-
const
|
|
27598
|
-
|
|
27599
|
-
const cacheKey = ['user', 'collection', uuid()];
|
|
27600
|
-
const responder = (data, isEventModel = false) => {
|
|
27601
|
-
var _a, _b;
|
|
27602
|
-
const users = (_a = data.data
|
|
27603
|
-
.map(userId => pullFromCache(['user', 'get', userId]))
|
|
27604
|
-
.filter(Boolean)
|
|
27605
|
-
.map(({ data }) => LinkedObject.user(data))) !== null && _a !== void 0 ? _a : [];
|
|
27606
|
-
callback({
|
|
27607
|
-
onNextPage: onFetch,
|
|
27608
|
-
/*
|
|
27609
|
-
* Only apply filter to RTE Model
|
|
27610
|
-
*/
|
|
27611
|
-
data: isEventModel ? applyFilter$2(users, params) : users,
|
|
27612
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
27613
|
-
loading: data.loading,
|
|
27614
|
-
error: data.error,
|
|
27615
|
-
});
|
|
27616
|
-
};
|
|
27617
|
-
const realtimeRouter = (_) => (user) => {
|
|
27618
|
-
var _a;
|
|
27619
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27620
|
-
if (!collection)
|
|
27621
|
-
return;
|
|
27622
|
-
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
27623
|
-
pushToCache(cacheKey, collection);
|
|
27624
|
-
responder(collection, true);
|
|
27625
|
-
};
|
|
27626
|
-
const onFetch = (initial = false) => {
|
|
27627
|
-
var _a, _b;
|
|
27628
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27629
|
-
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27630
|
-
if (!initial && users.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
27631
|
-
return;
|
|
27632
|
-
const pagingCondition = initial ? { limit } : { page: collection === null || collection === void 0 ? void 0 : collection.params.page };
|
|
27633
|
-
const query = createQuery(queryUsers, Object.assign(Object.assign({}, queryParams), pagingCondition));
|
|
27634
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
27635
|
-
const data = {
|
|
27636
|
-
loading,
|
|
27637
|
-
error,
|
|
27638
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
27639
|
-
data: users,
|
|
27640
|
-
};
|
|
27641
|
-
if (result) {
|
|
27642
|
-
data.data = initial
|
|
27643
|
-
? result.map(getResolver('user'))
|
|
27644
|
-
: [...new Set([...users, ...result.map(getResolver('user'))])];
|
|
27645
|
-
}
|
|
27646
|
-
pushToCache(cacheKey, data);
|
|
27647
|
-
responder(data);
|
|
27648
|
-
}, queryOptions(policy));
|
|
27649
|
-
};
|
|
27650
|
-
disposers.push(onUserUpdated(realtimeRouter()), onUserDeleted(realtimeRouter()), onUserFlagged(realtimeRouter()), onUserUnflagged(realtimeRouter()), onUserFlagCleared(realtimeRouter()));
|
|
27651
|
-
onFetch(true);
|
|
27857
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
27858
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
27859
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
27860
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
27652
27861
|
return () => {
|
|
27653
27862
|
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
27654
27863
|
disposers.forEach(fn => fn());
|
|
@@ -27671,27 +27880,9 @@ const getUsers = (params, callback, config) => {
|
|
|
27671
27880
|
* @async
|
|
27672
27881
|
*/
|
|
27673
27882
|
const getUser = async (userId) => {
|
|
27674
|
-
const
|
|
27675
|
-
client.log('user/getUser', userId);
|
|
27676
|
-
isInTombstone('user', userId);
|
|
27677
|
-
let data;
|
|
27678
|
-
try {
|
|
27679
|
-
const response = await client.http.get(`/api/v3/users/${encodeURIComponent(userId)}`);
|
|
27680
|
-
data = response.data;
|
|
27681
|
-
}
|
|
27682
|
-
catch (error) {
|
|
27683
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
27684
|
-
pushToTombstone('user', userId);
|
|
27685
|
-
}
|
|
27686
|
-
throw error;
|
|
27687
|
-
}
|
|
27688
|
-
const cachedAt = client.cache && Date.now();
|
|
27689
|
-
if (client.cache)
|
|
27690
|
-
ingestInCache(data, { cachedAt });
|
|
27691
|
-
const { users } = data;
|
|
27692
|
-
fireEvent('user.fetched', data);
|
|
27883
|
+
const { data, cachedAt } = await getUser$2(userId);
|
|
27693
27884
|
return {
|
|
27694
|
-
data: LinkedObject.user(
|
|
27885
|
+
data: LinkedObject.user(data),
|
|
27695
27886
|
cachedAt,
|
|
27696
27887
|
};
|
|
27697
27888
|
};
|
|
@@ -27709,11 +27900,7 @@ const getUser = async (userId) => {
|
|
|
27709
27900
|
* @category User API
|
|
27710
27901
|
*/
|
|
27711
27902
|
getUser.locally = (userId) => {
|
|
27712
|
-
const
|
|
27713
|
-
client.log('user/getUser.locally', userId);
|
|
27714
|
-
if (!client.cache)
|
|
27715
|
-
return;
|
|
27716
|
-
const cached = pullFromCache(['user', 'get', userId]);
|
|
27903
|
+
const cached = getUser$2.locally(userId);
|
|
27717
27904
|
if (!cached)
|
|
27718
27905
|
return;
|
|
27719
27906
|
return {
|
|
@@ -27763,6 +27950,130 @@ const observeUser = (userId, callback) => {
|
|
|
27763
27950
|
};
|
|
27764
27951
|
};
|
|
27765
27952
|
|
|
27953
|
+
class SearchUserPaginationController extends PaginationController {
|
|
27954
|
+
async getRequest(queryParams, token) {
|
|
27955
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
27956
|
+
const options = token ? { token } : { limit };
|
|
27957
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/users`, {
|
|
27958
|
+
params: Object.assign(Object.assign({}, params), { keyword: displayName, options, isDeleted: false }),
|
|
27959
|
+
});
|
|
27960
|
+
return queryResponse;
|
|
27961
|
+
}
|
|
27962
|
+
}
|
|
27963
|
+
|
|
27964
|
+
class SearchUserQueryStreamController extends QueryStreamController {
|
|
27965
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
27966
|
+
super(query, cacheKey);
|
|
27967
|
+
this.notifyChange = notifyChange;
|
|
27968
|
+
this.preparePayload = preparePayload;
|
|
27969
|
+
}
|
|
27970
|
+
async saveToMainDB(response) {
|
|
27971
|
+
const processedPayload = await this.preparePayload(response);
|
|
27972
|
+
const client = getActiveClient();
|
|
27973
|
+
const cachedAt = client.cache && Date.now();
|
|
27974
|
+
if (client.cache) {
|
|
27975
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
27976
|
+
}
|
|
27977
|
+
}
|
|
27978
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
27979
|
+
var _a, _b;
|
|
27980
|
+
if (refresh) {
|
|
27981
|
+
pushToCache(this.cacheKey, {
|
|
27982
|
+
data: response.users.map(getResolver('user')),
|
|
27983
|
+
});
|
|
27984
|
+
}
|
|
27985
|
+
else {
|
|
27986
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27987
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
27988
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
27989
|
+
}
|
|
27990
|
+
}
|
|
27991
|
+
reactor(action) {
|
|
27992
|
+
return (user) => {
|
|
27993
|
+
var _a;
|
|
27994
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
27995
|
+
if (!collection)
|
|
27996
|
+
return;
|
|
27997
|
+
/*
|
|
27998
|
+
* Simply update a collection and let responder decide what to do with data
|
|
27999
|
+
*/
|
|
28000
|
+
collection.data = [...new Set([user.userId, ...collection.data])];
|
|
28001
|
+
pushToCache(this.cacheKey, collection);
|
|
28002
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28003
|
+
};
|
|
28004
|
+
}
|
|
28005
|
+
subscribeRTE(createSubscriber) {
|
|
28006
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28007
|
+
}
|
|
28008
|
+
}
|
|
28009
|
+
|
|
28010
|
+
class SearchUserLiveCollectionController extends LiveCollectionController {
|
|
28011
|
+
constructor(query, callback) {
|
|
28012
|
+
var _a;
|
|
28013
|
+
const queryStreamId = hash(query);
|
|
28014
|
+
const cacheKey = ['user', 'collection', queryStreamId];
|
|
28015
|
+
const paginationController = new SearchUserPaginationController(query);
|
|
28016
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
28017
|
+
this.query = Object.assign(Object.assign({}, query), { filter: (_a = query.filter) !== null && _a !== void 0 ? _a : 'all' });
|
|
28018
|
+
this.queryStreamController = new SearchUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareUserPayload);
|
|
28019
|
+
this.callback = callback.bind(this);
|
|
28020
|
+
this.loadPage({ initial: true });
|
|
28021
|
+
}
|
|
28022
|
+
setup() {
|
|
28023
|
+
var _a;
|
|
28024
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28025
|
+
if (!collection) {
|
|
28026
|
+
pushToCache(this.cacheKey, {
|
|
28027
|
+
data: [],
|
|
28028
|
+
params: {},
|
|
28029
|
+
});
|
|
28030
|
+
}
|
|
28031
|
+
}
|
|
28032
|
+
async persistModel(queryPayload) {
|
|
28033
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
28034
|
+
}
|
|
28035
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28036
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28037
|
+
}
|
|
28038
|
+
startSubscription() {
|
|
28039
|
+
return this.queryStreamController.subscribeRTE([
|
|
28040
|
+
{ fn: onUserDeleted, action: EnumUserActions.OnUserDeleted },
|
|
28041
|
+
{ fn: onUserUpdated, action: EnumUserActions.OnUserUpdated },
|
|
28042
|
+
{ fn: onUserFlagged, action: EnumUserActions.OnUserFlagged },
|
|
28043
|
+
{ fn: onUserUnflagged, action: EnumUserActions.OnUserUnflagged },
|
|
28044
|
+
{ fn: onUserFlagCleared, action: EnumUserActions.OnUserFlagCleared },
|
|
28045
|
+
]);
|
|
28046
|
+
}
|
|
28047
|
+
notifyChange({ origin, loading, error }) {
|
|
28048
|
+
var _a, _b;
|
|
28049
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28050
|
+
if (!collection)
|
|
28051
|
+
return;
|
|
28052
|
+
const data = this.applyFilter((_b = collection.data
|
|
28053
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
28054
|
+
.filter(isNonNullable)
|
|
28055
|
+
.map(({ data }) => data)
|
|
28056
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
28057
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28058
|
+
return;
|
|
28059
|
+
this.callback({
|
|
28060
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28061
|
+
data,
|
|
28062
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28063
|
+
loading,
|
|
28064
|
+
error,
|
|
28065
|
+
});
|
|
28066
|
+
}
|
|
28067
|
+
applyFilter(data) {
|
|
28068
|
+
let users = data;
|
|
28069
|
+
if (this.query.filter === 'flagged') {
|
|
28070
|
+
users = users.filter(user => !!user.hashFlag);
|
|
28071
|
+
}
|
|
28072
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
28073
|
+
return users;
|
|
28074
|
+
}
|
|
28075
|
+
}
|
|
28076
|
+
|
|
27766
28077
|
/* begin_public_function
|
|
27767
28078
|
id: user.search
|
|
27768
28079
|
*/
|
|
@@ -27784,7 +28095,21 @@ const observeUser = (userId, callback) => {
|
|
|
27784
28095
|
* @category Category Live Collection
|
|
27785
28096
|
*/
|
|
27786
28097
|
const searchUserByDisplayName = (params, callback, config) => {
|
|
27787
|
-
|
|
28098
|
+
const { log, cache } = getActiveClient();
|
|
28099
|
+
if (!cache) {
|
|
28100
|
+
// eslint-disable-next-line no-console
|
|
28101
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28102
|
+
}
|
|
28103
|
+
const timestamp = Date.now();
|
|
28104
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > listen`);
|
|
28105
|
+
const searchUsersLiveCollection = new SearchUserLiveCollectionController(params, callback);
|
|
28106
|
+
const disposers = searchUsersLiveCollection.startSubscription();
|
|
28107
|
+
const cacheKey = searchUsersLiveCollection.getCacheKey();
|
|
28108
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28109
|
+
return () => {
|
|
28110
|
+
log(`liveSearchUsers(tmpid: ${timestamp}) > dispose`);
|
|
28111
|
+
disposers.forEach(fn => fn());
|
|
28112
|
+
};
|
|
27788
28113
|
};
|
|
27789
28114
|
/* end_public_function */
|
|
27790
28115
|
|
|
@@ -29849,29 +30174,98 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
29849
30174
|
getReactions: getReactions
|
|
29850
30175
|
});
|
|
29851
30176
|
|
|
29852
|
-
|
|
29853
|
-
|
|
29854
|
-
|
|
29855
|
-
|
|
29856
|
-
|
|
29857
|
-
|
|
29858
|
-
|
|
29859
|
-
|
|
29860
|
-
|
|
29861
|
-
|
|
29862
|
-
|
|
29863
|
-
|
|
29864
|
-
|
|
29865
|
-
|
|
29866
|
-
|
|
29867
|
-
|
|
29868
|
-
|
|
29869
|
-
|
|
29870
|
-
|
|
29871
|
-
|
|
29872
|
-
|
|
30177
|
+
const getMatchPostSetting = (value) => {
|
|
30178
|
+
var _a;
|
|
30179
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
30180
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
30181
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
30182
|
+
};
|
|
30183
|
+
function addPostSetting({ communities }) {
|
|
30184
|
+
return communities.map((_a) => {
|
|
30185
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
30186
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
30187
|
+
needApprovalOnPostCreation,
|
|
30188
|
+
onlyAdminCanPost,
|
|
30189
|
+
}) }, restCommunityPayload));
|
|
30190
|
+
});
|
|
30191
|
+
}
|
|
30192
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
30193
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
30194
|
+
// map users with community
|
|
30195
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
30196
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
30197
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30198
|
+
});
|
|
30199
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30200
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
30201
|
+
};
|
|
30202
|
+
const prepareCommunityRequest = (params) => {
|
|
30203
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
30204
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
30205
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
30206
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
30207
|
+
};
|
|
30208
|
+
|
|
30209
|
+
const preparePostPayload = (postPayload) => {
|
|
30210
|
+
const { posts } = postPayload;
|
|
30211
|
+
// Unpack community payload by mapping payload field to postSetting value.
|
|
30212
|
+
const communitiesWithPostSetting = addPostSetting({ communities: postPayload.communities });
|
|
30213
|
+
// map users with community
|
|
30214
|
+
const mappedCommunityUsers = postPayload.communityUsers.map(communityUser => {
|
|
30215
|
+
const user = postPayload.users.find(user => user.userId === communityUser.userId);
|
|
30216
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30217
|
+
});
|
|
30218
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30219
|
+
return Object.assign(Object.assign({}, postPayload), { posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
29873
30220
|
};
|
|
29874
30221
|
|
|
30222
|
+
function prepareCommentPayload(commentPayload) {
|
|
30223
|
+
const { comments } = commentPayload;
|
|
30224
|
+
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
30225
|
+
if (comment.hasOwnProperty('myReactions'))
|
|
30226
|
+
return comment;
|
|
30227
|
+
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
30228
|
+
// We need to put it with an empty array manually to make it show up in client side
|
|
30229
|
+
return Object.assign({ myReactions: [] }, comment);
|
|
30230
|
+
}) });
|
|
30231
|
+
}
|
|
30232
|
+
|
|
30233
|
+
const createMessageReport = async ({ client, referenceId, }) => {
|
|
30234
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30235
|
+
if (client.cache) {
|
|
30236
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30237
|
+
ingestInCache(messagePayload);
|
|
30238
|
+
}
|
|
30239
|
+
fireEvent(`message.flagged`, payload);
|
|
30240
|
+
return !!payload;
|
|
30241
|
+
};
|
|
30242
|
+
const createPostReport = async ({ client, referenceId, }) => {
|
|
30243
|
+
const { data: payload } = await client.http.post(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30244
|
+
if (client.cache) {
|
|
30245
|
+
const postPayload = await preparePostPayload(payload);
|
|
30246
|
+
ingestInCache(postPayload);
|
|
30247
|
+
}
|
|
30248
|
+
fireEvent(`post.flagged`, payload);
|
|
30249
|
+
return !!payload;
|
|
30250
|
+
};
|
|
30251
|
+
const createUserReport = async ({ client, referenceId, }) => {
|
|
30252
|
+
const { data: payload } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30253
|
+
if (client.cache) {
|
|
30254
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30255
|
+
ingestInCache(userPayload);
|
|
30256
|
+
}
|
|
30257
|
+
fireEvent(`user.flagged`, payload);
|
|
30258
|
+
return !!payload;
|
|
30259
|
+
};
|
|
30260
|
+
const createCommentReport = async ({ client, referenceId, }) => {
|
|
30261
|
+
const { data: payload } = await client.http.post(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30262
|
+
if (client.cache) {
|
|
30263
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30264
|
+
ingestInCache(commentPayload);
|
|
30265
|
+
}
|
|
30266
|
+
fireEvent(`comment.flagged`, payload);
|
|
30267
|
+
return !!payload;
|
|
30268
|
+
};
|
|
29875
30269
|
/**
|
|
29876
30270
|
* ```js
|
|
29877
30271
|
* import { createReport } from '@amityco/ts-sdk'
|
|
@@ -29888,33 +30282,57 @@ var REFERENCE_TYPES = {
|
|
|
29888
30282
|
const createReport = async (referenceType, referenceId) => {
|
|
29889
30283
|
const client = getActiveClient();
|
|
29890
30284
|
client.log('report/createReport', { referenceType, referenceId });
|
|
29891
|
-
|
|
29892
|
-
|
|
29893
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
29894
|
-
}
|
|
29895
|
-
if (referenceType === 'message') {
|
|
29896
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
29897
|
-
}
|
|
29898
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
29899
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/flag`;
|
|
29900
|
-
};
|
|
29901
|
-
const { data: payload } = await client.http.post(getAPIUrl());
|
|
29902
|
-
if (client.cache) {
|
|
29903
|
-
if (referenceType === 'message') {
|
|
29904
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
29905
|
-
ingestInCache(messagePayload);
|
|
29906
|
-
}
|
|
29907
|
-
else if (referenceType === 'post') {
|
|
29908
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
29909
|
-
}
|
|
29910
|
-
else {
|
|
29911
|
-
ingestInCache(payload);
|
|
29912
|
-
}
|
|
30285
|
+
if (referenceType === 'user') {
|
|
30286
|
+
return createUserReport({ client, referenceId });
|
|
29913
30287
|
}
|
|
29914
|
-
|
|
29915
|
-
|
|
30288
|
+
if (referenceType === 'message') {
|
|
30289
|
+
return createMessageReport({ client, referenceId });
|
|
30290
|
+
}
|
|
30291
|
+
if (referenceType === 'post') {
|
|
30292
|
+
return createPostReport({ client, referenceId });
|
|
30293
|
+
}
|
|
30294
|
+
if (referenceType === 'comment') {
|
|
30295
|
+
return createCommentReport({ client, referenceId });
|
|
30296
|
+
}
|
|
30297
|
+
return false;
|
|
29916
30298
|
};
|
|
29917
30299
|
|
|
30300
|
+
const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
30301
|
+
const { data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30302
|
+
if (client.cache) {
|
|
30303
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
30304
|
+
ingestInCache(messagePayload);
|
|
30305
|
+
}
|
|
30306
|
+
fireEvent(`message.unflagged`, payload);
|
|
30307
|
+
return !!payload;
|
|
30308
|
+
};
|
|
30309
|
+
const deletePostReport = async ({ client, referenceId, }) => {
|
|
30310
|
+
const { data: payload } = await client.http.delete(`/api/v3/post/${encodeURIComponent(referenceId)}/flag`);
|
|
30311
|
+
if (client.cache) {
|
|
30312
|
+
const postPayload = await preparePostPayload(payload);
|
|
30313
|
+
ingestInCache(postPayload);
|
|
30314
|
+
}
|
|
30315
|
+
fireEvent(`post.unflagged`, payload);
|
|
30316
|
+
return !!payload;
|
|
30317
|
+
};
|
|
30318
|
+
const deleteUserReport = async ({ client, referenceId, }) => {
|
|
30319
|
+
const { data: payload } = await client.http.delete(`/api/v4/me/flags/${encodeURIComponent(referenceId)}`);
|
|
30320
|
+
if (client.cache) {
|
|
30321
|
+
const userPayload = await prepareUserPayload(payload);
|
|
30322
|
+
ingestInCache(userPayload);
|
|
30323
|
+
}
|
|
30324
|
+
fireEvent(`user.unflagged`, payload);
|
|
30325
|
+
return !!payload;
|
|
30326
|
+
};
|
|
30327
|
+
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
30328
|
+
const { data: payload } = await client.http.delete(`/api/v3/comment/${encodeURIComponent(referenceId)}/flag`);
|
|
30329
|
+
if (client.cache) {
|
|
30330
|
+
const commentPayload = await prepareCommentPayload(payload);
|
|
30331
|
+
ingestInCache(commentPayload);
|
|
30332
|
+
}
|
|
30333
|
+
fireEvent(`comment.unflagged`, payload);
|
|
30334
|
+
return !!payload;
|
|
30335
|
+
};
|
|
29918
30336
|
/**
|
|
29919
30337
|
* ```js
|
|
29920
30338
|
* import { deleteReport } from '@amityco/ts-sdk'
|
|
@@ -29931,34 +30349,45 @@ const createReport = async (referenceType, referenceId) => {
|
|
|
29931
30349
|
const deleteReport = async (referenceType, referenceId) => {
|
|
29932
30350
|
const client = getActiveClient();
|
|
29933
30351
|
client.log('report/deleteReport', { referenceType, referenceId });
|
|
29934
|
-
|
|
29935
|
-
|
|
29936
|
-
return `/api/v4/me/flags/${encodeURIComponent(referenceId)}`;
|
|
29937
|
-
}
|
|
29938
|
-
if (referenceType === 'message') {
|
|
29939
|
-
return `/api/v5/messages/${encodeURIComponent(referenceId)}/flags`;
|
|
29940
|
-
}
|
|
29941
|
-
const { domainName } = REFERENCE_TYPES[referenceType];
|
|
29942
|
-
return `/api/v3/${domainName}/${encodeURIComponent(referenceId)}/unflag`;
|
|
29943
|
-
};
|
|
29944
|
-
const { data: payload } = await client.http.delete(getAPIUrl());
|
|
29945
|
-
if (client.cache) {
|
|
29946
|
-
if (referenceType === 'message') {
|
|
29947
|
-
const messagePayload = await prepareMessagePayload(payload);
|
|
29948
|
-
ingestInCache(messagePayload);
|
|
29949
|
-
}
|
|
29950
|
-
else if (referenceType === 'post') {
|
|
29951
|
-
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
29952
|
-
}
|
|
29953
|
-
else {
|
|
29954
|
-
ingestInCache(payload);
|
|
29955
|
-
}
|
|
30352
|
+
if (referenceType === 'user') {
|
|
30353
|
+
return deleteUserReport({ client, referenceId });
|
|
29956
30354
|
}
|
|
29957
|
-
|
|
29958
|
-
|
|
29959
|
-
|
|
30355
|
+
if (referenceType === 'message') {
|
|
30356
|
+
return deleteMessageReport({ client, referenceId });
|
|
30357
|
+
}
|
|
30358
|
+
if (referenceType === 'post') {
|
|
30359
|
+
return deletePostReport({ client, referenceId });
|
|
30360
|
+
}
|
|
30361
|
+
if (referenceType === 'comment') {
|
|
30362
|
+
return deleteCommentReport({ client, referenceId });
|
|
30363
|
+
}
|
|
30364
|
+
return false;
|
|
29960
30365
|
};
|
|
29961
30366
|
|
|
30367
|
+
const getMessageReport = async ({ client, referenceId, }) => {
|
|
30368
|
+
var _a;
|
|
30369
|
+
const { data } = await client.http.get(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
30370
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30371
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30372
|
+
};
|
|
30373
|
+
const getPostReport = async ({ client, referenceId, }) => {
|
|
30374
|
+
var _a;
|
|
30375
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30376
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30377
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30378
|
+
};
|
|
30379
|
+
const getUserReport = async ({ client, referenceId, }) => {
|
|
30380
|
+
var _a;
|
|
30381
|
+
const { data } = await client.http.get(`/api/v3/user/${referenceId}/isflagbyme`);
|
|
30382
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30383
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30384
|
+
};
|
|
30385
|
+
const getCommentReport = async ({ client, referenceId, }) => {
|
|
30386
|
+
var _a;
|
|
30387
|
+
const { data } = await client.http.get(`/api/v3/comment/${referenceId}/isflagbyme`);
|
|
30388
|
+
const { result, isFlagByMe } = data !== null && data !== void 0 ? data : {};
|
|
30389
|
+
return (_a = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _a !== void 0 ? _a : false;
|
|
30390
|
+
};
|
|
29962
30391
|
/**
|
|
29963
30392
|
* ```js
|
|
29964
30393
|
* import { isReportedByMe } from '@amityco/ts-sdk'
|
|
@@ -29973,17 +30402,21 @@ const deleteReport = async (referenceType, referenceId) => {
|
|
|
29973
30402
|
* @async
|
|
29974
30403
|
* */
|
|
29975
30404
|
const isReportedByMe = async (referenceType, referenceId) => {
|
|
29976
|
-
var _a;
|
|
29977
30405
|
const client = getActiveClient();
|
|
29978
30406
|
client.log('report/isReportedByMe', { referenceType, referenceId });
|
|
29979
|
-
|
|
30407
|
+
if (referenceType === 'user') {
|
|
30408
|
+
return getUserReport({ client, referenceId });
|
|
30409
|
+
}
|
|
29980
30410
|
if (referenceType === 'message') {
|
|
29981
|
-
|
|
29982
|
-
return data.result;
|
|
30411
|
+
return getMessageReport({ client, referenceId });
|
|
29983
30412
|
}
|
|
29984
|
-
|
|
29985
|
-
|
|
29986
|
-
|
|
30413
|
+
if (referenceType === 'post') {
|
|
30414
|
+
return getPostReport({ client, referenceId });
|
|
30415
|
+
}
|
|
30416
|
+
if (referenceType === 'comment') {
|
|
30417
|
+
return getCommentReport({ client, referenceId });
|
|
30418
|
+
}
|
|
30419
|
+
return false;
|
|
29987
30420
|
};
|
|
29988
30421
|
|
|
29989
30422
|
/* begin_public_function
|
|
@@ -31504,116 +31937,6 @@ const getMessage$1 = (messageId, callback) => {
|
|
|
31504
31937
|
};
|
|
31505
31938
|
/* end_public_function */
|
|
31506
31939
|
|
|
31507
|
-
class PaginationNoPageController {
|
|
31508
|
-
constructor(queryParams) {
|
|
31509
|
-
const { http } = getActiveClient();
|
|
31510
|
-
this.queryParams = queryParams;
|
|
31511
|
-
this.http = http;
|
|
31512
|
-
}
|
|
31513
|
-
async onFetch() {
|
|
31514
|
-
const queryResponse = await this.getRequest(this.queryParams);
|
|
31515
|
-
return queryResponse;
|
|
31516
|
-
}
|
|
31517
|
-
}
|
|
31518
|
-
|
|
31519
|
-
class LiveCollectionController {
|
|
31520
|
-
constructor(paginationController, queryStreamId, cacheKey, callback) {
|
|
31521
|
-
this.paginationController = paginationController;
|
|
31522
|
-
this.queryStreamId = queryStreamId;
|
|
31523
|
-
this.cacheKey = cacheKey;
|
|
31524
|
-
this.callback = callback;
|
|
31525
|
-
}
|
|
31526
|
-
async refresh() {
|
|
31527
|
-
try {
|
|
31528
|
-
let result;
|
|
31529
|
-
if (this.paginationController instanceof PaginationNoPageController) {
|
|
31530
|
-
result = await this.paginationController.onFetch();
|
|
31531
|
-
}
|
|
31532
|
-
else {
|
|
31533
|
-
result = await this.paginationController.loadFirstPage();
|
|
31534
|
-
}
|
|
31535
|
-
if (!result)
|
|
31536
|
-
return;
|
|
31537
|
-
await this.persistModel(result);
|
|
31538
|
-
this.persistQueryStream({
|
|
31539
|
-
response: result,
|
|
31540
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
31541
|
-
refresh: true,
|
|
31542
|
-
});
|
|
31543
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31544
|
-
}
|
|
31545
|
-
catch (e) {
|
|
31546
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31547
|
-
}
|
|
31548
|
-
}
|
|
31549
|
-
loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
|
|
31550
|
-
this.setup();
|
|
31551
|
-
this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
|
|
31552
|
-
if (initial) {
|
|
31553
|
-
this.refresh();
|
|
31554
|
-
}
|
|
31555
|
-
else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
|
|
31556
|
-
this.loadPrevPage();
|
|
31557
|
-
}
|
|
31558
|
-
else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
|
|
31559
|
-
this.loadNextPage();
|
|
31560
|
-
}
|
|
31561
|
-
}
|
|
31562
|
-
async loadNextPage() {
|
|
31563
|
-
try {
|
|
31564
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
31565
|
-
return;
|
|
31566
|
-
const result = await this.paginationController.loadNextPage();
|
|
31567
|
-
if (!result)
|
|
31568
|
-
return;
|
|
31569
|
-
await this.persistModel(result);
|
|
31570
|
-
this.persistQueryStream({
|
|
31571
|
-
response: result,
|
|
31572
|
-
direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
|
|
31573
|
-
});
|
|
31574
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31575
|
-
}
|
|
31576
|
-
catch (e) {
|
|
31577
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31578
|
-
}
|
|
31579
|
-
}
|
|
31580
|
-
async loadPrevPage() {
|
|
31581
|
-
try {
|
|
31582
|
-
if (this.paginationController instanceof PaginationNoPageController)
|
|
31583
|
-
return;
|
|
31584
|
-
const result = await this.paginationController.loadPreviousPage();
|
|
31585
|
-
if (!result)
|
|
31586
|
-
return;
|
|
31587
|
-
await this.persistModel(result);
|
|
31588
|
-
this.persistQueryStream({
|
|
31589
|
-
response: result,
|
|
31590
|
-
direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
|
|
31591
|
-
});
|
|
31592
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
|
|
31593
|
-
}
|
|
31594
|
-
catch (e) {
|
|
31595
|
-
this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
|
|
31596
|
-
}
|
|
31597
|
-
}
|
|
31598
|
-
shouldNotify(data) {
|
|
31599
|
-
const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
|
|
31600
|
-
if (isEqual(this.snapshot, newData))
|
|
31601
|
-
return false;
|
|
31602
|
-
this.snapshot = newData;
|
|
31603
|
-
return true;
|
|
31604
|
-
}
|
|
31605
|
-
getCacheKey() {
|
|
31606
|
-
return this.cacheKey;
|
|
31607
|
-
}
|
|
31608
|
-
}
|
|
31609
|
-
|
|
31610
|
-
class QueryStreamController {
|
|
31611
|
-
constructor(query, cacheKey) {
|
|
31612
|
-
this.query = query;
|
|
31613
|
-
this.cacheKey = cacheKey;
|
|
31614
|
-
}
|
|
31615
|
-
}
|
|
31616
|
-
|
|
31617
31940
|
/* eslint-disable no-use-before-define */
|
|
31618
31941
|
class MessageQueryStreamController extends QueryStreamController {
|
|
31619
31942
|
constructor(query, cacheKey, notifyChange, preparePayload, paginationController) {
|
|
@@ -31696,51 +32019,6 @@ class MessageQueryStreamController extends QueryStreamController {
|
|
|
31696
32019
|
}
|
|
31697
32020
|
}
|
|
31698
32021
|
|
|
31699
|
-
class PaginationController {
|
|
31700
|
-
constructor(queryParams) {
|
|
31701
|
-
const { http } = getActiveClient();
|
|
31702
|
-
this.queryParams = queryParams;
|
|
31703
|
-
this.http = http;
|
|
31704
|
-
}
|
|
31705
|
-
loadFirstPage() {
|
|
31706
|
-
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
31707
|
-
}
|
|
31708
|
-
loadNextPage() {
|
|
31709
|
-
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
31710
|
-
}
|
|
31711
|
-
loadPreviousPage() {
|
|
31712
|
-
return this.onFetch("prev" /* Amity.LiveCollectionPageDirection.PREV */);
|
|
31713
|
-
}
|
|
31714
|
-
async onFetch(direction = "first" /* Amity.LiveCollectionPageDirection.FIRST */) {
|
|
31715
|
-
var _a, _b, _c, _d;
|
|
31716
|
-
if (direction === 'prev' && !this.previousToken)
|
|
31717
|
-
return;
|
|
31718
|
-
if (direction === 'next' && !this.nextToken)
|
|
31719
|
-
return;
|
|
31720
|
-
let token;
|
|
31721
|
-
if (direction === 'prev')
|
|
31722
|
-
token = this.previousToken;
|
|
31723
|
-
if (direction === 'next')
|
|
31724
|
-
token = this.nextToken;
|
|
31725
|
-
const queryResponse = await this.getRequest(this.queryParams, token);
|
|
31726
|
-
if (direction === 'first') {
|
|
31727
|
-
this.nextToken = (_a = queryResponse.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
31728
|
-
this.previousToken = (_b = queryResponse.paging) === null || _b === void 0 ? void 0 : _b.previous;
|
|
31729
|
-
}
|
|
31730
|
-
if (direction === 'prev')
|
|
31731
|
-
this.previousToken = (_c = queryResponse.paging) === null || _c === void 0 ? void 0 : _c.previous;
|
|
31732
|
-
if (direction === 'next')
|
|
31733
|
-
this.nextToken = (_d = queryResponse.paging) === null || _d === void 0 ? void 0 : _d.next;
|
|
31734
|
-
return queryResponse;
|
|
31735
|
-
}
|
|
31736
|
-
getNextToken() {
|
|
31737
|
-
return this.nextToken;
|
|
31738
|
-
}
|
|
31739
|
-
getPrevToken() {
|
|
31740
|
-
return this.previousToken;
|
|
31741
|
-
}
|
|
31742
|
-
}
|
|
31743
|
-
|
|
31744
32022
|
/* eslint-disable no-use-before-define */
|
|
31745
32023
|
/**
|
|
31746
32024
|
* TODO: handle cache receive cache option, and cache policy
|
|
@@ -33685,6 +33963,9 @@ class ChannelMemberLiveCollectionController extends LiveCollectionController {
|
|
|
33685
33963
|
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.');
|
|
33686
33964
|
channelMembers = filterBySearchTerm(channelMembers, this.query.search);
|
|
33687
33965
|
}
|
|
33966
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
33967
|
+
channelMembers = channelMembers.filter(member => { var _a; return ((_a = member.user) === null || _a === void 0 ? void 0 : _a.isDeleted) === this.query.includeDeleted; });
|
|
33968
|
+
}
|
|
33688
33969
|
// sort, 'lastCreated' is the default sort order
|
|
33689
33970
|
const sortBy = this.query.sortBy ? this.query.sortBy : 'lastCreated';
|
|
33690
33971
|
channelMembers = channelMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
@@ -34052,57 +34333,6 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
34052
34333
|
});
|
|
34053
34334
|
};
|
|
34054
34335
|
|
|
34055
|
-
const getMatchPostSetting = (value) => {
|
|
34056
|
-
var _a;
|
|
34057
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
34058
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
34059
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
34060
|
-
};
|
|
34061
|
-
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
34062
|
-
if (!communityUsers)
|
|
34063
|
-
return communityUsers;
|
|
34064
|
-
const result = {};
|
|
34065
|
-
communityUsers.forEach(user => {
|
|
34066
|
-
result[`${user.userId}#${user.communityId}`] = user;
|
|
34067
|
-
});
|
|
34068
|
-
return result;
|
|
34069
|
-
};
|
|
34070
|
-
const convertCommunityPayload = (rawPayload) => {
|
|
34071
|
-
// Unpack community payload by mapping payload field to postSetting value.
|
|
34072
|
-
const communities = rawPayload.communities.map((_a) => {
|
|
34073
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
34074
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
34075
|
-
needApprovalOnPostCreation,
|
|
34076
|
-
onlyAdminCanPost,
|
|
34077
|
-
}) }, restCommunityPayload));
|
|
34078
|
-
});
|
|
34079
|
-
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
34080
|
-
var _a;
|
|
34081
|
-
const users = (_a = pullFromCache([
|
|
34082
|
-
'communityUsers',
|
|
34083
|
-
'collection',
|
|
34084
|
-
communityId,
|
|
34085
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
34086
|
-
if (!users)
|
|
34087
|
-
return acc;
|
|
34088
|
-
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
34089
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
34090
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
34091
|
-
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
34092
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
34093
|
-
};
|
|
34094
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
34095
|
-
const { communities, communityUsers } = convertCommunityPayload(rawPayload);
|
|
34096
|
-
return Object.assign(Object.assign({}, rawPayload), { communities,
|
|
34097
|
-
communityUsers });
|
|
34098
|
-
};
|
|
34099
|
-
const prepareCommunityRequest = (params) => {
|
|
34100
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
34101
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
34102
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
34103
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
34104
|
-
};
|
|
34105
|
-
|
|
34106
34336
|
/**
|
|
34107
34337
|
* ```js
|
|
34108
34338
|
* import { getCommunities } from '@amityco/ts-sdk'
|
|
@@ -34538,10 +34768,6 @@ const onCommunityUpdated = (callback) => createCommunityEventSubscriber('communi
|
|
|
34538
34768
|
*/
|
|
34539
34769
|
const onCommunityDeleted = (callback) => createCommunityEventSubscriber('community.deleted', callback);
|
|
34540
34770
|
|
|
34541
|
-
function isNonNullable(value) {
|
|
34542
|
-
return value != null;
|
|
34543
|
-
}
|
|
34544
|
-
|
|
34545
34771
|
function hasPermission(member, payload, permission) {
|
|
34546
34772
|
if (member.permissions.some(x => x === permission)) {
|
|
34547
34773
|
return true;
|
|
@@ -35090,6 +35316,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35090
35316
|
if (this.query.search) {
|
|
35091
35317
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35092
35318
|
}
|
|
35319
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
35320
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
|
|
35321
|
+
}
|
|
35093
35322
|
switch (this.query.sortBy) {
|
|
35094
35323
|
case 'firstCreated':
|
|
35095
35324
|
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
@@ -35327,6 +35556,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
35327
35556
|
if (this.query.search) {
|
|
35328
35557
|
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35329
35558
|
}
|
|
35559
|
+
if (typeof this.query.includeDeleted === 'boolean') {
|
|
35560
|
+
communityMembers = communityMembers.filter(({ user }) => (user === null || user === void 0 ? void 0 : user.isDeleted) === this.query.includeDeleted);
|
|
35561
|
+
}
|
|
35330
35562
|
return communityMembers;
|
|
35331
35563
|
}
|
|
35332
35564
|
}
|
|
@@ -35651,11 +35883,11 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
35651
35883
|
if (!this.query.displayName) {
|
|
35652
35884
|
const sortFn = (() => {
|
|
35653
35885
|
switch (this.query.sortBy) {
|
|
35654
|
-
case
|
|
35886
|
+
case "firstCreated" /* Amity.CommunitySortByEnum.FirstCreated */:
|
|
35655
35887
|
return sortByFirstCreated;
|
|
35656
|
-
case
|
|
35888
|
+
case "lastCreated" /* Amity.CommunitySortByEnum.LastCreated */:
|
|
35657
35889
|
return sortByLastCreated;
|
|
35658
|
-
case
|
|
35890
|
+
case "displayName" /* Amity.CommunitySortByEnum.DisplayName */:
|
|
35659
35891
|
return sortByDisplayName;
|
|
35660
35892
|
default:
|
|
35661
35893
|
return sortByLastCreated;
|
|
@@ -37880,17 +38112,6 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
37880
38112
|
}
|
|
37881
38113
|
}
|
|
37882
38114
|
|
|
37883
|
-
function prepareCommentPayload(commentPayload) {
|
|
37884
|
-
const { comments } = commentPayload;
|
|
37885
|
-
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
37886
|
-
if (comment.hasOwnProperty('myReactions'))
|
|
37887
|
-
return comment;
|
|
37888
|
-
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
37889
|
-
// We need to put it with an empty array manually to make it show up in client side
|
|
37890
|
-
return Object.assign({ myReactions: [] }, comment);
|
|
37891
|
-
}) });
|
|
37892
|
-
}
|
|
37893
|
-
|
|
37894
38115
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
37895
38116
|
constructor(query, callback) {
|
|
37896
38117
|
const queryStreamId = hash(query);
|
|
@@ -38243,17 +38464,6 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
38243
38464
|
}
|
|
38244
38465
|
}
|
|
38245
38466
|
|
|
38246
|
-
const preparePostPayload = (postPayload) => {
|
|
38247
|
-
const { posts } = postPayload;
|
|
38248
|
-
const { communities, communityUsers } = convertCommunityPayload({
|
|
38249
|
-
communities: postPayload.communities,
|
|
38250
|
-
communityUsers: postPayload.communityUsers,
|
|
38251
|
-
});
|
|
38252
|
-
return Object.assign(Object.assign({}, postPayload), { posts,
|
|
38253
|
-
communities,
|
|
38254
|
-
communityUsers });
|
|
38255
|
-
};
|
|
38256
|
-
|
|
38257
38467
|
const getPost = async (postId) => {
|
|
38258
38468
|
const client = getActiveClient();
|
|
38259
38469
|
client.log('post/getPost', postId);
|
|
@@ -38450,6 +38660,138 @@ const getPosts = (params, callback, config) => {
|
|
|
38450
38660
|
};
|
|
38451
38661
|
/* end_public_function */
|
|
38452
38662
|
|
|
38663
|
+
class PinnedPostPaginationController extends PaginationController {
|
|
38664
|
+
async getRequest(queryParams, token) {
|
|
38665
|
+
const params = __rest(queryParams, ["limit"]);
|
|
38666
|
+
const { communityId, placement } = params;
|
|
38667
|
+
const path = placement
|
|
38668
|
+
? `/api/v1/pinned-posts/communities/${communityId}/${placement}`
|
|
38669
|
+
: `/api/v1/pinned-posts/communities/${communityId}`;
|
|
38670
|
+
const { data: queryResponse } = await this.http.get(path);
|
|
38671
|
+
return queryResponse;
|
|
38672
|
+
}
|
|
38673
|
+
}
|
|
38674
|
+
|
|
38675
|
+
class PinnedPostQueryStreamController extends QueryStreamController {
|
|
38676
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
38677
|
+
super(query, cacheKey);
|
|
38678
|
+
this.notifyChange = notifyChange;
|
|
38679
|
+
this.preparePayload = preparePayload;
|
|
38680
|
+
}
|
|
38681
|
+
// eslint-disable-next-line class-methods-use-this
|
|
38682
|
+
async saveToMainDB(response) {
|
|
38683
|
+
const client = getActiveClient();
|
|
38684
|
+
const cachedAt = client.cache && Date.now();
|
|
38685
|
+
if (client.cache) {
|
|
38686
|
+
ingestInCache(response, { cachedAt });
|
|
38687
|
+
}
|
|
38688
|
+
}
|
|
38689
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
38690
|
+
var _a, _b;
|
|
38691
|
+
if (refresh) {
|
|
38692
|
+
pushToCache(this.cacheKey, {
|
|
38693
|
+
data: response.pins.map(getResolver('pin')),
|
|
38694
|
+
});
|
|
38695
|
+
}
|
|
38696
|
+
else {
|
|
38697
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38698
|
+
const pinnedPosts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
38699
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...pinnedPosts, ...response.pins.map(getResolver('pin'))])] }));
|
|
38700
|
+
this.notifyChange({
|
|
38701
|
+
origin: "server" /* Amity.LiveDataOrigin.SERVER */,
|
|
38702
|
+
loading: false,
|
|
38703
|
+
});
|
|
38704
|
+
}
|
|
38705
|
+
}
|
|
38706
|
+
}
|
|
38707
|
+
|
|
38708
|
+
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
38709
|
+
constructor(query, callback) {
|
|
38710
|
+
const queryStreamId = hash(query);
|
|
38711
|
+
const cacheKey = ['pinnedPosts', 'collection', queryStreamId];
|
|
38712
|
+
const paginationController = new PinnedPostPaginationController(query);
|
|
38713
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
38714
|
+
this.query = query;
|
|
38715
|
+
this.queryStreamController = new PinnedPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), response => response);
|
|
38716
|
+
this.callback = callback.bind(this);
|
|
38717
|
+
this.loadPage({ initial: true });
|
|
38718
|
+
}
|
|
38719
|
+
setup() {
|
|
38720
|
+
var _a;
|
|
38721
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38722
|
+
if (!collection) {
|
|
38723
|
+
pushToCache(this.cacheKey, {
|
|
38724
|
+
data: [],
|
|
38725
|
+
params: {},
|
|
38726
|
+
});
|
|
38727
|
+
}
|
|
38728
|
+
}
|
|
38729
|
+
async persistModel(queryPayload) {
|
|
38730
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
38731
|
+
}
|
|
38732
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
38733
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
38734
|
+
}
|
|
38735
|
+
// eslint-disable-next-line class-methods-use-this
|
|
38736
|
+
startSubscription() {
|
|
38737
|
+
return [];
|
|
38738
|
+
}
|
|
38739
|
+
notifyChange({ origin, loading, error }) {
|
|
38740
|
+
var _a, _b;
|
|
38741
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38742
|
+
if (!collection)
|
|
38743
|
+
return;
|
|
38744
|
+
let data = ((_b = collection.data
|
|
38745
|
+
.map(id => pullFromCache(['pin', 'get', id]))
|
|
38746
|
+
.filter(isNonNullable)
|
|
38747
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.pinnedPost);
|
|
38748
|
+
data = this.applyFilter(data);
|
|
38749
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
38750
|
+
return;
|
|
38751
|
+
this.callback({
|
|
38752
|
+
data,
|
|
38753
|
+
loading,
|
|
38754
|
+
error,
|
|
38755
|
+
});
|
|
38756
|
+
}
|
|
38757
|
+
applyFilter(data) {
|
|
38758
|
+
let pinnedPost = data;
|
|
38759
|
+
switch (this.query.sortBy) {
|
|
38760
|
+
case 'lastCreated':
|
|
38761
|
+
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 }));
|
|
38762
|
+
break;
|
|
38763
|
+
}
|
|
38764
|
+
return pinnedPost;
|
|
38765
|
+
}
|
|
38766
|
+
}
|
|
38767
|
+
|
|
38768
|
+
/**
|
|
38769
|
+
* Get pinned posts for a community
|
|
38770
|
+
*
|
|
38771
|
+
* @param communityId the ID of the community
|
|
38772
|
+
* @param placement the placement of the pinned post ('announcement' or 'default'), or null to fetch all pinned posts
|
|
38773
|
+
* @returns the associated pinned post(s)
|
|
38774
|
+
*
|
|
38775
|
+
* @category Pined Posts Live Collection
|
|
38776
|
+
*
|
|
38777
|
+
*/
|
|
38778
|
+
const getPinnedPosts = (params, callback, config) => {
|
|
38779
|
+
const { log, cache } = getActiveClient();
|
|
38780
|
+
if (!cache) {
|
|
38781
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
38782
|
+
}
|
|
38783
|
+
const timestamp = Date.now();
|
|
38784
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > listen`);
|
|
38785
|
+
const pinnedPostLiveCollection = new PinnedPostLiveCollectionController(params, callback);
|
|
38786
|
+
const disposers = pinnedPostLiveCollection.startSubscription();
|
|
38787
|
+
const cacheKey = pinnedPostLiveCollection.getCacheKey();
|
|
38788
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
38789
|
+
return () => {
|
|
38790
|
+
log(`getPinnedPosts(tmpid: ${timestamp}) > dispose`);
|
|
38791
|
+
disposers.forEach(fn => fn());
|
|
38792
|
+
};
|
|
38793
|
+
};
|
|
38794
|
+
|
|
38453
38795
|
var index$5 = /*#__PURE__*/Object.freeze({
|
|
38454
38796
|
__proto__: null,
|
|
38455
38797
|
getPostByIds: getPostByIds,
|
|
@@ -38476,7 +38818,8 @@ var index$5 = /*#__PURE__*/Object.freeze({
|
|
|
38476
38818
|
observePosts: observePosts,
|
|
38477
38819
|
observePost: observePost,
|
|
38478
38820
|
getPost: getPost$1,
|
|
38479
|
-
getPosts: getPosts
|
|
38821
|
+
getPosts: getPosts,
|
|
38822
|
+
getPinnedPosts: getPinnedPosts
|
|
38480
38823
|
});
|
|
38481
38824
|
|
|
38482
38825
|
/* begin_public_function
|
|
@@ -39370,7 +39713,7 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
39370
39713
|
getPoll: getPoll
|
|
39371
39714
|
});
|
|
39372
39715
|
|
|
39373
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
39716
|
+
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-----";
|
|
39374
39717
|
/*
|
|
39375
39718
|
* The crypto algorithm used for importing key and signing string
|
|
39376
39719
|
*/
|