@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.
Files changed (101) hide show
  1. package/dist/@types/core/events.d.ts +4 -0
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/core/model.d.ts +2 -0
  4. package/dist/@types/core/model.d.ts.map +1 -1
  5. package/dist/@types/core/payload.d.ts +16 -1
  6. package/dist/@types/core/payload.d.ts.map +1 -1
  7. package/dist/@types/domains/community.d.ts +28 -2
  8. package/dist/@types/domains/community.d.ts.map +1 -1
  9. package/dist/@types/domains/joinRequest.d.ts +53 -0
  10. package/dist/@types/domains/joinRequest.d.ts.map +1 -0
  11. package/dist/@types/index.d.ts +1 -0
  12. package/dist/@types/index.d.ts.map +1 -1
  13. package/dist/communityRepository/api/getCommunity.d.ts +1 -1
  14. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  15. package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
  16. package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
  17. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
  18. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
  19. package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
  20. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
  21. package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
  22. package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
  23. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
  24. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
  25. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
  26. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
  27. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
  28. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
  29. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
  30. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
  31. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
  32. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
  33. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
  34. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
  35. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
  36. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
  37. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
  38. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
  39. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
  40. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
  41. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
  42. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
  43. package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
  44. package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
  45. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
  46. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
  47. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
  48. package/dist/communityRepository/utils/payload.d.ts +1 -0
  49. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  50. package/dist/core/events.d.ts +3 -3
  51. package/dist/core/events.d.ts.map +1 -1
  52. package/dist/core/model/idResolvers.d.ts.map +1 -1
  53. package/dist/core/model/index.d.ts.map +1 -1
  54. package/dist/index.cjs.js +897 -389
  55. package/dist/index.esm.js +760 -252
  56. package/dist/index.umd.js +4 -4
  57. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
  58. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  59. package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
  60. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  61. package/dist/utils/linkedObject/index.d.ts +1 -0
  62. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  63. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
  64. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
  65. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  66. package/package.json +1 -1
  67. package/src/@types/core/events.ts +7 -1
  68. package/src/@types/core/model.ts +3 -0
  69. package/src/@types/core/payload.ts +22 -1
  70. package/src/@types/domains/community.ts +38 -2
  71. package/src/@types/domains/joinRequest.ts +66 -0
  72. package/src/@types/index.ts +1 -0
  73. package/src/communityRepository/api/getCommunity.ts +8 -0
  74. package/src/communityRepository/api/joinCommunity.ts +4 -1
  75. package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
  76. package/src/communityRepository/internalAPI/joinCommunity.ts +51 -0
  77. package/src/communityRepository/joinRequest/events/index.ts +3 -0
  78. package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
  79. package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
  80. package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
  81. package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
  82. package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
  83. package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
  84. package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
  85. package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
  86. package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
  87. package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
  88. package/src/communityRepository/observers/getJoinRequests.ts +44 -0
  89. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
  90. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
  91. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
  92. package/src/communityRepository/utils/communityWithMembership.ts +1 -1
  93. package/src/communityRepository/utils/payload.ts +27 -1
  94. package/src/core/model/idResolvers.ts +1 -0
  95. package/src/core/model/index.ts +1 -0
  96. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
  97. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
  98. package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
  99. package/src/utils/linkedObject/communityLinkedObject.ts +22 -0
  100. package/src/utils/linkedObject/index.ts +2 -0
  101. package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
package/dist/index.cjs.js CHANGED
@@ -136,6 +136,19 @@ exports.InvitationSortByEnum = void 0;
136
136
  InvitationSortByEnum["LastCreated"] = "lastCreated";
137
137
  })(exports.InvitationSortByEnum || (exports.InvitationSortByEnum = {}));
138
138
 
139
+ exports.JoinRequestStatusEnum = void 0;
140
+ (function (JoinRequestStatusEnum) {
141
+ JoinRequestStatusEnum["Pending"] = "pending";
142
+ JoinRequestStatusEnum["Approved"] = "approved";
143
+ JoinRequestStatusEnum["Rejected"] = "rejected";
144
+ JoinRequestStatusEnum["Cancelled"] = "cancelled";
145
+ })(exports.JoinRequestStatusEnum || (exports.JoinRequestStatusEnum = {}));
146
+ exports.JoinResultStatusEnum = void 0;
147
+ (function (JoinResultStatusEnum) {
148
+ JoinResultStatusEnum["Success"] = "success";
149
+ JoinResultStatusEnum["Pending"] = "pending";
150
+ })(exports.JoinResultStatusEnum || (exports.JoinResultStatusEnum = {}));
151
+
139
152
  function getVersion() {
140
153
  try {
141
154
  // the string ''v7.4.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
@@ -583,6 +596,7 @@ const idResolvers = {
583
596
  notificationTrayItem: ({ _id }) => _id,
584
597
  notificationTraySeen: ({ userId }) => userId,
585
598
  invitation: ({ _id }) => _id,
599
+ joinRequest: ({ joinRequestId }) => joinRequestId,
586
600
  };
587
601
  /**
588
602
  * Retrieve the id resolver matching a domain name
@@ -636,6 +650,7 @@ const PAYLOAD2MODEL = {
636
650
  pins: 'pin',
637
651
  notificationTrayItems: 'notificationTrayItem',
638
652
  invitations: 'invitation',
653
+ joinRequests: 'joinRequest',
639
654
  };
640
655
  /** hidden */
641
656
  const isOutdated = (prevData, nextData) => {
@@ -5467,6 +5482,10 @@ function convertQueryParams$1(_a) {
5467
5482
  return out;
5468
5483
  }
5469
5484
 
5485
+ function convertRawUserToInternalUser(rawUser) {
5486
+ return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
5487
+ }
5488
+
5470
5489
  const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
5471
5490
  /**
5472
5491
  * Filter sub channel by type. Only conversation, community and broadcast type are included.
@@ -5495,8 +5514,9 @@ const prepareSubChannelPayload = async (rawPayload) => {
5495
5514
  // attach marker to sub channel
5496
5515
  const messageFeeds = rawPayload.messageFeeds.map(convertFromRaw$2);
5497
5516
  const messages = rawPayload.messages.map(m => convertFromRaw$1(m));
5517
+ const user = rawPayload.users.map(convertRawUserToInternalUser);
5498
5518
  return Object.assign(Object.assign({}, rawPayload), { messageFeeds,
5499
- messages });
5519
+ messages, users: user });
5500
5520
  };
5501
5521
  function convertQueryParams(_a) {
5502
5522
  var { excludeDefaultSubChannel } = _a, rest = __rest(_a, ["excludeDefaultSubChannel"]);
@@ -5761,10 +5781,6 @@ const handleSubChannelUpdated = async (subChannel) => {
5761
5781
  }
5762
5782
  };
5763
5783
 
5764
- function convertRawUserToInternalUser(rawUser) {
5765
- return Object.assign(Object.assign({}, rawUser), { isGlobalBanned: (rawUser === null || rawUser === void 0 ? void 0 : rawUser.isGlobalBan) || false });
5766
- }
5767
-
5768
5784
  const MARKER_INCLUDED_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
5769
5785
  const isUnreadCountSupport = ({ type }) => MARKER_INCLUDED_CHANNEL_TYPE.includes(type);
5770
5786
  function convertFromRaw(channel, options = { isMessagePreviewUpdated: true }) {
@@ -7354,245 +7370,307 @@ const notificationTrayLinkedObject = (noti) => {
7354
7370
  .map(user => userLinkedObject(user)) });
7355
7371
  };
7356
7372
 
7357
- const convertRawInvitationToInternalInvitation = (rawInvitation) => {
7358
- return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
7359
- };
7360
-
7361
- const prepareInvitationPayload = (rawPayload) => {
7362
- return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
7363
- };
7364
-
7365
- /* begin_public_function
7366
- id: invitation.createInvitations
7367
- */
7368
- /**
7369
- * ```js
7370
- * import { createInvitations } from '@amityco/ts-sdk'
7371
- * const created = await createInvitations({
7372
- * type: string,
7373
- * targetType: string,
7374
- * targetId: string,
7375
- * userIds: string[]
7376
- * }))
7377
- * ```
7378
- *
7379
- * Creates an {@link Amity.Invitation}
7380
- *
7381
- * @param bundle The data necessary to create a new {@link Amity.Invitation}
7382
- * @returns The newly created {@link Amity.Invitation}
7373
+ /*
7374
+ * verifies membership status
7375
+ */
7376
+ function isMember(membership) {
7377
+ return membership !== 'none';
7378
+ }
7379
+ /*
7380
+ * checks if currently logged in user is part of the community
7381
+ */
7382
+ function isCurrentUserPartOfCommunity(c, m) {
7383
+ const { userId } = getActiveUser();
7384
+ return c.communityId === m.communityId && m.userId === userId;
7385
+ }
7386
+ /*
7387
+ * For mqtt events server will not send user specific data as it's broadcasted
7388
+ * to multiple users and it also does not include communityUser
7383
7389
  *
7384
- * @category Invitation API
7385
- * @async
7390
+ * Client SDK needs to check for the existing isJoined field in cache data before calculating.
7391
+ * Althought this can be calculated, it's not scalable.
7386
7392
  */
7387
- const createInvitations = async (bundle) => {
7388
- const client = getActiveClient();
7389
- client.log('invitation/createInvitations', bundle);
7390
- const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
7391
- const data = prepareInvitationPayload(payload);
7392
- const cachedAt = client.cache && Date.now();
7393
- if (client.cache)
7394
- ingestInCache(data, { cachedAt });
7395
- fireEvent('local.invitation.created', data.invitations);
7396
- return {
7397
- data: data.invitations,
7398
- cachedAt,
7399
- };
7393
+ function updateMembershipStatus(communities, communityUsers) {
7394
+ return communities.map(c => {
7395
+ const cachedCommunity = pullFromCache([
7396
+ 'community',
7397
+ 'get',
7398
+ c.communityId,
7399
+ ]);
7400
+ if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
7401
+ return Object.assign(Object.assign({}, cachedCommunity.data), c);
7402
+ }
7403
+ const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
7404
+ return Object.assign(Object.assign({}, c), { isJoined });
7405
+ });
7406
+ }
7407
+
7408
+ const getMatchPostSetting = (value) => {
7409
+ var _a;
7410
+ return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
7411
+ CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
7412
+ value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
7400
7413
  };
7401
- /* end_public_function */
7414
+ function addPostSetting({ communities }) {
7415
+ return communities.map((_a) => {
7416
+ var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
7417
+ return (Object.assign({ postSetting: getMatchPostSetting({
7418
+ needApprovalOnPostCreation,
7419
+ onlyAdminCanPost,
7420
+ }) }, restCommunityPayload));
7421
+ });
7422
+ }
7423
+ const prepareCommunityPayload = (rawPayload) => {
7424
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
7425
+ // Convert users to internal format
7426
+ const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
7427
+ // map users with community
7428
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
7429
+ const user = internalUsers.find(user => user.userId === communityUser.userId);
7430
+ return Object.assign(Object.assign({}, communityUser), { user });
7431
+ });
7432
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
7433
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
7434
+ };
7435
+ const prepareCommunityJoinRequestPayload = (rawPayload) => {
7436
+ const mappedJoinRequests = rawPayload.joinRequests.map(joinRequest => {
7437
+ return Object.assign(Object.assign({}, joinRequest), { joinRequestId: joinRequest._id });
7438
+ });
7439
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
7440
+ return Object.assign(Object.assign({}, rawPayload), { joinRequests: mappedJoinRequests, users });
7441
+ };
7442
+ const prepareCommunityMembershipPayload = (rawPayload) => {
7443
+ const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
7444
+ // map users with community
7445
+ const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
7446
+ const user = rawPayload.users.find(user => user.userId === communityUser.userId);
7447
+ return Object.assign(Object.assign({}, communityUser), { user });
7448
+ });
7449
+ const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
7450
+ return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
7451
+ };
7452
+ const prepareCommunityRequest = (params) => {
7453
+ const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
7454
+ return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
7455
+ // Convert story setting to the actual value. (Allow by default)
7456
+ allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
7457
+ };
7458
+ const prepareSemanticSearchCommunityPayload = (_a) => {
7459
+ var communityPayload = __rest(_a, ["searchResult"]);
7460
+ const processedCommunityPayload = prepareCommunityPayload(communityPayload);
7461
+ return Object.assign({}, processedCommunityPayload);
7462
+ };
7402
7463
 
7403
7464
  /* begin_public_function
7404
- id: invitation.accept
7465
+ id: joinRequest.approve
7405
7466
  */
7406
7467
  /**
7407
7468
  * ```js
7408
- * import { acceptInvitation } from '@amityco/ts-sdk'
7409
- * const isAccepted = await acceptInvitation(invitationId)
7469
+ * import { joinRequest } from '@amityco/ts-sdk'
7470
+ * const isAccepted = await joinRequest.approve()
7410
7471
  * ```
7411
7472
  *
7412
- * Accepts a {@link Amity.Invitation} object
7473
+ * Accepts a {@link Amity.JoinRequest} object
7413
7474
  *
7414
- * @param invitationId the {@link Amity.Invitation} to accept
7415
- * @returns A success boolean if the {@link Amity.Invitation} was accepted
7475
+ * @param joinRequest the {@link Amity.JoinRequest} to accept
7476
+ * @returns A success boolean if the {@link Amity.JoinRequest} was accepted
7416
7477
  *
7417
- * @category Invitation API
7478
+ * @category Join Request API
7418
7479
  * @async
7419
7480
  */
7420
- const acceptInvitation = async (invitationId) => {
7481
+ const approveJoinRequest = async (joinRequest) => {
7421
7482
  var _a;
7422
7483
  const client = getActiveClient();
7423
- client.log('invitation/acceptInvitation', invitationId);
7424
- const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
7425
- const invitation = (_a = pullFromCache([
7426
- 'invitation',
7484
+ client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
7485
+ const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/approve`, {
7486
+ userId: joinRequest.requestorInternalId,
7487
+ });
7488
+ const joinRequestCache = (_a = pullFromCache([
7489
+ 'joinRequest',
7427
7490
  'get',
7428
- invitationId,
7491
+ joinRequest.joinRequestId,
7429
7492
  ])) === null || _a === void 0 ? void 0 : _a.data;
7430
- if (invitation) {
7431
- upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
7432
- fireEvent('local.invitation.updated', [invitation]);
7493
+ if (joinRequestCache) {
7494
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
7495
+ status: "approved" /* JoinRequestStatusEnum.Approved */,
7496
+ });
7497
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
7433
7498
  }
7434
7499
  return data.success;
7435
7500
  };
7436
7501
  /* end_public_function */
7437
7502
 
7438
7503
  /* begin_public_function
7439
- id: invitation.reject
7504
+ id: joinRequest.cancel
7440
7505
  */
7441
7506
  /**
7442
7507
  * ```js
7443
- * import { rejectInvitation } from '@amityco/ts-sdk'
7444
- * const isRejected = await rejectInvitation(invitationId)
7508
+ * import { joinRequest } from '@amityco/ts-sdk'
7509
+ * const isCanceled = await joinRequest.cancel()
7445
7510
  * ```
7446
7511
  *
7447
- * Rejects a {@link Amity.Invitation} object
7512
+ * Cancels a {@link Amity.JoinRequest} object
7448
7513
  *
7449
- * @param invitationId the {@link Amity.Invitation} to reject
7450
- * @returns A success boolean if the {@link Amity.Invitation} was rejected
7514
+ * @param joinRequest the {@link Amity.JoinRequest} to cancel
7515
+ * @returns A success boolean if the {@link Amity.JoinRequest} was canceled
7451
7516
  *
7452
- * @category Invitation API
7517
+ * @category Join Request API
7453
7518
  * @async
7454
7519
  */
7455
- const rejectInvitation = async (invitationId) => {
7520
+ const cancelJoinRequest = async (joinRequest) => {
7456
7521
  var _a;
7457
7522
  const client = getActiveClient();
7458
- client.log('invitation/rejectInvitation', invitationId);
7459
- const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
7460
- const invitation = (_a = pullFromCache([
7461
- 'invitation',
7523
+ client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
7524
+ const { data } = await client.http.delete(`/api/v4/communities/${joinRequest.targetId}/join`);
7525
+ const joinRequestCache = (_a = pullFromCache([
7526
+ 'joinRequest',
7462
7527
  'get',
7463
- invitationId,
7528
+ joinRequest.joinRequestId,
7464
7529
  ])) === null || _a === void 0 ? void 0 : _a.data;
7465
- if (invitation) {
7466
- upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
7467
- fireEvent('local.invitation.updated', [invitation]);
7530
+ if (joinRequestCache) {
7531
+ dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
7532
+ fireEvent('local.joinRequest.deleted', [joinRequestCache]);
7468
7533
  }
7469
7534
  return data.success;
7470
7535
  };
7471
7536
  /* end_public_function */
7472
7537
 
7473
7538
  /* begin_public_function
7474
- id: invitation.cancel
7539
+ id: joinRequest.reject
7475
7540
  */
7476
7541
  /**
7477
7542
  * ```js
7478
- * import { cancelInvitation } from '@amityco/ts-sdk'
7479
- * const isCanceled = await cancelInvitation(invitationId)
7543
+ * import { joinRequest } from '@amityco/ts-sdk'
7544
+ * const isRejected = await joinRequest.reject()
7480
7545
  * ```
7481
7546
  *
7482
- * Cancels a {@link Amity.Invitation} object
7547
+ * Rejects a {@link Amity.JoinRequest} object
7483
7548
  *
7484
- * @param invitationId the {@link Amity.Invitation} to cancel
7485
- * @returns A success boolean if the {@link Amity.Invitation} was canceled
7549
+ * @param joinRequest the {@link Amity.JoinRequest} to reject
7550
+ * @returns A success boolean if the {@link Amity.JoinRequest} was rejected
7486
7551
  *
7487
- * @category Invitation API
7552
+ * @category Join Request API
7488
7553
  * @async
7489
7554
  */
7490
- const cancelInvitation = async (invitationId) => {
7555
+ const rejectJoinRequest = async (joinRequest) => {
7491
7556
  var _a;
7492
7557
  const client = getActiveClient();
7493
- client.log('invitation/cancelInvitation', invitationId);
7494
- const { data } = await client.http.delete(`/api/v1/invitations/${invitationId}`);
7495
- const invitation = (_a = pullFromCache([
7496
- 'invitation',
7558
+ client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
7559
+ const { data } = await client.http.post(`/api/v4/communities/${joinRequest.targetId}/join/reject`, {
7560
+ userId: joinRequest.requestorInternalId,
7561
+ });
7562
+ const joinRequestCache = (_a = pullFromCache([
7563
+ 'joinRequest',
7497
7564
  'get',
7498
- invitationId,
7565
+ joinRequest.joinRequestId,
7499
7566
  ])) === null || _a === void 0 ? void 0 : _a.data;
7500
- if (invitation) {
7501
- dropFromCache(['invitation', 'get', invitationId]);
7502
- fireEvent('local.invitation.deleted', [invitation]);
7567
+ if (joinRequestCache) {
7568
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
7569
+ status: "rejected" /* JoinRequestStatusEnum.Rejected */,
7570
+ });
7571
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
7503
7572
  }
7504
7573
  return data.success;
7505
7574
  };
7506
7575
  /* end_public_function */
7507
7576
 
7508
- const prepareMyInvitationsPayload = (rawPayload) => {
7509
- return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
7510
- };
7511
-
7512
- const invitationLinkedObject = (invitation) => {
7513
- return Object.assign(Object.assign({}, invitation), { get user() {
7514
- const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
7515
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
7516
- return userLinkedObject(cacheData.data);
7517
- return undefined;
7518
- },
7519
- get createdBy() {
7520
- const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
7521
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
7522
- return userLinkedObject(cacheData.data);
7523
- return undefined;
7524
- },
7525
- get target() {
7526
- if (invitation.targetType === 'community') {
7527
- const cacheData = pullFromCache([
7528
- 'community',
7529
- 'get',
7530
- invitation.targetId,
7531
- ]);
7532
- if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
7533
- return cacheData.data;
7577
+ const joinRequestLinkedObject = (joinRequest) => {
7578
+ return Object.assign(Object.assign({}, joinRequest), { get user() {
7579
+ var _a;
7580
+ const user = (_a = pullFromCache([
7581
+ 'user',
7582
+ 'get',
7583
+ joinRequest.requestorPublicId,
7584
+ ])) === null || _a === void 0 ? void 0 : _a.data;
7585
+ if (!user)
7534
7586
  return undefined;
7535
- }
7536
- return undefined;
7537
- }, accept: async () => {
7538
- await acceptInvitation(invitation._id);
7539
- }, reject: async () => {
7540
- await rejectInvitation(invitation._id);
7587
+ return userLinkedObject(user);
7541
7588
  }, cancel: async () => {
7542
- await cancelInvitation(invitation._id);
7589
+ await cancelJoinRequest(joinRequest);
7590
+ }, approve: async () => {
7591
+ await approveJoinRequest(joinRequest);
7592
+ }, reject: async () => {
7593
+ await rejectJoinRequest(joinRequest);
7543
7594
  } });
7544
7595
  };
7545
7596
 
7546
7597
  /* begin_public_function
7547
- id: invitation.get
7598
+ id: community.getMyJoinRequest
7548
7599
  */
7549
7600
  /**
7550
7601
  * ```js
7551
- * import { getInvitation } from '@amityco/ts-sdk'
7552
- * const { invitation } = await getInvitation(targetType, targetId)
7602
+ * import { community } from '@amityco/ts-sdk'
7603
+ * const isJoined = await community.getMyJoinRequest('foobar')
7553
7604
  * ```
7554
7605
  *
7555
- * Get a {@link Amity.Invitation} object
7606
+ * Joins a {@link Amity.Community} object
7556
7607
  *
7557
- * @param targetType The type of the target of the {@link Amity.Invitation}
7558
- * @param targetId The ID of the target of the {@link Amity.Invitation}
7559
- * @returns A {@link Amity.Invitation} object
7608
+ * @param communityId the {@link Amity.Community} to join
7609
+ * @returns A success boolean if the {@link Amity.Community} was joined
7560
7610
  *
7561
- * @category Invitation API
7611
+ * @category Community API
7562
7612
  * @async
7563
7613
  */
7564
- const getInvitation = async (targetType, targetId) => {
7614
+ const getMyJoinRequest = async (communityId) => {
7565
7615
  const client = getActiveClient();
7566
- client.log('invitation/getInvitation', targetType, targetId);
7567
- const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
7568
- const data = prepareMyInvitationsPayload(payload);
7616
+ client.log('community/myJoinRequest', communityId);
7617
+ const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
7618
+ const data = prepareCommunityJoinRequestPayload(payload);
7569
7619
  const cachedAt = client.cache && Date.now();
7570
7620
  if (client.cache)
7571
7621
  ingestInCache(data, { cachedAt });
7572
7622
  return {
7573
- data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
7623
+ data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
7574
7624
  cachedAt,
7575
7625
  };
7576
7626
  };
7577
7627
  /* end_public_function */
7578
7628
 
7579
- var InvitationActionsEnum;
7580
- (function (InvitationActionsEnum) {
7581
- InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
7582
- InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
7583
- InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
7584
- })(InvitationActionsEnum || (InvitationActionsEnum = {}));
7585
-
7586
- class PaginationController {
7587
- constructor(queryParams) {
7588
- const { http } = getActiveClient();
7589
- this.queryParams = queryParams;
7590
- this.http = http;
7591
- }
7592
- loadFirstPage() {
7593
- return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
7594
- }
7595
- loadNextPage() {
7629
+ /* begin_public_function
7630
+ id: community.join
7631
+ */
7632
+ /**
7633
+ * ```js
7634
+ * import { community } from '@amityco/ts-sdk'
7635
+ * const isJoined = await community.join('foobar')
7636
+ * ```
7637
+ *
7638
+ * Joins a {@link Amity.Community} object
7639
+ *
7640
+ * @param communityId the {@link Amity.Community} to join
7641
+ * @returns A status join result
7642
+ *
7643
+ * @category Community API
7644
+ * @async
7645
+ */
7646
+ const joinRequest = async (communityId) => {
7647
+ const client = getActiveClient();
7648
+ client.log('community/joinRequest', communityId);
7649
+ const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
7650
+ const data = prepareCommunityJoinRequestPayload(payload);
7651
+ const cachedAt = client.cache && Date.now();
7652
+ if (client.cache)
7653
+ ingestInCache(data, { cachedAt });
7654
+ fireEvent('local.community.join', data.joinRequests);
7655
+ const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
7656
+ ? "success" /* JoinResultStatusEnum.Success */
7657
+ : "pending" /* JoinResultStatusEnum.Pending */;
7658
+ return status === "success" /* JoinResultStatusEnum.Success */
7659
+ ? { status }
7660
+ : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
7661
+ };
7662
+ /* end_public_function */
7663
+
7664
+ class PaginationController {
7665
+ constructor(queryParams) {
7666
+ const { http } = getActiveClient();
7667
+ this.queryParams = queryParams;
7668
+ this.http = http;
7669
+ }
7670
+ loadFirstPage() {
7671
+ return this.onFetch("first" /* Amity.LiveCollectionPageDirection.FIRST */);
7672
+ }
7673
+ loadNextPage() {
7596
7674
  return this.onFetch("next" /* Amity.LiveCollectionPageDirection.NEXT */);
7597
7675
  }
7598
7676
  loadPreviousPage() {
@@ -7628,6 +7706,641 @@ class PaginationController {
7628
7706
  }
7629
7707
  }
7630
7708
 
7709
+ /**
7710
+ * TODO: handle cache receive cache option, and cache policy
7711
+ * TODO: check if querybyIds is supported
7712
+ */
7713
+ class JoinRequestsPaginationController extends PaginationController {
7714
+ async getRequest(queryParams, token) {
7715
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
7716
+ const options = token ? { token } : { limit };
7717
+ const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
7718
+ params: Object.assign(Object.assign({}, params), { options }),
7719
+ });
7720
+ return queryResponse;
7721
+ }
7722
+ }
7723
+
7724
+ class QueryStreamController {
7725
+ constructor(query, cacheKey) {
7726
+ this.query = query;
7727
+ this.cacheKey = cacheKey;
7728
+ }
7729
+ }
7730
+
7731
+ var EnumJoinRequestAction;
7732
+ (function (EnumJoinRequestAction) {
7733
+ EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
7734
+ EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
7735
+ EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
7736
+ })(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
7737
+
7738
+ class JoinRequestsQueryStreamController extends QueryStreamController {
7739
+ constructor(query, cacheKey, notifyChange, preparePayload) {
7740
+ super(query, cacheKey);
7741
+ this.notifyChange = notifyChange;
7742
+ this.preparePayload = preparePayload;
7743
+ }
7744
+ async saveToMainDB(response) {
7745
+ const processedPayload = await this.preparePayload(response);
7746
+ const client = getActiveClient();
7747
+ const cachedAt = client.cache && Date.now();
7748
+ if (client.cache) {
7749
+ ingestInCache(processedPayload, { cachedAt });
7750
+ }
7751
+ }
7752
+ appendToQueryStream(response, direction, refresh = false) {
7753
+ var _a, _b;
7754
+ if (refresh) {
7755
+ pushToCache(this.cacheKey, {
7756
+ data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
7757
+ });
7758
+ }
7759
+ else {
7760
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
7761
+ const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
7762
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
7763
+ ...new Set([
7764
+ ...joinRequests,
7765
+ ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
7766
+ ]),
7767
+ ] }));
7768
+ }
7769
+ }
7770
+ reactor(action) {
7771
+ return (joinRequest) => {
7772
+ var _a;
7773
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
7774
+ if (!collection)
7775
+ return;
7776
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
7777
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
7778
+ if (!isExist)
7779
+ return;
7780
+ }
7781
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
7782
+ collection.data = [
7783
+ ...new Set([
7784
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
7785
+ ...collection.data,
7786
+ ]),
7787
+ ];
7788
+ }
7789
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
7790
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
7791
+ }
7792
+ pushToCache(this.cacheKey, collection);
7793
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
7794
+ };
7795
+ }
7796
+ subscribeRTE(createSubscriber) {
7797
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
7798
+ }
7799
+ }
7800
+
7801
+ function isObject(value) {
7802
+ return typeof value === 'object' && value !== null;
7803
+ }
7804
+ /**
7805
+ * convert all object getter property to static value
7806
+ */
7807
+ const convertGetterPropsToStatic = (obj) => {
7808
+ if (!isObject(obj)) {
7809
+ return obj;
7810
+ }
7811
+ const entries = Object.entries(obj).map(([key, value]) => {
7812
+ const descriptor = Object.getOwnPropertyDescriptor(obj, key);
7813
+ if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
7814
+ return [key, descriptor.get.call(obj)];
7815
+ }
7816
+ return [key, value];
7817
+ });
7818
+ return Object.fromEntries(entries);
7819
+ };
7820
+ const removeFunctionProperties = (obj) => {
7821
+ if (!isObject(obj)) {
7822
+ return obj;
7823
+ }
7824
+ const entries = Object.entries(obj).map(([key, value]) => {
7825
+ if (typeof value === 'function') {
7826
+ return [key, undefined];
7827
+ }
7828
+ return [key, value];
7829
+ });
7830
+ return Object.fromEntries(entries);
7831
+ };
7832
+
7833
+ class PaginationNoPageController {
7834
+ constructor(queryParams) {
7835
+ const { http } = getActiveClient();
7836
+ this.queryParams = queryParams;
7837
+ this.http = http;
7838
+ }
7839
+ async onFetch() {
7840
+ const queryResponse = await this.getRequest(this.queryParams);
7841
+ return queryResponse;
7842
+ }
7843
+ }
7844
+
7845
+ class LiveCollectionController {
7846
+ constructor(paginationController, queryStreamId, cacheKey, callback) {
7847
+ this.paginationController = paginationController;
7848
+ this.queryStreamId = queryStreamId;
7849
+ this.cacheKey = cacheKey;
7850
+ this.callback = callback;
7851
+ }
7852
+ async refresh() {
7853
+ try {
7854
+ let result;
7855
+ if (this.paginationController instanceof PaginationNoPageController) {
7856
+ result = await this.paginationController.onFetch();
7857
+ }
7858
+ else {
7859
+ result = await this.paginationController.loadFirstPage();
7860
+ }
7861
+ if (!result)
7862
+ return;
7863
+ await this.persistModel(result);
7864
+ this.persistQueryStream({
7865
+ response: result,
7866
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
7867
+ refresh: true,
7868
+ });
7869
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7870
+ }
7871
+ catch (e) {
7872
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7873
+ }
7874
+ }
7875
+ loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
7876
+ this.setup();
7877
+ this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
7878
+ if (initial) {
7879
+ this.refresh();
7880
+ }
7881
+ else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
7882
+ this.loadPrevPage();
7883
+ }
7884
+ else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
7885
+ this.loadNextPage();
7886
+ }
7887
+ }
7888
+ async loadNextPage() {
7889
+ try {
7890
+ if (this.paginationController instanceof PaginationNoPageController)
7891
+ return;
7892
+ const result = await this.paginationController.loadNextPage();
7893
+ if (!result)
7894
+ return;
7895
+ await this.persistModel(result);
7896
+ this.persistQueryStream({
7897
+ response: result,
7898
+ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
7899
+ });
7900
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7901
+ }
7902
+ catch (e) {
7903
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7904
+ }
7905
+ }
7906
+ async loadPrevPage() {
7907
+ try {
7908
+ if (this.paginationController instanceof PaginationNoPageController)
7909
+ return;
7910
+ const result = await this.paginationController.loadPreviousPage();
7911
+ if (!result)
7912
+ return;
7913
+ await this.persistModel(result);
7914
+ this.persistQueryStream({
7915
+ response: result,
7916
+ direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
7917
+ });
7918
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7919
+ }
7920
+ catch (e) {
7921
+ this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7922
+ }
7923
+ }
7924
+ shouldNotify(data) {
7925
+ const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
7926
+ if (isEqual(this.snapshot, newData))
7927
+ return false;
7928
+ this.snapshot = newData;
7929
+ return true;
7930
+ }
7931
+ getCacheKey() {
7932
+ return this.cacheKey;
7933
+ }
7934
+ }
7935
+
7936
+ /**
7937
+ * ```js
7938
+ * import { onJoinRequestCreated } from '@amityco/ts-sdk'
7939
+ * const dispose = onJoinRequestCreated(data => {
7940
+ * // ...
7941
+ * })
7942
+ * ```
7943
+ *
7944
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7945
+ *
7946
+ * @param callback The function to call when the event was fired
7947
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
7948
+ *
7949
+ * @category JoinRequest Events
7950
+ */
7951
+ const onJoinRequestCreated = (callback) => {
7952
+ const client = getActiveClient();
7953
+ const disposers = [
7954
+ createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
7955
+ ];
7956
+ return () => {
7957
+ disposers.forEach(fn => fn());
7958
+ };
7959
+ };
7960
+
7961
+ /**
7962
+ * ```js
7963
+ * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
7964
+ * const dispose = onJoinRequestUpdated(data => {
7965
+ * // ...
7966
+ * })
7967
+ * ```
7968
+ *
7969
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7970
+ *
7971
+ * @param callback The function to call when the event was fired
7972
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
7973
+ *
7974
+ * @category JoinRequest Events
7975
+ */
7976
+ const onJoinRequestUpdated = (callback) => {
7977
+ const client = getActiveClient();
7978
+ const disposers = [
7979
+ createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
7980
+ ];
7981
+ return () => {
7982
+ disposers.forEach(fn => fn());
7983
+ };
7984
+ };
7985
+
7986
+ /**
7987
+ * ```js
7988
+ * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
7989
+ * const dispose = onJoinRequestDeleted(data => {
7990
+ * // ...
7991
+ * })
7992
+ * ```
7993
+ *
7994
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7995
+ *
7996
+ * @param callback The function to call when the event was fired
7997
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
7998
+ *
7999
+ * @category JoinRequest Events
8000
+ */
8001
+ const onJoinRequestDeleted = (callback) => {
8002
+ const client = getActiveClient();
8003
+ const disposers = [
8004
+ createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
8005
+ ];
8006
+ return () => {
8007
+ disposers.forEach(fn => fn());
8008
+ };
8009
+ };
8010
+
8011
+ class JoinRequestsLiveCollectionController extends LiveCollectionController {
8012
+ constructor(query, callback) {
8013
+ const queryStreamId = hash__default["default"](query);
8014
+ const cacheKey = ['joinRequest', 'collection', queryStreamId];
8015
+ const paginationController = new JoinRequestsPaginationController(query);
8016
+ super(paginationController, queryStreamId, cacheKey, callback);
8017
+ this.query = query;
8018
+ this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
8019
+ this.callback = callback.bind(this);
8020
+ this.loadPage({ initial: true });
8021
+ }
8022
+ setup() {
8023
+ var _a;
8024
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8025
+ if (!collection) {
8026
+ pushToCache(this.cacheKey, {
8027
+ data: [],
8028
+ params: this.query,
8029
+ });
8030
+ }
8031
+ }
8032
+ async persistModel(queryPayload) {
8033
+ await this.queryStreamController.saveToMainDB(queryPayload);
8034
+ }
8035
+ persistQueryStream({ response, direction, refresh, }) {
8036
+ const joinRequestResponse = response;
8037
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
8038
+ }
8039
+ startSubscription() {
8040
+ return this.queryStreamController.subscribeRTE([
8041
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
8042
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
8043
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
8044
+ ]);
8045
+ }
8046
+ notifyChange({ origin, loading, error }) {
8047
+ var _a;
8048
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8049
+ if (!collection)
8050
+ return;
8051
+ const data = this.applyFilter(collection.data
8052
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
8053
+ .filter(isNonNullable)
8054
+ .map(({ data }) => data)
8055
+ .map(joinRequestLinkedObject));
8056
+ if (!this.shouldNotify(data) && origin === 'event')
8057
+ return;
8058
+ this.callback({
8059
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
8060
+ data,
8061
+ hasNextPage: !!this.paginationController.getNextToken(),
8062
+ loading,
8063
+ error,
8064
+ });
8065
+ }
8066
+ applyFilter(data) {
8067
+ let joinRequest = data;
8068
+ if (this.query.status) {
8069
+ joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
8070
+ }
8071
+ const sortFn = (() => {
8072
+ switch (this.query.sortBy) {
8073
+ case 'firstCreated':
8074
+ return sortByFirstCreated;
8075
+ case 'lastCreated':
8076
+ return sortByLastCreated;
8077
+ default:
8078
+ return sortByLastCreated;
8079
+ }
8080
+ })();
8081
+ joinRequest = joinRequest.sort(sortFn);
8082
+ return joinRequest;
8083
+ }
8084
+ }
8085
+
8086
+ /**
8087
+ * Get Join Requests
8088
+ *
8089
+ * @param params the query parameters
8090
+ * @param callback the callback to be called when the join request are updated
8091
+ * @returns joinRequests
8092
+ *
8093
+ * @category joinRequest Live Collection
8094
+ *
8095
+ */
8096
+ const getJoinRequests = (params, callback, config) => {
8097
+ const { log, cache } = getActiveClient();
8098
+ if (!cache) {
8099
+ console.log(ENABLE_CACHE_MESSAGE);
8100
+ }
8101
+ const timestamp = Date.now();
8102
+ log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
8103
+ const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
8104
+ const disposers = joinRequestLiveCollection.startSubscription();
8105
+ const cacheKey = joinRequestLiveCollection.getCacheKey();
8106
+ disposers.push(() => {
8107
+ dropFromCache(cacheKey);
8108
+ });
8109
+ return () => {
8110
+ log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
8111
+ disposers.forEach(fn => fn());
8112
+ };
8113
+ };
8114
+
8115
+ const convertRawInvitationToInternalInvitation = (rawInvitation) => {
8116
+ return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
8117
+ };
8118
+
8119
+ const prepareInvitationPayload = (rawPayload) => {
8120
+ return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
8121
+ };
8122
+
8123
+ /* begin_public_function
8124
+ id: invitation.createInvitations
8125
+ */
8126
+ /**
8127
+ * ```js
8128
+ * import { createInvitations } from '@amityco/ts-sdk'
8129
+ * const created = await createInvitations({
8130
+ * type: string,
8131
+ * targetType: string,
8132
+ * targetId: string,
8133
+ * userIds: string[]
8134
+ * }))
8135
+ * ```
8136
+ *
8137
+ * Creates an {@link Amity.Invitation}
8138
+ *
8139
+ * @param bundle The data necessary to create a new {@link Amity.Invitation}
8140
+ * @returns The newly created {@link Amity.Invitation}
8141
+ *
8142
+ * @category Invitation API
8143
+ * @async
8144
+ */
8145
+ const createInvitations = async (bundle) => {
8146
+ const client = getActiveClient();
8147
+ client.log('invitation/createInvitations', bundle);
8148
+ const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
8149
+ const data = prepareInvitationPayload(payload);
8150
+ const cachedAt = client.cache && Date.now();
8151
+ if (client.cache)
8152
+ ingestInCache(data, { cachedAt });
8153
+ fireEvent('local.invitation.created', data.invitations);
8154
+ return {
8155
+ data: data.invitations,
8156
+ cachedAt,
8157
+ };
8158
+ };
8159
+ /* end_public_function */
8160
+
8161
+ /* begin_public_function
8162
+ id: invitation.accept
8163
+ */
8164
+ /**
8165
+ * ```js
8166
+ * import { acceptInvitation } from '@amityco/ts-sdk'
8167
+ * const isAccepted = await acceptInvitation(invitationId)
8168
+ * ```
8169
+ *
8170
+ * Accepts a {@link Amity.Invitation} object
8171
+ *
8172
+ * @param invitationId the {@link Amity.Invitation} to accept
8173
+ * @returns A success boolean if the {@link Amity.Invitation} was accepted
8174
+ *
8175
+ * @category Invitation API
8176
+ * @async
8177
+ */
8178
+ const acceptInvitation = async (invitationId) => {
8179
+ var _a;
8180
+ const client = getActiveClient();
8181
+ client.log('invitation/acceptInvitation', invitationId);
8182
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
8183
+ const invitation = (_a = pullFromCache([
8184
+ 'invitation',
8185
+ 'get',
8186
+ invitationId,
8187
+ ])) === null || _a === void 0 ? void 0 : _a.data;
8188
+ if (invitation) {
8189
+ upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
8190
+ fireEvent('local.invitation.updated', [invitation]);
8191
+ }
8192
+ return data.success;
8193
+ };
8194
+ /* end_public_function */
8195
+
8196
+ /* begin_public_function
8197
+ id: invitation.reject
8198
+ */
8199
+ /**
8200
+ * ```js
8201
+ * import { rejectInvitation } from '@amityco/ts-sdk'
8202
+ * const isRejected = await rejectInvitation(invitationId)
8203
+ * ```
8204
+ *
8205
+ * Rejects a {@link Amity.Invitation} object
8206
+ *
8207
+ * @param invitationId the {@link Amity.Invitation} to reject
8208
+ * @returns A success boolean if the {@link Amity.Invitation} was rejected
8209
+ *
8210
+ * @category Invitation API
8211
+ * @async
8212
+ */
8213
+ const rejectInvitation = async (invitationId) => {
8214
+ var _a;
8215
+ const client = getActiveClient();
8216
+ client.log('invitation/rejectInvitation', invitationId);
8217
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
8218
+ const invitation = (_a = pullFromCache([
8219
+ 'invitation',
8220
+ 'get',
8221
+ invitationId,
8222
+ ])) === null || _a === void 0 ? void 0 : _a.data;
8223
+ if (invitation) {
8224
+ upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
8225
+ fireEvent('local.invitation.updated', [invitation]);
8226
+ }
8227
+ return data.success;
8228
+ };
8229
+ /* end_public_function */
8230
+
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
+ const prepareMyInvitationsPayload = (rawPayload) => {
8267
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
8268
+ };
8269
+
8270
+ const invitationLinkedObject = (invitation) => {
8271
+ return Object.assign(Object.assign({}, invitation), { get user() {
8272
+ const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
8273
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8274
+ return userLinkedObject(cacheData.data);
8275
+ return undefined;
8276
+ },
8277
+ get createdBy() {
8278
+ const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
8279
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8280
+ return userLinkedObject(cacheData.data);
8281
+ return undefined;
8282
+ },
8283
+ get target() {
8284
+ if (invitation.targetType === 'community') {
8285
+ const cacheData = pullFromCache([
8286
+ 'community',
8287
+ 'get',
8288
+ invitation.targetId,
8289
+ ]);
8290
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8291
+ return cacheData.data;
8292
+ return undefined;
8293
+ }
8294
+ return undefined;
8295
+ }, accept: async () => {
8296
+ await acceptInvitation(invitation._id);
8297
+ }, reject: async () => {
8298
+ await rejectInvitation(invitation._id);
8299
+ }, cancel: async () => {
8300
+ await cancelInvitation(invitation._id);
8301
+ } });
8302
+ };
8303
+
8304
+ /* begin_public_function
8305
+ id: invitation.get
8306
+ */
8307
+ /**
8308
+ * ```js
8309
+ * import { getInvitation } from '@amityco/ts-sdk'
8310
+ * const { invitation } = await getInvitation(targetType, targetId)
8311
+ * ```
8312
+ *
8313
+ * Get a {@link Amity.Invitation} object
8314
+ *
8315
+ * @param targetType The type of the target of the {@link Amity.Invitation}
8316
+ * @param targetId The ID of the target of the {@link Amity.Invitation}
8317
+ * @returns A {@link Amity.Invitation} object
8318
+ *
8319
+ * @category Invitation API
8320
+ * @async
8321
+ */
8322
+ const getInvitation = async (targetType, targetId) => {
8323
+ const client = getActiveClient();
8324
+ client.log('invitation/getInvitation', targetType, targetId);
8325
+ const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
8326
+ const data = prepareMyInvitationsPayload(payload);
8327
+ const cachedAt = client.cache && Date.now();
8328
+ if (client.cache)
8329
+ ingestInCache(data, { cachedAt });
8330
+ return {
8331
+ data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
8332
+ cachedAt,
8333
+ };
8334
+ };
8335
+ /* end_public_function */
8336
+
8337
+ var InvitationActionsEnum;
8338
+ (function (InvitationActionsEnum) {
8339
+ InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
8340
+ InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
8341
+ InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
8342
+ })(InvitationActionsEnum || (InvitationActionsEnum = {}));
8343
+
7631
8344
  class InvitationsPaginationController extends PaginationController {
7632
8345
  async getRequest(queryParams, token) {
7633
8346
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
@@ -7637,13 +8350,6 @@ class InvitationsPaginationController extends PaginationController {
7637
8350
  }
7638
8351
  }
7639
8352
 
7640
- class QueryStreamController {
7641
- constructor(query, cacheKey) {
7642
- this.query = query;
7643
- this.cacheKey = cacheKey;
7644
- }
7645
- }
7646
-
7647
8353
  class InvitationsQueryStreamController extends QueryStreamController {
7648
8354
  constructor(query, cacheKey, notifyChange, preparePayload) {
7649
8355
  super(query, cacheKey);
@@ -7704,141 +8410,6 @@ class InvitationsQueryStreamController extends QueryStreamController {
7704
8410
  }
7705
8411
  }
7706
8412
 
7707
- function isObject(value) {
7708
- return typeof value === 'object' && value !== null;
7709
- }
7710
- /**
7711
- * convert all object getter property to static value
7712
- */
7713
- const convertGetterPropsToStatic = (obj) => {
7714
- if (!isObject(obj)) {
7715
- return obj;
7716
- }
7717
- const entries = Object.entries(obj).map(([key, value]) => {
7718
- const descriptor = Object.getOwnPropertyDescriptor(obj, key);
7719
- if (typeof (descriptor === null || descriptor === void 0 ? void 0 : descriptor.get) === 'function') {
7720
- return [key, descriptor.get.call(obj)];
7721
- }
7722
- return [key, value];
7723
- });
7724
- return Object.fromEntries(entries);
7725
- };
7726
- const removeFunctionProperties = (obj) => {
7727
- if (!isObject(obj)) {
7728
- return obj;
7729
- }
7730
- const entries = Object.entries(obj).map(([key, value]) => {
7731
- if (typeof value === 'function') {
7732
- return [key, undefined];
7733
- }
7734
- return [key, value];
7735
- });
7736
- return Object.fromEntries(entries);
7737
- };
7738
-
7739
- class PaginationNoPageController {
7740
- constructor(queryParams) {
7741
- const { http } = getActiveClient();
7742
- this.queryParams = queryParams;
7743
- this.http = http;
7744
- }
7745
- async onFetch() {
7746
- const queryResponse = await this.getRequest(this.queryParams);
7747
- return queryResponse;
7748
- }
7749
- }
7750
-
7751
- class LiveCollectionController {
7752
- constructor(paginationController, queryStreamId, cacheKey, callback) {
7753
- this.paginationController = paginationController;
7754
- this.queryStreamId = queryStreamId;
7755
- this.cacheKey = cacheKey;
7756
- this.callback = callback;
7757
- }
7758
- async refresh() {
7759
- try {
7760
- let result;
7761
- if (this.paginationController instanceof PaginationNoPageController) {
7762
- result = await this.paginationController.onFetch();
7763
- }
7764
- else {
7765
- result = await this.paginationController.loadFirstPage();
7766
- }
7767
- if (!result)
7768
- return;
7769
- await this.persistModel(result);
7770
- this.persistQueryStream({
7771
- response: result,
7772
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
7773
- refresh: true,
7774
- });
7775
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7776
- }
7777
- catch (e) {
7778
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7779
- }
7780
- }
7781
- loadPage({ initial = false, direction = "next" /* Amity.LiveCollectionPageDirection.NEXT */, }) {
7782
- this.setup();
7783
- this.notifyChange({ origin: "local" /* Amity.LiveDataOrigin.LOCAL */, loading: true });
7784
- if (initial) {
7785
- this.refresh();
7786
- }
7787
- else if (direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */) {
7788
- this.loadPrevPage();
7789
- }
7790
- else if (direction === "next" /* Amity.LiveCollectionPageDirection.NEXT */) {
7791
- this.loadNextPage();
7792
- }
7793
- }
7794
- async loadNextPage() {
7795
- try {
7796
- if (this.paginationController instanceof PaginationNoPageController)
7797
- return;
7798
- const result = await this.paginationController.loadNextPage();
7799
- if (!result)
7800
- return;
7801
- await this.persistModel(result);
7802
- this.persistQueryStream({
7803
- response: result,
7804
- direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */,
7805
- });
7806
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7807
- }
7808
- catch (e) {
7809
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7810
- }
7811
- }
7812
- async loadPrevPage() {
7813
- try {
7814
- if (this.paginationController instanceof PaginationNoPageController)
7815
- return;
7816
- const result = await this.paginationController.loadPreviousPage();
7817
- if (!result)
7818
- return;
7819
- await this.persistModel(result);
7820
- this.persistQueryStream({
7821
- response: result,
7822
- direction: "prev" /* Amity.LiveCollectionPageDirection.PREV */,
7823
- });
7824
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false });
7825
- }
7826
- catch (e) {
7827
- this.notifyChange({ origin: "server" /* Amity.LiveDataOrigin.SERVER */, loading: false, error: e });
7828
- }
7829
- }
7830
- shouldNotify(data) {
7831
- const newData = data.map(convertGetterPropsToStatic).map(removeFunctionProperties);
7832
- if (isEqual(this.snapshot, newData))
7833
- return false;
7834
- this.snapshot = newData;
7835
- return true;
7836
- }
7837
- getCacheKey() {
7838
- return this.cacheKey;
7839
- }
7840
- }
7841
-
7842
8413
  /**
7843
8414
  * ```js
7844
8415
  * import { onLocalInvitationCreated } from '@amityco/ts-sdk'
@@ -8047,6 +8618,13 @@ const communityLinkedObject = (community) => {
8047
8618
  }, getInvitation: async () => {
8048
8619
  const { data } = await getInvitation('community', community.communityId);
8049
8620
  return data;
8621
+ }, join: async () => {
8622
+ return joinRequest(community.communityId);
8623
+ }, getJoinRequests: (params, callback) => {
8624
+ return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
8625
+ }, getMyJoinRequest: async () => {
8626
+ const { data } = await getMyJoinRequest(community.communityId);
8627
+ return data;
8050
8628
  } });
8051
8629
  };
8052
8630
 
@@ -8066,6 +8644,7 @@ const LinkedObject = {
8066
8644
  notificationTray: notificationTrayLinkedObject,
8067
8645
  community: communityLinkedObject,
8068
8646
  invitation: invitationLinkedObject,
8647
+ joinRequest: joinRequestLinkedObject,
8069
8648
  };
8070
8649
 
8071
8650
  const constructChannelObject = (channel) => {
@@ -13622,41 +14201,6 @@ getComment$2.locally = (commentId) => {
13622
14201
  };
13623
14202
  };
13624
14203
 
13625
- /*
13626
- * verifies membership status
13627
- */
13628
- function isMember(membership) {
13629
- return membership !== 'none';
13630
- }
13631
- /*
13632
- * checks if currently logged in user is part of the community
13633
- */
13634
- function isCurrentUserPartOfCommunity(c, m) {
13635
- const { userId } = getActiveUser();
13636
- return c.communityId === m.communityId && m.userId === userId;
13637
- }
13638
- /*
13639
- * For mqtt events server will not send user specific data as it's broadcasted
13640
- * to multiple users and it also does not include communityUser
13641
- *
13642
- * Client SDK needs to check for the existing isJoined field in cache data before calculating.
13643
- * Althought this can be calculated, it's not scalable.
13644
- */
13645
- function updateMembershipStatus(communities, communityUsers) {
13646
- return communities.map(c => {
13647
- const cachedCommunity = pullFromCache([
13648
- 'community',
13649
- 'get',
13650
- c.communityId,
13651
- ]);
13652
- if ((cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data) && (cachedCommunity === null || cachedCommunity === void 0 ? void 0 : cachedCommunity.data.hasOwnProperty('isJoined'))) {
13653
- return Object.assign(Object.assign({}, cachedCommunity.data), c);
13654
- }
13655
- const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
13656
- return Object.assign(Object.assign({}, c), { isJoined });
13657
- });
13658
- }
13659
-
13660
14204
  const getMyReactionsInCache = (payload, eventPrefix) => {
13661
14205
  var _a, _b;
13662
14206
  let id;
@@ -13971,53 +14515,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13971
14515
  return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
13972
14516
  };
13973
14517
 
13974
- const getMatchPostSetting = (value) => {
13975
- var _a;
13976
- return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
13977
- CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
13978
- value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
13979
- };
13980
- function addPostSetting({ communities }) {
13981
- return communities.map((_a) => {
13982
- var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
13983
- return (Object.assign({ postSetting: getMatchPostSetting({
13984
- needApprovalOnPostCreation,
13985
- onlyAdminCanPost,
13986
- }) }, restCommunityPayload));
13987
- });
13988
- }
13989
- const prepareCommunityPayload = (rawPayload) => {
13990
- const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
13991
- // map users with community
13992
- const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
13993
- const user = rawPayload.users.find(user => user.userId === communityUser.userId);
13994
- return Object.assign(Object.assign({}, communityUser), { user });
13995
- });
13996
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
13997
- return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
13998
- };
13999
- const prepareCommunityMembershipPayload = (rawPayload) => {
14000
- const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
14001
- // map users with community
14002
- const mappedCommunityUsers = rawPayload.communityUsers.map(communityUser => {
14003
- const user = rawPayload.users.find(user => user.userId === communityUser.userId);
14004
- return Object.assign(Object.assign({}, communityUser), { user });
14005
- });
14006
- const communityWithMembershipStatus = updateMembershipStatus(communitiesWithPostSetting, mappedCommunityUsers);
14007
- return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
14008
- };
14009
- const prepareCommunityRequest = (params) => {
14010
- const { postSetting = undefined, storySetting } = params, restParam = __rest(params, ["postSetting", "storySetting"]);
14011
- return Object.assign(Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)), {
14012
- // Convert story setting to the actual value. (Allow by default)
14013
- allowCommentInStory: typeof (storySetting === null || storySetting === void 0 ? void 0 : storySetting.enableComment) === 'boolean' ? storySetting.enableComment : true });
14014
- };
14015
- const prepareSemanticSearchCommunityPayload = (_a) => {
14016
- var communityPayload = __rest(_a, ["searchResult"]);
14017
- const processedCommunityPayload = prepareCommunityPayload(communityPayload);
14018
- return Object.assign({}, processedCommunityPayload);
14019
- };
14020
-
14021
14518
  const preparePostPayload = (payload) => {
14022
14519
  const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
14023
14520
  // Unpack community payload by mapping payload field to postSetting value.
@@ -19218,11 +19715,16 @@ const updateCommunity = async (communityId, patch) => {
19218
19715
  * @category Community API
19219
19716
  * @async
19220
19717
  */
19221
- const getCommunity$1 = async (communityId) => {
19718
+ const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
19222
19719
  const client = getActiveClient();
19223
19720
  client.log('community/getCommunity', communityId);
19224
19721
  // API-FIX: endpoint should not be /list, parameters should be querystring.
19225
- const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
19722
+ const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
19723
+ params: {
19724
+ type: 'communityJoinRequest',
19725
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
19726
+ },
19727
+ });
19226
19728
  const data = prepareCommunityPayload(payload);
19227
19729
  const cachedAt = client.cache && Date.now();
19228
19730
  if (client.cache) {
@@ -19297,6 +19799,9 @@ const deleteCommunity = async (communityId) => {
19297
19799
  };
19298
19800
  /* end_public_function */
19299
19801
 
19802
+ /**
19803
+ * @deprecated This function will to be deprecated and use the new community.join().
19804
+ */
19300
19805
  /* begin_public_function
19301
19806
  id: community.join
19302
19807
  */
@@ -19437,10 +19942,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
19437
19942
  */
19438
19943
  class CommunitiesPaginationController$1 extends PaginationController {
19439
19944
  async getRequest(queryParams, token) {
19945
+ var _a;
19440
19946
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19441
19947
  const options = token ? { token } : { limit };
19442
19948
  const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
19443
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
19949
+ 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 }),
19444
19950
  });
19445
19951
  return queryResponse;
19446
19952
  }
@@ -20887,7 +21393,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
20887
21393
  const data = (_b = collection.data
20888
21394
  .map(id => pullFromCache(['community', 'get', id]))
20889
21395
  .filter(isNonNullable)
20890
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
21396
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
20891
21397
  if (!this.shouldNotify(data) && origin === 'event')
20892
21398
  return;
20893
21399
  this.callback({
@@ -21049,7 +21555,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
21049
21555
  const data = (_b = collection.data
21050
21556
  .map(id => pullFromCache(['community', 'get', id]))
21051
21557
  .filter(isNonNullable)
21052
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
21558
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
21053
21559
  if (!this.shouldNotify(data) && origin === 'event')
21054
21560
  return;
21055
21561
  this.callback({
@@ -23699,7 +24205,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
23699
24205
  const client = getActiveClient();
23700
24206
  const cachedAt = client.cache && Date.now();
23701
24207
  if (client.cache) {
23702
- ingestInCache(response, { cachedAt });
24208
+ const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
24209
+ ingestInCache(processedPayload, { cachedAt });
23703
24210
  }
23704
24211
  }
23705
24212
  appendToQueryStream(response, direction, refresh = false) {
@@ -23828,7 +24335,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
23828
24335
  const client = getActiveClient();
23829
24336
  const cachedAt = client.cache && Date.now();
23830
24337
  if (client.cache) {
23831
- ingestInCache(response, { cachedAt });
24338
+ const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
24339
+ ingestInCache(processedPayload, { cachedAt });
23832
24340
  }
23833
24341
  }
23834
24342
  appendToQueryStream(response, direction, refresh = false) {