@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,13 +1,32 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
1
4
|
import { getActiveClient } from '~/client/api';
|
|
2
5
|
import {
|
|
6
|
+
createQuery,
|
|
3
7
|
filterByPropIntersection,
|
|
4
8
|
filterBySearchTerm,
|
|
9
|
+
queryOptions,
|
|
10
|
+
runQuery,
|
|
5
11
|
sortByFirstCreated,
|
|
6
12
|
sortByLastCreated,
|
|
7
13
|
} from '~/core/query';
|
|
8
|
-
import {
|
|
9
|
-
|
|
10
|
-
|
|
14
|
+
import {
|
|
15
|
+
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
16
|
+
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
17
|
+
ENABLE_CACHE_MESSAGE,
|
|
18
|
+
} from '~/utils/constants';
|
|
19
|
+
import { isNonNullable } from '~/utils';
|
|
20
|
+
import {
|
|
21
|
+
onCommunityJoined,
|
|
22
|
+
onCommunityLeft,
|
|
23
|
+
onCommunityUserBanned,
|
|
24
|
+
onCommunityUserChanged,
|
|
25
|
+
onCommunityUserRoleAdded,
|
|
26
|
+
onCommunityUserRoleRemoved,
|
|
27
|
+
onCommunityUserUnbanned,
|
|
28
|
+
} from '../events';
|
|
29
|
+
import { queryCommunityMembers } from '../api/queryCommunityMembers';
|
|
11
30
|
|
|
12
31
|
/*
|
|
13
32
|
* Exported for testing
|
|
@@ -73,20 +92,114 @@ export const getMembers = (
|
|
|
73
92
|
const timestamp = Date.now();
|
|
74
93
|
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
75
94
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
const
|
|
95
|
+
const { limit: queryLimit, ...queryParams } = params;
|
|
96
|
+
|
|
97
|
+
const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
98
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
99
|
+
|
|
100
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
101
|
+
const cacheKey = ['communityUsers', 'collection', queryParams as unknown as Amity.Serializable];
|
|
102
|
+
const cacheByCommunityIdKey = [
|
|
103
|
+
'communityUsers',
|
|
104
|
+
'collection',
|
|
105
|
+
{ communityId: params.communityId },
|
|
106
|
+
];
|
|
107
|
+
|
|
108
|
+
const responder = (data: Amity.CommunityMemberLiveCollectionCache, isEventModel = false) => {
|
|
109
|
+
const communityMembers: Amity.Membership<'community'>[] =
|
|
110
|
+
data.data
|
|
111
|
+
.map(id => pullFromCache<Amity.Membership<'community'>>(['communityUsers', 'get', id])!)
|
|
112
|
+
.filter(Boolean)
|
|
113
|
+
.map(({ data }) => data) ?? [];
|
|
114
|
+
|
|
115
|
+
callback({
|
|
116
|
+
onNextPage: onFetch,
|
|
117
|
+
data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
|
|
118
|
+
hasNextPage: !!data.params?.page,
|
|
119
|
+
loading: data.loading,
|
|
120
|
+
error: data.error,
|
|
121
|
+
});
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
const realtimeRouter =
|
|
125
|
+
(_: Amity.CommunityMemberActionType) =>
|
|
126
|
+
(_: Amity.Community, communityMembers: Amity.Membership<'community'>[]) => {
|
|
127
|
+
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(cacheKey)?.data;
|
|
128
|
+
if (!collection) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
const communityMemberCacheIds = communityMembers
|
|
133
|
+
.map(communityMember => {
|
|
134
|
+
if (params.communityId !== communityMember.communityId) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
139
|
+
communityId: params.communityId,
|
|
140
|
+
userId: communityMember.userId,
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
return communityMemberCacheId;
|
|
144
|
+
})
|
|
145
|
+
.filter(isNonNullable);
|
|
84
146
|
|
|
85
|
-
|
|
147
|
+
collection.data = [...new Set([...communityMemberCacheIds, ...collection.data])];
|
|
148
|
+
|
|
149
|
+
pushToCache(cacheKey, collection);
|
|
150
|
+
pushToCache(cacheByCommunityIdKey, collection);
|
|
151
|
+
responder(collection, true);
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
const onFetch = (initial = false) => {
|
|
155
|
+
const collection = pullFromCache<Amity.CommunityMemberLiveCollectionCache>(cacheKey)?.data;
|
|
156
|
+
|
|
157
|
+
const communityMembers = collection?.data ?? [];
|
|
158
|
+
|
|
159
|
+
if (!initial && communityMembers.length > 0 && !collection?.params.page) return;
|
|
160
|
+
|
|
161
|
+
const query = createQuery(queryCommunityMembers, {
|
|
162
|
+
...queryParams,
|
|
163
|
+
limit: initial ? limit : undefined,
|
|
164
|
+
page: !initial ? collection?.params.page : undefined,
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
runQuery(
|
|
168
|
+
query,
|
|
169
|
+
({ data: result, error, loading, paging }) => {
|
|
170
|
+
const data = {
|
|
171
|
+
loading,
|
|
172
|
+
error,
|
|
173
|
+
params: { page: paging?.next },
|
|
174
|
+
data: communityMembers,
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
if (result) {
|
|
178
|
+
data.data = [
|
|
179
|
+
...new Set([...communityMembers, ...result.map(getResolver('communityUsers'))]),
|
|
180
|
+
];
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
pushToCache(cacheKey, data);
|
|
184
|
+
pushToCache(cacheByCommunityIdKey, data);
|
|
185
|
+
|
|
186
|
+
responder(data);
|
|
187
|
+
},
|
|
188
|
+
queryOptions(policy),
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
disposers.push(
|
|
193
|
+
onCommunityLeft(realtimeRouter('onLeft')),
|
|
194
|
+
onCommunityJoined(realtimeRouter('onJoin')),
|
|
195
|
+
onCommunityUserBanned(realtimeRouter('onBan')),
|
|
196
|
+
onCommunityUserUnbanned(realtimeRouter('onUnban')),
|
|
197
|
+
onCommunityUserChanged(realtimeRouter('onMemberCountChanged')),
|
|
198
|
+
onCommunityUserRoleAdded(realtimeRouter('onMemberCountChanged')),
|
|
199
|
+
onCommunityUserRoleRemoved(realtimeRouter('onMemberCountChanged')),
|
|
200
|
+
);
|
|
86
201
|
|
|
87
|
-
|
|
88
|
-
dropFromCache(cacheKey);
|
|
89
|
-
});
|
|
202
|
+
onFetch(true);
|
|
90
203
|
|
|
91
204
|
return () => {
|
|
92
205
|
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
@@ -1,7 +1,31 @@
|
|
|
1
|
-
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
4
|
import { getActiveClient } from '~/client/api';
|
|
3
|
-
import {
|
|
4
|
-
|
|
5
|
+
import {
|
|
6
|
+
createQuery,
|
|
7
|
+
filterByCommunityMembership,
|
|
8
|
+
filterByPropEquality,
|
|
9
|
+
filterByStringComparePartially,
|
|
10
|
+
queryOptions,
|
|
11
|
+
runQuery,
|
|
12
|
+
sortByDisplayName,
|
|
13
|
+
sortByFirstCreated,
|
|
14
|
+
sortByLastCreated,
|
|
15
|
+
} from '~/core/query';
|
|
16
|
+
import {
|
|
17
|
+
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
18
|
+
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
19
|
+
ENABLE_CACHE_MESSAGE,
|
|
20
|
+
} from '~/utils/constants';
|
|
21
|
+
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
22
|
+
import { onCommunityCreated, onCommunityDeleted, onCommunityUpdated } from '../events';
|
|
23
|
+
import {
|
|
24
|
+
onCommunityJoined,
|
|
25
|
+
onCommunityLeft,
|
|
26
|
+
onCommunityUserChanged,
|
|
27
|
+
} from '../communityMembership/events';
|
|
28
|
+
import { queryCommunities } from '../api/queryCommunities';
|
|
5
29
|
|
|
6
30
|
/* begin_public_function
|
|
7
31
|
id: community.query
|
|
@@ -29,7 +53,7 @@ export const getCommunities = (
|
|
|
29
53
|
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
30
54
|
config?: Amity.LiveCollectionConfig,
|
|
31
55
|
) => {
|
|
32
|
-
const { log, cache } = getActiveClient();
|
|
56
|
+
const { log, cache, userId } = getActiveClient();
|
|
33
57
|
|
|
34
58
|
if (!cache) {
|
|
35
59
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
@@ -38,11 +62,130 @@ export const getCommunities = (
|
|
|
38
62
|
const timestamp = Date.now();
|
|
39
63
|
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
40
64
|
|
|
41
|
-
const
|
|
42
|
-
const disposers = communitiesLiveCollection.startSubscription();
|
|
65
|
+
const { limit: queryLimit, ...queryParams } = params;
|
|
43
66
|
|
|
44
|
-
const
|
|
67
|
+
const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
68
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
45
69
|
|
|
70
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
71
|
+
const cacheKey = ['community', 'collection', queryParams as Amity.Serializable];
|
|
72
|
+
|
|
73
|
+
const responder = (data: Amity.CommunityLiveCollectionCache) => {
|
|
74
|
+
let communities: Amity.Community[] =
|
|
75
|
+
data.data
|
|
76
|
+
.map(communityId => pullFromCache<Amity.Community>(['community', 'get', communityId])!)
|
|
77
|
+
.filter(Boolean)
|
|
78
|
+
.map(({ data }) => data) ?? [];
|
|
79
|
+
|
|
80
|
+
communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
|
|
81
|
+
|
|
82
|
+
if (!params.includeDeleted) {
|
|
83
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
if (params.categoryId) {
|
|
87
|
+
communities = communities.filter(c => c.categoryIds?.includes(params.categoryId!));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
if (params.tags) {
|
|
91
|
+
communities = communities.filter(c => c.tags?.some(t => params.tags?.includes(t)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (params.membership && userId) {
|
|
95
|
+
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
99
|
+
|
|
100
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
101
|
+
communities = communities.sort(
|
|
102
|
+
sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/*
|
|
107
|
+
* The server returns communities with empty | null displayName's first before
|
|
108
|
+
* returning sorted list of communities with displayNames
|
|
109
|
+
*
|
|
110
|
+
* This section needs to be updated as displayNames can be null as well
|
|
111
|
+
*/
|
|
112
|
+
if (sortBy === 'displayName') {
|
|
113
|
+
communities = communities
|
|
114
|
+
// this needs to be aligned with the backend data type
|
|
115
|
+
.map(c => (c.displayName ? c : { ...c, displayName: '' }))
|
|
116
|
+
// @ts-ignore
|
|
117
|
+
.sort(sortByDisplayName);
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
callback({
|
|
121
|
+
onNextPage: onFetch,
|
|
122
|
+
data: communities,
|
|
123
|
+
hasNextPage: !!data.params?.page,
|
|
124
|
+
loading: data.loading,
|
|
125
|
+
error: data.error,
|
|
126
|
+
});
|
|
127
|
+
};
|
|
128
|
+
|
|
129
|
+
const realtimeRouter = (_: Amity.CommunityActionType) => (community: Amity.Community) => {
|
|
130
|
+
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
|
|
131
|
+
if (!collection) return;
|
|
132
|
+
|
|
133
|
+
/*
|
|
134
|
+
* Simply update collection and let responder decide what to do with data
|
|
135
|
+
*/
|
|
136
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
137
|
+
|
|
138
|
+
pushToCache(cacheKey, collection);
|
|
139
|
+
responder(collection);
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const onFetch = (initial = false) => {
|
|
143
|
+
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
|
|
144
|
+
|
|
145
|
+
const communities = collection?.data ?? [];
|
|
146
|
+
|
|
147
|
+
if (!initial && communities.length > 0 && !collection?.params.page) return;
|
|
148
|
+
|
|
149
|
+
const query = createQuery(queryCommunities, {
|
|
150
|
+
...queryParams,
|
|
151
|
+
limit: initial ? limit : undefined,
|
|
152
|
+
page: !initial ? collection?.params.page : undefined,
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
runQuery(
|
|
156
|
+
query,
|
|
157
|
+
({ data: result, error, loading, paging }) => {
|
|
158
|
+
const data = {
|
|
159
|
+
loading,
|
|
160
|
+
error,
|
|
161
|
+
params: { page: paging?.next },
|
|
162
|
+
data: communities,
|
|
163
|
+
};
|
|
164
|
+
|
|
165
|
+
if (result) {
|
|
166
|
+
data.data = initial
|
|
167
|
+
? result.map(getResolver('community'))
|
|
168
|
+
: [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
pushToCache(cacheKey, data);
|
|
172
|
+
|
|
173
|
+
responder(data);
|
|
174
|
+
},
|
|
175
|
+
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
176
|
+
);
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
disposers.push(
|
|
180
|
+
onCommunityCreated(realtimeRouter('onCreate')),
|
|
181
|
+
onCommunityDeleted(realtimeRouter('onDelete')),
|
|
182
|
+
onCommunityUpdated(realtimeRouter('onUpdate')),
|
|
183
|
+
onCommunityJoined(realtimeRouter('onJoin')),
|
|
184
|
+
onCommunityLeft(realtimeRouter('onLeft')),
|
|
185
|
+
onCommunityUserChanged(realtimeRouter('onMemberCountChanged')),
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
onFetch(true);
|
|
46
189
|
disposers.push(() => dropFromCache(cacheKey));
|
|
47
190
|
|
|
48
191
|
return () => {
|
|
@@ -8,7 +8,7 @@ import { SearchCommunityLiveCollectionController } from './searchCommunities/Sea
|
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
10
|
* ```js
|
|
11
|
-
* import { CommunityRepository } from '@amityco/ts-sdk
|
|
11
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
12
12
|
*
|
|
13
13
|
* let communities = []
|
|
14
14
|
* const unsub = CommunityRepository.searchCommunities({
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { CommunityPostSettingMaps, DefaultCommunityPostSetting } from '~/@types';
|
|
2
|
-
import { pullFromCache } from '~/cache/api';
|
|
3
2
|
import { withUsers } from '~/group/utils';
|
|
4
3
|
import { updateMembershipStatus } from './communityWithMembership';
|
|
5
4
|
|
|
@@ -14,22 +13,6 @@ const getMatchPostSetting = (value: {
|
|
|
14
13
|
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost,
|
|
15
14
|
) ?? DefaultCommunityPostSetting;
|
|
16
15
|
|
|
17
|
-
const convertCommunityUsersToUniqueObject = (
|
|
18
|
-
communityUsers: Amity.RawMembership<'community'>[],
|
|
19
|
-
) => {
|
|
20
|
-
if (!communityUsers) return communityUsers;
|
|
21
|
-
|
|
22
|
-
const result: {
|
|
23
|
-
[key: Amity.RawMembership<'community'>['userId']]: Amity.RawMembership<'community'>;
|
|
24
|
-
} = {};
|
|
25
|
-
|
|
26
|
-
communityUsers.forEach(user => {
|
|
27
|
-
result[user.userId] = user;
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
return result;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
16
|
export const prepareCommunityPayload = (
|
|
34
17
|
rawPayload: Amity.CommunityPayload,
|
|
35
18
|
): Amity.ProcessedCommunityPayload => {
|
|
@@ -44,24 +27,7 @@ export const prepareCommunityPayload = (
|
|
|
44
27
|
}),
|
|
45
28
|
);
|
|
46
29
|
|
|
47
|
-
const
|
|
48
|
-
[key: string]: Amity.RawMembership<'community'>;
|
|
49
|
-
}>((acc, { communityId }) => {
|
|
50
|
-
const users = pullFromCache<Amity.RawMembership<'community'>[]>([
|
|
51
|
-
'communityUsers',
|
|
52
|
-
'collection',
|
|
53
|
-
communityId,
|
|
54
|
-
])?.data;
|
|
55
|
-
|
|
56
|
-
if (!users) return acc;
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
...convertCommunityUsersToUniqueObject(users),
|
|
60
|
-
...acc,
|
|
61
|
-
};
|
|
62
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
63
|
-
|
|
64
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
30
|
+
const communityUsers = withUsers(rawPayload.communityUsers);
|
|
65
31
|
|
|
66
32
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
67
33
|
|
package/src/core/model/index.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
-
import { LinkedObject } from '~/utils/linkedObject';
|
|
5
4
|
|
|
6
5
|
/* begin_public_function
|
|
7
6
|
id: stream.create
|
|
@@ -12,18 +11,16 @@ import { LinkedObject } from '~/utils/linkedObject';
|
|
|
12
11
|
* const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
|
|
13
12
|
* ```
|
|
14
13
|
*
|
|
15
|
-
* Creates an {@link Amity.
|
|
14
|
+
* Creates an {@link Amity.Stream}
|
|
16
15
|
*
|
|
17
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
18
|
-
* @returns The newly created {@link Amity.
|
|
16
|
+
* @param bundle The data necessary to create a new {@link Amity.Stream}
|
|
17
|
+
* @returns The newly created {@link Amity.Stream}
|
|
19
18
|
*
|
|
20
19
|
* @category Stream API
|
|
21
20
|
* @async
|
|
22
21
|
*/
|
|
23
22
|
export const createStream = async (
|
|
24
|
-
bundle: Pick<Amity.
|
|
25
|
-
isSecure?: boolean;
|
|
26
|
-
},
|
|
23
|
+
bundle: Pick<Amity.Stream, 'title' | 'thumbnailFileId' | 'description'> & { isSecure?: boolean },
|
|
27
24
|
): Promise<Amity.Cached<Amity.Stream>> => {
|
|
28
25
|
const client = getActiveClient();
|
|
29
26
|
client.log('stream/createStream', bundle);
|
|
@@ -36,7 +33,7 @@ export const createStream = async (
|
|
|
36
33
|
const { videoStreamings } = data;
|
|
37
34
|
|
|
38
35
|
return {
|
|
39
|
-
data:
|
|
36
|
+
data: videoStreamings[0],
|
|
40
37
|
cachedAt,
|
|
41
38
|
};
|
|
42
39
|
};
|
|
@@ -15,17 +15,15 @@ import { getStream } from './getStream';
|
|
|
15
15
|
* const success = await deleteStream(streamId)
|
|
16
16
|
* ```
|
|
17
17
|
*
|
|
18
|
-
* Deletes a {@link Amity.
|
|
18
|
+
* Deletes a {@link Amity.Stream}
|
|
19
19
|
*
|
|
20
|
-
* @param streamId The {@link Amity.
|
|
21
|
-
* @return A success boolean if the {@link Amity.
|
|
20
|
+
* @param streamId The {@link Amity.Stream} ID to delete
|
|
21
|
+
* @return A success boolean if the {@link Amity.Stream} was deleted
|
|
22
22
|
*
|
|
23
23
|
* @category Stream API
|
|
24
24
|
* @async
|
|
25
25
|
*/
|
|
26
|
-
export const deleteStream = async (
|
|
27
|
-
streamId: Amity.InternalStream['streamId'],
|
|
28
|
-
): Promise<boolean> => {
|
|
26
|
+
export const deleteStream = async (streamId: Amity.Stream['streamId']): Promise<boolean> => {
|
|
29
27
|
const client = getActiveClient();
|
|
30
28
|
client.log('stream/deleteStream', streamId);
|
|
31
29
|
|
|
@@ -8,18 +8,18 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
8
8
|
* const stream = await disposeStream(streamId)
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Dispose a {@link Amity.
|
|
11
|
+
* Dispose a {@link Amity.Stream}.
|
|
12
12
|
* Streaming status will be updated to "ended" and streaming url will be invalidated
|
|
13
13
|
*
|
|
14
|
-
* @param streamId The {@link Amity.
|
|
15
|
-
* @returns the associated {@link Amity.
|
|
14
|
+
* @param streamId The {@link Amity.Stream} ID to dispose
|
|
15
|
+
* @returns the associated {@link Amity.Stream} object
|
|
16
16
|
*
|
|
17
17
|
* @category Stream API
|
|
18
18
|
* @async
|
|
19
19
|
*/
|
|
20
20
|
export const disposeStream = async (
|
|
21
|
-
streamId: Amity.
|
|
22
|
-
): Promise<Amity.Cached<Amity.
|
|
21
|
+
streamId: Amity.Stream['streamId'],
|
|
22
|
+
): Promise<Amity.Cached<Amity.Stream>> => {
|
|
23
23
|
const client = getActiveClient();
|
|
24
24
|
client.log('stream/disposeStream', streamId);
|
|
25
25
|
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import { toPage, toToken } from '~/core/query';
|
|
4
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
+
|
|
6
|
+
/* begin_public_function
|
|
7
|
+
id: stream.query
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* ```js
|
|
11
|
+
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
12
|
+
* const streams = await getStreams()
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* Queries a paginable list of {@link Amity.Stream} objects
|
|
16
|
+
*
|
|
17
|
+
* @param query The query parameters
|
|
18
|
+
* @returns A page of {@link Amity.Stream} objects
|
|
19
|
+
*
|
|
20
|
+
* @category Stream API
|
|
21
|
+
* @async
|
|
22
|
+
*/
|
|
23
|
+
export const getStreams = async (query?: {
|
|
24
|
+
isLive?: boolean;
|
|
25
|
+
statuses?: Amity.StreamStatus[];
|
|
26
|
+
userPublicIds?: Amity.InternalUser['userId'][];
|
|
27
|
+
sortBy?: 'lastCreated' | 'firstCreated';
|
|
28
|
+
isDeleted?: Amity.Stream['isDeleted'];
|
|
29
|
+
page?: Amity.Page;
|
|
30
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.Stream>>> => {
|
|
31
|
+
const client = getActiveClient();
|
|
32
|
+
client.log('stream/getStreams', query);
|
|
33
|
+
|
|
34
|
+
const { page, ...params } = query ?? {};
|
|
35
|
+
|
|
36
|
+
const { data } = await client.http.get<{ results: Amity.StreamPayload } & Amity.Pagination>(
|
|
37
|
+
`/api/v3/video-streaming`,
|
|
38
|
+
{
|
|
39
|
+
params: {
|
|
40
|
+
...params,
|
|
41
|
+
options: {
|
|
42
|
+
token: toToken(page, 'skiplimit'),
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
},
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
49
|
+
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
50
|
+
const { paging, results: payload } = data;
|
|
51
|
+
const { videoStreamings } = payload;
|
|
52
|
+
|
|
53
|
+
const cachedAt = client.cache && Date.now();
|
|
54
|
+
if (client.cache) ingestInCache(payload as Amity.StreamPayload, { cachedAt });
|
|
55
|
+
|
|
56
|
+
const nextPage = toPage(paging.next);
|
|
57
|
+
const prevPage = toPage(paging.previous);
|
|
58
|
+
|
|
59
|
+
return { data: videoStreamings, cachedAt, prevPage, nextPage };
|
|
60
|
+
};
|
|
61
|
+
/* end_public_function */
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* ```js
|
|
65
|
+
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
66
|
+
* const streams = getStreams.locally()
|
|
67
|
+
* ```
|
|
68
|
+
*
|
|
69
|
+
* Queries a paginable list of {@link Amity.Stream} objects from cache
|
|
70
|
+
*
|
|
71
|
+
* @param query The query parameters
|
|
72
|
+
* @returns streams
|
|
73
|
+
*
|
|
74
|
+
* @category Stream API
|
|
75
|
+
*/
|
|
76
|
+
getStreams.locally = (query: Parameters<typeof getStreams>[0]) => {
|
|
77
|
+
const client = getActiveClient();
|
|
78
|
+
client.log('stream/getStreams.locally', query);
|
|
79
|
+
|
|
80
|
+
// TODO
|
|
81
|
+
};
|
|
@@ -14,10 +14,10 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
14
14
|
* const streams = await getStreams()
|
|
15
15
|
* ```
|
|
16
16
|
*
|
|
17
|
-
* Queries a paginable list of {@link Amity.
|
|
17
|
+
* Queries a paginable list of {@link Amity.Stream} objects
|
|
18
18
|
*
|
|
19
19
|
* @param query The query parameters
|
|
20
|
-
* @returns A page of {@link Amity.
|
|
20
|
+
* @returns A page of {@link Amity.Stream} objects
|
|
21
21
|
*
|
|
22
22
|
* @category Stream API
|
|
23
23
|
* @async
|
|
@@ -27,9 +27,9 @@ export const queryStreams = async (query?: {
|
|
|
27
27
|
statuses?: Amity.StreamStatus[];
|
|
28
28
|
userPublicIds?: Amity.InternalUser['userId'][];
|
|
29
29
|
sortBy?: 'lastCreated' | 'firstCreated';
|
|
30
|
-
isDeleted?: Amity.
|
|
30
|
+
isDeleted?: Amity.Stream['isDeleted'];
|
|
31
31
|
page?: Amity.Page;
|
|
32
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.
|
|
32
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.Stream>>> => {
|
|
33
33
|
const client = getActiveClient();
|
|
34
34
|
client.log('stream/queryStreams', query);
|
|
35
35
|
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
-
import { LinkedObject } from '~/utils/linkedObject';
|
|
5
4
|
|
|
6
5
|
/* begin_public_function
|
|
7
6
|
id: stream.update
|
|
@@ -39,7 +38,7 @@ export const updateStream = async (
|
|
|
39
38
|
const { videoStreamings } = data;
|
|
40
39
|
|
|
41
40
|
return {
|
|
42
|
-
data:
|
|
41
|
+
data: videoStreamings.find(stream => stream.streamId === streamId)!,
|
|
43
42
|
cachedAt,
|
|
44
43
|
};
|
|
45
44
|
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export { onStreamStarted } from './onStreamStarted';
|
|
2
2
|
export { onStreamStopped } from './onStreamStopped';
|
|
3
3
|
export { onStreamRecorded } from './onStreamRecorded';
|
|
4
|
-
export { onStreamFlagged } from './onStreamFlagged';
|
|
5
|
-
export { onStreamTerminated } from './onStreamTerminated';
|
|
@@ -11,16 +11,14 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* })
|
|
12
12
|
* ```
|
|
13
13
|
*
|
|
14
|
-
* Fired when the recordings of a {@link Amity.
|
|
14
|
+
* Fired when the recordings of a {@link Amity.Stream} are available
|
|
15
15
|
*
|
|
16
16
|
* @param callback The function to call when the event was fired
|
|
17
17
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18
18
|
*
|
|
19
19
|
* @category Stream Events
|
|
20
20
|
*/
|
|
21
|
-
export const onStreamRecorded = (
|
|
22
|
-
callback: Amity.Listener<Amity.InternalStream>,
|
|
23
|
-
): Amity.Unsubscriber => {
|
|
21
|
+
export const onStreamRecorded = (callback: Amity.Listener<Amity.Stream>): Amity.Unsubscriber => {
|
|
24
22
|
const client = getActiveClient();
|
|
25
23
|
|
|
26
24
|
const filter = (payload: Amity.StreamPayload) => {
|