@amityco/ts-sdk 7.4.1-fd0f791a.0 → 7.5.1-12f08f0.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 +1 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +11 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +0 -1
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +4 -2
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.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/joinCommunity.d.ts.map +1 -1
- 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/index.d.ts +1 -0
- package/dist/communityRepository/observers/index.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +242 -58
- package/dist/index.esm.js +242 -58
- package/dist/index.umd.js +2 -2
- package/dist/invitationRepository/internalApi/index.d.ts +0 -1
- package/dist/invitationRepository/internalApi/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +2 -2
- package/src/@types/domains/community.ts +17 -0
- package/src/@types/domains/invitation.ts +0 -1
- package/src/@types/domains/notification.ts +2 -0
- package/src/communityRepository/api/getCommunities.ts +3 -1
- package/src/communityRepository/communityMembership/events/index.ts +1 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +17 -2
- 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/index.ts +1 -0
- package/src/invitationRepository/internalApi/index.ts +0 -1
- package/src/utils/linkedObject/communityLinkedObject.ts +1 -3
- package/src/utils/linkedObject/invitationLinkedObject.ts +3 -10
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +3 -3
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +0 -16
- package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +0 -1
- package/src/invitationRepository/internalApi/cancelInvitation.ts +0 -44
package/dist/index.cjs.js
CHANGED
|
@@ -151,8 +151,8 @@ exports.JoinResultStatusEnum = void 0;
|
|
|
151
151
|
|
|
152
152
|
function getVersion() {
|
|
153
153
|
try {
|
|
154
|
-
// the string ''v7.
|
|
155
|
-
return 'v7.
|
|
154
|
+
// the string ''v7.5.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
155
|
+
return 'v7.5.0-cjs';
|
|
156
156
|
}
|
|
157
157
|
catch (error) {
|
|
158
158
|
return '__dev__';
|
|
@@ -7586,11 +7586,11 @@ const joinRequestLinkedObject = (joinRequest) => {
|
|
|
7586
7586
|
return undefined;
|
|
7587
7587
|
return userLinkedObject(user);
|
|
7588
7588
|
}, cancel: async () => {
|
|
7589
|
-
|
|
7589
|
+
cancelJoinRequest(joinRequest);
|
|
7590
7590
|
}, approve: async () => {
|
|
7591
|
-
|
|
7591
|
+
approveJoinRequest(joinRequest);
|
|
7592
7592
|
}, reject: async () => {
|
|
7593
|
-
|
|
7593
|
+
rejectJoinRequest(joinRequest);
|
|
7594
7594
|
} });
|
|
7595
7595
|
};
|
|
7596
7596
|
|
|
@@ -7644,6 +7644,7 @@ const getMyJoinRequest = async (communityId) => {
|
|
|
7644
7644
|
* @async
|
|
7645
7645
|
*/
|
|
7646
7646
|
const joinRequest = async (communityId) => {
|
|
7647
|
+
var _a;
|
|
7647
7648
|
const client = getActiveClient();
|
|
7648
7649
|
client.log('community/joinRequest', communityId);
|
|
7649
7650
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
@@ -7651,10 +7652,17 @@ const joinRequest = async (communityId) => {
|
|
|
7651
7652
|
const cachedAt = client.cache && Date.now();
|
|
7652
7653
|
if (client.cache)
|
|
7653
7654
|
ingestInCache(data, { cachedAt });
|
|
7654
|
-
fireEvent('local.community.join', data.joinRequests);
|
|
7655
7655
|
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
7656
7656
|
? "success" /* JoinResultStatusEnum.Success */
|
|
7657
7657
|
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
7658
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
7659
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7660
|
+
if (community) {
|
|
7661
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
7662
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
7663
|
+
}
|
|
7664
|
+
}
|
|
7665
|
+
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
7658
7666
|
return status === "success" /* JoinResultStatusEnum.Success */
|
|
7659
7667
|
? { status }
|
|
7660
7668
|
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
@@ -7728,12 +7736,12 @@ class QueryStreamController {
|
|
|
7728
7736
|
}
|
|
7729
7737
|
}
|
|
7730
7738
|
|
|
7731
|
-
var EnumJoinRequestAction;
|
|
7739
|
+
var EnumJoinRequestAction$1;
|
|
7732
7740
|
(function (EnumJoinRequestAction) {
|
|
7733
7741
|
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
7734
7742
|
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
7735
7743
|
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
7736
|
-
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
7744
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
7737
7745
|
|
|
7738
7746
|
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
7739
7747
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -7773,12 +7781,12 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
7773
7781
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
7774
7782
|
if (!collection)
|
|
7775
7783
|
return;
|
|
7776
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
7784
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
7777
7785
|
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
7778
7786
|
if (!isExist)
|
|
7779
7787
|
return;
|
|
7780
7788
|
}
|
|
7781
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
7789
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
7782
7790
|
collection.data = [
|
|
7783
7791
|
...new Set([
|
|
7784
7792
|
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
@@ -7786,7 +7794,7 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
7786
7794
|
]),
|
|
7787
7795
|
];
|
|
7788
7796
|
}
|
|
7789
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
7797
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
7790
7798
|
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
7791
7799
|
}
|
|
7792
7800
|
pushToCache(this.cacheKey, collection);
|
|
@@ -8038,9 +8046,9 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
|
8038
8046
|
}
|
|
8039
8047
|
startSubscription() {
|
|
8040
8048
|
return this.queryStreamController.subscribeRTE([
|
|
8041
|
-
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
8042
|
-
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
8043
|
-
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
8049
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
8050
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
8051
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
8044
8052
|
]);
|
|
8045
8053
|
}
|
|
8046
8054
|
notifyChange({ origin, loading, error }) {
|
|
@@ -8228,41 +8236,6 @@ const rejectInvitation = async (invitationId) => {
|
|
|
8228
8236
|
};
|
|
8229
8237
|
/* end_public_function */
|
|
8230
8238
|
|
|
8231
|
-
/* begin_public_function
|
|
8232
|
-
id: invitation.cancel
|
|
8233
|
-
*/
|
|
8234
|
-
/**
|
|
8235
|
-
* ```js
|
|
8236
|
-
* import { cancelInvitation } from '@amityco/ts-sdk'
|
|
8237
|
-
* const isCanceled = await cancelInvitation(invitationId)
|
|
8238
|
-
* ```
|
|
8239
|
-
*
|
|
8240
|
-
* Cancels a {@link Amity.Invitation} object
|
|
8241
|
-
*
|
|
8242
|
-
* @param invitationId the {@link Amity.Invitation} to cancel
|
|
8243
|
-
* @returns A success boolean if the {@link Amity.Invitation} was canceled
|
|
8244
|
-
*
|
|
8245
|
-
* @category Invitation API
|
|
8246
|
-
* @async
|
|
8247
|
-
*/
|
|
8248
|
-
const cancelInvitation = async (invitationId) => {
|
|
8249
|
-
var _a;
|
|
8250
|
-
const client = getActiveClient();
|
|
8251
|
-
client.log('invitation/cancelInvitation', invitationId);
|
|
8252
|
-
const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
|
|
8253
|
-
const invitation = (_a = pullFromCache([
|
|
8254
|
-
'invitation',
|
|
8255
|
-
'get',
|
|
8256
|
-
invitationId,
|
|
8257
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8258
|
-
if (invitation) {
|
|
8259
|
-
dropFromCache(['invitation', 'get', invitationId]);
|
|
8260
|
-
fireEvent('local.invitation.deleted', [invitation]);
|
|
8261
|
-
}
|
|
8262
|
-
return data.success;
|
|
8263
|
-
};
|
|
8264
|
-
/* end_public_function */
|
|
8265
|
-
|
|
8266
8239
|
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
8267
8240
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
8268
8241
|
};
|
|
@@ -8293,11 +8266,9 @@ const invitationLinkedObject = (invitation) => {
|
|
|
8293
8266
|
}
|
|
8294
8267
|
return undefined;
|
|
8295
8268
|
}, accept: async () => {
|
|
8296
|
-
|
|
8269
|
+
acceptInvitation(invitation._id);
|
|
8297
8270
|
}, reject: async () => {
|
|
8298
|
-
|
|
8299
|
-
}, cancel: async () => {
|
|
8300
|
-
await cancelInvitation(invitation._id);
|
|
8271
|
+
rejectInvitation(invitation._id);
|
|
8301
8272
|
} });
|
|
8302
8273
|
};
|
|
8303
8274
|
|
|
@@ -8618,9 +8589,7 @@ const communityLinkedObject = (community) => {
|
|
|
8618
8589
|
}, getInvitation: async () => {
|
|
8619
8590
|
const { data } = await getInvitation('community', community.communityId);
|
|
8620
8591
|
return data;
|
|
8621
|
-
}, join: async () => {
|
|
8622
|
-
return joinRequest(community.communityId);
|
|
8623
|
-
}, getJoinRequests: (params, callback) => {
|
|
8592
|
+
}, join: async () => joinRequest(community.communityId), getJoinRequests: (params, callback) => {
|
|
8624
8593
|
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
8625
8594
|
}, getMyJoinRequest: async () => {
|
|
8626
8595
|
const { data } = await getMyJoinRequest(community.communityId);
|
|
@@ -19578,10 +19547,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
19578
19547
|
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
19579
19548
|
const client = getActiveClient();
|
|
19580
19549
|
client.log('community/getCommunities', communityIds);
|
|
19550
|
+
const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
19581
19551
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
19582
19552
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
19583
19553
|
params: {
|
|
19584
|
-
communityIds,
|
|
19554
|
+
communityIds: encodedCommunityIds,
|
|
19585
19555
|
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
19586
19556
|
},
|
|
19587
19557
|
});
|
|
@@ -20446,6 +20416,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
20446
20416
|
|
|
20447
20417
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
20448
20418
|
|
|
20419
|
+
const onLocalCommunityJoin = (callback) => {
|
|
20420
|
+
const client = getActiveClient();
|
|
20421
|
+
const filter = async (rawPayload) => {
|
|
20422
|
+
callback(rawPayload[0]);
|
|
20423
|
+
};
|
|
20424
|
+
const disposers = [
|
|
20425
|
+
createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
|
|
20426
|
+
];
|
|
20427
|
+
return () => {
|
|
20428
|
+
disposers.forEach(fn => fn());
|
|
20429
|
+
};
|
|
20430
|
+
};
|
|
20431
|
+
|
|
20449
20432
|
/**
|
|
20450
20433
|
* ```js
|
|
20451
20434
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -20932,7 +20915,8 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
20932
20915
|
onCommunityJoined: onCommunityJoined,
|
|
20933
20916
|
onCommunityLeft: onCommunityLeft,
|
|
20934
20917
|
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
20935
|
-
onLocalCommunityLeft: onLocalCommunityLeft
|
|
20918
|
+
onLocalCommunityLeft: onLocalCommunityLeft,
|
|
20919
|
+
onLocalCommunityJoin: onLocalCommunityJoin
|
|
20936
20920
|
});
|
|
20937
20921
|
|
|
20938
20922
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -21156,6 +21140,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
21156
21140
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
21157
21141
|
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
21158
21142
|
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
21143
|
+
{
|
|
21144
|
+
fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
21145
|
+
action: EnumCommunityActions$3.OnCommunityUpdated,
|
|
21146
|
+
},
|
|
21159
21147
|
]);
|
|
21160
21148
|
}
|
|
21161
21149
|
notifyChange({ origin, loading, error }) {
|
|
@@ -21279,6 +21267,7 @@ const getCommunity = (communityId, callback) => {
|
|
|
21279
21267
|
onCommunityUserBanned,
|
|
21280
21268
|
onCommunityUserUnbanned,
|
|
21281
21269
|
onCommunityUserChanged,
|
|
21270
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
21282
21271
|
]);
|
|
21283
21272
|
};
|
|
21284
21273
|
/* end_public_function */
|
|
@@ -21795,6 +21784,200 @@ const semanticSearchCommunities = (params, callback, config) => {
|
|
|
21795
21784
|
};
|
|
21796
21785
|
};
|
|
21797
21786
|
|
|
21787
|
+
/**
|
|
21788
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
21789
|
+
* TODO: check if querybyIds is supported
|
|
21790
|
+
*/
|
|
21791
|
+
class JoinRequestListPaginationController extends PaginationController {
|
|
21792
|
+
async getRequest(queryParams, token) {
|
|
21793
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
|
|
21794
|
+
const options = token ? { token } : { limit };
|
|
21795
|
+
const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
21796
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
|
|
21797
|
+
params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
|
|
21798
|
+
});
|
|
21799
|
+
return queryResponse;
|
|
21800
|
+
}
|
|
21801
|
+
}
|
|
21802
|
+
|
|
21803
|
+
var EnumJoinRequestAction;
|
|
21804
|
+
(function (EnumJoinRequestAction) {
|
|
21805
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
21806
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
21807
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
21808
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
21809
|
+
|
|
21810
|
+
class JoinRequestListQueryStreamController extends QueryStreamController {
|
|
21811
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
21812
|
+
super(query, cacheKey);
|
|
21813
|
+
this.notifyChange = notifyChange;
|
|
21814
|
+
this.preparePayload = preparePayload;
|
|
21815
|
+
}
|
|
21816
|
+
async saveToMainDB(response) {
|
|
21817
|
+
const processedPayload = await this.preparePayload(response);
|
|
21818
|
+
const client = getActiveClient();
|
|
21819
|
+
const cachedAt = client.cache && Date.now();
|
|
21820
|
+
if (client.cache) {
|
|
21821
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21822
|
+
}
|
|
21823
|
+
}
|
|
21824
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21825
|
+
var _a, _b;
|
|
21826
|
+
if (refresh) {
|
|
21827
|
+
pushToCache(this.cacheKey, {
|
|
21828
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
21829
|
+
});
|
|
21830
|
+
}
|
|
21831
|
+
else {
|
|
21832
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21833
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21834
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
21835
|
+
...new Set([
|
|
21836
|
+
...joinRequests,
|
|
21837
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
21838
|
+
]),
|
|
21839
|
+
] }));
|
|
21840
|
+
}
|
|
21841
|
+
}
|
|
21842
|
+
reactor(action) {
|
|
21843
|
+
return (joinRequest) => {
|
|
21844
|
+
var _a;
|
|
21845
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21846
|
+
if (!collection)
|
|
21847
|
+
return;
|
|
21848
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
21849
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
21850
|
+
if (!isExist)
|
|
21851
|
+
return;
|
|
21852
|
+
}
|
|
21853
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
21854
|
+
collection.data = [
|
|
21855
|
+
...new Set([
|
|
21856
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
21857
|
+
...collection.data,
|
|
21858
|
+
]),
|
|
21859
|
+
];
|
|
21860
|
+
}
|
|
21861
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
21862
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
21863
|
+
}
|
|
21864
|
+
pushToCache(this.cacheKey, collection);
|
|
21865
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21866
|
+
};
|
|
21867
|
+
}
|
|
21868
|
+
subscribeRTE(createSubscriber) {
|
|
21869
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
21870
|
+
}
|
|
21871
|
+
}
|
|
21872
|
+
|
|
21873
|
+
class JoinRequestListLiveCollectionController extends LiveCollectionController {
|
|
21874
|
+
constructor(query, callback) {
|
|
21875
|
+
const queryStreamId = hash__default["default"](query);
|
|
21876
|
+
const cacheKey = ['joinRequestList', 'collection', queryStreamId];
|
|
21877
|
+
const paginationController = new JoinRequestListPaginationController(query);
|
|
21878
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21879
|
+
this.query = query;
|
|
21880
|
+
this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
21881
|
+
this.callback = callback.bind(this);
|
|
21882
|
+
this.loadPage({ initial: true });
|
|
21883
|
+
}
|
|
21884
|
+
setup() {
|
|
21885
|
+
var _a;
|
|
21886
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21887
|
+
if (!collection) {
|
|
21888
|
+
pushToCache(this.cacheKey, {
|
|
21889
|
+
data: [],
|
|
21890
|
+
params: this.query,
|
|
21891
|
+
});
|
|
21892
|
+
}
|
|
21893
|
+
}
|
|
21894
|
+
async persistModel(queryPayload) {
|
|
21895
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
21896
|
+
}
|
|
21897
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
21898
|
+
const joinRequestResponse = response;
|
|
21899
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
21900
|
+
}
|
|
21901
|
+
startSubscription() {
|
|
21902
|
+
return this.queryStreamController.subscribeRTE([
|
|
21903
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
21904
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
21905
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
21906
|
+
]);
|
|
21907
|
+
}
|
|
21908
|
+
notifyChange({ origin, loading, error }) {
|
|
21909
|
+
var _a;
|
|
21910
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21911
|
+
if (!collection)
|
|
21912
|
+
return;
|
|
21913
|
+
const data = this.applyFilter(collection.data
|
|
21914
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
21915
|
+
.filter(isNonNullable)
|
|
21916
|
+
.map(({ data }) => data)
|
|
21917
|
+
.map(joinRequestLinkedObject));
|
|
21918
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
21919
|
+
return;
|
|
21920
|
+
this.callback({
|
|
21921
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
21922
|
+
data,
|
|
21923
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
21924
|
+
loading,
|
|
21925
|
+
error,
|
|
21926
|
+
});
|
|
21927
|
+
}
|
|
21928
|
+
applyFilter(data) {
|
|
21929
|
+
let joinRequest = data;
|
|
21930
|
+
if (this.query.communityIds && this.query.communityIds.length > 0) {
|
|
21931
|
+
joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
|
|
21932
|
+
}
|
|
21933
|
+
const sortFn = (() => {
|
|
21934
|
+
switch (this.query.sortBy) {
|
|
21935
|
+
case 'firstCreated':
|
|
21936
|
+
return sortByFirstCreated;
|
|
21937
|
+
case 'lastCreated':
|
|
21938
|
+
return sortByLastCreated;
|
|
21939
|
+
default:
|
|
21940
|
+
return sortByLastCreated;
|
|
21941
|
+
}
|
|
21942
|
+
})();
|
|
21943
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
21944
|
+
return joinRequest;
|
|
21945
|
+
}
|
|
21946
|
+
}
|
|
21947
|
+
|
|
21948
|
+
/* begin_public_function
|
|
21949
|
+
id: community.getJoinRequestList
|
|
21950
|
+
*/
|
|
21951
|
+
/**
|
|
21952
|
+
* Get Join Requests
|
|
21953
|
+
*
|
|
21954
|
+
* @param params the query parameters
|
|
21955
|
+
* @param callback the callback to be called when the join request are updated
|
|
21956
|
+
* @returns joinRequest[]
|
|
21957
|
+
*
|
|
21958
|
+
* @category joinRequestList Live Collection
|
|
21959
|
+
*
|
|
21960
|
+
*/
|
|
21961
|
+
const getJoinRequestList = (params, callback, config) => {
|
|
21962
|
+
const { log, cache } = getActiveClient();
|
|
21963
|
+
if (!cache) {
|
|
21964
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
21965
|
+
}
|
|
21966
|
+
const timestamp = Date.now();
|
|
21967
|
+
log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
|
|
21968
|
+
const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
|
|
21969
|
+
const disposers = joinRequestListLiveCollection.startSubscription();
|
|
21970
|
+
const cacheKey = joinRequestListLiveCollection.getCacheKey();
|
|
21971
|
+
disposers.push(() => {
|
|
21972
|
+
dropFromCache(cacheKey);
|
|
21973
|
+
});
|
|
21974
|
+
return () => {
|
|
21975
|
+
log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
|
|
21976
|
+
disposers.forEach(fn => fn());
|
|
21977
|
+
};
|
|
21978
|
+
};
|
|
21979
|
+
/* end_public_function */
|
|
21980
|
+
|
|
21798
21981
|
var AmityCommunityMemberStatusFilter;
|
|
21799
21982
|
(function (AmityCommunityMemberStatusFilter) {
|
|
21800
21983
|
AmityCommunityMemberStatusFilter["ALL"] = "all";
|
|
@@ -21965,6 +22148,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
21965
22148
|
getTrendingCommunities: getTrendingCommunities,
|
|
21966
22149
|
getRecommendedCommunities: getRecommendedCommunities,
|
|
21967
22150
|
semanticSearchCommunities: semanticSearchCommunities,
|
|
22151
|
+
getJoinRequestList: getJoinRequestList,
|
|
21968
22152
|
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
21969
22153
|
});
|
|
21970
22154
|
|