@amityco/ts-sdk-react-native 6.24.0 → 6.24.1
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/domains/community.d.ts +15 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/client/api/secureLogout.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +9 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +11 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts +1 -0
- package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +9 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +10 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +20 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +3 -2
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +3 -2
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts +2 -0
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +1 -0
- package/dist/fileRepository/api/createFile.d.ts.map +1 -1
- package/dist/fileRepository/api/createImage.d.ts.map +1 -1
- package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
- package/dist/index.cjs.js +802 -474
- package/dist/index.esm.js +778 -450
- package/dist/index.umd.js +4 -4
- package/dist/utils/liveObject.d.ts +3 -0
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/community.ts +25 -1
- package/src/client/api/secureLogout.ts +1 -1
- package/src/client/utils/markerSyncEngine.ts +4 -1
- package/src/commentRepository/events/utils.ts +8 -5
- package/src/communityRepository/api/createCommunity.ts +5 -2
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +5 -1
- package/src/communityRepository/api/queryCommunities.ts +2 -2
- package/src/communityRepository/api/updateCommunity.ts +5 -1
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +151 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +26 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +114 -0
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +10 -0
- package/src/communityRepository/communityMembership/observers/getMembers.ts +15 -128
- package/src/communityRepository/communityMembership/observers/index.ts +1 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +130 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +29 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +105 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +9 -0
- package/src/communityRepository/communityMembership/observers/searchMembers.ts +60 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +9 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +6 -3
- package/src/communityRepository/observers/getCommunities.ts +7 -150
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +11 -13
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +3 -2
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/communityRepository/utils/payload.ts +35 -1
- package/src/communityRepository/utils/saveCommunityUsers.ts +16 -0
- package/src/fileRepository/api/createFile.ts +5 -2
- package/src/fileRepository/api/createImage.ts +6 -2
- package/src/fileRepository/api/createVideo.ts +5 -2
- package/src/fileRepository/api/uploadFile.ts +5 -2
- package/src/fileRepository/api/uploadImage.ts +5 -2
- package/src/fileRepository/api/uploadVideo.ts +5 -2
- package/src/utils/liveObject.ts +3 -0
|
@@ -1,2 +1,5 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @deprecated This function is deprecated
|
|
3
|
+
*/
|
|
1
4
|
export declare const liveObject: <T extends Amity.Model, K extends keyof T, CallbackData extends unknown = any>(id: T[K], callback: Amity.LiveObjectCallback<CallbackData>, key: K, fetcher: (id: T[K]) => Promise<Amity.Cached<T>>, eventHandlers: ((callback: Amity.Listener<T>) => Amity.Unsubscriber)[], options?: Amity.LiveObjectOptions<T, CallbackData> | undefined) => Amity.Unsubscriber;
|
|
2
5
|
//# sourceMappingURL=liveObject.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"liveObject.d.ts","sourceRoot":"","sources":["../../src/utils/liveObject.ts"],"names":[],"mappings":"AAYA,eAAO,MAAM,UAAU,uPASiC,MAAM,YAAY,wEAEvE,MAAM,YAmFR,CAAC"}
|
|
1
|
+
{"version":3,"file":"liveObject.d.ts","sourceRoot":"","sources":["../../src/utils/liveObject.ts"],"names":[],"mappings":"AAYA;;GAEG;AACH,eAAO,MAAM,UAAU,uPASiC,MAAM,YAAY,wEAEvE,MAAM,YAmFR,CAAC"}
|
package/package.json
CHANGED
|
@@ -121,7 +121,22 @@ declare global {
|
|
|
121
121
|
communityId: string;
|
|
122
122
|
memberships?: ('banned' | 'member')[];
|
|
123
123
|
roles?: string[];
|
|
124
|
-
sortBy?:
|
|
124
|
+
sortBy?:
|
|
125
|
+
| 'firstCreated'
|
|
126
|
+
| 'lastCreated'
|
|
127
|
+
/** @deprecated sortBy displayName is not available */
|
|
128
|
+
| 'displayName';
|
|
129
|
+
/** @deprecated use searchCommunityMembers instead */
|
|
130
|
+
search?: Amity.InternalUser['displayName'] | Amity.InternalUser['userId'];
|
|
131
|
+
page?: string;
|
|
132
|
+
limit?: number;
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
type QuerySearchCommunityMembers = {
|
|
136
|
+
communityId: string;
|
|
137
|
+
memberships?: ('banned' | 'member')[];
|
|
138
|
+
roles?: string[];
|
|
139
|
+
sortBy?: 'firstCreated' | 'lastCreated' | 'displayName';
|
|
125
140
|
search?: Amity.InternalUser['displayName'] | Amity.InternalUser['userId'];
|
|
126
141
|
page?: string;
|
|
127
142
|
limit?: number;
|
|
@@ -131,9 +146,18 @@ declare global {
|
|
|
131
146
|
Omit<QueryCommunityMembers, 'page'>
|
|
132
147
|
>;
|
|
133
148
|
|
|
149
|
+
type SearchCommunityMemberLiveCollection = Amity.LiveCollectionParams<
|
|
150
|
+
Omit<QuerySearchCommunityMembers, 'page'>
|
|
151
|
+
>;
|
|
152
|
+
|
|
134
153
|
type CommunityMemberLiveCollectionCache = Amity.LiveCollectionCache<
|
|
135
154
|
Amity.Membership<'community'>['userId'],
|
|
136
155
|
Pick<QueryCommunityMembers, 'page'>
|
|
137
156
|
>;
|
|
157
|
+
|
|
158
|
+
type SearchCommunityMemberLiveCollectionCache = Amity.LiveCollectionCache<
|
|
159
|
+
Amity.Community['communityId'],
|
|
160
|
+
Pick<QuerySearchCommunityMembers, 'page'>
|
|
161
|
+
>;
|
|
138
162
|
}
|
|
139
163
|
}
|
|
@@ -18,6 +18,7 @@ import { enableUnreadCount } from '../api/enableUnreadCount';
|
|
|
18
18
|
|
|
19
19
|
import { onOnline } from './onOnline';
|
|
20
20
|
import { onUserFeedMarkerUpdated } from '~/marker/events/onUserFeedMarkerUpdated';
|
|
21
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
21
22
|
|
|
22
23
|
const SYNC_TRIGGER_INTERVAL_TIME = 2000;
|
|
23
24
|
const ON_SUB_CHANNEL_DELETE_SYNC_TRIGGER_DELAY = 2000;
|
|
@@ -145,7 +146,9 @@ const registerEventListeners = () => {
|
|
|
145
146
|
|
|
146
147
|
onMessageCreatedMqtt(message => {
|
|
147
148
|
// only conversation, community and broadcast types can sync
|
|
148
|
-
|
|
149
|
+
const client = getActiveClient();
|
|
150
|
+
if (isUnreadCountSupport(message) && message.creatorId !== client.userId)
|
|
151
|
+
events.push(Amity.MarkerSyncEvent.NEW_MESSAGE);
|
|
149
152
|
}),
|
|
150
153
|
|
|
151
154
|
onChannelCreated(() => events.push(Amity.MarkerSyncEvent.CHANNEL_CREATED)),
|
|
@@ -39,11 +39,14 @@ export const createCommentEventSubscriber = (
|
|
|
39
39
|
]);
|
|
40
40
|
|
|
41
41
|
if (parentComment?.data) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
42
|
+
// Skip to update parent childComment if current comment already exists
|
|
43
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
44
|
+
pushToCache(['comment', 'get', comments[0].parentId], {
|
|
45
|
+
...parentComment.data,
|
|
46
|
+
childrenNumber: parentComment.data.childrenNumber + 1,
|
|
47
|
+
children: [...new Set([...parentComment.data.children, comments[0].commentId])],
|
|
48
|
+
});
|
|
49
|
+
}
|
|
47
50
|
}
|
|
48
51
|
}
|
|
49
52
|
|
|
@@ -2,7 +2,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { fireEvent } from '~/core/events';
|
|
5
|
-
|
|
5
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
6
6
|
import { prepareCommunityPayload, prepareCommunityRequest } from '../utils';
|
|
7
7
|
|
|
8
8
|
/* begin_public_function
|
|
@@ -53,7 +53,10 @@ export const createCommunity = async (
|
|
|
53
53
|
const data = prepareCommunityPayload(payload);
|
|
54
54
|
|
|
55
55
|
const cachedAt = client.cache && Date.now();
|
|
56
|
-
if (client.cache)
|
|
56
|
+
if (client.cache) {
|
|
57
|
+
ingestInCache(data, { cachedAt });
|
|
58
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
59
|
+
}
|
|
57
60
|
|
|
58
61
|
const { communities } = data;
|
|
59
62
|
return {
|
|
@@ -3,6 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
6
7
|
import { prepareCommunityPayload } from '../utils';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -36,7 +37,10 @@ export const getCommunities = async (
|
|
|
36
37
|
const data = prepareCommunityPayload(payload);
|
|
37
38
|
|
|
38
39
|
const cachedAt = client.cache && Date.now();
|
|
39
|
-
if (client.cache)
|
|
40
|
+
if (client.cache) {
|
|
41
|
+
ingestInCache(data, { cachedAt });
|
|
42
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
43
|
+
}
|
|
40
44
|
|
|
41
45
|
return {
|
|
42
46
|
data: data.communities,
|
|
@@ -3,6 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
6
7
|
import { prepareCommunityPayload } from '../utils';
|
|
7
8
|
|
|
8
9
|
/**
|
|
@@ -33,7 +34,10 @@ export const getCommunity = async (
|
|
|
33
34
|
const data = prepareCommunityPayload(payload);
|
|
34
35
|
|
|
35
36
|
const cachedAt = client.cache && Date.now();
|
|
36
|
-
if (client.cache)
|
|
37
|
+
if (client.cache) {
|
|
38
|
+
ingestInCache(data, { cachedAt });
|
|
39
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
40
|
+
}
|
|
37
41
|
|
|
38
42
|
const { communities } = data;
|
|
39
43
|
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
|
-
|
|
3
|
-
import { toPage, toToken } from '~/core/query';
|
|
4
2
|
import { pushToCache } from '~/cache/api';
|
|
5
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
6
4
|
import { getResolver } from '~/core/model';
|
|
7
5
|
|
|
8
6
|
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
7
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
9
8
|
import { prepareCommunityPayload } from '../utils';
|
|
10
9
|
|
|
11
10
|
/**
|
|
@@ -67,6 +66,7 @@ export const queryCommunities = async (
|
|
|
67
66
|
|
|
68
67
|
const cacheKey = ['community', 'query', { ...params, options } as Amity.Serializable];
|
|
69
68
|
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
69
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
72
|
return { data: communities, cachedAt, paging };
|
|
@@ -3,6 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { fireEvent } from '~/core/events';
|
|
5
5
|
|
|
6
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
6
7
|
import { prepareCommunityPayload, prepareCommunityRequest } from '../utils';
|
|
7
8
|
|
|
8
9
|
/* begin_public_function
|
|
@@ -44,7 +45,10 @@ export const updateCommunity = async (
|
|
|
44
45
|
const data = prepareCommunityPayload(payload);
|
|
45
46
|
|
|
46
47
|
const cachedAt = client.cache && Date.now();
|
|
47
|
-
if (client.cache)
|
|
48
|
+
if (client.cache) {
|
|
49
|
+
ingestInCache(data, { cachedAt });
|
|
50
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
51
|
+
}
|
|
48
52
|
|
|
49
53
|
const { communities } = data;
|
|
50
54
|
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { CommunityMembersPaginationController } from './CommunityMembersPaginationController';
|
|
4
|
+
import { CommunityMembersQueryStreamController } from './CommunityMembersQueryStreamController';
|
|
5
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
6
|
+
import {
|
|
7
|
+
onCommunityJoined,
|
|
8
|
+
onCommunityLeft,
|
|
9
|
+
onCommunityUserBanned,
|
|
10
|
+
onCommunityUserChanged,
|
|
11
|
+
onCommunityUserRoleAdded,
|
|
12
|
+
onCommunityUserRoleRemoved,
|
|
13
|
+
onCommunityUserUnbanned,
|
|
14
|
+
} from '~/communityRepository/communityMembership/events';
|
|
15
|
+
import {
|
|
16
|
+
filterByPropIntersection,
|
|
17
|
+
filterBySearchTerm,
|
|
18
|
+
sortByDisplayName,
|
|
19
|
+
sortByFirstCreated,
|
|
20
|
+
sortByLastCreated,
|
|
21
|
+
} from '~/core/query';
|
|
22
|
+
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
23
|
+
import { isNonNullable } from '~/utils';
|
|
24
|
+
import { EnumCommunityMemberActions } from './enums';
|
|
25
|
+
|
|
26
|
+
export class CommunityMembersLiveCollectionController extends LiveCollectionController<
|
|
27
|
+
'communityUser',
|
|
28
|
+
Amity.CommunityMemberLiveCollection,
|
|
29
|
+
Amity.Membership<'community'>,
|
|
30
|
+
CommunityMembersPaginationController
|
|
31
|
+
> {
|
|
32
|
+
private queryStreamController: CommunityMembersQueryStreamController;
|
|
33
|
+
|
|
34
|
+
private query: Amity.CommunityMemberLiveCollection;
|
|
35
|
+
|
|
36
|
+
constructor(
|
|
37
|
+
query: Amity.CommunityMemberLiveCollection,
|
|
38
|
+
callback: Amity.LiveCollectionCallback<Amity.Membership<'community'>>,
|
|
39
|
+
) {
|
|
40
|
+
const queryStreamId = hash(query);
|
|
41
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
42
|
+
const paginationController = new CommunityMembersPaginationController(query);
|
|
43
|
+
|
|
44
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
45
|
+
|
|
46
|
+
this.query = query;
|
|
47
|
+
this.queryStreamController = new CommunityMembersQueryStreamController(
|
|
48
|
+
this.query,
|
|
49
|
+
this.cacheKey,
|
|
50
|
+
this.notifyChange.bind(this),
|
|
51
|
+
prepareCommunityPayload,
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
this.callback = callback.bind(this);
|
|
55
|
+
this.loadPage({ initial: true });
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
protected setup() {
|
|
59
|
+
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(this.cacheKey)?.data;
|
|
60
|
+
if (!collection) {
|
|
61
|
+
pushToCache(this.cacheKey, {
|
|
62
|
+
data: [],
|
|
63
|
+
params: {},
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
protected async persistModel(queryPayload: Amity.CommunityMembershipPayload & Amity.Pagination) {
|
|
69
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
protected persistQueryStream({
|
|
73
|
+
response,
|
|
74
|
+
direction,
|
|
75
|
+
refresh,
|
|
76
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'communityUser'>) {
|
|
77
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
startSubscription() {
|
|
81
|
+
return this.queryStreamController.subscribeRTE([
|
|
82
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
83
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
84
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
85
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
86
|
+
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions.OnCommunityUserRoleAdded },
|
|
87
|
+
{
|
|
88
|
+
fn: onCommunityUserRoleRemoved,
|
|
89
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
90
|
+
},
|
|
91
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
92
|
+
]);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
96
|
+
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(this.cacheKey)?.data;
|
|
97
|
+
if (!collection) return;
|
|
98
|
+
|
|
99
|
+
const data = this.applyFilter(
|
|
100
|
+
collection.data
|
|
101
|
+
.map(id => pullFromCache<Amity.Membership<'community'>>(['communityUsers', 'get', id])!)
|
|
102
|
+
.filter(isNonNullable)
|
|
103
|
+
.map(({ data }) => data) ?? [],
|
|
104
|
+
);
|
|
105
|
+
|
|
106
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
107
|
+
|
|
108
|
+
this.callback({
|
|
109
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
110
|
+
data,
|
|
111
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
112
|
+
loading,
|
|
113
|
+
error,
|
|
114
|
+
});
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
applyFilter(data: Amity.Membership<'community'>[]) {
|
|
118
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
119
|
+
|
|
120
|
+
if (this.query.memberships) {
|
|
121
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
122
|
+
const memberships: Amity.GroupMembership[] = this.query.memberships || [];
|
|
123
|
+
return memberships.includes(communityMembership);
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (this.query.search) {
|
|
128
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
switch (this.query.sortBy) {
|
|
132
|
+
case 'firstCreated':
|
|
133
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
134
|
+
break;
|
|
135
|
+
case 'displayName':
|
|
136
|
+
communityMembers = communityMembers.sort((a, b) => {
|
|
137
|
+
if (a?.user?.displayName && b?.user?.displayName) {
|
|
138
|
+
return a?.user?.displayName.localeCompare(b?.user?.displayName);
|
|
139
|
+
}
|
|
140
|
+
return 0;
|
|
141
|
+
});
|
|
142
|
+
break;
|
|
143
|
+
case 'lastCreated':
|
|
144
|
+
default:
|
|
145
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
146
|
+
break;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return communityMembers;
|
|
150
|
+
}
|
|
151
|
+
}
|
|
@@ -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 CommunityMembersPaginationController extends PaginationController<
|
|
9
|
+
'communityUser',
|
|
10
|
+
Amity.CommunityMemberLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
async getRequest(queryParams: Amity.CommunityMemberLiveCollection, token: string | undefined) {
|
|
13
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
14
|
+
const options = token ? { token } : { limit };
|
|
15
|
+
|
|
16
|
+
const { data: queryResponse } = await this.http.get<
|
|
17
|
+
Amity.CommunityMembershipPayload & Amity.Pagination
|
|
18
|
+
>(`/api/v3/communities/${params.communityId}/users`, {
|
|
19
|
+
params: {
|
|
20
|
+
...params,
|
|
21
|
+
options,
|
|
22
|
+
},
|
|
23
|
+
});
|
|
24
|
+
return queryResponse;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
@@ -0,0 +1,114 @@
|
|
|
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';
|
|
6
|
+
import { EnumCommunityMemberActions } from './enums';
|
|
7
|
+
|
|
8
|
+
export class CommunityMembersQueryStreamController extends QueryStreamController<
|
|
9
|
+
Amity.CommunityMembershipPayload,
|
|
10
|
+
Amity.CommunityMemberLiveCollection
|
|
11
|
+
> {
|
|
12
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
13
|
+
|
|
14
|
+
private preparePayload: (
|
|
15
|
+
response: Amity.CommunityMembershipPayload,
|
|
16
|
+
) => Amity.ProcessedCommunityMembershipPayload;
|
|
17
|
+
|
|
18
|
+
constructor(
|
|
19
|
+
query: Amity.CommunityMemberLiveCollection,
|
|
20
|
+
cacheKey: string[],
|
|
21
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
22
|
+
preparePayload: (
|
|
23
|
+
response: Amity.CommunityMembershipPayload,
|
|
24
|
+
) => Amity.ProcessedCommunityMembershipPayload,
|
|
25
|
+
) {
|
|
26
|
+
super(query, cacheKey);
|
|
27
|
+
this.notifyChange = notifyChange;
|
|
28
|
+
this.preparePayload = preparePayload;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async saveToMainDB(response: Amity.CommunityMembershipPayload) {
|
|
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.CommunityMembershipPayload & Partial<Amity.Pagination>,
|
|
44
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
45
|
+
refresh = false,
|
|
46
|
+
) {
|
|
47
|
+
if (refresh) {
|
|
48
|
+
pushToCache(this.cacheKey, {
|
|
49
|
+
data: response.communityUsers.map(({ communityId, userId }) =>
|
|
50
|
+
getResolver('communityUsers')({ communityId, userId }),
|
|
51
|
+
),
|
|
52
|
+
});
|
|
53
|
+
} else {
|
|
54
|
+
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(this.cacheKey)?.data;
|
|
55
|
+
|
|
56
|
+
const communityUsers = collection?.data ?? [];
|
|
57
|
+
|
|
58
|
+
pushToCache(this.cacheKey, {
|
|
59
|
+
...collection,
|
|
60
|
+
data: [
|
|
61
|
+
...new Set([
|
|
62
|
+
...communityUsers,
|
|
63
|
+
...response.communityUsers.map(({ communityId, userId }) =>
|
|
64
|
+
getResolver('communityUsers')({ communityId, userId }),
|
|
65
|
+
),
|
|
66
|
+
]),
|
|
67
|
+
],
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
reactor(action: EnumCommunityMemberActions) {
|
|
73
|
+
return (community: Amity.Community, communityMembers: Amity.Membership<'community'>[]) => {
|
|
74
|
+
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(
|
|
75
|
+
this.cacheKey,
|
|
76
|
+
)?.data;
|
|
77
|
+
if (!collection) return;
|
|
78
|
+
|
|
79
|
+
if (
|
|
80
|
+
action === EnumCommunityMemberActions.OnCommunityUserRoleAdded &&
|
|
81
|
+
this.query.sortBy === 'displayName'
|
|
82
|
+
) {
|
|
83
|
+
return;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
communityMembers.forEach(communityMember => {
|
|
87
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
88
|
+
communityId: this.query.communityId,
|
|
89
|
+
userId: communityMember.userId,
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
if (communityMember.communityMembership === 'none') {
|
|
93
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
94
|
+
} else if (!collection.data.includes(communityMemberCacheId)) {
|
|
95
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
96
|
+
}
|
|
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: (
|
|
107
|
+
reactor: (channel: Amity.Community, communityUser: Amity.Membership<'community'>[]) => void,
|
|
108
|
+
) => Amity.Unsubscriber;
|
|
109
|
+
action: EnumCommunityMemberActions;
|
|
110
|
+
}[],
|
|
111
|
+
) {
|
|
112
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
113
|
+
}
|
|
114
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export enum EnumCommunityMemberActions {
|
|
2
|
+
OnCommunityJoined = 'onCommunityJoined',
|
|
3
|
+
OnCommunityLeft = 'onCommunityLeft',
|
|
4
|
+
OnCommunityUserBanned = 'onCommunityUserBanned',
|
|
5
|
+
OnCommunityUserChanged = 'onCommunityUserChanged',
|
|
6
|
+
OnCommunityUserRoleAdded = 'onCommunityUserRoleAdded',
|
|
7
|
+
OnCommunityUserRoleRemoved = 'onCommunityUserRoleRemoved',
|
|
8
|
+
OnCommunityUserUnbanned = 'onCommunityUserUnbanned',
|
|
9
|
+
OnMemberCountChanged = 'OnMemberCountChanged',
|
|
10
|
+
}
|