@amityco/ts-sdk 7.4.1-fd0f791a.0 → 7.5.1-12f08f0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/@types/core/events.d.ts +1 -1
  2. package/dist/@types/core/events.d.ts.map +1 -1
  3. package/dist/@types/domains/community.d.ts +11 -0
  4. package/dist/@types/domains/community.d.ts.map +1 -1
  5. package/dist/@types/domains/invitation.d.ts +0 -1
  6. package/dist/@types/domains/invitation.d.ts.map +1 -1
  7. package/dist/@types/domains/notification.d.ts +4 -2
  8. package/dist/@types/domains/notification.d.ts.map +1 -1
  9. package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
  10. package/dist/communityRepository/communityMembership/events/index.d.ts +1 -0
  11. package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
  12. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts +2 -0
  13. package/dist/communityRepository/communityMembership/events/onLocalCommunityJoin.d.ts.map +1 -0
  14. package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -1
  15. package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
  16. package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
  17. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts +14 -0
  18. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.d.ts.map +1 -0
  19. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts +9 -0
  20. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.d.ts.map +1 -0
  21. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts +15 -0
  22. package/dist/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.d.ts.map +1 -0
  23. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts +6 -0
  24. package/dist/communityRepository/observers/getJoinRequestList/enum.d.ts.map +1 -0
  25. package/dist/communityRepository/observers/getJoinRequestList.d.ts +12 -0
  26. package/dist/communityRepository/observers/getJoinRequestList.d.ts.map +1 -0
  27. package/dist/communityRepository/observers/index.d.ts +1 -0
  28. package/dist/communityRepository/observers/index.d.ts.map +1 -1
  29. package/dist/core/events.d.ts +3 -3
  30. package/dist/core/events.d.ts.map +1 -1
  31. package/dist/index.cjs.js +242 -58
  32. package/dist/index.esm.js +242 -58
  33. package/dist/index.umd.js +2 -2
  34. package/dist/invitationRepository/internalApi/index.d.ts +0 -1
  35. package/dist/invitationRepository/internalApi/index.d.ts.map +1 -1
  36. package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
  37. package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
  38. package/dist/utils/tests/dummy/comment.d.ts +1 -1
  39. package/package.json +1 -1
  40. package/src/@types/core/events.ts +2 -2
  41. package/src/@types/domains/community.ts +17 -0
  42. package/src/@types/domains/invitation.ts +0 -1
  43. package/src/@types/domains/notification.ts +2 -0
  44. package/src/communityRepository/api/getCommunities.ts +3 -1
  45. package/src/communityRepository/communityMembership/events/index.ts +1 -0
  46. package/src/communityRepository/communityMembership/events/onLocalCommunityJoin.ts +20 -0
  47. package/src/communityRepository/internalAPI/joinCommunity.ts +17 -2
  48. package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +6 -0
  49. package/src/communityRepository/observers/getCommunity.ts +3 -0
  50. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListLiveCollectionController.ts +130 -0
  51. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListPaginationController.ts +30 -0
  52. package/src/communityRepository/observers/getJoinRequestList/JoinRequestListQueryStreamController.ts +112 -0
  53. package/src/communityRepository/observers/getJoinRequestList/enum.ts +5 -0
  54. package/src/communityRepository/observers/getJoinRequestList.ts +51 -0
  55. package/src/communityRepository/observers/index.ts +1 -0
  56. package/src/invitationRepository/internalApi/index.ts +0 -1
  57. package/src/utils/linkedObject/communityLinkedObject.ts +1 -3
  58. package/src/utils/linkedObject/invitationLinkedObject.ts +3 -10
  59. package/src/utils/linkedObject/joinRequestLinkedObject.ts +3 -3
  60. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts +0 -16
  61. package/dist/invitationRepository/internalApi/cancelInvitation.d.ts.map +0 -1
  62. package/src/invitationRepository/internalApi/cancelInvitation.ts +0 -44
@@ -1,5 +1,4 @@
1
1
  export * from './createInvitations';
2
2
  export * from './acceptInvitation';
3
3
  export * from './rejectInvitation';
4
- export * from './cancelInvitation';
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/internalApi/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/invitationRepository/internalApi/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,oBAAoB,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"communityLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/communityLinkedObject.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,qBAAqB,cAAe,MAAM,iBAAiB,KAAG,MAAM,SAiDhF,CAAC"}
1
+ {"version":3,"file":"communityLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/communityLinkedObject.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,qBAAqB,cAAe,MAAM,iBAAiB,KAAG,MAAM,SA+ChF,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"invitationLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/invitationLinkedObject.ts"],"names":[],"mappings":"AAQA,eAAO,MAAM,sBAAsB,eAAgB,MAAM,kBAAkB,KAAG,MAAM,UAmCnF,CAAC"}
1
+ {"version":3,"file":"invitationLinkedObject.d.ts","sourceRoot":"","sources":["../../../src/utils/linkedObject/invitationLinkedObject.ts"],"names":[],"mappings":"AAIA,eAAO,MAAM,sBAAsB,eAAgB,MAAM,kBAAkB,KAAG,MAAM,UAgCnF,CAAC"}
@@ -23,7 +23,7 @@ export declare const generateComment: (params?: Partial<Amity.InternalComment>)
23
23
  referenceType: Amity.CommentReferenceType;
24
24
  dataType?: any;
25
25
  dataTypes?: any[] | undefined;
26
- data?: string | Amity.ContentDataText | Amity.ContentDataFile | Amity.ContentDataImage | Amity.ContentDataVideo | Amity.ContentDataPoll | Record<string, unknown> | undefined;
26
+ data?: string | Record<string, unknown> | Amity.ContentDataText | Amity.ContentDataFile | Amity.ContentDataImage | Amity.ContentDataVideo | Amity.ContentDataPoll | undefined;
27
27
  metadata?: Record<string, any> | undefined;
28
28
  flagCount: number;
29
29
  hashFlag: {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@amityco/ts-sdk",
3
- "version": "7.4.1-fd0f791a.0",
3
+ "version": "7.5.1-12f08f0.0",
4
4
  "license": "CC-BY-ND-4.0",
5
5
  "author": "amity.co <developers@amity.co> (https://amity.co)",
6
6
  "description": "Amity Social Cloud Typescript SDK",
@@ -188,7 +188,7 @@ declare global {
188
188
  };
189
189
 
190
190
  type LocalCommunityEvents = {
191
- 'local.community.joined': Amity.CommunityMembershipPayload; // v3 join community
191
+ 'local.community.joined': Amity.CommunityMembershipPayload;
192
192
  'local.community.left': Amity.CommunityMembershipPayload;
193
193
  'local.community.roleAdded': Amity.ProcessedCommunityPayload;
194
194
  'local.community.roleRemoved': Amity.ProcessedCommunityPayload;
@@ -265,7 +265,7 @@ declare global {
265
265
  'local.invitation.updated': Amity.InternalInvitation[];
266
266
  'local.invitation.deleted': Amity.InternalInvitation[];
267
267
 
268
- 'local.community.join': Amity.InternalJoinRequest[]; // v4 join community with status
268
+ 'v4.local.community.joined': Amity.InternalJoinRequest[];
269
269
 
270
270
  'local.joinRequest.created': Amity.InternalJoinRequest[];
271
271
  'local.joinRequest.updated': Amity.InternalJoinRequest[];
@@ -159,6 +159,16 @@ declare global {
159
159
  page?: string;
160
160
  };
161
161
 
162
+ type QueryJoinRequestList = {
163
+ communityIds: string[];
164
+ sortBy?: Amity.CommunitySortBy | Amity.CommunitySortByEnum;
165
+ options?: {
166
+ limit?: number;
167
+ token?: string;
168
+ };
169
+ page?: string;
170
+ };
171
+
162
172
  type CommunityLiveCollection = Amity.LiveCollectionParams<Omit<QueryCommunities, 'page'>>;
163
173
 
164
174
  type RecommendedCommunityLiveCollection = Amity.LiveCollectionParams<{ limit?: number }>;
@@ -166,6 +176,8 @@ declare global {
166
176
 
167
177
  type JoinRequestLiveCollection = Amity.LiveCollectionParams<QueryJoinRequest>;
168
178
 
179
+ type JoinRequestListLiveCollection = Amity.LiveCollectionParams<QueryJoinRequestList>;
180
+
169
181
  type SearchCommunityLiveCollection = Amity.LiveCollectionParams<
170
182
  Omit<SearchQueryCommunities, 'page'>
171
183
  >;
@@ -188,6 +200,11 @@ declare global {
188
200
  Pick<QueryJoinRequest, 'page'>
189
201
  >;
190
202
 
203
+ type JoinRequestListLiveCollectionCache = Amity.LiveCollectionCache<
204
+ Amity.JoinRequest['joinRequestId'],
205
+ Pick<QueryJoinRequestList, 'page'>
206
+ >;
207
+
191
208
  type QueryCommunityMembers = {
192
209
  communityId: string;
193
210
  memberships?: ('banned' | 'member')[];
@@ -103,7 +103,6 @@ declare global {
103
103
  type InvitationLinkedObject = {
104
104
  accept: () => Promise<void>;
105
105
  reject: () => Promise<void>;
106
- cancel: () => Promise<void>;
107
106
  };
108
107
 
109
108
  type CreateInvitations = {
@@ -10,6 +10,7 @@ declare global {
10
10
  POST_REACT = 'reaction_on_post',
11
11
  COMMENT_REACT = 'reaction_on_comment',
12
12
  REPLY_REACT = 'reaction_on_reply',
13
+ RESPONSE_JOIN_REQUEST = 'respond_on_join_request',
13
14
  }
14
15
 
15
16
  const enum TrayAction {
@@ -19,6 +20,7 @@ declare global {
19
20
  REACTION = 'reaction',
20
21
  MENTION = 'mention',
21
22
  REPLY = 'reply',
23
+ JOIN_REQUEST = 'join_request',
22
24
  }
23
25
 
24
26
  type RawNotificationTrayItem = {
@@ -28,12 +28,14 @@ export const getCommunities = async (
28
28
  const client = getActiveClient();
29
29
  client.log('community/getCommunities', communityIds);
30
30
 
31
+ const encodedCommunityIds = communityIds.map(communityId => encodeURIComponent(communityId));
32
+
31
33
  // API-FIX: endpoint should not be /list, parameters should be querystring.
32
34
  const { data: payload } = await client.http.get<Amity.CommunityPayload>(
33
35
  `/api/v3/communities/list`,
34
36
  {
35
37
  params: {
36
- communityIds,
38
+ communityIds: encodedCommunityIds,
37
39
  includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
38
40
  },
39
41
  },
@@ -12,3 +12,4 @@ export * from './onCommunityJoined';
12
12
  export * from './onCommunityLeft';
13
13
  export * from './onLocalCommunityJoined';
14
14
  export * from './onLocalCommunityLeft';
15
+ export * from './onLocalCommunityJoin';
@@ -0,0 +1,20 @@
1
+ import { getActiveClient } from '~/client/api/activeClient';
2
+ import { createEventSubscriber } from '~/core/events';
3
+
4
+ export const onLocalCommunityJoin = (
5
+ callback: (joinRequest: Amity.InternalJoinRequest) => void,
6
+ ) => {
7
+ const client = getActiveClient();
8
+
9
+ const filter = async (rawPayload: Amity.InternalJoinRequest[]) => {
10
+ callback(rawPayload[0]);
11
+ };
12
+
13
+ const disposers = [
14
+ createEventSubscriber(client, 'onCommunityUpdate', 'v4.local.community.joined', filter),
15
+ ];
16
+
17
+ return () => {
18
+ disposers.forEach(fn => fn());
19
+ };
20
+ };
@@ -1,5 +1,7 @@
1
1
  import { getActiveClient } from '~/client/api/activeClient';
2
2
  import { ingestInCache } from '~/cache/api/ingestInCache';
3
+ import { pullFromCache } from '~/cache/api/pullFromCache';
4
+ import { upsertInCache } from '~/cache/api/upsertInCache';
3
5
  import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
4
6
  import { fireEvent } from '~/core/events';
5
7
  import { JoinRequestStatusEnum, JoinResultStatusEnum } from '~/@types/domains/joinRequest';
@@ -37,13 +39,26 @@ export const joinRequest = async (
37
39
  const cachedAt = client.cache && Date.now();
38
40
  if (client.cache) ingestInCache(data, { cachedAt });
39
41
 
40
- fireEvent('local.community.join', data.joinRequests);
41
-
42
42
  const status =
43
43
  data.joinRequests[0].status === JoinRequestStatusEnum.Approved
44
44
  ? JoinResultStatusEnum.Success
45
45
  : JoinResultStatusEnum.Pending;
46
46
 
47
+ if (status === JoinResultStatusEnum.Success && client.cache) {
48
+ const community = pullFromCache<Amity.Community>(['community', 'get', communityId])?.data;
49
+
50
+ if (community) {
51
+ const updatedCommunity = {
52
+ ...community,
53
+ isJoined: true,
54
+ };
55
+
56
+ upsertInCache(['community', 'get', communityId], updatedCommunity);
57
+ }
58
+ }
59
+
60
+ fireEvent('v4.local.community.joined', data.joinRequests);
61
+
47
62
  return status === JoinResultStatusEnum.Success
48
63
  ? { status }
49
64
  : { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
@@ -25,8 +25,10 @@ import {
25
25
  onLocalCommunityJoined,
26
26
  onLocalCommunityLeft,
27
27
  onCommunityUserChanged,
28
+ onLocalCommunityJoin,
28
29
  } from '~/communityRepository/communityMembership';
29
30
  import { isNonNullable } from '~/utils';
31
+ import { convertEventPayload } from '~/utils/event';
30
32
 
31
33
  export class CommunityLiveCollectionController extends LiveCollectionController<
32
34
  'community',
@@ -92,6 +94,10 @@ export class CommunityLiveCollectionController extends LiveCollectionController<
92
94
  { fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
93
95
  { fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
94
96
  { fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
97
+ {
98
+ fn: convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
99
+ action: EnumCommunityActions.OnCommunityUpdated,
100
+ },
95
101
  ]);
96
102
  }
97
103
 
@@ -9,7 +9,9 @@ import {
9
9
  onCommunityLeft,
10
10
  onLocalCommunityJoined,
11
11
  onLocalCommunityLeft,
12
+ onLocalCommunityJoin,
12
13
  } from '../communityMembership/events';
14
+ import { convertEventPayload } from '~/utils/event';
13
15
 
14
16
  /* begin_public_function
15
17
  id: community.get
@@ -47,6 +49,7 @@ export const getCommunity = (
47
49
  onCommunityUserBanned,
48
50
  onCommunityUserUnbanned,
49
51
  onCommunityUserChanged,
52
+ convertEventPayload(onLocalCommunityJoin, 'targetId', 'community'),
50
53
  ]);
51
54
  };
52
55
  /* end_public_function */
@@ -0,0 +1,130 @@
1
+ import hash from 'object-hash';
2
+ import { pullFromCache, pushToCache } from '~/cache/api';
3
+ import { JoinRequestListPaginationController } from './JoinRequestListPaginationController';
4
+ import { JoinRequestListQueryStreamController } from './JoinRequestListQueryStreamController';
5
+ import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
6
+ import { sortByFirstCreated, sortByLastCreated } from '~/core/query';
7
+ import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
8
+ import { EnumJoinRequestAction } from './enum';
9
+ import { isNonNullable } from '~/utils';
10
+ import { joinRequestLinkedObject } from '~/utils/linkedObject/joinRequestLinkedObject';
11
+ import {
12
+ onJoinRequestCreated,
13
+ onJoinRequestDeleted,
14
+ onJoinRequestUpdated,
15
+ } from '~/communityRepository/joinRequest/events/';
16
+
17
+ export class JoinRequestListLiveCollectionController extends LiveCollectionController<
18
+ 'joinRequest',
19
+ Amity.JoinRequestListLiveCollection,
20
+ Amity.JoinRequest,
21
+ JoinRequestListPaginationController
22
+ > {
23
+ private queryStreamController: JoinRequestListQueryStreamController;
24
+
25
+ private query: Amity.JoinRequestListLiveCollection;
26
+
27
+ constructor(
28
+ query: Amity.JoinRequestListLiveCollection,
29
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
30
+ ) {
31
+ const queryStreamId = hash(query);
32
+ const cacheKey = ['joinRequestList', 'collection', queryStreamId];
33
+ const paginationController = new JoinRequestListPaginationController(query);
34
+
35
+ super(paginationController, queryStreamId, cacheKey, callback);
36
+
37
+ this.query = query;
38
+ this.queryStreamController = new JoinRequestListQueryStreamController(
39
+ this.query,
40
+ this.cacheKey,
41
+ this.notifyChange.bind(this),
42
+ prepareCommunityJoinRequestPayload,
43
+ );
44
+
45
+ this.callback = callback.bind(this);
46
+ this.loadPage({ initial: true });
47
+ }
48
+
49
+ protected setup() {
50
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(this.cacheKey)?.data;
51
+
52
+ if (!collection) {
53
+ pushToCache(this.cacheKey, {
54
+ data: [],
55
+ params: this.query,
56
+ });
57
+ }
58
+ }
59
+
60
+ protected async persistModel(queryPayload: Amity.CommunityJoinRequestPayload & Amity.Pagination) {
61
+ await this.queryStreamController.saveToMainDB(queryPayload);
62
+ }
63
+
64
+ protected persistQueryStream({
65
+ response,
66
+ direction,
67
+ refresh,
68
+ }: Amity.LiveCollectionPersistQueryStreamParams<'joinRequest'>) {
69
+ const joinRequestResponse = response as unknown as Amity.CommunityJoinRequestPayload &
70
+ Partial<Amity.Pagination>;
71
+ this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
72
+ }
73
+
74
+ startSubscription() {
75
+ return this.queryStreamController.subscribeRTE([
76
+ { fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
77
+ { fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
78
+ { fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
79
+ ]);
80
+ }
81
+
82
+ notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
83
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(this.cacheKey)?.data;
84
+
85
+ if (!collection) return;
86
+
87
+ const data = this.applyFilter(
88
+ collection.data
89
+ .map(id => pullFromCache<Amity.InternalJoinRequest>(['joinRequest', 'get', id])!)
90
+ .filter(isNonNullable)
91
+ .map(({ data }) => data)
92
+ .map(joinRequestLinkedObject),
93
+ );
94
+
95
+ if (!this.shouldNotify(data) && origin === 'event') return;
96
+
97
+ this.callback({
98
+ onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
99
+ data,
100
+ hasNextPage: !!this.paginationController.getNextToken(),
101
+ loading,
102
+ error,
103
+ });
104
+ }
105
+
106
+ applyFilter(data: Amity.JoinRequest[]) {
107
+ let joinRequest = data;
108
+
109
+ if (this.query.communityIds && this.query.communityIds.length > 0) {
110
+ joinRequest = joinRequest.filter(joinRequest =>
111
+ this.query.communityIds.some(id => id === joinRequest.targetId),
112
+ );
113
+ }
114
+
115
+ const sortFn = (() => {
116
+ switch (this.query.sortBy) {
117
+ case 'firstCreated':
118
+ return sortByFirstCreated;
119
+ case 'lastCreated':
120
+ return sortByLastCreated;
121
+ default:
122
+ return sortByLastCreated;
123
+ }
124
+ })();
125
+
126
+ joinRequest = joinRequest.sort(sortFn);
127
+
128
+ return joinRequest;
129
+ }
130
+ }
@@ -0,0 +1,30 @@
1
+ import { PaginationController } from '~/core/liveCollection/PaginationController';
2
+ import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
3
+
4
+ /**
5
+ * TODO: handle cache receive cache option, and cache policy
6
+ * TODO: check if querybyIds is supported
7
+ */
8
+ export class JoinRequestListPaginationController extends PaginationController<
9
+ 'joinRequest',
10
+ Amity.JoinRequestListLiveCollection
11
+ > {
12
+ async getRequest(queryParams: Amity.JoinRequestListLiveCollection, token: string | undefined) {
13
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityIds, ...params } = queryParams;
14
+ const options = token ? { token } : { limit };
15
+
16
+ const encodedChannelIds = communityIds.map(communityId => encodeURIComponent(communityId));
17
+
18
+ const { data: queryResponse } = await this.http.get<
19
+ Amity.CommunityJoinRequestPayload & Amity.Pagination
20
+ >(`/api/v4/communities/join/requests`, {
21
+ params: {
22
+ ...params,
23
+ options,
24
+ communityIds: encodedChannelIds,
25
+ },
26
+ });
27
+
28
+ return queryResponse;
29
+ }
30
+ }
@@ -0,0 +1,112 @@
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 JoinRequestListQueryStreamController extends QueryStreamController<
9
+ Amity.CommunityJoinRequestPayload,
10
+ Amity.JoinRequestListLiveCollection
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.JoinRequestListLiveCollection,
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.JoinRequestListLiveCollectionCache>(
55
+ this.cacheKey,
56
+ )?.data;
57
+
58
+ const joinRequests = collection?.data ?? [];
59
+
60
+ pushToCache(this.cacheKey, {
61
+ ...collection,
62
+ data: [
63
+ ...new Set([
64
+ ...joinRequests,
65
+ ...response.joinRequests.map(joinRequest =>
66
+ getResolver('joinRequest')({ joinRequestId: joinRequest._id }),
67
+ ),
68
+ ]),
69
+ ],
70
+ });
71
+ }
72
+ }
73
+
74
+ reactor(action: EnumJoinRequestAction) {
75
+ return (joinRequest: Amity.InternalJoinRequest[]) => {
76
+ const collection = pullFromCache<Amity.JoinRequestListLiveCollectionCache>(
77
+ this.cacheKey,
78
+ )?.data;
79
+ if (!collection) return;
80
+
81
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestUpdated) {
82
+ const isExist = collection.data.find(id => id === joinRequest[0].joinRequestId);
83
+ if (!isExist) return;
84
+ }
85
+
86
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestCreated) {
87
+ collection.data = [
88
+ ...new Set([
89
+ ...joinRequest.map(joinRequest => joinRequest.joinRequestId),
90
+ ...collection.data,
91
+ ]),
92
+ ];
93
+ }
94
+
95
+ if (action === EnumJoinRequestAction.OnLocalJoinRequestDeleted) {
96
+ collection.data = collection.data.filter(id => id !== joinRequest[0].joinRequestId);
97
+ }
98
+
99
+ pushToCache(this.cacheKey, collection);
100
+ this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
101
+ };
102
+ }
103
+
104
+ subscribeRTE(
105
+ createSubscriber: {
106
+ fn: (reactor: Amity.Listener<Amity.InternalJoinRequest[]>) => Amity.Unsubscriber;
107
+ action: EnumJoinRequestAction;
108
+ }[],
109
+ ) {
110
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
111
+ }
112
+ }
@@ -0,0 +1,5 @@
1
+ export enum EnumJoinRequestAction {
2
+ OnLocalJoinRequestCreated = 'OnLocalJoinRequestCreated',
3
+ OnLocalJoinRequestUpdated = 'OnLocalJoinRequestUpdated',
4
+ OnLocalJoinRequestDeleted = 'OnLocalJoinRequestDeleted',
5
+ }
@@ -0,0 +1,51 @@
1
+ import { dropFromCache } from '~/cache/api/dropFromCache';
2
+ import { getActiveClient } from '~/client/api/activeClient';
3
+ import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
4
+ import { JoinRequestListLiveCollectionController } from './getJoinRequestList/JoinRequestListLiveCollectionController';
5
+
6
+ /* begin_public_function
7
+ id: community.getJoinRequestList
8
+ */
9
+ /**
10
+ * Get Join Requests
11
+ *
12
+ * @param params the query parameters
13
+ * @param callback the callback to be called when the join request are updated
14
+ * @returns joinRequest[]
15
+ *
16
+ * @category joinRequestList Live Collection
17
+ *
18
+ */
19
+ export const getJoinRequestList = (
20
+ params: Amity.JoinRequestListLiveCollection,
21
+ callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
22
+ config?: Amity.LiveCollectionConfig,
23
+ ) => {
24
+ const { log, cache } = getActiveClient();
25
+
26
+ if (!cache) {
27
+ console.log(ENABLE_CACHE_MESSAGE);
28
+ }
29
+
30
+ const timestamp = Date.now();
31
+ log(`getJoinRequestList: (tmpid: ${timestamp}) > listen`);
32
+
33
+ const joinRequestListLiveCollection = new JoinRequestListLiveCollectionController(
34
+ params,
35
+ callback,
36
+ );
37
+
38
+ const disposers = joinRequestListLiveCollection.startSubscription();
39
+
40
+ const cacheKey = joinRequestListLiveCollection.getCacheKey();
41
+
42
+ disposers.push(() => {
43
+ dropFromCache(cacheKey);
44
+ });
45
+
46
+ return () => {
47
+ log(`getJoinRequestList (tmpid: ${timestamp}) > dispose`);
48
+ disposers.forEach(fn => fn());
49
+ };
50
+ };
51
+ /* end_public_function */
@@ -5,3 +5,4 @@ export * from './getTrendingCommunities';
5
5
  export * from './getRecommendedCommunities';
6
6
 
7
7
  export * from './semanticSearchCommunities';
8
+ export * from './getJoinRequestList';
@@ -1,4 +1,3 @@
1
1
  export * from './createInvitations';
2
2
  export * from './acceptInvitation';
3
3
  export * from './rejectInvitation';
4
- export * from './cancelInvitation';
@@ -35,9 +35,7 @@ export const communityLinkedObject = (community: Amity.InternalCommunity): Amity
35
35
  const { data } = await getInvitation('community', community.communityId);
36
36
  return data;
37
37
  },
38
- join: async (): Promise<Amity.JoinResult> => {
39
- return joinRequest(community.communityId);
40
- },
38
+ join: async () => joinRequest(community.communityId),
41
39
  getJoinRequests: (
42
40
  params: Omit<Amity.QueryJoinRequest, 'communityId'>,
43
41
  callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
@@ -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 {
@@ -32,13 +28,10 @@ export const invitationLinkedObject = (invitation: Amity.InternalInvitation): Am
32
28
  return undefined;
33
29
  },
34
30
  accept: async () => {
35
- await acceptInvitation(invitation._id);
31
+ acceptInvitation(invitation._id);
36
32
  },
37
33
  reject: async () => {
38
- await rejectInvitation(invitation._id);
39
- },
40
- cancel: async () => {
41
- await cancelInvitation(invitation._id);
34
+ rejectInvitation(invitation._id);
42
35
  },
43
36
  };
44
37
  };
@@ -19,13 +19,13 @@ export const joinRequestLinkedObject = (
19
19
  return userLinkedObject(user);
20
20
  },
21
21
  cancel: async () => {
22
- await cancelJoinRequest(joinRequest);
22
+ cancelJoinRequest(joinRequest);
23
23
  },
24
24
  approve: async () => {
25
- await approveJoinRequest(joinRequest);
25
+ approveJoinRequest(joinRequest);
26
26
  },
27
27
  reject: async () => {
28
- await rejectJoinRequest(joinRequest);
28
+ rejectJoinRequest(joinRequest);
29
29
  },
30
30
  };
31
31
  };
@@ -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