@amityco/ts-sdk 7.4.1-4207cb63.0 → 7.4.1-82bb9867.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +39 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/joinRequest.d.ts +53 -0
- package/dist/@types/domains/joinRequest.d.ts.map +1 -0
- package/dist/@types/domains/notification.d.ts +4 -2
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
- package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
- package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +1 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.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/index.cjs.js +997 -266
- package/dist/index.esm.js +1126 -395
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/events.ts +7 -1
- package/src/@types/core/model.ts +3 -0
- package/src/@types/core/payload.ts +22 -1
- package/src/@types/domains/community.ts +55 -2
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/domains/notification.ts +2 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunities.ts +3 -1
- package/src/communityRepository/api/getCommunity.ts +8 -0
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/communityMembership/events/index.ts +1 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +66 -0
- package/src/communityRepository/joinRequest/events/index.ts +3 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
- package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
- package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
- package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
- package/src/communityRepository/observers/getCommunity.ts +3 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
- package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
- package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequests.ts +44 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/index.ts +1 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
- package/src/communityRepository/utils/communityWithMembership.ts +1 -1
- package/src/communityRepository/utils/payload.ts +27 -1
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +22 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
package/dist/index.cjs.js
CHANGED
|
@@ -136,6 +136,19 @@ exports.InvitationSortByEnum = void 0;
|
|
|
136
136
|
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
137
137
|
})(exports.InvitationSortByEnum || (exports.InvitationSortByEnum = {}));
|
|
138
138
|
|
|
139
|
+
exports.JoinRequestStatusEnum = void 0;
|
|
140
|
+
(function (JoinRequestStatusEnum) {
|
|
141
|
+
JoinRequestStatusEnum["Pending"] = "pending";
|
|
142
|
+
JoinRequestStatusEnum["Approved"] = "approved";
|
|
143
|
+
JoinRequestStatusEnum["Rejected"] = "rejected";
|
|
144
|
+
JoinRequestStatusEnum["Cancelled"] = "cancelled";
|
|
145
|
+
})(exports.JoinRequestStatusEnum || (exports.JoinRequestStatusEnum = {}));
|
|
146
|
+
exports.JoinResultStatusEnum = void 0;
|
|
147
|
+
(function (JoinResultStatusEnum) {
|
|
148
|
+
JoinResultStatusEnum["Success"] = "success";
|
|
149
|
+
JoinResultStatusEnum["Pending"] = "pending";
|
|
150
|
+
})(exports.JoinResultStatusEnum || (exports.JoinResultStatusEnum = {}));
|
|
151
|
+
|
|
139
152
|
function getVersion() {
|
|
140
153
|
try {
|
|
141
154
|
// the string ''v7.4.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -583,6 +596,7 @@ const idResolvers = {
|
|
|
583
596
|
notificationTrayItem: ({ _id }) => _id,
|
|
584
597
|
notificationTraySeen: ({ userId }) => userId,
|
|
585
598
|
invitation: ({ _id }) => _id,
|
|
599
|
+
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
586
600
|
};
|
|
587
601
|
/**
|
|
588
602
|
* Retrieve the id resolver matching a domain name
|
|
@@ -636,6 +650,7 @@ const PAYLOAD2MODEL = {
|
|
|
636
650
|
pins: 'pin',
|
|
637
651
|
notificationTrayItems: 'notificationTrayItem',
|
|
638
652
|
invitations: 'invitation',
|
|
653
|
+
joinRequests: 'joinRequest',
|
|
639
654
|
};
|
|
640
655
|
/** hidden */
|
|
641
656
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -5467,6 +5482,10 @@ function convertQueryParams$1(_a) {
|
|
|
5467
5482
|
return out;
|
|
5468
5483
|
}
|
|
5469
5484
|
|
|
5485
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
5486
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
5487
|
+
}
|
|
5488
|
+
|
|
5470
5489
|
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
5471
5490
|
/**
|
|
5472
5491
|
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
@@ -5495,8 +5514,9 @@ const prepareSubChannelPayload = async (rawPayload) => {
|
|
|
5495
5514
|
// attach marker to sub channel
|
|
5496
5515
|
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
5497
5516
|
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
5517
|
+
const user = rawPayload.users.map(convertRawUserToInternalUser);
|
|
5498
5518
|
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
5499
|
-
messages });
|
|
5519
|
+
messages, users: user });
|
|
5500
5520
|
};
|
|
5501
5521
|
function convertQueryParams(_a) {
|
|
5502
5522
|
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
@@ -5761,10 +5781,6 @@ const handleSubChannelUpdated = async (subChannel) => {
|
|
|
5761
5781
|
}
|
|
5762
5782
|
};
|
|
5763
5783
|
|
|
5764
|
-
function convertRawUserToInternalUser(rawUser) {
|
|
5765
|
-
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
5766
|
-
}
|
|
5767
|
-
|
|
5768
5784
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
5769
5785
|
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
5770
5786
|
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -7354,245 +7370,315 @@ const notificationTrayLinkedObject = (noti) => {
|
|
|
7354
7370
|
.map(user => userLinkedObject(user)) });
|
|
7355
7371
|
};
|
|
7356
7372
|
|
|
7357
|
-
|
|
7358
|
-
|
|
7359
|
-
|
|
7360
|
-
|
|
7361
|
-
|
|
7362
|
-
|
|
7363
|
-
|
|
7364
|
-
|
|
7365
|
-
|
|
7366
|
-
|
|
7367
|
-
|
|
7368
|
-
|
|
7369
|
-
|
|
7370
|
-
|
|
7371
|
-
*
|
|
7372
|
-
*
|
|
7373
|
-
* targetType: string,
|
|
7374
|
-
* targetId: string,
|
|
7375
|
-
* userIds: string[]
|
|
7376
|
-
* }))
|
|
7377
|
-
* ```
|
|
7378
|
-
*
|
|
7379
|
-
* Creates an {@link Amity.Invitation}
|
|
7380
|
-
*
|
|
7381
|
-
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
7382
|
-
* @returns The newly created {@link Amity.Invitation}
|
|
7373
|
+
/*
|
|
7374
|
+
* verifies membership status
|
|
7375
|
+
*/
|
|
7376
|
+
function isMember(membership) {
|
|
7377
|
+
return membership !== 'none';
|
|
7378
|
+
}
|
|
7379
|
+
/*
|
|
7380
|
+
* checks if currently logged in user is part of the community
|
|
7381
|
+
*/
|
|
7382
|
+
function isCurrentUserPartOfCommunity(c, m) {
|
|
7383
|
+
const { userId } = getActiveUser();
|
|
7384
|
+
return c.communityId === m.communityId && m.userId === userId;
|
|
7385
|
+
}
|
|
7386
|
+
/*
|
|
7387
|
+
* For mqtt events server will not send user specific data as it's broadcasted
|
|
7388
|
+
* to multiple users and it also does not include communityUser
|
|
7383
7389
|
*
|
|
7384
|
-
*
|
|
7385
|
-
*
|
|
7390
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
7391
|
+
* Althought this can be calculated, it's not scalable.
|
|
7386
7392
|
*/
|
|
7387
|
-
|
|
7388
|
-
|
|
7389
|
-
|
|
7390
|
-
|
|
7391
|
-
|
|
7392
|
-
|
|
7393
|
-
|
|
7394
|
-
|
|
7395
|
-
|
|
7396
|
-
|
|
7397
|
-
|
|
7398
|
-
|
|
7399
|
-
};
|
|
7393
|
+
function updateMembershipStatus(communities, communityUsers) {
|
|
7394
|
+
return communities.map(c => {
|
|
7395
|
+
const cachedCommunity = pullFromCache([
|
|
7396
|
+
'community',
|
|
7397
|
+
'get',
|
|
7398
|
+
c.communityId,
|
|
7399
|
+
]);
|
|
7400
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
7401
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
7402
|
+
}
|
|
7403
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
7404
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
7405
|
+
});
|
|
7406
|
+
}
|
|
7407
|
+
|
|
7408
|
+
const getMatchPostSetting = (value) => {
|
|
7409
|
+
var _a;
|
|
7410
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
7411
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
7412
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
7400
7413
|
};
|
|
7401
|
-
|
|
7414
|
+
function addPostSetting({ communities }) {
|
|
7415
|
+
return communities.map((_a) => {
|
|
7416
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
7417
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
7418
|
+
needApprovalOnPostCreation,
|
|
7419
|
+
onlyAdminCanPost,
|
|
7420
|
+
}) }, restCommunityPayload));
|
|
7421
|
+
});
|
|
7422
|
+
}
|
|
7423
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
7424
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
7425
|
+
// Convert users to internal format
|
|
7426
|
+
const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7427
|
+
// map users with community
|
|
7428
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
7429
|
+
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
7430
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
7431
|
+
});
|
|
7432
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
7433
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
7434
|
+
};
|
|
7435
|
+
const prepareCommunityJoinRequestPayload = (rawPayload) => {
|
|
7436
|
+
const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
|
|
7437
|
+
return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
|
|
7438
|
+
});
|
|
7439
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
7440
|
+
return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
|
|
7441
|
+
};
|
|
7442
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
7443
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
7444
|
+
// map users with community
|
|
7445
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
7446
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
7447
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
7448
|
+
});
|
|
7449
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
7450
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
7451
|
+
};
|
|
7452
|
+
const prepareCommunityRequest = (params) => {
|
|
7453
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
7454
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
7455
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
7456
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
7457
|
+
};
|
|
7458
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
7459
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
7460
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
7461
|
+
return Object.assign({}, processedCommunityPayload);
|
|
7462
|
+
};
|
|
7402
7463
|
|
|
7403
7464
|
/* begin_public_function
|
|
7404
|
-
id:
|
|
7465
|
+
id: joinRequest.approve
|
|
7405
7466
|
*/
|
|
7406
7467
|
/**
|
|
7407
7468
|
* ```js
|
|
7408
|
-
* import {
|
|
7409
|
-
* const isAccepted = await
|
|
7469
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7470
|
+
* const isAccepted = await joinRequest.approve()
|
|
7410
7471
|
* ```
|
|
7411
7472
|
*
|
|
7412
|
-
* Accepts a {@link Amity.
|
|
7473
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
7413
7474
|
*
|
|
7414
|
-
* @param
|
|
7415
|
-
* @returns A success boolean if the {@link Amity.
|
|
7475
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
7476
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
7416
7477
|
*
|
|
7417
|
-
* @category
|
|
7478
|
+
* @category Join Request API
|
|
7418
7479
|
* @async
|
|
7419
7480
|
*/
|
|
7420
|
-
const
|
|
7481
|
+
const approveJoinRequest = async (joinRequest) => {
|
|
7421
7482
|
var _a;
|
|
7422
7483
|
const client = getActiveClient();
|
|
7423
|
-
client.log('
|
|
7424
|
-
const { data } = await client.http.post(`/api/
|
|
7425
|
-
|
|
7426
|
-
|
|
7484
|
+
client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
|
|
7485
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
|
|
7486
|
+
userId: joinRequest.requestorInternalId,
|
|
7487
|
+
});
|
|
7488
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7489
|
+
'joinRequest',
|
|
7427
7490
|
'get',
|
|
7428
|
-
|
|
7491
|
+
joinRequest.joinRequestId,
|
|
7429
7492
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7430
|
-
if (
|
|
7431
|
-
upsertInCache(['
|
|
7432
|
-
|
|
7493
|
+
if (joinRequestCache) {
|
|
7494
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
7495
|
+
status: "approved" /* JoinRequestStatusEnum.Approved */,
|
|
7496
|
+
});
|
|
7497
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
7433
7498
|
}
|
|
7434
7499
|
return data.success;
|
|
7435
7500
|
};
|
|
7436
7501
|
/* end_public_function */
|
|
7437
7502
|
|
|
7438
7503
|
/* begin_public_function
|
|
7439
|
-
id:
|
|
7504
|
+
id: joinRequest.cancel
|
|
7440
7505
|
*/
|
|
7441
7506
|
/**
|
|
7442
7507
|
* ```js
|
|
7443
|
-
* import {
|
|
7444
|
-
* const
|
|
7508
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7509
|
+
* const isCanceled = await joinRequest.cancel()
|
|
7445
7510
|
* ```
|
|
7446
7511
|
*
|
|
7447
|
-
*
|
|
7512
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
7448
7513
|
*
|
|
7449
|
-
* @param
|
|
7450
|
-
* @returns A success boolean if the {@link Amity.
|
|
7514
|
+
* @param joinRequest the {@link Amity.JoinRequest} to cancel
|
|
7515
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was canceled
|
|
7451
7516
|
*
|
|
7452
|
-
* @category
|
|
7517
|
+
* @category Join Request API
|
|
7453
7518
|
* @async
|
|
7454
7519
|
*/
|
|
7455
|
-
const
|
|
7520
|
+
const cancelJoinRequest = async (joinRequest) => {
|
|
7456
7521
|
var _a;
|
|
7457
7522
|
const client = getActiveClient();
|
|
7458
|
-
client.log('
|
|
7459
|
-
const { data } = await client.http.
|
|
7460
|
-
const
|
|
7461
|
-
'
|
|
7523
|
+
client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
|
|
7524
|
+
const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
|
|
7525
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7526
|
+
'joinRequest',
|
|
7462
7527
|
'get',
|
|
7463
|
-
|
|
7528
|
+
joinRequest.joinRequestId,
|
|
7464
7529
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7465
|
-
if (
|
|
7466
|
-
|
|
7467
|
-
fireEvent('local.
|
|
7530
|
+
if (joinRequestCache) {
|
|
7531
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
7532
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
7468
7533
|
}
|
|
7469
7534
|
return data.success;
|
|
7470
7535
|
};
|
|
7471
7536
|
/* end_public_function */
|
|
7472
7537
|
|
|
7473
7538
|
/* begin_public_function
|
|
7474
|
-
id:
|
|
7539
|
+
id: joinRequest.reject
|
|
7475
7540
|
*/
|
|
7476
7541
|
/**
|
|
7477
7542
|
* ```js
|
|
7478
|
-
* import {
|
|
7479
|
-
* const
|
|
7543
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
7544
|
+
* const isRejected = await joinRequest.reject()
|
|
7480
7545
|
* ```
|
|
7481
7546
|
*
|
|
7482
|
-
*
|
|
7547
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
7483
7548
|
*
|
|
7484
|
-
* @param
|
|
7485
|
-
* @returns A success boolean if the {@link Amity.
|
|
7549
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
7550
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
7486
7551
|
*
|
|
7487
|
-
* @category
|
|
7552
|
+
* @category Join Request API
|
|
7488
7553
|
* @async
|
|
7489
7554
|
*/
|
|
7490
|
-
const
|
|
7555
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
7491
7556
|
var _a;
|
|
7492
7557
|
const client = getActiveClient();
|
|
7493
|
-
client.log('
|
|
7494
|
-
const { data } = await client.http.
|
|
7495
|
-
|
|
7496
|
-
|
|
7558
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
7559
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
|
|
7560
|
+
userId: joinRequest.requestorInternalId,
|
|
7561
|
+
});
|
|
7562
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
7563
|
+
'joinRequest',
|
|
7497
7564
|
'get',
|
|
7498
|
-
|
|
7565
|
+
joinRequest.joinRequestId,
|
|
7499
7566
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7500
|
-
if (
|
|
7501
|
-
|
|
7502
|
-
|
|
7567
|
+
if (joinRequestCache) {
|
|
7568
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
7569
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
7570
|
+
});
|
|
7571
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
7503
7572
|
}
|
|
7504
7573
|
return data.success;
|
|
7505
7574
|
};
|
|
7506
7575
|
/* end_public_function */
|
|
7507
7576
|
|
|
7508
|
-
const
|
|
7509
|
-
return Object.assign(Object.assign({},
|
|
7510
|
-
|
|
7511
|
-
|
|
7512
|
-
|
|
7513
|
-
|
|
7514
|
-
|
|
7515
|
-
|
|
7516
|
-
|
|
7517
|
-
return undefined;
|
|
7518
|
-
},
|
|
7519
|
-
get createdBy() {
|
|
7520
|
-
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
7521
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
7522
|
-
return userLinkedObject(cacheData.data);
|
|
7523
|
-
return undefined;
|
|
7524
|
-
},
|
|
7525
|
-
get target() {
|
|
7526
|
-
if (invitation.targetType === 'community') {
|
|
7527
|
-
const cacheData = pullFromCache([
|
|
7528
|
-
'community',
|
|
7529
|
-
'get',
|
|
7530
|
-
invitation.targetId,
|
|
7531
|
-
]);
|
|
7532
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
7533
|
-
return cacheData.data;
|
|
7577
|
+
const joinRequestLinkedObject = (joinRequest) => {
|
|
7578
|
+
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
7579
|
+
var _a;
|
|
7580
|
+
const user = (_a = pullFromCache([
|
|
7581
|
+
'user',
|
|
7582
|
+
'get',
|
|
7583
|
+
joinRequest.requestorPublicId,
|
|
7584
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7585
|
+
if (!user)
|
|
7534
7586
|
return undefined;
|
|
7535
|
-
|
|
7536
|
-
return undefined;
|
|
7537
|
-
}, accept: async () => {
|
|
7538
|
-
await acceptInvitation(invitation._id);
|
|
7539
|
-
}, reject: async () => {
|
|
7540
|
-
await rejectInvitation(invitation._id);
|
|
7587
|
+
return userLinkedObject(user);
|
|
7541
7588
|
}, cancel: async () => {
|
|
7542
|
-
await
|
|
7589
|
+
await cancelJoinRequest(joinRequest);
|
|
7590
|
+
}, approve: async () => {
|
|
7591
|
+
await approveJoinRequest(joinRequest);
|
|
7592
|
+
}, reject: async () => {
|
|
7593
|
+
await rejectJoinRequest(joinRequest);
|
|
7543
7594
|
} });
|
|
7544
7595
|
};
|
|
7545
7596
|
|
|
7546
7597
|
/* begin_public_function
|
|
7547
|
-
id:
|
|
7598
|
+
id: community.getMyJoinRequest
|
|
7548
7599
|
*/
|
|
7549
7600
|
/**
|
|
7550
7601
|
* ```js
|
|
7551
|
-
* import {
|
|
7552
|
-
* const
|
|
7602
|
+
* import { community } from '@amityco/ts-sdk'
|
|
7603
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
7553
7604
|
* ```
|
|
7554
7605
|
*
|
|
7555
|
-
*
|
|
7606
|
+
* Joins a {@link Amity.Community} object
|
|
7556
7607
|
*
|
|
7557
|
-
* @param
|
|
7558
|
-
* @
|
|
7559
|
-
* @returns A {@link Amity.Invitation} object
|
|
7608
|
+
* @param communityId the {@link Amity.Community} to join
|
|
7609
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
7560
7610
|
*
|
|
7561
|
-
* @category
|
|
7611
|
+
* @category Community API
|
|
7562
7612
|
* @async
|
|
7563
7613
|
*/
|
|
7564
|
-
const
|
|
7614
|
+
const getMyJoinRequest = async (communityId) => {
|
|
7565
7615
|
const client = getActiveClient();
|
|
7566
|
-
client.log('
|
|
7567
|
-
const { data: payload } = await client.http.get(`/api/
|
|
7568
|
-
const data =
|
|
7616
|
+
client.log('community/myJoinRequest', communityId);
|
|
7617
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
7618
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
7569
7619
|
const cachedAt = client.cache && Date.now();
|
|
7570
7620
|
if (client.cache)
|
|
7571
7621
|
ingestInCache(data, { cachedAt });
|
|
7572
7622
|
return {
|
|
7573
|
-
data: data.
|
|
7623
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
7574
7624
|
cachedAt,
|
|
7575
7625
|
};
|
|
7576
7626
|
};
|
|
7577
7627
|
/* end_public_function */
|
|
7578
7628
|
|
|
7579
|
-
|
|
7580
|
-
|
|
7581
|
-
|
|
7582
|
-
|
|
7583
|
-
|
|
7584
|
-
|
|
7585
|
-
|
|
7586
|
-
|
|
7587
|
-
|
|
7588
|
-
|
|
7589
|
-
|
|
7590
|
-
|
|
7591
|
-
|
|
7592
|
-
|
|
7593
|
-
|
|
7594
|
-
|
|
7595
|
-
|
|
7629
|
+
/* begin_public_function
|
|
7630
|
+
id: community.join
|
|
7631
|
+
*/
|
|
7632
|
+
/**
|
|
7633
|
+
* ```js
|
|
7634
|
+
* import { community } from '@amityco/ts-sdk'
|
|
7635
|
+
* const isJoined = await community.join('foobar')
|
|
7636
|
+
* ```
|
|
7637
|
+
*
|
|
7638
|
+
* Joins a {@link Amity.Community} object
|
|
7639
|
+
*
|
|
7640
|
+
* @param communityId the {@link Amity.Community} to join
|
|
7641
|
+
* @returns A status join result
|
|
7642
|
+
*
|
|
7643
|
+
* @category Community API
|
|
7644
|
+
* @async
|
|
7645
|
+
*/
|
|
7646
|
+
const joinRequest = async (communityId) => {
|
|
7647
|
+
var _a;
|
|
7648
|
+
const client = getActiveClient();
|
|
7649
|
+
client.log('community/joinRequest', communityId);
|
|
7650
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
7651
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
7652
|
+
const cachedAt = client.cache && Date.now();
|
|
7653
|
+
if (client.cache)
|
|
7654
|
+
ingestInCache(data, { cachedAt });
|
|
7655
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
7656
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
7657
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
7658
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
7659
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7660
|
+
if (community) {
|
|
7661
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
7662
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
7663
|
+
}
|
|
7664
|
+
}
|
|
7665
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
7666
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
7667
|
+
? { status }
|
|
7668
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
7669
|
+
};
|
|
7670
|
+
/* end_public_function */
|
|
7671
|
+
|
|
7672
|
+
class PaginationController {
|
|
7673
|
+
constructor(queryParams) {
|
|
7674
|
+
const { http } = getActiveClient();
|
|
7675
|
+
this.queryParams = queryParams;
|
|
7676
|
+
this.http = http;
|
|
7677
|
+
}
|
|
7678
|
+
loadFirstPage() {
|
|
7679
|
+
return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
|
|
7680
|
+
}
|
|
7681
|
+
loadNextPage() {
|
|
7596
7682
|
return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
|
|
7597
7683
|
}
|
|
7598
7684
|
loadPreviousPage() {
|
|
@@ -7628,12 +7714,18 @@ class PaginationController {
|
|
|
7628
7714
|
}
|
|
7629
7715
|
}
|
|
7630
7716
|
|
|
7631
|
-
|
|
7717
|
+
/**
|
|
7718
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
7719
|
+
* TODO: check if querybyIds is supported
|
|
7720
|
+
*/
|
|
7721
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
7632
7722
|
async getRequest(queryParams, token) {
|
|
7633
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
7723
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
7634
7724
|
const options = token ? { token } : { limit };
|
|
7635
|
-
const { data } = await this.http.get(
|
|
7636
|
-
|
|
7725
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
7726
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
7727
|
+
});
|
|
7728
|
+
return queryResponse;
|
|
7637
7729
|
}
|
|
7638
7730
|
}
|
|
7639
7731
|
|
|
@@ -7644,7 +7736,14 @@ class QueryStreamController {
|
|
|
7644
7736
|
}
|
|
7645
7737
|
}
|
|
7646
7738
|
|
|
7647
|
-
|
|
7739
|
+
var EnumJoinRequestAction$1;
|
|
7740
|
+
(function (EnumJoinRequestAction) {
|
|
7741
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
7742
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
7743
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
7744
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
7745
|
+
|
|
7746
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
7648
7747
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
7649
7748
|
super(query, cacheKey);
|
|
7650
7749
|
this.notifyChange = notifyChange;
|
|
@@ -7662,38 +7761,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
7662
7761
|
var _a, _b;
|
|
7663
7762
|
if (refresh) {
|
|
7664
7763
|
pushToCache(this.cacheKey, {
|
|
7665
|
-
data: response.
|
|
7764
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
7666
7765
|
});
|
|
7667
7766
|
}
|
|
7668
7767
|
else {
|
|
7669
7768
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7670
|
-
const
|
|
7769
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
7671
7770
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
7672
|
-
...new Set([
|
|
7771
|
+
...new Set([
|
|
7772
|
+
...joinRequests,
|
|
7773
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
7774
|
+
]),
|
|
7673
7775
|
] }));
|
|
7674
7776
|
}
|
|
7675
7777
|
}
|
|
7676
7778
|
reactor(action) {
|
|
7677
|
-
return (
|
|
7779
|
+
return (joinRequest) => {
|
|
7678
7780
|
var _a;
|
|
7679
7781
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7680
7782
|
if (!collection)
|
|
7681
7783
|
return;
|
|
7682
|
-
if (action ===
|
|
7683
|
-
const isExist = collection.data.find(id => id ===
|
|
7784
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
7785
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
7684
7786
|
if (!isExist)
|
|
7685
7787
|
return;
|
|
7686
7788
|
}
|
|
7687
|
-
if (action ===
|
|
7789
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
7688
7790
|
collection.data = [
|
|
7689
7791
|
...new Set([
|
|
7690
|
-
...
|
|
7792
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
7691
7793
|
...collection.data,
|
|
7692
7794
|
]),
|
|
7693
7795
|
];
|
|
7694
7796
|
}
|
|
7695
|
-
if (action ===
|
|
7696
|
-
collection.data = collection.data.filter(id => id !==
|
|
7797
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
7798
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
7697
7799
|
}
|
|
7698
7800
|
pushToCache(this.cacheKey, collection);
|
|
7699
7801
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -7834,8 +7936,485 @@ class LiveCollectionController {
|
|
|
7834
7936
|
this.snapshot = newData;
|
|
7835
7937
|
return true;
|
|
7836
7938
|
}
|
|
7837
|
-
getCacheKey() {
|
|
7838
|
-
return this.cacheKey;
|
|
7939
|
+
getCacheKey() {
|
|
7940
|
+
return this.cacheKey;
|
|
7941
|
+
}
|
|
7942
|
+
}
|
|
7943
|
+
|
|
7944
|
+
/**
|
|
7945
|
+
* ```js
|
|
7946
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
7947
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
7948
|
+
* // ...
|
|
7949
|
+
* })
|
|
7950
|
+
* ```
|
|
7951
|
+
*
|
|
7952
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
7953
|
+
*
|
|
7954
|
+
* @param callback The function to call when the event was fired
|
|
7955
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7956
|
+
*
|
|
7957
|
+
* @category JoinRequest Events
|
|
7958
|
+
*/
|
|
7959
|
+
const onJoinRequestCreated = (callback) => {
|
|
7960
|
+
const client = getActiveClient();
|
|
7961
|
+
const disposers = [
|
|
7962
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
7963
|
+
];
|
|
7964
|
+
return () => {
|
|
7965
|
+
disposers.forEach(fn => fn());
|
|
7966
|
+
};
|
|
7967
|
+
};
|
|
7968
|
+
|
|
7969
|
+
/**
|
|
7970
|
+
* ```js
|
|
7971
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
7972
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
7973
|
+
* // ...
|
|
7974
|
+
* })
|
|
7975
|
+
* ```
|
|
7976
|
+
*
|
|
7977
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
7978
|
+
*
|
|
7979
|
+
* @param callback The function to call when the event was fired
|
|
7980
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7981
|
+
*
|
|
7982
|
+
* @category JoinRequest Events
|
|
7983
|
+
*/
|
|
7984
|
+
const onJoinRequestUpdated = (callback) => {
|
|
7985
|
+
const client = getActiveClient();
|
|
7986
|
+
const disposers = [
|
|
7987
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
7988
|
+
];
|
|
7989
|
+
return () => {
|
|
7990
|
+
disposers.forEach(fn => fn());
|
|
7991
|
+
};
|
|
7992
|
+
};
|
|
7993
|
+
|
|
7994
|
+
/**
|
|
7995
|
+
* ```js
|
|
7996
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
7997
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
7998
|
+
* // ...
|
|
7999
|
+
* })
|
|
8000
|
+
* ```
|
|
8001
|
+
*
|
|
8002
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
8003
|
+
*
|
|
8004
|
+
* @param callback The function to call when the event was fired
|
|
8005
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
8006
|
+
*
|
|
8007
|
+
* @category JoinRequest Events
|
|
8008
|
+
*/
|
|
8009
|
+
const onJoinRequestDeleted = (callback) => {
|
|
8010
|
+
const client = getActiveClient();
|
|
8011
|
+
const disposers = [
|
|
8012
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
8013
|
+
];
|
|
8014
|
+
return () => {
|
|
8015
|
+
disposers.forEach(fn => fn());
|
|
8016
|
+
};
|
|
8017
|
+
};
|
|
8018
|
+
|
|
8019
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
8020
|
+
constructor(query, callback) {
|
|
8021
|
+
const queryStreamId = hash__default["default"](query);
|
|
8022
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
8023
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
8024
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
8025
|
+
this.query = query;
|
|
8026
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
8027
|
+
this.callback = callback.bind(this);
|
|
8028
|
+
this.loadPage({ initial: true });
|
|
8029
|
+
}
|
|
8030
|
+
setup() {
|
|
8031
|
+
var _a;
|
|
8032
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8033
|
+
if (!collection) {
|
|
8034
|
+
pushToCache(this.cacheKey, {
|
|
8035
|
+
data: [],
|
|
8036
|
+
params: this.query,
|
|
8037
|
+
});
|
|
8038
|
+
}
|
|
8039
|
+
}
|
|
8040
|
+
async persistModel(queryPayload) {
|
|
8041
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
8042
|
+
}
|
|
8043
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
8044
|
+
const joinRequestResponse = response;
|
|
8045
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
8046
|
+
}
|
|
8047
|
+
startSubscription() {
|
|
8048
|
+
return this.queryStreamController.subscribeRTE([
|
|
8049
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
8050
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
8051
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
8052
|
+
]);
|
|
8053
|
+
}
|
|
8054
|
+
notifyChange({ origin, loading, error }) {
|
|
8055
|
+
var _a;
|
|
8056
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8057
|
+
if (!collection)
|
|
8058
|
+
return;
|
|
8059
|
+
const data = this.applyFilter(collection.data
|
|
8060
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
8061
|
+
.filter(isNonNullable)
|
|
8062
|
+
.map(({ data }) => data)
|
|
8063
|
+
.map(joinRequestLinkedObject));
|
|
8064
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
8065
|
+
return;
|
|
8066
|
+
this.callback({
|
|
8067
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
8068
|
+
data,
|
|
8069
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
8070
|
+
loading,
|
|
8071
|
+
error,
|
|
8072
|
+
});
|
|
8073
|
+
}
|
|
8074
|
+
applyFilter(data) {
|
|
8075
|
+
let joinRequest = data;
|
|
8076
|
+
if (this.query.status) {
|
|
8077
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
8078
|
+
}
|
|
8079
|
+
const sortFn = (() => {
|
|
8080
|
+
switch (this.query.sortBy) {
|
|
8081
|
+
case 'firstCreated':
|
|
8082
|
+
return sortByFirstCreated;
|
|
8083
|
+
case 'lastCreated':
|
|
8084
|
+
return sortByLastCreated;
|
|
8085
|
+
default:
|
|
8086
|
+
return sortByLastCreated;
|
|
8087
|
+
}
|
|
8088
|
+
})();
|
|
8089
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
8090
|
+
return joinRequest;
|
|
8091
|
+
}
|
|
8092
|
+
}
|
|
8093
|
+
|
|
8094
|
+
/**
|
|
8095
|
+
* Get Join Requests
|
|
8096
|
+
*
|
|
8097
|
+
* @param params the query parameters
|
|
8098
|
+
* @param callback the callback to be called when the join request are updated
|
|
8099
|
+
* @returns joinRequests
|
|
8100
|
+
*
|
|
8101
|
+
* @category joinRequest Live Collection
|
|
8102
|
+
*
|
|
8103
|
+
*/
|
|
8104
|
+
const getJoinRequests = (params, callback, config) => {
|
|
8105
|
+
const { log, cache } = getActiveClient();
|
|
8106
|
+
if (!cache) {
|
|
8107
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
8108
|
+
}
|
|
8109
|
+
const timestamp = Date.now();
|
|
8110
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
8111
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
8112
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
8113
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
8114
|
+
disposers.push(() => {
|
|
8115
|
+
dropFromCache(cacheKey);
|
|
8116
|
+
});
|
|
8117
|
+
return () => {
|
|
8118
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
8119
|
+
disposers.forEach(fn => fn());
|
|
8120
|
+
};
|
|
8121
|
+
};
|
|
8122
|
+
|
|
8123
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
8124
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
8125
|
+
};
|
|
8126
|
+
|
|
8127
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
8128
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
8129
|
+
};
|
|
8130
|
+
|
|
8131
|
+
/* begin_public_function
|
|
8132
|
+
id: invitation.createInvitations
|
|
8133
|
+
*/
|
|
8134
|
+
/**
|
|
8135
|
+
* ```js
|
|
8136
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
8137
|
+
* const created = await createInvitations({
|
|
8138
|
+
* type: string,
|
|
8139
|
+
* targetType: string,
|
|
8140
|
+
* targetId: string,
|
|
8141
|
+
* userIds: string[]
|
|
8142
|
+
* }))
|
|
8143
|
+
* ```
|
|
8144
|
+
*
|
|
8145
|
+
* Creates an {@link Amity.Invitation}
|
|
8146
|
+
*
|
|
8147
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
8148
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
8149
|
+
*
|
|
8150
|
+
* @category Invitation API
|
|
8151
|
+
* @async
|
|
8152
|
+
*/
|
|
8153
|
+
const createInvitations = async (bundle) => {
|
|
8154
|
+
const client = getActiveClient();
|
|
8155
|
+
client.log('invitation/createInvitations', bundle);
|
|
8156
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
8157
|
+
const data = prepareInvitationPayload(payload);
|
|
8158
|
+
const cachedAt = client.cache && Date.now();
|
|
8159
|
+
if (client.cache)
|
|
8160
|
+
ingestInCache(data, { cachedAt });
|
|
8161
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
8162
|
+
return {
|
|
8163
|
+
data: data.invitations,
|
|
8164
|
+
cachedAt,
|
|
8165
|
+
};
|
|
8166
|
+
};
|
|
8167
|
+
/* end_public_function */
|
|
8168
|
+
|
|
8169
|
+
/* begin_public_function
|
|
8170
|
+
id: invitation.accept
|
|
8171
|
+
*/
|
|
8172
|
+
/**
|
|
8173
|
+
* ```js
|
|
8174
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
8175
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
8176
|
+
* ```
|
|
8177
|
+
*
|
|
8178
|
+
* Accepts a {@link Amity.Invitation} object
|
|
8179
|
+
*
|
|
8180
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
8181
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
8182
|
+
*
|
|
8183
|
+
* @category Invitation API
|
|
8184
|
+
* @async
|
|
8185
|
+
*/
|
|
8186
|
+
const acceptInvitation = async (invitationId) => {
|
|
8187
|
+
var _a;
|
|
8188
|
+
const client = getActiveClient();
|
|
8189
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
8190
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
8191
|
+
const invitation = (_a = pullFromCache([
|
|
8192
|
+
'invitation',
|
|
8193
|
+
'get',
|
|
8194
|
+
invitationId,
|
|
8195
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8196
|
+
if (invitation) {
|
|
8197
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
8198
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
8199
|
+
}
|
|
8200
|
+
return data.success;
|
|
8201
|
+
};
|
|
8202
|
+
/* end_public_function */
|
|
8203
|
+
|
|
8204
|
+
/* begin_public_function
|
|
8205
|
+
id: invitation.reject
|
|
8206
|
+
*/
|
|
8207
|
+
/**
|
|
8208
|
+
* ```js
|
|
8209
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
8210
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
8211
|
+
* ```
|
|
8212
|
+
*
|
|
8213
|
+
* Rejects a {@link Amity.Invitation} object
|
|
8214
|
+
*
|
|
8215
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
8216
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
8217
|
+
*
|
|
8218
|
+
* @category Invitation API
|
|
8219
|
+
* @async
|
|
8220
|
+
*/
|
|
8221
|
+
const rejectInvitation = async (invitationId) => {
|
|
8222
|
+
var _a;
|
|
8223
|
+
const client = getActiveClient();
|
|
8224
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
8225
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
8226
|
+
const invitation = (_a = pullFromCache([
|
|
8227
|
+
'invitation',
|
|
8228
|
+
'get',
|
|
8229
|
+
invitationId,
|
|
8230
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8231
|
+
if (invitation) {
|
|
8232
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
8233
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
8234
|
+
}
|
|
8235
|
+
return data.success;
|
|
8236
|
+
};
|
|
8237
|
+
/* end_public_function */
|
|
8238
|
+
|
|
8239
|
+
/* begin_public_function
|
|
8240
|
+
id: invitation.cancel
|
|
8241
|
+
*/
|
|
8242
|
+
/**
|
|
8243
|
+
* ```js
|
|
8244
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
8245
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
8246
|
+
* ```
|
|
8247
|
+
*
|
|
8248
|
+
* Cancels a {@link Amity.Invitation} object
|
|
8249
|
+
*
|
|
8250
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
8251
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
8252
|
+
*
|
|
8253
|
+
* @category Invitation API
|
|
8254
|
+
* @async
|
|
8255
|
+
*/
|
|
8256
|
+
const cancelInvitation = async (invitationId) => {
|
|
8257
|
+
var _a;
|
|
8258
|
+
const client = getActiveClient();
|
|
8259
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
8260
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
8261
|
+
const invitation = (_a = pullFromCache([
|
|
8262
|
+
'invitation',
|
|
8263
|
+
'get',
|
|
8264
|
+
invitationId,
|
|
8265
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8266
|
+
if (invitation) {
|
|
8267
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
8268
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
8269
|
+
}
|
|
8270
|
+
return data.success;
|
|
8271
|
+
};
|
|
8272
|
+
/* end_public_function */
|
|
8273
|
+
|
|
8274
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
8275
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
8276
|
+
};
|
|
8277
|
+
|
|
8278
|
+
const invitationLinkedObject = (invitation) => {
|
|
8279
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
8280
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
8281
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8282
|
+
return userLinkedObject(cacheData.data);
|
|
8283
|
+
return undefined;
|
|
8284
|
+
},
|
|
8285
|
+
get createdBy() {
|
|
8286
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
8287
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8288
|
+
return userLinkedObject(cacheData.data);
|
|
8289
|
+
return undefined;
|
|
8290
|
+
},
|
|
8291
|
+
get target() {
|
|
8292
|
+
if (invitation.targetType === 'community') {
|
|
8293
|
+
const cacheData = pullFromCache([
|
|
8294
|
+
'community',
|
|
8295
|
+
'get',
|
|
8296
|
+
invitation.targetId,
|
|
8297
|
+
]);
|
|
8298
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
8299
|
+
return cacheData.data;
|
|
8300
|
+
return undefined;
|
|
8301
|
+
}
|
|
8302
|
+
return undefined;
|
|
8303
|
+
}, accept: async () => {
|
|
8304
|
+
await acceptInvitation(invitation._id);
|
|
8305
|
+
}, reject: async () => {
|
|
8306
|
+
await rejectInvitation(invitation._id);
|
|
8307
|
+
}, cancel: async () => {
|
|
8308
|
+
await cancelInvitation(invitation._id);
|
|
8309
|
+
} });
|
|
8310
|
+
};
|
|
8311
|
+
|
|
8312
|
+
/* begin_public_function
|
|
8313
|
+
id: invitation.get
|
|
8314
|
+
*/
|
|
8315
|
+
/**
|
|
8316
|
+
* ```js
|
|
8317
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
8318
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
8319
|
+
* ```
|
|
8320
|
+
*
|
|
8321
|
+
* Get a {@link Amity.Invitation} object
|
|
8322
|
+
*
|
|
8323
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
8324
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
8325
|
+
* @returns A {@link Amity.Invitation} object
|
|
8326
|
+
*
|
|
8327
|
+
* @category Invitation API
|
|
8328
|
+
* @async
|
|
8329
|
+
*/
|
|
8330
|
+
const getInvitation = async (targetType, targetId) => {
|
|
8331
|
+
const client = getActiveClient();
|
|
8332
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
8333
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
8334
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
8335
|
+
const cachedAt = client.cache && Date.now();
|
|
8336
|
+
if (client.cache)
|
|
8337
|
+
ingestInCache(data, { cachedAt });
|
|
8338
|
+
return {
|
|
8339
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
8340
|
+
cachedAt,
|
|
8341
|
+
};
|
|
8342
|
+
};
|
|
8343
|
+
/* end_public_function */
|
|
8344
|
+
|
|
8345
|
+
var InvitationActionsEnum;
|
|
8346
|
+
(function (InvitationActionsEnum) {
|
|
8347
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
8348
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
8349
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
8350
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
8351
|
+
|
|
8352
|
+
class InvitationsPaginationController extends PaginationController {
|
|
8353
|
+
async getRequest(queryParams, token) {
|
|
8354
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
8355
|
+
const options = token ? { token } : { limit };
|
|
8356
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
8357
|
+
return data;
|
|
8358
|
+
}
|
|
8359
|
+
}
|
|
8360
|
+
|
|
8361
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
8362
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
8363
|
+
super(query, cacheKey);
|
|
8364
|
+
this.notifyChange = notifyChange;
|
|
8365
|
+
this.preparePayload = preparePayload;
|
|
8366
|
+
}
|
|
8367
|
+
async saveToMainDB(response) {
|
|
8368
|
+
const processedPayload = await this.preparePayload(response);
|
|
8369
|
+
const client = getActiveClient();
|
|
8370
|
+
const cachedAt = client.cache && Date.now();
|
|
8371
|
+
if (client.cache) {
|
|
8372
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
8373
|
+
}
|
|
8374
|
+
}
|
|
8375
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
8376
|
+
var _a, _b;
|
|
8377
|
+
if (refresh) {
|
|
8378
|
+
pushToCache(this.cacheKey, {
|
|
8379
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
8380
|
+
});
|
|
8381
|
+
}
|
|
8382
|
+
else {
|
|
8383
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8384
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
8385
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
8386
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
8387
|
+
] }));
|
|
8388
|
+
}
|
|
8389
|
+
}
|
|
8390
|
+
reactor(action) {
|
|
8391
|
+
return (invitations) => {
|
|
8392
|
+
var _a;
|
|
8393
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8394
|
+
if (!collection)
|
|
8395
|
+
return;
|
|
8396
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
8397
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
8398
|
+
if (!isExist)
|
|
8399
|
+
return;
|
|
8400
|
+
}
|
|
8401
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
8402
|
+
collection.data = [
|
|
8403
|
+
...new Set([
|
|
8404
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
8405
|
+
...collection.data,
|
|
8406
|
+
]),
|
|
8407
|
+
];
|
|
8408
|
+
}
|
|
8409
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
8410
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
8411
|
+
}
|
|
8412
|
+
pushToCache(this.cacheKey, collection);
|
|
8413
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
8414
|
+
};
|
|
8415
|
+
}
|
|
8416
|
+
subscribeRTE(createSubscriber) {
|
|
8417
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
7839
8418
|
}
|
|
7840
8419
|
}
|
|
7841
8420
|
|
|
@@ -8047,6 +8626,13 @@ const communityLinkedObject = (community) => {
|
|
|
8047
8626
|
}, getInvitation: async () => {
|
|
8048
8627
|
const { data } = await getInvitation('community', community.communityId);
|
|
8049
8628
|
return data;
|
|
8629
|
+
}, join: async () => {
|
|
8630
|
+
return joinRequest(community.communityId);
|
|
8631
|
+
}, getJoinRequests: (params, callback) => {
|
|
8632
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
8633
|
+
}, getMyJoinRequest: async () => {
|
|
8634
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
8635
|
+
return data;
|
|
8050
8636
|
} });
|
|
8051
8637
|
};
|
|
8052
8638
|
|
|
@@ -8066,6 +8652,7 @@ const LinkedObject = {
|
|
|
8066
8652
|
notificationTray: notificationTrayLinkedObject,
|
|
8067
8653
|
community: communityLinkedObject,
|
|
8068
8654
|
invitation: invitationLinkedObject,
|
|
8655
|
+
joinRequest: joinRequestLinkedObject,
|
|
8069
8656
|
};
|
|
8070
8657
|
|
|
8071
8658
|
const constructChannelObject = (channel) => {
|
|
@@ -13622,41 +14209,6 @@ getComment$2.locally = (commentId) => {
|
|
|
13622
14209
|
};
|
|
13623
14210
|
};
|
|
13624
14211
|
|
|
13625
|
-
/*
|
|
13626
|
-
* verifies membership status
|
|
13627
|
-
*/
|
|
13628
|
-
function isMember(membership) {
|
|
13629
|
-
return membership !== 'none';
|
|
13630
|
-
}
|
|
13631
|
-
/*
|
|
13632
|
-
* checks if currently logged in user is part of the community
|
|
13633
|
-
*/
|
|
13634
|
-
function isCurrentUserPartOfCommunity(c, m) {
|
|
13635
|
-
const { userId } = getActiveUser();
|
|
13636
|
-
return c.communityId === m.communityId && m.userId === userId;
|
|
13637
|
-
}
|
|
13638
|
-
/*
|
|
13639
|
-
* For mqtt events server will not send user specific data as it's broadcasted
|
|
13640
|
-
* to multiple users and it also does not include communityUser
|
|
13641
|
-
*
|
|
13642
|
-
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
13643
|
-
* Althought this can be calculated, it's not scalable.
|
|
13644
|
-
*/
|
|
13645
|
-
function updateMembershipStatus(communities, communityUsers) {
|
|
13646
|
-
return communities.map(c => {
|
|
13647
|
-
const cachedCommunity = pullFromCache([
|
|
13648
|
-
'community',
|
|
13649
|
-
'get',
|
|
13650
|
-
c.communityId,
|
|
13651
|
-
]);
|
|
13652
|
-
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
13653
|
-
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
13654
|
-
}
|
|
13655
|
-
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
13656
|
-
return Object.assign(Object.assign({}, c), { isJoined });
|
|
13657
|
-
});
|
|
13658
|
-
}
|
|
13659
|
-
|
|
13660
14212
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
13661
14213
|
var _a, _b;
|
|
13662
14214
|
let id;
|
|
@@ -13971,53 +14523,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
13971
14523
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
13972
14524
|
};
|
|
13973
14525
|
|
|
13974
|
-
const getMatchPostSetting = (value) => {
|
|
13975
|
-
var _a;
|
|
13976
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
13977
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
13978
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
13979
|
-
};
|
|
13980
|
-
function addPostSetting({ communities }) {
|
|
13981
|
-
return communities.map((_a) => {
|
|
13982
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
13983
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
13984
|
-
needApprovalOnPostCreation,
|
|
13985
|
-
onlyAdminCanPost,
|
|
13986
|
-
}) }, restCommunityPayload));
|
|
13987
|
-
});
|
|
13988
|
-
}
|
|
13989
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
13990
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
13991
|
-
// map users with community
|
|
13992
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
13993
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
13994
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
13995
|
-
});
|
|
13996
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
13997
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
13998
|
-
};
|
|
13999
|
-
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
14000
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
14001
|
-
// map users with community
|
|
14002
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
14003
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
14004
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
14005
|
-
});
|
|
14006
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
14007
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
14008
|
-
};
|
|
14009
|
-
const prepareCommunityRequest = (params) => {
|
|
14010
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
14011
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
14012
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
14013
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
14014
|
-
};
|
|
14015
|
-
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
14016
|
-
var communityPayload = __rest(_a, ["searchResult"]);
|
|
14017
|
-
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
14018
|
-
return Object.assign({}, processedCommunityPayload);
|
|
14019
|
-
};
|
|
14020
|
-
|
|
14021
14526
|
const preparePostPayload = (payload) => {
|
|
14022
14527
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
14023
14528
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -19081,10 +19586,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
19081
19586
|
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
19082
19587
|
const client = getActiveClient();
|
|
19083
19588
|
client.log('community/getCommunities', communityIds);
|
|
19589
|
+
const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
19084
19590
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
19085
19591
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
19086
19592
|
params: {
|
|
19087
|
-
communityIds,
|
|
19593
|
+
communityIds: encodedCommunityIds,
|
|
19088
19594
|
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
19089
19595
|
},
|
|
19090
19596
|
});
|
|
@@ -19218,11 +19724,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
19218
19724
|
* @category Community API
|
|
19219
19725
|
* @async
|
|
19220
19726
|
*/
|
|
19221
|
-
const getCommunity$1 = async (communityId) => {
|
|
19727
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
19222
19728
|
const client = getActiveClient();
|
|
19223
19729
|
client.log('community/getCommunity', communityId);
|
|
19224
19730
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
19225
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
19731
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
19732
|
+
params: {
|
|
19733
|
+
type: 'communityJoinRequest',
|
|
19734
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
19735
|
+
},
|
|
19736
|
+
});
|
|
19226
19737
|
const data = prepareCommunityPayload(payload);
|
|
19227
19738
|
const cachedAt = client.cache && Date.now();
|
|
19228
19739
|
if (client.cache) {
|
|
@@ -19297,6 +19808,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
19297
19808
|
};
|
|
19298
19809
|
/* end_public_function */
|
|
19299
19810
|
|
|
19811
|
+
/**
|
|
19812
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
19813
|
+
*/
|
|
19300
19814
|
/* begin_public_function
|
|
19301
19815
|
id: community.join
|
|
19302
19816
|
*/
|
|
@@ -19437,10 +19951,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
19437
19951
|
*/
|
|
19438
19952
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
19439
19953
|
async getRequest(queryParams, token) {
|
|
19954
|
+
var _a;
|
|
19440
19955
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19441
19956
|
const options = token ? { token } : { limit };
|
|
19442
19957
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
19443
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
19958
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, includeDiscoverablePrivateCommunity: (_a = params.includeDiscoverablePrivateCommunity) !== null && _a !== void 0 ? _a : true, options }),
|
|
19444
19959
|
});
|
|
19445
19960
|
return queryResponse;
|
|
19446
19961
|
}
|
|
@@ -19940,6 +20455,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
19940
20455
|
|
|
19941
20456
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
19942
20457
|
|
|
20458
|
+
const onLocalCommunityJoin = (callback) => {
|
|
20459
|
+
const client = getActiveClient();
|
|
20460
|
+
const filter = async (rawPayload) => {
|
|
20461
|
+
callback(rawPayload[0]);
|
|
20462
|
+
};
|
|
20463
|
+
const disposers = [
|
|
20464
|
+
createEventSubscriber(client, 'onCommunityUpdate', 'local.community.join', filter),
|
|
20465
|
+
];
|
|
20466
|
+
return () => {
|
|
20467
|
+
disposers.forEach(fn => fn());
|
|
20468
|
+
};
|
|
20469
|
+
};
|
|
20470
|
+
|
|
19943
20471
|
/**
|
|
19944
20472
|
* ```js
|
|
19945
20473
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -20426,7 +20954,8 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
20426
20954
|
onCommunityJoined: onCommunityJoined,
|
|
20427
20955
|
onCommunityLeft: onCommunityLeft,
|
|
20428
20956
|
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
20429
|
-
onLocalCommunityLeft: onLocalCommunityLeft
|
|
20957
|
+
onLocalCommunityLeft: onLocalCommunityLeft,
|
|
20958
|
+
onLocalCommunityJoin: onLocalCommunityJoin
|
|
20430
20959
|
});
|
|
20431
20960
|
|
|
20432
20961
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -20650,6 +21179,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20650
21179
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
20651
21180
|
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20652
21181
|
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
21182
|
+
{
|
|
21183
|
+
fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
21184
|
+
action: EnumCommunityActions$3.OnCommunityUpdated,
|
|
21185
|
+
},
|
|
20653
21186
|
]);
|
|
20654
21187
|
}
|
|
20655
21188
|
notifyChange({ origin, loading, error }) {
|
|
@@ -20773,6 +21306,7 @@ const getCommunity = (communityId, callback) => {
|
|
|
20773
21306
|
onCommunityUserBanned,
|
|
20774
21307
|
onCommunityUserUnbanned,
|
|
20775
21308
|
onCommunityUserChanged,
|
|
21309
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
20776
21310
|
]);
|
|
20777
21311
|
};
|
|
20778
21312
|
/* end_public_function */
|
|
@@ -20887,7 +21421,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
20887
21421
|
const data = (_b = collection.data
|
|
20888
21422
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
20889
21423
|
.filter(isNonNullable)
|
|
20890
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
21424
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
20891
21425
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
20892
21426
|
return;
|
|
20893
21427
|
this.callback({
|
|
@@ -21049,7 +21583,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
21049
21583
|
const data = (_b = collection.data
|
|
21050
21584
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
21051
21585
|
.filter(isNonNullable)
|
|
21052
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
21586
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
21053
21587
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
21054
21588
|
return;
|
|
21055
21589
|
this.callback({
|
|
@@ -21289,6 +21823,200 @@ const semanticSearchCommunities = (params, callback, config) => {
|
|
|
21289
21823
|
};
|
|
21290
21824
|
};
|
|
21291
21825
|
|
|
21826
|
+
/**
|
|
21827
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
21828
|
+
* TODO: check if querybyIds is supported
|
|
21829
|
+
*/
|
|
21830
|
+
class JoinRequestListPaginationController extends PaginationController {
|
|
21831
|
+
async getRequest(queryParams, token) {
|
|
21832
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
|
|
21833
|
+
const options = token ? { token } : { limit };
|
|
21834
|
+
const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
21835
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
|
|
21836
|
+
params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
|
|
21837
|
+
});
|
|
21838
|
+
return queryResponse;
|
|
21839
|
+
}
|
|
21840
|
+
}
|
|
21841
|
+
|
|
21842
|
+
var EnumJoinRequestAction;
|
|
21843
|
+
(function (EnumJoinRequestAction) {
|
|
21844
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
21845
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
21846
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
21847
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
21848
|
+
|
|
21849
|
+
class JoinRequestListQueryStreamController extends QueryStreamController {
|
|
21850
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
21851
|
+
super(query, cacheKey);
|
|
21852
|
+
this.notifyChange = notifyChange;
|
|
21853
|
+
this.preparePayload = preparePayload;
|
|
21854
|
+
}
|
|
21855
|
+
async saveToMainDB(response) {
|
|
21856
|
+
const processedPayload = await this.preparePayload(response);
|
|
21857
|
+
const client = getActiveClient();
|
|
21858
|
+
const cachedAt = client.cache && Date.now();
|
|
21859
|
+
if (client.cache) {
|
|
21860
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21861
|
+
}
|
|
21862
|
+
}
|
|
21863
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21864
|
+
var _a, _b;
|
|
21865
|
+
if (refresh) {
|
|
21866
|
+
pushToCache(this.cacheKey, {
|
|
21867
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
21868
|
+
});
|
|
21869
|
+
}
|
|
21870
|
+
else {
|
|
21871
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21872
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21873
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
21874
|
+
...new Set([
|
|
21875
|
+
...joinRequests,
|
|
21876
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
21877
|
+
]),
|
|
21878
|
+
] }));
|
|
21879
|
+
}
|
|
21880
|
+
}
|
|
21881
|
+
reactor(action) {
|
|
21882
|
+
return (joinRequest) => {
|
|
21883
|
+
var _a;
|
|
21884
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21885
|
+
if (!collection)
|
|
21886
|
+
return;
|
|
21887
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
21888
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
21889
|
+
if (!isExist)
|
|
21890
|
+
return;
|
|
21891
|
+
}
|
|
21892
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
21893
|
+
collection.data = [
|
|
21894
|
+
...new Set([
|
|
21895
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
21896
|
+
...collection.data,
|
|
21897
|
+
]),
|
|
21898
|
+
];
|
|
21899
|
+
}
|
|
21900
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
21901
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
21902
|
+
}
|
|
21903
|
+
pushToCache(this.cacheKey, collection);
|
|
21904
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21905
|
+
};
|
|
21906
|
+
}
|
|
21907
|
+
subscribeRTE(createSubscriber) {
|
|
21908
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
21909
|
+
}
|
|
21910
|
+
}
|
|
21911
|
+
|
|
21912
|
+
class JoinRequestListLiveCollectionController extends LiveCollectionController {
|
|
21913
|
+
constructor(query, callback) {
|
|
21914
|
+
const queryStreamId = hash__default["default"](query);
|
|
21915
|
+
const cacheKey = ['joinRequestList', 'collection', queryStreamId];
|
|
21916
|
+
const paginationController = new JoinRequestListPaginationController(query);
|
|
21917
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21918
|
+
this.query = query;
|
|
21919
|
+
this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
21920
|
+
this.callback = callback.bind(this);
|
|
21921
|
+
this.loadPage({ initial: true });
|
|
21922
|
+
}
|
|
21923
|
+
setup() {
|
|
21924
|
+
var _a;
|
|
21925
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21926
|
+
if (!collection) {
|
|
21927
|
+
pushToCache(this.cacheKey, {
|
|
21928
|
+
data: [],
|
|
21929
|
+
params: this.query,
|
|
21930
|
+
});
|
|
21931
|
+
}
|
|
21932
|
+
}
|
|
21933
|
+
async persistModel(queryPayload) {
|
|
21934
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
21935
|
+
}
|
|
21936
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
21937
|
+
const joinRequestResponse = response;
|
|
21938
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
21939
|
+
}
|
|
21940
|
+
startSubscription() {
|
|
21941
|
+
return this.queryStreamController.subscribeRTE([
|
|
21942
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
21943
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
21944
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
21945
|
+
]);
|
|
21946
|
+
}
|
|
21947
|
+
notifyChange({ origin, loading, error }) {
|
|
21948
|
+
var _a;
|
|
21949
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21950
|
+
if (!collection)
|
|
21951
|
+
return;
|
|
21952
|
+
const data = this.applyFilter(collection.data
|
|
21953
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
21954
|
+
.filter(isNonNullable)
|
|
21955
|
+
.map(({ data }) => data)
|
|
21956
|
+
.map(joinRequestLinkedObject));
|
|
21957
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
21958
|
+
return;
|
|
21959
|
+
this.callback({
|
|
21960
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
21961
|
+
data,
|
|
21962
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
21963
|
+
loading,
|
|
21964
|
+
error,
|
|
21965
|
+
});
|
|
21966
|
+
}
|
|
21967
|
+
applyFilter(data) {
|
|
21968
|
+
let joinRequest = data;
|
|
21969
|
+
if (this.query.communityIds && this.query.communityIds.length > 0) {
|
|
21970
|
+
joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
|
|
21971
|
+
}
|
|
21972
|
+
const sortFn = (() => {
|
|
21973
|
+
switch (this.query.sortBy) {
|
|
21974
|
+
case 'firstCreated':
|
|
21975
|
+
return sortByFirstCreated;
|
|
21976
|
+
case 'lastCreated':
|
|
21977
|
+
return sortByLastCreated;
|
|
21978
|
+
default:
|
|
21979
|
+
return sortByLastCreated;
|
|
21980
|
+
}
|
|
21981
|
+
})();
|
|
21982
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
21983
|
+
return joinRequest;
|
|
21984
|
+
}
|
|
21985
|
+
}
|
|
21986
|
+
|
|
21987
|
+
/* begin_public_function
|
|
21988
|
+
id: community.getJoinRequestList
|
|
21989
|
+
*/
|
|
21990
|
+
/**
|
|
21991
|
+
* Get Join Requests
|
|
21992
|
+
*
|
|
21993
|
+
* @param params the query parameters
|
|
21994
|
+
* @param callback the callback to be called when the join request are updated
|
|
21995
|
+
* @returns joinRequest[]
|
|
21996
|
+
*
|
|
21997
|
+
* @category joinRequestList Live Collection
|
|
21998
|
+
*
|
|
21999
|
+
*/
|
|
22000
|
+
const getJoinRequestList = (params, callback, config) => {
|
|
22001
|
+
const { log, cache } = getActiveClient();
|
|
22002
|
+
if (!cache) {
|
|
22003
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
22004
|
+
}
|
|
22005
|
+
const timestamp = Date.now();
|
|
22006
|
+
log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
|
|
22007
|
+
const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
|
|
22008
|
+
const disposers = joinRequestListLiveCollection.startSubscription();
|
|
22009
|
+
const cacheKey = joinRequestListLiveCollection.getCacheKey();
|
|
22010
|
+
disposers.push(() => {
|
|
22011
|
+
dropFromCache(cacheKey);
|
|
22012
|
+
});
|
|
22013
|
+
return () => {
|
|
22014
|
+
log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
|
|
22015
|
+
disposers.forEach(fn => fn());
|
|
22016
|
+
};
|
|
22017
|
+
};
|
|
22018
|
+
/* end_public_function */
|
|
22019
|
+
|
|
21292
22020
|
var AmityCommunityMemberStatusFilter;
|
|
21293
22021
|
(function (AmityCommunityMemberStatusFilter) {
|
|
21294
22022
|
AmityCommunityMemberStatusFilter["ALL"] = "all";
|
|
@@ -21459,6 +22187,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
21459
22187
|
getTrendingCommunities: getTrendingCommunities,
|
|
21460
22188
|
getRecommendedCommunities: getRecommendedCommunities,
|
|
21461
22189
|
semanticSearchCommunities: semanticSearchCommunities,
|
|
22190
|
+
getJoinRequestList: getJoinRequestList,
|
|
21462
22191
|
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
21463
22192
|
});
|
|
21464
22193
|
|
|
@@ -23699,7 +24428,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
23699
24428
|
const client = getActiveClient();
|
|
23700
24429
|
const cachedAt = client.cache && Date.now();
|
|
23701
24430
|
if (client.cache) {
|
|
23702
|
-
|
|
24431
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
24432
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23703
24433
|
}
|
|
23704
24434
|
}
|
|
23705
24435
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -23828,7 +24558,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
23828
24558
|
const client = getActiveClient();
|
|
23829
24559
|
const cachedAt = client.cache && Date.now();
|
|
23830
24560
|
if (client.cache) {
|
|
23831
|
-
|
|
24561
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
24562
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23832
24563
|
}
|
|
23833
24564
|
}
|
|
23834
24565
|
appendToQueryStream(response, direction, refresh = false) {
|