@amityco/ts-sdk 7.4.1-4207cb63.0 → 7.4.1-7cfcde16.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 (144) 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 +39 -2
  8. package/dist/@types/domains/community.d.ts.map +1 -1
  9. package/dist/@types/domains/invitation.d.ts +0 -1
  10. package/dist/@types/domains/invitation.d.ts.map +1 -1
  11. package/dist/@types/domains/joinRequest.d.ts +53 -0
  12. package/dist/@types/domains/joinRequest.d.ts.map +1 -0
  13. package/dist/@types/domains/notification.d.ts +4 -2
  14. package/dist/@types/domains/notification.d.ts.map +1 -1
  15. package/dist/@types/index.d.ts +1 -0
  16. package/dist/@types/index.d.ts.map +1 -1
  17. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  18. package/dist/communityRepository/api/getCommunity.d.ts +1 -1
  19. package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
  20. package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
  21. package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
  22. package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
  23. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  24. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
  25. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
  26. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
  27. package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
  28. package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
  29. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
  30. package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
  31. package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
  32. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
  33. package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
  34. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
  35. package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
  36. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
  37. package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
  38. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
  39. package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
  40. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
  41. package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
  42. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
  43. package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
  44. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  45. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  46. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
  47. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
  48. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
  49. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
  50. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
  51. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
  52. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
  53. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
  54. package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
  55. package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
  56. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
  57. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
  58. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
  59. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
  60. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
  61. package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
  62. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
  63. package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
  64. package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
  65. package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
  66. package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
  67. package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
  68. package/dist/communityRepository/observers/index.d.ts +1 -0
  69. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  70. package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
  71. package/dist/communityRepository/utils/payload.d.ts +1 -0
  72. package/dist/communityRepository/utils/payload.d.ts.map +1 -1
  73. package/dist/core/events.d.ts +3 -3
  74. package/dist/core/events.d.ts.map +1 -1
  75. package/dist/core/model/idResolvers.d.ts.map +1 -1
  76. package/dist/core/model/index.d.ts.map +1 -1
  77. package/dist/index.cjs.js +943 -257
  78. package/dist/index.esm.js +1082 -396
  79. package/dist/index.umd.js +4 -4
  80. package/dist/invitationRepository/internalApi/index.d.ts +0 -1
  81. package/dist/invitationRepository/internalApi/index.d.ts.map +1 -1
  82. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
  83. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  84. package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
  85. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  86. package/dist/utils/linkedObject/index.d.ts +1 -0
  87. package/dist/utils/linkedObject/index.d.ts.map +1 -1
  88. package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
  89. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
  90. package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
  91. package/package.json +1 -1
  92. package/src/@types/core/events.ts +6 -0
  93. package/src/@types/core/model.ts +3 -0
  94. package/src/@types/core/payload.ts +22 -1
  95. package/src/@types/domains/community.ts +55 -2
  96. package/src/@types/domains/invitation.ts +0 -1
  97. package/src/@types/domains/joinRequest.ts +66 -0
  98. package/src/@types/domains/notification.ts +2 -0
  99. package/src/@types/index.ts +1 -0
  100. package/src/communityRepository/api/getCommunities.ts +3 -1
  101. package/src/communityRepository/api/getCommunity.ts +8 -0
  102. package/src/communityRepository/api/joinCommunity.ts +4 -1
  103. package/src/communityRepository/communityMembership/events/index.ts +1 -0
  104. package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
  105. package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
  106. package/src/communityRepository/internalAPI/joinCommunity.ts +66 -0
  107. package/src/communityRepository/joinRequest/events/index.ts +3 -0
  108. package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
  109. package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
  110. package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
  111. package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
  112. package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
  113. package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
  114. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
  115. package/src/communityRepository/observers/getCommunity.ts +3 -0
  116. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
  117. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
  118. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
  119. package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
  120. package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
  121. package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
  122. package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
  123. package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
  124. package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
  125. package/src/communityRepository/observers/getJoinRequests.ts +44 -0
  126. package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
  127. package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
  128. package/src/communityRepository/observers/index.ts +1 -0
  129. package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
  130. package/src/communityRepository/utils/communityWithMembership.ts +1 -1
  131. package/src/communityRepository/utils/payload.ts +27 -1
  132. package/src/core/model/idResolvers.ts +1 -0
  133. package/src/core/model/index.ts +1 -0
  134. package/src/invitationRepository/internalApi/index.ts +0 -1
  135. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
  136. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
  137. package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
  138. package/src/utils/linkedObject/communityLinkedObject.ts +20 -0
  139. package/src/utils/linkedObject/index.ts +2 -0
  140. package/src/utils/linkedObject/invitationLinkedObject.ts +1 -8
  141. package/src/utils/linkedObject/joinRequestLinkedObject.ts +25 -0
  142. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +0 -16
  143. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +0 -1
  144. package/src/invitationRepository/internalApi/cancelInvitation.ts +0 -44
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,235 +7370,299 @@ 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
- };
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
7389
+ *
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.
7392
+ */
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
+ }
7360
7407
 
7361
- const prepareInvitationPayload = (rawPayload) => {
7362
- return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
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;
7413
+ };
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);
7363
7462
  };
7364
7463
 
7365
7464
  /* begin_public_function
7366
- id: invitation.createInvitations
7465
+ id: joinRequest.approve
7367
7466
  */
7368
7467
  /**
7369
7468
  * ```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
- * }))
7469
+ * import { joinRequest } from '@amityco/ts-sdk'
7470
+ * const isAccepted = await joinRequest.approve()
7377
7471
  * ```
7378
7472
  *
7379
- * Creates an {@link Amity.Invitation}
7473
+ * Accepts a {@link Amity.JoinRequest} object
7380
7474
  *
7381
- * @param bundle The data necessary to create a new {@link Amity.Invitation}
7382
- * @returns The newly created {@link Amity.Invitation}
7475
+ * @param joinRequest the {@link Amity.JoinRequest} to accept
7476
+ * @returns A success boolean if the {@link Amity.JoinRequest} was accepted
7383
7477
  *
7384
- * @category Invitation API
7478
+ * @category Join Request API
7385
7479
  * @async
7386
7480
  */
7387
- const createInvitations = async (bundle) => {
7481
+ const approveJoinRequest = async (joinRequest) => {
7482
+ var _a;
7388
7483
  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
- };
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',
7490
+ 'get',
7491
+ joinRequest.joinRequestId,
7492
+ ])) === null || _a === void 0 ? void 0 : _a.data;
7493
+ if (joinRequestCache) {
7494
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
7495
+ status: "approved" /* JoinRequestStatusEnum.Approved */,
7496
+ });
7497
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
7498
+ }
7499
+ return data.success;
7400
7500
  };
7401
7501
  /* end_public_function */
7402
7502
 
7403
7503
  /* begin_public_function
7404
- id: invitation.accept
7504
+ id: joinRequest.cancel
7405
7505
  */
7406
7506
  /**
7407
7507
  * ```js
7408
- * import { acceptInvitation } from '@amityco/ts-sdk'
7409
- * const isAccepted = await acceptInvitation(invitationId)
7508
+ * import { joinRequest } from '@amityco/ts-sdk'
7509
+ * const isCanceled = await joinRequest.cancel()
7410
7510
  * ```
7411
7511
  *
7412
- * Accepts a {@link Amity.Invitation} object
7512
+ * Cancels a {@link Amity.JoinRequest} object
7413
7513
  *
7414
- * @param invitationId the {@link Amity.Invitation} to accept
7415
- * @returns A success boolean if the {@link Amity.Invitation} was accepted
7514
+ * @param joinRequest the {@link Amity.JoinRequest} to cancel
7515
+ * @returns A success boolean if the {@link Amity.JoinRequest} was canceled
7416
7516
  *
7417
- * @category Invitation API
7517
+ * @category Join Request API
7418
7518
  * @async
7419
7519
  */
7420
- const acceptInvitation = async (invitationId) => {
7520
+ const cancelJoinRequest = async (joinRequest) => {
7421
7521
  var _a;
7422
7522
  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',
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',
7427
7527
  'get',
7428
- invitationId,
7528
+ joinRequest.joinRequestId,
7429
7529
  ])) === 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]);
7530
+ if (joinRequestCache) {
7531
+ dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
7532
+ fireEvent('local.joinRequest.deleted', [joinRequestCache]);
7433
7533
  }
7434
7534
  return data.success;
7435
7535
  };
7436
7536
  /* end_public_function */
7437
7537
 
7438
7538
  /* begin_public_function
7439
- id: invitation.reject
7539
+ id: joinRequest.reject
7440
7540
  */
7441
7541
  /**
7442
7542
  * ```js
7443
- * import { rejectInvitation } from '@amityco/ts-sdk'
7444
- * const isRejected = await rejectInvitation(invitationId)
7543
+ * import { joinRequest } from '@amityco/ts-sdk'
7544
+ * const isRejected = await joinRequest.reject()
7445
7545
  * ```
7446
7546
  *
7447
- * Rejects a {@link Amity.Invitation} object
7547
+ * Rejects a {@link Amity.JoinRequest} object
7448
7548
  *
7449
- * @param invitationId the {@link Amity.Invitation} to reject
7450
- * @returns A success boolean if the {@link Amity.Invitation} was rejected
7549
+ * @param joinRequest the {@link Amity.JoinRequest} to reject
7550
+ * @returns A success boolean if the {@link Amity.JoinRequest} was rejected
7451
7551
  *
7452
- * @category Invitation API
7552
+ * @category Join Request API
7453
7553
  * @async
7454
7554
  */
7455
- const rejectInvitation = async (invitationId) => {
7555
+ const rejectJoinRequest = async (joinRequest) => {
7456
7556
  var _a;
7457
7557
  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',
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',
7462
7564
  'get',
7463
- invitationId,
7565
+ joinRequest.joinRequestId,
7464
7566
  ])) === 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]);
7567
+ if (joinRequestCache) {
7568
+ upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
7569
+ status: "rejected" /* JoinRequestStatusEnum.Rejected */,
7570
+ });
7571
+ fireEvent('local.joinRequest.updated', [joinRequestCache]);
7468
7572
  }
7469
7573
  return data.success;
7470
7574
  };
7471
7575
  /* end_public_function */
7472
7576
 
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)
7586
+ return undefined;
7587
+ return userLinkedObject(user);
7588
+ }, cancel: () => cancelJoinRequest(joinRequest), approve: () => approveJoinRequest(joinRequest), reject: () => rejectJoinRequest(joinRequest) });
7589
+ };
7590
+
7473
7591
  /* begin_public_function
7474
- id: invitation.cancel
7592
+ id: community.getMyJoinRequest
7475
7593
  */
7476
7594
  /**
7477
7595
  * ```js
7478
- * import { cancelInvitation } from '@amityco/ts-sdk'
7479
- * const isCanceled = await cancelInvitation(invitationId)
7596
+ * import { community } from '@amityco/ts-sdk'
7597
+ * const isJoined = await community.getMyJoinRequest('foobar')
7480
7598
  * ```
7481
7599
  *
7482
- * Cancels a {@link Amity.Invitation} object
7600
+ * Joins a {@link Amity.Community} object
7483
7601
  *
7484
- * @param invitationId the {@link Amity.Invitation} to cancel
7485
- * @returns A success boolean if the {@link Amity.Invitation} was canceled
7602
+ * @param communityId the {@link Amity.Community} to join
7603
+ * @returns A success boolean if the {@link Amity.Community} was joined
7486
7604
  *
7487
- * @category Invitation API
7605
+ * @category Community API
7488
7606
  * @async
7489
7607
  */
7490
- const cancelInvitation = async (invitationId) => {
7491
- var _a;
7608
+ const getMyJoinRequest = async (communityId) => {
7492
7609
  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',
7497
- 'get',
7498
- invitationId,
7499
- ])) === null || _a === void 0 ? void 0 : _a.data;
7500
- if (invitation) {
7501
- dropFromCache(['invitation', 'get', invitationId]);
7502
- fireEvent('local.invitation.deleted', [invitation]);
7503
- }
7504
- return data.success;
7610
+ client.log('community/myJoinRequest', communityId);
7611
+ const { data: payload } = await client.http.get(`/api/v4/communities/${communityId}/join/me`);
7612
+ const data = prepareCommunityJoinRequestPayload(payload);
7613
+ const cachedAt = client.cache && Date.now();
7614
+ if (client.cache)
7615
+ ingestInCache(data, { cachedAt });
7616
+ return {
7617
+ data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
7618
+ cachedAt,
7619
+ };
7505
7620
  };
7506
7621
  /* end_public_function */
7507
7622
 
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;
7534
- return undefined;
7535
- }
7536
- return undefined;
7537
- }, accept: async () => {
7538
- await acceptInvitation(invitation._id);
7539
- }, reject: async () => {
7540
- await rejectInvitation(invitation._id);
7541
- }, cancel: async () => {
7542
- await cancelInvitation(invitation._id);
7543
- } });
7544
- };
7545
-
7546
7623
  /* begin_public_function
7547
- id: invitation.get
7624
+ id: community.join
7548
7625
  */
7549
7626
  /**
7550
7627
  * ```js
7551
- * import { getInvitation } from '@amityco/ts-sdk'
7552
- * const { invitation } = await getInvitation(targetType, targetId)
7628
+ * import { community } from '@amityco/ts-sdk'
7629
+ * const isJoined = await community.join('foobar')
7553
7630
  * ```
7554
7631
  *
7555
- * Get a {@link Amity.Invitation} object
7632
+ * Joins a {@link Amity.Community} object
7556
7633
  *
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
7634
+ * @param communityId the {@link Amity.Community} to join
7635
+ * @returns A status join result
7560
7636
  *
7561
- * @category Invitation API
7637
+ * @category Community API
7562
7638
  * @async
7563
7639
  */
7564
- const getInvitation = async (targetType, targetId) => {
7640
+ const joinRequest = async (communityId) => {
7641
+ var _a;
7565
7642
  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);
7643
+ client.log('community/joinRequest', communityId);
7644
+ const { data: payload } = await client.http.post(`/api/v4/communities/${communityId}/join`);
7645
+ const data = prepareCommunityJoinRequestPayload(payload);
7569
7646
  const cachedAt = client.cache && Date.now();
7570
7647
  if (client.cache)
7571
7648
  ingestInCache(data, { cachedAt });
7572
- return {
7573
- data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
7574
- cachedAt,
7575
- };
7649
+ const status = data.joinRequests[0].status === "approved" /* JoinRequestStatusEnum.Approved */
7650
+ ? "success" /* JoinResultStatusEnum.Success */
7651
+ : "pending" /* JoinResultStatusEnum.Pending */;
7652
+ if (status === "success" /* JoinResultStatusEnum.Success */ && client.cache) {
7653
+ const community = (_a = pullFromCache(['community', 'get', communityId])) === null || _a === void 0 ? void 0 : _a.data;
7654
+ if (community) {
7655
+ const updatedCommunity = Object.assign(Object.assign({}, community), { isJoined: true });
7656
+ upsertInCache(['community', 'get', communityId], updatedCommunity);
7657
+ }
7658
+ }
7659
+ fireEvent('v4.local.community.joined', data.joinRequests);
7660
+ return status === "success" /* JoinResultStatusEnum.Success */
7661
+ ? { status }
7662
+ : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
7576
7663
  };
7577
7664
  /* end_public_function */
7578
7665
 
7579
- var InvitationActionsEnum;
7580
- (function (InvitationActionsEnum) {
7581
- InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
7582
- InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
7583
- InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
7584
- })(InvitationActionsEnum || (InvitationActionsEnum = {}));
7585
-
7586
7666
  class PaginationController {
7587
7667
  constructor(queryParams) {
7588
7668
  const { http } = getActiveClient();
@@ -7628,12 +7708,18 @@ class PaginationController {
7628
7708
  }
7629
7709
  }
7630
7710
 
7631
- class InvitationsPaginationController extends PaginationController {
7632
- async getRequest(queryParams, token) {
7633
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
7711
+ /**
7712
+ * TODO: handle cache receive cache option, and cache policy
7713
+ * TODO: check if querybyIds is supported
7714
+ */
7715
+ class JoinRequestsPaginationController extends PaginationController {
7716
+ async getRequest(queryParams, token) {
7717
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId } = queryParams, params = __rest(queryParams, ["limit", "communityId"]);
7634
7718
  const options = token ? { token } : { limit };
7635
- const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
7636
- return data;
7719
+ const { data: queryResponse } = await this.http.get(`/api/v4/communities/${communityId}/join`, {
7720
+ params: Object.assign(Object.assign({}, params), { options }),
7721
+ });
7722
+ return queryResponse;
7637
7723
  }
7638
7724
  }
7639
7725
 
@@ -7644,7 +7730,14 @@ class QueryStreamController {
7644
7730
  }
7645
7731
  }
7646
7732
 
7647
- class InvitationsQueryStreamController extends QueryStreamController {
7733
+ var EnumJoinRequestAction$1;
7734
+ (function (EnumJoinRequestAction) {
7735
+ EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
7736
+ EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
7737
+ EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
7738
+ })(EnumJoinRequestAction$1 || (EnumJoinRequestAction$1 = {}));
7739
+
7740
+ class JoinRequestsQueryStreamController extends QueryStreamController {
7648
7741
  constructor(query, cacheKey, notifyChange, preparePayload) {
7649
7742
  super(query, cacheKey);
7650
7743
  this.notifyChange = notifyChange;
@@ -7662,38 +7755,41 @@ class InvitationsQueryStreamController extends QueryStreamController {
7662
7755
  var _a, _b;
7663
7756
  if (refresh) {
7664
7757
  pushToCache(this.cacheKey, {
7665
- data: response.invitations.map(getResolver('invitation')),
7758
+ data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
7666
7759
  });
7667
7760
  }
7668
7761
  else {
7669
7762
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
7670
- const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
7763
+ const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
7671
7764
  pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
7672
- ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
7765
+ ...new Set([
7766
+ ...joinRequests,
7767
+ ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
7768
+ ]),
7673
7769
  ] }));
7674
7770
  }
7675
7771
  }
7676
7772
  reactor(action) {
7677
- return (invitations) => {
7773
+ return (joinRequest) => {
7678
7774
  var _a;
7679
7775
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
7680
7776
  if (!collection)
7681
7777
  return;
7682
- if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
7683
- const isExist = collection.data.find(id => id === invitations[0].invitationId);
7778
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestUpdated) {
7779
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
7684
7780
  if (!isExist)
7685
7781
  return;
7686
7782
  }
7687
- if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
7783
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestCreated) {
7688
7784
  collection.data = [
7689
7785
  ...new Set([
7690
- ...invitations.map(invitation => invitation.invitationId),
7786
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
7691
7787
  ...collection.data,
7692
7788
  ]),
7693
7789
  ];
7694
7790
  }
7695
- if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
7696
- collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
7791
+ if (action === EnumJoinRequestAction$1.OnLocalJoinRequestDeleted) {
7792
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
7697
7793
  }
7698
7794
  pushToCache(this.cacheKey, collection);
7699
7795
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
@@ -7834,8 +7930,448 @@ class LiveCollectionController {
7834
7930
  this.snapshot = newData;
7835
7931
  return true;
7836
7932
  }
7837
- getCacheKey() {
7838
- return this.cacheKey;
7933
+ getCacheKey() {
7934
+ return this.cacheKey;
7935
+ }
7936
+ }
7937
+
7938
+ /**
7939
+ * ```js
7940
+ * import { onJoinRequestCreated } from '@amityco/ts-sdk'
7941
+ * const dispose = onJoinRequestCreated(data => {
7942
+ * // ...
7943
+ * })
7944
+ * ```
7945
+ *
7946
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7947
+ *
7948
+ * @param callback The function to call when the event was fired
7949
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
7950
+ *
7951
+ * @category JoinRequest Events
7952
+ */
7953
+ const onJoinRequestCreated = (callback) => {
7954
+ const client = getActiveClient();
7955
+ const disposers = [
7956
+ createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload => callback(payload)),
7957
+ ];
7958
+ return () => {
7959
+ disposers.forEach(fn => fn());
7960
+ };
7961
+ };
7962
+
7963
+ /**
7964
+ * ```js
7965
+ * import { onJoinRequestUpdated } from '@amityco/ts-sdk'
7966
+ * const dispose = onJoinRequestUpdated(data => {
7967
+ * // ...
7968
+ * })
7969
+ * ```
7970
+ *
7971
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7972
+ *
7973
+ * @param callback The function to call when the event was fired
7974
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
7975
+ *
7976
+ * @category JoinRequest Events
7977
+ */
7978
+ const onJoinRequestUpdated = (callback) => {
7979
+ const client = getActiveClient();
7980
+ const disposers = [
7981
+ createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload => callback(payload)),
7982
+ ];
7983
+ return () => {
7984
+ disposers.forEach(fn => fn());
7985
+ };
7986
+ };
7987
+
7988
+ /**
7989
+ * ```js
7990
+ * import { onJoinRequestDeleted } from '@amityco/ts-sdk'
7991
+ * const dispose = onJoinRequestDeleted(data => {
7992
+ * // ...
7993
+ * })
7994
+ * ```
7995
+ *
7996
+ * Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
7997
+ *
7998
+ * @param callback The function to call when the event was fired
7999
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
8000
+ *
8001
+ * @category JoinRequest Events
8002
+ */
8003
+ const onJoinRequestDeleted = (callback) => {
8004
+ const client = getActiveClient();
8005
+ const disposers = [
8006
+ createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload => callback(payload)),
8007
+ ];
8008
+ return () => {
8009
+ disposers.forEach(fn => fn());
8010
+ };
8011
+ };
8012
+
8013
+ class JoinRequestsLiveCollectionController extends LiveCollectionController {
8014
+ constructor(query, callback) {
8015
+ const queryStreamId = hash__default["default"](query);
8016
+ const cacheKey = ['joinRequest', 'collection', queryStreamId];
8017
+ const paginationController = new JoinRequestsPaginationController(query);
8018
+ super(paginationController, queryStreamId, cacheKey, callback);
8019
+ this.query = query;
8020
+ this.queryStreamController = new JoinRequestsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
8021
+ this.callback = callback.bind(this);
8022
+ this.loadPage({ initial: true });
8023
+ }
8024
+ setup() {
8025
+ var _a;
8026
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8027
+ if (!collection) {
8028
+ pushToCache(this.cacheKey, {
8029
+ data: [],
8030
+ params: this.query,
8031
+ });
8032
+ }
8033
+ }
8034
+ async persistModel(queryPayload) {
8035
+ await this.queryStreamController.saveToMainDB(queryPayload);
8036
+ }
8037
+ persistQueryStream({ response, direction, refresh, }) {
8038
+ const joinRequestResponse = response;
8039
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
8040
+ }
8041
+ startSubscription() {
8042
+ return this.queryStreamController.subscribeRTE([
8043
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction$1.OnLocalJoinRequestCreated },
8044
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction$1.OnLocalJoinRequestUpdated },
8045
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction$1.OnLocalJoinRequestDeleted },
8046
+ ]);
8047
+ }
8048
+ notifyChange({ origin, loading, error }) {
8049
+ var _a;
8050
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8051
+ if (!collection)
8052
+ return;
8053
+ const data = this.applyFilter(collection.data
8054
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
8055
+ .filter(isNonNullable)
8056
+ .map(({ data }) => data)
8057
+ .map(joinRequestLinkedObject));
8058
+ if (!this.shouldNotify(data) && origin === 'event')
8059
+ return;
8060
+ this.callback({
8061
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
8062
+ data,
8063
+ hasNextPage: !!this.paginationController.getNextToken(),
8064
+ loading,
8065
+ error,
8066
+ });
8067
+ }
8068
+ applyFilter(data) {
8069
+ let joinRequest = data;
8070
+ if (this.query.status) {
8071
+ joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
8072
+ }
8073
+ const sortFn = (() => {
8074
+ switch (this.query.sortBy) {
8075
+ case 'firstCreated':
8076
+ return sortByFirstCreated;
8077
+ case 'lastCreated':
8078
+ return sortByLastCreated;
8079
+ default:
8080
+ return sortByLastCreated;
8081
+ }
8082
+ })();
8083
+ joinRequest = joinRequest.sort(sortFn);
8084
+ return joinRequest;
8085
+ }
8086
+ }
8087
+
8088
+ /**
8089
+ * Get Join Requests
8090
+ *
8091
+ * @param params the query parameters
8092
+ * @param callback the callback to be called when the join request are updated
8093
+ * @returns joinRequests
8094
+ *
8095
+ * @category joinRequest Live Collection
8096
+ *
8097
+ */
8098
+ const getJoinRequests = (params, callback, config) => {
8099
+ const { log, cache } = getActiveClient();
8100
+ if (!cache) {
8101
+ console.log(ENABLE_CACHE_MESSAGE);
8102
+ }
8103
+ const timestamp = Date.now();
8104
+ log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
8105
+ const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
8106
+ const disposers = joinRequestLiveCollection.startSubscription();
8107
+ const cacheKey = joinRequestLiveCollection.getCacheKey();
8108
+ disposers.push(() => {
8109
+ dropFromCache(cacheKey);
8110
+ });
8111
+ return () => {
8112
+ log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
8113
+ disposers.forEach(fn => fn());
8114
+ };
8115
+ };
8116
+
8117
+ const convertRawInvitationToInternalInvitation = (rawInvitation) => {
8118
+ return Object.assign(Object.assign({}, rawInvitation), { createdById: rawInvitation.createdBy });
8119
+ };
8120
+
8121
+ const prepareInvitationPayload = (rawPayload) => {
8122
+ return Object.assign(Object.assign({}, rawPayload), { invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation), users: rawPayload.users.map(convertRawUserToInternalUser) });
8123
+ };
8124
+
8125
+ /* begin_public_function
8126
+ id: invitation.createInvitations
8127
+ */
8128
+ /**
8129
+ * ```js
8130
+ * import { createInvitations } from '@amityco/ts-sdk'
8131
+ * const created = await createInvitations({
8132
+ * type: string,
8133
+ * targetType: string,
8134
+ * targetId: string,
8135
+ * userIds: string[]
8136
+ * }))
8137
+ * ```
8138
+ *
8139
+ * Creates an {@link Amity.Invitation}
8140
+ *
8141
+ * @param bundle The data necessary to create a new {@link Amity.Invitation}
8142
+ * @returns The newly created {@link Amity.Invitation}
8143
+ *
8144
+ * @category Invitation API
8145
+ * @async
8146
+ */
8147
+ const createInvitations = async (bundle) => {
8148
+ const client = getActiveClient();
8149
+ client.log('invitation/createInvitations', bundle);
8150
+ const { data: payload } = await client.http.post('/api/v1/invitations', bundle);
8151
+ const data = prepareInvitationPayload(payload);
8152
+ const cachedAt = client.cache && Date.now();
8153
+ if (client.cache)
8154
+ ingestInCache(data, { cachedAt });
8155
+ fireEvent('local.invitation.created', data.invitations);
8156
+ return {
8157
+ data: data.invitations,
8158
+ cachedAt,
8159
+ };
8160
+ };
8161
+ /* end_public_function */
8162
+
8163
+ /* begin_public_function
8164
+ id: invitation.accept
8165
+ */
8166
+ /**
8167
+ * ```js
8168
+ * import { acceptInvitation } from '@amityco/ts-sdk'
8169
+ * const isAccepted = await acceptInvitation(invitationId)
8170
+ * ```
8171
+ *
8172
+ * Accepts a {@link Amity.Invitation} object
8173
+ *
8174
+ * @param invitationId the {@link Amity.Invitation} to accept
8175
+ * @returns A success boolean if the {@link Amity.Invitation} was accepted
8176
+ *
8177
+ * @category Invitation API
8178
+ * @async
8179
+ */
8180
+ const acceptInvitation = async (invitationId) => {
8181
+ var _a;
8182
+ const client = getActiveClient();
8183
+ client.log('invitation/acceptInvitation', invitationId);
8184
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/accept`);
8185
+ const invitation = (_a = pullFromCache([
8186
+ 'invitation',
8187
+ 'get',
8188
+ invitationId,
8189
+ ])) === null || _a === void 0 ? void 0 : _a.data;
8190
+ if (invitation) {
8191
+ upsertInCache(['invitation', 'get', invitationId], { status: "approved" /* InvitationStatusEnum.Approved */ });
8192
+ fireEvent('local.invitation.updated', [invitation]);
8193
+ }
8194
+ return data.success;
8195
+ };
8196
+ /* end_public_function */
8197
+
8198
+ /* begin_public_function
8199
+ id: invitation.reject
8200
+ */
8201
+ /**
8202
+ * ```js
8203
+ * import { rejectInvitation } from '@amityco/ts-sdk'
8204
+ * const isRejected = await rejectInvitation(invitationId)
8205
+ * ```
8206
+ *
8207
+ * Rejects a {@link Amity.Invitation} object
8208
+ *
8209
+ * @param invitationId the {@link Amity.Invitation} to reject
8210
+ * @returns A success boolean if the {@link Amity.Invitation} was rejected
8211
+ *
8212
+ * @category Invitation API
8213
+ * @async
8214
+ */
8215
+ const rejectInvitation = async (invitationId) => {
8216
+ var _a;
8217
+ const client = getActiveClient();
8218
+ client.log('invitation/rejectInvitation', invitationId);
8219
+ const { data } = await client.http.post(`/api/v1/invitations/${invitationId}/reject`);
8220
+ const invitation = (_a = pullFromCache([
8221
+ 'invitation',
8222
+ 'get',
8223
+ invitationId,
8224
+ ])) === null || _a === void 0 ? void 0 : _a.data;
8225
+ if (invitation) {
8226
+ upsertInCache(['invitation', 'get', invitationId], { status: "rejected" /* InvitationStatusEnum.Rejected */ });
8227
+ fireEvent('local.invitation.updated', [invitation]);
8228
+ }
8229
+ return data.success;
8230
+ };
8231
+ /* end_public_function */
8232
+
8233
+ const prepareMyInvitationsPayload = (rawPayload) => {
8234
+ return Object.assign(Object.assign({}, rawPayload), { users: rawPayload.users.map(convertRawUserToInternalUser), invitations: rawPayload.invitations.map(convertRawInvitationToInternalInvitation) });
8235
+ };
8236
+
8237
+ const invitationLinkedObject = (invitation) => {
8238
+ return Object.assign(Object.assign({}, invitation), { get user() {
8239
+ const cacheData = pullFromCache(['user', 'get', invitation.invitedUserPublicId]);
8240
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8241
+ return userLinkedObject(cacheData.data);
8242
+ return undefined;
8243
+ },
8244
+ get createdBy() {
8245
+ const cacheData = pullFromCache(['user', 'get', invitation.inviterUserPublicId]);
8246
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8247
+ return userLinkedObject(cacheData.data);
8248
+ return undefined;
8249
+ },
8250
+ get target() {
8251
+ if (invitation.targetType === 'community') {
8252
+ const cacheData = pullFromCache([
8253
+ 'community',
8254
+ 'get',
8255
+ invitation.targetId,
8256
+ ]);
8257
+ if (cacheData === null || cacheData === void 0 ? void 0 : cacheData.data)
8258
+ return cacheData.data;
8259
+ return undefined;
8260
+ }
8261
+ return undefined;
8262
+ }, accept: async () => {
8263
+ await acceptInvitation(invitation._id);
8264
+ }, reject: async () => {
8265
+ await rejectInvitation(invitation._id);
8266
+ } });
8267
+ };
8268
+
8269
+ /* begin_public_function
8270
+ id: invitation.get
8271
+ */
8272
+ /**
8273
+ * ```js
8274
+ * import { getInvitation } from '@amityco/ts-sdk'
8275
+ * const { invitation } = await getInvitation(targetType, targetId)
8276
+ * ```
8277
+ *
8278
+ * Get a {@link Amity.Invitation} object
8279
+ *
8280
+ * @param targetType The type of the target of the {@link Amity.Invitation}
8281
+ * @param targetId The ID of the target of the {@link Amity.Invitation}
8282
+ * @returns A {@link Amity.Invitation} object
8283
+ *
8284
+ * @category Invitation API
8285
+ * @async
8286
+ */
8287
+ const getInvitation = async (targetType, targetId) => {
8288
+ const client = getActiveClient();
8289
+ client.log('invitation/getInvitation', targetType, targetId);
8290
+ const { data: payload } = await client.http.get(`/api/v1/invitations/me`, { params: { targetType, targetId } });
8291
+ const data = prepareMyInvitationsPayload(payload);
8292
+ const cachedAt = client.cache && Date.now();
8293
+ if (client.cache)
8294
+ ingestInCache(data, { cachedAt });
8295
+ return {
8296
+ data: data.invitations[0] ? invitationLinkedObject(data.invitations[0]) : undefined,
8297
+ cachedAt,
8298
+ };
8299
+ };
8300
+ /* end_public_function */
8301
+
8302
+ var InvitationActionsEnum;
8303
+ (function (InvitationActionsEnum) {
8304
+ InvitationActionsEnum["OnLocalInvitationCreated"] = "onLocalInvitationCreated";
8305
+ InvitationActionsEnum["OnLocalInvitationUpdated"] = "onLocalInvitationUpdated";
8306
+ InvitationActionsEnum["OnLocalInvitationDeleted"] = "onLocalInvitationDeleted";
8307
+ })(InvitationActionsEnum || (InvitationActionsEnum = {}));
8308
+
8309
+ class InvitationsPaginationController extends PaginationController {
8310
+ async getRequest(queryParams, token) {
8311
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
8312
+ const options = token ? { token } : { limit };
8313
+ const { data } = await this.http.get('/api/v1/invitations', { params: Object.assign(Object.assign({}, params), { options }) });
8314
+ return data;
8315
+ }
8316
+ }
8317
+
8318
+ class InvitationsQueryStreamController extends QueryStreamController {
8319
+ constructor(query, cacheKey, notifyChange, preparePayload) {
8320
+ super(query, cacheKey);
8321
+ this.notifyChange = notifyChange;
8322
+ this.preparePayload = preparePayload;
8323
+ }
8324
+ async saveToMainDB(response) {
8325
+ const processedPayload = await this.preparePayload(response);
8326
+ const client = getActiveClient();
8327
+ const cachedAt = client.cache && Date.now();
8328
+ if (client.cache) {
8329
+ ingestInCache(processedPayload, { cachedAt });
8330
+ }
8331
+ }
8332
+ appendToQueryStream(response, direction, refresh = false) {
8333
+ var _a, _b;
8334
+ if (refresh) {
8335
+ pushToCache(this.cacheKey, {
8336
+ data: response.invitations.map(getResolver('invitation')),
8337
+ });
8338
+ }
8339
+ else {
8340
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8341
+ const invitations = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
8342
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
8343
+ ...new Set([...invitations, ...response.invitations.map(getResolver('invitation'))]),
8344
+ ] }));
8345
+ }
8346
+ }
8347
+ reactor(action) {
8348
+ return (invitations) => {
8349
+ var _a;
8350
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
8351
+ if (!collection)
8352
+ return;
8353
+ if (action === InvitationActionsEnum.OnLocalInvitationUpdated) {
8354
+ const isExist = collection.data.find(id => id === invitations[0].invitationId);
8355
+ if (!isExist)
8356
+ return;
8357
+ }
8358
+ if (action === InvitationActionsEnum.OnLocalInvitationCreated) {
8359
+ collection.data = [
8360
+ ...new Set([
8361
+ ...invitations.map(invitation => invitation.invitationId),
8362
+ ...collection.data,
8363
+ ]),
8364
+ ];
8365
+ }
8366
+ if (action === InvitationActionsEnum.OnLocalInvitationDeleted) {
8367
+ collection.data = collection.data.filter(id => id !== invitations[0].invitationId);
8368
+ }
8369
+ pushToCache(this.cacheKey, collection);
8370
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
8371
+ };
8372
+ }
8373
+ subscribeRTE(createSubscriber) {
8374
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
7839
8375
  }
7840
8376
  }
7841
8377
 
@@ -8047,6 +8583,11 @@ const communityLinkedObject = (community) => {
8047
8583
  }, getInvitation: async () => {
8048
8584
  const { data } = await getInvitation('community', community.communityId);
8049
8585
  return data;
8586
+ }, join: joinRequest(community.communityId), getJoinRequests: (params, callback) => {
8587
+ return getJoinRequests(Object.assign(Object.assign({}, params), { communityId: community.communityId }), callback);
8588
+ }, getMyJoinRequest: async () => {
8589
+ const { data } = await getMyJoinRequest(community.communityId);
8590
+ return data;
8050
8591
  } });
8051
8592
  };
8052
8593
 
@@ -8066,6 +8607,7 @@ const LinkedObject = {
8066
8607
  notificationTray: notificationTrayLinkedObject,
8067
8608
  community: communityLinkedObject,
8068
8609
  invitation: invitationLinkedObject,
8610
+ joinRequest: joinRequestLinkedObject,
8069
8611
  };
8070
8612
 
8071
8613
  const constructChannelObject = (channel) => {
@@ -13622,41 +14164,6 @@ getComment$2.locally = (commentId) => {
13622
14164
  };
13623
14165
  };
13624
14166
 
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
14167
  const getMyReactionsInCache = (payload, eventPrefix) => {
13661
14168
  var _a, _b;
13662
14169
  let id;
@@ -13971,53 +14478,6 @@ removeReaction.optimistically = (referenceType, referenceId, reactionName) => {
13971
14478
  return !((_d = reaction === null || reaction === void 0 ? void 0 : reaction.myReactions) === null || _d === void 0 ? void 0 : _d.includes(reactionName));
13972
14479
  };
13973
14480
 
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
14481
  const preparePostPayload = (payload) => {
14022
14482
  const { posts: postsData } = payload, postPayload = __rest(payload, ["posts"]);
14023
14483
  // Unpack community payload by mapping payload field to postSetting value.
@@ -19081,10 +19541,11 @@ const saveCommunityUsers = (communities, communityUsers) => {
19081
19541
  const getCommunities$1 = async (communityIds, includeDiscoverablePrivateCommunity) => {
19082
19542
  const client = getActiveClient();
19083
19543
  client.log('community/getCommunities', communityIds);
19544
+ const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
19084
19545
  // API-FIX: endpoint should not be /list, parameters should be querystring.
19085
19546
  const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
19086
19547
  params: {
19087
- communityIds,
19548
+ communityIds: encodedCommunityIds,
19088
19549
  includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
19089
19550
  },
19090
19551
  });
@@ -19218,11 +19679,16 @@ const updateCommunity = async (communityId, patch) => {
19218
19679
  * @category Community API
19219
19680
  * @async
19220
19681
  */
19221
- const getCommunity$1 = async (communityId) => {
19682
+ const getCommunity$1 = async (communityId, type, includeDiscoverablePrivateCommunity) => {
19222
19683
  const client = getActiveClient();
19223
19684
  client.log('community/getCommunity', communityId);
19224
19685
  // API-FIX: endpoint should not be /list, parameters should be querystring.
19225
- const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
19686
+ const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`, {
19687
+ params: {
19688
+ type: 'communityJoinRequest',
19689
+ includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity !== null && includeDiscoverablePrivateCommunity !== void 0 ? includeDiscoverablePrivateCommunity : true,
19690
+ },
19691
+ });
19226
19692
  const data = prepareCommunityPayload(payload);
19227
19693
  const cachedAt = client.cache && Date.now();
19228
19694
  if (client.cache) {
@@ -19297,6 +19763,9 @@ const deleteCommunity = async (communityId) => {
19297
19763
  };
19298
19764
  /* end_public_function */
19299
19765
 
19766
+ /**
19767
+ * @deprecated This function will to be deprecated and use the new community.join().
19768
+ */
19300
19769
  /* begin_public_function
19301
19770
  id: community.join
19302
19771
  */
@@ -19437,10 +19906,11 @@ const onCommunityDeleted = (callback) => createCommunityEventSubscriber('communi
19437
19906
  */
19438
19907
  class CommunitiesPaginationController$1 extends PaginationController {
19439
19908
  async getRequest(queryParams, token) {
19909
+ var _a;
19440
19910
  const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
19441
19911
  const options = token ? { token } : { limit };
19442
19912
  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 }),
19913
+ 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
19914
  });
19445
19915
  return queryResponse;
19446
19916
  }
@@ -19940,6 +20410,19 @@ const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubs
19940
20410
 
19941
20411
  const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
19942
20412
 
20413
+ const onLocalCommunityJoin = (callback) => {
20414
+ const client = getActiveClient();
20415
+ const filter = async (rawPayload) => {
20416
+ callback(rawPayload[0]);
20417
+ };
20418
+ const disposers = [
20419
+ createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
20420
+ ];
20421
+ return () => {
20422
+ disposers.forEach(fn => fn());
20423
+ };
20424
+ };
20425
+
19943
20426
  /**
19944
20427
  * ```js
19945
20428
  * import { onLocalCommunityRoleRemoved } from '@amityco/ts-sdk'
@@ -20426,7 +20909,8 @@ var index$d = /*#__PURE__*/Object.freeze({
20426
20909
  onCommunityJoined: onCommunityJoined,
20427
20910
  onCommunityLeft: onCommunityLeft,
20428
20911
  onLocalCommunityJoined: onLocalCommunityJoined,
20429
- onLocalCommunityLeft: onLocalCommunityLeft
20912
+ onLocalCommunityLeft: onLocalCommunityLeft,
20913
+ onLocalCommunityJoin: onLocalCommunityJoin
20430
20914
  });
20431
20915
 
20432
20916
  class SearchCommunityLiveCollectionController extends LiveCollectionController {
@@ -20650,6 +21134,10 @@ class CommunityLiveCollectionController extends LiveCollectionController {
20650
21134
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
20651
21135
  { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
20652
21136
  { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
21137
+ {
21138
+ fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
21139
+ action: EnumCommunityActions$3.OnCommunityUpdated,
21140
+ },
20653
21141
  ]);
20654
21142
  }
20655
21143
  notifyChange({ origin, loading, error }) {
@@ -20773,6 +21261,7 @@ const getCommunity = (communityId, callback) => {
20773
21261
  onCommunityUserBanned,
20774
21262
  onCommunityUserUnbanned,
20775
21263
  onCommunityUserChanged,
21264
+ convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
20776
21265
  ]);
20777
21266
  };
20778
21267
  /* end_public_function */
@@ -20887,7 +21376,7 @@ class TrendingCommunityLiveCollectionController extends LiveCollectionController
20887
21376
  const data = (_b = collection.data
20888
21377
  .map(id => pullFromCache(['community', 'get', id]))
20889
21378
  .filter(isNonNullable)
20890
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
21379
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
20891
21380
  if (!this.shouldNotify(data) && origin === 'event')
20892
21381
  return;
20893
21382
  this.callback({
@@ -21049,7 +21538,7 @@ class RecommendedCommunityLiveCollectionController extends LiveCollectionControl
21049
21538
  const data = (_b = collection.data
21050
21539
  .map(id => pullFromCache(['community', 'get', id]))
21051
21540
  .filter(isNonNullable)
21052
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
21541
+ .map(({ data }) => communityLinkedObject(data))) !== null && _b !== void 0 ? _b : [];
21053
21542
  if (!this.shouldNotify(data) && origin === 'event')
21054
21543
  return;
21055
21544
  this.callback({
@@ -21289,6 +21778,200 @@ const semanticSearchCommunities = (params, callback, config) => {
21289
21778
  };
21290
21779
  };
21291
21780
 
21781
+ /**
21782
+ * TODO: handle cache receive cache option, and cache policy
21783
+ * TODO: check if querybyIds is supported
21784
+ */
21785
+ class JoinRequestListPaginationController extends PaginationController {
21786
+ async getRequest(queryParams, token) {
21787
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds } = queryParams, params = __rest(queryParams, ["limit", "communityIds"]);
21788
+ const options = token ? { token } : { limit };
21789
+ const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
21790
+ const { data: queryResponse } = await this.http.get(`/api/v4/communities/join/requests`, {
21791
+ params: Object.assign(Object.assign({}, params), { options, communityIds: encodedChannelIds }),
21792
+ });
21793
+ return queryResponse;
21794
+ }
21795
+ }
21796
+
21797
+ var EnumJoinRequestAction;
21798
+ (function (EnumJoinRequestAction) {
21799
+ EnumJoinRequestAction["OnLocalJoinRequestCreated"] = "OnLocalJoinRequestCreated";
21800
+ EnumJoinRequestAction["OnLocalJoinRequestUpdated"] = "OnLocalJoinRequestUpdated";
21801
+ EnumJoinRequestAction["OnLocalJoinRequestDeleted"] = "OnLocalJoinRequestDeleted";
21802
+ })(EnumJoinRequestAction || (EnumJoinRequestAction = {}));
21803
+
21804
+ class JoinRequestListQueryStreamController extends QueryStreamController {
21805
+ constructor(query, cacheKey, notifyChange, preparePayload) {
21806
+ super(query, cacheKey);
21807
+ this.notifyChange = notifyChange;
21808
+ this.preparePayload = preparePayload;
21809
+ }
21810
+ async saveToMainDB(response) {
21811
+ const processedPayload = await this.preparePayload(response);
21812
+ const client = getActiveClient();
21813
+ const cachedAt = client.cache && Date.now();
21814
+ if (client.cache) {
21815
+ ingestInCache(processedPayload, { cachedAt });
21816
+ }
21817
+ }
21818
+ appendToQueryStream(response, direction, refresh = false) {
21819
+ var _a, _b;
21820
+ if (refresh) {
21821
+ pushToCache(this.cacheKey, {
21822
+ data: response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
21823
+ });
21824
+ }
21825
+ else {
21826
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21827
+ const joinRequests = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
21828
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
21829
+ ...new Set([
21830
+ ...joinRequests,
21831
+ ...response.joinRequests.map(joinRequest => getResolver('joinRequest')({ joinRequestId: joinRequest._id })),
21832
+ ]),
21833
+ ] }));
21834
+ }
21835
+ }
21836
+ reactor(action) {
21837
+ return (joinRequest) => {
21838
+ var _a;
21839
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21840
+ if (!collection)
21841
+ return;
21842
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
21843
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
21844
+ if (!isExist)
21845
+ return;
21846
+ }
21847
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
21848
+ collection.data = [
21849
+ ...new Set([
21850
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
21851
+ ...collection.data,
21852
+ ]),
21853
+ ];
21854
+ }
21855
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
21856
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
21857
+ }
21858
+ pushToCache(this.cacheKey, collection);
21859
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
21860
+ };
21861
+ }
21862
+ subscribeRTE(createSubscriber) {
21863
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
21864
+ }
21865
+ }
21866
+
21867
+ class JoinRequestListLiveCollectionController extends LiveCollectionController {
21868
+ constructor(query, callback) {
21869
+ const queryStreamId = hash__default["default"](query);
21870
+ const cacheKey = ['joinRequestList', 'collection', queryStreamId];
21871
+ const paginationController = new JoinRequestListPaginationController(query);
21872
+ super(paginationController, queryStreamId, cacheKey, callback);
21873
+ this.query = query;
21874
+ this.queryStreamController = new JoinRequestListQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityJoinRequestPayload);
21875
+ this.callback = callback.bind(this);
21876
+ this.loadPage({ initial: true });
21877
+ }
21878
+ setup() {
21879
+ var _a;
21880
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21881
+ if (!collection) {
21882
+ pushToCache(this.cacheKey, {
21883
+ data: [],
21884
+ params: this.query,
21885
+ });
21886
+ }
21887
+ }
21888
+ async persistModel(queryPayload) {
21889
+ await this.queryStreamController.saveToMainDB(queryPayload);
21890
+ }
21891
+ persistQueryStream({ response, direction, refresh, }) {
21892
+ const joinRequestResponse = response;
21893
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
21894
+ }
21895
+ startSubscription() {
21896
+ return this.queryStreamController.subscribeRTE([
21897
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
21898
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
21899
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
21900
+ ]);
21901
+ }
21902
+ notifyChange({ origin, loading, error }) {
21903
+ var _a;
21904
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
21905
+ if (!collection)
21906
+ return;
21907
+ const data = this.applyFilter(collection.data
21908
+ .map(id => pullFromCache(['joinRequest', 'get', id]))
21909
+ .filter(isNonNullable)
21910
+ .map(({ data }) => data)
21911
+ .map(joinRequestLinkedObject));
21912
+ if (!this.shouldNotify(data) && origin === 'event')
21913
+ return;
21914
+ this.callback({
21915
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
21916
+ data,
21917
+ hasNextPage: !!this.paginationController.getNextToken(),
21918
+ loading,
21919
+ error,
21920
+ });
21921
+ }
21922
+ applyFilter(data) {
21923
+ let joinRequest = data;
21924
+ if (this.query.communityIds && this.query.communityIds.length > 0) {
21925
+ joinRequest = joinRequest.filter(joinRequest => this.query.communityIds.some(id => id === joinRequest.targetId));
21926
+ }
21927
+ const sortFn = (() => {
21928
+ switch (this.query.sortBy) {
21929
+ case 'firstCreated':
21930
+ return sortByFirstCreated;
21931
+ case 'lastCreated':
21932
+ return sortByLastCreated;
21933
+ default:
21934
+ return sortByLastCreated;
21935
+ }
21936
+ })();
21937
+ joinRequest = joinRequest.sort(sortFn);
21938
+ return joinRequest;
21939
+ }
21940
+ }
21941
+
21942
+ /* begin_public_function
21943
+ id: community.getJoinRequestList
21944
+ */
21945
+ /**
21946
+ * Get Join Requests
21947
+ *
21948
+ * @param params the query parameters
21949
+ * @param callback the callback to be called when the join request are updated
21950
+ * @returns joinRequest[]
21951
+ *
21952
+ * @category joinRequestList Live Collection
21953
+ *
21954
+ */
21955
+ const getJoinRequestList = (params, callback, config) => {
21956
+ const { log, cache } = getActiveClient();
21957
+ if (!cache) {
21958
+ console.log(ENABLE_CACHE_MESSAGE);
21959
+ }
21960
+ const timestamp = Date.now();
21961
+ log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
21962
+ const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(params, callback);
21963
+ const disposers = joinRequestListLiveCollection.startSubscription();
21964
+ const cacheKey = joinRequestListLiveCollection.getCacheKey();
21965
+ disposers.push(() => {
21966
+ dropFromCache(cacheKey);
21967
+ });
21968
+ return () => {
21969
+ log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
21970
+ disposers.forEach(fn => fn());
21971
+ };
21972
+ };
21973
+ /* end_public_function */
21974
+
21292
21975
  var AmityCommunityMemberStatusFilter;
21293
21976
  (function (AmityCommunityMemberStatusFilter) {
21294
21977
  AmityCommunityMemberStatusFilter["ALL"] = "all";
@@ -21459,6 +22142,7 @@ var index$b = /*#__PURE__*/Object.freeze({
21459
22142
  getTrendingCommunities: getTrendingCommunities,
21460
22143
  getRecommendedCommunities: getRecommendedCommunities,
21461
22144
  semanticSearchCommunities: semanticSearchCommunities,
22145
+ getJoinRequestList: getJoinRequestList,
21462
22146
  get AmityCommunityMemberStatusFilter () { return AmityCommunityMemberStatusFilter; }
21463
22147
  });
21464
22148
 
@@ -23699,7 +24383,8 @@ class PinnedPostQueryStreamController extends QueryStreamController {
23699
24383
  const client = getActiveClient();
23700
24384
  const cachedAt = client.cache && Date.now();
23701
24385
  if (client.cache) {
23702
- ingestInCache(response, { cachedAt });
24386
+ const processedPayload = Object.assign(Object.assign({}, response), { users: response.users ? response.users.map(convertRawUserToInternalUser) : [] });
24387
+ ingestInCache(processedPayload, { cachedAt });
23703
24388
  }
23704
24389
  }
23705
24390
  appendToQueryStream(response, direction, refresh = false) {
@@ -23828,7 +24513,8 @@ class GlobalPinnedPostQueryStreamController extends QueryStreamController {
23828
24513
  const client = getActiveClient();
23829
24514
  const cachedAt = client.cache && Date.now();
23830
24515
  if (client.cache) {
23831
- ingestInCache(response, { cachedAt });
24516
+ const processedPayload = Object.assign(Object.assign({}, response), { users: response.users.map(convertRawUserToInternalUser) });
24517
+ ingestInCache(processedPayload, { cachedAt });
23832
24518
  }
23833
24519
  }
23834
24520
  appendToQueryStream(response, direction, refresh = false) {