@amityco/ts-sdk 7.4.1-4207cb63.0 → 7.4.1-82bb9867.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +4 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +39 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/joinRequest.d.ts +53 -0
- package/dist/@types/domains/joinRequest.d.ts.map +1 -0
- package/dist/@types/domains/notification.d.ts +4 -2
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
- package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
- package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/index.d.ts +1 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +997 -266
- package/dist/index.esm.js +1126 -395
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/events.ts +7 -1
- package/src/@types/core/model.ts +3 -0
- package/src/@types/core/payload.ts +22 -1
- package/src/@types/domains/community.ts +55 -2
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/domains/notification.ts +2 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunities.ts +3 -1
- package/src/communityRepository/api/getCommunity.ts +8 -0
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/communityMembership/events/index.ts +1 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +66 -0
- package/src/communityRepository/joinRequest/events/index.ts +3 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
- package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
- package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
- package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
- package/src/communityRepository/observers/getCommunity.ts +3 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
- package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
- package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
- package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequests.ts +44 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/index.ts +1 -0
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
- package/src/communityRepository/utils/communityWithMembership.ts +1 -1
- package/src/communityRepository/utils/payload.ts +27 -1
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +22 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
package/dist/index.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,234 +23462,304 @@ const notificationTrayLinkedObject = (noti) => {
|
|
|
23446
23462
|
.map(user => userLinkedObject(user)) });
|
|
23447
23463
|
};
|
|
23448
23464
|
|
|
23449
|
-
|
|
23450
|
-
|
|
23451
|
-
|
|
23452
|
-
|
|
23453
|
-
|
|
23454
|
-
|
|
23455
|
-
|
|
23456
|
-
|
|
23457
|
-
|
|
23458
|
-
|
|
23459
|
-
|
|
23460
|
-
|
|
23461
|
-
|
|
23462
|
-
|
|
23463
|
-
*
|
|
23464
|
-
*
|
|
23465
|
-
* targetType: string,
|
|
23466
|
-
* targetId: string,
|
|
23467
|
-
* userIds: string[]
|
|
23468
|
-
* }))
|
|
23469
|
-
* ```
|
|
23470
|
-
*
|
|
23471
|
-
* Creates an {@link Amity.Invitation}
|
|
23472
|
-
*
|
|
23473
|
-
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
23474
|
-
* @returns The newly created {@link Amity.Invitation}
|
|
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
|
|
23475
23481
|
*
|
|
23476
|
-
*
|
|
23477
|
-
*
|
|
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.
|
|
23478
23484
|
*/
|
|
23479
|
-
|
|
23480
|
-
|
|
23481
|
-
|
|
23482
|
-
|
|
23483
|
-
|
|
23484
|
-
|
|
23485
|
-
|
|
23486
|
-
|
|
23487
|
-
|
|
23488
|
-
|
|
23489
|
-
|
|
23490
|
-
|
|
23491
|
-
};
|
|
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
|
+
}
|
|
23499
|
+
|
|
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;
|
|
23492
23505
|
};
|
|
23493
|
-
|
|
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);
|
|
23554
|
+
};
|
|
23494
23555
|
|
|
23495
23556
|
/* begin_public_function
|
|
23496
|
-
id:
|
|
23557
|
+
id: joinRequest.approve
|
|
23497
23558
|
*/
|
|
23498
23559
|
/**
|
|
23499
23560
|
* ```js
|
|
23500
|
-
* import {
|
|
23501
|
-
* const isAccepted = await
|
|
23561
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23562
|
+
* const isAccepted = await joinRequest.approve()
|
|
23502
23563
|
* ```
|
|
23503
23564
|
*
|
|
23504
|
-
* Accepts a {@link Amity.
|
|
23565
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
23505
23566
|
*
|
|
23506
|
-
* @param
|
|
23507
|
-
* @returns A success boolean if the {@link Amity.
|
|
23567
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
23568
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
23508
23569
|
*
|
|
23509
|
-
* @category
|
|
23570
|
+
* @category Join Request API
|
|
23510
23571
|
* @async
|
|
23511
23572
|
*/
|
|
23512
|
-
const
|
|
23573
|
+
const approveJoinRequest = async (joinRequest) => {
|
|
23513
23574
|
var _a;
|
|
23514
23575
|
const client = getActiveClient();
|
|
23515
|
-
client.log('
|
|
23516
|
-
const { data } = await client.http.post(`/api/
|
|
23517
|
-
|
|
23518
|
-
|
|
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',
|
|
23519
23582
|
'get',
|
|
23520
|
-
|
|
23583
|
+
joinRequest.joinRequestId,
|
|
23521
23584
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23522
|
-
if (
|
|
23523
|
-
upsertInCache(['
|
|
23524
|
-
|
|
23585
|
+
if (joinRequestCache) {
|
|
23586
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23587
|
+
status: "approved" /* JoinRequestStatusEnum.Approved */,
|
|
23588
|
+
});
|
|
23589
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
23525
23590
|
}
|
|
23526
23591
|
return data.success;
|
|
23527
23592
|
};
|
|
23528
23593
|
/* end_public_function */
|
|
23529
23594
|
|
|
23530
23595
|
/* begin_public_function
|
|
23531
|
-
id:
|
|
23596
|
+
id: joinRequest.cancel
|
|
23532
23597
|
*/
|
|
23533
23598
|
/**
|
|
23534
23599
|
* ```js
|
|
23535
|
-
* import {
|
|
23536
|
-
* const
|
|
23600
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23601
|
+
* const isCanceled = await joinRequest.cancel()
|
|
23537
23602
|
* ```
|
|
23538
23603
|
*
|
|
23539
|
-
*
|
|
23604
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
23540
23605
|
*
|
|
23541
|
-
* @param
|
|
23542
|
-
* @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
|
|
23543
23608
|
*
|
|
23544
|
-
* @category
|
|
23609
|
+
* @category Join Request API
|
|
23545
23610
|
* @async
|
|
23546
23611
|
*/
|
|
23547
|
-
const
|
|
23612
|
+
const cancelJoinRequest = async (joinRequest) => {
|
|
23548
23613
|
var _a;
|
|
23549
23614
|
const client = getActiveClient();
|
|
23550
|
-
client.log('
|
|
23551
|
-
const { data } = await client.http.
|
|
23552
|
-
const
|
|
23553
|
-
'
|
|
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',
|
|
23554
23619
|
'get',
|
|
23555
|
-
|
|
23620
|
+
joinRequest.joinRequestId,
|
|
23556
23621
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23557
|
-
if (
|
|
23558
|
-
|
|
23559
|
-
fireEvent('local.
|
|
23622
|
+
if (joinRequestCache) {
|
|
23623
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
23624
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
23560
23625
|
}
|
|
23561
23626
|
return data.success;
|
|
23562
23627
|
};
|
|
23563
23628
|
/* end_public_function */
|
|
23564
23629
|
|
|
23565
23630
|
/* begin_public_function
|
|
23566
|
-
id:
|
|
23631
|
+
id: joinRequest.reject
|
|
23567
23632
|
*/
|
|
23568
23633
|
/**
|
|
23569
23634
|
* ```js
|
|
23570
|
-
* import {
|
|
23571
|
-
* const
|
|
23635
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
23636
|
+
* const isRejected = await joinRequest.reject()
|
|
23572
23637
|
* ```
|
|
23573
23638
|
*
|
|
23574
|
-
*
|
|
23639
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
23575
23640
|
*
|
|
23576
|
-
* @param
|
|
23577
|
-
* @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
|
|
23578
23643
|
*
|
|
23579
|
-
* @category
|
|
23644
|
+
* @category Join Request API
|
|
23580
23645
|
* @async
|
|
23581
23646
|
*/
|
|
23582
|
-
const
|
|
23647
|
+
const rejectJoinRequest = async (joinRequest) => {
|
|
23583
23648
|
var _a;
|
|
23584
23649
|
const client = getActiveClient();
|
|
23585
|
-
client.log('
|
|
23586
|
-
const { data } = await client.http.
|
|
23587
|
-
|
|
23588
|
-
|
|
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',
|
|
23589
23656
|
'get',
|
|
23590
|
-
|
|
23657
|
+
joinRequest.joinRequestId,
|
|
23591
23658
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23592
|
-
if (
|
|
23593
|
-
|
|
23594
|
-
|
|
23659
|
+
if (joinRequestCache) {
|
|
23660
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
23661
|
+
status: "rejected" /* JoinRequestStatusEnum.Rejected */,
|
|
23662
|
+
});
|
|
23663
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
23595
23664
|
}
|
|
23596
23665
|
return data.success;
|
|
23597
23666
|
};
|
|
23598
23667
|
/* end_public_function */
|
|
23599
23668
|
|
|
23600
|
-
const
|
|
23601
|
-
return Object.assign(Object.assign({},
|
|
23602
|
-
|
|
23603
|
-
|
|
23604
|
-
|
|
23605
|
-
|
|
23606
|
-
|
|
23607
|
-
|
|
23608
|
-
|
|
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;
|
|
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)
|
|
23626
23678
|
return undefined;
|
|
23627
|
-
|
|
23628
|
-
return undefined;
|
|
23629
|
-
}, accept: async () => {
|
|
23630
|
-
await acceptInvitation(invitation._id);
|
|
23631
|
-
}, reject: async () => {
|
|
23632
|
-
await rejectInvitation(invitation._id);
|
|
23679
|
+
return userLinkedObject(user);
|
|
23633
23680
|
}, cancel: async () => {
|
|
23634
|
-
await
|
|
23681
|
+
await cancelJoinRequest(joinRequest);
|
|
23682
|
+
}, approve: async () => {
|
|
23683
|
+
await approveJoinRequest(joinRequest);
|
|
23684
|
+
}, reject: async () => {
|
|
23685
|
+
await rejectJoinRequest(joinRequest);
|
|
23635
23686
|
} });
|
|
23636
23687
|
};
|
|
23637
23688
|
|
|
23638
23689
|
/* begin_public_function
|
|
23639
|
-
id:
|
|
23690
|
+
id: community.getMyJoinRequest
|
|
23640
23691
|
*/
|
|
23641
23692
|
/**
|
|
23642
23693
|
* ```js
|
|
23643
|
-
* import {
|
|
23644
|
-
* const
|
|
23694
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23695
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
23645
23696
|
* ```
|
|
23646
23697
|
*
|
|
23647
|
-
*
|
|
23698
|
+
* Joins a {@link Amity.Community} object
|
|
23648
23699
|
*
|
|
23649
|
-
* @param
|
|
23650
|
-
* @
|
|
23651
|
-
* @returns A {@link Amity.Invitation} object
|
|
23700
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23701
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
23652
23702
|
*
|
|
23653
|
-
* @category
|
|
23703
|
+
* @category Community API
|
|
23654
23704
|
* @async
|
|
23655
23705
|
*/
|
|
23656
|
-
const
|
|
23706
|
+
const getMyJoinRequest = async (communityId) => {
|
|
23657
23707
|
const client = getActiveClient();
|
|
23658
|
-
client.log('
|
|
23659
|
-
const { data: payload } = await client.http.get(`/api/
|
|
23660
|
-
const data =
|
|
23708
|
+
client.log('community/myJoinRequest', communityId);
|
|
23709
|
+
const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
|
|
23710
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23661
23711
|
const cachedAt = client.cache && Date.now();
|
|
23662
23712
|
if (client.cache)
|
|
23663
23713
|
ingestInCache(data, { cachedAt });
|
|
23664
23714
|
return {
|
|
23665
|
-
data: data.
|
|
23715
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
23666
23716
|
cachedAt,
|
|
23667
23717
|
};
|
|
23668
23718
|
};
|
|
23669
23719
|
/* end_public_function */
|
|
23670
23720
|
|
|
23671
|
-
|
|
23672
|
-
|
|
23673
|
-
|
|
23674
|
-
|
|
23675
|
-
|
|
23676
|
-
|
|
23721
|
+
/* begin_public_function
|
|
23722
|
+
id: community.join
|
|
23723
|
+
*/
|
|
23724
|
+
/**
|
|
23725
|
+
* ```js
|
|
23726
|
+
* import { community } from '@amityco/ts-sdk'
|
|
23727
|
+
* const isJoined = await community.join('foobar')
|
|
23728
|
+
* ```
|
|
23729
|
+
*
|
|
23730
|
+
* Joins a {@link Amity.Community} object
|
|
23731
|
+
*
|
|
23732
|
+
* @param communityId the {@link Amity.Community} to join
|
|
23733
|
+
* @returns A status join result
|
|
23734
|
+
*
|
|
23735
|
+
* @category Community API
|
|
23736
|
+
* @async
|
|
23737
|
+
*/
|
|
23738
|
+
const joinRequest = async (communityId) => {
|
|
23739
|
+
var _a;
|
|
23740
|
+
const client = getActiveClient();
|
|
23741
|
+
client.log('community/joinRequest', communityId);
|
|
23742
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
23743
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23744
|
+
const cachedAt = client.cache && Date.now();
|
|
23745
|
+
if (client.cache)
|
|
23746
|
+
ingestInCache(data, { cachedAt });
|
|
23747
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
23748
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
23749
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
23750
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
23751
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23752
|
+
if (community) {
|
|
23753
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
23754
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
23755
|
+
}
|
|
23756
|
+
}
|
|
23757
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
23758
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
23759
|
+
? { status }
|
|
23760
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
23761
|
+
};
|
|
23762
|
+
/* end_public_function */
|
|
23677
23763
|
|
|
23678
23764
|
class PaginationController {
|
|
23679
23765
|
constructor(queryParams) {
|
|
@@ -23720,12 +23806,18 @@ class PaginationController {
|
|
|
23720
23806
|
}
|
|
23721
23807
|
}
|
|
23722
23808
|
|
|
23723
|
-
|
|
23809
|
+
/**
|
|
23810
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
23811
|
+
* TODO: check if querybyIds is supported
|
|
23812
|
+
*/
|
|
23813
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
23724
23814
|
async getRequest(queryParams, token) {
|
|
23725
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23815
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
23726
23816
|
const options = token ? { token } : { limit };
|
|
23727
|
-
const { data } = await this.http.get(
|
|
23728
|
-
|
|
23817
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
23818
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
23819
|
+
});
|
|
23820
|
+
return queryResponse;
|
|
23729
23821
|
}
|
|
23730
23822
|
}
|
|
23731
23823
|
|
|
@@ -23736,7 +23828,14 @@ class QueryStreamController {
|
|
|
23736
23828
|
}
|
|
23737
23829
|
}
|
|
23738
23830
|
|
|
23739
|
-
|
|
23831
|
+
var EnumJoinRequestAction$1;
|
|
23832
|
+
(function (EnumJoinRequestAction) {
|
|
23833
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
23834
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
23835
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
23836
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
23837
|
+
|
|
23838
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
23740
23839
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23741
23840
|
super(query, cacheKey);
|
|
23742
23841
|
this.notifyChange = notifyChange;
|
|
@@ -23754,38 +23853,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
23754
23853
|
var _a, _b;
|
|
23755
23854
|
if (refresh) {
|
|
23756
23855
|
pushToCache(this.cacheKey, {
|
|
23757
|
-
data: response.
|
|
23856
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23758
23857
|
});
|
|
23759
23858
|
}
|
|
23760
23859
|
else {
|
|
23761
23860
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23762
|
-
const
|
|
23861
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23763
23862
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23764
|
-
...new Set([
|
|
23863
|
+
...new Set([
|
|
23864
|
+
...joinRequests,
|
|
23865
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23866
|
+
]),
|
|
23765
23867
|
] }));
|
|
23766
23868
|
}
|
|
23767
23869
|
}
|
|
23768
23870
|
reactor(action) {
|
|
23769
|
-
return (
|
|
23871
|
+
return (joinRequest) => {
|
|
23770
23872
|
var _a;
|
|
23771
23873
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23772
23874
|
if (!collection)
|
|
23773
23875
|
return;
|
|
23774
|
-
if (action ===
|
|
23775
|
-
const isExist = collection.data.find(id => id ===
|
|
23876
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
23877
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
23776
23878
|
if (!isExist)
|
|
23777
23879
|
return;
|
|
23778
23880
|
}
|
|
23779
|
-
if (action ===
|
|
23881
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
23780
23882
|
collection.data = [
|
|
23781
23883
|
...new Set([
|
|
23782
|
-
...
|
|
23884
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
23783
23885
|
...collection.data,
|
|
23784
23886
|
]),
|
|
23785
23887
|
];
|
|
23786
23888
|
}
|
|
23787
|
-
if (action ===
|
|
23788
|
-
collection.data = collection.data.filter(id => id !==
|
|
23889
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
23890
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
23789
23891
|
}
|
|
23790
23892
|
pushToCache(this.cacheKey, collection);
|
|
23791
23893
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -23931,6 +24033,483 @@ class LiveCollectionController {
|
|
|
23931
24033
|
}
|
|
23932
24034
|
}
|
|
23933
24035
|
|
|
24036
|
+
/**
|
|
24037
|
+
* ```js
|
|
24038
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
24039
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
24040
|
+
* // ...
|
|
24041
|
+
* })
|
|
24042
|
+
* ```
|
|
24043
|
+
*
|
|
24044
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24045
|
+
*
|
|
24046
|
+
* @param callback The function to call when the event was fired
|
|
24047
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24048
|
+
*
|
|
24049
|
+
* @category JoinRequest Events
|
|
24050
|
+
*/
|
|
24051
|
+
const onJoinRequestCreated = (callback) => {
|
|
24052
|
+
const client = getActiveClient();
|
|
24053
|
+
const disposers = [
|
|
24054
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
24055
|
+
];
|
|
24056
|
+
return () => {
|
|
24057
|
+
disposers.forEach(fn => fn());
|
|
24058
|
+
};
|
|
24059
|
+
};
|
|
24060
|
+
|
|
24061
|
+
/**
|
|
24062
|
+
* ```js
|
|
24063
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
24064
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
24065
|
+
* // ...
|
|
24066
|
+
* })
|
|
24067
|
+
* ```
|
|
24068
|
+
*
|
|
24069
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24070
|
+
*
|
|
24071
|
+
* @param callback The function to call when the event was fired
|
|
24072
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24073
|
+
*
|
|
24074
|
+
* @category JoinRequest Events
|
|
24075
|
+
*/
|
|
24076
|
+
const onJoinRequestUpdated = (callback) => {
|
|
24077
|
+
const client = getActiveClient();
|
|
24078
|
+
const disposers = [
|
|
24079
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
24080
|
+
];
|
|
24081
|
+
return () => {
|
|
24082
|
+
disposers.forEach(fn => fn());
|
|
24083
|
+
};
|
|
24084
|
+
};
|
|
24085
|
+
|
|
24086
|
+
/**
|
|
24087
|
+
* ```js
|
|
24088
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
24089
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
24090
|
+
* // ...
|
|
24091
|
+
* })
|
|
24092
|
+
* ```
|
|
24093
|
+
*
|
|
24094
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24095
|
+
*
|
|
24096
|
+
* @param callback The function to call when the event was fired
|
|
24097
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24098
|
+
*
|
|
24099
|
+
* @category JoinRequest Events
|
|
24100
|
+
*/
|
|
24101
|
+
const onJoinRequestDeleted = (callback) => {
|
|
24102
|
+
const client = getActiveClient();
|
|
24103
|
+
const disposers = [
|
|
24104
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
24105
|
+
];
|
|
24106
|
+
return () => {
|
|
24107
|
+
disposers.forEach(fn => fn());
|
|
24108
|
+
};
|
|
24109
|
+
};
|
|
24110
|
+
|
|
24111
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
24112
|
+
constructor(query, callback) {
|
|
24113
|
+
const queryStreamId = hash(query);
|
|
24114
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
24115
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
24116
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24117
|
+
this.query = query;
|
|
24118
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
24119
|
+
this.callback = callback.bind(this);
|
|
24120
|
+
this.loadPage({ initial: true });
|
|
24121
|
+
}
|
|
24122
|
+
setup() {
|
|
24123
|
+
var _a;
|
|
24124
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24125
|
+
if (!collection) {
|
|
24126
|
+
pushToCache(this.cacheKey, {
|
|
24127
|
+
data: [],
|
|
24128
|
+
params: this.query,
|
|
24129
|
+
});
|
|
24130
|
+
}
|
|
24131
|
+
}
|
|
24132
|
+
async persistModel(queryPayload) {
|
|
24133
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24134
|
+
}
|
|
24135
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24136
|
+
const joinRequestResponse = response;
|
|
24137
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
24138
|
+
}
|
|
24139
|
+
startSubscription() {
|
|
24140
|
+
return this.queryStreamController.subscribeRTE([
|
|
24141
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
24142
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
24143
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
24144
|
+
]);
|
|
24145
|
+
}
|
|
24146
|
+
notifyChange({ origin, loading, error }) {
|
|
24147
|
+
var _a;
|
|
24148
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24149
|
+
if (!collection)
|
|
24150
|
+
return;
|
|
24151
|
+
const data = this.applyFilter(collection.data
|
|
24152
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
24153
|
+
.filter(isNonNullable)
|
|
24154
|
+
.map(({ data }) => data)
|
|
24155
|
+
.map(joinRequestLinkedObject));
|
|
24156
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24157
|
+
return;
|
|
24158
|
+
this.callback({
|
|
24159
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24160
|
+
data,
|
|
24161
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24162
|
+
loading,
|
|
24163
|
+
error,
|
|
24164
|
+
});
|
|
24165
|
+
}
|
|
24166
|
+
applyFilter(data) {
|
|
24167
|
+
let joinRequest = data;
|
|
24168
|
+
if (this.query.status) {
|
|
24169
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
24170
|
+
}
|
|
24171
|
+
const sortFn = (() => {
|
|
24172
|
+
switch (this.query.sortBy) {
|
|
24173
|
+
case 'firstCreated':
|
|
24174
|
+
return sortByFirstCreated;
|
|
24175
|
+
case 'lastCreated':
|
|
24176
|
+
return sortByLastCreated;
|
|
24177
|
+
default:
|
|
24178
|
+
return sortByLastCreated;
|
|
24179
|
+
}
|
|
24180
|
+
})();
|
|
24181
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
24182
|
+
return joinRequest;
|
|
24183
|
+
}
|
|
24184
|
+
}
|
|
24185
|
+
|
|
24186
|
+
/**
|
|
24187
|
+
* Get Join Requests
|
|
24188
|
+
*
|
|
24189
|
+
* @param params the query parameters
|
|
24190
|
+
* @param callback the callback to be called when the join request are updated
|
|
24191
|
+
* @returns joinRequests
|
|
24192
|
+
*
|
|
24193
|
+
* @category joinRequest Live Collection
|
|
24194
|
+
*
|
|
24195
|
+
*/
|
|
24196
|
+
const getJoinRequests = (params, callback, config) => {
|
|
24197
|
+
const { log, cache } = getActiveClient();
|
|
24198
|
+
if (!cache) {
|
|
24199
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24200
|
+
}
|
|
24201
|
+
const timestamp = Date.now();
|
|
24202
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
24203
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
24204
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
24205
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
24206
|
+
disposers.push(() => {
|
|
24207
|
+
dropFromCache(cacheKey);
|
|
24208
|
+
});
|
|
24209
|
+
return () => {
|
|
24210
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
24211
|
+
disposers.forEach(fn => fn());
|
|
24212
|
+
};
|
|
24213
|
+
};
|
|
24214
|
+
|
|
24215
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
24216
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
24217
|
+
};
|
|
24218
|
+
|
|
24219
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
24220
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
24221
|
+
};
|
|
24222
|
+
|
|
24223
|
+
/* begin_public_function
|
|
24224
|
+
id: invitation.createInvitations
|
|
24225
|
+
*/
|
|
24226
|
+
/**
|
|
24227
|
+
* ```js
|
|
24228
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
24229
|
+
* const created = await createInvitations({
|
|
24230
|
+
* type: string,
|
|
24231
|
+
* targetType: string,
|
|
24232
|
+
* targetId: string,
|
|
24233
|
+
* userIds: string[]
|
|
24234
|
+
* }))
|
|
24235
|
+
* ```
|
|
24236
|
+
*
|
|
24237
|
+
* Creates an {@link Amity.Invitation}
|
|
24238
|
+
*
|
|
24239
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
24240
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
24241
|
+
*
|
|
24242
|
+
* @category Invitation API
|
|
24243
|
+
* @async
|
|
24244
|
+
*/
|
|
24245
|
+
const createInvitations = async (bundle) => {
|
|
24246
|
+
const client = getActiveClient();
|
|
24247
|
+
client.log('invitation/createInvitations', bundle);
|
|
24248
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
24249
|
+
const data = prepareInvitationPayload(payload);
|
|
24250
|
+
const cachedAt = client.cache && Date.now();
|
|
24251
|
+
if (client.cache)
|
|
24252
|
+
ingestInCache(data, { cachedAt });
|
|
24253
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
24254
|
+
return {
|
|
24255
|
+
data: data.invitations,
|
|
24256
|
+
cachedAt,
|
|
24257
|
+
};
|
|
24258
|
+
};
|
|
24259
|
+
/* end_public_function */
|
|
24260
|
+
|
|
24261
|
+
/* begin_public_function
|
|
24262
|
+
id: invitation.accept
|
|
24263
|
+
*/
|
|
24264
|
+
/**
|
|
24265
|
+
* ```js
|
|
24266
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
24267
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
24268
|
+
* ```
|
|
24269
|
+
*
|
|
24270
|
+
* Accepts a {@link Amity.Invitation} object
|
|
24271
|
+
*
|
|
24272
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
24273
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
24274
|
+
*
|
|
24275
|
+
* @category Invitation API
|
|
24276
|
+
* @async
|
|
24277
|
+
*/
|
|
24278
|
+
const acceptInvitation = async (invitationId) => {
|
|
24279
|
+
var _a;
|
|
24280
|
+
const client = getActiveClient();
|
|
24281
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
24282
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
24283
|
+
const invitation = (_a = pullFromCache([
|
|
24284
|
+
'invitation',
|
|
24285
|
+
'get',
|
|
24286
|
+
invitationId,
|
|
24287
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24288
|
+
if (invitation) {
|
|
24289
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
24290
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24291
|
+
}
|
|
24292
|
+
return data.success;
|
|
24293
|
+
};
|
|
24294
|
+
/* end_public_function */
|
|
24295
|
+
|
|
24296
|
+
/* begin_public_function
|
|
24297
|
+
id: invitation.reject
|
|
24298
|
+
*/
|
|
24299
|
+
/**
|
|
24300
|
+
* ```js
|
|
24301
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
24302
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
24303
|
+
* ```
|
|
24304
|
+
*
|
|
24305
|
+
* Rejects a {@link Amity.Invitation} object
|
|
24306
|
+
*
|
|
24307
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
24308
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
24309
|
+
*
|
|
24310
|
+
* @category Invitation API
|
|
24311
|
+
* @async
|
|
24312
|
+
*/
|
|
24313
|
+
const rejectInvitation = async (invitationId) => {
|
|
24314
|
+
var _a;
|
|
24315
|
+
const client = getActiveClient();
|
|
24316
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
24317
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
24318
|
+
const invitation = (_a = pullFromCache([
|
|
24319
|
+
'invitation',
|
|
24320
|
+
'get',
|
|
24321
|
+
invitationId,
|
|
24322
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24323
|
+
if (invitation) {
|
|
24324
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
24325
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24326
|
+
}
|
|
24327
|
+
return data.success;
|
|
24328
|
+
};
|
|
24329
|
+
/* end_public_function */
|
|
24330
|
+
|
|
24331
|
+
/* begin_public_function
|
|
24332
|
+
id: invitation.cancel
|
|
24333
|
+
*/
|
|
24334
|
+
/**
|
|
24335
|
+
* ```js
|
|
24336
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
24337
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
24338
|
+
* ```
|
|
24339
|
+
*
|
|
24340
|
+
* Cancels a {@link Amity.Invitation} object
|
|
24341
|
+
*
|
|
24342
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
24343
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
24344
|
+
*
|
|
24345
|
+
* @category Invitation API
|
|
24346
|
+
* @async
|
|
24347
|
+
*/
|
|
24348
|
+
const cancelInvitation = async (invitationId) => {
|
|
24349
|
+
var _a;
|
|
24350
|
+
const client = getActiveClient();
|
|
24351
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
24352
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
24353
|
+
const invitation = (_a = pullFromCache([
|
|
24354
|
+
'invitation',
|
|
24355
|
+
'get',
|
|
24356
|
+
invitationId,
|
|
24357
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24358
|
+
if (invitation) {
|
|
24359
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
24360
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
24361
|
+
}
|
|
24362
|
+
return data.success;
|
|
24363
|
+
};
|
|
24364
|
+
/* end_public_function */
|
|
24365
|
+
|
|
24366
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
24367
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
24368
|
+
};
|
|
24369
|
+
|
|
24370
|
+
const invitationLinkedObject = (invitation) => {
|
|
24371
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
24372
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
24373
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24374
|
+
return userLinkedObject(cacheData.data);
|
|
24375
|
+
return undefined;
|
|
24376
|
+
},
|
|
24377
|
+
get createdBy() {
|
|
24378
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
24379
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24380
|
+
return userLinkedObject(cacheData.data);
|
|
24381
|
+
return undefined;
|
|
24382
|
+
},
|
|
24383
|
+
get target() {
|
|
24384
|
+
if (invitation.targetType === 'community') {
|
|
24385
|
+
const cacheData = pullFromCache([
|
|
24386
|
+
'community',
|
|
24387
|
+
'get',
|
|
24388
|
+
invitation.targetId,
|
|
24389
|
+
]);
|
|
24390
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24391
|
+
return cacheData.data;
|
|
24392
|
+
return undefined;
|
|
24393
|
+
}
|
|
24394
|
+
return undefined;
|
|
24395
|
+
}, accept: async () => {
|
|
24396
|
+
await acceptInvitation(invitation._id);
|
|
24397
|
+
}, reject: async () => {
|
|
24398
|
+
await rejectInvitation(invitation._id);
|
|
24399
|
+
}, cancel: async () => {
|
|
24400
|
+
await cancelInvitation(invitation._id);
|
|
24401
|
+
} });
|
|
24402
|
+
};
|
|
24403
|
+
|
|
24404
|
+
/* begin_public_function
|
|
24405
|
+
id: invitation.get
|
|
24406
|
+
*/
|
|
24407
|
+
/**
|
|
24408
|
+
* ```js
|
|
24409
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
24410
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
24411
|
+
* ```
|
|
24412
|
+
*
|
|
24413
|
+
* Get a {@link Amity.Invitation} object
|
|
24414
|
+
*
|
|
24415
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
24416
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
24417
|
+
* @returns A {@link Amity.Invitation} object
|
|
24418
|
+
*
|
|
24419
|
+
* @category Invitation API
|
|
24420
|
+
* @async
|
|
24421
|
+
*/
|
|
24422
|
+
const getInvitation = async (targetType, targetId) => {
|
|
24423
|
+
const client = getActiveClient();
|
|
24424
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
24425
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
24426
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
24427
|
+
const cachedAt = client.cache && Date.now();
|
|
24428
|
+
if (client.cache)
|
|
24429
|
+
ingestInCache(data, { cachedAt });
|
|
24430
|
+
return {
|
|
24431
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
24432
|
+
cachedAt,
|
|
24433
|
+
};
|
|
24434
|
+
};
|
|
24435
|
+
/* end_public_function */
|
|
24436
|
+
|
|
24437
|
+
var InvitationActionsEnum;
|
|
24438
|
+
(function (InvitationActionsEnum) {
|
|
24439
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
24440
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
24441
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
24442
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
24443
|
+
|
|
24444
|
+
class InvitationsPaginationController extends PaginationController {
|
|
24445
|
+
async getRequest(queryParams, token) {
|
|
24446
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
24447
|
+
const options = token ? { token } : { limit };
|
|
24448
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
24449
|
+
return data;
|
|
24450
|
+
}
|
|
24451
|
+
}
|
|
24452
|
+
|
|
24453
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
24454
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24455
|
+
super(query, cacheKey);
|
|
24456
|
+
this.notifyChange = notifyChange;
|
|
24457
|
+
this.preparePayload = preparePayload;
|
|
24458
|
+
}
|
|
24459
|
+
async saveToMainDB(response) {
|
|
24460
|
+
const processedPayload = await this.preparePayload(response);
|
|
24461
|
+
const client = getActiveClient();
|
|
24462
|
+
const cachedAt = client.cache && Date.now();
|
|
24463
|
+
if (client.cache) {
|
|
24464
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
24465
|
+
}
|
|
24466
|
+
}
|
|
24467
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
24468
|
+
var _a, _b;
|
|
24469
|
+
if (refresh) {
|
|
24470
|
+
pushToCache(this.cacheKey, {
|
|
24471
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
24472
|
+
});
|
|
24473
|
+
}
|
|
24474
|
+
else {
|
|
24475
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24476
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24477
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
24478
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
24479
|
+
] }));
|
|
24480
|
+
}
|
|
24481
|
+
}
|
|
24482
|
+
reactor(action) {
|
|
24483
|
+
return (invitations) => {
|
|
24484
|
+
var _a;
|
|
24485
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24486
|
+
if (!collection)
|
|
24487
|
+
return;
|
|
24488
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
24489
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
24490
|
+
if (!isExist)
|
|
24491
|
+
return;
|
|
24492
|
+
}
|
|
24493
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
24494
|
+
collection.data = [
|
|
24495
|
+
...new Set([
|
|
24496
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
24497
|
+
...collection.data,
|
|
24498
|
+
]),
|
|
24499
|
+
];
|
|
24500
|
+
}
|
|
24501
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
24502
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
24503
|
+
}
|
|
24504
|
+
pushToCache(this.cacheKey, collection);
|
|
24505
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24506
|
+
};
|
|
24507
|
+
}
|
|
24508
|
+
subscribeRTE(createSubscriber) {
|
|
24509
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24510
|
+
}
|
|
24511
|
+
}
|
|
24512
|
+
|
|
23934
24513
|
/**
|
|
23935
24514
|
* ```js
|
|
23936
24515
|
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
@@ -24139,6 +24718,13 @@ const communityLinkedObject = (community) => {
|
|
|
24139
24718
|
}, getInvitation: async () => {
|
|
24140
24719
|
const { data } = await getInvitation('community', community.communityId);
|
|
24141
24720
|
return data;
|
|
24721
|
+
}, join: async () => {
|
|
24722
|
+
return joinRequest(community.communityId);
|
|
24723
|
+
}, getJoinRequests: (params, callback) => {
|
|
24724
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
24725
|
+
}, getMyJoinRequest: async () => {
|
|
24726
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
24727
|
+
return data;
|
|
24142
24728
|
} });
|
|
24143
24729
|
};
|
|
24144
24730
|
|
|
@@ -24158,6 +24744,7 @@ const LinkedObject = {
|
|
|
24158
24744
|
notificationTray: notificationTrayLinkedObject,
|
|
24159
24745
|
community: communityLinkedObject,
|
|
24160
24746
|
invitation: invitationLinkedObject,
|
|
24747
|
+
joinRequest: joinRequestLinkedObject,
|
|
24161
24748
|
};
|
|
24162
24749
|
|
|
24163
24750
|
const constructChannelObject = (channel) => {
|
|
@@ -29714,41 +30301,6 @@ getComment$2.locally = (commentId) => {
|
|
|
29714
30301
|
};
|
|
29715
30302
|
};
|
|
29716
30303
|
|
|
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
30304
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
29753
30305
|
var _a, _b;
|
|
29754
30306
|
let id;
|
|
@@ -30063,53 +30615,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
30063
30615
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
30064
30616
|
};
|
|
30065
30617
|
|
|
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
30618
|
const preparePostPayload = (payload) => {
|
|
30114
30619
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
30115
30620
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -35173,10 +35678,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
35173
35678
|
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
35174
35679
|
const client = getActiveClient();
|
|
35175
35680
|
client.log('community/getCommunities', communityIds);
|
|
35681
|
+
const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
35176
35682
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35177
35683
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
35178
35684
|
params: {
|
|
35179
|
-
communityIds,
|
|
35685
|
+
communityIds: encodedCommunityIds,
|
|
35180
35686
|
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35181
35687
|
},
|
|
35182
35688
|
});
|
|
@@ -35310,11 +35816,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
35310
35816
|
* @category Community API
|
|
35311
35817
|
* @async
|
|
35312
35818
|
*/
|
|
35313
|
-
const getCommunity$1 = async (communityId) => {
|
|
35819
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
35314
35820
|
const client = getActiveClient();
|
|
35315
35821
|
client.log('community/getCommunity', communityId);
|
|
35316
35822
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35317
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
35823
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
35824
|
+
params: {
|
|
35825
|
+
type: 'communityJoinRequest',
|
|
35826
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35827
|
+
},
|
|
35828
|
+
});
|
|
35318
35829
|
const data = prepareCommunityPayload(payload);
|
|
35319
35830
|
const cachedAt = client.cache && Date.now();
|
|
35320
35831
|
if (client.cache) {
|
|
@@ -35389,6 +35900,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
35389
35900
|
};
|
|
35390
35901
|
/* end_public_function */
|
|
35391
35902
|
|
|
35903
|
+
/**
|
|
35904
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
35905
|
+
*/
|
|
35392
35906
|
/* begin_public_function
|
|
35393
35907
|
id: community.join
|
|
35394
35908
|
*/
|
|
@@ -35529,10 +36043,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
35529
36043
|
*/
|
|
35530
36044
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35531
36045
|
async getRequest(queryParams, token) {
|
|
36046
|
+
var _a;
|
|
35532
36047
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35533
36048
|
const options = token ? { token } : { limit };
|
|
35534
36049
|
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 }),
|
|
36050
|
+
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
36051
|
});
|
|
35537
36052
|
return queryResponse;
|
|
35538
36053
|
}
|
|
@@ -36032,6 +36547,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
36032
36547
|
|
|
36033
36548
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
36034
36549
|
|
|
36550
|
+
const onLocalCommunityJoin = (callback) => {
|
|
36551
|
+
const client = getActiveClient();
|
|
36552
|
+
const filter = async (rawPayload) => {
|
|
36553
|
+
callback(rawPayload[0]);
|
|
36554
|
+
};
|
|
36555
|
+
const disposers = [
|
|
36556
|
+
createEventSubscriber(client, 'onCommunityUpdate', 'local.community.join', filter),
|
|
36557
|
+
];
|
|
36558
|
+
return () => {
|
|
36559
|
+
disposers.forEach(fn => fn());
|
|
36560
|
+
};
|
|
36561
|
+
};
|
|
36562
|
+
|
|
36035
36563
|
/**
|
|
36036
36564
|
* ```js
|
|
36037
36565
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -36518,7 +37046,8 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
36518
37046
|
onCommunityJoined: onCommunityJoined,
|
|
36519
37047
|
onCommunityLeft: onCommunityLeft,
|
|
36520
37048
|
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
36521
|
-
onLocalCommunityLeft: onLocalCommunityLeft
|
|
37049
|
+
onLocalCommunityLeft: onLocalCommunityLeft,
|
|
37050
|
+
onLocalCommunityJoin: onLocalCommunityJoin
|
|
36522
37051
|
});
|
|
36523
37052
|
|
|
36524
37053
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -36742,6 +37271,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36742
37271
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36743
37272
|
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36744
37273
|
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37274
|
+
{
|
|
37275
|
+
fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
37276
|
+
action: EnumCommunityActions$3.OnCommunityUpdated,
|
|
37277
|
+
},
|
|
36745
37278
|
]);
|
|
36746
37279
|
}
|
|
36747
37280
|
notifyChange({ origin, loading, error }) {
|
|
@@ -36865,6 +37398,7 @@ const getCommunity = (communityId, callback) => {
|
|
|
36865
37398
|
onCommunityUserBanned,
|
|
36866
37399
|
onCommunityUserUnbanned,
|
|
36867
37400
|
onCommunityUserChanged,
|
|
37401
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
36868
37402
|
]);
|
|
36869
37403
|
};
|
|
36870
37404
|
/* end_public_function */
|
|
@@ -36979,7 +37513,169 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36979
37513
|
const data = (_b = collection.data
|
|
36980
37514
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36981
37515
|
.filter(isNonNullable)
|
|
36982
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37516
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
37517
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37518
|
+
return;
|
|
37519
|
+
this.callback({
|
|
37520
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
37521
|
+
data,
|
|
37522
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
37523
|
+
loading,
|
|
37524
|
+
error,
|
|
37525
|
+
});
|
|
37526
|
+
}
|
|
37527
|
+
}
|
|
37528
|
+
|
|
37529
|
+
/* begin_public_function
|
|
37530
|
+
id: community.query.trending_communities
|
|
37531
|
+
*/
|
|
37532
|
+
/**
|
|
37533
|
+
* ```js
|
|
37534
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
37535
|
+
*
|
|
37536
|
+
* let communities = []
|
|
37537
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
37538
|
+
* displayName: Amity.Community['displayName'],
|
|
37539
|
+
* }, response => merge(communities, response.data))
|
|
37540
|
+
* ```
|
|
37541
|
+
*
|
|
37542
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
37543
|
+
*
|
|
37544
|
+
* @param params for querying communities
|
|
37545
|
+
* @param callback the function to call when new data are available
|
|
37546
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
37547
|
+
*
|
|
37548
|
+
* @category Community Live Collection
|
|
37549
|
+
*/
|
|
37550
|
+
const getTrendingCommunities = (params, callback, config) => {
|
|
37551
|
+
const { log, cache, userId } = getActiveClient();
|
|
37552
|
+
if (!cache) {
|
|
37553
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37554
|
+
}
|
|
37555
|
+
const timestamp = Date.now();
|
|
37556
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
|
|
37557
|
+
const trendingCommunitiesLiveCollection = new TrendingCommunityLiveCollectionController(params, callback);
|
|
37558
|
+
const disposers = trendingCommunitiesLiveCollection.startSubscription();
|
|
37559
|
+
const cacheKey = trendingCommunitiesLiveCollection.getCacheKey();
|
|
37560
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
37561
|
+
return () => {
|
|
37562
|
+
log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37563
|
+
disposers.forEach(fn => fn());
|
|
37564
|
+
};
|
|
37565
|
+
};
|
|
37566
|
+
/* end_public_function */
|
|
37567
|
+
|
|
37568
|
+
/**
|
|
37569
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
37570
|
+
* TODO: check if querybyIds is supported
|
|
37571
|
+
*/
|
|
37572
|
+
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
37573
|
+
async getRequest(queryParams, token) {
|
|
37574
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
37575
|
+
const options = token ? { token } : { limit };
|
|
37576
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/recommended`, {
|
|
37577
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
37578
|
+
});
|
|
37579
|
+
return queryResponse;
|
|
37580
|
+
}
|
|
37581
|
+
}
|
|
37582
|
+
|
|
37583
|
+
class RecommendedCommunitiesQueryStreamController extends QueryStreamController {
|
|
37584
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37585
|
+
super(query, cacheKey);
|
|
37586
|
+
this.notifyChange = notifyChange;
|
|
37587
|
+
this.preparePayload = preparePayload;
|
|
37588
|
+
}
|
|
37589
|
+
async saveToMainDB(response) {
|
|
37590
|
+
const processedPayload = await this.preparePayload(response);
|
|
37591
|
+
const client = getActiveClient();
|
|
37592
|
+
const cachedAt = client.cache && Date.now();
|
|
37593
|
+
if (client.cache) {
|
|
37594
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37595
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
37596
|
+
}
|
|
37597
|
+
}
|
|
37598
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37599
|
+
var _a, _b;
|
|
37600
|
+
if (refresh) {
|
|
37601
|
+
pushToCache(this.cacheKey, {
|
|
37602
|
+
data: response.communities.map(getResolver('community')),
|
|
37603
|
+
});
|
|
37604
|
+
}
|
|
37605
|
+
else {
|
|
37606
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37607
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37608
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
37609
|
+
}
|
|
37610
|
+
}
|
|
37611
|
+
reactor(action) {
|
|
37612
|
+
return (community) => {
|
|
37613
|
+
var _a;
|
|
37614
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37615
|
+
if (!collection)
|
|
37616
|
+
return;
|
|
37617
|
+
pushToCache(this.cacheKey, collection);
|
|
37618
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37619
|
+
};
|
|
37620
|
+
}
|
|
37621
|
+
subscribeRTE(createSubscriber) {
|
|
37622
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37623
|
+
}
|
|
37624
|
+
}
|
|
37625
|
+
|
|
37626
|
+
var EnumCommunityActions$1;
|
|
37627
|
+
(function (EnumCommunityActions) {
|
|
37628
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37629
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37630
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
37631
|
+
|
|
37632
|
+
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
37633
|
+
constructor(query, callback) {
|
|
37634
|
+
const queryStreamId = hash(query);
|
|
37635
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
37636
|
+
const paginationController = new RecommendedCommunitiesPaginationController(query);
|
|
37637
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37638
|
+
this.query = query;
|
|
37639
|
+
this.queryStreamController = new RecommendedCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
37640
|
+
this.callback = callback.bind(this);
|
|
37641
|
+
this.loadPage({ initial: true });
|
|
37642
|
+
}
|
|
37643
|
+
setup() {
|
|
37644
|
+
var _a;
|
|
37645
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37646
|
+
if (!collection) {
|
|
37647
|
+
pushToCache(this.cacheKey, {
|
|
37648
|
+
data: [],
|
|
37649
|
+
params: {},
|
|
37650
|
+
});
|
|
37651
|
+
}
|
|
37652
|
+
}
|
|
37653
|
+
async persistModel(queryPayload) {
|
|
37654
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37655
|
+
}
|
|
37656
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37657
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37658
|
+
}
|
|
37659
|
+
startSubscription() {
|
|
37660
|
+
return this.queryStreamController.subscribeRTE([
|
|
37661
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
37662
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
37663
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37664
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37665
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
37666
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37667
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37668
|
+
]);
|
|
37669
|
+
}
|
|
37670
|
+
notifyChange({ origin, loading, error }) {
|
|
37671
|
+
var _a, _b;
|
|
37672
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37673
|
+
if (!collection)
|
|
37674
|
+
return;
|
|
37675
|
+
const data = (_b = collection.data
|
|
37676
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
37677
|
+
.filter(isNonNullable)
|
|
37678
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
36983
37679
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36984
37680
|
return;
|
|
36985
37681
|
this.callback({
|
|
@@ -36993,7 +37689,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36993
37689
|
}
|
|
36994
37690
|
|
|
36995
37691
|
/* begin_public_function
|
|
36996
|
-
id: community.query.
|
|
37692
|
+
id: community.query.recommended_communities
|
|
36997
37693
|
*/
|
|
36998
37694
|
/**
|
|
36999
37695
|
* ```js
|
|
@@ -37013,65 +37709,70 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
37013
37709
|
*
|
|
37014
37710
|
* @category Community Live Collection
|
|
37015
37711
|
*/
|
|
37016
|
-
const
|
|
37712
|
+
const getRecommendedCommunities = (params, callback, config) => {
|
|
37017
37713
|
const { log, cache, userId } = getActiveClient();
|
|
37018
37714
|
if (!cache) {
|
|
37019
37715
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37020
37716
|
}
|
|
37021
37717
|
const timestamp = Date.now();
|
|
37022
|
-
log(`
|
|
37023
|
-
const
|
|
37024
|
-
const disposers =
|
|
37025
|
-
const cacheKey =
|
|
37718
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
37719
|
+
const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(params, callback);
|
|
37720
|
+
const disposers = recommendedCommunitiesLiveCollection.startSubscription();
|
|
37721
|
+
const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
|
|
37026
37722
|
disposers.push(() => dropFromCache(cacheKey));
|
|
37027
37723
|
return () => {
|
|
37028
|
-
log(`
|
|
37724
|
+
log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37029
37725
|
disposers.forEach(fn => fn());
|
|
37030
37726
|
};
|
|
37031
37727
|
};
|
|
37032
37728
|
/* end_public_function */
|
|
37033
37729
|
|
|
37034
|
-
|
|
37035
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
37036
|
-
* TODO: check if querybyIds is supported
|
|
37037
|
-
*/
|
|
37038
|
-
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
37730
|
+
class SemanticSearchCommunityPaginationController extends PaginationController {
|
|
37039
37731
|
async getRequest(queryParams, token) {
|
|
37040
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
37041
|
-
const
|
|
37042
|
-
|
|
37043
|
-
|
|
37732
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityMembershipStatus } = queryParams, params = __rest(queryParams, ["limit", "communityMembershipStatus"]);
|
|
37733
|
+
const baseOptions = {
|
|
37734
|
+
type: queryParams.limit ? 'pagination' : undefined,
|
|
37735
|
+
};
|
|
37736
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
37737
|
+
const { data: queryResponse } = await this.http.get(`/api/v1/semantic-search/communities`, {
|
|
37738
|
+
params: Object.assign(Object.assign({}, params), { filter: communityMembershipStatus !== null && communityMembershipStatus !== void 0 ? communityMembershipStatus : "all" /* AmityCommunityMemberStatusFilter.ALL */, options }),
|
|
37044
37739
|
});
|
|
37045
37740
|
return queryResponse;
|
|
37046
37741
|
}
|
|
37047
37742
|
}
|
|
37048
37743
|
|
|
37049
|
-
|
|
37744
|
+
function prepareSemanticCommunitiesReferenceId(response) {
|
|
37745
|
+
return response.communities.map(community => {
|
|
37746
|
+
const score = response.searchResult.find(result => result.communityId === community.communityId);
|
|
37747
|
+
return `${community.communityId}:${score}`;
|
|
37748
|
+
});
|
|
37749
|
+
}
|
|
37750
|
+
|
|
37751
|
+
class SemanticSearchCommunityQueryStreamController extends QueryStreamController {
|
|
37050
37752
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37051
37753
|
super(query, cacheKey);
|
|
37052
37754
|
this.notifyChange = notifyChange;
|
|
37053
37755
|
this.preparePayload = preparePayload;
|
|
37054
37756
|
}
|
|
37055
37757
|
async saveToMainDB(response) {
|
|
37056
|
-
const processedPayload =
|
|
37758
|
+
const processedPayload = this.preparePayload(response);
|
|
37057
37759
|
const client = getActiveClient();
|
|
37058
37760
|
const cachedAt = client.cache && Date.now();
|
|
37059
37761
|
if (client.cache) {
|
|
37060
37762
|
ingestInCache(processedPayload, { cachedAt });
|
|
37061
|
-
saveCommunityUsers(response.communities, response.communityUsers);
|
|
37062
37763
|
}
|
|
37063
37764
|
}
|
|
37064
37765
|
appendToQueryStream(response, direction, refresh = false) {
|
|
37065
37766
|
var _a, _b;
|
|
37066
37767
|
if (refresh) {
|
|
37067
37768
|
pushToCache(this.cacheKey, {
|
|
37068
|
-
data: response
|
|
37769
|
+
data: prepareSemanticCommunitiesReferenceId(response),
|
|
37069
37770
|
});
|
|
37070
37771
|
}
|
|
37071
37772
|
else {
|
|
37072
37773
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37073
37774
|
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
|
|
37775
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...prepareSemanticCommunitiesReferenceId(response)])] }));
|
|
37075
37776
|
}
|
|
37076
37777
|
}
|
|
37077
37778
|
reactor(action) {
|
|
@@ -37080,29 +37781,32 @@ class RecommendedCommunitiesQueryStreamController extends QueryStreamController
|
|
|
37080
37781
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37081
37782
|
if (!collection)
|
|
37082
37783
|
return;
|
|
37784
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
37083
37785
|
pushToCache(this.cacheKey, collection);
|
|
37084
37786
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37085
37787
|
};
|
|
37788
|
+
//
|
|
37086
37789
|
}
|
|
37087
37790
|
subscribeRTE(createSubscriber) {
|
|
37088
37791
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37089
37792
|
}
|
|
37090
37793
|
}
|
|
37091
37794
|
|
|
37092
|
-
var EnumCommunityActions
|
|
37795
|
+
var EnumCommunityActions;
|
|
37093
37796
|
(function (EnumCommunityActions) {
|
|
37797
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
37094
37798
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
37095
37799
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
37096
|
-
})(EnumCommunityActions
|
|
37800
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
37097
37801
|
|
|
37098
|
-
class
|
|
37802
|
+
class SemanticSearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
37099
37803
|
constructor(query, callback) {
|
|
37100
37804
|
const queryStreamId = hash(query);
|
|
37101
37805
|
const cacheKey = ['community', 'collection', queryStreamId];
|
|
37102
|
-
const paginationController = new
|
|
37806
|
+
const paginationController = new SemanticSearchCommunityPaginationController(query);
|
|
37103
37807
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37104
37808
|
this.query = query;
|
|
37105
|
-
this.queryStreamController = new
|
|
37809
|
+
this.queryStreamController = new SemanticSearchCommunityQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareSemanticSearchCommunityPayload);
|
|
37106
37810
|
this.callback = callback.bind(this);
|
|
37107
37811
|
this.loadPage({ initial: true });
|
|
37108
37812
|
}
|
|
@@ -37124,8 +37828,9 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37124
37828
|
}
|
|
37125
37829
|
startSubscription() {
|
|
37126
37830
|
return this.queryStreamController.subscribeRTE([
|
|
37127
|
-
{ fn:
|
|
37128
|
-
{ fn:
|
|
37831
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
37832
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
37833
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
37129
37834
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37130
37835
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37131
37836
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
@@ -37138,10 +37843,18 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37138
37843
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37139
37844
|
if (!collection)
|
|
37140
37845
|
return;
|
|
37141
|
-
const data = (_b = collection.data
|
|
37142
|
-
.map(
|
|
37846
|
+
const data = this.applyFilter((_b = collection.data
|
|
37847
|
+
.map(communityIdWithScore => {
|
|
37848
|
+
const [communityId, score] = communityIdWithScore.split(':');
|
|
37849
|
+
return {
|
|
37850
|
+
communityId,
|
|
37851
|
+
score: parseFloat(score),
|
|
37852
|
+
};
|
|
37853
|
+
})
|
|
37854
|
+
.sort((a, b) => b.score - a.score)
|
|
37855
|
+
.map(({ communityId }) => pullFromCache(['community', 'get', communityId]))
|
|
37143
37856
|
.filter(isNonNullable)
|
|
37144
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37857
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
37145
37858
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
37146
37859
|
return;
|
|
37147
37860
|
this.callback({
|
|
@@ -37152,76 +37865,87 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37152
37865
|
error,
|
|
37153
37866
|
});
|
|
37154
37867
|
}
|
|
37868
|
+
applyFilter(data) {
|
|
37869
|
+
const { userId } = getActiveClient();
|
|
37870
|
+
let communities = data;
|
|
37871
|
+
if (this.query.categoryIds) {
|
|
37872
|
+
communities = communities.filter(c => {
|
|
37873
|
+
var _a;
|
|
37874
|
+
return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.some((id) => {
|
|
37875
|
+
if (!this.query.categoryIds)
|
|
37876
|
+
return true;
|
|
37877
|
+
if (this.query.categoryIds.length === 0)
|
|
37878
|
+
return true;
|
|
37879
|
+
return this.query.categoryIds.includes(id);
|
|
37880
|
+
});
|
|
37881
|
+
});
|
|
37882
|
+
}
|
|
37883
|
+
if (this.query.tags) {
|
|
37884
|
+
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); }); });
|
|
37885
|
+
}
|
|
37886
|
+
if (this.query.communityMembershipStatus && userId) {
|
|
37887
|
+
communities = filterByCommunityMembership(communities, this.query.communityMembershipStatus, userId);
|
|
37888
|
+
}
|
|
37889
|
+
return communities;
|
|
37890
|
+
}
|
|
37155
37891
|
}
|
|
37156
37892
|
|
|
37157
|
-
/* begin_public_function
|
|
37158
|
-
id: community.query.recommended_communities
|
|
37159
|
-
*/
|
|
37160
37893
|
/**
|
|
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
|
-
* ```
|
|
37894
|
+
* search posts by semantic search
|
|
37169
37895
|
*
|
|
37170
|
-
*
|
|
37896
|
+
* @returns the associated pinned post(s)
|
|
37171
37897
|
*
|
|
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
|
|
37898
|
+
* @category Posts Live Collection
|
|
37175
37899
|
*
|
|
37176
|
-
* @category Community Live Collection
|
|
37177
37900
|
*/
|
|
37178
|
-
const
|
|
37179
|
-
const { log, cache
|
|
37901
|
+
const semanticSearchCommunities = (params, callback, config) => {
|
|
37902
|
+
const { log, cache } = getActiveClient();
|
|
37180
37903
|
if (!cache) {
|
|
37181
37904
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37182
37905
|
}
|
|
37183
37906
|
const timestamp = Date.now();
|
|
37184
|
-
log(`
|
|
37185
|
-
const
|
|
37186
|
-
const disposers =
|
|
37187
|
-
const cacheKey =
|
|
37907
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > listen`);
|
|
37908
|
+
const semanticSearchPostLiveCollection = new SemanticSearchCommunityLiveCollectionController(params, callback);
|
|
37909
|
+
const disposers = semanticSearchPostLiveCollection.startSubscription();
|
|
37910
|
+
const cacheKey = semanticSearchPostLiveCollection.getCacheKey();
|
|
37188
37911
|
disposers.push(() => dropFromCache(cacheKey));
|
|
37189
37912
|
return () => {
|
|
37190
|
-
log(`
|
|
37913
|
+
log(`semanticSearchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
37191
37914
|
disposers.forEach(fn => fn());
|
|
37192
37915
|
};
|
|
37193
|
-
};
|
|
37194
|
-
/* end_public_function */
|
|
37916
|
+
};
|
|
37195
37917
|
|
|
37196
|
-
|
|
37918
|
+
/**
|
|
37919
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
37920
|
+
* TODO: check if querybyIds is supported
|
|
37921
|
+
*/
|
|
37922
|
+
class JoinRequestListPaginationController extends PaginationController {
|
|
37197
37923
|
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 }),
|
|
37924
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
|
|
37925
|
+
const options = token ? { token } : { limit };
|
|
37926
|
+
const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
37927
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
|
|
37928
|
+
params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
|
|
37205
37929
|
});
|
|
37206
37930
|
return queryResponse;
|
|
37207
37931
|
}
|
|
37208
37932
|
}
|
|
37209
37933
|
|
|
37210
|
-
|
|
37211
|
-
|
|
37212
|
-
|
|
37213
|
-
|
|
37214
|
-
|
|
37215
|
-
}
|
|
37934
|
+
var EnumJoinRequestAction;
|
|
37935
|
+
(function (EnumJoinRequestAction) {
|
|
37936
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
37937
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
37938
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
37939
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
37216
37940
|
|
|
37217
|
-
class
|
|
37941
|
+
class JoinRequestListQueryStreamController extends QueryStreamController {
|
|
37218
37942
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37219
37943
|
super(query, cacheKey);
|
|
37220
37944
|
this.notifyChange = notifyChange;
|
|
37221
37945
|
this.preparePayload = preparePayload;
|
|
37222
37946
|
}
|
|
37223
37947
|
async saveToMainDB(response) {
|
|
37224
|
-
const processedPayload = this.preparePayload(response);
|
|
37948
|
+
const processedPayload = await this.preparePayload(response);
|
|
37225
37949
|
const client = getActiveClient();
|
|
37226
37950
|
const cachedAt = client.cache && Date.now();
|
|
37227
37951
|
if (client.cache) {
|
|
@@ -37232,47 +37956,59 @@ class SemanticSearchCommunityQueryStreamController extends QueryStreamController
|
|
|
37232
37956
|
var _a, _b;
|
|
37233
37957
|
if (refresh) {
|
|
37234
37958
|
pushToCache(this.cacheKey, {
|
|
37235
|
-
data:
|
|
37959
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37236
37960
|
});
|
|
37237
37961
|
}
|
|
37238
37962
|
else {
|
|
37239
37963
|
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: [
|
|
37964
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37965
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
37966
|
+
...new Set([
|
|
37967
|
+
...joinRequests,
|
|
37968
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37969
|
+
]),
|
|
37970
|
+
] }));
|
|
37242
37971
|
}
|
|
37243
37972
|
}
|
|
37244
37973
|
reactor(action) {
|
|
37245
|
-
return (
|
|
37974
|
+
return (joinRequest) => {
|
|
37246
37975
|
var _a;
|
|
37247
37976
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37248
37977
|
if (!collection)
|
|
37249
37978
|
return;
|
|
37250
|
-
|
|
37979
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
37980
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
37981
|
+
if (!isExist)
|
|
37982
|
+
return;
|
|
37983
|
+
}
|
|
37984
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
37985
|
+
collection.data = [
|
|
37986
|
+
...new Set([
|
|
37987
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
37988
|
+
...collection.data,
|
|
37989
|
+
]),
|
|
37990
|
+
];
|
|
37991
|
+
}
|
|
37992
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
37993
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
37994
|
+
}
|
|
37251
37995
|
pushToCache(this.cacheKey, collection);
|
|
37252
37996
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37253
37997
|
};
|
|
37254
|
-
//
|
|
37255
37998
|
}
|
|
37256
37999
|
subscribeRTE(createSubscriber) {
|
|
37257
38000
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37258
38001
|
}
|
|
37259
38002
|
}
|
|
37260
38003
|
|
|
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 {
|
|
38004
|
+
class JoinRequestListLiveCollectionController extends LiveCollectionController {
|
|
37269
38005
|
constructor(query, callback) {
|
|
37270
38006
|
const queryStreamId = hash(query);
|
|
37271
|
-
const cacheKey = ['
|
|
37272
|
-
const paginationController = new
|
|
38007
|
+
const cacheKey = ['joinRequestList', 'collection', queryStreamId];
|
|
38008
|
+
const paginationController = new JoinRequestListPaginationController(query);
|
|
37273
38009
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37274
38010
|
this.query = query;
|
|
37275
|
-
this.queryStreamController = new
|
|
38011
|
+
this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
37276
38012
|
this.callback = callback.bind(this);
|
|
37277
38013
|
this.loadPage({ initial: true });
|
|
37278
38014
|
}
|
|
@@ -37282,7 +38018,7 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37282
38018
|
if (!collection) {
|
|
37283
38019
|
pushToCache(this.cacheKey, {
|
|
37284
38020
|
data: [],
|
|
37285
|
-
params:
|
|
38021
|
+
params: this.query,
|
|
37286
38022
|
});
|
|
37287
38023
|
}
|
|
37288
38024
|
}
|
|
@@ -37290,37 +38026,26 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37290
38026
|
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37291
38027
|
}
|
|
37292
38028
|
persistQueryStream({ response, direction, refresh, }) {
|
|
37293
|
-
|
|
38029
|
+
const joinRequestResponse = response;
|
|
38030
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
37294
38031
|
}
|
|
37295
38032
|
startSubscription() {
|
|
37296
38033
|
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 },
|
|
38034
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
38035
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
38036
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
37305
38037
|
]);
|
|
37306
38038
|
}
|
|
37307
38039
|
notifyChange({ origin, loading, error }) {
|
|
37308
|
-
var _a
|
|
38040
|
+
var _a;
|
|
37309
38041
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37310
38042
|
if (!collection)
|
|
37311
38043
|
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]))
|
|
38044
|
+
const data = this.applyFilter(collection.data
|
|
38045
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
37322
38046
|
.filter(isNonNullable)
|
|
37323
|
-
.map(({ data }) => data)
|
|
38047
|
+
.map(({ data }) => data)
|
|
38048
|
+
.map(joinRequestLinkedObject));
|
|
37324
38049
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
37325
38050
|
return;
|
|
37326
38051
|
this.callback({
|
|
@@ -37332,54 +38057,57 @@ class SemanticSearchCommunityLiveCollectionController extends LiveCollectionCont
|
|
|
37332
38057
|
});
|
|
37333
38058
|
}
|
|
37334
38059
|
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); }); });
|
|
38060
|
+
let joinRequest = data;
|
|
38061
|
+
if (this.query.communityIds && this.query.communityIds.length > 0) {
|
|
38062
|
+
joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
|
|
37351
38063
|
}
|
|
37352
|
-
|
|
37353
|
-
|
|
37354
|
-
|
|
37355
|
-
|
|
38064
|
+
const sortFn = (() => {
|
|
38065
|
+
switch (this.query.sortBy) {
|
|
38066
|
+
case 'firstCreated':
|
|
38067
|
+
return sortByFirstCreated;
|
|
38068
|
+
case 'lastCreated':
|
|
38069
|
+
return sortByLastCreated;
|
|
38070
|
+
default:
|
|
38071
|
+
return sortByLastCreated;
|
|
38072
|
+
}
|
|
38073
|
+
})();
|
|
38074
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
38075
|
+
return joinRequest;
|
|
37356
38076
|
}
|
|
37357
38077
|
}
|
|
37358
38078
|
|
|
38079
|
+
/* begin_public_function
|
|
38080
|
+
id: community.getJoinRequestList
|
|
38081
|
+
*/
|
|
37359
38082
|
/**
|
|
37360
|
-
*
|
|
38083
|
+
* Get Join Requests
|
|
37361
38084
|
*
|
|
37362
|
-
* @
|
|
38085
|
+
* @param params the query parameters
|
|
38086
|
+
* @param callback the callback to be called when the join request are updated
|
|
38087
|
+
* @returns joinRequest[]
|
|
37363
38088
|
*
|
|
37364
|
-
* @category
|
|
38089
|
+
* @category joinRequestList Live Collection
|
|
37365
38090
|
*
|
|
37366
38091
|
*/
|
|
37367
|
-
const
|
|
38092
|
+
const getJoinRequestList = (params, callback, config) => {
|
|
37368
38093
|
const { log, cache } = getActiveClient();
|
|
37369
38094
|
if (!cache) {
|
|
37370
38095
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
37371
38096
|
}
|
|
37372
38097
|
const timestamp = Date.now();
|
|
37373
|
-
log(`
|
|
37374
|
-
const
|
|
37375
|
-
const disposers =
|
|
37376
|
-
const cacheKey =
|
|
37377
|
-
disposers.push(() =>
|
|
38098
|
+
log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
|
|
38099
|
+
const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
|
|
38100
|
+
const disposers = joinRequestListLiveCollection.startSubscription();
|
|
38101
|
+
const cacheKey = joinRequestListLiveCollection.getCacheKey();
|
|
38102
|
+
disposers.push(() => {
|
|
38103
|
+
dropFromCache(cacheKey);
|
|
38104
|
+
});
|
|
37378
38105
|
return () => {
|
|
37379
|
-
log(`
|
|
38106
|
+
log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
|
|
37380
38107
|
disposers.forEach(fn => fn());
|
|
37381
38108
|
};
|
|
37382
|
-
};
|
|
38109
|
+
};
|
|
38110
|
+
/* end_public_function */
|
|
37383
38111
|
|
|
37384
38112
|
var AmityCommunityMemberStatusFilter;
|
|
37385
38113
|
(function (AmityCommunityMemberStatusFilter) {
|
|
@@ -37551,6 +38279,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
37551
38279
|
getTrendingCommunities: getTrendingCommunities,
|
|
37552
38280
|
getRecommendedCommunities: getRecommendedCommunities,
|
|
37553
38281
|
semanticSearchCommunities: semanticSearchCommunities,
|
|
38282
|
+
getJoinRequestList: getJoinRequestList,
|
|
37554
38283
|
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
37555
38284
|
});
|
|
37556
38285
|
|
|
@@ -39791,7 +40520,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39791
40520
|
const client = getActiveClient();
|
|
39792
40521
|
const cachedAt = client.cache && Date.now();
|
|
39793
40522
|
if (client.cache) {
|
|
39794
|
-
|
|
40523
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
40524
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39795
40525
|
}
|
|
39796
40526
|
}
|
|
39797
40527
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -39920,7 +40650,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39920
40650
|
const client = getActiveClient();
|
|
39921
40651
|
const cachedAt = client.cache && Date.now();
|
|
39922
40652
|
if (client.cache) {
|
|
39923
|
-
|
|
40653
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
40654
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39924
40655
|
}
|
|
39925
40656
|
}
|
|
39926
40657
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -43274,4 +44005,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
43274
44005
|
getMyCommunityInvitations: getMyCommunityInvitations
|
|
43275
44006
|
});
|
|
43276
44007
|
|
|
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 };
|
|
44008
|
+
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 };
|