@amityco/ts-sdk 7.4.1-e8631ca7.0 → 7.4.1-fd0f791a.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 +28 -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/index.d.ts +1 -0
- package/dist/@types/index.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/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/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/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 +897 -389
- package/dist/index.esm.js +760 -252
- 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/dist/utils/tests/dummy/comment.d.ts +1 -1
- 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 +38 -2
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunity.ts +8 -0
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +51 -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/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/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,296 @@ 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
|
+
const client = getActiveClient();
|
|
23740
|
+
client.log('community/joinRequest', communityId);
|
|
23741
|
+
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
23742
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
23743
|
+
const cachedAt = client.cache && Date.now();
|
|
23744
|
+
if (client.cache)
|
|
23745
|
+
ingestInCache(data, { cachedAt });
|
|
23746
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
23747
|
+
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
23748
|
+
? "success" /* JoinResultStatusEnum.Success */
|
|
23749
|
+
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
23750
|
+
return status === "success" /* JoinResultStatusEnum.Success */
|
|
23751
|
+
? { status }
|
|
23752
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
23753
|
+
};
|
|
23754
|
+
/* end_public_function */
|
|
23677
23755
|
|
|
23678
23756
|
class PaginationController {
|
|
23679
23757
|
constructor(queryParams) {
|
|
@@ -23720,12 +23798,18 @@ class PaginationController {
|
|
|
23720
23798
|
}
|
|
23721
23799
|
}
|
|
23722
23800
|
|
|
23723
|
-
|
|
23801
|
+
/**
|
|
23802
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
23803
|
+
* TODO: check if querybyIds is supported
|
|
23804
|
+
*/
|
|
23805
|
+
class JoinRequestsPaginationController extends PaginationController {
|
|
23724
23806
|
async getRequest(queryParams, token) {
|
|
23725
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23807
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
|
|
23726
23808
|
const options = token ? { token } : { limit };
|
|
23727
|
-
const { data } = await this.http.get(
|
|
23728
|
-
|
|
23809
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
|
|
23810
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
23811
|
+
});
|
|
23812
|
+
return queryResponse;
|
|
23729
23813
|
}
|
|
23730
23814
|
}
|
|
23731
23815
|
|
|
@@ -23736,7 +23820,14 @@ class QueryStreamController {
|
|
|
23736
23820
|
}
|
|
23737
23821
|
}
|
|
23738
23822
|
|
|
23739
|
-
|
|
23823
|
+
var EnumJoinRequestAction;
|
|
23824
|
+
(function (EnumJoinRequestAction) {
|
|
23825
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
23826
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
23827
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
23828
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
23829
|
+
|
|
23830
|
+
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
23740
23831
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23741
23832
|
super(query, cacheKey);
|
|
23742
23833
|
this.notifyChange = notifyChange;
|
|
@@ -23754,38 +23845,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
|
|
|
23754
23845
|
var _a, _b;
|
|
23755
23846
|
if (refresh) {
|
|
23756
23847
|
pushToCache(this.cacheKey, {
|
|
23757
|
-
data: response.
|
|
23848
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23758
23849
|
});
|
|
23759
23850
|
}
|
|
23760
23851
|
else {
|
|
23761
23852
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23762
|
-
const
|
|
23853
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23763
23854
|
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
23764
|
-
...new Set([
|
|
23855
|
+
...new Set([
|
|
23856
|
+
...joinRequests,
|
|
23857
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
23858
|
+
]),
|
|
23765
23859
|
] }));
|
|
23766
23860
|
}
|
|
23767
23861
|
}
|
|
23768
23862
|
reactor(action) {
|
|
23769
|
-
return (
|
|
23863
|
+
return (joinRequest) => {
|
|
23770
23864
|
var _a;
|
|
23771
23865
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23772
23866
|
if (!collection)
|
|
23773
23867
|
return;
|
|
23774
|
-
if (action ===
|
|
23775
|
-
const isExist = collection.data.find(id => id ===
|
|
23868
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
23869
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
23776
23870
|
if (!isExist)
|
|
23777
23871
|
return;
|
|
23778
23872
|
}
|
|
23779
|
-
if (action ===
|
|
23873
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
23780
23874
|
collection.data = [
|
|
23781
23875
|
...new Set([
|
|
23782
|
-
...
|
|
23876
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
23783
23877
|
...collection.data,
|
|
23784
23878
|
]),
|
|
23785
23879
|
];
|
|
23786
23880
|
}
|
|
23787
|
-
if (action ===
|
|
23788
|
-
collection.data = collection.data.filter(id => id !==
|
|
23881
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
23882
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
23789
23883
|
}
|
|
23790
23884
|
pushToCache(this.cacheKey, collection);
|
|
23791
23885
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -23931,6 +24025,483 @@ class LiveCollectionController {
|
|
|
23931
24025
|
}
|
|
23932
24026
|
}
|
|
23933
24027
|
|
|
24028
|
+
/**
|
|
24029
|
+
* ```js
|
|
24030
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
24031
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
24032
|
+
* // ...
|
|
24033
|
+
* })
|
|
24034
|
+
* ```
|
|
24035
|
+
*
|
|
24036
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24037
|
+
*
|
|
24038
|
+
* @param callback The function to call when the event was fired
|
|
24039
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24040
|
+
*
|
|
24041
|
+
* @category JoinRequest Events
|
|
24042
|
+
*/
|
|
24043
|
+
const onJoinRequestCreated = (callback) => {
|
|
24044
|
+
const client = getActiveClient();
|
|
24045
|
+
const disposers = [
|
|
24046
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
|
|
24047
|
+
];
|
|
24048
|
+
return () => {
|
|
24049
|
+
disposers.forEach(fn => fn());
|
|
24050
|
+
};
|
|
24051
|
+
};
|
|
24052
|
+
|
|
24053
|
+
/**
|
|
24054
|
+
* ```js
|
|
24055
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
24056
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
24057
|
+
* // ...
|
|
24058
|
+
* })
|
|
24059
|
+
* ```
|
|
24060
|
+
*
|
|
24061
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24062
|
+
*
|
|
24063
|
+
* @param callback The function to call when the event was fired
|
|
24064
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24065
|
+
*
|
|
24066
|
+
* @category JoinRequest Events
|
|
24067
|
+
*/
|
|
24068
|
+
const onJoinRequestUpdated = (callback) => {
|
|
24069
|
+
const client = getActiveClient();
|
|
24070
|
+
const disposers = [
|
|
24071
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
|
|
24072
|
+
];
|
|
24073
|
+
return () => {
|
|
24074
|
+
disposers.forEach(fn => fn());
|
|
24075
|
+
};
|
|
24076
|
+
};
|
|
24077
|
+
|
|
24078
|
+
/**
|
|
24079
|
+
* ```js
|
|
24080
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
24081
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
24082
|
+
* // ...
|
|
24083
|
+
* })
|
|
24084
|
+
* ```
|
|
24085
|
+
*
|
|
24086
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
24087
|
+
*
|
|
24088
|
+
* @param callback The function to call when the event was fired
|
|
24089
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24090
|
+
*
|
|
24091
|
+
* @category JoinRequest Events
|
|
24092
|
+
*/
|
|
24093
|
+
const onJoinRequestDeleted = (callback) => {
|
|
24094
|
+
const client = getActiveClient();
|
|
24095
|
+
const disposers = [
|
|
24096
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
|
|
24097
|
+
];
|
|
24098
|
+
return () => {
|
|
24099
|
+
disposers.forEach(fn => fn());
|
|
24100
|
+
};
|
|
24101
|
+
};
|
|
24102
|
+
|
|
24103
|
+
class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
24104
|
+
constructor(query, callback) {
|
|
24105
|
+
const queryStreamId = hash(query);
|
|
24106
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
24107
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
24108
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24109
|
+
this.query = query;
|
|
24110
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
24111
|
+
this.callback = callback.bind(this);
|
|
24112
|
+
this.loadPage({ initial: true });
|
|
24113
|
+
}
|
|
24114
|
+
setup() {
|
|
24115
|
+
var _a;
|
|
24116
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24117
|
+
if (!collection) {
|
|
24118
|
+
pushToCache(this.cacheKey, {
|
|
24119
|
+
data: [],
|
|
24120
|
+
params: this.query,
|
|
24121
|
+
});
|
|
24122
|
+
}
|
|
24123
|
+
}
|
|
24124
|
+
async persistModel(queryPayload) {
|
|
24125
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24126
|
+
}
|
|
24127
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24128
|
+
const joinRequestResponse = response;
|
|
24129
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
24130
|
+
}
|
|
24131
|
+
startSubscription() {
|
|
24132
|
+
return this.queryStreamController.subscribeRTE([
|
|
24133
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
24134
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
24135
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
24136
|
+
]);
|
|
24137
|
+
}
|
|
24138
|
+
notifyChange({ origin, loading, error }) {
|
|
24139
|
+
var _a;
|
|
24140
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24141
|
+
if (!collection)
|
|
24142
|
+
return;
|
|
24143
|
+
const data = this.applyFilter(collection.data
|
|
24144
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
24145
|
+
.filter(isNonNullable)
|
|
24146
|
+
.map(({ data }) => data)
|
|
24147
|
+
.map(joinRequestLinkedObject));
|
|
24148
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24149
|
+
return;
|
|
24150
|
+
this.callback({
|
|
24151
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24152
|
+
data,
|
|
24153
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24154
|
+
loading,
|
|
24155
|
+
error,
|
|
24156
|
+
});
|
|
24157
|
+
}
|
|
24158
|
+
applyFilter(data) {
|
|
24159
|
+
let joinRequest = data;
|
|
24160
|
+
if (this.query.status) {
|
|
24161
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
24162
|
+
}
|
|
24163
|
+
const sortFn = (() => {
|
|
24164
|
+
switch (this.query.sortBy) {
|
|
24165
|
+
case 'firstCreated':
|
|
24166
|
+
return sortByFirstCreated;
|
|
24167
|
+
case 'lastCreated':
|
|
24168
|
+
return sortByLastCreated;
|
|
24169
|
+
default:
|
|
24170
|
+
return sortByLastCreated;
|
|
24171
|
+
}
|
|
24172
|
+
})();
|
|
24173
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
24174
|
+
return joinRequest;
|
|
24175
|
+
}
|
|
24176
|
+
}
|
|
24177
|
+
|
|
24178
|
+
/**
|
|
24179
|
+
* Get Join Requests
|
|
24180
|
+
*
|
|
24181
|
+
* @param params the query parameters
|
|
24182
|
+
* @param callback the callback to be called when the join request are updated
|
|
24183
|
+
* @returns joinRequests
|
|
24184
|
+
*
|
|
24185
|
+
* @category joinRequest Live Collection
|
|
24186
|
+
*
|
|
24187
|
+
*/
|
|
24188
|
+
const getJoinRequests = (params, callback, config) => {
|
|
24189
|
+
const { log, cache } = getActiveClient();
|
|
24190
|
+
if (!cache) {
|
|
24191
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24192
|
+
}
|
|
24193
|
+
const timestamp = Date.now();
|
|
24194
|
+
log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
|
|
24195
|
+
const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
|
|
24196
|
+
const disposers = joinRequestLiveCollection.startSubscription();
|
|
24197
|
+
const cacheKey = joinRequestLiveCollection.getCacheKey();
|
|
24198
|
+
disposers.push(() => {
|
|
24199
|
+
dropFromCache(cacheKey);
|
|
24200
|
+
});
|
|
24201
|
+
return () => {
|
|
24202
|
+
log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
|
|
24203
|
+
disposers.forEach(fn => fn());
|
|
24204
|
+
};
|
|
24205
|
+
};
|
|
24206
|
+
|
|
24207
|
+
const convertRawInvitationToInternalInvitation = (rawInvitation) => {
|
|
24208
|
+
return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
|
|
24209
|
+
};
|
|
24210
|
+
|
|
24211
|
+
const prepareInvitationPayload = (rawPayload) => {
|
|
24212
|
+
return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
|
|
24213
|
+
};
|
|
24214
|
+
|
|
24215
|
+
/* begin_public_function
|
|
24216
|
+
id: invitation.createInvitations
|
|
24217
|
+
*/
|
|
24218
|
+
/**
|
|
24219
|
+
* ```js
|
|
24220
|
+
* import { createInvitations } from '@amityco/ts-sdk'
|
|
24221
|
+
* const created = await createInvitations({
|
|
24222
|
+
* type: string,
|
|
24223
|
+
* targetType: string,
|
|
24224
|
+
* targetId: string,
|
|
24225
|
+
* userIds: string[]
|
|
24226
|
+
* }))
|
|
24227
|
+
* ```
|
|
24228
|
+
*
|
|
24229
|
+
* Creates an {@link Amity.Invitation}
|
|
24230
|
+
*
|
|
24231
|
+
* @param bundle The data necessary to create a new {@link Amity.Invitation}
|
|
24232
|
+
* @returns The newly created {@link Amity.Invitation}
|
|
24233
|
+
*
|
|
24234
|
+
* @category Invitation API
|
|
24235
|
+
* @async
|
|
24236
|
+
*/
|
|
24237
|
+
const createInvitations = async (bundle) => {
|
|
24238
|
+
const client = getActiveClient();
|
|
24239
|
+
client.log('invitation/createInvitations', bundle);
|
|
24240
|
+
const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
|
|
24241
|
+
const data = prepareInvitationPayload(payload);
|
|
24242
|
+
const cachedAt = client.cache && Date.now();
|
|
24243
|
+
if (client.cache)
|
|
24244
|
+
ingestInCache(data, { cachedAt });
|
|
24245
|
+
fireEvent('local.invitation.created', data.invitations);
|
|
24246
|
+
return {
|
|
24247
|
+
data: data.invitations,
|
|
24248
|
+
cachedAt,
|
|
24249
|
+
};
|
|
24250
|
+
};
|
|
24251
|
+
/* end_public_function */
|
|
24252
|
+
|
|
24253
|
+
/* begin_public_function
|
|
24254
|
+
id: invitation.accept
|
|
24255
|
+
*/
|
|
24256
|
+
/**
|
|
24257
|
+
* ```js
|
|
24258
|
+
* import { acceptInvitation } from '@amityco/ts-sdk'
|
|
24259
|
+
* const isAccepted = await acceptInvitation(invitationId)
|
|
24260
|
+
* ```
|
|
24261
|
+
*
|
|
24262
|
+
* Accepts a {@link Amity.Invitation} object
|
|
24263
|
+
*
|
|
24264
|
+
* @param invitationId the {@link Amity.Invitation} to accept
|
|
24265
|
+
* @returns A success boolean if the {@link Amity.Invitation} was accepted
|
|
24266
|
+
*
|
|
24267
|
+
* @category Invitation API
|
|
24268
|
+
* @async
|
|
24269
|
+
*/
|
|
24270
|
+
const acceptInvitation = async (invitationId) => {
|
|
24271
|
+
var _a;
|
|
24272
|
+
const client = getActiveClient();
|
|
24273
|
+
client.log('invitation/acceptInvitation', invitationId);
|
|
24274
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
|
|
24275
|
+
const invitation = (_a = pullFromCache([
|
|
24276
|
+
'invitation',
|
|
24277
|
+
'get',
|
|
24278
|
+
invitationId,
|
|
24279
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24280
|
+
if (invitation) {
|
|
24281
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
|
|
24282
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24283
|
+
}
|
|
24284
|
+
return data.success;
|
|
24285
|
+
};
|
|
24286
|
+
/* end_public_function */
|
|
24287
|
+
|
|
24288
|
+
/* begin_public_function
|
|
24289
|
+
id: invitation.reject
|
|
24290
|
+
*/
|
|
24291
|
+
/**
|
|
24292
|
+
* ```js
|
|
24293
|
+
* import { rejectInvitation } from '@amityco/ts-sdk'
|
|
24294
|
+
* const isRejected = await rejectInvitation(invitationId)
|
|
24295
|
+
* ```
|
|
24296
|
+
*
|
|
24297
|
+
* Rejects a {@link Amity.Invitation} object
|
|
24298
|
+
*
|
|
24299
|
+
* @param invitationId the {@link Amity.Invitation} to reject
|
|
24300
|
+
* @returns A success boolean if the {@link Amity.Invitation} was rejected
|
|
24301
|
+
*
|
|
24302
|
+
* @category Invitation API
|
|
24303
|
+
* @async
|
|
24304
|
+
*/
|
|
24305
|
+
const rejectInvitation = async (invitationId) => {
|
|
24306
|
+
var _a;
|
|
24307
|
+
const client = getActiveClient();
|
|
24308
|
+
client.log('invitation/rejectInvitation', invitationId);
|
|
24309
|
+
const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
|
|
24310
|
+
const invitation = (_a = pullFromCache([
|
|
24311
|
+
'invitation',
|
|
24312
|
+
'get',
|
|
24313
|
+
invitationId,
|
|
24314
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24315
|
+
if (invitation) {
|
|
24316
|
+
upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
|
|
24317
|
+
fireEvent('local.invitation.updated', [invitation]);
|
|
24318
|
+
}
|
|
24319
|
+
return data.success;
|
|
24320
|
+
};
|
|
24321
|
+
/* end_public_function */
|
|
24322
|
+
|
|
24323
|
+
/* begin_public_function
|
|
24324
|
+
id: invitation.cancel
|
|
24325
|
+
*/
|
|
24326
|
+
/**
|
|
24327
|
+
* ```js
|
|
24328
|
+
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
24329
|
+
* const isCanceled = await cancelInvitation(invitationId)
|
|
24330
|
+
* ```
|
|
24331
|
+
*
|
|
24332
|
+
* Cancels a {@link Amity.Invitation} object
|
|
24333
|
+
*
|
|
24334
|
+
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
24335
|
+
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
24336
|
+
*
|
|
24337
|
+
* @category Invitation API
|
|
24338
|
+
* @async
|
|
24339
|
+
*/
|
|
24340
|
+
const cancelInvitation = async (invitationId) => {
|
|
24341
|
+
var _a;
|
|
24342
|
+
const client = getActiveClient();
|
|
24343
|
+
client.log('invitation/cancelInvitation', invitationId);
|
|
24344
|
+
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
24345
|
+
const invitation = (_a = pullFromCache([
|
|
24346
|
+
'invitation',
|
|
24347
|
+
'get',
|
|
24348
|
+
invitationId,
|
|
24349
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24350
|
+
if (invitation) {
|
|
24351
|
+
dropFromCache(['invitation', 'get', invitationId]);
|
|
24352
|
+
fireEvent('local.invitation.deleted', [invitation]);
|
|
24353
|
+
}
|
|
24354
|
+
return data.success;
|
|
24355
|
+
};
|
|
24356
|
+
/* end_public_function */
|
|
24357
|
+
|
|
24358
|
+
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
24359
|
+
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
24360
|
+
};
|
|
24361
|
+
|
|
24362
|
+
const invitationLinkedObject = (invitation) => {
|
|
24363
|
+
return Object.assign(Object.assign({}, invitation), { get user() {
|
|
24364
|
+
const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
|
|
24365
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24366
|
+
return userLinkedObject(cacheData.data);
|
|
24367
|
+
return undefined;
|
|
24368
|
+
},
|
|
24369
|
+
get createdBy() {
|
|
24370
|
+
const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
|
|
24371
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24372
|
+
return userLinkedObject(cacheData.data);
|
|
24373
|
+
return undefined;
|
|
24374
|
+
},
|
|
24375
|
+
get target() {
|
|
24376
|
+
if (invitation.targetType === 'community') {
|
|
24377
|
+
const cacheData = pullFromCache([
|
|
24378
|
+
'community',
|
|
24379
|
+
'get',
|
|
24380
|
+
invitation.targetId,
|
|
24381
|
+
]);
|
|
24382
|
+
if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
|
|
24383
|
+
return cacheData.data;
|
|
24384
|
+
return undefined;
|
|
24385
|
+
}
|
|
24386
|
+
return undefined;
|
|
24387
|
+
}, accept: async () => {
|
|
24388
|
+
await acceptInvitation(invitation._id);
|
|
24389
|
+
}, reject: async () => {
|
|
24390
|
+
await rejectInvitation(invitation._id);
|
|
24391
|
+
}, cancel: async () => {
|
|
24392
|
+
await cancelInvitation(invitation._id);
|
|
24393
|
+
} });
|
|
24394
|
+
};
|
|
24395
|
+
|
|
24396
|
+
/* begin_public_function
|
|
24397
|
+
id: invitation.get
|
|
24398
|
+
*/
|
|
24399
|
+
/**
|
|
24400
|
+
* ```js
|
|
24401
|
+
* import { getInvitation } from '@amityco/ts-sdk'
|
|
24402
|
+
* const { invitation } = await getInvitation(targetType, targetId)
|
|
24403
|
+
* ```
|
|
24404
|
+
*
|
|
24405
|
+
* Get a {@link Amity.Invitation} object
|
|
24406
|
+
*
|
|
24407
|
+
* @param targetType The type of the target of the {@link Amity.Invitation}
|
|
24408
|
+
* @param targetId The ID of the target of the {@link Amity.Invitation}
|
|
24409
|
+
* @returns A {@link Amity.Invitation} object
|
|
24410
|
+
*
|
|
24411
|
+
* @category Invitation API
|
|
24412
|
+
* @async
|
|
24413
|
+
*/
|
|
24414
|
+
const getInvitation = async (targetType, targetId) => {
|
|
24415
|
+
const client = getActiveClient();
|
|
24416
|
+
client.log('invitation/getInvitation', targetType, targetId);
|
|
24417
|
+
const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
|
|
24418
|
+
const data = prepareMyInvitationsPayload(payload);
|
|
24419
|
+
const cachedAt = client.cache && Date.now();
|
|
24420
|
+
if (client.cache)
|
|
24421
|
+
ingestInCache(data, { cachedAt });
|
|
24422
|
+
return {
|
|
24423
|
+
data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
|
|
24424
|
+
cachedAt,
|
|
24425
|
+
};
|
|
24426
|
+
};
|
|
24427
|
+
/* end_public_function */
|
|
24428
|
+
|
|
24429
|
+
var InvitationActionsEnum;
|
|
24430
|
+
(function (InvitationActionsEnum) {
|
|
24431
|
+
InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
|
|
24432
|
+
InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
|
|
24433
|
+
InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
|
|
24434
|
+
})(InvitationActionsEnum || (InvitationActionsEnum = {}));
|
|
24435
|
+
|
|
24436
|
+
class InvitationsPaginationController extends PaginationController {
|
|
24437
|
+
async getRequest(queryParams, token) {
|
|
24438
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
24439
|
+
const options = token ? { token } : { limit };
|
|
24440
|
+
const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
|
|
24441
|
+
return data;
|
|
24442
|
+
}
|
|
24443
|
+
}
|
|
24444
|
+
|
|
24445
|
+
class InvitationsQueryStreamController extends QueryStreamController {
|
|
24446
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24447
|
+
super(query, cacheKey);
|
|
24448
|
+
this.notifyChange = notifyChange;
|
|
24449
|
+
this.preparePayload = preparePayload;
|
|
24450
|
+
}
|
|
24451
|
+
async saveToMainDB(response) {
|
|
24452
|
+
const processedPayload = await this.preparePayload(response);
|
|
24453
|
+
const client = getActiveClient();
|
|
24454
|
+
const cachedAt = client.cache && Date.now();
|
|
24455
|
+
if (client.cache) {
|
|
24456
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
24457
|
+
}
|
|
24458
|
+
}
|
|
24459
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
24460
|
+
var _a, _b;
|
|
24461
|
+
if (refresh) {
|
|
24462
|
+
pushToCache(this.cacheKey, {
|
|
24463
|
+
data: response.invitations.map(getResolver('invitation')),
|
|
24464
|
+
});
|
|
24465
|
+
}
|
|
24466
|
+
else {
|
|
24467
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24468
|
+
const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24469
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
24470
|
+
...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
|
|
24471
|
+
] }));
|
|
24472
|
+
}
|
|
24473
|
+
}
|
|
24474
|
+
reactor(action) {
|
|
24475
|
+
return (invitations) => {
|
|
24476
|
+
var _a;
|
|
24477
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24478
|
+
if (!collection)
|
|
24479
|
+
return;
|
|
24480
|
+
if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
|
|
24481
|
+
const isExist = collection.data.find(id => id === invitations[0].invitationId);
|
|
24482
|
+
if (!isExist)
|
|
24483
|
+
return;
|
|
24484
|
+
}
|
|
24485
|
+
if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
|
|
24486
|
+
collection.data = [
|
|
24487
|
+
...new Set([
|
|
24488
|
+
...invitations.map(invitation => invitation.invitationId),
|
|
24489
|
+
...collection.data,
|
|
24490
|
+
]),
|
|
24491
|
+
];
|
|
24492
|
+
}
|
|
24493
|
+
if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
|
|
24494
|
+
collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
|
|
24495
|
+
}
|
|
24496
|
+
pushToCache(this.cacheKey, collection);
|
|
24497
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24498
|
+
};
|
|
24499
|
+
}
|
|
24500
|
+
subscribeRTE(createSubscriber) {
|
|
24501
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24502
|
+
}
|
|
24503
|
+
}
|
|
24504
|
+
|
|
23934
24505
|
/**
|
|
23935
24506
|
* ```js
|
|
23936
24507
|
* import { onLocalInvitationCreated } from '@amityco/ts-sdk'
|
|
@@ -24139,6 +24710,13 @@ const communityLinkedObject = (community) => {
|
|
|
24139
24710
|
}, getInvitation: async () => {
|
|
24140
24711
|
const { data } = await getInvitation('community', community.communityId);
|
|
24141
24712
|
return data;
|
|
24713
|
+
}, join: async () => {
|
|
24714
|
+
return joinRequest(community.communityId);
|
|
24715
|
+
}, getJoinRequests: (params, callback) => {
|
|
24716
|
+
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
24717
|
+
}, getMyJoinRequest: async () => {
|
|
24718
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
24719
|
+
return data;
|
|
24142
24720
|
} });
|
|
24143
24721
|
};
|
|
24144
24722
|
|
|
@@ -24158,6 +24736,7 @@ const LinkedObject = {
|
|
|
24158
24736
|
notificationTray: notificationTrayLinkedObject,
|
|
24159
24737
|
community: communityLinkedObject,
|
|
24160
24738
|
invitation: invitationLinkedObject,
|
|
24739
|
+
joinRequest: joinRequestLinkedObject,
|
|
24161
24740
|
};
|
|
24162
24741
|
|
|
24163
24742
|
const constructChannelObject = (channel) => {
|
|
@@ -29714,41 +30293,6 @@ getComment$2.locally = (commentId) => {
|
|
|
29714
30293
|
};
|
|
29715
30294
|
};
|
|
29716
30295
|
|
|
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
30296
|
const getMyReactionsInCache = (payload, eventPrefix) => {
|
|
29753
30297
|
var _a, _b;
|
|
29754
30298
|
let id;
|
|
@@ -30063,53 +30607,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
|
|
|
30063
30607
|
return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
|
|
30064
30608
|
};
|
|
30065
30609
|
|
|
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
30610
|
const preparePostPayload = (payload) => {
|
|
30114
30611
|
const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
|
|
30115
30612
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
@@ -35310,11 +35807,16 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
35310
35807
|
* @category Community API
|
|
35311
35808
|
* @async
|
|
35312
35809
|
*/
|
|
35313
|
-
const getCommunity$1 = async (communityId) => {
|
|
35810
|
+
const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
|
|
35314
35811
|
const client = getActiveClient();
|
|
35315
35812
|
client.log('community/getCommunity', communityId);
|
|
35316
35813
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35317
|
-
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}
|
|
35814
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
|
|
35815
|
+
params: {
|
|
35816
|
+
type: 'communityJoinRequest',
|
|
35817
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35818
|
+
},
|
|
35819
|
+
});
|
|
35318
35820
|
const data = prepareCommunityPayload(payload);
|
|
35319
35821
|
const cachedAt = client.cache && Date.now();
|
|
35320
35822
|
if (client.cache) {
|
|
@@ -35389,6 +35891,9 @@ const deleteCommunity = async (communityId) => {
|
|
|
35389
35891
|
};
|
|
35390
35892
|
/* end_public_function */
|
|
35391
35893
|
|
|
35894
|
+
/**
|
|
35895
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
35896
|
+
*/
|
|
35392
35897
|
/* begin_public_function
|
|
35393
35898
|
id: community.join
|
|
35394
35899
|
*/
|
|
@@ -35529,10 +36034,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
|
|
|
35529
36034
|
*/
|
|
35530
36035
|
class CommunitiesPaginationController$1 extends PaginationController {
|
|
35531
36036
|
async getRequest(queryParams, token) {
|
|
36037
|
+
var _a;
|
|
35532
36038
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35533
36039
|
const options = token ? { token } : { limit };
|
|
35534
36040
|
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 }),
|
|
36041
|
+
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
36042
|
});
|
|
35537
36043
|
return queryResponse;
|
|
35538
36044
|
}
|
|
@@ -36979,7 +37485,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
|
|
|
36979
37485
|
const data = (_b = collection.data
|
|
36980
37486
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36981
37487
|
.filter(isNonNullable)
|
|
36982
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37488
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
36983
37489
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36984
37490
|
return;
|
|
36985
37491
|
this.callback({
|
|
@@ -37141,7 +37647,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
|
|
|
37141
37647
|
const data = (_b = collection.data
|
|
37142
37648
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
37143
37649
|
.filter(isNonNullable)
|
|
37144
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
37650
|
+
.map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
|
|
37145
37651
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
37146
37652
|
return;
|
|
37147
37653
|
this.callback({
|
|
@@ -39791,7 +40297,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39791
40297
|
const client = getActiveClient();
|
|
39792
40298
|
const cachedAt = client.cache && Date.now();
|
|
39793
40299
|
if (client.cache) {
|
|
39794
|
-
|
|
40300
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
|
|
40301
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39795
40302
|
}
|
|
39796
40303
|
}
|
|
39797
40304
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -39920,7 +40427,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
|
|
|
39920
40427
|
const client = getActiveClient();
|
|
39921
40428
|
const cachedAt = client.cache && Date.now();
|
|
39922
40429
|
if (client.cache) {
|
|
39923
|
-
|
|
40430
|
+
const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
|
|
40431
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39924
40432
|
}
|
|
39925
40433
|
}
|
|
39926
40434
|
appendToQueryStream(response, direction, refresh = false) {
|
|
@@ -43274,4 +43782,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
43274
43782
|
getMyCommunityInvitations: getMyCommunityInvitations
|
|
43275
43783
|
});
|
|
43276
43784
|
|
|
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 };
|
|
43785
|
+
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 };
|