@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
@@ -0,0 +1,108 @@
1
+ import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { ingestInCache } from '~/cache/api/ingestInCache';
4
+ import { getResolver } from '~/core/model';
5
+ import { getActiveClient } from '~/client/api/activeClient';
6
+ import { EnumJoinRequestAction } from './enum';
7
+
8
+ export class JoinRequestsQueryStreamController extends QueryStreamController<
9
+ Amity.CommunityJoinRequestPayload,
10
+ Amity.JoinRequestLiveCollection
11
+ > {
12
+ private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
13
+
14
+ private preparePayload: (
15
+ response: Amity.CommunityJoinRequestPayload,
16
+ ) => Amity.ProcessedJoinRequestPayload;
17
+
18
+ constructor(
19
+ query: Amity.JoinRequestLiveCollection,
20
+ cacheKey: string[],
21
+ notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
22
+ preparePayload: (
23
+ response: Amity.CommunityJoinRequestPayload,
24
+ ) => Amity.ProcessedJoinRequestPayload,
25
+ ) {
26
+ super(query, cacheKey);
27
+ this.notifyChange = notifyChange;
28
+ this.preparePayload = preparePayload;
29
+ }
30
+
31
+ async saveToMainDB(response: Amity.CommunityJoinRequestPayload) {
32
+ const processedPayload = await this.preparePayload(response);
33
+
34
+ const client = getActiveClient();
35
+ const cachedAt = client.cache && Date.now();
36
+
37
+ if (client.cache) {
38
+ ingestInCache(processedPayload, { cachedAt });
39
+ }
40
+ }
41
+
42
+ appendToQueryStream(
43
+ response: Amity.CommunityJoinRequestPayload & Partial<Amity.Pagination>,
44
+ direction: Amity.LiveCollectionPageDirection,
45
+ refresh = false,
46
+ ) {
47
+ if (refresh) {
48
+ pushToCache(this.cacheKey, {
49
+ data: response.joinRequests.map(joinRequest =>
50
+ getResolver('joinRequest')({ joinRequestId: joinRequest._id }),
51
+ ),
52
+ });
53
+ } else {
54
+ const collection = pullFromCache<Amity.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
55
+
56
+ const joinRequests = collection?.data ?? [];
57
+
58
+ pushToCache(this.cacheKey, {
59
+ ...collection,
60
+ data: [
61
+ ...new Set([
62
+ ...joinRequests,
63
+ ...response.joinRequests.map(joinRequest =>
64
+ getResolver('joinRequest')({ joinRequestId: joinRequest._id }),
65
+ ),
66
+ ]),
67
+ ],
68
+ });
69
+ }
70
+ }
71
+
72
+ reactor(action: EnumJoinRequestAction) {
73
+ return (joinRequest: Amity.InternalJoinRequest[]) => {
74
+ const collection = pullFromCache<Amity.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
75
+ if (!collection) return;
76
+
77
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
78
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
79
+ if (!isExist) return;
80
+ }
81
+
82
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
83
+ collection.data = [
84
+ ...new Set([
85
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
86
+ ...collection.data,
87
+ ]),
88
+ ];
89
+ }
90
+
91
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
92
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
93
+ }
94
+
95
+ pushToCache(this.cacheKey, collection);
96
+ this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
97
+ };
98
+ }
99
+
100
+ subscribeRTE(
101
+ createSubscriber: {
102
+ fn: (reactor: Amity.Listener<Amity.InternalJoinRequest[]>) => Amity.Unsubscriber;
103
+ action: EnumJoinRequestAction;
104
+ }[],
105
+ ) {
106
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
107
+ }
108
+ }
@@ -0,0 +1,5 @@
1
+ export enum EnumJoinRequestAction {
2
+ OnLocalJoinRequestCreated = 'OnLocalJoinRequestCreated',
3
+ OnLocalJoinRequestUpdated = 'OnLocalJoinRequestUpdated',
4
+ OnLocalJoinRequestDeleted = 'OnLocalJoinRequestDeleted',
5
+ }
@@ -0,0 +1,44 @@
1
+ import { dropFromCache } from '~/cache/api/dropFromCache';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
4
+ import { JoinRequestsLiveCollectionController } from './getJoinRequests/JoinRequestsLiveCollectionController';
5
+
6
+ /**
7
+ * Get Join Requests
8
+ *
9
+ * @param params the query parameters
10
+ * @param callback the callback to be called when the join request are updated
11
+ * @returns joinRequests
12
+ *
13
+ * @category joinRequest Live Collection
14
+ *
15
+ */
16
+ export const getJoinRequests = (
17
+ params: Amity.JoinRequestLiveCollection,
18
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
19
+ config?: Amity.LiveCollectionConfig,
20
+ ) => {
21
+ const { log, cache } = getActiveClient();
22
+
23
+ if (!cache) {
24
+ console.log(ENABLE_CACHE_MESSAGE);
25
+ }
26
+
27
+ const timestamp = Date.now();
28
+ log(`getJoinRequests: (tmpid: ${timestamp}) > listen`);
29
+
30
+ const joinRequestLiveCollection = new JoinRequestsLiveCollectionController(params, callback);
31
+
32
+ const disposers = joinRequestLiveCollection.startSubscription();
33
+
34
+ const cacheKey = joinRequestLiveCollection.getCacheKey();
35
+
36
+ disposers.push(() => {
37
+ dropFromCache(cacheKey);
38
+ });
39
+
40
+ return () => {
41
+ log(`getJoinRequests (tmpid: ${timestamp}) > dispose`);
42
+ disposers.forEach(fn => fn());
43
+ };
44
+ };
@@ -15,6 +15,7 @@ import {
15
15
  onCommunityUserChanged,
16
16
  } from '~/communityRepository/communityMembership';
17
17
  import { isNonNullable } from '~/utils';
18
+ import { communityLinkedObject } from '~/utils/linkedObject/communityLinkedObject';
18
19
 
19
20
  export class RecommendedCommunityLiveCollectionController extends LiveCollectionController<
20
21
  'community',
@@ -94,7 +95,7 @@ export class RecommendedCommunityLiveCollectionController extends LiveCollection
94
95
  collection.data
95
96
  .map(id => pullFromCache<Amity.Community>(['community', 'get', id]))
96
97
  .filter(isNonNullable)
97
- .map(({ data }) => data) ?? [];
98
+ .map(({ data }) => communityLinkedObject(data)) ?? [];
98
99
 
99
100
  if (!this.shouldNotify(data) && origin === 'event') return;
100
101
 
@@ -15,6 +15,7 @@ import {
15
15
  onCommunityUserChanged,
16
16
  } from '~/communityRepository/communityMembership';
17
17
  import { isNonNullable } from '~/utils';
18
+ import { communityLinkedObject } from '~/utils/linkedObject/communityLinkedObject';
18
19
 
19
20
  export class TrendingCommunityLiveCollectionController extends LiveCollectionController<
20
21
  'community',
@@ -94,7 +95,7 @@ export class TrendingCommunityLiveCollectionController extends LiveCollectionCon
94
95
  collection.data
95
96
  .map(id => pullFromCache<Amity.Community>(['community', 'get', id]))
96
97
  .filter(isNonNullable)
97
- .map(({ data }) => data) ?? [];
98
+ .map(({ data }) => communityLinkedObject(data)) ?? [];
98
99
 
99
100
  if (!this.shouldNotify(data) && origin === 'event') return;
100
101
 
@@ -5,3 +5,4 @@ export * from './getTrendingCommunities';
5
5
  export * from './getRecommendedCommunities';
6
6
 
7
7
  export * from './semanticSearchCommunities';
8
+ export * from './getJoinRequestList';
@@ -22,6 +22,7 @@ export class CommunitiesPaginationController extends PaginationController<
22
22
  isDeleted: inferIsDeleted(params.includeDeleted),
23
23
  keyword: params.displayName,
24
24
  filter: params.membership,
25
+ includeDiscoverablePrivateCommunity: params.includeDiscoverablePrivateCommunity ?? true,
25
26
  options,
26
27
  },
27
28
  },
@@ -1,5 +1,5 @@
1
1
  import { pullFromCache } from '~/cache/api';
2
- import { getActiveUser } from '~/client';
2
+ import { getActiveUser } from '~/client/api/activeUser';
3
3
 
4
4
  /*
5
5
  * verifies membership status
@@ -1,5 +1,6 @@
1
1
  import { CommunityPostSettingMaps, DefaultCommunityPostSetting } from '~/@types';
2
2
  import { updateMembershipStatus } from './communityWithMembership';
3
+ import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
3
4
 
4
5
  const getMatchPostSetting = (value: {
5
6
  needApprovalOnPostCreation: Amity.RawCommunity['needApprovalOnPostCreation'];
@@ -29,10 +30,13 @@ export const prepareCommunityPayload = (
29
30
  ): Amity.ProcessedCommunityPayload => {
30
31
  const communitiesWithPostSetting = addPostSetting({ communities: rawPayload.communities });
31
32
 
33
+ // Convert users to internal format
34
+ const internalUsers = rawPayload.users.map(convertRawUserToInternalUser);
35
+
32
36
  // map users with community
33
37
  const mappedCommunityUsers: Array<Amity.Membership<'community'>> = rawPayload.communityUsers.map(
34
38
  communityUser => {
35
- const user = rawPayload.users.find(user => user.userId === communityUser.userId)!;
39
+ const user = internalUsers.find(user => user.userId === communityUser.userId)!;
36
40
 
37
41
  return {
38
42
  ...communityUser,
@@ -48,11 +52,33 @@ export const prepareCommunityPayload = (
48
52
 
49
53
  return {
50
54
  ...rawPayload,
55
+ users: rawPayload.users.map(convertRawUserToInternalUser),
51
56
  communities: communityWithMembershipStatus,
52
57
  communityUsers: mappedCommunityUsers,
53
58
  };
54
59
  };
55
60
 
61
+ export const prepareCommunityJoinRequestPayload = (
62
+ rawPayload: Amity.CommunityJoinRequestPayload,
63
+ ): Amity.ProcessedJoinRequestPayload => {
64
+ const mappedJoinRequests: Array<Amity.InternalJoinRequest> = rawPayload.joinRequests.map(
65
+ joinRequest => {
66
+ return {
67
+ ...joinRequest,
68
+ joinRequestId: joinRequest._id,
69
+ };
70
+ },
71
+ );
72
+
73
+ const users = rawPayload.users.map(convertRawUserToInternalUser);
74
+
75
+ return {
76
+ ...rawPayload,
77
+ joinRequests: mappedJoinRequests,
78
+ users,
79
+ };
80
+ };
81
+
56
82
  export const prepareCommunityMembershipPayload = (
57
83
  rawPayload: Amity.CommunityMembershipPayload,
58
84
  ): Amity.ProcessedCommunityMembershipPayload => {
@@ -66,6 +66,7 @@ const idResolvers: Resolvers = {
66
66
  notificationTraySeen: ({ userId }) => userId,
67
67
 
68
68
  invitation: ({ _id }) => _id,
69
+ joinRequest: ({ joinRequestId }) => joinRequestId,
69
70
  };
70
71
 
71
72
  /**
@@ -56,6 +56,7 @@ export const PAYLOAD2MODEL: Record<string, Amity.Domain> = {
56
56
  notificationTrayItems: 'notificationTrayItem',
57
57
 
58
58
  invitations: 'invitation',
59
+ joinRequests: 'joinRequest',
59
60
  };
60
61
 
61
62
  /** hidden */
@@ -1,4 +1,3 @@
1
1
  export * from './createInvitations';
2
2
  export * from './acceptInvitation';
3
3
  export * from './rejectInvitation';
4
- export * from './cancelInvitation';
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
  import { getResolver } from '~/core/model';
5
5
  import { getActiveClient } from '~/client';
6
6
  import { EnumPostActions } from '../enums';
7
+ import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
7
8
 
8
9
  export class GlobalPinnedPostQueryStreamController extends QueryStreamController<
9
10
  Amity.PinnedPostPayload,
@@ -30,7 +31,12 @@ export class GlobalPinnedPostQueryStreamController extends QueryStreamController
30
31
  const cachedAt = client.cache && Date.now();
31
32
 
32
33
  if (client.cache) {
33
- ingestInCache(response, { cachedAt });
34
+ const processedPayload = {
35
+ ...response,
36
+ users: response.users.map(convertRawUserToInternalUser),
37
+ };
38
+
39
+ ingestInCache(processedPayload, { cachedAt });
34
40
  }
35
41
  }
36
42
 
@@ -3,6 +3,7 @@ import { pullFromCache, pushToCache } from '~/cache/api';
3
3
  import { ingestInCache } from '~/cache/api/ingestInCache';
4
4
  import { getResolver } from '~/core/model';
5
5
  import { getActiveClient } from '~/client';
6
+ import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
6
7
 
7
8
  export class PinnedPostQueryStreamController extends QueryStreamController<
8
9
  Amity.PinnedPostPayload,
@@ -29,7 +30,12 @@ export class PinnedPostQueryStreamController extends QueryStreamController<
29
30
  const cachedAt = client.cache && Date.now();
30
31
 
31
32
  if (client.cache) {
32
- ingestInCache(response, { cachedAt });
33
+ const processedPayload = {
34
+ ...response,
35
+ users: response.users ? response.users.map(convertRawUserToInternalUser) : [],
36
+ };
37
+
38
+ ingestInCache(processedPayload, { cachedAt });
33
39
  }
34
40
  }
35
41
 
@@ -4,6 +4,7 @@ import { convertFromRaw as convertMessageFromRaw } from '~/messageRepository/uti
4
4
  import { convertFromRaw as convertSubChannelFromRaw } from './convertSubChannelFromRaw';
5
5
 
6
6
  import { updateSubChannelMessagePreviewCache } from '../../messagePreview/utils/updateSubChannelMessagePreviewCache';
7
+ import { convertRawUserToInternalUser } from '~/userRepository/utils/convertRawUserToInternalUser';
7
8
 
8
9
  export const MARKER_INCLUDED_SUB_CHANNEL_TYPE = ['broadcast', 'conversation', 'community'];
9
10
 
@@ -44,10 +45,13 @@ export const prepareSubChannelPayload = async (
44
45
 
45
46
  const messages = rawPayload.messages.map(m => convertMessageFromRaw(m));
46
47
 
48
+ const user = rawPayload.users.map(convertRawUserToInternalUser);
49
+
47
50
  return {
48
51
  ...rawPayload,
49
52
  messageFeeds,
50
53
  messages,
54
+ users: user,
51
55
  };
52
56
  };
53
57
 
@@ -1,4 +1,7 @@
1
1
  import { InvitationTypeEnum } from '~/@types';
2
+ import { getMyJoinRequest } from '~/communityRepository/internalAPI/getMyJoinRequest';
3
+ import { joinRequest } from '~/communityRepository/internalAPI/joinCommunity';
4
+ import { getJoinRequests } from '~/communityRepository/observers/getJoinRequests';
2
5
  import { createInvitations } from '~/invitationRepository/internalApi';
3
6
  import { getInvitation } from '~/invitationRepository/internalApi/getInvitation';
4
7
  import { getInvitations } from '~/invitationRepository/observers/getInvitations';
@@ -32,5 +35,22 @@ export const communityLinkedObject = (community: Amity.InternalCommunity): Amity
32
35
  const { data } = await getInvitation('community', community.communityId);
33
36
  return data;
34
37
  },
38
+ join: joinRequest(community.communityId),
39
+ getJoinRequests: (
40
+ params: Omit<Amity.QueryJoinRequest, 'communityId'>,
41
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
42
+ ): Amity.Unsubscriber => {
43
+ return getJoinRequests(
44
+ {
45
+ ...params,
46
+ communityId: community.communityId,
47
+ },
48
+ callback,
49
+ );
50
+ },
51
+ getMyJoinRequest: async () => {
52
+ const { data } = await getMyJoinRequest(community.communityId);
53
+ return data;
54
+ },
35
55
  };
36
56
  };
@@ -13,6 +13,7 @@ import { pinnedPostLinkedObject } from './pinnedPostLinkedObject';
13
13
  import { notificationTrayLinkedObject } from './notificationTrayLinkedObject';
14
14
  import { communityLinkedObject } from './communityLinkedObject';
15
15
  import { invitationLinkedObject } from './invitationLinkedObject';
16
+ import { joinRequestLinkedObject } from './joinRequestLinkedObject';
16
17
 
17
18
  export const LinkedObject = {
18
19
  ad: adLinkedObject,
@@ -30,4 +31,5 @@ export const LinkedObject = {
30
31
  notificationTray: notificationTrayLinkedObject,
31
32
  community: communityLinkedObject,
32
33
  invitation: invitationLinkedObject,
34
+ joinRequest: joinRequestLinkedObject,
33
35
  };
@@ -1,10 +1,6 @@
1
1
  import { pullFromCache } from '~/cache/api';
2
2
  import { userLinkedObject } from './userLinkedObject';
3
- import {
4
- acceptInvitation,
5
- cancelInvitation,
6
- rejectInvitation,
7
- } from '~/invitationRepository/internalApi';
3
+ import { acceptInvitation, rejectInvitation } from '~/invitationRepository/internalApi';
8
4
 
9
5
  export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Amity.Invitation => {
10
6
  return {
@@ -37,8 +33,5 @@ export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Am
37
33
  reject: async () => {
38
34
  await rejectInvitation(invitation._id);
39
35
  },
40
- cancel: async () => {
41
- await cancelInvitation(invitation._id);
42
- },
43
36
  };
44
37
  };
@@ -0,0 +1,25 @@
1
+ import { pullFromCache } from '~/cache/api';
2
+ import { userLinkedObject } from './userLinkedObject';
3
+ import { approveJoinRequest } from '~/communityRepository/joinRequest/internalAPI/approveJoinRequest';
4
+ import { cancelJoinRequest } from '~/communityRepository/joinRequest/internalAPI/cancelJoinRequest';
5
+ import { rejectJoinRequest } from '~/communityRepository/joinRequest/internalAPI/rejectJoinRequest';
6
+
7
+ export const joinRequestLinkedObject = (
8
+ joinRequest: Amity.InternalJoinRequest,
9
+ ): Amity.JoinRequest => {
10
+ return {
11
+ ...joinRequest,
12
+ get user(): Amity.User | undefined {
13
+ const user = pullFromCache<Amity.InternalUser>([
14
+ 'user',
15
+ 'get',
16
+ joinRequest.requestorPublicId,
17
+ ])?.data;
18
+ if (!user) return undefined;
19
+ return userLinkedObject(user);
20
+ },
21
+ cancel: () => cancelJoinRequest(joinRequest),
22
+ approve: () => approveJoinRequest(joinRequest),
23
+ reject: () => rejectJoinRequest(joinRequest),
24
+ };
25
+ };
@@ -1,16 +0,0 @@
1
- /**
2
- * ```js
3
- * import { cancelInvitation } from '@amityco/ts-sdk'
4
- * const isCanceled = await cancelInvitation(invitationId)
5
- * ```
6
- *
7
- * Cancels a {@link Amity.Invitation} object
8
- *
9
- * @param invitationId the {@link Amity.Invitation} to cancel
10
- * @returns A success boolean if the {@link Amity.Invitation} was canceled
11
- *
12
- * @category Invitation API
13
- * @async
14
- */
15
- export declare const cancelInvitation: (invitationId: Amity.Invitation['_id']) => Promise<boolean>;
16
- //# sourceMappingURL=cancelInvitation.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"cancelInvitation.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/internalApi/cancelInvitation.ts"],"names":[],"mappings":"AAOA;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,gBAAgB,iBAAwB,MAAM,UAAU,CAAC,KAAK,CAAC,KAAG,QAAQ,OAAO,CAqB7F,CAAC"}
@@ -1,44 +0,0 @@
1
- import { fireEvent } from '~/core/events';
2
- import { dropFromCache, pullFromCache } from '~/cache/api';
3
- import { getActiveClient } from '~/client/api/activeClient';
4
-
5
- /* begin_public_function
6
- id: invitation.cancel
7
- */
8
- /**
9
- * ```js
10
- * import { cancelInvitation } from '@amityco/ts-sdk'
11
- * const isCanceled = await cancelInvitation(invitationId)
12
- * ```
13
- *
14
- * Cancels a {@link Amity.Invitation} object
15
- *
16
- * @param invitationId the {@link Amity.Invitation} to cancel
17
- * @returns A success boolean if the {@link Amity.Invitation} was canceled
18
- *
19
- * @category Invitation API
20
- * @async
21
- */
22
- export const cancelInvitation = async (invitationId: Amity.Invitation['_id']): Promise<boolean> => {
23
- const client = getActiveClient();
24
- client.log('invitation/cancelInvitation', invitationId);
25
-
26
- const { data } = await client.http.delete<{ success: boolean }>(
27
- `/api/v1/invitations/${invitationId}`,
28
- );
29
-
30
- const invitation = pullFromCache<Amity.InternalInvitation>([
31
- 'invitation',
32
- 'get',
33
- invitationId,
34
- ])?.data;
35
-
36
- if (invitation) {
37
- dropFromCache(['invitation', 'get', invitationId]);
38
-
39
- fireEvent('local.invitation.deleted', [invitation]);
40
- }
41
-
42
- return data.success;
43
- };
44
- /* end_public_function */