@amityco/ts-sdk 7.4.1-4207cb63.0 → 7.4.1-7cfcde16.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/invitation.d.ts +0 -1
- package/dist/@types/domains/invitation.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 +943 -257
- package/dist/index.esm.js +1082 -396
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/internalApi/index.d.ts +0 -1
- package/dist/invitationRepository/internalApi/index.d.ts.map +1 -1
- 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/invitationLinkedObject.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 +6 -0
- 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/invitation.ts +0 -1
- 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/invitationRepository/internalApi/index.ts +0 -1
- 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 +20 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +1 -8
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +25 -0
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +0 -16
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +0 -1
- package/src/invitationRepository/internalApi/cancelInvitation.ts +0 -44
package/dist/index.esm.js
CHANGED
|
@@ -121,6 +121,19 @@ var InvitationSortByEnum;
|
|
|
121
121
|
InvitationSortByEnum["LastCreated"] = "lastCreated";
|
|
122
122
|
})(InvitationSortByEnum || (InvitationSortByEnum = {}));
|
|
123
123
|
|
|
124
|
+
var JoinRequestStatusEnum;
|
|
125
|
+
(function (JoinRequestStatusEnum) {
|
|
126
|
+
JoinRequestStatusEnum["Pending"] = "pending";
|
|
127
|
+
JoinRequestStatusEnum["Approved"] = "approved";
|
|
128
|
+
JoinRequestStatusEnum["Rejected"] = "rejected";
|
|
129
|
+
JoinRequestStatusEnum["Cancelled"] = "cancelled";
|
|
130
|
+
})(JoinRequestStatusEnum || (JoinRequestStatusEnum = {}));
|
|
131
|
+
var JoinResultStatusEnum;
|
|
132
|
+
(function (JoinResultStatusEnum) {
|
|
133
|
+
JoinResultStatusEnum["Success"] = "success";
|
|
134
|
+
JoinResultStatusEnum["Pending"] = "pending";
|
|
135
|
+
})(JoinResultStatusEnum || (JoinResultStatusEnum = {}));
|
|
136
|
+
|
|
124
137
|
function getVersion() {
|
|
125
138
|
try {
|
|
126
139
|
// the string ''v7.4.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -568,6 +581,7 @@ const idResolvers = {
|
|
|
568
581
|
notificationTrayItem: ({ _id }) => _id,
|
|
569
582
|
notificationTraySeen: ({ userId }) => userId,
|
|
570
583
|
invitation: ({ _id }) => _id,
|
|
584
|
+
joinRequest: ({ joinRequestId }) => joinRequestId,
|
|
571
585
|
};
|
|
572
586
|
/**
|
|
573
587
|
* Retrieve the id resolver matching a domain name
|
|
@@ -621,6 +635,7 @@ const PAYLOAD2MODEL = {
|
|
|
621
635
|
pins: 'pin',
|
|
622
636
|
notificationTrayItems: 'notificationTrayItem',
|
|
623
637
|
invitations: 'invitation',
|
|
638
|
+
joinRequests: 'joinRequest',
|
|
624
639
|
};
|
|
625
640
|
/** hidden */
|
|
626
641
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -21559,6 +21574,10 @@ function convertQueryParams$1(_a) {
|
|
|
21559
21574
|
return out;
|
|
21560
21575
|
}
|
|
21561
21576
|
|
|
21577
|
+
function convertRawUserToInternalUser(rawUser) {
|
|
21578
|
+
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
21579
|
+
}
|
|
21580
|
+
|
|
21562
21581
|
const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21563
21582
|
/**
|
|
21564
21583
|
* Filter sub channel by type. Only conversation, community and broadcast type are included.
|
|
@@ -21587,8 +21606,9 @@ const prepareSubChannelPayload = async (rawPayload) => {
|
|
|
21587
21606
|
// attach marker to sub channel
|
|
21588
21607
|
const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
|
|
21589
21608
|
const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
|
|
21609
|
+
const user = rawPayload.users.map(convertRawUserToInternalUser);
|
|
21590
21610
|
return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
|
|
21591
|
-
messages });
|
|
21611
|
+
messages, users: user });
|
|
21592
21612
|
};
|
|
21593
21613
|
function convertQueryParams(_a) {
|
|
21594
21614
|
var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
|
|
@@ -21853,10 +21873,6 @@ const handleSubChannelUpdated = async (subChannel) => {
|
|
|
21853
21873
|
}
|
|
21854
21874
|
};
|
|
21855
21875
|
|
|
21856
|
-
function convertRawUserToInternalUser(rawUser) {
|
|
21857
|
-
return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
|
|
21858
|
-
}
|
|
21859
|
-
|
|
21860
21876
|
const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
|
|
21861
21877
|
const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
|
|
21862
21878
|
function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
|
|
@@ -23446,235 +23462,299 @@ const notificationTrayLinkedObject = (noti) => {
|
|
|
23446
23462
|
.map(user => userLinkedObject(user)) });
|
|
23447
23463
|
};
|
|
23448
23464
|
|
|
23449
|
-
|
|
23450
|
-
|
|
23451
|
-
|
|
23465
|
+
/*
|
|
23466
|
+
* verifies membership status
|
|
23467
|
+
*/
|
|
23468
|
+
function isMember(membership) {
|
|
23469
|
+
return membership !== 'none';
|
|
23470
|
+
}
|
|
23471
|
+
/*
|
|
23472
|
+
* checks if currently logged in user is part of the community
|
|
23473
|
+
*/
|
|
23474
|
+
function isCurrentUserPartOfCommunity(c, m) {
|
|
23475
|
+
const { userId } = getActiveUser();
|
|
23476
|
+
return c.communityId === m.communityId && m.userId === userId;
|
|
23477
|
+
}
|
|
23478
|
+
/*
|
|
23479
|
+
* For mqtt events server will not send user specific data as it's broadcasted
|
|
23480
|
+
* to multiple users and it also does not include communityUser
|
|
23481
|
+
*
|
|
23482
|
+
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
23483
|
+
* Althought this can be calculated, it's not scalable.
|
|
23484
|
+
*/
|
|
23485
|
+
function updateMembershipStatus(communities, communityUsers) {
|
|
23486
|
+
return communities.map(c => {
|
|
23487
|
+
const cachedCommunity = pullFromCache([
|
|
23488
|
+
'community',
|
|
23489
|
+
'get',
|
|
23490
|
+
c.communityId,
|
|
23491
|
+
]);
|
|
23492
|
+
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
23493
|
+
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
23494
|
+
}
|
|
23495
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
23496
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
23497
|
+
});
|
|
23498
|
+
}
|
|
23452
23499
|
|
|
23453
|
-
const
|
|
23454
|
-
|
|
23500
|
+
const getMatchPostSetting = (value) => {
|
|
23501
|
+
var _a;
|
|
23502
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
23503
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
23504
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
23505
|
+
};
|
|
23506
|
+
function addPostSetting({ communities }) {
|
|
23507
|
+
return communities.map((_a) => {
|
|
23508
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
23509
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
23510
|
+
needApprovalOnPostCreation,
|
|
23511
|
+
onlyAdminCanPost,
|
|
23512
|
+
}) }, restCommunityPayload));
|
|
23513
|
+
});
|
|
23514
|
+
}
|
|
23515
|
+
const prepareCommunityPayload = (rawPayload) => {
|
|
23516
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
23517
|
+
// Convert users to internal format
|
|
23518
|
+
const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
|
|
23519
|
+
// map users with community
|
|
23520
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
23521
|
+
const user = internalUsers.find(user => user.userId === communityUser.userId);
|
|
23522
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
23523
|
+
});
|
|
23524
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
23525
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
23526
|
+
};
|
|
23527
|
+
const prepareCommunityJoinRequestPayload = (rawPayload) => {
|
|
23528
|
+
const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
|
|
23529
|
+
return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
|
|
23530
|
+
});
|
|
23531
|
+
const users = rawPayload.users.map(convertRawUserToInternalUser);
|
|
23532
|
+
return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
|
|
23533
|
+
};
|
|
23534
|
+
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
23535
|
+
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
23536
|
+
// map users with community
|
|
23537
|
+
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
23538
|
+
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
23539
|
+
return Object.assign(Object.assign({}, communityUser), { user });
|
|
23540
|
+
});
|
|
23541
|
+
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
23542
|
+
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
23543
|
+
};
|
|
23544
|
+
const prepareCommunityRequest = (params) => {
|
|
23545
|
+
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
23546
|
+
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
23547
|
+
// Convert story setting to the actual value. (Allow by default)
|
|
23548
|
+
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
23549
|
+
};
|
|
23550
|
+
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
23551
|
+
var communityPayload = __rest(_a, ["searchResult"]);
|
|
23552
|
+
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
23553
|
+
return Object.assign({}, processedCommunityPayload);
|
|
23455
23554
|
};
|
|
23456
23555
|
|
|
23457
23556
|
/* begin_public_function
|
|
23458
|
-
id:
|
|
23557
|
+
id: joinRequest.approve
|
|
23459
23558
|
*/
|
|
23460
23559
|
/**
|
|
23461
23560
|
* ```js
|
|
23462
|
-
* import {
|
|
23463
|
-
* const
|
|
23464
|
-
* type: string,
|
|
23465
|
-
* targetType: string,
|
|
23466
|
-
* targetId: string,
|
|
23467
|
-
* userIds: string[]
|
|
23468
|
-
* }))
|
|
23561
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23562
|
+
* const isAccepted = await joinRequest.approve()
|
|
23469
23563
|
* ```
|
|
23470
23564
|
*
|
|
23471
|
-
*
|
|
23565
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
23472
23566
|
*
|
|
23473
|
-
* @param
|
|
23474
|
-
* @returns
|
|
23567
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
23568
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
23475
23569
|
*
|
|
23476
|
-
* @category
|
|
23570
|
+
* @category Join Request API
|
|
23477
23571
|
* @async
|
|
23478
23572
|
*/
|
|
23479
|
-
const
|
|
23573
|
+
const approveJoinRequest = async (joinRequest) => {
|
|
23574
|
+
var _a;
|
|
23480
23575
|
const client = getActiveClient();
|
|
23481
|
-
client.log('
|
|
23482
|
-
const { data
|
|
23483
|
-
|
|
23484
|
-
|
|
23485
|
-
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
|
|
23576
|
+
client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
|
|
23577
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
|
|
23578
|
+
userId: joinRequest.requestorInternalId,
|
|
23579
|
+
});
|
|
23580
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23581
|
+
'joinRequest',
|
|
23582
|
+
'get',
|
|
23583
|
+
joinRequest.joinRequestId,
|
|
23584
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23585
|
+
if (joinRequestCache) {
|
|
23586
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23587
|
+
status: "approved" /* JoinRequestStatusEnum.Approved */,
|
|
23588
|
+
});
|
|
23589
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
23590
|
+
}
|
|
23591
|
+
return data.success;
|
|
23492
23592
|
};
|
|
23493
23593
|
/* end_public_function */
|
|
23494
23594
|
|
|
23495
23595
|
/* begin_public_function
|
|
23496
|
-
id:
|
|
23596
|
+
id: joinRequest.cancel
|
|
23497
23597
|
*/
|
|
23498
23598
|
/**
|
|
23499
23599
|
* ```js
|
|
23500
|
-
* import {
|
|
23501
|
-
* const
|
|
23600
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23601
|
+
* const isCanceled = await joinRequest.cancel()
|
|
23502
23602
|
* ```
|
|
23503
23603
|
*
|
|
23504
|
-
*
|
|
23604
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
23505
23605
|
*
|
|
23506
|
-
* @param
|
|
23507
|
-
* @returns A success boolean if the {@link Amity.
|
|
23606
|
+
* @param joinRequest the {@link Amity.JoinRequest} to cancel
|
|
23607
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was canceled
|
|
23508
23608
|
*
|
|
23509
|
-
* @category
|
|
23609
|
+
* @category Join Request API
|
|
23510
23610
|
* @async
|
|
23511
23611
|
*/
|
|
23512
|
-
const
|
|
23612
|
+
const cancelJoinRequest = async (joinRequest) => {
|
|
23513
23613
|
var _a;
|
|
23514
23614
|
const client = getActiveClient();
|
|
23515
|
-
client.log('
|
|
23516
|
-
const { data } = await client.http.
|
|
23517
|
-
const
|
|
23518
|
-
'
|
|
23615
|
+
client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
|
|
23616
|
+
const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
|
|
23617
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23618
|
+
'joinRequest',
|
|
23519
23619
|
'get',
|
|
23520
|
-
|
|
23620
|
+
joinRequest.joinRequestId,
|
|
23521
23621
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23522
|
-
if (
|
|
23523
|
-
|
|
23524
|
-
fireEvent('local.
|
|
23622
|
+
if (joinRequestCache) {
|
|
23623
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
23624
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
23525
23625
|
}
|
|
23526
23626
|
return data.success;
|
|
23527
23627
|
};
|
|
23528
23628
|
/* end_public_function */
|
|
23529
23629
|
|
|
23530
23630
|
/* begin_public_function
|
|
23531
|
-
id:
|
|
23631
|
+
id: joinRequest.reject
|
|
23532
23632
|
*/
|
|
23533
23633
|
/**
|
|
23534
23634
|
* ```js
|
|
23535
|
-
* import {
|
|
23536
|
-
* const isRejected = await
|
|
23635
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23636
|
+
* const isRejected = await joinRequest.reject()
|
|
23537
23637
|
* ```
|
|
23538
23638
|
*
|
|
23539
|
-
* Rejects a {@link Amity.
|
|
23639
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
23540
23640
|
*
|
|
23541
|
-
* @param
|
|
23542
|
-
* @returns A success boolean if the {@link Amity.
|
|
23641
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
23642
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
23543
23643
|
*
|
|
23544
|
-
* @category
|
|
23644
|
+
* @category Join Request API
|
|
23545
23645
|
* @async
|
|
23546
23646
|
*/
|
|
23547
|
-
const
|
|
23647
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
23548
23648
|
var _a;
|
|
23549
23649
|
const client = getActiveClient();
|
|
23550
|
-
client.log('
|
|
23551
|
-
const { data } = await client.http.post(`/api/
|
|
23552
|
-
|
|
23553
|
-
|
|
23650
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
23651
|
+
const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
|
|
23652
|
+
userId: joinRequest.requestorInternalId,
|
|
23653
|
+
});
|
|
23654
|
+
const joinRequestCache = (_a = pullFromCache([
|
|
23655
|
+
'joinRequest',
|
|
23554
23656
|
'get',
|
|
23555
|
-
|
|
23657
|
+
joinRequest.joinRequestId,
|
|
23556
23658
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23557
|
-
if (
|
|
23558
|
-
upsertInCache(['
|
|
23559
|
-
|
|
23659
|
+
if (joinRequestCache) {
|
|
23660
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23661
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
23662
|
+
});
|
|
23663
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
23560
23664
|
}
|
|
23561
23665
|
return data.success;
|
|
23562
23666
|
};
|
|
23563
23667
|
/* end_public_function */
|
|
23564
23668
|
|
|
23669
|
+
const joinRequestLinkedObject = (joinRequest) => {
|
|
23670
|
+
return Object.assign(Object.assign({}, joinRequest), { get user() {
|
|
23671
|
+
var _a;
|
|
23672
|
+
const user = (_a = pullFromCache([
|
|
23673
|
+
'user',
|
|
23674
|
+
'get',
|
|
23675
|
+
joinRequest.requestorPublicId,
|
|
23676
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23677
|
+
if (!user)
|
|
23678
|
+
return undefined;
|
|
23679
|
+
return userLinkedObject(user);
|
|
23680
|
+
}, cancel: () => cancelJoinRequest(joinRequest), approve: () => approveJoinRequest(joinRequest), reject: () => rejectJoinRequest(joinRequest) });
|
|
23681
|
+
};
|
|
23682
|
+
|
|
23565
23683
|
/* begin_public_function
|
|
23566
|
-
id:
|
|
23684
|
+
id: community.getMyJoinRequest
|
|
23567
23685
|
*/
|
|
23568
23686
|
/**
|
|
23569
23687
|
* ```js
|
|
23570
|
-
* import {
|
|
23571
|
-
* const
|
|
23688
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23689
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
23572
23690
|
* ```
|
|
23573
23691
|
*
|
|
23574
|
-
*
|
|
23692
|
+
* Joins a {@link Amity.Community} object
|
|
23575
23693
|
*
|
|
23576
|
-
* @param
|
|
23577
|
-
* @returns A success boolean if the {@link Amity.
|
|
23694
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23695
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
23578
23696
|
*
|
|
23579
|
-
* @category
|
|
23697
|
+
* @category Community API
|
|
23580
23698
|
* @async
|
|
23581
23699
|
*/
|
|
23582
|
-
const
|
|
23583
|
-
var _a;
|
|
23700
|
+
const getMyJoinRequest = async (communityId) => {
|
|
23584
23701
|
const client = getActiveClient();
|
|
23585
|
-
client.log('
|
|
23586
|
-
const { data } = await client.http.
|
|
23587
|
-
const
|
|
23588
|
-
|
|
23589
|
-
|
|
23590
|
-
|
|
23591
|
-
|
|
23592
|
-
|
|
23593
|
-
|
|
23594
|
-
|
|
23595
|
-
}
|
|
23596
|
-
return data.success;
|
|
23702
|
+
client.log('community/myJoinRequest', communityId);
|
|
23703
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
23704
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23705
|
+
const cachedAt = client.cache && Date.now();
|
|
23706
|
+
if (client.cache)
|
|
23707
|
+
ingestInCache(data, { cachedAt });
|
|
23708
|
+
return {
|
|
23709
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
23710
|
+
cachedAt,
|
|
23711
|
+
};
|
|
23597
23712
|
};
|
|
23598
23713
|
/* end_public_function */
|
|
23599
23714
|
|
|
23600
|
-
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
23601
|
-
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
23602
|
-
};
|
|
23603
|
-
|
|
23604
|
-
const invitationLinkedObject = (invitation) => {
|
|
23605
|
-
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
23606
|
-
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
23607
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23608
|
-
return userLinkedObject(cacheData.data);
|
|
23609
|
-
return undefined;
|
|
23610
|
-
},
|
|
23611
|
-
get createdBy() {
|
|
23612
|
-
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
23613
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23614
|
-
return userLinkedObject(cacheData.data);
|
|
23615
|
-
return undefined;
|
|
23616
|
-
},
|
|
23617
|
-
get target() {
|
|
23618
|
-
if (invitation.targetType === 'community') {
|
|
23619
|
-
const cacheData = pullFromCache([
|
|
23620
|
-
'community',
|
|
23621
|
-
'get',
|
|
23622
|
-
invitation.targetId,
|
|
23623
|
-
]);
|
|
23624
|
-
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
23625
|
-
return cacheData.data;
|
|
23626
|
-
return undefined;
|
|
23627
|
-
}
|
|
23628
|
-
return undefined;
|
|
23629
|
-
}, accept: async () => {
|
|
23630
|
-
await acceptInvitation(invitation._id);
|
|
23631
|
-
}, reject: async () => {
|
|
23632
|
-
await rejectInvitation(invitation._id);
|
|
23633
|
-
}, cancel: async () => {
|
|
23634
|
-
await cancelInvitation(invitation._id);
|
|
23635
|
-
} });
|
|
23636
|
-
};
|
|
23637
|
-
|
|
23638
23715
|
/* begin_public_function
|
|
23639
|
-
id:
|
|
23716
|
+
id: community.join
|
|
23640
23717
|
*/
|
|
23641
23718
|
/**
|
|
23642
23719
|
* ```js
|
|
23643
|
-
* import {
|
|
23644
|
-
* const
|
|
23720
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23721
|
+
* const isJoined = await community.join('foobar')
|
|
23645
23722
|
* ```
|
|
23646
23723
|
*
|
|
23647
|
-
*
|
|
23724
|
+
* Joins a {@link Amity.Community} object
|
|
23648
23725
|
*
|
|
23649
|
-
* @param
|
|
23650
|
-
* @
|
|
23651
|
-
* @returns A {@link Amity.Invitation} object
|
|
23726
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23727
|
+
* @returns A status join result
|
|
23652
23728
|
*
|
|
23653
|
-
* @category
|
|
23729
|
+
* @category Community API
|
|
23654
23730
|
* @async
|
|
23655
23731
|
*/
|
|
23656
|
-
const
|
|
23732
|
+
const joinRequest = async (communityId) => {
|
|
23733
|
+
var _a;
|
|
23657
23734
|
const client = getActiveClient();
|
|
23658
|
-
client.log('
|
|
23659
|
-
const { data: payload } = await client.http.
|
|
23660
|
-
const data =
|
|
23735
|
+
client.log('community/joinRequest', communityId);
|
|
23736
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
23737
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23661
23738
|
const cachedAt = client.cache && Date.now();
|
|
23662
23739
|
if (client.cache)
|
|
23663
23740
|
ingestInCache(data, { cachedAt });
|
|
23664
|
-
|
|
23665
|
-
|
|
23666
|
-
|
|
23667
|
-
|
|
23741
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
23742
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
23743
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
23744
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
23745
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23746
|
+
if (community) {
|
|
23747
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
23748
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
23749
|
+
}
|
|
23750
|
+
}
|
|
23751
|
+
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
23752
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
23753
|
+
? { status }
|
|
23754
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
23668
23755
|
};
|
|
23669
23756
|
/* end_public_function */
|
|
23670
23757
|
|
|
23671
|
-
var InvitationActionsEnum;
|
|
23672
|
-
(function (InvitationActionsEnum) {
|
|
23673
|
-
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
23674
|
-
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
23675
|
-
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
23676
|
-
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
23677
|
-
|
|
23678
23758
|
class PaginationController {
|
|
23679
23759
|
constructor(queryParams) {
|
|
23680
23760
|
const { http } = getActiveClient();
|
|
@@ -23720,12 +23800,18 @@ class PaginationController {
|
|
|
23720
23800
|
}
|
|
23721
23801
|
}
|
|
23722
23802
|
|
|
23723
|
-
|
|
23803
|
+
/**
|
|
23804
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
23805
|
+
* TODO: check if querybyIds is supported
|
|
23806
|
+
*/
|
|
23807
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
23724
23808
|
async getRequest(queryParams, token) {
|
|
23725
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23809
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
23726
23810
|
const options = token ? { token } : { limit };
|
|
23727
|
-
const { data } = await this.http.get(
|
|
23728
|
-
|
|
23811
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
23812
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
23813
|
+
});
|
|
23814
|
+
return queryResponse;
|
|
23729
23815
|
}
|
|
23730
23816
|
}
|
|
23731
23817
|
|
|
@@ -23736,7 +23822,14 @@ class QueryStreamController {
|
|
|
23736
23822
|
}
|
|
23737
23823
|
}
|
|
23738
23824
|
|
|
23739
|
-
|
|
23825
|
+
var EnumJoinRequestAction$1;
|
|
23826
|
+
(function (EnumJoinRequestAction) {
|
|
23827
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
23828
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
23829
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
23830
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
23831
|
+
|
|
23832
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
23740
23833
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23741
23834
|
super(query, cacheKey);
|
|
23742
23835
|
this.notifyChange = notifyChange;
|
|
@@ -23754,38 +23847,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
23754
23847
|
var _a, _b;
|
|
23755
23848
|
if (refresh) {
|
|
23756
23849
|
pushToCache(this.cacheKey, {
|
|
23757
|
-
data: response.
|
|
23850
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23758
23851
|
});
|
|
23759
23852
|
}
|
|
23760
23853
|
else {
|
|
23761
23854
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23762
|
-
const
|
|
23855
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23763
23856
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23764
|
-
...new Set([
|
|
23857
|
+
...new Set([
|
|
23858
|
+
...joinRequests,
|
|
23859
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23860
|
+
]),
|
|
23765
23861
|
] }));
|
|
23766
23862
|
}
|
|
23767
23863
|
}
|
|
23768
23864
|
reactor(action) {
|
|
23769
|
-
return (
|
|
23865
|
+
return (joinRequest) => {
|
|
23770
23866
|
var _a;
|
|
23771
23867
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23772
23868
|
if (!collection)
|
|
23773
23869
|
return;
|
|
23774
|
-
if (action ===
|
|
23775
|
-
const isExist = collection.data.find(id => id ===
|
|
23870
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
23871
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
23776
23872
|
if (!isExist)
|
|
23777
23873
|
return;
|
|
23778
23874
|
}
|
|
23779
|
-
if (action ===
|
|
23875
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
23780
23876
|
collection.data = [
|
|
23781
23877
|
...new Set([
|
|
23782
|
-
...
|
|
23878
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
23783
23879
|
...collection.data,
|
|
23784
23880
|
]),
|
|
23785
23881
|
];
|
|
23786
23882
|
}
|
|
23787
|
-
if (action ===
|
|
23788
|
-
collection.data = collection.data.filter(id => id !==
|
|
23883
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
23884
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
23789
23885
|
}
|
|
23790
23886
|
pushToCache(this.cacheKey, collection);
|
|
23791
23887
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -23931,6 +24027,446 @@ class LiveCollectionController {
|
|
|
23931
24027
|
}
|
|
23932
24028
|
}
|
|
23933
24029
|
|
|
24030
|
+
/**
|
|
24031
|
+
* ```js
|
|
24032
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
24033
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
24034
|
+
* // ...
|
|
24035
|
+
* })
|
|
24036
|
+
* ```
|
|
24037
|
+
*
|
|
24038
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24039
|
+
*
|
|
24040
|
+
* @param callback The function to call when the event was fired
|
|
24041
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24042
|
+
*
|
|
24043
|
+
* @category JoinRequest Events
|
|
24044
|
+
*/
|
|
24045
|
+
const onJoinRequestCreated = (callback) => {
|
|
24046
|
+
const client = getActiveClient();
|
|
24047
|
+
const disposers = [
|
|
24048
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
24049
|
+
];
|
|
24050
|
+
return () => {
|
|
24051
|
+
disposers.forEach(fn => fn());
|
|
24052
|
+
};
|
|
24053
|
+
};
|
|
24054
|
+
|
|
24055
|
+
/**
|
|
24056
|
+
* ```js
|
|
24057
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
24058
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
24059
|
+
* // ...
|
|
24060
|
+
* })
|
|
24061
|
+
* ```
|
|
24062
|
+
*
|
|
24063
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24064
|
+
*
|
|
24065
|
+
* @param callback The function to call when the event was fired
|
|
24066
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24067
|
+
*
|
|
24068
|
+
* @category JoinRequest Events
|
|
24069
|
+
*/
|
|
24070
|
+
const onJoinRequestUpdated = (callback) => {
|
|
24071
|
+
const client = getActiveClient();
|
|
24072
|
+
const disposers = [
|
|
24073
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
24074
|
+
];
|
|
24075
|
+
return () => {
|
|
24076
|
+
disposers.forEach(fn => fn());
|
|
24077
|
+
};
|
|
24078
|
+
};
|
|
24079
|
+
|
|
24080
|
+
/**
|
|
24081
|
+
* ```js
|
|
24082
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
24083
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
24084
|
+
* // ...
|
|
24085
|
+
* })
|
|
24086
|
+
* ```
|
|
24087
|
+
*
|
|
24088
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24089
|
+
*
|
|
24090
|
+
* @param callback The function to call when the event was fired
|
|
24091
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24092
|
+
*
|
|
24093
|
+
* @category JoinRequest Events
|
|
24094
|
+
*/
|
|
24095
|
+
const onJoinRequestDeleted = (callback) => {
|
|
24096
|
+
const client = getActiveClient();
|
|
24097
|
+
const disposers = [
|
|
24098
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
24099
|
+
];
|
|
24100
|
+
return () => {
|
|
24101
|
+
disposers.forEach(fn => fn());
|
|
24102
|
+
};
|
|
24103
|
+
};
|
|
24104
|
+
|
|
24105
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
24106
|
+
constructor(query, callback) {
|
|
24107
|
+
const queryStreamId = hash(query);
|
|
24108
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
24109
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
24110
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24111
|
+
this.query = query;
|
|
24112
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
24113
|
+
this.callback = callback.bind(this);
|
|
24114
|
+
this.loadPage({ initial: true });
|
|
24115
|
+
}
|
|
24116
|
+
setup() {
|
|
24117
|
+
var _a;
|
|
24118
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24119
|
+
if (!collection) {
|
|
24120
|
+
pushToCache(this.cacheKey, {
|
|
24121
|
+
data: [],
|
|
24122
|
+
params: this.query,
|
|
24123
|
+
});
|
|
24124
|
+
}
|
|
24125
|
+
}
|
|
24126
|
+
async persistModel(queryPayload) {
|
|
24127
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24128
|
+
}
|
|
24129
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24130
|
+
const joinRequestResponse = response;
|
|
24131
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
24132
|
+
}
|
|
24133
|
+
startSubscription() {
|
|
24134
|
+
return this.queryStreamController.subscribeRTE([
|
|
24135
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
24136
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
24137
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
24138
|
+
]);
|
|
24139
|
+
}
|
|
24140
|
+
notifyChange({ origin, loading, error }) {
|
|
24141
|
+
var _a;
|
|
24142
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24143
|
+
if (!collection)
|
|
24144
|
+
return;
|
|
24145
|
+
const data = this.applyFilter(collection.data
|
|
24146
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
24147
|
+
.filter(isNonNullable)
|
|
24148
|
+
.map(({ data }) => data)
|
|
24149
|
+
.map(joinRequestLinkedObject));
|
|
24150
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24151
|
+
return;
|
|
24152
|
+
this.callback({
|
|
24153
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24154
|
+
data,
|
|
24155
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24156
|
+
loading,
|
|
24157
|
+
error,
|
|
24158
|
+
});
|
|
24159
|
+
}
|
|
24160
|
+
applyFilter(data) {
|
|
24161
|
+
let joinRequest = data;
|
|
24162
|
+
if (this.query.status) {
|
|
24163
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
24164
|
+
}
|
|
24165
|
+
const sortFn = (() => {
|
|
24166
|
+
switch (this.query.sortBy) {
|
|
24167
|
+
case 'firstCreated':
|
|
24168
|
+
return sortByFirstCreated;
|
|
24169
|
+
case 'lastCreated':
|
|
24170
|
+
return sortByLastCreated;
|
|
24171
|
+
default:
|
|
24172
|
+
return sortByLastCreated;
|
|
24173
|
+
}
|
|
24174
|
+
})();
|
|
24175
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
24176
|
+
return joinRequest;
|
|
24177
|
+
}
|
|
24178
|
+
}
|
|
24179
|
+
|
|
24180
|
+
/**
|
|
24181
|
+
* Get Join Requests
|
|
24182
|
+
*
|
|
24183
|
+
* @param params the query parameters
|
|
24184
|
+
* @param callback the callback to be called when the join request are updated
|
|
24185
|
+
* @returns joinRequests
|
|
24186
|
+
*
|
|
24187
|
+
* @category joinRequest Live Collection
|
|
24188
|
+
*
|
|
24189
|
+
*/
|
|
24190
|
+
const getJoinRequests = (params, callback, config) => {
|
|
24191
|
+
const { log, cache } = getActiveClient();
|
|
24192
|
+
if (!cache) {
|
|
24193
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24194
|
+
}
|
|
24195
|
+
const timestamp = Date.now();
|
|
24196
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
24197
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
24198
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
24199
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
24200
|
+
disposers.push(() => {
|
|
24201
|
+
dropFromCache(cacheKey);
|
|
24202
|
+
});
|
|
24203
|
+
return () => {
|
|
24204
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
24205
|
+
disposers.forEach(fn => fn());
|
|
24206
|
+
};
|
|
24207
|
+
};
|
|
24208
|
+
|
|
24209
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
24210
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
24211
|
+
};
|
|
24212
|
+
|
|
24213
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
24214
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
24215
|
+
};
|
|
24216
|
+
|
|
24217
|
+
/* begin_public_function
|
|
24218
|
+
id: invitation.createInvitations
|
|
24219
|
+
*/
|
|
24220
|
+
/**
|
|
24221
|
+
* ```js
|
|
24222
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
24223
|
+
* const created = await createInvitations({
|
|
24224
|
+
* type: string,
|
|
24225
|
+
* targetType: string,
|
|
24226
|
+
* targetId: string,
|
|
24227
|
+
* userIds: string[]
|
|
24228
|
+
* }))
|
|
24229
|
+
* ```
|
|
24230
|
+
*
|
|
24231
|
+
* Creates an {@link Amity.Invitation}
|
|
24232
|
+
*
|
|
24233
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
24234
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
24235
|
+
*
|
|
24236
|
+
* @category Invitation API
|
|
24237
|
+
* @async
|
|
24238
|
+
*/
|
|
24239
|
+
const createInvitations = async (bundle) => {
|
|
24240
|
+
const client = getActiveClient();
|
|
24241
|
+
client.log('invitation/createInvitations', bundle);
|
|
24242
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
24243
|
+
const data = prepareInvitationPayload(payload);
|
|
24244
|
+
const cachedAt = client.cache && Date.now();
|
|
24245
|
+
if (client.cache)
|
|
24246
|
+
ingestInCache(data, { cachedAt });
|
|
24247
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
24248
|
+
return {
|
|
24249
|
+
data: data.invitations,
|
|
24250
|
+
cachedAt,
|
|
24251
|
+
};
|
|
24252
|
+
};
|
|
24253
|
+
/* end_public_function */
|
|
24254
|
+
|
|
24255
|
+
/* begin_public_function
|
|
24256
|
+
id: invitation.accept
|
|
24257
|
+
*/
|
|
24258
|
+
/**
|
|
24259
|
+
* ```js
|
|
24260
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
24261
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
24262
|
+
* ```
|
|
24263
|
+
*
|
|
24264
|
+
* Accepts a {@link Amity.Invitation} object
|
|
24265
|
+
*
|
|
24266
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
24267
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
24268
|
+
*
|
|
24269
|
+
* @category Invitation API
|
|
24270
|
+
* @async
|
|
24271
|
+
*/
|
|
24272
|
+
const acceptInvitation = async (invitationId) => {
|
|
24273
|
+
var _a;
|
|
24274
|
+
const client = getActiveClient();
|
|
24275
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
24276
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
24277
|
+
const invitation = (_a = pullFromCache([
|
|
24278
|
+
'invitation',
|
|
24279
|
+
'get',
|
|
24280
|
+
invitationId,
|
|
24281
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24282
|
+
if (invitation) {
|
|
24283
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
24284
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24285
|
+
}
|
|
24286
|
+
return data.success;
|
|
24287
|
+
};
|
|
24288
|
+
/* end_public_function */
|
|
24289
|
+
|
|
24290
|
+
/* begin_public_function
|
|
24291
|
+
id: invitation.reject
|
|
24292
|
+
*/
|
|
24293
|
+
/**
|
|
24294
|
+
* ```js
|
|
24295
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
24296
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
24297
|
+
* ```
|
|
24298
|
+
*
|
|
24299
|
+
* Rejects a {@link Amity.Invitation} object
|
|
24300
|
+
*
|
|
24301
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
24302
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
24303
|
+
*
|
|
24304
|
+
* @category Invitation API
|
|
24305
|
+
* @async
|
|
24306
|
+
*/
|
|
24307
|
+
const rejectInvitation = async (invitationId) => {
|
|
24308
|
+
var _a;
|
|
24309
|
+
const client = getActiveClient();
|
|
24310
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
24311
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
24312
|
+
const invitation = (_a = pullFromCache([
|
|
24313
|
+
'invitation',
|
|
24314
|
+
'get',
|
|
24315
|
+
invitationId,
|
|
24316
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24317
|
+
if (invitation) {
|
|
24318
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
24319
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24320
|
+
}
|
|
24321
|
+
return data.success;
|
|
24322
|
+
};
|
|
24323
|
+
/* end_public_function */
|
|
24324
|
+
|
|
24325
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
24326
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
24327
|
+
};
|
|
24328
|
+
|
|
24329
|
+
const invitationLinkedObject = (invitation) => {
|
|
24330
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
24331
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
24332
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24333
|
+
return userLinkedObject(cacheData.data);
|
|
24334
|
+
return undefined;
|
|
24335
|
+
},
|
|
24336
|
+
get createdBy() {
|
|
24337
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
24338
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24339
|
+
return userLinkedObject(cacheData.data);
|
|
24340
|
+
return undefined;
|
|
24341
|
+
},
|
|
24342
|
+
get target() {
|
|
24343
|
+
if (invitation.targetType === 'community') {
|
|
24344
|
+
const cacheData = pullFromCache([
|
|
24345
|
+
'community',
|
|
24346
|
+
'get',
|
|
24347
|
+
invitation.targetId,
|
|
24348
|
+
]);
|
|
24349
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24350
|
+
return cacheData.data;
|
|
24351
|
+
return undefined;
|
|
24352
|
+
}
|
|
24353
|
+
return undefined;
|
|
24354
|
+
}, accept: async () => {
|
|
24355
|
+
await acceptInvitation(invitation._id);
|
|
24356
|
+
}, reject: async () => {
|
|
24357
|
+
await rejectInvitation(invitation._id);
|
|
24358
|
+
} });
|
|
24359
|
+
};
|
|
24360
|
+
|
|
24361
|
+
/* begin_public_function
|
|
24362
|
+
id: invitation.get
|
|
24363
|
+
*/
|
|
24364
|
+
/**
|
|
24365
|
+
* ```js
|
|
24366
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
24367
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
24368
|
+
* ```
|
|
24369
|
+
*
|
|
24370
|
+
* Get a {@link Amity.Invitation} object
|
|
24371
|
+
*
|
|
24372
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
24373
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
24374
|
+
* @returns A {@link Amity.Invitation} object
|
|
24375
|
+
*
|
|
24376
|
+
* @category Invitation API
|
|
24377
|
+
* @async
|
|
24378
|
+
*/
|
|
24379
|
+
const getInvitation = async (targetType, targetId) => {
|
|
24380
|
+
const client = getActiveClient();
|
|
24381
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
24382
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
24383
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
24384
|
+
const cachedAt = client.cache && Date.now();
|
|
24385
|
+
if (client.cache)
|
|
24386
|
+
ingestInCache(data, { cachedAt });
|
|
24387
|
+
return {
|
|
24388
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
24389
|
+
cachedAt,
|
|
24390
|
+
};
|
|
24391
|
+
};
|
|
24392
|
+
/* end_public_function */
|
|
24393
|
+
|
|
24394
|
+
var InvitationActionsEnum;
|
|
24395
|
+
(function (InvitationActionsEnum) {
|
|
24396
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
24397
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
24398
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
24399
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
24400
|
+
|
|
24401
|
+
class InvitationsPaginationController extends PaginationController {
|
|
24402
|
+
async getRequest(queryParams, token) {
|
|
24403
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
24404
|
+
const options = token ? { token } : { limit };
|
|
24405
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
24406
|
+
return data;
|
|
24407
|
+
}
|
|
24408
|
+
}
|
|
24409
|
+
|
|
24410
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
24411
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24412
|
+
super(query, cacheKey);
|
|
24413
|
+
this.notifyChange = notifyChange;
|
|
24414
|
+
this.preparePayload = preparePayload;
|
|
24415
|
+
}
|
|
24416
|
+
async saveToMainDB(response) {
|
|
24417
|
+
const processedPayload = await this.preparePayload(response);
|
|
24418
|
+
const client = getActiveClient();
|
|
24419
|
+
const cachedAt = client.cache && Date.now();
|
|
24420
|
+
if (client.cache) {
|
|
24421
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
24422
|
+
}
|
|
24423
|
+
}
|
|
24424
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
24425
|
+
var _a, _b;
|
|
24426
|
+
if (refresh) {
|
|
24427
|
+
pushToCache(this.cacheKey, {
|
|
24428
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
24429
|
+
});
|
|
24430
|
+
}
|
|
24431
|
+
else {
|
|
24432
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24433
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24434
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
24435
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
24436
|
+
] }));
|
|
24437
|
+
}
|
|
24438
|
+
}
|
|
24439
|
+
reactor(action) {
|
|
24440
|
+
return (invitations) => {
|
|
24441
|
+
var _a;
|
|
24442
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24443
|
+
if (!collection)
|
|
24444
|
+
return;
|
|
24445
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
24446
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
24447
|
+
if (!isExist)
|
|
24448
|
+
return;
|
|
24449
|
+
}
|
|
24450
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
24451
|
+
collection.data = [
|
|
24452
|
+
...new Set([
|
|
24453
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
24454
|
+
...collection.data,
|
|
24455
|
+
]),
|
|
24456
|
+
];
|
|
24457
|
+
}
|
|
24458
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
24459
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
24460
|
+
}
|
|
24461
|
+
pushToCache(this.cacheKey, collection);
|
|
24462
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24463
|
+
};
|
|
24464
|
+
}
|
|
24465
|
+
subscribeRTE(createSubscriber) {
|
|
24466
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24467
|
+
}
|
|
24468
|
+
}
|
|
24469
|
+
|
|
23934
24470
|
/**
|
|
23935
24471
|
* ```js
|
|
23936
24472
|
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
@@ -24139,6 +24675,11 @@ const communityLinkedObject = (community) => {
|
|
|
24139
24675
|
}, getInvitation: async () => {
|
|
24140
24676
|
const { data } = await getInvitation('community', community.communityId);
|
|
24141
24677
|
return data;
|
|
24678
|
+
}, join: joinRequest(community.communityId), getJoinRequests: (params, callback) => {
|
|
24679
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
24680
|
+
}, getMyJoinRequest: async () => {
|
|
24681
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
24682
|
+
return data;
|
|
24142
24683
|
} });
|
|
24143
24684
|
};
|
|
24144
24685
|
|
|
@@ -24158,6 +24699,7 @@ const LinkedObject = {
|
|
|
24158
24699
|
notificationTray: notificationTrayLinkedObject,
|
|
24159
24700
|
community: communityLinkedObject,
|
|
24160
24701
|
invitation: invitationLinkedObject,
|
|
24702
|
+
joinRequest: joinRequestLinkedObject,
|
|
24161
24703
|
};
|
|
24162
24704
|
|
|
24163
24705
|
const constructChannelObject = (channel) => {
|
|
@@ -29714,41 +30256,6 @@ getComment$2.locally = (commentId) => {
|
|
|
29714
30256
|
};
|
|
29715
30257
|
};
|
|
29716
30258
|
|
|
29717
|
-
/*
|
|
29718
|
-
* verifies membership status
|
|
29719
|
-
*/
|
|
29720
|
-
function isMember(membership) {
|
|
29721
|
-
return membership !== 'none';
|
|
29722
|
-
}
|
|
29723
|
-
/*
|
|
29724
|
-
* checks if currently logged in user is part of the community
|
|
29725
|
-
*/
|
|
29726
|
-
function isCurrentUserPartOfCommunity(c, m) {
|
|
29727
|
-
const { userId } = getActiveUser();
|
|
29728
|
-
return c.communityId === m.communityId && m.userId === userId;
|
|
29729
|
-
}
|
|
29730
|
-
/*
|
|
29731
|
-
* For mqtt events server will not send user specific data as it's broadcasted
|
|
29732
|
-
* to multiple users and it also does not include communityUser
|
|
29733
|
-
*
|
|
29734
|
-
* Client SDK needs to check for the existing isJoined field in cache data before calculating.
|
|
29735
|
-
* Althought this can be calculated, it's not scalable.
|
|
29736
|
-
*/
|
|
29737
|
-
function updateMembershipStatus(communities, communityUsers) {
|
|
29738
|
-
return communities.map(c => {
|
|
29739
|
-
const cachedCommunity = pullFromCache([
|
|
29740
|
-
'community',
|
|
29741
|
-
'get',
|
|
29742
|
-
c.communityId,
|
|
29743
|
-
]);
|
|
29744
|
-
if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
|
|
29745
|
-
return Object.assign(Object.assign({}, cachedCommunity.data), c);
|
|
29746
|
-
}
|
|
29747
|
-
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
29748
|
-
return Object.assign(Object.assign({}, c), { isJoined });
|
|
29749
|
-
});
|
|
29750
|
-
}
|
|
29751
|
-
|
|
29752
30259
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
29753
30260
|
var _a, _b;
|
|
29754
30261
|
let id;
|
|
@@ -30063,53 +30570,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
30063
30570
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
30064
30571
|
};
|
|
30065
30572
|
|
|
30066
|
-
const getMatchPostSetting = (value) => {
|
|
30067
|
-
var _a;
|
|
30068
|
-
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
30069
|
-
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
30070
|
-
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
30071
|
-
};
|
|
30072
|
-
function addPostSetting({ communities }) {
|
|
30073
|
-
return communities.map((_a) => {
|
|
30074
|
-
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
30075
|
-
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
30076
|
-
needApprovalOnPostCreation,
|
|
30077
|
-
onlyAdminCanPost,
|
|
30078
|
-
}) }, restCommunityPayload));
|
|
30079
|
-
});
|
|
30080
|
-
}
|
|
30081
|
-
const prepareCommunityPayload = (rawPayload) => {
|
|
30082
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
30083
|
-
// map users with community
|
|
30084
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
30085
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
30086
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30087
|
-
});
|
|
30088
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30089
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
30090
|
-
};
|
|
30091
|
-
const prepareCommunityMembershipPayload = (rawPayload) => {
|
|
30092
|
-
const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
|
|
30093
|
-
// map users with community
|
|
30094
|
-
const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
|
|
30095
|
-
const user = rawPayload.users.find(user => user.userId === communityUser.userId);
|
|
30096
|
-
return Object.assign(Object.assign({}, communityUser), { user });
|
|
30097
|
-
});
|
|
30098
|
-
const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
|
|
30099
|
-
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
30100
|
-
};
|
|
30101
|
-
const prepareCommunityRequest = (params) => {
|
|
30102
|
-
const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
|
|
30103
|
-
return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
|
|
30104
|
-
// Convert story setting to the actual value. (Allow by default)
|
|
30105
|
-
allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
|
|
30106
|
-
};
|
|
30107
|
-
const prepareSemanticSearchCommunityPayload = (_a) => {
|
|
30108
|
-
var communityPayload = __rest(_a, ["searchResult"]);
|
|
30109
|
-
const processedCommunityPayload = prepareCommunityPayload(communityPayload);
|
|
30110
|
-
return Object.assign({}, processedCommunityPayload);
|
|
30111
|
-
};
|
|
30112
|
-
|
|
30113
30573
|
const preparePostPayload = (payload) => {
|
|
30114
30574
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
30115
30575
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -35173,10 +35633,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
35173
35633
|
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
35174
35634
|
const client = getActiveClient();
|
|
35175
35635
|
client.log('community/getCommunities', communityIds);
|
|
35636
|
+
const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
35176
35637
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35177
35638
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
35178
35639
|
params: {
|
|
35179
|
-
communityIds,
|
|
35640
|
+
communityIds: encodedCommunityIds,
|
|
35180
35641
|
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35181
35642
|
},
|
|
35182
35643
|
});
|
|
@@ -35310,11 +35771,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
35310
35771
|
* @category Community API
|
|
35311
35772
|
* @async
|
|
35312
35773
|
*/
|
|
35313
|
-
const getCommunity$1 = async (communityId) => {
|
|
35774
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
35314
35775
|
const client = getActiveClient();
|
|
35315
35776
|
client.log('community/getCommunity', communityId);
|
|
35316
35777
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35317
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
35778
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
35779
|
+
params: {
|
|
35780
|
+
type: 'communityJoinRequest',
|
|
35781
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35782
|
+
},
|
|
35783
|
+
});
|
|
35318
35784
|
const data = prepareCommunityPayload(payload);
|
|
35319
35785
|
const cachedAt = client.cache && Date.now();
|
|
35320
35786
|
if (client.cache) {
|
|
@@ -35389,6 +35855,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
35389
35855
|
};
|
|
35390
35856
|
/* end_public_function */
|
|
35391
35857
|
|
|
35858
|
+
/**
|
|
35859
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
35860
|
+
*/
|
|
35392
35861
|
/* begin_public_function
|
|
35393
35862
|
id: community.join
|
|
35394
35863
|
*/
|
|
@@ -35529,10 +35998,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
35529
35998
|
*/
|
|
35530
35999
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35531
36000
|
async getRequest(queryParams, token) {
|
|
36001
|
+
var _a;
|
|
35532
36002
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35533
36003
|
const options = token ? { token } : { limit };
|
|
35534
36004
|
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35535
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
36005
|
+
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 }),
|
|
35536
36006
|
});
|
|
35537
36007
|
return queryResponse;
|
|
35538
36008
|
}
|
|
@@ -36032,6 +36502,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
36032
36502
|
|
|
36033
36503
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
36034
36504
|
|
|
36505
|
+
const onLocalCommunityJoin = (callback) => {
|
|
36506
|
+
const client = getActiveClient();
|
|
36507
|
+
const filter = async (rawPayload) => {
|
|
36508
|
+
callback(rawPayload[0]);
|
|
36509
|
+
};
|
|
36510
|
+
const disposers = [
|
|
36511
|
+
createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
|
|
36512
|
+
];
|
|
36513
|
+
return () => {
|
|
36514
|
+
disposers.forEach(fn => fn());
|
|
36515
|
+
};
|
|
36516
|
+
};
|
|
36517
|
+
|
|
36035
36518
|
/**
|
|
36036
36519
|
* ```js
|
|
36037
36520
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -36518,7 +37001,8 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
36518
37001
|
onCommunityJoined: onCommunityJoined,
|
|
36519
37002
|
onCommunityLeft: onCommunityLeft,
|
|
36520
37003
|
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
36521
|
-
onLocalCommunityLeft: onLocalCommunityLeft
|
|
37004
|
+
onLocalCommunityLeft: onLocalCommunityLeft,
|
|
37005
|
+
onLocalCommunityJoin: onLocalCommunityJoin
|
|
36522
37006
|
});
|
|
36523
37007
|
|
|
36524
37008
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -36742,6 +37226,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36742
37226
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36743
37227
|
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36744
37228
|
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37229
|
+
{
|
|
37230
|
+
fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
37231
|
+
action: EnumCommunityActions$3.OnCommunityUpdated,
|
|
37232
|
+
},
|
|
36745
37233
|
]);
|
|
36746
37234
|
}
|
|
36747
37235
|
notifyChange({ origin, loading, error }) {
|
|
@@ -36865,6 +37353,7 @@ const getCommunity = (communityId, callback) => {
|
|
|
36865
37353
|
onCommunityUserBanned,
|
|
36866
37354
|
onCommunityUserUnbanned,
|
|
36867
37355
|
onCommunityUserChanged,
|
|
37356
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
36868
37357
|
]);
|
|
36869
37358
|
};
|
|
36870
37359
|
/* end_public_function */
|
|
@@ -36979,7 +37468,169 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36979
37468
|
const data = (_b = collection.data
|
|
36980
37469
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36981
37470
|
.filter(isNonNullable)
|
|
36982
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37471
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
37472
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37473
|
+
return;
|
|
37474
|
+
this.callback({
|
|
37475
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
37476
|
+
data,
|
|
37477
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
37478
|
+
loading,
|
|
37479
|
+
error,
|
|
37480
|
+
});
|
|
37481
|
+
}
|
|
37482
|
+
}
|
|
37483
|
+
|
|
37484
|
+
/* begin_public_function
|
|
37485
|
+
id: community.query.trending_communities
|
|
37486
|
+
*/
|
|
37487
|
+
/**
|
|
37488
|
+
* ```js
|
|
37489
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
37490
|
+
*
|
|
37491
|
+
* let communities = []
|
|
37492
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
37493
|
+
* displayName: Amity.Community['displayName'],
|
|
37494
|
+
* }, response => merge(communities, response.data))
|
|
37495
|
+
* ```
|
|
37496
|
+
*
|
|
37497
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
37498
|
+
*
|
|
37499
|
+
* @param params for querying communities
|
|
37500
|
+
* @param callback the function to call when new data are available
|
|
37501
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
37502
|
+
*
|
|
37503
|
+
* @category Community Live Collection
|
|
37504
|
+
*/
|
|
37505
|
+
const getTrendingCommunities = (params, callback, config) => {
|
|
37506
|
+
const { log, cache, userId } = getActiveClient();
|
|
37507
|
+
if (!cache) {
|
|
37508
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37509
|
+
}
|
|
37510
|
+
const timestamp = Date.now();
|
|
37511
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
|
|
37512
|
+
const trendingCommunitiesLiveCollection = new TrendingCommunityLiveCollectionController(params, callback);
|
|
37513
|
+
const disposers = trendingCommunitiesLiveCollection.startSubscription();
|
|
37514
|
+
const cacheKey = trendingCommunitiesLiveCollection.getCacheKey();
|
|
37515
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
37516
|
+
return () => {
|
|
37517
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37518
|
+
disposers.forEach(fn => fn());
|
|
37519
|
+
};
|
|
37520
|
+
};
|
|
37521
|
+
/* end_public_function */
|
|
37522
|
+
|
|
37523
|
+
/**
|
|
37524
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
37525
|
+
* TODO: check if querybyIds is supported
|
|
37526
|
+
*/
|
|
37527
|
+
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
37528
|
+
async getRequest(queryParams, token) {
|
|
37529
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
37530
|
+
const options = token ? { token } : { limit };
|
|
37531
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/recommended`, {
|
|
37532
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
37533
|
+
});
|
|
37534
|
+
return queryResponse;
|
|
37535
|
+
}
|
|
37536
|
+
}
|
|
37537
|
+
|
|
37538
|
+
class RecommendedCommunitiesQueryStreamController extends QueryStreamController {
|
|
37539
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37540
|
+
super(query, cacheKey);
|
|
37541
|
+
this.notifyChange = notifyChange;
|
|
37542
|
+
this.preparePayload = preparePayload;
|
|
37543
|
+
}
|
|
37544
|
+
async saveToMainDB(response) {
|
|
37545
|
+
const processedPayload = await this.preparePayload(response);
|
|
37546
|
+
const client = getActiveClient();
|
|
37547
|
+
const cachedAt = client.cache && Date.now();
|
|
37548
|
+
if (client.cache) {
|
|
37549
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37550
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
37551
|
+
}
|
|
37552
|
+
}
|
|
37553
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37554
|
+
var _a, _b;
|
|
37555
|
+
if (refresh) {
|
|
37556
|
+
pushToCache(this.cacheKey, {
|
|
37557
|
+
data: response.communities.map(getResolver('community')),
|
|
37558
|
+
});
|
|
37559
|
+
}
|
|
37560
|
+
else {
|
|
37561
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37562
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37563
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
37564
|
+
}
|
|
37565
|
+
}
|
|
37566
|
+
reactor(action) {
|
|
37567
|
+
return (community) => {
|
|
37568
|
+
var _a;
|
|
37569
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37570
|
+
if (!collection)
|
|
37571
|
+
return;
|
|
37572
|
+
pushToCache(this.cacheKey, collection);
|
|
37573
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37574
|
+
};
|
|
37575
|
+
}
|
|
37576
|
+
subscribeRTE(createSubscriber) {
|
|
37577
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37578
|
+
}
|
|
37579
|
+
}
|
|
37580
|
+
|
|
37581
|
+
var EnumCommunityActions$1;
|
|
37582
|
+
(function (EnumCommunityActions) {
|
|
37583
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37584
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37585
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
37586
|
+
|
|
37587
|
+
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
37588
|
+
constructor(query, callback) {
|
|
37589
|
+
const queryStreamId = hash(query);
|
|
37590
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
37591
|
+
const paginationController = new RecommendedCommunitiesPaginationController(query);
|
|
37592
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37593
|
+
this.query = query;
|
|
37594
|
+
this.queryStreamController = new RecommendedCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
37595
|
+
this.callback = callback.bind(this);
|
|
37596
|
+
this.loadPage({ initial: true });
|
|
37597
|
+
}
|
|
37598
|
+
setup() {
|
|
37599
|
+
var _a;
|
|
37600
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37601
|
+
if (!collection) {
|
|
37602
|
+
pushToCache(this.cacheKey, {
|
|
37603
|
+
data: [],
|
|
37604
|
+
params: {},
|
|
37605
|
+
});
|
|
37606
|
+
}
|
|
37607
|
+
}
|
|
37608
|
+
async persistModel(queryPayload) {
|
|
37609
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37610
|
+
}
|
|
37611
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37612
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37613
|
+
}
|
|
37614
|
+
startSubscription() {
|
|
37615
|
+
return this.queryStreamController.subscribeRTE([
|
|
37616
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
37617
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
37618
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37619
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37620
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
37621
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37622
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37623
|
+
]);
|
|
37624
|
+
}
|
|
37625
|
+
notifyChange({ origin, loading, error }) {
|
|
37626
|
+
var _a, _b;
|
|
37627
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37628
|
+
if (!collection)
|
|
37629
|
+
return;
|
|
37630
|
+
const data = (_b = collection.data
|
|
37631
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
37632
|
+
.filter(isNonNullable)
|
|
37633
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
36983
37634
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36984
37635
|
return;
|
|
36985
37636
|
this.callback({
|
|
@@ -36993,7 +37644,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36993
37644
|
}
|
|
36994
37645
|
|
|
36995
37646
|
/* begin_public_function
|
|
36996
|
-
id: community.query.
|
|
37647
|
+
id: community.query.recommended_communities
|
|
36997
37648
|
*/
|
|
36998
37649
|
/**
|
|
36999
37650
|
* ```js
|
|
@@ -37013,65 +37664,70 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
37013
37664
|
*
|
|
37014
37665
|
* @category Community Live Collection
|
|
37015
37666
|
*/
|
|
37016
|
-
const
|
|
37667
|
+
const getRecommendedCommunities = (params, callback, config) => {
|
|
37017
37668
|
const { log, cache, userId } = getActiveClient();
|
|
37018
37669
|
if (!cache) {
|
|
37019
37670
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37020
37671
|
}
|
|
37021
37672
|
const timestamp = Date.now();
|
|
37022
|
-
log(`
|
|
37023
|
-
const
|
|
37024
|
-
const disposers =
|
|
37025
|
-
const cacheKey =
|
|
37673
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
37674
|
+
const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(params, callback);
|
|
37675
|
+
const disposers = recommendedCommunitiesLiveCollection.startSubscription();
|
|
37676
|
+
const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
|
|
37026
37677
|
disposers.push(() => dropFromCache(cacheKey));
|
|
37027
37678
|
return () => {
|
|
37028
|
-
log(`
|
|
37679
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37029
37680
|
disposers.forEach(fn => fn());
|
|
37030
37681
|
};
|
|
37031
37682
|
};
|
|
37032
37683
|
/* end_public_function */
|
|
37033
37684
|
|
|
37034
|
-
|
|
37035
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
37036
|
-
* TODO: check if querybyIds is supported
|
|
37037
|
-
*/
|
|
37038
|
-
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
37685
|
+
class SemanticSearchCommunityPaginationController extends PaginationController {
|
|
37039
37686
|
async getRequest(queryParams, token) {
|
|
37040
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
37041
|
-
const
|
|
37042
|
-
|
|
37043
|
-
|
|
37687
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityMembershipStatus } = queryParams, params = __rest(queryParams, ["limit", "communityMembershipStatus"]);
|
|
37688
|
+
const baseOptions = {
|
|
37689
|
+
type: queryParams.limit ? 'pagination' : undefined,
|
|
37690
|
+
};
|
|
37691
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
37692
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/communities`, {
|
|
37693
|
+
params: Object.assign(Object.assign({}, params), { filter: communityMembershipStatus !== null && communityMembershipStatus !== void 0 ? communityMembershipStatus : "all" /* AmityCommunityMemberStatusFilter.ALL */, options }),
|
|
37044
37694
|
});
|
|
37045
37695
|
return queryResponse;
|
|
37046
37696
|
}
|
|
37047
37697
|
}
|
|
37048
37698
|
|
|
37049
|
-
|
|
37699
|
+
function prepareSemanticCommunitiesReferenceId(response) {
|
|
37700
|
+
return response.communities.map(community => {
|
|
37701
|
+
const score = response.searchResult.find(result => result.communityId === community.communityId);
|
|
37702
|
+
return `${community.communityId}:${score}`;
|
|
37703
|
+
});
|
|
37704
|
+
}
|
|
37705
|
+
|
|
37706
|
+
class SemanticSearchCommunityQueryStreamController extends QueryStreamController {
|
|
37050
37707
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37051
37708
|
super(query, cacheKey);
|
|
37052
37709
|
this.notifyChange = notifyChange;
|
|
37053
37710
|
this.preparePayload = preparePayload;
|
|
37054
37711
|
}
|
|
37055
37712
|
async saveToMainDB(response) {
|
|
37056
|
-
const processedPayload =
|
|
37713
|
+
const processedPayload = this.preparePayload(response);
|
|
37057
37714
|
const client = getActiveClient();
|
|
37058
37715
|
const cachedAt = client.cache && Date.now();
|
|
37059
37716
|
if (client.cache) {
|
|
37060
37717
|
ingestInCache(processedPayload, { cachedAt });
|
|
37061
|
-
saveCommunityUsers(response.communities, response.communityUsers);
|
|
37062
37718
|
}
|
|
37063
37719
|
}
|
|
37064
37720
|
appendToQueryStream(response, direction, refresh = false) {
|
|
37065
37721
|
var _a, _b;
|
|
37066
37722
|
if (refresh) {
|
|
37067
37723
|
pushToCache(this.cacheKey, {
|
|
37068
|
-
data: response
|
|
37724
|
+
data: prepareSemanticCommunitiesReferenceId(response),
|
|
37069
37725
|
});
|
|
37070
37726
|
}
|
|
37071
37727
|
else {
|
|
37072
37728
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37073
37729
|
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37074
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response
|
|
37730
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...prepareSemanticCommunitiesReferenceId(response)])] }));
|
|
37075
37731
|
}
|
|
37076
37732
|
}
|
|
37077
37733
|
reactor(action) {
|
|
@@ -37080,29 +37736,32 @@ class RecommendedCommunitiesQueryStreamController extends QueryStreamController
|
|
|
37080
37736
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37081
37737
|
if (!collection)
|
|
37082
37738
|
return;
|
|
37739
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
37083
37740
|
pushToCache(this.cacheKey, collection);
|
|
37084
37741
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37085
37742
|
};
|
|
37743
|
+
//
|
|
37086
37744
|
}
|
|
37087
37745
|
subscribeRTE(createSubscriber) {
|
|
37088
37746
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37089
37747
|
}
|
|
37090
37748
|
}
|
|
37091
37749
|
|
|
37092
|
-
var EnumCommunityActions
|
|
37750
|
+
var EnumCommunityActions;
|
|
37093
37751
|
(function (EnumCommunityActions) {
|
|
37752
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
37094
37753
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37095
37754
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37096
|
-
})(EnumCommunityActions
|
|
37755
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
37097
37756
|
|
|
37098
|
-
class
|
|
37757
|
+
class SemanticSearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
37099
37758
|
constructor(query, callback) {
|
|
37100
37759
|
const queryStreamId = hash(query);
|
|
37101
37760
|
const cacheKey = ['community', 'collection', queryStreamId];
|
|
37102
|
-
const paginationController = new
|
|
37761
|
+
const paginationController = new SemanticSearchCommunityPaginationController(query);
|
|
37103
37762
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37104
37763
|
this.query = query;
|
|
37105
|
-
this.queryStreamController = new
|
|
37764
|
+
this.queryStreamController = new SemanticSearchCommunityQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSemanticSearchCommunityPayload);
|
|
37106
37765
|
this.callback = callback.bind(this);
|
|
37107
37766
|
this.loadPage({ initial: true });
|
|
37108
37767
|
}
|
|
@@ -37124,8 +37783,9 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37124
37783
|
}
|
|
37125
37784
|
startSubscription() {
|
|
37126
37785
|
return this.queryStreamController.subscribeRTE([
|
|
37127
|
-
{ fn:
|
|
37128
|
-
{ fn:
|
|
37786
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
37787
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
37788
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
37129
37789
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37130
37790
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37131
37791
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -37138,10 +37798,18 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37138
37798
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37139
37799
|
if (!collection)
|
|
37140
37800
|
return;
|
|
37141
|
-
const data = (_b = collection.data
|
|
37142
|
-
.map(
|
|
37801
|
+
const data = this.applyFilter((_b = collection.data
|
|
37802
|
+
.map(communityIdWithScore => {
|
|
37803
|
+
const [communityId, score] = communityIdWithScore.split(':');
|
|
37804
|
+
return {
|
|
37805
|
+
communityId,
|
|
37806
|
+
score: parseFloat(score),
|
|
37807
|
+
};
|
|
37808
|
+
})
|
|
37809
|
+
.sort((a, b) => b.score - a.score)
|
|
37810
|
+
.map(({ communityId }) => pullFromCache(['community', 'get', communityId]))
|
|
37143
37811
|
.filter(isNonNullable)
|
|
37144
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37812
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
37145
37813
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
37146
37814
|
return;
|
|
37147
37815
|
this.callback({
|
|
@@ -37152,76 +37820,87 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37152
37820
|
error,
|
|
37153
37821
|
});
|
|
37154
37822
|
}
|
|
37823
|
+
applyFilter(data) {
|
|
37824
|
+
const { userId } = getActiveClient();
|
|
37825
|
+
let communities = data;
|
|
37826
|
+
if (this.query.categoryIds) {
|
|
37827
|
+
communities = communities.filter(c => {
|
|
37828
|
+
var _a;
|
|
37829
|
+
return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.some((id) => {
|
|
37830
|
+
if (!this.query.categoryIds)
|
|
37831
|
+
return true;
|
|
37832
|
+
if (this.query.categoryIds.length === 0)
|
|
37833
|
+
return true;
|
|
37834
|
+
return this.query.categoryIds.includes(id);
|
|
37835
|
+
});
|
|
37836
|
+
});
|
|
37837
|
+
}
|
|
37838
|
+
if (this.query.tags) {
|
|
37839
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
37840
|
+
}
|
|
37841
|
+
if (this.query.communityMembershipStatus && userId) {
|
|
37842
|
+
communities = filterByCommunityMembership(communities, this.query.communityMembershipStatus, userId);
|
|
37843
|
+
}
|
|
37844
|
+
return communities;
|
|
37845
|
+
}
|
|
37155
37846
|
}
|
|
37156
37847
|
|
|
37157
|
-
/* begin_public_function
|
|
37158
|
-
id: community.query.recommended_communities
|
|
37159
|
-
*/
|
|
37160
37848
|
/**
|
|
37161
|
-
*
|
|
37162
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
37163
|
-
*
|
|
37164
|
-
* let communities = []
|
|
37165
|
-
* const unsub = CommunityRepository.getCommunities({
|
|
37166
|
-
* displayName: Amity.Community['displayName'],
|
|
37167
|
-
* }, response => merge(communities, response.data))
|
|
37168
|
-
* ```
|
|
37849
|
+
* search posts by semantic search
|
|
37169
37850
|
*
|
|
37170
|
-
*
|
|
37851
|
+
* @returns the associated pinned post(s)
|
|
37171
37852
|
*
|
|
37172
|
-
* @
|
|
37173
|
-
* @param callback the function to call when new data are available
|
|
37174
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
37853
|
+
* @category Posts Live Collection
|
|
37175
37854
|
*
|
|
37176
|
-
* @category Community Live Collection
|
|
37177
37855
|
*/
|
|
37178
|
-
const
|
|
37179
|
-
const { log, cache
|
|
37856
|
+
const semanticSearchCommunities = (params, callback, config) => {
|
|
37857
|
+
const { log, cache } = getActiveClient();
|
|
37180
37858
|
if (!cache) {
|
|
37181
37859
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37182
37860
|
}
|
|
37183
37861
|
const timestamp = Date.now();
|
|
37184
|
-
log(`
|
|
37185
|
-
const
|
|
37186
|
-
const disposers =
|
|
37187
|
-
const cacheKey =
|
|
37862
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > listen`);
|
|
37863
|
+
const semanticSearchPostLiveCollection = new SemanticSearchCommunityLiveCollectionController(params, callback);
|
|
37864
|
+
const disposers = semanticSearchPostLiveCollection.startSubscription();
|
|
37865
|
+
const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
|
|
37188
37866
|
disposers.push(() => dropFromCache(cacheKey));
|
|
37189
37867
|
return () => {
|
|
37190
|
-
log(`
|
|
37868
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37191
37869
|
disposers.forEach(fn => fn());
|
|
37192
37870
|
};
|
|
37193
|
-
};
|
|
37194
|
-
/* end_public_function */
|
|
37871
|
+
};
|
|
37195
37872
|
|
|
37196
|
-
|
|
37873
|
+
/**
|
|
37874
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
37875
|
+
* TODO: check if querybyIds is supported
|
|
37876
|
+
*/
|
|
37877
|
+
class JoinRequestListPaginationController extends PaginationController {
|
|
37197
37878
|
async getRequest(queryParams, token) {
|
|
37198
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
37199
|
-
const
|
|
37200
|
-
|
|
37201
|
-
}
|
|
37202
|
-
|
|
37203
|
-
const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/communities`, {
|
|
37204
|
-
params: Object.assign(Object.assign({}, params), { filter: communityMembershipStatus !== null && communityMembershipStatus !== void 0 ? communityMembershipStatus : "all" /* AmityCommunityMemberStatusFilter.ALL */, options }),
|
|
37879
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
|
|
37880
|
+
const options = token ? { token } : { limit };
|
|
37881
|
+
const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
37882
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
|
|
37883
|
+
params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
|
|
37205
37884
|
});
|
|
37206
37885
|
return queryResponse;
|
|
37207
37886
|
}
|
|
37208
37887
|
}
|
|
37209
37888
|
|
|
37210
|
-
|
|
37211
|
-
|
|
37212
|
-
|
|
37213
|
-
|
|
37214
|
-
|
|
37215
|
-
}
|
|
37889
|
+
var EnumJoinRequestAction;
|
|
37890
|
+
(function (EnumJoinRequestAction) {
|
|
37891
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
37892
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
37893
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
37894
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
37216
37895
|
|
|
37217
|
-
class
|
|
37896
|
+
class JoinRequestListQueryStreamController extends QueryStreamController {
|
|
37218
37897
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37219
37898
|
super(query, cacheKey);
|
|
37220
37899
|
this.notifyChange = notifyChange;
|
|
37221
37900
|
this.preparePayload = preparePayload;
|
|
37222
37901
|
}
|
|
37223
37902
|
async saveToMainDB(response) {
|
|
37224
|
-
const processedPayload = this.preparePayload(response);
|
|
37903
|
+
const processedPayload = await this.preparePayload(response);
|
|
37225
37904
|
const client = getActiveClient();
|
|
37226
37905
|
const cachedAt = client.cache && Date.now();
|
|
37227
37906
|
if (client.cache) {
|
|
@@ -37232,47 +37911,59 @@ class SemanticSearchCommunityQueryStreamController extends QueryStreamController
|
|
|
37232
37911
|
var _a, _b;
|
|
37233
37912
|
if (refresh) {
|
|
37234
37913
|
pushToCache(this.cacheKey, {
|
|
37235
|
-
data:
|
|
37914
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37236
37915
|
});
|
|
37237
37916
|
}
|
|
37238
37917
|
else {
|
|
37239
37918
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37240
|
-
const
|
|
37241
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
37919
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37920
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
37921
|
+
...new Set([
|
|
37922
|
+
...joinRequests,
|
|
37923
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37924
|
+
]),
|
|
37925
|
+
] }));
|
|
37242
37926
|
}
|
|
37243
37927
|
}
|
|
37244
37928
|
reactor(action) {
|
|
37245
|
-
return (
|
|
37929
|
+
return (joinRequest) => {
|
|
37246
37930
|
var _a;
|
|
37247
37931
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37248
37932
|
if (!collection)
|
|
37249
37933
|
return;
|
|
37250
|
-
|
|
37934
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
37935
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
37936
|
+
if (!isExist)
|
|
37937
|
+
return;
|
|
37938
|
+
}
|
|
37939
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
37940
|
+
collection.data = [
|
|
37941
|
+
...new Set([
|
|
37942
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
37943
|
+
...collection.data,
|
|
37944
|
+
]),
|
|
37945
|
+
];
|
|
37946
|
+
}
|
|
37947
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
37948
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
37949
|
+
}
|
|
37251
37950
|
pushToCache(this.cacheKey, collection);
|
|
37252
37951
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37253
37952
|
};
|
|
37254
|
-
//
|
|
37255
37953
|
}
|
|
37256
37954
|
subscribeRTE(createSubscriber) {
|
|
37257
37955
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37258
37956
|
}
|
|
37259
37957
|
}
|
|
37260
37958
|
|
|
37261
|
-
|
|
37262
|
-
(function (EnumCommunityActions) {
|
|
37263
|
-
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
37264
|
-
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37265
|
-
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37266
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
37267
|
-
|
|
37268
|
-
class SemanticSearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
37959
|
+
class JoinRequestListLiveCollectionController extends LiveCollectionController {
|
|
37269
37960
|
constructor(query, callback) {
|
|
37270
37961
|
const queryStreamId = hash(query);
|
|
37271
|
-
const cacheKey = ['
|
|
37272
|
-
const paginationController = new
|
|
37962
|
+
const cacheKey = ['joinRequestList', 'collection', queryStreamId];
|
|
37963
|
+
const paginationController = new JoinRequestListPaginationController(query);
|
|
37273
37964
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37274
37965
|
this.query = query;
|
|
37275
|
-
this.queryStreamController = new
|
|
37966
|
+
this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
37276
37967
|
this.callback = callback.bind(this);
|
|
37277
37968
|
this.loadPage({ initial: true });
|
|
37278
37969
|
}
|
|
@@ -37282,7 +37973,7 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37282
37973
|
if (!collection) {
|
|
37283
37974
|
pushToCache(this.cacheKey, {
|
|
37284
37975
|
data: [],
|
|
37285
|
-
params:
|
|
37976
|
+
params: this.query,
|
|
37286
37977
|
});
|
|
37287
37978
|
}
|
|
37288
37979
|
}
|
|
@@ -37290,37 +37981,26 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37290
37981
|
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37291
37982
|
}
|
|
37292
37983
|
persistQueryStream({ response, direction, refresh, }) {
|
|
37293
|
-
|
|
37984
|
+
const joinRequestResponse = response;
|
|
37985
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
37294
37986
|
}
|
|
37295
37987
|
startSubscription() {
|
|
37296
37988
|
return this.queryStreamController.subscribeRTE([
|
|
37297
|
-
{ fn:
|
|
37298
|
-
{ fn:
|
|
37299
|
-
{ fn:
|
|
37300
|
-
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37301
|
-
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37302
|
-
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
37303
|
-
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37304
|
-
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37989
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
37990
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
37991
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
37305
37992
|
]);
|
|
37306
37993
|
}
|
|
37307
37994
|
notifyChange({ origin, loading, error }) {
|
|
37308
|
-
var _a
|
|
37995
|
+
var _a;
|
|
37309
37996
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37310
37997
|
if (!collection)
|
|
37311
37998
|
return;
|
|
37312
|
-
const data = this.applyFilter(
|
|
37313
|
-
.map(
|
|
37314
|
-
const [communityId, score] = communityIdWithScore.split(':');
|
|
37315
|
-
return {
|
|
37316
|
-
communityId,
|
|
37317
|
-
score: parseFloat(score),
|
|
37318
|
-
};
|
|
37319
|
-
})
|
|
37320
|
-
.sort((a, b) => b.score - a.score)
|
|
37321
|
-
.map(({ communityId }) => pullFromCache(['community', 'get', communityId]))
|
|
37999
|
+
const data = this.applyFilter(collection.data
|
|
38000
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
37322
38001
|
.filter(isNonNullable)
|
|
37323
|
-
.map(({ data }) => data)
|
|
38002
|
+
.map(({ data }) => data)
|
|
38003
|
+
.map(joinRequestLinkedObject));
|
|
37324
38004
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
37325
38005
|
return;
|
|
37326
38006
|
this.callback({
|
|
@@ -37332,54 +38012,57 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37332
38012
|
});
|
|
37333
38013
|
}
|
|
37334
38014
|
applyFilter(data) {
|
|
37335
|
-
|
|
37336
|
-
|
|
37337
|
-
|
|
37338
|
-
communities = communities.filter(c => {
|
|
37339
|
-
var _a;
|
|
37340
|
-
return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.some((id) => {
|
|
37341
|
-
if (!this.query.categoryIds)
|
|
37342
|
-
return true;
|
|
37343
|
-
if (this.query.categoryIds.length === 0)
|
|
37344
|
-
return true;
|
|
37345
|
-
return this.query.categoryIds.includes(id);
|
|
37346
|
-
});
|
|
37347
|
-
});
|
|
37348
|
-
}
|
|
37349
|
-
if (this.query.tags) {
|
|
37350
|
-
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
38015
|
+
let joinRequest = data;
|
|
38016
|
+
if (this.query.communityIds && this.query.communityIds.length > 0) {
|
|
38017
|
+
joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
|
|
37351
38018
|
}
|
|
37352
|
-
|
|
37353
|
-
|
|
37354
|
-
|
|
37355
|
-
|
|
38019
|
+
const sortFn = (() => {
|
|
38020
|
+
switch (this.query.sortBy) {
|
|
38021
|
+
case 'firstCreated':
|
|
38022
|
+
return sortByFirstCreated;
|
|
38023
|
+
case 'lastCreated':
|
|
38024
|
+
return sortByLastCreated;
|
|
38025
|
+
default:
|
|
38026
|
+
return sortByLastCreated;
|
|
38027
|
+
}
|
|
38028
|
+
})();
|
|
38029
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
38030
|
+
return joinRequest;
|
|
37356
38031
|
}
|
|
37357
38032
|
}
|
|
37358
38033
|
|
|
38034
|
+
/* begin_public_function
|
|
38035
|
+
id: community.getJoinRequestList
|
|
38036
|
+
*/
|
|
37359
38037
|
/**
|
|
37360
|
-
*
|
|
38038
|
+
* Get Join Requests
|
|
37361
38039
|
*
|
|
37362
|
-
* @
|
|
38040
|
+
* @param params the query parameters
|
|
38041
|
+
* @param callback the callback to be called when the join request are updated
|
|
38042
|
+
* @returns joinRequest[]
|
|
37363
38043
|
*
|
|
37364
|
-
* @category
|
|
38044
|
+
* @category joinRequestList Live Collection
|
|
37365
38045
|
*
|
|
37366
38046
|
*/
|
|
37367
|
-
const
|
|
38047
|
+
const getJoinRequestList = (params, callback, config) => {
|
|
37368
38048
|
const { log, cache } = getActiveClient();
|
|
37369
38049
|
if (!cache) {
|
|
37370
38050
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37371
38051
|
}
|
|
37372
38052
|
const timestamp = Date.now();
|
|
37373
|
-
log(`
|
|
37374
|
-
const
|
|
37375
|
-
const disposers =
|
|
37376
|
-
const cacheKey =
|
|
37377
|
-
disposers.push(() =>
|
|
38053
|
+
log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
|
|
38054
|
+
const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
|
|
38055
|
+
const disposers = joinRequestListLiveCollection.startSubscription();
|
|
38056
|
+
const cacheKey = joinRequestListLiveCollection.getCacheKey();
|
|
38057
|
+
disposers.push(() => {
|
|
38058
|
+
dropFromCache(cacheKey);
|
|
38059
|
+
});
|
|
37378
38060
|
return () => {
|
|
37379
|
-
log(`
|
|
38061
|
+
log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
|
|
37380
38062
|
disposers.forEach(fn => fn());
|
|
37381
38063
|
};
|
|
37382
|
-
};
|
|
38064
|
+
};
|
|
38065
|
+
/* end_public_function */
|
|
37383
38066
|
|
|
37384
38067
|
var AmityCommunityMemberStatusFilter;
|
|
37385
38068
|
(function (AmityCommunityMemberStatusFilter) {
|
|
@@ -37551,6 +38234,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
37551
38234
|
getTrendingCommunities: getTrendingCommunities,
|
|
37552
38235
|
getRecommendedCommunities: getRecommendedCommunities,
|
|
37553
38236
|
semanticSearchCommunities: semanticSearchCommunities,
|
|
38237
|
+
getJoinRequestList: getJoinRequestList,
|
|
37554
38238
|
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
37555
38239
|
});
|
|
37556
38240
|
|
|
@@ -39791,7 +40475,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39791
40475
|
const client = getActiveClient();
|
|
39792
40476
|
const cachedAt = client.cache && Date.now();
|
|
39793
40477
|
if (client.cache) {
|
|
39794
|
-
|
|
40478
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
40479
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39795
40480
|
}
|
|
39796
40481
|
}
|
|
39797
40482
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -39920,7 +40605,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39920
40605
|
const client = getActiveClient();
|
|
39921
40606
|
const cachedAt = client.cache && Date.now();
|
|
39922
40607
|
if (client.cache) {
|
|
39923
|
-
|
|
40608
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
40609
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39924
40610
|
}
|
|
39925
40611
|
}
|
|
39926
40612
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -43274,4 +43960,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
43274
43960
|
getMyCommunityInvitations: getMyCommunityInvitations
|
|
43275
43961
|
});
|
|
43276
43962
|
|
|
43277
|
-
export { API_REGIONS, index$2 as AdRepository, index$a as CategoryRepository, index$e as ChannelRepository, index$n as Client, index$8 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$b as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$k as FileRepository, FileType, index as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, index$4 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$i as MessageRepository, index$5 as PollRepository, PostContentType, index$7 as PostRepository, index$j as ReactionRepository, index$3 as StoryRepository, index$6 as StreamRepository, index$h as SubChannelRepository, SubscriptionLevels, index$l as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$1 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|
|
43963
|
+
export { API_REGIONS, index$2 as AdRepository, index$a as CategoryRepository, index$e as ChannelRepository, index$n as Client, index$8 as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$b as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$k as FileRepository, FileType, index as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$4 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$i as MessageRepository, index$5 as PollRepository, PostContentType, index$7 as PostRepository, index$j as ReactionRepository, index$3 as StoryRepository, index$6 as StreamRepository, index$h as SubChannelRepository, SubscriptionLevels, index$l as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$1 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|