@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.esm.js
CHANGED
|
@@ -136,8 +136,8 @@ var JoinResultStatusEnum;
|
|
|
136
136
|
|
|
137
137
|
function getVersion() {
|
|
138
138
|
try {
|
|
139
|
-
// the string ''v7.
|
|
140
|
-
return 'v7.
|
|
139
|
+
// the string ''v7.5.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
140
|
+
return 'v7.5.0-esm';
|
|
141
141
|
}
|
|
142
142
|
catch (error) {
|
|
143
143
|
return '__dev__';
|
|
@@ -23678,11 +23678,11 @@ const joinRequestLinkedObject = (joinRequest) => {
|
|
|
23678
23678
|
return undefined;
|
|
23679
23679
|
return userLinkedObject(user);
|
|
23680
23680
|
}, cancel: async () => {
|
|
23681
|
-
|
|
23681
|
+
cancelJoinRequest(joinRequest);
|
|
23682
23682
|
}, approve: async () => {
|
|
23683
|
-
|
|
23683
|
+
approveJoinRequest(joinRequest);
|
|
23684
23684
|
}, reject: async () => {
|
|
23685
|
-
|
|
23685
|
+
rejectJoinRequest(joinRequest);
|
|
23686
23686
|
} });
|
|
23687
23687
|
};
|
|
23688
23688
|
|
|
@@ -23736,6 +23736,7 @@ const getMyJoinRequest = async (communityId) => {
|
|
|
23736
23736
|
* @async
|
|
23737
23737
|
*/
|
|
23738
23738
|
const joinRequest = async (communityId) => {
|
|
23739
|
+
var _a;
|
|
23739
23740
|
const client = getActiveClient();
|
|
23740
23741
|
client.log('community/joinRequest', communityId);
|
|
23741
23742
|
const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
|
|
@@ -23743,10 +23744,17 @@ const joinRequest = async (communityId) => {
|
|
|
23743
23744
|
const cachedAt = client.cache && Date.now();
|
|
23744
23745
|
if (client.cache)
|
|
23745
23746
|
ingestInCache(data, { cachedAt });
|
|
23746
|
-
fireEvent('local.community.join', data.joinRequests);
|
|
23747
23747
|
const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
|
|
23748
23748
|
? "success" /* JoinResultStatusEnum.Success */
|
|
23749
23749
|
: "pending" /* JoinResultStatusEnum.Pending */;
|
|
23750
|
+
if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
|
|
23751
|
+
const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23752
|
+
if (community) {
|
|
23753
|
+
const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
|
|
23754
|
+
upsertInCache(['community', 'get', communityId], updatedCommunity);
|
|
23755
|
+
}
|
|
23756
|
+
}
|
|
23757
|
+
fireEvent('v4.local.community.joined', data.joinRequests);
|
|
23750
23758
|
return status === "success" /* JoinResultStatusEnum.Success */
|
|
23751
23759
|
? { status }
|
|
23752
23760
|
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
@@ -23820,12 +23828,12 @@ class QueryStreamController {
|
|
|
23820
23828
|
}
|
|
23821
23829
|
}
|
|
23822
23830
|
|
|
23823
|
-
var EnumJoinRequestAction;
|
|
23831
|
+
var EnumJoinRequestAction$1;
|
|
23824
23832
|
(function (EnumJoinRequestAction) {
|
|
23825
23833
|
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
23826
23834
|
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
23827
23835
|
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
23828
|
-
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
23836
|
+
})(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
|
|
23829
23837
|
|
|
23830
23838
|
class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
23831
23839
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -23865,12 +23873,12 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
23865
23873
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23866
23874
|
if (!collection)
|
|
23867
23875
|
return;
|
|
23868
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
23876
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
|
|
23869
23877
|
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
23870
23878
|
if (!isExist)
|
|
23871
23879
|
return;
|
|
23872
23880
|
}
|
|
23873
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
23881
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
|
|
23874
23882
|
collection.data = [
|
|
23875
23883
|
...new Set([
|
|
23876
23884
|
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
@@ -23878,7 +23886,7 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
|
|
|
23878
23886
|
]),
|
|
23879
23887
|
];
|
|
23880
23888
|
}
|
|
23881
|
-
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
23889
|
+
if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
|
|
23882
23890
|
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
23883
23891
|
}
|
|
23884
23892
|
pushToCache(this.cacheKey, collection);
|
|
@@ -24130,9 +24138,9 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
|
|
|
24130
24138
|
}
|
|
24131
24139
|
startSubscription() {
|
|
24132
24140
|
return this.queryStreamController.subscribeRTE([
|
|
24133
|
-
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
24134
|
-
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
24135
|
-
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
24141
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
|
|
24142
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
|
|
24143
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
|
|
24136
24144
|
]);
|
|
24137
24145
|
}
|
|
24138
24146
|
notifyChange({ origin, loading, error }) {
|
|
@@ -24320,41 +24328,6 @@ const rejectInvitation = async (invitationId) => {
|
|
|
24320
24328
|
};
|
|
24321
24329
|
/* end_public_function */
|
|
24322
24330
|
|
|
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
24331
|
const prepareMyInvitationsPayload = (rawPayload) => {
|
|
24359
24332
|
return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
|
|
24360
24333
|
};
|
|
@@ -24385,11 +24358,9 @@ const invitationLinkedObject = (invitation) => {
|
|
|
24385
24358
|
}
|
|
24386
24359
|
return undefined;
|
|
24387
24360
|
}, accept: async () => {
|
|
24388
|
-
|
|
24361
|
+
acceptInvitation(invitation._id);
|
|
24389
24362
|
}, reject: async () => {
|
|
24390
|
-
|
|
24391
|
-
}, cancel: async () => {
|
|
24392
|
-
await cancelInvitation(invitation._id);
|
|
24363
|
+
rejectInvitation(invitation._id);
|
|
24393
24364
|
} });
|
|
24394
24365
|
};
|
|
24395
24366
|
|
|
@@ -24710,9 +24681,7 @@ const communityLinkedObject = (community) => {
|
|
|
24710
24681
|
}, getInvitation: async () => {
|
|
24711
24682
|
const { data } = await getInvitation('community', community.communityId);
|
|
24712
24683
|
return data;
|
|
24713
|
-
}, join: async () => {
|
|
24714
|
-
return joinRequest(community.communityId);
|
|
24715
|
-
}, getJoinRequests: (params, callback) => {
|
|
24684
|
+
}, join: async () => joinRequest(community.communityId), getJoinRequests: (params, callback) => {
|
|
24716
24685
|
return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
|
|
24717
24686
|
}, getMyJoinRequest: async () => {
|
|
24718
24687
|
const { data } = await getMyJoinRequest(community.communityId);
|
|
@@ -35670,10 +35639,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
|
|
|
35670
35639
|
const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
|
|
35671
35640
|
const client = getActiveClient();
|
|
35672
35641
|
client.log('community/getCommunities', communityIds);
|
|
35642
|
+
const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
35673
35643
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
35674
35644
|
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
35675
35645
|
params: {
|
|
35676
|
-
communityIds,
|
|
35646
|
+
communityIds: encodedCommunityIds,
|
|
35677
35647
|
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
|
|
35678
35648
|
},
|
|
35679
35649
|
});
|
|
@@ -36538,6 +36508,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
|
|
|
36538
36508
|
|
|
36539
36509
|
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
36540
36510
|
|
|
36511
|
+
const onLocalCommunityJoin = (callback) => {
|
|
36512
|
+
const client = getActiveClient();
|
|
36513
|
+
const filter = async (rawPayload) => {
|
|
36514
|
+
callback(rawPayload[0]);
|
|
36515
|
+
};
|
|
36516
|
+
const disposers = [
|
|
36517
|
+
createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
|
|
36518
|
+
];
|
|
36519
|
+
return () => {
|
|
36520
|
+
disposers.forEach(fn => fn());
|
|
36521
|
+
};
|
|
36522
|
+
};
|
|
36523
|
+
|
|
36541
36524
|
/**
|
|
36542
36525
|
* ```js
|
|
36543
36526
|
* import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
|
|
@@ -37024,7 +37007,8 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
37024
37007
|
onCommunityJoined: onCommunityJoined,
|
|
37025
37008
|
onCommunityLeft: onCommunityLeft,
|
|
37026
37009
|
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
37027
|
-
onLocalCommunityLeft: onLocalCommunityLeft
|
|
37010
|
+
onLocalCommunityLeft: onLocalCommunityLeft,
|
|
37011
|
+
onLocalCommunityJoin: onLocalCommunityJoin
|
|
37028
37012
|
});
|
|
37029
37013
|
|
|
37030
37014
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -37248,6 +37232,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
37248
37232
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
37249
37233
|
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
37250
37234
|
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
37235
|
+
{
|
|
37236
|
+
fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
37237
|
+
action: EnumCommunityActions$3.OnCommunityUpdated,
|
|
37238
|
+
},
|
|
37251
37239
|
]);
|
|
37252
37240
|
}
|
|
37253
37241
|
notifyChange({ origin, loading, error }) {
|
|
@@ -37371,6 +37359,7 @@ const getCommunity = (communityId, callback) => {
|
|
|
37371
37359
|
onCommunityUserBanned,
|
|
37372
37360
|
onCommunityUserUnbanned,
|
|
37373
37361
|
onCommunityUserChanged,
|
|
37362
|
+
convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
|
|
37374
37363
|
]);
|
|
37375
37364
|
};
|
|
37376
37365
|
/* end_public_function */
|
|
@@ -37887,6 +37876,200 @@ const semanticSearchCommunities = (params, callback, config) => {
|
|
|
37887
37876
|
};
|
|
37888
37877
|
};
|
|
37889
37878
|
|
|
37879
|
+
/**
|
|
37880
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
37881
|
+
* TODO: check if querybyIds is supported
|
|
37882
|
+
*/
|
|
37883
|
+
class JoinRequestListPaginationController extends PaginationController {
|
|
37884
|
+
async getRequest(queryParams, token) {
|
|
37885
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
|
|
37886
|
+
const options = token ? { token } : { limit };
|
|
37887
|
+
const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
|
|
37888
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
|
|
37889
|
+
params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
|
|
37890
|
+
});
|
|
37891
|
+
return queryResponse;
|
|
37892
|
+
}
|
|
37893
|
+
}
|
|
37894
|
+
|
|
37895
|
+
var EnumJoinRequestAction;
|
|
37896
|
+
(function (EnumJoinRequestAction) {
|
|
37897
|
+
EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
|
|
37898
|
+
EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
|
|
37899
|
+
EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
|
|
37900
|
+
})(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
|
|
37901
|
+
|
|
37902
|
+
class JoinRequestListQueryStreamController extends QueryStreamController {
|
|
37903
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
37904
|
+
super(query, cacheKey);
|
|
37905
|
+
this.notifyChange = notifyChange;
|
|
37906
|
+
this.preparePayload = preparePayload;
|
|
37907
|
+
}
|
|
37908
|
+
async saveToMainDB(response) {
|
|
37909
|
+
const processedPayload = await this.preparePayload(response);
|
|
37910
|
+
const client = getActiveClient();
|
|
37911
|
+
const cachedAt = client.cache && Date.now();
|
|
37912
|
+
if (client.cache) {
|
|
37913
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37914
|
+
}
|
|
37915
|
+
}
|
|
37916
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37917
|
+
var _a, _b;
|
|
37918
|
+
if (refresh) {
|
|
37919
|
+
pushToCache(this.cacheKey, {
|
|
37920
|
+
data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37921
|
+
});
|
|
37922
|
+
}
|
|
37923
|
+
else {
|
|
37924
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37925
|
+
const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37926
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
37927
|
+
...new Set([
|
|
37928
|
+
...joinRequests,
|
|
37929
|
+
...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
|
|
37930
|
+
]),
|
|
37931
|
+
] }));
|
|
37932
|
+
}
|
|
37933
|
+
}
|
|
37934
|
+
reactor(action) {
|
|
37935
|
+
return (joinRequest) => {
|
|
37936
|
+
var _a;
|
|
37937
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37938
|
+
if (!collection)
|
|
37939
|
+
return;
|
|
37940
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
|
|
37941
|
+
const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
|
|
37942
|
+
if (!isExist)
|
|
37943
|
+
return;
|
|
37944
|
+
}
|
|
37945
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
|
|
37946
|
+
collection.data = [
|
|
37947
|
+
...new Set([
|
|
37948
|
+
...joinRequest.map(joinRequest => joinRequest.joinRequestId),
|
|
37949
|
+
...collection.data,
|
|
37950
|
+
]),
|
|
37951
|
+
];
|
|
37952
|
+
}
|
|
37953
|
+
if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
|
|
37954
|
+
collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
|
|
37955
|
+
}
|
|
37956
|
+
pushToCache(this.cacheKey, collection);
|
|
37957
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37958
|
+
};
|
|
37959
|
+
}
|
|
37960
|
+
subscribeRTE(createSubscriber) {
|
|
37961
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
37962
|
+
}
|
|
37963
|
+
}
|
|
37964
|
+
|
|
37965
|
+
class JoinRequestListLiveCollectionController extends LiveCollectionController {
|
|
37966
|
+
constructor(query, callback) {
|
|
37967
|
+
const queryStreamId = hash(query);
|
|
37968
|
+
const cacheKey = ['joinRequestList', 'collection', queryStreamId];
|
|
37969
|
+
const paginationController = new JoinRequestListPaginationController(query);
|
|
37970
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37971
|
+
this.query = query;
|
|
37972
|
+
this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
|
|
37973
|
+
this.callback = callback.bind(this);
|
|
37974
|
+
this.loadPage({ initial: true });
|
|
37975
|
+
}
|
|
37976
|
+
setup() {
|
|
37977
|
+
var _a;
|
|
37978
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37979
|
+
if (!collection) {
|
|
37980
|
+
pushToCache(this.cacheKey, {
|
|
37981
|
+
data: [],
|
|
37982
|
+
params: this.query,
|
|
37983
|
+
});
|
|
37984
|
+
}
|
|
37985
|
+
}
|
|
37986
|
+
async persistModel(queryPayload) {
|
|
37987
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
37988
|
+
}
|
|
37989
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37990
|
+
const joinRequestResponse = response;
|
|
37991
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
37992
|
+
}
|
|
37993
|
+
startSubscription() {
|
|
37994
|
+
return this.queryStreamController.subscribeRTE([
|
|
37995
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
37996
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
37997
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
37998
|
+
]);
|
|
37999
|
+
}
|
|
38000
|
+
notifyChange({ origin, loading, error }) {
|
|
38001
|
+
var _a;
|
|
38002
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
38003
|
+
if (!collection)
|
|
38004
|
+
return;
|
|
38005
|
+
const data = this.applyFilter(collection.data
|
|
38006
|
+
.map(id => pullFromCache(['joinRequest', 'get', id]))
|
|
38007
|
+
.filter(isNonNullable)
|
|
38008
|
+
.map(({ data }) => data)
|
|
38009
|
+
.map(joinRequestLinkedObject));
|
|
38010
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
38011
|
+
return;
|
|
38012
|
+
this.callback({
|
|
38013
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
38014
|
+
data,
|
|
38015
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
38016
|
+
loading,
|
|
38017
|
+
error,
|
|
38018
|
+
});
|
|
38019
|
+
}
|
|
38020
|
+
applyFilter(data) {
|
|
38021
|
+
let joinRequest = data;
|
|
38022
|
+
if (this.query.communityIds && this.query.communityIds.length > 0) {
|
|
38023
|
+
joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
|
|
38024
|
+
}
|
|
38025
|
+
const sortFn = (() => {
|
|
38026
|
+
switch (this.query.sortBy) {
|
|
38027
|
+
case 'firstCreated':
|
|
38028
|
+
return sortByFirstCreated;
|
|
38029
|
+
case 'lastCreated':
|
|
38030
|
+
return sortByLastCreated;
|
|
38031
|
+
default:
|
|
38032
|
+
return sortByLastCreated;
|
|
38033
|
+
}
|
|
38034
|
+
})();
|
|
38035
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
38036
|
+
return joinRequest;
|
|
38037
|
+
}
|
|
38038
|
+
}
|
|
38039
|
+
|
|
38040
|
+
/* begin_public_function
|
|
38041
|
+
id: community.getJoinRequestList
|
|
38042
|
+
*/
|
|
38043
|
+
/**
|
|
38044
|
+
* Get Join Requests
|
|
38045
|
+
*
|
|
38046
|
+
* @param params the query parameters
|
|
38047
|
+
* @param callback the callback to be called when the join request are updated
|
|
38048
|
+
* @returns joinRequest[]
|
|
38049
|
+
*
|
|
38050
|
+
* @category joinRequestList Live Collection
|
|
38051
|
+
*
|
|
38052
|
+
*/
|
|
38053
|
+
const getJoinRequestList = (params, callback, config) => {
|
|
38054
|
+
const { log, cache } = getActiveClient();
|
|
38055
|
+
if (!cache) {
|
|
38056
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
38057
|
+
}
|
|
38058
|
+
const timestamp = Date.now();
|
|
38059
|
+
log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
|
|
38060
|
+
const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
|
|
38061
|
+
const disposers = joinRequestListLiveCollection.startSubscription();
|
|
38062
|
+
const cacheKey = joinRequestListLiveCollection.getCacheKey();
|
|
38063
|
+
disposers.push(() => {
|
|
38064
|
+
dropFromCache(cacheKey);
|
|
38065
|
+
});
|
|
38066
|
+
return () => {
|
|
38067
|
+
log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
|
|
38068
|
+
disposers.forEach(fn => fn());
|
|
38069
|
+
};
|
|
38070
|
+
};
|
|
38071
|
+
/* end_public_function */
|
|
38072
|
+
|
|
37890
38073
|
var AmityCommunityMemberStatusFilter;
|
|
37891
38074
|
(function (AmityCommunityMemberStatusFilter) {
|
|
37892
38075
|
AmityCommunityMemberStatusFilter["ALL"] = "all";
|
|
@@ -38057,6 +38240,7 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
38057
38240
|
getTrendingCommunities: getTrendingCommunities,
|
|
38058
38241
|
getRecommendedCommunities: getRecommendedCommunities,
|
|
38059
38242
|
semanticSearchCommunities: semanticSearchCommunities,
|
|
38243
|
+
getJoinRequestList: getJoinRequestList,
|
|
38060
38244
|
get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
|
|
38061
38245
|
});
|
|
38062
38246
|
|