@amityco/ts-sdk 7.4.1-d23fab2f.0 → 7.4.1-fd0f791a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +7 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +30 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +32 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/invitation.d.ts +48 -3
- package/dist/@types/domains/invitation.d.ts.map +1 -1
- package/dist/@types/domains/joinRequest.d.ts +53 -0
- package/dist/@types/domains/joinRequest.d.ts.map +1 -0
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts +3 -1
- package/dist/communityRepository/api/getTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/joinCommunity.d.ts +3 -0
- package/dist/communityRepository/api/joinCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +2 -2
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts +16 -0
- package/dist/communityRepository/internalAPI/getMyJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts +16 -0
- package/dist/communityRepository/internalAPI/joinCommunity.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts +4 -0
- package/dist/communityRepository/joinRequest/events/index.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestCreated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestDeleted.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts +17 -0
- package/dist/communityRepository/joinRequest/events/onJoinRequestUpdated.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/approveJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/cancelJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts +16 -0
- package/dist/communityRepository/joinRequest/internalAPI/rejectJoinRequest.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts +6 -0
- package/dist/communityRepository/observers/getJoinRequests/enum.d.ts.map +1 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts +12 -0
- package/dist/communityRepository/observers/getJoinRequests.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.d.ts.map +1 -1
- package/dist/communityRepository/utils/payload.d.ts +1 -0
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +2608 -1576
- package/dist/index.esm.js +2432 -1400
- package/dist/index.umd.js +4 -4
- package/dist/invitationRepository/events/index.d.ts +2 -0
- package/dist/invitationRepository/events/index.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationCreated.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationDeleted.d.ts.map +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts +1 -1
- package/dist/invitationRepository/events/onLocalInvitationUpdated.d.ts.map +1 -1
- package/dist/invitationRepository/index.d.ts +1 -0
- package/dist/invitationRepository/index.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/createInvitations.d.ts.map +1 -1
- package/dist/invitationRepository/internalApi/getInvitation.d.ts +17 -0
- package/dist/invitationRepository/internalApi/getInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts +6 -0
- package/dist/invitationRepository/observers/getInvitations/enums.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts +12 -0
- package/dist/invitationRepository/observers/getMyCommunityInvitations.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts +14 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts +5 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts +15 -0
- package/dist/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.d.ts.map +1 -0
- package/dist/invitationRepository/observers/index.d.ts +2 -0
- package/dist/invitationRepository/observers/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts +2 -0
- package/dist/invitationRepository/utils/convertRawInvitationToInternalInvitation.d.ts.map +1 -0
- package/dist/invitationRepository/utils/index.d.ts +2 -0
- package/dist/invitationRepository/utils/index.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareInvitationPayload.d.ts.map +1 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts +2 -0
- package/dist/invitationRepository/utils/prepareMyInvitationsPayload.d.ts.map +1 -0
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/subChannelRepository/utils/prepareSubChannelPayload.d.ts.map +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/communityLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +3 -2
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts +1 -1
- package/dist/utils/linkedObject/invitationLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/joinRequestLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +10 -4
- package/src/@types/core/model.ts +3 -0
- package/src/@types/core/payload.ts +39 -1
- package/src/@types/domains/community.ts +45 -2
- package/src/@types/domains/invitation.ts +67 -3
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +9 -1
- package/src/communityRepository/api/getRecommendedCommunities.ts +9 -3
- package/src/communityRepository/api/getTrendingCommunities.ts +9 -3
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- package/src/communityRepository/api/updateCommunity.ts +9 -2
- package/src/communityRepository/internalAPI/getMyJoinRequest.ts +43 -0
- package/src/communityRepository/internalAPI/joinCommunity.ts +51 -0
- package/src/communityRepository/joinRequest/events/index.ts +3 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestCreated.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestDeleted.ts +33 -0
- package/src/communityRepository/joinRequest/events/onJoinRequestUpdated.ts +33 -0
- package/src/communityRepository/joinRequest/internalAPI/approveJoinRequest.ts +52 -0
- package/src/communityRepository/joinRequest/internalAPI/cancelJoinRequest.ts +46 -0
- package/src/communityRepository/joinRequest/internalAPI/rejectJoinRequest.ts +52 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts +126 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsPaginationController.ts +26 -0
- package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts +108 -0
- package/src/communityRepository/observers/getJoinRequests/enum.ts +5 -0
- package/src/communityRepository/observers/getJoinRequests.ts +44 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +2 -1
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts +1 -0
- package/src/communityRepository/utils/communityWithMembership.ts +1 -1
- package/src/communityRepository/utils/payload.ts +27 -1
- package/src/core/liveCollection/PaginationController.ts +1 -1
- package/src/core/liveCollection/PaginationNoPageController.ts +1 -1
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- package/src/invitationRepository/events/index.ts +2 -0
- package/src/invitationRepository/events/onLocalInvitationCreated.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationDeleted.ts +1 -1
- package/src/invitationRepository/events/onLocalInvitationUpdated.ts +1 -1
- package/src/invitationRepository/index.ts +1 -0
- package/src/invitationRepository/internalApi/acceptInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/cancelInvitation.ts +1 -1
- package/src/invitationRepository/internalApi/createInvitations.ts +8 -2
- package/src/invitationRepository/internalApi/getInvitation.ts +47 -0
- package/src/invitationRepository/internalApi/rejectInvitation.ts +1 -1
- package/src/invitationRepository/observers/getInvitations/InvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsPaginationController.ts +19 -0
- package/src/invitationRepository/observers/getInvitations/InvitationsQueryStreamController.ts +97 -0
- package/src/invitationRepository/observers/getInvitations/enums.ts +5 -0
- package/src/invitationRepository/observers/getInvitations.ts +44 -0
- package/src/invitationRepository/observers/getMyCommunityInvitations.ts +48 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsLiveCollectionController.ts +148 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsPaginationController.ts +22 -0
- package/src/invitationRepository/observers/getMyInvitations/MyInvitationsQueryStreamController.ts +105 -0
- package/src/invitationRepository/observers/index.ts +1 -0
- package/src/invitationRepository/utils/convertRawInvitationToInternalInvitation.ts +8 -0
- package/src/invitationRepository/utils/index.ts +1 -0
- package/src/invitationRepository/utils/prepareInvitationPayload.ts +12 -0
- package/src/invitationRepository/utils/prepareMyInvitationsPayload.ts +12 -0
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +3 -3
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +7 -1
- package/src/subChannelRepository/utils/prepareSubChannelPayload.ts +4 -0
- package/src/utils/linkedObject/communityLinkedObject.ts +43 -1
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/invitationLinkedObject.ts +25 -1
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
|
@@ -12,13 +12,26 @@ export const enum InvitationStatusEnum {
|
|
|
12
12
|
Cancelled = 'cancelled',
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
export const enum InvitationSortByEnum {
|
|
16
|
+
FirstCreated = 'firstCreated',
|
|
17
|
+
LastCreated = 'lastCreated',
|
|
18
|
+
}
|
|
19
|
+
|
|
15
20
|
declare global {
|
|
16
21
|
namespace Amity {
|
|
17
22
|
type InvitationType = InvitationTypeEnum;
|
|
18
23
|
|
|
19
24
|
type InvitationStatus = InvitationStatusEnum;
|
|
20
25
|
|
|
21
|
-
type InvitationTargetType = Extract<Amity.Domain, 'community'
|
|
26
|
+
type InvitationTargetType = Extract<Amity.Domain, 'community'>;
|
|
27
|
+
|
|
28
|
+
type InvitationTargetMap = {
|
|
29
|
+
community: Amity.InternalCommunity;
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
type InvitationTarget<T extends InvitationTargetType> = InvitationTargetMap[T];
|
|
33
|
+
|
|
34
|
+
type InvitationSortBy = InvitationSortByEnum;
|
|
22
35
|
|
|
23
36
|
type RawInvitation = {
|
|
24
37
|
_id: string;
|
|
@@ -30,11 +43,62 @@ declare global {
|
|
|
30
43
|
status: Amity.InvitationStatus;
|
|
31
44
|
respondedAt: Amity.timestamp;
|
|
32
45
|
createdBy: string;
|
|
46
|
+
invitationId: string;
|
|
47
|
+
invitedUserId: string;
|
|
48
|
+
invitedUserInternalId: string;
|
|
49
|
+
invitedUserPublicId: string;
|
|
50
|
+
inviterUserId: string;
|
|
51
|
+
inviterUserInternalId: string;
|
|
52
|
+
inviterUserPublicId: string;
|
|
33
53
|
} & Amity.Timestamps;
|
|
34
54
|
|
|
35
|
-
type InternalInvitation = RawInvitation
|
|
55
|
+
type InternalInvitation = Omit<RawInvitation, 'createdBy'> & {
|
|
56
|
+
createdById: string;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
type Invitation = Omit<Amity.InternalInvitation, 'createdBy'> &
|
|
60
|
+
Amity.InvitationLinkedObject & {
|
|
61
|
+
user?: Amity.User;
|
|
62
|
+
createdById: string;
|
|
63
|
+
createdBy?: Amity.User;
|
|
64
|
+
target?: Amity.InvitationTarget<Amity.InvitationTargetType>;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
type QueryInvitations = {
|
|
68
|
+
targetId: string;
|
|
69
|
+
statuses?: string[];
|
|
70
|
+
token?: Amity.Token;
|
|
71
|
+
type: Amity.InvitationType;
|
|
72
|
+
sortBy?: Amity.InvitationSortBy;
|
|
73
|
+
limit?: Amity.PageLimit['limit'];
|
|
74
|
+
targetType: Amity.InvitationTargetType;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type InvitationLiveCollection = Amity.LiveCollectionParams<Omit<QueryInvitations, 'limit'>>;
|
|
78
|
+
|
|
79
|
+
type InvitationLiveCollectionCache = Amity.LiveCollectionCache<
|
|
80
|
+
Amity.InternalInvitation['_id'],
|
|
81
|
+
Pick<QueryInvitations, 'limit'>
|
|
82
|
+
>;
|
|
83
|
+
|
|
84
|
+
type QueryMyInvitations = {
|
|
85
|
+
targetId?: string;
|
|
86
|
+
token?: Amity.Token;
|
|
87
|
+
type?: Amity.InvitationType;
|
|
88
|
+
sortBy?: Amity.InvitationSortBy;
|
|
89
|
+
limit?: Amity.PageLimit['limit'];
|
|
90
|
+
statuses?: InvitationStatusEnum[];
|
|
91
|
+
targetType?: Amity.InvitationTargetType;
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
type MyInvitationsLiveCollection = Amity.LiveCollectionParams<
|
|
95
|
+
Omit<QueryMyInvitations, 'limit'>
|
|
96
|
+
>;
|
|
36
97
|
|
|
37
|
-
type
|
|
98
|
+
type MyInvitationsLiveCollectionCache = Amity.LiveCollectionCache<
|
|
99
|
+
Amity.InternalInvitation['_id'],
|
|
100
|
+
Pick<QueryMyInvitations, 'limit'>
|
|
101
|
+
>;
|
|
38
102
|
|
|
39
103
|
type InvitationLinkedObject = {
|
|
40
104
|
accept: () => Promise<void>;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
export {};
|
|
2
|
+
|
|
3
|
+
export const enum JoinRequestStatusEnum {
|
|
4
|
+
Pending = 'pending',
|
|
5
|
+
Approved = 'approved',
|
|
6
|
+
Rejected = 'rejected',
|
|
7
|
+
Cancelled = 'cancelled',
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export const enum JoinResultStatusEnum {
|
|
11
|
+
Success = 'success',
|
|
12
|
+
Pending = 'pending',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
declare global {
|
|
16
|
+
namespace Amity {
|
|
17
|
+
type JoinRequestStatus = JoinRequestStatusEnum;
|
|
18
|
+
|
|
19
|
+
type JoinResultStatus = JoinResultStatusEnum;
|
|
20
|
+
|
|
21
|
+
type JoinRequestType = 'communityJoinRequest';
|
|
22
|
+
|
|
23
|
+
type JoinResult = {
|
|
24
|
+
status: Amity.JoinResultStatus;
|
|
25
|
+
request?: Amity.JoinRequest;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
type RawJoinRequest = {
|
|
29
|
+
_id: string;
|
|
30
|
+
createdAt: Amity.timestamp;
|
|
31
|
+
joinRequestId: string;
|
|
32
|
+
networkId: string;
|
|
33
|
+
|
|
34
|
+
requestorId: string;
|
|
35
|
+
requestorInternalId: string;
|
|
36
|
+
requestorPublicId: string;
|
|
37
|
+
|
|
38
|
+
respondedAt: Amity.timestamp | null;
|
|
39
|
+
responderId: string | null;
|
|
40
|
+
responderInternalId: string | null;
|
|
41
|
+
responderPublicId: string | null;
|
|
42
|
+
|
|
43
|
+
status: Amity.JoinRequestStatus;
|
|
44
|
+
targetId: string;
|
|
45
|
+
targetType: string;
|
|
46
|
+
type: Amity.JoinRequestType;
|
|
47
|
+
updatedAt: Amity.timestamp;
|
|
48
|
+
userId: string;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
type InternalJoinRequest = Omit<RawJoinRequest, '_id'>;
|
|
52
|
+
|
|
53
|
+
type JoinRequest = Omit<Amity.InternalJoinRequest, 'responderId'> &
|
|
54
|
+
Amity.JoinRequestLinkedObject & {
|
|
55
|
+
user?: Amity.User;
|
|
56
|
+
feeds?: Amity.Feed[];
|
|
57
|
+
files?: Amity.File[];
|
|
58
|
+
};
|
|
59
|
+
|
|
60
|
+
type JoinRequestLinkedObject = {
|
|
61
|
+
cancel: () => Promise<void>;
|
|
62
|
+
approve: () => Promise<void>;
|
|
63
|
+
reject: () => Promise<void>;
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
}
|
package/src/@types/index.ts
CHANGED
|
@@ -23,6 +23,7 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
23
23
|
*/
|
|
24
24
|
export const getCommunities = async (
|
|
25
25
|
communityIds: Amity.Community['communityId'][],
|
|
26
|
+
includeDiscoverablePrivateCommunity?: boolean,
|
|
26
27
|
): Promise<Amity.Cached<Amity.Community[]>> => {
|
|
27
28
|
const client = getActiveClient();
|
|
28
29
|
client.log('community/getCommunities', communityIds);
|
|
@@ -31,7 +32,10 @@ export const getCommunities = async (
|
|
|
31
32
|
const { data: payload } = await client.http.get<Amity.CommunityPayload>(
|
|
32
33
|
`/api/v3/communities/list`,
|
|
33
34
|
{
|
|
34
|
-
params: {
|
|
35
|
+
params: {
|
|
36
|
+
communityIds,
|
|
37
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
|
|
38
|
+
},
|
|
35
39
|
},
|
|
36
40
|
);
|
|
37
41
|
|
|
@@ -23,6 +23,8 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
23
23
|
*/
|
|
24
24
|
export const getCommunity = async (
|
|
25
25
|
communityId: Amity.Community['communityId'],
|
|
26
|
+
type?: Amity.JoinRequestType,
|
|
27
|
+
includeDiscoverablePrivateCommunity?: boolean,
|
|
26
28
|
): Promise<Amity.Cached<Amity.Community>> => {
|
|
27
29
|
const client = getActiveClient();
|
|
28
30
|
client.log('community/getCommunity', communityId);
|
|
@@ -30,6 +32,12 @@ export const getCommunity = async (
|
|
|
30
32
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
31
33
|
const { data: payload } = await client.http.get<Amity.CommunityPayload>(
|
|
32
34
|
`/api/v3/communities/${communityId}`,
|
|
35
|
+
{
|
|
36
|
+
params: {
|
|
37
|
+
type: 'communityJoinRequest',
|
|
38
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
|
|
39
|
+
},
|
|
40
|
+
},
|
|
33
41
|
);
|
|
34
42
|
|
|
35
43
|
const data = prepareCommunityPayload(payload);
|
|
@@ -76,7 +84,7 @@ getCommunity.locally = (
|
|
|
76
84
|
if (!cached) return;
|
|
77
85
|
|
|
78
86
|
return {
|
|
79
|
-
data: cached.data,
|
|
87
|
+
data: LinkedObject.community(cached.data),
|
|
80
88
|
cachedAt: cached.cachedAt,
|
|
81
89
|
};
|
|
82
90
|
};
|
|
@@ -25,18 +25,24 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
25
25
|
* @private
|
|
26
26
|
*/
|
|
27
27
|
export const getRecommendedCommunities = async (
|
|
28
|
-
query?: Amity.PageLimit,
|
|
28
|
+
query?: Amity.PageLimit & { includeDiscoverablePrivateCommunity?: boolean },
|
|
29
29
|
): Promise<Amity.Cached<Amity.Community[]>> => {
|
|
30
30
|
const client = getActiveClient();
|
|
31
31
|
client.log('community/getRecommendedCommunities', query);
|
|
32
32
|
|
|
33
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } =
|
|
33
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDiscoverablePrivateCommunity } =
|
|
34
|
+
query ?? {};
|
|
34
35
|
|
|
35
36
|
// API-FIX: backend doesnt answer Amity.Response
|
|
36
37
|
// const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
37
38
|
const { data: payload } = await client.http.get<Amity.CommunityPayload>(
|
|
38
39
|
`/api/v3/communities/recommended`,
|
|
39
|
-
{
|
|
40
|
+
{
|
|
41
|
+
params: {
|
|
42
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
|
|
43
|
+
options: { limit },
|
|
44
|
+
},
|
|
45
|
+
},
|
|
40
46
|
);
|
|
41
47
|
|
|
42
48
|
const data = prepareCommunityPayload(payload);
|
|
@@ -22,18 +22,24 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
22
22
|
* @private
|
|
23
23
|
*/
|
|
24
24
|
export const getTrendingCommunities = async (
|
|
25
|
-
query?: Amity.PageLimit,
|
|
25
|
+
query?: Amity.PageLimit & { includeDiscoverablePrivateCommunity?: boolean },
|
|
26
26
|
): Promise<Amity.Cached<Amity.Community[]>> => {
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('community/getTrendingCommunities', query);
|
|
29
29
|
|
|
30
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } =
|
|
30
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDiscoverablePrivateCommunity } =
|
|
31
|
+
query ?? {};
|
|
31
32
|
|
|
32
33
|
// API-FIX: backend doesnt answer Amity.Response
|
|
33
34
|
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
34
35
|
const { data: payload } = await client.http.get<Amity.CommunityPayload>(
|
|
35
36
|
`/api/v3/communities/top-trending`,
|
|
36
|
-
{
|
|
37
|
+
{
|
|
38
|
+
params: {
|
|
39
|
+
includeDiscoverablePrivateCommunity: includeDiscoverablePrivateCommunity ?? true,
|
|
40
|
+
options: { limit },
|
|
41
|
+
},
|
|
42
|
+
},
|
|
37
43
|
);
|
|
38
44
|
|
|
39
45
|
const data = prepareCommunityPayload(payload);
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
5
5
|
import { fireEvent } from '~/core/events';
|
|
6
6
|
|
|
7
|
+
/**
|
|
8
|
+
* @deprecated This function will to be deprecated and use the new community.join().
|
|
9
|
+
*/
|
|
7
10
|
/* begin_public_function
|
|
8
11
|
id: community.join
|
|
9
12
|
*/
|
|
@@ -13,7 +13,7 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
13
13
|
/**
|
|
14
14
|
* ```js
|
|
15
15
|
* import { updateCommunity } from '@amityco/ts-sdk'
|
|
16
|
-
* const updated = await updateCommunity(communityId, { displayName: 'foobar' })
|
|
16
|
+
* const updated = await updateCommunity(communityId, { displayName: 'foobar', isDiscoverable: true, requiresJoinApproval: false })
|
|
17
17
|
* ```
|
|
18
18
|
*
|
|
19
19
|
* Updates an {@link Amity.Community}
|
|
@@ -29,7 +29,14 @@ export const updateCommunity = async (
|
|
|
29
29
|
communityId: Amity.Community['communityId'],
|
|
30
30
|
patch: Patch<
|
|
31
31
|
Amity.Community,
|
|
32
|
-
|
|
32
|
+
| 'displayName'
|
|
33
|
+
| 'avatarFileId'
|
|
34
|
+
| 'description'
|
|
35
|
+
| 'postSetting'
|
|
36
|
+
| 'tags'
|
|
37
|
+
| 'metadata'
|
|
38
|
+
| 'isDiscoverable'
|
|
39
|
+
| 'requiresJoinApproval'
|
|
33
40
|
> &
|
|
34
41
|
Amity.CommunityStorySettings,
|
|
35
42
|
): Promise<Amity.Cached<Amity.Community>> => {
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
+
import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
|
|
4
|
+
import { joinRequestLinkedObject } from '~/utils/linkedObject/joinRequestLinkedObject';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: community.getMyJoinRequest
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { community } from '@amityco/ts-sdk'
|
|
12
|
+
* const isJoined = await community.getMyJoinRequest('foobar')
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Joins a {@link Amity.Community} object
|
|
16
|
+
*
|
|
17
|
+
* @param communityId the {@link Amity.Community} to join
|
|
18
|
+
* @returns A success boolean if the {@link Amity.Community} was joined
|
|
19
|
+
*
|
|
20
|
+
* @category Community API
|
|
21
|
+
* @async
|
|
22
|
+
*/
|
|
23
|
+
export const getMyJoinRequest = async (
|
|
24
|
+
communityId: Amity.Community['communityId'],
|
|
25
|
+
): Promise<Amity.Cached<Amity.JoinRequest | undefined>> => {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
client.log('community/myJoinRequest', communityId);
|
|
28
|
+
|
|
29
|
+
const { data: payload } = await client.http.get<Amity.CommunityJoinRequestPayload>(
|
|
30
|
+
`/api/v4/communities/${communityId}/join/me`,
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
34
|
+
|
|
35
|
+
const cachedAt = client.cache && Date.now();
|
|
36
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
37
|
+
|
|
38
|
+
return {
|
|
39
|
+
data: data.joinRequests[0] ? joinRequestLinkedObject(data.joinRequests[0]) : undefined,
|
|
40
|
+
cachedAt,
|
|
41
|
+
};
|
|
42
|
+
};
|
|
43
|
+
/* end_public_function */
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
3
|
+
import { prepareCommunityJoinRequestPayload } from '~/communityRepository/utils';
|
|
4
|
+
import { fireEvent } from '~/core/events';
|
|
5
|
+
import { JoinRequestStatusEnum, JoinResultStatusEnum } from '~/@types/domains/joinRequest';
|
|
6
|
+
import { joinRequestLinkedObject } from '~/utils/linkedObject/joinRequestLinkedObject';
|
|
7
|
+
|
|
8
|
+
/* begin_public_function
|
|
9
|
+
id: community.join
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* ```js
|
|
13
|
+
* import { community } from '@amityco/ts-sdk'
|
|
14
|
+
* const isJoined = await community.join('foobar')
|
|
15
|
+
* ```
|
|
16
|
+
*
|
|
17
|
+
* Joins a {@link Amity.Community} object
|
|
18
|
+
*
|
|
19
|
+
* @param communityId the {@link Amity.Community} to join
|
|
20
|
+
* @returns A status join result
|
|
21
|
+
*
|
|
22
|
+
* @category Community API
|
|
23
|
+
* @async
|
|
24
|
+
*/
|
|
25
|
+
export const joinRequest = async (
|
|
26
|
+
communityId: Amity.Community['communityId'],
|
|
27
|
+
): Promise<Amity.JoinResult> => {
|
|
28
|
+
const client = getActiveClient();
|
|
29
|
+
client.log('community/joinRequest', communityId);
|
|
30
|
+
|
|
31
|
+
const { data: payload } = await client.http.post<Amity.CommunityJoinRequestPayload>(
|
|
32
|
+
`/api/v4/communities/${communityId}/join`,
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
const data = prepareCommunityJoinRequestPayload(payload);
|
|
36
|
+
|
|
37
|
+
const cachedAt = client.cache && Date.now();
|
|
38
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
39
|
+
|
|
40
|
+
fireEvent('local.community.join', data.joinRequests);
|
|
41
|
+
|
|
42
|
+
const status =
|
|
43
|
+
data.joinRequests[0].status === JoinRequestStatusEnum.Approved
|
|
44
|
+
? JoinResultStatusEnum.Success
|
|
45
|
+
: JoinResultStatusEnum.Pending;
|
|
46
|
+
|
|
47
|
+
return status === JoinResultStatusEnum.Success
|
|
48
|
+
? { status }
|
|
49
|
+
: { status, request: joinRequestLinkedObject(data.joinRequests[0]) };
|
|
50
|
+
};
|
|
51
|
+
/* end_public_function */
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ```js
|
|
6
|
+
* import { onJoinRequestCreated } from '@amityco/ts-sdk'
|
|
7
|
+
* const dispose = onJoinRequestCreated(data => {
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
13
|
+
*
|
|
14
|
+
* @param callback The function to call when the event was fired
|
|
15
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16
|
+
*
|
|
17
|
+
* @category JoinRequest Events
|
|
18
|
+
*/
|
|
19
|
+
export const onJoinRequestCreated = (
|
|
20
|
+
callback: Amity.Listener<Amity.InternalJoinRequest[]>,
|
|
21
|
+
): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const disposers = [
|
|
25
|
+
createEventSubscriber(client, 'onJoinRequestCreated', 'local.joinRequest.created', payload =>
|
|
26
|
+
callback(payload),
|
|
27
|
+
),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
disposers.forEach(fn => fn());
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ```js
|
|
6
|
+
* import { onJoinRequestDeleted } from '@amityco/ts-sdk'
|
|
7
|
+
* const dispose = onJoinRequestDeleted(data => {
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
13
|
+
*
|
|
14
|
+
* @param callback The function to call when the event was fired
|
|
15
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16
|
+
*
|
|
17
|
+
* @category JoinRequest Events
|
|
18
|
+
*/
|
|
19
|
+
export const onJoinRequestDeleted = (
|
|
20
|
+
callback: Amity.Listener<Amity.InternalJoinRequest[]>,
|
|
21
|
+
): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const disposers = [
|
|
25
|
+
createEventSubscriber(client, 'onJoinRequestDeleted', 'local.joinRequest.deleted', payload =>
|
|
26
|
+
callback(payload),
|
|
27
|
+
),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
disposers.forEach(fn => fn());
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
import { createEventSubscriber } from '~/core/events';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ```js
|
|
6
|
+
* import { onJoinRequestUpdated } from '@amityco/ts-sdk'
|
|
7
|
+
* const dispose = onJoinRequestUpdated(data => {
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* Fired when an {@link Amity.CommunityJoinRequestPayload} has been created
|
|
13
|
+
*
|
|
14
|
+
* @param callback The function to call when the event was fired
|
|
15
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
16
|
+
*
|
|
17
|
+
* @category JoinRequest Events
|
|
18
|
+
*/
|
|
19
|
+
export const onJoinRequestUpdated = (
|
|
20
|
+
callback: Amity.Listener<Amity.InternalJoinRequest[]>,
|
|
21
|
+
): Amity.Unsubscriber => {
|
|
22
|
+
const client = getActiveClient();
|
|
23
|
+
|
|
24
|
+
const disposers = [
|
|
25
|
+
createEventSubscriber(client, 'onJoinRequestUpdated', 'local.joinRequest.updated', payload =>
|
|
26
|
+
callback(payload),
|
|
27
|
+
),
|
|
28
|
+
];
|
|
29
|
+
|
|
30
|
+
return () => {
|
|
31
|
+
disposers.forEach(fn => fn());
|
|
32
|
+
};
|
|
33
|
+
};
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
2
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
3
|
+
import { pullFromCache, upsertInCache } from '~/cache/api';
|
|
4
|
+
import { JoinRequestStatusEnum } from '~/@types/domains/joinRequest';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: joinRequest.approve
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
12
|
+
* const isAccepted = await joinRequest.approve()
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Accepts a {@link Amity.JoinRequest} object
|
|
16
|
+
*
|
|
17
|
+
* @param joinRequest the {@link Amity.JoinRequest} to accept
|
|
18
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was accepted
|
|
19
|
+
*
|
|
20
|
+
* @category Join Request API
|
|
21
|
+
* @async
|
|
22
|
+
*/
|
|
23
|
+
export const approveJoinRequest = async (
|
|
24
|
+
joinRequest: Amity.InternalJoinRequest,
|
|
25
|
+
): Promise<boolean> => {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
client.log('joinRequest/approveJoinRequest', joinRequest.joinRequestId);
|
|
28
|
+
|
|
29
|
+
const { data } = await client.http.post<{ success: boolean }>(
|
|
30
|
+
`/api/v4/communities/${joinRequest.targetId}/join/approve`,
|
|
31
|
+
{
|
|
32
|
+
userId: joinRequest.requestorInternalId,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([
|
|
37
|
+
'joinRequest',
|
|
38
|
+
'get',
|
|
39
|
+
joinRequest.joinRequestId,
|
|
40
|
+
])?.data;
|
|
41
|
+
|
|
42
|
+
if (joinRequestCache) {
|
|
43
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
44
|
+
status: JoinRequestStatusEnum.Approved,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return data.success;
|
|
51
|
+
};
|
|
52
|
+
/* end_public_function */
|
|
@@ -0,0 +1,46 @@
|
|
|
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: joinRequest.cancel
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* ```js
|
|
10
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
11
|
+
* const isCanceled = await joinRequest.cancel()
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Cancels a {@link Amity.JoinRequest} object
|
|
15
|
+
*
|
|
16
|
+
* @param joinRequest the {@link Amity.JoinRequest} to cancel
|
|
17
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was canceled
|
|
18
|
+
*
|
|
19
|
+
* @category Join Request API
|
|
20
|
+
* @async
|
|
21
|
+
*/
|
|
22
|
+
export const cancelJoinRequest = async (
|
|
23
|
+
joinRequest: Amity.InternalJoinRequest,
|
|
24
|
+
): Promise<boolean> => {
|
|
25
|
+
const client = getActiveClient();
|
|
26
|
+
client.log('joinRequest/cancelJoinRequest', joinRequest.joinRequestId);
|
|
27
|
+
|
|
28
|
+
const { data } = await client.http.delete<{ success: boolean }>(
|
|
29
|
+
`/api/v4/communities/${joinRequest.targetId}/join`,
|
|
30
|
+
);
|
|
31
|
+
|
|
32
|
+
const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([
|
|
33
|
+
'joinRequest',
|
|
34
|
+
'get',
|
|
35
|
+
joinRequest.joinRequestId,
|
|
36
|
+
])?.data;
|
|
37
|
+
|
|
38
|
+
if (joinRequestCache) {
|
|
39
|
+
dropFromCache(['joinRequest', 'get', joinRequest.joinRequestId]);
|
|
40
|
+
|
|
41
|
+
fireEvent('local.joinRequest.deleted', [joinRequestCache]);
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return data.success;
|
|
45
|
+
};
|
|
46
|
+
/* end_public_function */
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { fireEvent } from '~/core/events';
|
|
2
|
+
import { pullFromCache, upsertInCache } from '~/cache/api';
|
|
3
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
4
|
+
import { JoinRequestStatusEnum } from '~/@types/domains/joinRequest';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: joinRequest.reject
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { joinRequest } from '@amityco/ts-sdk'
|
|
12
|
+
* const isRejected = await joinRequest.reject()
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Rejects a {@link Amity.JoinRequest} object
|
|
16
|
+
*
|
|
17
|
+
* @param joinRequest the {@link Amity.JoinRequest} to reject
|
|
18
|
+
* @returns A success boolean if the {@link Amity.JoinRequest} was rejected
|
|
19
|
+
*
|
|
20
|
+
* @category Join Request API
|
|
21
|
+
* @async
|
|
22
|
+
*/
|
|
23
|
+
export const rejectJoinRequest = async (
|
|
24
|
+
joinRequest: Amity.InternalJoinRequest,
|
|
25
|
+
): Promise<boolean> => {
|
|
26
|
+
const client = getActiveClient();
|
|
27
|
+
client.log('joinRequest/rejectJoinRequest', joinRequest.joinRequestId);
|
|
28
|
+
|
|
29
|
+
const { data } = await client.http.post<{ success: boolean }>(
|
|
30
|
+
`/api/v4/communities/${joinRequest.targetId}/join/reject`,
|
|
31
|
+
{
|
|
32
|
+
userId: joinRequest.requestorInternalId,
|
|
33
|
+
},
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
const joinRequestCache = pullFromCache<Amity.InternalJoinRequest>([
|
|
37
|
+
'joinRequest',
|
|
38
|
+
'get',
|
|
39
|
+
joinRequest.joinRequestId,
|
|
40
|
+
])?.data;
|
|
41
|
+
|
|
42
|
+
if (joinRequestCache) {
|
|
43
|
+
upsertInCache(['joinRequest', 'get', joinRequest.joinRequestId], {
|
|
44
|
+
status: JoinRequestStatusEnum.Rejected,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
fireEvent('local.joinRequest.updated', [joinRequestCache]);
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
return data.success;
|
|
51
|
+
};
|
|
52
|
+
/* end_public_function */
|