@amityco/ts-sdk-react-native 6.23.1-d8b4c4c.0 → 6.24.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/.env +26 -26
- package/dist/@types/core/events.d.ts +0 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -4
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -2
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -15
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +3 -19
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/client/api/secureLogout.d.ts +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.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts +0 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities.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/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 +463 -842
- package/dist/index.esm.js +438 -817
- package/dist/index.umd.js +4 -4
- package/dist/streamRepository/api/createStream.d.ts +4 -4
- package/dist/streamRepository/api/createStream.d.ts.map +1 -1
- package/dist/streamRepository/api/deleteStream.d.ts +4 -4
- package/dist/streamRepository/api/deleteStream.d.ts.map +1 -1
- package/dist/streamRepository/api/disposeStream.d.ts +4 -4
- package/dist/streamRepository/api/disposeStream.d.ts.map +1 -1
- package/dist/streamRepository/api/getStreams.d.ts +39 -0
- package/dist/streamRepository/api/getStreams.d.ts.map +1 -0
- package/dist/streamRepository/api/queryStreams.d.ts +4 -4
- package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
- package/dist/streamRepository/events/index.d.ts +0 -2
- package/dist/streamRepository/events/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamRecorded.d.ts +2 -2
- package/dist/streamRepository/events/onStreamRecorded.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStarted.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStarted.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStopped.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
- package/dist/streamRepository/internalApi/queryStreams.d.ts +3 -3
- package/dist/streamRepository/internalApi/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreamById.d.ts +0 -1
- package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams.d.ts +17 -0
- package/dist/streamRepository/observers/getStreams.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +0 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +0 -3
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +1 -5
- package/src/@types/core/model.ts +2 -4
- package/src/@types/core/payload.ts +1 -2
- package/src/@types/domains/community.ts +1 -25
- package/src/@types/domains/stream.ts +3 -23
- package/src/client/api/secureLogout.ts +1 -1
- package/src/communityRepository/api/createCommunity.ts +2 -5
- package/src/communityRepository/api/getCommunities.ts +1 -5
- package/src/communityRepository/api/getCommunity.ts +1 -5
- package/src/communityRepository/api/queryCommunities.ts +2 -2
- package/src/communityRepository/api/updateCommunity.ts +1 -5
- package/src/communityRepository/communityMembership/observers/getMembers.ts +128 -15
- package/src/communityRepository/communityMembership/observers/index.ts +0 -1
- package/src/communityRepository/observers/getCommunities.ts +150 -7
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/communityRepository/utils/payload.ts +1 -35
- package/src/core/model/idResolvers.ts +0 -1
- package/src/core/model/index.ts +0 -1
- package/src/streamRepository/api/createStream.ts +5 -8
- package/src/streamRepository/api/deleteStream.ts +4 -6
- package/src/streamRepository/api/disposeStream.ts +5 -5
- package/src/streamRepository/api/getStreams.ts +81 -0
- package/src/streamRepository/api/queryStreams.ts +4 -4
- package/src/streamRepository/api/updateStream.ts +1 -2
- package/src/streamRepository/events/index.ts +0 -2
- package/src/streamRepository/events/onStreamRecorded.ts +2 -4
- package/src/streamRepository/events/onStreamStarted.ts +2 -4
- package/src/streamRepository/events/onStreamStopped.ts +2 -4
- package/src/streamRepository/internalApi/queryStreams.ts +3 -3
- package/src/streamRepository/observers/getStreamById.ts +5 -18
- package/src/streamRepository/observers/getStreams.ts +152 -0
- package/src/streamRepository/observers/tests/getStreamById.test.ts +1 -1
- package/src/utils/linkedObject/index.ts +0 -2
- package/src/utils/liveObject.ts +0 -3
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +0 -14
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +0 -9
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +0 -15
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +0 -10
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +0 -14
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +0 -9
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +0 -15
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +0 -10
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +0 -20
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +0 -1
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts +0 -2
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +0 -1
- package/dist/streamRepository/events/onStreamFlagged.d.ts +0 -17
- package/dist/streamRepository/events/onStreamFlagged.d.ts.map +0 -1
- package/dist/streamRepository/events/onStreamTerminated.d.ts +0 -17
- package/dist/streamRepository/events/onStreamTerminated.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts +0 -14
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +0 -14
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts +0 -15
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts +0 -2
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/index.d.ts +0 -2
- package/dist/streamRepository/observers/getStreams/index.d.ts.map +0 -1
- package/dist/utils/linkedObject/streamLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +0 -1
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -152
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +0 -26
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -114
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +0 -9
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +0 -130
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +0 -29
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +0 -105
- package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +0 -9
- package/src/communityRepository/communityMembership/observers/searchMembers.ts +0 -60
- package/src/communityRepository/utils/saveCommunityUsers.ts +0 -16
- package/src/streamRepository/events/onStreamFlagged.ts +0 -37
- package/src/streamRepository/events/onStreamTerminated.ts +0 -37
- package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +0 -114
- package/src/streamRepository/observers/getStreams/GetStreamsPageController.ts +0 -23
- package/src/streamRepository/observers/getStreams/GetStreamsQueryStreamController.ts +0 -83
- package/src/streamRepository/observers/getStreams/getStreams.ts +0 -32
- package/src/streamRepository/observers/getStreams/index.ts +0 -1
- package/src/utils/linkedObject/streamLinkedObject.ts +0 -11
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
import hash from 'object-hash';
|
|
3
|
-
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
-
import { CommunityMembersPaginationController } from './CommunityMembersPaginationController';
|
|
5
|
-
import { CommunityMembersQueryStreamController } from './CommunityMembersQueryStreamController';
|
|
6
|
-
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
7
|
-
import {
|
|
8
|
-
onCommunityJoined,
|
|
9
|
-
onCommunityLeft,
|
|
10
|
-
onCommunityUserBanned,
|
|
11
|
-
onCommunityUserChanged,
|
|
12
|
-
onCommunityUserRoleAdded,
|
|
13
|
-
onCommunityUserRoleRemoved,
|
|
14
|
-
onCommunityUserUnbanned,
|
|
15
|
-
} from '~/communityRepository/communityMembership/events';
|
|
16
|
-
import {
|
|
17
|
-
filterByPropIntersection,
|
|
18
|
-
filterBySearchTerm,
|
|
19
|
-
sortByDisplayName,
|
|
20
|
-
sortByFirstCreated,
|
|
21
|
-
sortByLastCreated,
|
|
22
|
-
} from '~/core/query';
|
|
23
|
-
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
24
|
-
import { isNonNullable } from '~/utils';
|
|
25
|
-
import { EnumCommunityMemberActions } from './enums';
|
|
26
|
-
|
|
27
|
-
export class CommunityMembersLiveCollectionController extends LiveCollectionController<
|
|
28
|
-
'communityUser',
|
|
29
|
-
Amity.CommunityMemberLiveCollection,
|
|
30
|
-
Amity.Membership<'community'>,
|
|
31
|
-
CommunityMembersPaginationController
|
|
32
|
-
> {
|
|
33
|
-
private queryStreamController: CommunityMembersQueryStreamController;
|
|
34
|
-
|
|
35
|
-
private query: Amity.CommunityMemberLiveCollection;
|
|
36
|
-
|
|
37
|
-
constructor(
|
|
38
|
-
query: Amity.CommunityMemberLiveCollection,
|
|
39
|
-
callback: Amity.LiveCollectionCallback<Amity.Membership<'community'>>,
|
|
40
|
-
) {
|
|
41
|
-
const queryStreamId = hash(query);
|
|
42
|
-
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
43
|
-
const paginationController = new CommunityMembersPaginationController(query);
|
|
44
|
-
|
|
45
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
46
|
-
|
|
47
|
-
this.query = query;
|
|
48
|
-
this.queryStreamController = new CommunityMembersQueryStreamController(
|
|
49
|
-
this.query,
|
|
50
|
-
this.cacheKey,
|
|
51
|
-
this.notifyChange.bind(this),
|
|
52
|
-
prepareCommunityPayload,
|
|
53
|
-
);
|
|
54
|
-
|
|
55
|
-
this.callback = callback.bind(this);
|
|
56
|
-
this.loadPage({ initial: true });
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
protected setup() {
|
|
60
|
-
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(this.cacheKey)?.data;
|
|
61
|
-
if (!collection) {
|
|
62
|
-
pushToCache(this.cacheKey, {
|
|
63
|
-
data: [],
|
|
64
|
-
params: {},
|
|
65
|
-
});
|
|
66
|
-
}
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
protected async persistModel(queryPayload: Amity.CommunityMembershipPayload & Amity.Pagination) {
|
|
70
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
protected persistQueryStream({
|
|
74
|
-
response,
|
|
75
|
-
direction,
|
|
76
|
-
refresh,
|
|
77
|
-
}: Amity.LiveCollectionPersistQueryStreamParams<'communityUser'>) {
|
|
78
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
startSubscription() {
|
|
82
|
-
return this.queryStreamController.subscribeRTE([
|
|
83
|
-
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
84
|
-
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
85
|
-
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
86
|
-
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
87
|
-
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions.OnCommunityUserRoleAdded },
|
|
88
|
-
{
|
|
89
|
-
fn: onCommunityUserRoleRemoved,
|
|
90
|
-
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
91
|
-
},
|
|
92
|
-
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
93
|
-
]);
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
97
|
-
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(this.cacheKey)?.data;
|
|
98
|
-
if (!collection) return;
|
|
99
|
-
|
|
100
|
-
const data = this.applyFilter(
|
|
101
|
-
collection.data
|
|
102
|
-
.map(id => pullFromCache<Amity.Membership<'community'>>(['communityUsers', 'get', id])!)
|
|
103
|
-
.filter(isNonNullable)
|
|
104
|
-
.map(({ data }) => data) ?? [],
|
|
105
|
-
);
|
|
106
|
-
|
|
107
|
-
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
108
|
-
|
|
109
|
-
this.callback({
|
|
110
|
-
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
111
|
-
data,
|
|
112
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
113
|
-
loading,
|
|
114
|
-
error,
|
|
115
|
-
});
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
applyFilter(data: Amity.Membership<'community'>[]) {
|
|
119
|
-
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
120
|
-
|
|
121
|
-
if (this.query.memberships) {
|
|
122
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
123
|
-
const memberships: Amity.GroupMembership[] = this.query.memberships || [];
|
|
124
|
-
return memberships.includes(communityMembership);
|
|
125
|
-
});
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
if (this.query.search) {
|
|
129
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
130
|
-
}
|
|
131
|
-
|
|
132
|
-
switch (this.query.sortBy) {
|
|
133
|
-
case 'firstCreated':
|
|
134
|
-
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
135
|
-
break;
|
|
136
|
-
case 'displayName':
|
|
137
|
-
communityMembers = communityMembers.sort((a, b) => {
|
|
138
|
-
if (a?.user?.displayName && b?.user?.displayName) {
|
|
139
|
-
return a?.user?.displayName.localeCompare(b?.user?.displayName);
|
|
140
|
-
}
|
|
141
|
-
return 0;
|
|
142
|
-
});
|
|
143
|
-
break;
|
|
144
|
-
case 'lastCreated':
|
|
145
|
-
default:
|
|
146
|
-
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
147
|
-
break;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
return communityMembers;
|
|
151
|
-
}
|
|
152
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,114 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,130 +0,0 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
import hash from 'object-hash';
|
|
3
|
-
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
|
-
import { SearchCommunityMembersPaginationController } from './SearchCommunityMembersPaginationController';
|
|
5
|
-
import { SearchCommunityMembersQueryStreamController } from './SearchCommunityMembersQueryStreamController';
|
|
6
|
-
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
7
|
-
import {
|
|
8
|
-
onCommunityJoined,
|
|
9
|
-
onCommunityLeft,
|
|
10
|
-
onCommunityUserBanned,
|
|
11
|
-
onCommunityUserChanged,
|
|
12
|
-
onCommunityUserRoleRemoved,
|
|
13
|
-
onCommunityUserUnbanned,
|
|
14
|
-
} from '~/communityRepository/communityMembership/events';
|
|
15
|
-
import { filterByPropIntersection, filterBySearchTerm } from '~/core/query';
|
|
16
|
-
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
17
|
-
import { isNonNullable } from '~/utils';
|
|
18
|
-
import { EnumCommunityMemberActions } from './enums';
|
|
19
|
-
|
|
20
|
-
export class SearchCommunityMembersLiveCollectionController extends LiveCollectionController<
|
|
21
|
-
'communityUser',
|
|
22
|
-
Amity.SearchCommunityMemberLiveCollection,
|
|
23
|
-
Amity.Membership<'community'>,
|
|
24
|
-
SearchCommunityMembersPaginationController
|
|
25
|
-
> {
|
|
26
|
-
private queryStreamController: SearchCommunityMembersQueryStreamController;
|
|
27
|
-
|
|
28
|
-
private query: Amity.SearchCommunityMemberLiveCollection;
|
|
29
|
-
|
|
30
|
-
constructor(
|
|
31
|
-
query: Amity.SearchCommunityMemberLiveCollection,
|
|
32
|
-
callback: Amity.LiveCollectionCallback<Amity.Membership<'community'>>,
|
|
33
|
-
) {
|
|
34
|
-
const queryStreamId = hash(query);
|
|
35
|
-
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
36
|
-
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
37
|
-
|
|
38
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39
|
-
|
|
40
|
-
this.query = query;
|
|
41
|
-
this.queryStreamController = new SearchCommunityMembersQueryStreamController(
|
|
42
|
-
this.query,
|
|
43
|
-
this.cacheKey,
|
|
44
|
-
this.notifyChange.bind(this),
|
|
45
|
-
prepareCommunityPayload,
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
this.callback = callback.bind(this);
|
|
49
|
-
this.loadPage({ initial: true });
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
protected setup() {
|
|
53
|
-
const collection = pullFromCache<Amity.SearchCommunityMemberLiveCollectionCache>(
|
|
54
|
-
this.cacheKey,
|
|
55
|
-
)?.data;
|
|
56
|
-
if (!collection) {
|
|
57
|
-
pushToCache(this.cacheKey, {
|
|
58
|
-
data: [],
|
|
59
|
-
params: {},
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
protected async persistModel(queryPayload: Amity.CommunityMembershipPayload & Amity.Pagination) {
|
|
65
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
protected persistQueryStream({
|
|
69
|
-
response,
|
|
70
|
-
direction,
|
|
71
|
-
refresh,
|
|
72
|
-
}: Amity.LiveCollectionPersistQueryStreamParams<'communityUser'>) {
|
|
73
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
startSubscription() {
|
|
77
|
-
return this.queryStreamController.subscribeRTE([
|
|
78
|
-
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
79
|
-
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
80
|
-
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
81
|
-
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
82
|
-
{
|
|
83
|
-
fn: onCommunityUserRoleRemoved,
|
|
84
|
-
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
85
|
-
},
|
|
86
|
-
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
87
|
-
]);
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
91
|
-
const collection = pullFromCache<Amity.SearchCommunityMemberLiveCollectionCache>(
|
|
92
|
-
this.cacheKey,
|
|
93
|
-
)?.data;
|
|
94
|
-
if (!collection) return;
|
|
95
|
-
|
|
96
|
-
const data = this.applyFilter(
|
|
97
|
-
collection.data
|
|
98
|
-
.map(id => pullFromCache<Amity.Membership<'community'>>(['communityUsers', 'get', id])!)
|
|
99
|
-
.filter(isNonNullable)
|
|
100
|
-
.map(({ data }) => data) ?? [],
|
|
101
|
-
);
|
|
102
|
-
|
|
103
|
-
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
104
|
-
|
|
105
|
-
this.callback({
|
|
106
|
-
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
107
|
-
data,
|
|
108
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
109
|
-
loading,
|
|
110
|
-
error,
|
|
111
|
-
});
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
applyFilter(data: Amity.Membership<'community'>[]) {
|
|
115
|
-
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
116
|
-
|
|
117
|
-
if (this.query.memberships) {
|
|
118
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
119
|
-
const memberships: Amity.GroupMembership[] = this.query.memberships || [];
|
|
120
|
-
return memberships.includes(communityMembership);
|
|
121
|
-
});
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
if (this.query.search) {
|
|
125
|
-
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
return communityMembers;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
@@ -1,29 +0,0 @@
|
|
|
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 SearchCommunityMembersPaginationController extends PaginationController<
|
|
9
|
-
'communityUser',
|
|
10
|
-
Amity.CommunityMemberLiveCollection
|
|
11
|
-
> {
|
|
12
|
-
async getRequest(
|
|
13
|
-
queryParams: Amity.SearchCommunityMemberLiveCollection,
|
|
14
|
-
token: string | undefined,
|
|
15
|
-
) {
|
|
16
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
17
|
-
const options = token ? { token } : { limit };
|
|
18
|
-
|
|
19
|
-
const { data: queryResponse } = await this.http.get<
|
|
20
|
-
Amity.CommunityMembershipPayload & Amity.Pagination
|
|
21
|
-
>(`/api/v3/communities/${params.communityId}/users`, {
|
|
22
|
-
params: {
|
|
23
|
-
...params,
|
|
24
|
-
options,
|
|
25
|
-
},
|
|
26
|
-
});
|
|
27
|
-
return queryResponse;
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,105 +0,0 @@
|
|
|
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 SearchCommunityMembersQueryStreamController extends QueryStreamController<
|
|
9
|
-
Amity.CommunityMembershipPayload,
|
|
10
|
-
Amity.SearchCommunityMemberLiveCollection
|
|
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.SearchCommunityMemberLiveCollection,
|
|
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.SearchCommunityMemberLiveCollectionCache>(
|
|
75
|
-
this.cacheKey,
|
|
76
|
-
)?.data;
|
|
77
|
-
if (!collection) return;
|
|
78
|
-
|
|
79
|
-
communityMembers.forEach(communityMember => {
|
|
80
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
81
|
-
communityId: this.query.communityId,
|
|
82
|
-
userId: communityMember.userId,
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
if (communityMember.communityMembership === 'none') {
|
|
86
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
87
|
-
}
|
|
88
|
-
});
|
|
89
|
-
|
|
90
|
-
pushToCache(this.cacheKey, collection);
|
|
91
|
-
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
subscribeRTE(
|
|
96
|
-
createSubscriber: {
|
|
97
|
-
fn: (
|
|
98
|
-
reactor: (channel: Amity.Community, communityUser: Amity.Membership<'community'>[]) => void,
|
|
99
|
-
) => Amity.Unsubscriber;
|
|
100
|
-
action: EnumCommunityMemberActions;
|
|
101
|
-
}[],
|
|
102
|
-
) {
|
|
103
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
104
|
-
}
|
|
105
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
import { getActiveClient } from '~/client/api';
|
|
2
|
-
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
3
|
-
import { dropFromCache } from '~/cache/api';
|
|
4
|
-
import { SearchCommunityMembersLiveCollectionController } from './searchMembers/SearchCommunityMembersLiveCollectionController';
|
|
5
|
-
|
|
6
|
-
/* begin_public_function
|
|
7
|
-
id: community.membership.query
|
|
8
|
-
*/
|
|
9
|
-
/**
|
|
10
|
-
* ```js
|
|
11
|
-
* import { searchMembers } from '@amityco/ts-sdk-react-native'
|
|
12
|
-
*
|
|
13
|
-
* let communityMembers = []
|
|
14
|
-
* const unsub = searchMembers({
|
|
15
|
-
* communityId: Amity.Community['communityId'],
|
|
16
|
-
* }, response => merge(communityMembers, response.data))
|
|
17
|
-
* ```
|
|
18
|
-
*
|
|
19
|
-
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
20
|
-
*
|
|
21
|
-
* @param params for querying community users
|
|
22
|
-
* @param callback the function to call when new data are available
|
|
23
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
24
|
-
*
|
|
25
|
-
* @category Community Live Collection
|
|
26
|
-
*/
|
|
27
|
-
export const searchMembers = (
|
|
28
|
-
params: Amity.SearchCommunityMemberLiveCollection,
|
|
29
|
-
callback: Amity.LiveCollectionCallback<Amity.Membership<'community'>>,
|
|
30
|
-
config?: Amity.LiveCollectionConfig,
|
|
31
|
-
) => {
|
|
32
|
-
const { log, cache } = getActiveClient();
|
|
33
|
-
|
|
34
|
-
if (!cache) {
|
|
35
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
const timestamp = Date.now();
|
|
39
|
-
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
40
|
-
|
|
41
|
-
const searchCommunityMemberLiveCollection = new SearchCommunityMembersLiveCollectionController(
|
|
42
|
-
params,
|
|
43
|
-
resp => {
|
|
44
|
-
callback(resp);
|
|
45
|
-
},
|
|
46
|
-
);
|
|
47
|
-
const disposers = searchCommunityMemberLiveCollection.startSubscription();
|
|
48
|
-
|
|
49
|
-
const cacheKey = searchCommunityMemberLiveCollection.getCacheKey();
|
|
50
|
-
|
|
51
|
-
disposers.push(() => {
|
|
52
|
-
dropFromCache(cacheKey);
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
return () => {
|
|
56
|
-
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
57
|
-
disposers.forEach(fn => fn());
|
|
58
|
-
};
|
|
59
|
-
};
|
|
60
|
-
/* end_public_function */
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { pushToCache } from '~/cache/api';
|
|
2
|
-
|
|
3
|
-
export const saveCommunityUsers = (
|
|
4
|
-
communities: Amity.CommunityPayload['communities'],
|
|
5
|
-
communityUsers: Amity.CommunityPayload['communityUsers'],
|
|
6
|
-
) => {
|
|
7
|
-
if (communities.length === 0 || communityUsers.length === 0) return;
|
|
8
|
-
|
|
9
|
-
communities.forEach(({ communityId }) => {
|
|
10
|
-
const collection = communityUsers.filter(
|
|
11
|
-
({ communityId: userCommunityId }) => communityId === userCommunityId,
|
|
12
|
-
);
|
|
13
|
-
|
|
14
|
-
pushToCache(['communityUsers', 'collection', communityId], collection);
|
|
15
|
-
});
|
|
16
|
-
};
|