@amityco/ts-sdk 7.4.1-0e170b02.0 → 7.4.1-108e44a8.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.
Files changed (63) hide show
  1. package/dist/@types/core/events.d.ts +1 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/domains/community.d.ts +12 -1
  4. package/dist/@types/domains/community.d.ts.map +1 -1
  5. package/dist/@types/domains/joinRequest.d.ts +7 -7
  6. package/dist/@types/domains/joinRequest.d.ts.map +1 -1
  7. package/dist/@types/domains/notification.d.ts +4 -2
  8. package/dist/@types/domains/notification.d.ts.map +1 -1
  9. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  10. package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
  11. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  12. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
  13. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
  14. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -1
  15. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -1
  16. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -1
  17. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -1
  18. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  19. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  20. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
  21. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
  22. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
  23. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
  24. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
  25. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
  26. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
  27. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
  28. package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
  29. package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
  30. package/dist/communityRepository/observers/index.d.ts +1 -0
  31. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  32. package/dist/core/events.d.ts +3 -3
  33. package/dist/core/events.d.ts.map +1 -1
  34. package/dist/core/model/index.d.ts.map +1 -1
  35. package/dist/index.cjs.js +254 -36
  36. package/dist/index.esm.js +254 -36
  37. package/dist/index.umd.js +2 -2
  38. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  39. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -1
  40. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  41. package/package.json +1 -1
  42. package/src/@types/core/events.ts +2 -2
  43. package/src/@types/domains/community.ts +18 -1
  44. package/src/@types/domains/joinRequest.ts +7 -7
  45. package/src/@types/domains/notification.ts +2 -0
  46. package/src/communityRepository/api/getCommunities.ts +3 -1
  47. package/src/communityRepository/communityMembership/events/index.ts +1 -0
  48. package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
  49. package/src/communityRepository/internalAPI/joinCommunity.ts +21 -4
  50. package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +1 -5
  51. package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +0 -5
  52. package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +3 -0
  53. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
  54. package/src/communityRepository/observers/getCommunity.ts +3 -0
  55. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
  56. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
  57. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
  58. package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
  59. package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
  60. package/src/communityRepository/observers/index.ts +1 -0
  61. package/src/core/model/index.ts +1 -0
  62. package/src/utils/linkedObject/communityLinkedObject.ts +1 -3
  63. package/src/utils/linkedObject/joinRequestLinkedObject.ts +11 -13
package/dist/index.esm.js CHANGED
@@ -635,6 +635,7 @@ const PAYLOAD2MODEL = {
635
635
  pins: 'pin',
636
636
  notificationTrayItems: 'notificationTrayItem',
637
637
  invitations: 'invitation',
638
+ joinRequests: 'joinRequest',
638
639
  };
639
640
  /** hidden */
640
641
  const isOutdated = (prevData, nextData) => {
@@ -23574,11 +23575,8 @@ const approveJoinRequest = async (joinRequest) => {
23574
23575
  const client = getActiveClient();
23575
23576
  client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
23576
23577
  const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
23577
- params: {
23578
- userId: joinRequest.userId,
23579
- },
23578
+ userId: joinRequest.requestorInternalId,
23580
23579
  });
23581
- // TODO : Check cache id
23582
23580
  const joinRequestCache = (_a = pullFromCache([
23583
23581
  'joinRequest',
23584
23582
  'get',
@@ -23615,11 +23613,7 @@ const cancelJoinRequest = async (joinRequest) => {
23615
23613
  var _a;
23616
23614
  const client = getActiveClient();
23617
23615
  client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
23618
- const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`, {
23619
- params: {
23620
- userId: joinRequest.userId,
23621
- },
23622
- });
23616
+ const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
23623
23617
  const joinRequestCache = (_a = pullFromCache([
23624
23618
  'joinRequest',
23625
23619
  'get',
@@ -23654,7 +23648,9 @@ const rejectJoinRequest = async (joinRequest) => {
23654
23648
  var _a;
23655
23649
  const client = getActiveClient();
23656
23650
  client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
23657
- const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`);
23651
+ const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
23652
+ userId: joinRequest.requestorInternalId,
23653
+ });
23658
23654
  const joinRequestCache = (_a = pullFromCache([
23659
23655
  'joinRequest',
23660
23656
  'get',
@@ -23672,17 +23668,16 @@ const rejectJoinRequest = async (joinRequest) => {
23672
23668
 
23673
23669
  const joinRequestLinkedObject = (joinRequest) => {
23674
23670
  return Object.assign(Object.assign({}, joinRequest), { get user() {
23675
- const cacheData = pullFromCache(['user', 'get', joinRequest.userId]);
23676
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
23677
- return userLinkedObject(cacheData.data);
23678
- return undefined;
23679
- }, cancel: async () => {
23680
- await cancelJoinRequest(joinRequest);
23681
- }, approve: async () => {
23682
- await approveJoinRequest(joinRequest);
23683
- }, reject: async () => {
23684
- await rejectJoinRequest(joinRequest);
23685
- } });
23671
+ var _a;
23672
+ const user = (_a = pullFromCache([
23673
+ 'user',
23674
+ 'get',
23675
+ joinRequest.requestorPublicId,
23676
+ ])) === null || _a === void 0 ? void 0 : _a.data;
23677
+ if (!user)
23678
+ return undefined;
23679
+ return userLinkedObject(user);
23680
+ }, cancel: () => cancelJoinRequest(joinRequest), approve: () => approveJoinRequest(joinRequest), reject: () => rejectJoinRequest(joinRequest) });
23686
23681
  };
23687
23682
 
23688
23683
  /* begin_public_function
@@ -23735,6 +23730,7 @@ const getMyJoinRequest = async (communityId) => {
23735
23730
  * @async
23736
23731
  */
23737
23732
  const joinRequest = async (communityId) => {
23733
+ var _a;
23738
23734
  const client = getActiveClient();
23739
23735
  client.log('community/joinRequest', communityId);
23740
23736
  const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
@@ -23742,8 +23738,17 @@ const joinRequest = async (communityId) => {
23742
23738
  const cachedAt = client.cache && Date.now();
23743
23739
  if (client.cache)
23744
23740
  ingestInCache(data, { cachedAt });
23745
- fireEvent('local.community.join', data.joinRequests);
23746
- const status = data.joinRequests.length === 0 ? "success" /* JoinResultStatusEnum.Success */ : "pending" /* JoinResultStatusEnum.Pending */;
23741
+ const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
23742
+ ? "success" /* JoinResultStatusEnum.Success */
23743
+ : "pending" /* JoinResultStatusEnum.Pending */;
23744
+ if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
23745
+ const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
23746
+ if (community) {
23747
+ const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
23748
+ upsertInCache(['community', 'get', communityId], updatedCommunity);
23749
+ }
23750
+ }
23751
+ fireEvent('v4.local.community.joined', data.joinRequests);
23747
23752
  return status === "success" /* JoinResultStatusEnum.Success */
23748
23753
  ? { status }
23749
23754
  : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
@@ -23817,12 +23822,12 @@ class QueryStreamController {
23817
23822
  }
23818
23823
  }
23819
23824
 
23820
- var EnumJoinRequestAction;
23825
+ var EnumJoinRequestAction$1;
23821
23826
  (function (EnumJoinRequestAction) {
23822
23827
  EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
23823
23828
  EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
23824
23829
  EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
23825
- })(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
23830
+ })(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
23826
23831
 
23827
23832
  class JoinRequestsQueryStreamController extends QueryStreamController {
23828
23833
  constructor(query, cacheKey, notifyChange, preparePayload) {
@@ -23862,12 +23867,12 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
23862
23867
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
23863
23868
  if (!collection)
23864
23869
  return;
23865
- if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
23870
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
23866
23871
  const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
23867
23872
  if (!isExist)
23868
23873
  return;
23869
23874
  }
23870
- if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
23875
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
23871
23876
  collection.data = [
23872
23877
  ...new Set([
23873
23878
  ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
@@ -23875,7 +23880,7 @@ class JoinRequestsQueryStreamController extends QueryStreamController {
23875
23880
  ]),
23876
23881
  ];
23877
23882
  }
23878
- if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
23883
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
23879
23884
  collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
23880
23885
  }
23881
23886
  pushToCache(this.cacheKey, collection);
@@ -24127,9 +24132,9 @@ class JoinRequestsLiveCollectionController extends LiveCollectionController {
24127
24132
  }
24128
24133
  startSubscription() {
24129
24134
  return this.queryStreamController.subscribeRTE([
24130
- { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
24131
- { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
24132
- { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
24135
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
24136
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
24137
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
24133
24138
  ]);
24134
24139
  }
24135
24140
  notifyChange({ origin, loading, error }) {
@@ -24707,9 +24712,7 @@ const communityLinkedObject = (community) => {
24707
24712
  }, getInvitation: async () => {
24708
24713
  const { data } = await getInvitation('community', community.communityId);
24709
24714
  return data;
24710
- }, join: async () => {
24711
- return joinRequest(community.communityId);
24712
- }, getJoinRequests: (params, callback) => {
24715
+ }, join: joinRequest(community.communityId), getJoinRequests: (params, callback) => {
24713
24716
  return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
24714
24717
  }, getMyJoinRequest: async () => {
24715
24718
  const { data } = await getMyJoinRequest(community.communityId);
@@ -35667,10 +35670,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
35667
35670
  const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
35668
35671
  const client = getActiveClient();
35669
35672
  client.log('community/getCommunities', communityIds);
35673
+ const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
35670
35674
  // API-FIX: endpoint should not be /list, parameters should be querystring.
35671
35675
  const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
35672
35676
  params: {
35673
- communityIds,
35677
+ communityIds: encodedCommunityIds,
35674
35678
  includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
35675
35679
  },
35676
35680
  });
@@ -36535,6 +36539,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
36535
36539
 
36536
36540
  const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
36537
36541
 
36542
+ const onLocalCommunityJoin = (callback) => {
36543
+ const client = getActiveClient();
36544
+ const filter = async (rawPayload) => {
36545
+ callback(rawPayload[0]);
36546
+ };
36547
+ const disposers = [
36548
+ createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
36549
+ ];
36550
+ return () => {
36551
+ disposers.forEach(fn => fn());
36552
+ };
36553
+ };
36554
+
36538
36555
  /**
36539
36556
  * ```js
36540
36557
  * import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
@@ -37021,7 +37038,8 @@ var index$d = /*#__PURE__*/Object.freeze({
37021
37038
  onCommunityJoined: onCommunityJoined,
37022
37039
  onCommunityLeft: onCommunityLeft,
37023
37040
  onLocalCommunityJoined: onLocalCommunityJoined,
37024
- onLocalCommunityLeft: onLocalCommunityLeft
37041
+ onLocalCommunityLeft: onLocalCommunityLeft,
37042
+ onLocalCommunityJoin: onLocalCommunityJoin
37025
37043
  });
37026
37044
 
37027
37045
  class SearchCommunityLiveCollectionController extends LiveCollectionController {
@@ -37245,6 +37263,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
37245
37263
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
37246
37264
  { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
37247
37265
  { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
37266
+ {
37267
+ fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
37268
+ action: EnumCommunityActions$3.OnCommunityUpdated,
37269
+ },
37248
37270
  ]);
37249
37271
  }
37250
37272
  notifyChange({ origin, loading, error }) {
@@ -37368,6 +37390,7 @@ const getCommunity = (communityId, callback) => {
37368
37390
  onCommunityUserBanned,
37369
37391
  onCommunityUserUnbanned,
37370
37392
  onCommunityUserChanged,
37393
+ convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
37371
37394
  ]);
37372
37395
  };
37373
37396
  /* end_public_function */
@@ -37884,6 +37907,200 @@ const semanticSearchCommunities = (params, callback, config) => {
37884
37907
  };
37885
37908
  };
37886
37909
 
37910
+ /**
37911
+ * TODO: handle cache receive cache option, and cache policy
37912
+ * TODO: check if querybyIds is supported
37913
+ */
37914
+ class JoinRequestListPaginationController extends PaginationController {
37915
+ async getRequest(queryParams, token) {
37916
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
37917
+ const options = token ? { token } : { limit };
37918
+ const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
37919
+ const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
37920
+ params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
37921
+ });
37922
+ return queryResponse;
37923
+ }
37924
+ }
37925
+
37926
+ var EnumJoinRequestAction;
37927
+ (function (EnumJoinRequestAction) {
37928
+ EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
37929
+ EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
37930
+ EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
37931
+ })(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
37932
+
37933
+ class JoinRequestListQueryStreamController extends QueryStreamController {
37934
+ constructor(query, cacheKey, notifyChange, preparePayload) {
37935
+ super(query, cacheKey);
37936
+ this.notifyChange = notifyChange;
37937
+ this.preparePayload = preparePayload;
37938
+ }
37939
+ async saveToMainDB(response) {
37940
+ const processedPayload = await this.preparePayload(response);
37941
+ const client = getActiveClient();
37942
+ const cachedAt = client.cache && Date.now();
37943
+ if (client.cache) {
37944
+ ingestInCache(processedPayload, { cachedAt });
37945
+ }
37946
+ }
37947
+ appendToQueryStream(response, direction, refresh = false) {
37948
+ var _a, _b;
37949
+ if (refresh) {
37950
+ pushToCache(this.cacheKey, {
37951
+ data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
37952
+ });
37953
+ }
37954
+ else {
37955
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37956
+ const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
37957
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
37958
+ ...new Set([
37959
+ ...joinRequests,
37960
+ ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
37961
+ ]),
37962
+ ] }));
37963
+ }
37964
+ }
37965
+ reactor(action) {
37966
+ return (joinRequest) => {
37967
+ var _a;
37968
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
37969
+ if (!collection)
37970
+ return;
37971
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
37972
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
37973
+ if (!isExist)
37974
+ return;
37975
+ }
37976
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
37977
+ collection.data = [
37978
+ ...new Set([
37979
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
37980
+ ...collection.data,
37981
+ ]),
37982
+ ];
37983
+ }
37984
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
37985
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
37986
+ }
37987
+ pushToCache(this.cacheKey, collection);
37988
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
37989
+ };
37990
+ }
37991
+ subscribeRTE(createSubscriber) {
37992
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
37993
+ }
37994
+ }
37995
+
37996
+ class JoinRequestListLiveCollectionController extends LiveCollectionController {
37997
+ constructor(query, callback) {
37998
+ const queryStreamId = hash(query);
37999
+ const cacheKey = ['joinRequestList', 'collection', queryStreamId];
38000
+ const paginationController = new JoinRequestListPaginationController(query);
38001
+ super(paginationController, queryStreamId, cacheKey, callback);
38002
+ this.query = query;
38003
+ this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
38004
+ this.callback = callback.bind(this);
38005
+ this.loadPage({ initial: true });
38006
+ }
38007
+ setup() {
38008
+ var _a;
38009
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38010
+ if (!collection) {
38011
+ pushToCache(this.cacheKey, {
38012
+ data: [],
38013
+ params: this.query,
38014
+ });
38015
+ }
38016
+ }
38017
+ async persistModel(queryPayload) {
38018
+ await this.queryStreamController.saveToMainDB(queryPayload);
38019
+ }
38020
+ persistQueryStream({ response, direction, refresh, }) {
38021
+ const joinRequestResponse = response;
38022
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
38023
+ }
38024
+ startSubscription() {
38025
+ return this.queryStreamController.subscribeRTE([
38026
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
38027
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
38028
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
38029
+ ]);
38030
+ }
38031
+ notifyChange({ origin, loading, error }) {
38032
+ var _a;
38033
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
38034
+ if (!collection)
38035
+ return;
38036
+ const data = this.applyFilter(collection.data
38037
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
38038
+ .filter(isNonNullable)
38039
+ .map(({ data }) => data)
38040
+ .map(joinRequestLinkedObject));
38041
+ if (!this.shouldNotify(data) && origin === 'event')
38042
+ return;
38043
+ this.callback({
38044
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
38045
+ data,
38046
+ hasNextPage: !!this.paginationController.getNextToken(),
38047
+ loading,
38048
+ error,
38049
+ });
38050
+ }
38051
+ applyFilter(data) {
38052
+ let joinRequest = data;
38053
+ if (this.query.communityIds && this.query.communityIds.length > 0) {
38054
+ joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
38055
+ }
38056
+ const sortFn = (() => {
38057
+ switch (this.query.sortBy) {
38058
+ case 'firstCreated':
38059
+ return sortByFirstCreated;
38060
+ case 'lastCreated':
38061
+ return sortByLastCreated;
38062
+ default:
38063
+ return sortByLastCreated;
38064
+ }
38065
+ })();
38066
+ joinRequest = joinRequest.sort(sortFn);
38067
+ return joinRequest;
38068
+ }
38069
+ }
38070
+
38071
+ /* begin_public_function
38072
+ id: community.getJoinRequestList
38073
+ */
38074
+ /**
38075
+ * Get Join Requests
38076
+ *
38077
+ * @param params the query parameters
38078
+ * @param callback the callback to be called when the join request are updated
38079
+ * @returns joinRequest[]
38080
+ *
38081
+ * @category joinRequestList Live Collection
38082
+ *
38083
+ */
38084
+ const getJoinRequestList = (params, callback, config) => {
38085
+ const { log, cache } = getActiveClient();
38086
+ if (!cache) {
38087
+ console.log(ENABLE_CACHE_MESSAGE);
38088
+ }
38089
+ const timestamp = Date.now();
38090
+ log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
38091
+ const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
38092
+ const disposers = joinRequestListLiveCollection.startSubscription();
38093
+ const cacheKey = joinRequestListLiveCollection.getCacheKey();
38094
+ disposers.push(() => {
38095
+ dropFromCache(cacheKey);
38096
+ });
38097
+ return () => {
38098
+ log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
38099
+ disposers.forEach(fn => fn());
38100
+ };
38101
+ };
38102
+ /* end_public_function */
38103
+
37887
38104
  var AmityCommunityMemberStatusFilter;
37888
38105
  (function (AmityCommunityMemberStatusFilter) {
37889
38106
  AmityCommunityMemberStatusFilter["ALL"] = "all";
@@ -38054,6 +38271,7 @@ var index$b = /*#__PURE__*/Object.freeze({
38054
38271
  getTrendingCommunities: getTrendingCommunities,
38055
38272
  getRecommendedCommunities: getRecommendedCommunities,
38056
38273
  semanticSearchCommunities: semanticSearchCommunities,
38274
+ getJoinRequestList: getJoinRequestList,
38057
38275
  get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
38058
38276
  });
38059
38277