@amityco/ts-sdk 7.4.1-e8631ca7.0 → 7.4.1-fd0f791a.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +4 -0
- 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 +16 -1
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +28 -2
- package/dist/@types/domains/community.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/getCommunity.d.ts +1 -1
- package/dist/communityRepository/api/getCommunity.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/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 +897 -389
- package/dist/index.esm.js +760 -252
- package/dist/index.umd.js +4 -4
- 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.map +1 -1
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.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 +7 -1
- package/src/@types/core/model.ts +3 -0
- package/src/@types/core/payload.ts +22 -1
- package/src/@types/domains/community.ts +38 -2
- package/src/@types/domains/joinRequest.ts +66 -0
- package/src/@types/index.ts +1 -0
- package/src/communityRepository/api/getCommunity.ts +8 -0
- package/src/communityRepository/api/joinCommunity.ts +4 -1
- 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/model/idResolvers.ts +1 -0
- package/src/core/model/index.ts +1 -0
- 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 +22 -0
- package/src/utils/linkedObject/index.ts +2 -0
- package/src/utils/linkedObject/joinRequestLinkedObject.ts +31 -0
|
@@ -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 */
|
package/src/communityRepository/observers/getJoinRequests/JoinRequestsLiveCollectionController.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { JoinRequestsPaginationController } from './JoinRequestsPaginationController';
|
|
4
|
+
import { JoinRequestsQueryStreamController } from './JoinRequestsQueryStreamController';
|
|
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 JoinRequestsLiveCollectionController extends LiveCollectionController<
|
|
18
|
+
'joinRequest',
|
|
19
|
+
Amity.JoinRequestLiveCollection,
|
|
20
|
+
Amity.JoinRequest,
|
|
21
|
+
JoinRequestsPaginationController
|
|
22
|
+
> {
|
|
23
|
+
private queryStreamController: JoinRequestsQueryStreamController;
|
|
24
|
+
|
|
25
|
+
private query: Amity.JoinRequestLiveCollection;
|
|
26
|
+
|
|
27
|
+
constructor(
|
|
28
|
+
query: Amity.JoinRequestLiveCollection,
|
|
29
|
+
callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
|
|
30
|
+
) {
|
|
31
|
+
const queryStreamId = hash(query);
|
|
32
|
+
const cacheKey = ['joinRequest', 'collection', queryStreamId];
|
|
33
|
+
const paginationController = new JoinRequestsPaginationController(query);
|
|
34
|
+
|
|
35
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36
|
+
|
|
37
|
+
this.query = query;
|
|
38
|
+
this.queryStreamController = new JoinRequestsQueryStreamController(
|
|
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.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
|
|
51
|
+
if (!collection) {
|
|
52
|
+
pushToCache(this.cacheKey, {
|
|
53
|
+
data: [],
|
|
54
|
+
params: this.query,
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
protected async persistModel(queryPayload: Amity.CommunityJoinRequestPayload & Amity.Pagination) {
|
|
60
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected persistQueryStream({
|
|
64
|
+
response,
|
|
65
|
+
direction,
|
|
66
|
+
refresh,
|
|
67
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'joinRequest'>) {
|
|
68
|
+
const joinRequestResponse = response as unknown as Amity.CommunityJoinRequestPayload &
|
|
69
|
+
Partial<Amity.Pagination>;
|
|
70
|
+
this.queryStreamController.appendToQueryStream(joinRequestResponse, direction, refresh);
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
startSubscription() {
|
|
74
|
+
return this.queryStreamController.subscribeRTE([
|
|
75
|
+
{ fn: onJoinRequestCreated, action: EnumJoinRequestAction.OnLocalJoinRequestCreated },
|
|
76
|
+
{ fn: onJoinRequestUpdated, action: EnumJoinRequestAction.OnLocalJoinRequestUpdated },
|
|
77
|
+
{ fn: onJoinRequestDeleted, action: EnumJoinRequestAction.OnLocalJoinRequestDeleted },
|
|
78
|
+
]);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
82
|
+
const collection = pullFromCache<Amity.JoinRequestLiveCollectionCache>(this.cacheKey)?.data;
|
|
83
|
+
if (!collection) return;
|
|
84
|
+
|
|
85
|
+
const data = this.applyFilter(
|
|
86
|
+
collection.data
|
|
87
|
+
.map(id => pullFromCache<Amity.InternalJoinRequest>(['joinRequest', 'get', id])!)
|
|
88
|
+
.filter(isNonNullable)
|
|
89
|
+
.map(({ data }) => data)
|
|
90
|
+
.map(joinRequestLinkedObject),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
94
|
+
|
|
95
|
+
this.callback({
|
|
96
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
97
|
+
data,
|
|
98
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
99
|
+
loading,
|
|
100
|
+
error,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
applyFilter(data: Amity.JoinRequest[]) {
|
|
105
|
+
let joinRequest = data;
|
|
106
|
+
|
|
107
|
+
if (this.query.status) {
|
|
108
|
+
joinRequest = joinRequest.filter(joinRequest => joinRequest.status === this.query.status);
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
const sortFn = (() => {
|
|
112
|
+
switch (this.query.sortBy) {
|
|
113
|
+
case 'firstCreated':
|
|
114
|
+
return sortByFirstCreated;
|
|
115
|
+
case 'lastCreated':
|
|
116
|
+
return sortByLastCreated;
|
|
117
|
+
default:
|
|
118
|
+
return sortByLastCreated;
|
|
119
|
+
}
|
|
120
|
+
})();
|
|
121
|
+
|
|
122
|
+
joinRequest = joinRequest.sort(sortFn);
|
|
123
|
+
|
|
124
|
+
return joinRequest;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
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 JoinRequestsPaginationController extends PaginationController<
|
|
9
|
+
'joinRequest',
|
|
10
|
+
Amity.JoinRequestLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
async getRequest(queryParams: Amity.JoinRequestLiveCollection, token: string | undefined) {
|
|
13
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, communityId, ...params } = queryParams;
|
|
14
|
+
const options = token ? { token } : { limit };
|
|
15
|
+
|
|
16
|
+
const { data: queryResponse } = await this.http.get<
|
|
17
|
+
Amity.CommunityJoinRequestPayload & Amity.Pagination
|
|
18
|
+
>(`/api/v4/communities/${communityId}/join`, {
|
|
19
|
+
params: {
|
|
20
|
+
...params,
|
|
21
|
+
options,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return queryResponse;
|
|
25
|
+
}
|
|
26
|
+
}
|
package/src/communityRepository/observers/getJoinRequests/JoinRequestsQueryStreamController.ts
ADDED
|
@@ -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,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
|
|
package/src/communityRepository/observers/searchCommunities/SearchCommunitiesPaginationController.ts
CHANGED
|
@@ -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,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 =
|
|
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 => {
|
package/src/core/model/index.ts
CHANGED
package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostQueryStreamController.ts
CHANGED
|
@@ -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
|
-
|
|
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
|
-
|
|
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,24 @@ export const communityLinkedObject = (community: Amity.InternalCommunity): Amity
|
|
|
32
35
|
const { data } = await getInvitation('community', community.communityId);
|
|
33
36
|
return data;
|
|
34
37
|
},
|
|
38
|
+
join: async (): Promise<Amity.JoinResult> => {
|
|
39
|
+
return joinRequest(community.communityId);
|
|
40
|
+
},
|
|
41
|
+
getJoinRequests: (
|
|
42
|
+
params: Omit<Amity.QueryJoinRequest, 'communityId'>,
|
|
43
|
+
callback: Amity.LiveCollectionCallback<Amity.JoinRequest>,
|
|
44
|
+
): Amity.Unsubscriber => {
|
|
45
|
+
return getJoinRequests(
|
|
46
|
+
{
|
|
47
|
+
...params,
|
|
48
|
+
communityId: community.communityId,
|
|
49
|
+
},
|
|
50
|
+
callback,
|
|
51
|
+
);
|
|
52
|
+
},
|
|
53
|
+
getMyJoinRequest: async () => {
|
|
54
|
+
const { data } = await getMyJoinRequest(community.communityId);
|
|
55
|
+
return data;
|
|
56
|
+
},
|
|
35
57
|
};
|
|
36
58
|
};
|
|
@@ -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
|
};
|
|
@@ -0,0 +1,31 @@
|
|
|
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: async () => {
|
|
22
|
+
await cancelJoinRequest(joinRequest);
|
|
23
|
+
},
|
|
24
|
+
approve: async () => {
|
|
25
|
+
await approveJoinRequest(joinRequest);
|
|
26
|
+
},
|
|
27
|
+
reject: async () => {
|
|
28
|
+
await rejectJoinRequest(joinRequest);
|
|
29
|
+
},
|
|
30
|
+
};
|
|
31
|
+
};
|