@amityco/ts-sdk-react-native 6.24.1-13ac472.0 → 6.24.2-18b8e6d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/domains/community.d.ts +15 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +2 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/registerPushNotification.d.ts +2 -0
- package/dist/client/api/registerPushNotification.d.ts.map +1 -0
- package/dist/client/api/secureLogout.d.ts +1 -1
- package/dist/client/api/unregisterPushNotification.d.ts +2 -0
- package/dist/client/api/unregisterPushNotification.d.ts.map +1 -0
- 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 +849 -469
- package/dist/index.esm.js +830 -450
- package/dist/index.umd.js +3 -4
- package/dist/streamRepository/api/getStreams.d.ts +2 -2
- package/dist/utils/liveObject.d.ts +3 -0
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +3 -1
- package/rollup.config.js +6 -0
- package/src/@types/domains/community.ts +25 -1
- package/src/client/api/index.ts +3 -0
- package/src/client/api/registerPushNotification.ts +37 -0
- package/src/client/api/secureLogout.ts +1 -1
- package/src/client/api/unregisterPushNotification.ts +26 -0
- 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/streamRepository/api/getStreams.ts +2 -2
- package/src/utils/liveObject.ts +3 -0
|
@@ -1,31 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
import { getResolver } from '~/core/model';
|
|
3
|
-
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
1
|
+
import { dropFromCache } from '~/cache/api';
|
|
4
2
|
import { getActiveClient } from '~/client/api';
|
|
5
|
-
import {
|
|
6
|
-
|
|
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';
|
|
3
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
4
|
+
import { CommunityLiveCollectionController } from './getCommunities/CommunitiesLiveCollectionController';
|
|
29
5
|
|
|
30
6
|
/* begin_public_function
|
|
31
7
|
id: community.query
|
|
@@ -53,7 +29,7 @@ export const getCommunities = (
|
|
|
53
29
|
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
54
30
|
config?: Amity.LiveCollectionConfig,
|
|
55
31
|
) => {
|
|
56
|
-
const { log, cache
|
|
32
|
+
const { log, cache } = getActiveClient();
|
|
57
33
|
|
|
58
34
|
if (!cache) {
|
|
59
35
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
@@ -62,130 +38,11 @@ export const getCommunities = (
|
|
|
62
38
|
const timestamp = Date.now();
|
|
63
39
|
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
64
40
|
|
|
65
|
-
const
|
|
41
|
+
const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
|
|
42
|
+
const disposers = communitiesLiveCollection.startSubscription();
|
|
66
43
|
|
|
67
|
-
const
|
|
68
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
44
|
+
const cacheKey = communitiesLiveCollection.getCacheKey();
|
|
69
45
|
|
|
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);
|
|
189
46
|
disposers.push(() => dropFromCache(cacheKey));
|
|
190
47
|
|
|
191
48
|
return () => {
|
|
@@ -1,24 +1,19 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
1
|
import hash from 'object-hash';
|
|
3
2
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
4
3
|
import { CommunitiesPaginationController } from './SearchCommunitiesPaginationController';
|
|
5
4
|
import { CommunitiesQueryStreamController } from './SearchCommunitiesQueryStreamController';
|
|
6
5
|
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
7
|
-
import {
|
|
8
|
-
|
|
9
|
-
onCommunityDeleted,
|
|
10
|
-
onCommunityUpdated,
|
|
11
|
-
} from '~/communityRepository/events';
|
|
12
|
-
import {
|
|
13
|
-
filterByCommunityMembership,
|
|
14
|
-
filterByPropEquality,
|
|
15
|
-
sortByDisplayName,
|
|
16
|
-
sortByFirstCreated,
|
|
17
|
-
sortByLastCreated,
|
|
18
|
-
} from '~/core/query';
|
|
6
|
+
import { onCommunityDeleted, onCommunityUpdated } from '~/communityRepository/events';
|
|
7
|
+
import { filterByCommunityMembership, filterByPropEquality } from '~/core/query';
|
|
19
8
|
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
20
9
|
import { getActiveClient } from '~/client';
|
|
21
10
|
import { EnumCommunityActions } from './enums';
|
|
11
|
+
import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
|
|
12
|
+
import {
|
|
13
|
+
onCommunityJoined,
|
|
14
|
+
onCommunityLeft,
|
|
15
|
+
onCommunityUserChanged,
|
|
16
|
+
} from '~/communityRepository/communityMembership';
|
|
22
17
|
|
|
23
18
|
export class SearchCommunityLiveCollectionController extends LiveCollectionController<
|
|
24
19
|
'community',
|
|
@@ -78,6 +73,9 @@ export class SearchCommunityLiveCollectionController extends LiveCollectionContr
|
|
|
78
73
|
return this.queryStreamController.subscribeRTE([
|
|
79
74
|
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
80
75
|
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
76
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
77
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
78
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
|
|
81
79
|
]);
|
|
82
80
|
}
|
|
83
81
|
|
|
@@ -4,6 +4,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
4
4
|
import { getResolver } from '~/core/model';
|
|
5
5
|
import { getActiveClient } from '~/client';
|
|
6
6
|
import { EnumCommunityActions } from './enums';
|
|
7
|
+
import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
|
|
7
8
|
|
|
8
9
|
export class CommunitiesQueryStreamController extends QueryStreamController<
|
|
9
10
|
Amity.CommunityPayload,
|
|
@@ -58,7 +59,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
|
|
|
58
59
|
}
|
|
59
60
|
}
|
|
60
61
|
|
|
61
|
-
reactor(action: EnumCommunityActions) {
|
|
62
|
+
reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
|
|
62
63
|
return (community: Amity.Community) => {
|
|
63
64
|
const collection = pullFromCache<Amity.SearchCommunityLiveCollectionCache>(
|
|
64
65
|
this.cacheKey,
|
|
@@ -73,7 +74,7 @@ export class CommunitiesQueryStreamController extends QueryStreamController<
|
|
|
73
74
|
subscribeRTE(
|
|
74
75
|
createSubscriber: {
|
|
75
76
|
fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
|
|
76
|
-
action: EnumCommunityActions;
|
|
77
|
+
action: EnumCommunityActions | EnumCommunityMemberActions;
|
|
77
78
|
}[],
|
|
78
79
|
) {
|
|
79
80
|
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
@@ -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-react-native'
|
|
12
12
|
*
|
|
13
13
|
* let communities = []
|
|
14
14
|
* const unsub = CommunityRepository.searchCommunities({
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CommunityPostSettingMaps, DefaultCommunityPostSetting } from '~/@types';
|
|
2
|
+
import { pullFromCache } from '~/cache/api';
|
|
2
3
|
import { withUsers } from '~/group/utils';
|
|
3
4
|
import { updateMembershipStatus } from './communityWithMembership';
|
|
4
5
|
|
|
@@ -13,6 +14,22 @@ const getMatchPostSetting = (value: {
|
|
|
13
14
|
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost,
|
|
14
15
|
) ?? DefaultCommunityPostSetting;
|
|
15
16
|
|
|
17
|
+
const convertCommunityUsersToUniqueObject = (
|
|
18
|
+
communityUsers: Amity.RawMembership<'community'>[],
|
|
19
|
+
) => {
|
|
20
|
+
if (!communityUsers) return communityUsers;
|
|
21
|
+
|
|
22
|
+
const result: {
|
|
23
|
+
[key: string]: Amity.RawMembership<'community'>;
|
|
24
|
+
} = {};
|
|
25
|
+
|
|
26
|
+
communityUsers.forEach(user => {
|
|
27
|
+
result[`${user.userId}#${user.communityId}`] = user;
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return result;
|
|
31
|
+
};
|
|
32
|
+
|
|
16
33
|
export const prepareCommunityPayload = (
|
|
17
34
|
rawPayload: Amity.CommunityPayload,
|
|
18
35
|
): Amity.ProcessedCommunityPayload => {
|
|
@@ -27,7 +44,24 @@ export const prepareCommunityPayload = (
|
|
|
27
44
|
}),
|
|
28
45
|
);
|
|
29
46
|
|
|
30
|
-
const
|
|
47
|
+
const mergeCommunityUsers = communities.reduce<{
|
|
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));
|
|
31
65
|
|
|
32
66
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
33
67
|
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
};
|
|
@@ -24,8 +24,11 @@ export const createFile = async <T extends Amity.FileType = any>(
|
|
|
24
24
|
const client = getActiveClient();
|
|
25
25
|
client.log('file/createFile', formData);
|
|
26
26
|
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
const files = formData.getAll('files');
|
|
28
|
+
|
|
29
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
30
|
+
|
|
31
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
29
32
|
|
|
30
33
|
const headers =
|
|
31
34
|
'getHeaders' in formData
|
|
@@ -23,8 +23,12 @@ export const createImage = async (
|
|
|
23
23
|
const client = getActiveClient();
|
|
24
24
|
client.log('file/createImage', formData);
|
|
25
25
|
|
|
26
|
-
|
|
27
|
-
|
|
26
|
+
const files = formData.getAll('files');
|
|
27
|
+
|
|
28
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
29
|
+
|
|
30
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
31
|
+
|
|
28
32
|
const headers =
|
|
29
33
|
'getHeaders' in formData
|
|
30
34
|
? (formData as any).getHeaders()
|
|
@@ -26,8 +26,11 @@ export const createVideo = async (
|
|
|
26
26
|
const client = getActiveClient();
|
|
27
27
|
client.log('file/createVideo', formData);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const files = formData.getAll('files');
|
|
30
|
+
|
|
31
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
32
|
+
|
|
33
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
31
34
|
|
|
32
35
|
if (feedType) {
|
|
33
36
|
formData.append('feedType', feedType);
|
|
@@ -27,8 +27,11 @@ export const uploadFile = async <T extends Amity.FileType = any>(
|
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('file/uploadFile', formData);
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const files = formData.getAll('files');
|
|
31
|
+
|
|
32
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
33
|
+
|
|
34
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
32
35
|
|
|
33
36
|
const headers =
|
|
34
37
|
'getHeaders' in formData
|
|
@@ -27,8 +27,11 @@ export const uploadImage = async (
|
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('file/uploadImage', formData);
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
const files = formData.getAll('files');
|
|
31
|
+
|
|
32
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
33
|
+
|
|
34
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
32
35
|
|
|
33
36
|
const headers =
|
|
34
37
|
'getHeaders' in formData
|
|
@@ -29,8 +29,11 @@ export const uploadVideo = async (
|
|
|
29
29
|
const client = getActiveClient();
|
|
30
30
|
client.log('file/uploadVideo', formData);
|
|
31
31
|
|
|
32
|
-
|
|
33
|
-
|
|
32
|
+
const files = formData.getAll('files');
|
|
33
|
+
|
|
34
|
+
if (!files.length) throw new Error('The formData object must have a `files` key.');
|
|
35
|
+
|
|
36
|
+
formData.append('preferredFilename', (files[0] as File).name);
|
|
34
37
|
|
|
35
38
|
if (feedType) {
|
|
36
39
|
formData.append('feedType', feedType);
|
|
@@ -8,7 +8,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
8
8
|
*/
|
|
9
9
|
/**
|
|
10
10
|
* ```js
|
|
11
|
-
* import { getStreams } from '@amityco/ts-sdk'
|
|
11
|
+
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
12
12
|
* const streams = await getStreams()
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
@@ -62,7 +62,7 @@ export const getStreams = async (query?: {
|
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
* ```js
|
|
65
|
-
* import { getStreams } from '@amityco/ts-sdk'
|
|
65
|
+
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
66
66
|
* const streams = getStreams.locally()
|
|
67
67
|
* ```
|
|
68
68
|
*
|
package/src/utils/liveObject.ts
CHANGED