@amityco/ts-sdk-react-native 6.24.0 → 6.24.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/domains/community.d.ts +15 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/client/api/secureLogout.d.ts +1 -1
- package/dist/client/utils/markerSyncEngine.d.ts.map +1 -1
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +9 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +11 -0
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts +1 -0
- package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +14 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +9 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +15 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +10 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +20 -0
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +1 -0
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts +3 -2
- package/dist/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts +3 -2
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts +2 -0
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +1 -0
- package/dist/fileRepository/api/createFile.d.ts.map +1 -1
- package/dist/fileRepository/api/createImage.d.ts.map +1 -1
- package/dist/fileRepository/api/createVideo.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadFile.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadImage.d.ts.map +1 -1
- package/dist/fileRepository/api/uploadVideo.d.ts.map +1 -1
- package/dist/index.cjs.js +802 -474
- package/dist/index.esm.js +778 -450
- package/dist/index.umd.js +4 -4
- package/dist/utils/liveObject.d.ts +3 -0
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/community.ts +25 -1
- package/src/client/api/secureLogout.ts +1 -1
- package/src/client/utils/markerSyncEngine.ts +4 -1
- package/src/commentRepository/events/utils.ts +8 -5
- package/src/communityRepository/api/createCommunity.ts +5 -2
- package/src/communityRepository/api/getCommunities.ts +5 -1
- package/src/communityRepository/api/getCommunity.ts +5 -1
- package/src/communityRepository/api/queryCommunities.ts +2 -2
- package/src/communityRepository/api/updateCommunity.ts +5 -1
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +151 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +26 -0
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +114 -0
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +10 -0
- package/src/communityRepository/communityMembership/observers/getMembers.ts +15 -128
- package/src/communityRepository/communityMembership/observers/index.ts +1 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +130 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +29 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +105 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +9 -0
- package/src/communityRepository/communityMembership/observers/searchMembers.ts +60 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +9 -1
- package/src/communityRepository/observers/getCommunities/CommunitiesQueryStreamController.ts +6 -3
- package/src/communityRepository/observers/getCommunities.ts +7 -150
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +11 -13
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesQueryStreamController.ts +3 -2
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/communityRepository/utils/payload.ts +35 -1
- package/src/communityRepository/utils/saveCommunityUsers.ts +16 -0
- package/src/fileRepository/api/createFile.ts +5 -2
- package/src/fileRepository/api/createImage.ts +6 -2
- package/src/fileRepository/api/createVideo.ts +5 -2
- package/src/fileRepository/api/uploadFile.ts +5 -2
- package/src/fileRepository/api/uploadImage.ts +5 -2
- package/src/fileRepository/api/uploadVideo.ts +5 -2
- package/src/utils/liveObject.ts +3 -0
package/dist/index.cjs.js
CHANGED
|
@@ -117,8 +117,8 @@ const PostContentType = Object.freeze({
|
|
|
117
117
|
|
|
118
118
|
function getVersion() {
|
|
119
119
|
try {
|
|
120
|
-
// the string ''v6.24.
|
|
121
|
-
return 'v6.24.
|
|
120
|
+
// the string ''v6.24.1-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
121
|
+
return 'v6.24.1-cjs';
|
|
122
122
|
}
|
|
123
123
|
catch (error) {
|
|
124
124
|
return '__dev__';
|
|
@@ -8705,7 +8705,8 @@ const registerEventListeners = () => {
|
|
|
8705
8705
|
events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
|
|
8706
8706
|
}), onMessageCreatedMqtt(message => {
|
|
8707
8707
|
// only conversation, community and broadcast types can sync
|
|
8708
|
-
|
|
8708
|
+
const client = getActiveClient();
|
|
8709
|
+
if (isUnreadCountSupport(message) && message.creatorId !== client.userId)
|
|
8709
8710
|
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
8710
8711
|
}), onChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.CHANNEL_CREATED */)), onChannelDeleted(() => events.push("subchannel is deleted" /* Amity.MarkerSyncEvent.CHANNEL_DELETED */)), onChannelJoined(() => events.push("subchannel is joined" /* Amity.MarkerSyncEvent.CHANNEL_JOINED */)), onChannelLeft(() => events.push("subchannel is left" /* Amity.MarkerSyncEvent.CHANNEL_LEFT */)), onSubChannelCreated(() => events.push("subchannel is created" /* Amity.MarkerSyncEvent.SUB_CHANNEL_CREATED */)), onSubChannelDeleted(() =>
|
|
8711
8712
|
/*
|
|
@@ -9106,7 +9107,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9106
9107
|
*/
|
|
9107
9108
|
/**
|
|
9108
9109
|
* ```js
|
|
9109
|
-
* import { Client } from '@amityco/ts-sdk'
|
|
9110
|
+
* import { Client } from '@amityco/ts-sdk-react-native'
|
|
9110
9111
|
* const success = await Client.secureLogout()
|
|
9111
9112
|
* ```
|
|
9112
9113
|
*
|
|
@@ -9462,6 +9463,9 @@ function isEqual(x, y) {
|
|
|
9462
9463
|
}));
|
|
9463
9464
|
}
|
|
9464
9465
|
|
|
9466
|
+
/**
|
|
9467
|
+
* @deprecated This function is deprecated
|
|
9468
|
+
*/
|
|
9465
9469
|
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
9466
9470
|
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
9467
9471
|
const { cache } = getActiveClient();
|
|
@@ -11812,8 +11816,10 @@ getFile.locally = (fileId) => {
|
|
|
11812
11816
|
const uploadFile = async (formData, onProgress) => {
|
|
11813
11817
|
const client = getActiveClient();
|
|
11814
11818
|
client.log('file/uploadFile', formData);
|
|
11815
|
-
|
|
11819
|
+
const files = formData.getAll('files');
|
|
11820
|
+
if (!files.length)
|
|
11816
11821
|
throw new Error('The formData object must have a `files` key.');
|
|
11822
|
+
formData.append('preferredFilename', files[0].name);
|
|
11817
11823
|
const headers = 'getHeaders' in formData
|
|
11818
11824
|
? formData.getHeaders()
|
|
11819
11825
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -11895,8 +11901,10 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
11895
11901
|
const uploadVideo = async (formData, feedType, onProgress) => {
|
|
11896
11902
|
const client = getActiveClient();
|
|
11897
11903
|
client.log('file/uploadVideo', formData);
|
|
11898
|
-
|
|
11904
|
+
const files = formData.getAll('files');
|
|
11905
|
+
if (!files.length)
|
|
11899
11906
|
throw new Error('The formData object must have a `files` key.');
|
|
11907
|
+
formData.append('preferredFilename', files[0].name);
|
|
11900
11908
|
if (feedType) {
|
|
11901
11909
|
formData.append('feedType', feedType);
|
|
11902
11910
|
}
|
|
@@ -11942,8 +11950,10 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
11942
11950
|
const uploadImage = async (formData, onProgress) => {
|
|
11943
11951
|
const client = getActiveClient();
|
|
11944
11952
|
client.log('file/uploadImage', formData);
|
|
11945
|
-
|
|
11953
|
+
const files = formData.getAll('files');
|
|
11954
|
+
if (!files.length)
|
|
11946
11955
|
throw new Error('The formData object must have a `files` key.');
|
|
11956
|
+
formData.append('preferredFilename', files[0].name);
|
|
11947
11957
|
const headers = 'getHeaders' in formData
|
|
11948
11958
|
? formData.getHeaders()
|
|
11949
11959
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -11983,8 +11993,10 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
11983
11993
|
const createImage = async (formData, onProgress) => {
|
|
11984
11994
|
const client = getActiveClient();
|
|
11985
11995
|
client.log('file/createImage', formData);
|
|
11986
|
-
|
|
11996
|
+
const files = formData.getAll('files');
|
|
11997
|
+
if (!files.length)
|
|
11987
11998
|
throw new Error('The formData object must have a `files` key.');
|
|
11999
|
+
formData.append('preferredFilename', files[0].name);
|
|
11988
12000
|
const headers = 'getHeaders' in formData
|
|
11989
12001
|
? formData.getHeaders()
|
|
11990
12002
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -12024,8 +12036,10 @@ const createImage = async (formData, onProgress) => {
|
|
|
12024
12036
|
const createFile = async (formData, onProgress) => {
|
|
12025
12037
|
const client = getActiveClient();
|
|
12026
12038
|
client.log('file/createFile', formData);
|
|
12027
|
-
|
|
12039
|
+
const files = formData.getAll('files');
|
|
12040
|
+
if (!files.length)
|
|
12028
12041
|
throw new Error('The formData object must have a `files` key.');
|
|
12042
|
+
formData.append('preferredFilename', files[0].name);
|
|
12029
12043
|
const headers = 'getHeaders' in formData
|
|
12030
12044
|
? formData.getHeaders()
|
|
12031
12045
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -12065,8 +12079,10 @@ const createFile = async (formData, onProgress) => {
|
|
|
12065
12079
|
const createVideo = async (formData, feedType, onProgress) => {
|
|
12066
12080
|
const client = getActiveClient();
|
|
12067
12081
|
client.log('file/createVideo', formData);
|
|
12068
|
-
|
|
12082
|
+
const files = formData.getAll('files');
|
|
12083
|
+
if (!files.length)
|
|
12069
12084
|
throw new Error('The formData object must have a `files` key.');
|
|
12085
|
+
formData.append('preferredFilename', files[0].name);
|
|
12070
12086
|
if (feedType) {
|
|
12071
12087
|
formData.append('feedType', feedType);
|
|
12072
12088
|
}
|
|
@@ -13018,7 +13034,10 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
13018
13034
|
comments[0].parentId,
|
|
13019
13035
|
]);
|
|
13020
13036
|
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
13021
|
-
|
|
13037
|
+
// Skip to update parent childComment if current comment already exists
|
|
13038
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
13039
|
+
pushToCache(['comment', 'get', comments[0].parentId], Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] }));
|
|
13040
|
+
}
|
|
13022
13041
|
}
|
|
13023
13042
|
}
|
|
13024
13043
|
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
@@ -17536,7 +17555,7 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
17536
17555
|
*
|
|
17537
17556
|
* @category Channel Live Collection
|
|
17538
17557
|
*/
|
|
17539
|
-
const searchMembers = (params, callback, config) => {
|
|
17558
|
+
const searchMembers$1 = (params, callback, config) => {
|
|
17540
17559
|
return getMembers$1(params, callback);
|
|
17541
17560
|
};
|
|
17542
17561
|
/* end_public_function */
|
|
@@ -17547,7 +17566,7 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
17547
17566
|
removeMembers: removeMembers$1,
|
|
17548
17567
|
applyFilter: applyFilter$1,
|
|
17549
17568
|
getMembers: getMembers$1,
|
|
17550
|
-
searchMembers: searchMembers
|
|
17569
|
+
searchMembers: searchMembers$1
|
|
17551
17570
|
});
|
|
17552
17571
|
|
|
17553
17572
|
/* begin_public_function
|
|
@@ -17790,12 +17809,30 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
17790
17809
|
prepareChannelPayload: prepareChannelPayload
|
|
17791
17810
|
});
|
|
17792
17811
|
|
|
17812
|
+
const saveCommunityUsers = (communities, communityUsers) => {
|
|
17813
|
+
if (communities.length === 0 || communityUsers.length === 0)
|
|
17814
|
+
return;
|
|
17815
|
+
communities.forEach(({ communityId }) => {
|
|
17816
|
+
const collection = communityUsers.filter(({ communityId: userCommunityId }) => communityId === userCommunityId);
|
|
17817
|
+
pushToCache(['communityUsers', 'collection', communityId], collection);
|
|
17818
|
+
});
|
|
17819
|
+
};
|
|
17820
|
+
|
|
17793
17821
|
const getMatchPostSetting = (value) => {
|
|
17794
17822
|
var _a;
|
|
17795
17823
|
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
17796
17824
|
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
17797
17825
|
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
17798
17826
|
};
|
|
17827
|
+
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
17828
|
+
if (!communityUsers)
|
|
17829
|
+
return communityUsers;
|
|
17830
|
+
const result = {};
|
|
17831
|
+
communityUsers.forEach(user => {
|
|
17832
|
+
result[`${user.userId}#${user.communityId}`] = user;
|
|
17833
|
+
});
|
|
17834
|
+
return result;
|
|
17835
|
+
};
|
|
17799
17836
|
const prepareCommunityPayload = (rawPayload) => {
|
|
17800
17837
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
17801
17838
|
const communities = rawPayload.communities.map((_a) => {
|
|
@@ -17805,7 +17842,18 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
17805
17842
|
onlyAdminCanPost,
|
|
17806
17843
|
}) }, restCommunityPayload));
|
|
17807
17844
|
});
|
|
17808
|
-
const
|
|
17845
|
+
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
17846
|
+
var _a;
|
|
17847
|
+
const users = (_a = pullFromCache([
|
|
17848
|
+
'communityUsers',
|
|
17849
|
+
'collection',
|
|
17850
|
+
communityId,
|
|
17851
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17852
|
+
if (!users)
|
|
17853
|
+
return acc;
|
|
17854
|
+
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
17855
|
+
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
17856
|
+
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
17809
17857
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
17810
17858
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
17811
17859
|
};
|
|
@@ -17839,8 +17887,10 @@ const getCommunities$1 = async (communityIds) => {
|
|
|
17839
17887
|
});
|
|
17840
17888
|
const data = prepareCommunityPayload(payload);
|
|
17841
17889
|
const cachedAt = client.cache && Date.now();
|
|
17842
|
-
if (client.cache)
|
|
17890
|
+
if (client.cache) {
|
|
17843
17891
|
ingestInCache(data, { cachedAt });
|
|
17892
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17893
|
+
}
|
|
17844
17894
|
return {
|
|
17845
17895
|
data: data.communities,
|
|
17846
17896
|
cachedAt,
|
|
@@ -17902,8 +17952,10 @@ const createCommunity = async (bundle) => {
|
|
|
17902
17952
|
fireEvent('community.created', payload);
|
|
17903
17953
|
const data = prepareCommunityPayload(payload);
|
|
17904
17954
|
const cachedAt = client.cache && Date.now();
|
|
17905
|
-
if (client.cache)
|
|
17955
|
+
if (client.cache) {
|
|
17906
17956
|
ingestInCache(data, { cachedAt });
|
|
17957
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17958
|
+
}
|
|
17907
17959
|
const { communities } = data;
|
|
17908
17960
|
return {
|
|
17909
17961
|
data: communities[0],
|
|
@@ -17937,8 +17989,10 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
17937
17989
|
fireEvent('community.updated', payload);
|
|
17938
17990
|
const data = prepareCommunityPayload(payload);
|
|
17939
17991
|
const cachedAt = client.cache && Date.now();
|
|
17940
|
-
if (client.cache)
|
|
17992
|
+
if (client.cache) {
|
|
17941
17993
|
ingestInCache(data, { cachedAt });
|
|
17994
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17995
|
+
}
|
|
17942
17996
|
const { communities } = data;
|
|
17943
17997
|
return {
|
|
17944
17998
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -17968,8 +18022,10 @@ const getCommunity$1 = async (communityId) => {
|
|
|
17968
18022
|
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
17969
18023
|
const data = prepareCommunityPayload(payload);
|
|
17970
18024
|
const cachedAt = client.cache && Date.now();
|
|
17971
|
-
if (client.cache)
|
|
18025
|
+
if (client.cache) {
|
|
17972
18026
|
ingestInCache(data, { cachedAt });
|
|
18027
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
18028
|
+
}
|
|
17973
18029
|
const { communities } = data;
|
|
17974
18030
|
return {
|
|
17975
18031
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -18512,7 +18568,7 @@ const observeCommunity = (communityId, callback) => {
|
|
|
18512
18568
|
* TODO: handle cache receive cache option, and cache policy
|
|
18513
18569
|
* TODO: check if querybyIds is supported
|
|
18514
18570
|
*/
|
|
18515
|
-
class CommunitiesPaginationController extends PaginationController {
|
|
18571
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
18516
18572
|
async getRequest(queryParams, token) {
|
|
18517
18573
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18518
18574
|
const options = token ? { token } : { limit };
|
|
@@ -18523,7 +18579,7 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
18523
18579
|
}
|
|
18524
18580
|
}
|
|
18525
18581
|
|
|
18526
|
-
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
18582
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
18527
18583
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18528
18584
|
super(query, cacheKey);
|
|
18529
18585
|
this.notifyChange = notifyChange;
|
|
@@ -18565,22 +18621,173 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
18565
18621
|
}
|
|
18566
18622
|
}
|
|
18567
18623
|
|
|
18568
|
-
var EnumCommunityActions;
|
|
18624
|
+
var EnumCommunityActions$1;
|
|
18569
18625
|
(function (EnumCommunityActions) {
|
|
18570
18626
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
18571
18627
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
18572
18628
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
18573
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
18629
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
18630
|
+
|
|
18631
|
+
var EnumCommunityMemberActions$1;
|
|
18632
|
+
(function (EnumCommunityMemberActions) {
|
|
18633
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
18634
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
18635
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
18636
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
18637
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
18638
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
18639
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
18640
|
+
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
18641
|
+
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
18574
18642
|
|
|
18575
|
-
/*
|
|
18576
|
-
|
|
18643
|
+
/* begin_public_function
|
|
18644
|
+
id: community.membership.add_members
|
|
18645
|
+
*/
|
|
18646
|
+
/**
|
|
18647
|
+
* ```js
|
|
18648
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
18649
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
18650
|
+
* ```
|
|
18651
|
+
*
|
|
18652
|
+
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
18653
|
+
*
|
|
18654
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
18655
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
18656
|
+
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
18657
|
+
*
|
|
18658
|
+
* @category Community API
|
|
18659
|
+
* @async
|
|
18660
|
+
*/
|
|
18661
|
+
const addMembers = async (communityId, userIds) => {
|
|
18662
|
+
const client = getActiveClient();
|
|
18663
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
18664
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
18665
|
+
fireEvent('community.userAdded', payload);
|
|
18666
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18667
|
+
if (client.cache)
|
|
18668
|
+
ingestInCache(data);
|
|
18669
|
+
const { communityUsers } = data;
|
|
18670
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
18671
|
+
};
|
|
18672
|
+
/* end_public_function */
|
|
18673
|
+
|
|
18674
|
+
/* begin_public_function
|
|
18675
|
+
id: community.membership.remove_member
|
|
18676
|
+
*/
|
|
18677
|
+
/**
|
|
18678
|
+
* ```js
|
|
18679
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
18680
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
18681
|
+
* ```
|
|
18682
|
+
*
|
|
18683
|
+
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
18684
|
+
*
|
|
18685
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
18686
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
18687
|
+
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
18688
|
+
*
|
|
18689
|
+
* @category Community API
|
|
18690
|
+
* @async
|
|
18691
|
+
*/
|
|
18692
|
+
const removeMembers = async (communityId, userIds) => {
|
|
18693
|
+
const client = getActiveClient();
|
|
18694
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
18695
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
18696
|
+
fireEvent('community.userRemoved', payload);
|
|
18697
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
18698
|
+
if (client.cache)
|
|
18699
|
+
ingestInCache(data);
|
|
18700
|
+
const { communityUsers } = data;
|
|
18701
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
18702
|
+
};
|
|
18703
|
+
/* end_public_function */
|
|
18704
|
+
|
|
18705
|
+
/**
|
|
18706
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18707
|
+
* TODO: check if querybyIds is supported
|
|
18708
|
+
*/
|
|
18709
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
18710
|
+
async getRequest(queryParams, token) {
|
|
18711
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18712
|
+
const options = token ? { token } : { limit };
|
|
18713
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
18714
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
18715
|
+
});
|
|
18716
|
+
return queryResponse;
|
|
18717
|
+
}
|
|
18718
|
+
}
|
|
18719
|
+
|
|
18720
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
18721
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18722
|
+
super(query, cacheKey);
|
|
18723
|
+
this.notifyChange = notifyChange;
|
|
18724
|
+
this.preparePayload = preparePayload;
|
|
18725
|
+
}
|
|
18726
|
+
async saveToMainDB(response) {
|
|
18727
|
+
const processedPayload = await this.preparePayload(response);
|
|
18728
|
+
const client = getActiveClient();
|
|
18729
|
+
const cachedAt = client.cache && Date.now();
|
|
18730
|
+
if (client.cache) {
|
|
18731
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18732
|
+
}
|
|
18733
|
+
}
|
|
18734
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18735
|
+
var _a, _b;
|
|
18736
|
+
if (refresh) {
|
|
18737
|
+
pushToCache(this.cacheKey, {
|
|
18738
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18739
|
+
});
|
|
18740
|
+
}
|
|
18741
|
+
else {
|
|
18742
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18743
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18744
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
18745
|
+
...new Set([
|
|
18746
|
+
...communityUsers,
|
|
18747
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18748
|
+
]),
|
|
18749
|
+
] }));
|
|
18750
|
+
}
|
|
18751
|
+
}
|
|
18752
|
+
reactor(action) {
|
|
18753
|
+
return (community, communityMembers) => {
|
|
18754
|
+
var _a;
|
|
18755
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18756
|
+
if (!collection)
|
|
18757
|
+
return;
|
|
18758
|
+
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
18759
|
+
this.query.sortBy === 'displayName') {
|
|
18760
|
+
return;
|
|
18761
|
+
}
|
|
18762
|
+
communityMembers.forEach(communityMember => {
|
|
18763
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
18764
|
+
communityId: this.query.communityId,
|
|
18765
|
+
userId: communityMember.userId,
|
|
18766
|
+
});
|
|
18767
|
+
if (communityMember.communityMembership === 'none') {
|
|
18768
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
18769
|
+
}
|
|
18770
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
18771
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
18772
|
+
}
|
|
18773
|
+
});
|
|
18774
|
+
pushToCache(this.cacheKey, collection);
|
|
18775
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18776
|
+
};
|
|
18777
|
+
}
|
|
18778
|
+
subscribeRTE(createSubscriber) {
|
|
18779
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18780
|
+
}
|
|
18781
|
+
}
|
|
18782
|
+
|
|
18783
|
+
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
18577
18784
|
constructor(query, callback) {
|
|
18578
18785
|
const queryStreamId = hash__default["default"](query);
|
|
18579
|
-
const cacheKey = ['
|
|
18580
|
-
const paginationController = new
|
|
18786
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
18787
|
+
const paginationController = new CommunityMembersPaginationController(query);
|
|
18581
18788
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
18582
18789
|
this.query = query;
|
|
18583
|
-
this.queryStreamController = new
|
|
18790
|
+
this.queryStreamController = new CommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
18584
18791
|
this.callback = callback.bind(this);
|
|
18585
18792
|
this.loadPage({ initial: true });
|
|
18586
18793
|
}
|
|
@@ -18602,8 +18809,16 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18602
18809
|
}
|
|
18603
18810
|
startSubscription() {
|
|
18604
18811
|
return this.queryStreamController.subscribeRTE([
|
|
18605
|
-
{ fn:
|
|
18606
|
-
{ fn:
|
|
18812
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
18813
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
18814
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
|
|
18815
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
|
|
18816
|
+
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
|
|
18817
|
+
{
|
|
18818
|
+
fn: onCommunityUserRoleRemoved,
|
|
18819
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
18820
|
+
},
|
|
18821
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
18607
18822
|
]);
|
|
18608
18823
|
}
|
|
18609
18824
|
notifyChange({ origin, loading, error }) {
|
|
@@ -18612,8 +18827,8 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18612
18827
|
if (!collection)
|
|
18613
18828
|
return;
|
|
18614
18829
|
const data = this.applyFilter((_b = collection.data
|
|
18615
|
-
.map(id => pullFromCache(['
|
|
18616
|
-
.filter(
|
|
18830
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
18831
|
+
.filter(isNonNullable)
|
|
18617
18832
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
18618
18833
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
18619
18834
|
return;
|
|
@@ -18626,108 +18841,392 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18626
18841
|
});
|
|
18627
18842
|
}
|
|
18628
18843
|
applyFilter(data) {
|
|
18629
|
-
|
|
18630
|
-
|
|
18631
|
-
|
|
18632
|
-
|
|
18633
|
-
|
|
18634
|
-
|
|
18635
|
-
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
18844
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
18845
|
+
if (this.query.memberships) {
|
|
18846
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
18847
|
+
const memberships = this.query.memberships || [];
|
|
18848
|
+
return memberships.includes(communityMembership);
|
|
18849
|
+
});
|
|
18636
18850
|
}
|
|
18637
|
-
if (this.query.
|
|
18638
|
-
|
|
18851
|
+
if (this.query.search) {
|
|
18852
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
18639
18853
|
}
|
|
18640
|
-
|
|
18641
|
-
|
|
18854
|
+
switch (this.query.sortBy) {
|
|
18855
|
+
case 'firstCreated':
|
|
18856
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
18857
|
+
break;
|
|
18858
|
+
case 'displayName':
|
|
18859
|
+
communityMembers = communityMembers.sort((a, b) => {
|
|
18860
|
+
var _a, _b, _c, _d;
|
|
18861
|
+
if (((_a = a === null || a === void 0 ? void 0 : a.user) === null || _a === void 0 ? void 0 : _a.displayName) && ((_b = b === null || b === void 0 ? void 0 : b.user) === null || _b === void 0 ? void 0 : _b.displayName)) {
|
|
18862
|
+
return (_c = a === null || a === void 0 ? void 0 : a.user) === null || _c === void 0 ? void 0 : _c.displayName.localeCompare((_d = b === null || b === void 0 ? void 0 : b.user) === null || _d === void 0 ? void 0 : _d.displayName);
|
|
18863
|
+
}
|
|
18864
|
+
return 0;
|
|
18865
|
+
});
|
|
18866
|
+
break;
|
|
18867
|
+
case 'lastCreated':
|
|
18868
|
+
default:
|
|
18869
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
18870
|
+
break;
|
|
18642
18871
|
}
|
|
18643
|
-
return
|
|
18872
|
+
return communityMembers;
|
|
18644
18873
|
}
|
|
18645
18874
|
}
|
|
18646
18875
|
|
|
18876
|
+
/*
|
|
18877
|
+
* Exported for testing
|
|
18878
|
+
* @hidden
|
|
18879
|
+
*/
|
|
18880
|
+
const applyFilter = (data, params) => {
|
|
18881
|
+
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
18882
|
+
if (params.memberships) {
|
|
18883
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
18884
|
+
const membership = params.memberships;
|
|
18885
|
+
return membership.includes(communityMembership);
|
|
18886
|
+
});
|
|
18887
|
+
}
|
|
18888
|
+
if (params.search) {
|
|
18889
|
+
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
18890
|
+
}
|
|
18891
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
18892
|
+
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
18893
|
+
return communityMembers;
|
|
18894
|
+
};
|
|
18647
18895
|
/* begin_public_function
|
|
18648
|
-
id: community.query
|
|
18896
|
+
id: community.membership.query
|
|
18649
18897
|
*/
|
|
18650
18898
|
/**
|
|
18651
18899
|
* ```js
|
|
18652
|
-
* import {
|
|
18900
|
+
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
18653
18901
|
*
|
|
18654
|
-
* let
|
|
18655
|
-
* const unsub =
|
|
18656
|
-
*
|
|
18657
|
-
* }, response => merge(
|
|
18902
|
+
* let communityMembers = []
|
|
18903
|
+
* const unsub = getMembers({
|
|
18904
|
+
* communityId: Amity.Community['communityId'],
|
|
18905
|
+
* }, response => merge(communityMembers, response.data))
|
|
18658
18906
|
* ```
|
|
18659
18907
|
*
|
|
18660
|
-
* Observe all mutations on a list of {@link Amity.
|
|
18908
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
18661
18909
|
*
|
|
18662
|
-
* @param params for querying
|
|
18910
|
+
* @param params for querying community users
|
|
18663
18911
|
* @param callback the function to call when new data are available
|
|
18664
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the
|
|
18912
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
18665
18913
|
*
|
|
18666
18914
|
* @category Community Live Collection
|
|
18667
18915
|
*/
|
|
18668
|
-
const
|
|
18916
|
+
const getMembers = (params, callback, config) => {
|
|
18669
18917
|
const { log, cache } = getActiveClient();
|
|
18670
18918
|
if (!cache) {
|
|
18671
18919
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
18672
18920
|
}
|
|
18673
18921
|
const timestamp = Date.now();
|
|
18674
|
-
log(`
|
|
18675
|
-
const
|
|
18676
|
-
|
|
18677
|
-
|
|
18678
|
-
|
|
18922
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
18923
|
+
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
18924
|
+
console.log('resp', resp);
|
|
18925
|
+
callback(resp);
|
|
18926
|
+
});
|
|
18927
|
+
const disposers = communityMemberLiveCollection.startSubscription();
|
|
18928
|
+
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
18929
|
+
disposers.push(() => {
|
|
18930
|
+
dropFromCache(cacheKey);
|
|
18931
|
+
});
|
|
18679
18932
|
return () => {
|
|
18680
|
-
log(`
|
|
18933
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
18681
18934
|
disposers.forEach(fn => fn());
|
|
18682
18935
|
};
|
|
18683
18936
|
};
|
|
18684
18937
|
/* end_public_function */
|
|
18685
18938
|
|
|
18686
18939
|
/**
|
|
18687
|
-
*
|
|
18688
|
-
*
|
|
18689
|
-
* const communities = await queryCommunities()
|
|
18690
|
-
* ```
|
|
18691
|
-
*
|
|
18692
|
-
* Queries a paginable list of {@link Amity.Community} objects
|
|
18693
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
18694
|
-
*
|
|
18695
|
-
* @param query The query parameters
|
|
18696
|
-
* @returns A page of {@link Amity.Community} objects
|
|
18697
|
-
*
|
|
18698
|
-
* @category Community API
|
|
18699
|
-
* @async
|
|
18940
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
18941
|
+
* TODO: check if querybyIds is supported
|
|
18700
18942
|
*/
|
|
18701
|
-
|
|
18702
|
-
|
|
18703
|
-
|
|
18704
|
-
|
|
18705
|
-
|
|
18706
|
-
|
|
18707
|
-
|
|
18708
|
-
|
|
18709
|
-
|
|
18710
|
-
|
|
18711
|
-
|
|
18712
|
-
|
|
18713
|
-
|
|
18714
|
-
|
|
18715
|
-
|
|
18716
|
-
|
|
18717
|
-
|
|
18718
|
-
|
|
18943
|
+
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
18944
|
+
async getRequest(queryParams, token) {
|
|
18945
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18946
|
+
const options = token ? { token } : { limit };
|
|
18947
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
18948
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
18949
|
+
});
|
|
18950
|
+
return queryResponse;
|
|
18951
|
+
}
|
|
18952
|
+
}
|
|
18953
|
+
|
|
18954
|
+
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
18955
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18956
|
+
super(query, cacheKey);
|
|
18957
|
+
this.notifyChange = notifyChange;
|
|
18958
|
+
this.preparePayload = preparePayload;
|
|
18959
|
+
}
|
|
18960
|
+
async saveToMainDB(response) {
|
|
18961
|
+
const processedPayload = await this.preparePayload(response);
|
|
18962
|
+
const client = getActiveClient();
|
|
18963
|
+
const cachedAt = client.cache && Date.now();
|
|
18964
|
+
if (client.cache) {
|
|
18965
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
18966
|
+
}
|
|
18967
|
+
}
|
|
18968
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18969
|
+
var _a, _b;
|
|
18970
|
+
if (refresh) {
|
|
18971
|
+
pushToCache(this.cacheKey, {
|
|
18972
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18973
|
+
});
|
|
18974
|
+
}
|
|
18975
|
+
else {
|
|
18976
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18977
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18978
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
18979
|
+
...new Set([
|
|
18980
|
+
...communityUsers,
|
|
18981
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
18982
|
+
]),
|
|
18983
|
+
] }));
|
|
18984
|
+
}
|
|
18985
|
+
}
|
|
18986
|
+
reactor(action) {
|
|
18987
|
+
return (community, communityMembers) => {
|
|
18988
|
+
var _a;
|
|
18989
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18990
|
+
if (!collection)
|
|
18991
|
+
return;
|
|
18992
|
+
communityMembers.forEach(communityMember => {
|
|
18993
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
18994
|
+
communityId: this.query.communityId,
|
|
18995
|
+
userId: communityMember.userId,
|
|
18996
|
+
});
|
|
18997
|
+
if (communityMember.communityMembership === 'none') {
|
|
18998
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
18999
|
+
}
|
|
19000
|
+
});
|
|
19001
|
+
pushToCache(this.cacheKey, collection);
|
|
19002
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19003
|
+
};
|
|
19004
|
+
}
|
|
19005
|
+
subscribeRTE(createSubscriber) {
|
|
19006
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19007
|
+
}
|
|
19008
|
+
}
|
|
19009
|
+
|
|
19010
|
+
var EnumCommunityMemberActions;
|
|
19011
|
+
(function (EnumCommunityMemberActions) {
|
|
19012
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
19013
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
19014
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
19015
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
19016
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
19017
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
19018
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
19019
|
+
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
19020
|
+
|
|
19021
|
+
/* eslint-disable no-use-before-define */
|
|
19022
|
+
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
19023
|
+
constructor(query, callback) {
|
|
19024
|
+
const queryStreamId = hash__default["default"](query);
|
|
19025
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
19026
|
+
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
19027
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19028
|
+
this.query = query;
|
|
19029
|
+
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19030
|
+
this.callback = callback.bind(this);
|
|
19031
|
+
this.loadPage({ initial: true });
|
|
19032
|
+
}
|
|
19033
|
+
setup() {
|
|
19034
|
+
var _a;
|
|
19035
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19036
|
+
if (!collection) {
|
|
19037
|
+
pushToCache(this.cacheKey, {
|
|
19038
|
+
data: [],
|
|
19039
|
+
params: {},
|
|
19040
|
+
});
|
|
19041
|
+
}
|
|
19042
|
+
}
|
|
19043
|
+
async persistModel(queryPayload) {
|
|
19044
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
19045
|
+
}
|
|
19046
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
19047
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
19048
|
+
}
|
|
19049
|
+
startSubscription() {
|
|
19050
|
+
return this.queryStreamController.subscribeRTE([
|
|
19051
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
19052
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
19053
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
19054
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
19055
|
+
{
|
|
19056
|
+
fn: onCommunityUserRoleRemoved,
|
|
19057
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
19058
|
+
},
|
|
19059
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
19060
|
+
]);
|
|
19061
|
+
}
|
|
19062
|
+
notifyChange({ origin, loading, error }) {
|
|
19063
|
+
var _a, _b;
|
|
19064
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19065
|
+
if (!collection)
|
|
19066
|
+
return;
|
|
19067
|
+
const data = this.applyFilter((_b = collection.data
|
|
19068
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19069
|
+
.filter(isNonNullable)
|
|
19070
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19071
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
19072
|
+
return;
|
|
19073
|
+
this.callback({
|
|
19074
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
19075
|
+
data,
|
|
19076
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
19077
|
+
loading,
|
|
19078
|
+
error,
|
|
19079
|
+
});
|
|
19080
|
+
}
|
|
19081
|
+
applyFilter(data) {
|
|
19082
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
19083
|
+
if (this.query.memberships) {
|
|
19084
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
19085
|
+
const memberships = this.query.memberships || [];
|
|
19086
|
+
return memberships.includes(communityMembership);
|
|
19087
|
+
});
|
|
19088
|
+
}
|
|
19089
|
+
if (this.query.search) {
|
|
19090
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
19091
|
+
}
|
|
19092
|
+
return communityMembers;
|
|
19093
|
+
}
|
|
19094
|
+
}
|
|
19095
|
+
|
|
19096
|
+
/* begin_public_function
|
|
19097
|
+
id: community.membership.query
|
|
19098
|
+
*/
|
|
19099
|
+
/**
|
|
19100
|
+
* ```js
|
|
19101
|
+
* import { searchMembers } from '@amityco/ts-sdk-react-native'
|
|
19102
|
+
*
|
|
19103
|
+
* let communityMembers = []
|
|
19104
|
+
* const unsub = searchMembers({
|
|
19105
|
+
* communityId: Amity.Community['communityId'],
|
|
19106
|
+
* }, response => merge(communityMembers, response.data))
|
|
19107
|
+
* ```
|
|
19108
|
+
*
|
|
19109
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
19110
|
+
*
|
|
19111
|
+
* @param params for querying community users
|
|
19112
|
+
* @param callback the function to call when new data are available
|
|
19113
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
19114
|
+
*
|
|
19115
|
+
* @category Community Live Collection
|
|
19116
|
+
*/
|
|
19117
|
+
const searchMembers = (params, callback, config) => {
|
|
19118
|
+
const { log, cache } = getActiveClient();
|
|
19119
|
+
if (!cache) {
|
|
19120
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
19121
|
+
}
|
|
19122
|
+
const timestamp = Date.now();
|
|
19123
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
19124
|
+
const searchCommunityMemberLiveCollection = new SearchCommunityMembersLiveCollectionController(params, resp => {
|
|
19125
|
+
callback(resp);
|
|
18719
19126
|
});
|
|
18720
|
-
const
|
|
18721
|
-
const
|
|
18722
|
-
|
|
18723
|
-
|
|
18724
|
-
|
|
18725
|
-
|
|
18726
|
-
|
|
18727
|
-
|
|
19127
|
+
const disposers = searchCommunityMemberLiveCollection.startSubscription();
|
|
19128
|
+
const cacheKey = searchCommunityMemberLiveCollection.getCacheKey();
|
|
19129
|
+
disposers.push(() => {
|
|
19130
|
+
dropFromCache(cacheKey);
|
|
19131
|
+
});
|
|
19132
|
+
return () => {
|
|
19133
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
19134
|
+
disposers.forEach(fn => fn());
|
|
19135
|
+
};
|
|
19136
|
+
};
|
|
19137
|
+
/* end_public_function */
|
|
19138
|
+
|
|
19139
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
19140
|
+
__proto__: null,
|
|
19141
|
+
addMembers: addMembers,
|
|
19142
|
+
removeMembers: removeMembers,
|
|
19143
|
+
applyFilter: applyFilter,
|
|
19144
|
+
getMembers: getMembers,
|
|
19145
|
+
searchMembers: searchMembers,
|
|
19146
|
+
onCommunityUserAdded: onCommunityUserAdded,
|
|
19147
|
+
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
19148
|
+
onCommunityUserBanned: onCommunityUserBanned,
|
|
19149
|
+
onCommunityUserChanged: onCommunityUserChanged,
|
|
19150
|
+
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
19151
|
+
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
19152
|
+
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
19153
|
+
onCommunityJoined: onCommunityJoined,
|
|
19154
|
+
onCommunityLeft: onCommunityLeft
|
|
19155
|
+
});
|
|
19156
|
+
|
|
19157
|
+
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
19158
|
+
constructor(query, callback) {
|
|
19159
|
+
const queryStreamId = hash__default["default"](query);
|
|
19160
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
19161
|
+
const paginationController = new CommunitiesPaginationController$1(query);
|
|
19162
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19163
|
+
this.query = query;
|
|
19164
|
+
this.queryStreamController = new CommunitiesQueryStreamController$1(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19165
|
+
this.callback = callback.bind(this);
|
|
19166
|
+
this.loadPage({ initial: true });
|
|
18728
19167
|
}
|
|
18729
|
-
|
|
18730
|
-
|
|
19168
|
+
setup() {
|
|
19169
|
+
var _a;
|
|
19170
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19171
|
+
if (!collection) {
|
|
19172
|
+
pushToCache(this.cacheKey, {
|
|
19173
|
+
data: [],
|
|
19174
|
+
params: {},
|
|
19175
|
+
});
|
|
19176
|
+
}
|
|
19177
|
+
}
|
|
19178
|
+
async persistModel(queryPayload) {
|
|
19179
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
19180
|
+
}
|
|
19181
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
19182
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
19183
|
+
}
|
|
19184
|
+
startSubscription() {
|
|
19185
|
+
return this.queryStreamController.subscribeRTE([
|
|
19186
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
19187
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
19188
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
19189
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
19190
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
19191
|
+
]);
|
|
19192
|
+
}
|
|
19193
|
+
notifyChange({ origin, loading, error }) {
|
|
19194
|
+
var _a, _b;
|
|
19195
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19196
|
+
if (!collection)
|
|
19197
|
+
return;
|
|
19198
|
+
const data = this.applyFilter((_b = collection.data
|
|
19199
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
19200
|
+
.filter(Boolean)
|
|
19201
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19202
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
19203
|
+
return;
|
|
19204
|
+
this.callback({
|
|
19205
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
19206
|
+
data,
|
|
19207
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
19208
|
+
loading,
|
|
19209
|
+
error,
|
|
19210
|
+
});
|
|
19211
|
+
}
|
|
19212
|
+
applyFilter(data) {
|
|
19213
|
+
const { userId } = getActiveClient();
|
|
19214
|
+
let communities = data;
|
|
19215
|
+
if (this.query.includeDeleted) {
|
|
19216
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
19217
|
+
}
|
|
19218
|
+
if (this.query.categoryId) {
|
|
19219
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
19220
|
+
}
|
|
19221
|
+
if (this.query.tags) {
|
|
19222
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
19223
|
+
}
|
|
19224
|
+
if (this.query.membership && userId) {
|
|
19225
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
19226
|
+
}
|
|
19227
|
+
return communities;
|
|
19228
|
+
}
|
|
19229
|
+
}
|
|
18731
19230
|
|
|
18732
19231
|
/* begin_public_function
|
|
18733
19232
|
id: community.query
|
|
@@ -18737,7 +19236,7 @@ const queryCommunities = async (query) => {
|
|
|
18737
19236
|
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
18738
19237
|
*
|
|
18739
19238
|
* let communities = []
|
|
18740
|
-
* const unsub = CommunityRepository.
|
|
19239
|
+
* const unsub = CommunityRepository.searchCommunities({
|
|
18741
19240
|
* displayName: Amity.Community['displayName'],
|
|
18742
19241
|
* }, response => merge(communities, response.data))
|
|
18743
19242
|
* ```
|
|
@@ -18750,99 +19249,217 @@ const queryCommunities = async (query) => {
|
|
|
18750
19249
|
*
|
|
18751
19250
|
* @category Community Live Collection
|
|
18752
19251
|
*/
|
|
18753
|
-
const
|
|
18754
|
-
const { log, cache
|
|
19252
|
+
const searchCommunities = (params, callback, config) => {
|
|
19253
|
+
const { log, cache } = getActiveClient();
|
|
18755
19254
|
if (!cache) {
|
|
18756
19255
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
18757
19256
|
}
|
|
18758
19257
|
const timestamp = Date.now();
|
|
18759
|
-
log(`
|
|
18760
|
-
const
|
|
18761
|
-
const
|
|
18762
|
-
const
|
|
18763
|
-
|
|
18764
|
-
|
|
18765
|
-
|
|
19258
|
+
log(`searchCommunities(tmpid: ${timestamp}) > listen`);
|
|
19259
|
+
const searchCommunitiesLiveCollection = new SearchCommunityLiveCollectionController(params, callback);
|
|
19260
|
+
const disposers = searchCommunitiesLiveCollection.startSubscription();
|
|
19261
|
+
const cacheKey = searchCommunitiesLiveCollection.getCacheKey();
|
|
19262
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
19263
|
+
return () => {
|
|
19264
|
+
log(`searchCommunities(tmpid: ${timestamp}) > dispose`);
|
|
19265
|
+
disposers.forEach(fn => fn());
|
|
19266
|
+
};
|
|
19267
|
+
};
|
|
19268
|
+
/* end_public_function */
|
|
19269
|
+
|
|
19270
|
+
/**
|
|
19271
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
19272
|
+
* TODO: check if querybyIds is supported
|
|
19273
|
+
*/
|
|
19274
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
19275
|
+
async getRequest(queryParams, token) {
|
|
19276
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19277
|
+
const options = token ? { token } : { limit };
|
|
19278
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
19279
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
19280
|
+
});
|
|
19281
|
+
return queryResponse;
|
|
19282
|
+
}
|
|
19283
|
+
}
|
|
19284
|
+
|
|
19285
|
+
var EnumCommunityActions;
|
|
19286
|
+
(function (EnumCommunityActions) {
|
|
19287
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
19288
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
19289
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
19290
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
19291
|
+
|
|
19292
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
19293
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
19294
|
+
super(query, cacheKey);
|
|
19295
|
+
this.notifyChange = notifyChange;
|
|
19296
|
+
this.preparePayload = preparePayload;
|
|
19297
|
+
}
|
|
19298
|
+
async saveToMainDB(response) {
|
|
19299
|
+
const processedPayload = await this.preparePayload(response);
|
|
19300
|
+
const client = getActiveClient();
|
|
19301
|
+
const cachedAt = client.cache && Date.now();
|
|
19302
|
+
if (client.cache) {
|
|
19303
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
19304
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
19305
|
+
}
|
|
19306
|
+
}
|
|
19307
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
18766
19308
|
var _a, _b;
|
|
18767
|
-
|
|
18768
|
-
.
|
|
19309
|
+
if (refresh) {
|
|
19310
|
+
pushToCache(this.cacheKey, {
|
|
19311
|
+
data: response.communities.map(getResolver('community')),
|
|
19312
|
+
});
|
|
19313
|
+
}
|
|
19314
|
+
else {
|
|
19315
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19316
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19317
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
19318
|
+
}
|
|
19319
|
+
}
|
|
19320
|
+
reactor(action) {
|
|
19321
|
+
return (community) => {
|
|
19322
|
+
var _a;
|
|
19323
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19324
|
+
if (!collection)
|
|
19325
|
+
return;
|
|
19326
|
+
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
19327
|
+
return;
|
|
19328
|
+
}
|
|
19329
|
+
/*
|
|
19330
|
+
* Simply update a collection and let responder decide what to do with data
|
|
19331
|
+
*/
|
|
19332
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
19333
|
+
pushToCache(this.cacheKey, collection);
|
|
19334
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19335
|
+
};
|
|
19336
|
+
}
|
|
19337
|
+
subscribeRTE(createSubscriber) {
|
|
19338
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19339
|
+
}
|
|
19340
|
+
}
|
|
19341
|
+
|
|
19342
|
+
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
19343
|
+
constructor(query, callback) {
|
|
19344
|
+
const queryStreamId = hash__default["default"](query);
|
|
19345
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
19346
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
19347
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19348
|
+
this.query = query;
|
|
19349
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19350
|
+
this.callback = callback.bind(this);
|
|
19351
|
+
this.loadPage({ initial: true });
|
|
19352
|
+
}
|
|
19353
|
+
setup() {
|
|
19354
|
+
var _a;
|
|
19355
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19356
|
+
if (!collection) {
|
|
19357
|
+
pushToCache(this.cacheKey, {
|
|
19358
|
+
data: [],
|
|
19359
|
+
params: {},
|
|
19360
|
+
});
|
|
19361
|
+
}
|
|
19362
|
+
}
|
|
19363
|
+
async persistModel(queryPayload) {
|
|
19364
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
19365
|
+
}
|
|
19366
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
19367
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
19368
|
+
}
|
|
19369
|
+
startSubscription() {
|
|
19370
|
+
return this.queryStreamController.subscribeRTE([
|
|
19371
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
19372
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
19373
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
19374
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
19375
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
19376
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
19377
|
+
]);
|
|
19378
|
+
}
|
|
19379
|
+
notifyChange({ origin, loading, error }) {
|
|
19380
|
+
var _a, _b;
|
|
19381
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19382
|
+
if (!collection)
|
|
19383
|
+
return;
|
|
19384
|
+
const data = this.applyFilter((_b = collection.data
|
|
19385
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
18769
19386
|
.filter(Boolean)
|
|
18770
|
-
.map(({ data }) => data)) !== null &&
|
|
18771
|
-
|
|
18772
|
-
|
|
19387
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19388
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
19389
|
+
return;
|
|
19390
|
+
this.callback({
|
|
19391
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
19392
|
+
data,
|
|
19393
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
19394
|
+
loading,
|
|
19395
|
+
error,
|
|
19396
|
+
});
|
|
19397
|
+
}
|
|
19398
|
+
applyFilter(data) {
|
|
19399
|
+
const { userId } = getActiveClient();
|
|
19400
|
+
let communities = data;
|
|
19401
|
+
if (this.query.includeDeleted) {
|
|
18773
19402
|
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18774
19403
|
}
|
|
18775
|
-
if (
|
|
18776
|
-
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(
|
|
18777
|
-
}
|
|
18778
|
-
if (params.tags) {
|
|
18779
|
-
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
19404
|
+
if (this.query.categoryId) {
|
|
19405
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
18780
19406
|
}
|
|
18781
|
-
if (
|
|
18782
|
-
communities =
|
|
19407
|
+
if (this.query.tags) {
|
|
19408
|
+
communities = communities.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = this.query.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
18783
19409
|
}
|
|
18784
|
-
|
|
18785
|
-
|
|
18786
|
-
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
19410
|
+
if (this.query.membership && userId) {
|
|
19411
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
18787
19412
|
}
|
|
18788
|
-
|
|
18789
|
-
|
|
18790
|
-
|
|
18791
|
-
|
|
18792
|
-
|
|
18793
|
-
|
|
18794
|
-
|
|
18795
|
-
|
|
18796
|
-
|
|
18797
|
-
|
|
18798
|
-
|
|
18799
|
-
|
|
19413
|
+
if (!this.query.displayName) {
|
|
19414
|
+
const sortFn = (() => {
|
|
19415
|
+
switch (this.query.sortBy) {
|
|
19416
|
+
case 'firstCreated':
|
|
19417
|
+
return sortByFirstCreated;
|
|
19418
|
+
case 'lastCreated':
|
|
19419
|
+
return sortByLastCreated;
|
|
19420
|
+
case 'displayName':
|
|
19421
|
+
return sortByDisplayName;
|
|
19422
|
+
default:
|
|
19423
|
+
return sortByLastCreated;
|
|
19424
|
+
}
|
|
19425
|
+
})();
|
|
19426
|
+
communities = communities.sort(sortFn);
|
|
18800
19427
|
}
|
|
18801
|
-
|
|
18802
|
-
|
|
18803
|
-
|
|
18804
|
-
|
|
18805
|
-
|
|
18806
|
-
|
|
18807
|
-
|
|
18808
|
-
|
|
18809
|
-
|
|
18810
|
-
|
|
18811
|
-
|
|
18812
|
-
|
|
18813
|
-
|
|
18814
|
-
|
|
18815
|
-
|
|
18816
|
-
|
|
18817
|
-
|
|
18818
|
-
|
|
18819
|
-
|
|
18820
|
-
|
|
18821
|
-
|
|
18822
|
-
|
|
18823
|
-
|
|
18824
|
-
|
|
18825
|
-
|
|
18826
|
-
|
|
18827
|
-
|
|
18828
|
-
|
|
18829
|
-
|
|
18830
|
-
|
|
18831
|
-
|
|
18832
|
-
|
|
18833
|
-
|
|
18834
|
-
|
|
18835
|
-
|
|
18836
|
-
data.data = initial
|
|
18837
|
-
? result.map(getResolver('community'))
|
|
18838
|
-
: [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
18839
|
-
}
|
|
18840
|
-
pushToCache(cacheKey, data);
|
|
18841
|
-
responder(data);
|
|
18842
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
18843
|
-
};
|
|
18844
|
-
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
18845
|
-
onFetch(true);
|
|
19428
|
+
return communities;
|
|
19429
|
+
}
|
|
19430
|
+
}
|
|
19431
|
+
|
|
19432
|
+
/* begin_public_function
|
|
19433
|
+
id: community.query
|
|
19434
|
+
*/
|
|
19435
|
+
/**
|
|
19436
|
+
* ```js
|
|
19437
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
19438
|
+
*
|
|
19439
|
+
* let communities = []
|
|
19440
|
+
* const unsub = CommunityRepository.getCommunities({
|
|
19441
|
+
* displayName: Amity.Community['displayName'],
|
|
19442
|
+
* }, response => merge(communities, response.data))
|
|
19443
|
+
* ```
|
|
19444
|
+
*
|
|
19445
|
+
* Observe all mutations on a list of {@link Amity.Community}s
|
|
19446
|
+
*
|
|
19447
|
+
* @param params for querying communities
|
|
19448
|
+
* @param callback the function to call when new data are available
|
|
19449
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the communities
|
|
19450
|
+
*
|
|
19451
|
+
* @category Community Live Collection
|
|
19452
|
+
*/
|
|
19453
|
+
const getCommunities = (params, callback, config) => {
|
|
19454
|
+
const { log, cache } = getActiveClient();
|
|
19455
|
+
if (!cache) {
|
|
19456
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
19457
|
+
}
|
|
19458
|
+
const timestamp = Date.now();
|
|
19459
|
+
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
19460
|
+
const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
|
|
19461
|
+
const disposers = communitiesLiveCollection.startSubscription();
|
|
19462
|
+
const cacheKey = communitiesLiveCollection.getCacheKey();
|
|
18846
19463
|
disposers.push(() => dropFromCache(cacheKey));
|
|
18847
19464
|
return () => {
|
|
18848
19465
|
log(`getCommunities(tmpid: ${timestamp}) > dispose`);
|
|
@@ -19300,7 +19917,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
19300
19917
|
};
|
|
19301
19918
|
/* end_public_function */
|
|
19302
19919
|
|
|
19303
|
-
var index$
|
|
19920
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
19304
19921
|
__proto__: null,
|
|
19305
19922
|
addRoles: addRoles,
|
|
19306
19923
|
removeRoles: removeRoles,
|
|
@@ -19308,299 +19925,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
19308
19925
|
unbanMembers: unbanMembers
|
|
19309
19926
|
});
|
|
19310
19927
|
|
|
19311
|
-
/* begin_public_function
|
|
19312
|
-
id: community.membership.add_members
|
|
19313
|
-
*/
|
|
19314
|
-
/**
|
|
19315
|
-
* ```js
|
|
19316
|
-
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
19317
|
-
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
19318
|
-
* ```
|
|
19319
|
-
*
|
|
19320
|
-
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
19321
|
-
*
|
|
19322
|
-
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
19323
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
19324
|
-
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
19325
|
-
*
|
|
19326
|
-
* @category Community API
|
|
19327
|
-
* @async
|
|
19328
|
-
*/
|
|
19329
|
-
const addMembers = async (communityId, userIds) => {
|
|
19330
|
-
const client = getActiveClient();
|
|
19331
|
-
client.log('community/moderation/addMembers', communityId, userIds);
|
|
19332
|
-
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
19333
|
-
fireEvent('community.userAdded', payload);
|
|
19334
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
19335
|
-
if (client.cache)
|
|
19336
|
-
ingestInCache(data);
|
|
19337
|
-
const { communityUsers } = data;
|
|
19338
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
19339
|
-
};
|
|
19340
|
-
/* end_public_function */
|
|
19341
|
-
|
|
19342
|
-
/* begin_public_function
|
|
19343
|
-
id: community.membership.remove_member
|
|
19344
|
-
*/
|
|
19345
|
-
/**
|
|
19346
|
-
* ```js
|
|
19347
|
-
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
19348
|
-
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
19349
|
-
* ```
|
|
19350
|
-
*
|
|
19351
|
-
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
19352
|
-
*
|
|
19353
|
-
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
19354
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
19355
|
-
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
19356
|
-
*
|
|
19357
|
-
* @category Community API
|
|
19358
|
-
* @async
|
|
19359
|
-
*/
|
|
19360
|
-
const removeMembers = async (communityId, userIds) => {
|
|
19361
|
-
const client = getActiveClient();
|
|
19362
|
-
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
19363
|
-
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
19364
|
-
fireEvent('community.userRemoved', payload);
|
|
19365
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
19366
|
-
if (client.cache)
|
|
19367
|
-
ingestInCache(data);
|
|
19368
|
-
const { communityUsers } = data;
|
|
19369
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
19370
|
-
};
|
|
19371
|
-
/* end_public_function */
|
|
19372
|
-
|
|
19373
|
-
/**
|
|
19374
|
-
* ```js
|
|
19375
|
-
* import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
|
|
19376
|
-
* const communityMembers = await queryCommunityMembers({ communityId: 'foo' })
|
|
19377
|
-
* ```
|
|
19378
|
-
*
|
|
19379
|
-
* Queries a paginable list of {@link Amity.CommunityUser} objects
|
|
19380
|
-
*
|
|
19381
|
-
* @param query The query parameters
|
|
19382
|
-
* @returns A page of {@link Amity.CommunityUser} objects
|
|
19383
|
-
*
|
|
19384
|
-
* @category Community API
|
|
19385
|
-
* @async
|
|
19386
|
-
* */
|
|
19387
|
-
const queryCommunityMembers = async (query) => {
|
|
19388
|
-
const client = getActiveClient();
|
|
19389
|
-
client.log('community/queryCommunityMembers', query);
|
|
19390
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
|
|
19391
|
-
const options = (() => {
|
|
19392
|
-
if (page)
|
|
19393
|
-
return { token: page };
|
|
19394
|
-
if (limit)
|
|
19395
|
-
return { limit };
|
|
19396
|
-
return undefined;
|
|
19397
|
-
})();
|
|
19398
|
-
const { data: queryPayload } = await client.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
19399
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
19400
|
-
});
|
|
19401
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
19402
|
-
const preparedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
19403
|
-
const { communityUsers } = preparedPayload;
|
|
19404
|
-
const cachedAt = client.cache && Date.now();
|
|
19405
|
-
if (client.cache) {
|
|
19406
|
-
ingestInCache(preparedPayload, { cachedAt });
|
|
19407
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
19408
|
-
pushToCache(cacheKey, {
|
|
19409
|
-
communityUsers: communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19410
|
-
paging,
|
|
19411
|
-
});
|
|
19412
|
-
}
|
|
19413
|
-
return { data: communityUsers, cachedAt, paging };
|
|
19414
|
-
};
|
|
19415
|
-
/**
|
|
19416
|
-
* ```js
|
|
19417
|
-
* import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
|
|
19418
|
-
* const communityMembers = await queryCommunityMembers(query)
|
|
19419
|
-
* ```
|
|
19420
|
-
*
|
|
19421
|
-
* Queries a paginable list of {@link Amity.InternalPost} objects from cache
|
|
19422
|
-
*
|
|
19423
|
-
* @param query The query parameters
|
|
19424
|
-
* @returns posts
|
|
19425
|
-
*
|
|
19426
|
-
* @category Post API
|
|
19427
|
-
*/
|
|
19428
|
-
queryCommunityMembers.locally = (query) => {
|
|
19429
|
-
var _a, _b;
|
|
19430
|
-
const client = getActiveClient();
|
|
19431
|
-
client.log('community/queryCommunityMembers', query);
|
|
19432
|
-
if (!client.cache)
|
|
19433
|
-
return;
|
|
19434
|
-
const _c = query !== null && query !== void 0 ? query : {}, { page, limit } = _c, params = __rest(_c, ["page", "limit"]);
|
|
19435
|
-
const options = (() => {
|
|
19436
|
-
if (page)
|
|
19437
|
-
return { token: page };
|
|
19438
|
-
if (limit)
|
|
19439
|
-
return { limit };
|
|
19440
|
-
return undefined;
|
|
19441
|
-
})();
|
|
19442
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
19443
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
19444
|
-
if (!(data === null || data === void 0 ? void 0 : data.communityUsers.length))
|
|
19445
|
-
return;
|
|
19446
|
-
const communityUsers = data.communityUsers
|
|
19447
|
-
.map(key => pullFromCache(['communityUsers', 'get', key]))
|
|
19448
|
-
.filter(Boolean)
|
|
19449
|
-
.map(({ data }) => data);
|
|
19450
|
-
const { paging } = data;
|
|
19451
|
-
return communityUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.communityUsers) === null || _b === void 0 ? void 0 : _b.length)
|
|
19452
|
-
? { data: communityUsers, cachedAt, paging }
|
|
19453
|
-
: undefined;
|
|
19454
|
-
};
|
|
19455
|
-
|
|
19456
|
-
/*
|
|
19457
|
-
* Exported for testing
|
|
19458
|
-
* @hidden
|
|
19459
|
-
*/
|
|
19460
|
-
const applyFilter = (data, params) => {
|
|
19461
|
-
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
19462
|
-
if (params.memberships) {
|
|
19463
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
19464
|
-
const membership = params.memberships;
|
|
19465
|
-
return membership.includes(communityMembership);
|
|
19466
|
-
});
|
|
19467
|
-
}
|
|
19468
|
-
if (params.search) {
|
|
19469
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
19470
|
-
}
|
|
19471
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
19472
|
-
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
19473
|
-
return communityMembers;
|
|
19474
|
-
};
|
|
19475
|
-
/* begin_public_function
|
|
19476
|
-
id: community.membership.query
|
|
19477
|
-
*/
|
|
19478
|
-
/**
|
|
19479
|
-
* ```js
|
|
19480
|
-
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
19481
|
-
*
|
|
19482
|
-
* let communityMembers = []
|
|
19483
|
-
* const unsub = getMembers({
|
|
19484
|
-
* communityId: Amity.Community['communityId'],
|
|
19485
|
-
* }, response => merge(communityMembers, response.data))
|
|
19486
|
-
* ```
|
|
19487
|
-
*
|
|
19488
|
-
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
19489
|
-
*
|
|
19490
|
-
* @param params for querying community users
|
|
19491
|
-
* @param callback the function to call when new data are available
|
|
19492
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
19493
|
-
*
|
|
19494
|
-
* @category Community Live Collection
|
|
19495
|
-
*/
|
|
19496
|
-
const getMembers = (params, callback, config) => {
|
|
19497
|
-
const { log, cache } = getActiveClient();
|
|
19498
|
-
if (!cache) {
|
|
19499
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
19500
|
-
}
|
|
19501
|
-
const timestamp = Date.now();
|
|
19502
|
-
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
19503
|
-
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
19504
|
-
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
19505
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
19506
|
-
const disposers = [];
|
|
19507
|
-
const cacheKey = ['communityUsers', 'collection', queryParams];
|
|
19508
|
-
const cacheByCommunityIdKey = [
|
|
19509
|
-
'communityUsers',
|
|
19510
|
-
'collection',
|
|
19511
|
-
{ communityId: params.communityId },
|
|
19512
|
-
];
|
|
19513
|
-
const responder = (data, isEventModel = false) => {
|
|
19514
|
-
var _a, _b;
|
|
19515
|
-
const communityMembers = (_a = data.data
|
|
19516
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19517
|
-
.filter(Boolean)
|
|
19518
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
19519
|
-
callback({
|
|
19520
|
-
onNextPage: onFetch,
|
|
19521
|
-
data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
|
|
19522
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
19523
|
-
loading: data.loading,
|
|
19524
|
-
error: data.error,
|
|
19525
|
-
});
|
|
19526
|
-
};
|
|
19527
|
-
const realtimeRouter = (_) => (_, communityMembers) => {
|
|
19528
|
-
var _a;
|
|
19529
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19530
|
-
if (!collection) {
|
|
19531
|
-
return;
|
|
19532
|
-
}
|
|
19533
|
-
const communityMemberCacheIds = communityMembers
|
|
19534
|
-
.map(communityMember => {
|
|
19535
|
-
if (params.communityId !== communityMember.communityId) {
|
|
19536
|
-
return;
|
|
19537
|
-
}
|
|
19538
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
19539
|
-
communityId: params.communityId,
|
|
19540
|
-
userId: communityMember.userId,
|
|
19541
|
-
});
|
|
19542
|
-
return communityMemberCacheId;
|
|
19543
|
-
})
|
|
19544
|
-
.filter(isNonNullable);
|
|
19545
|
-
collection.data = [...new Set([...communityMemberCacheIds, ...collection.data])];
|
|
19546
|
-
pushToCache(cacheKey, collection);
|
|
19547
|
-
pushToCache(cacheByCommunityIdKey, collection);
|
|
19548
|
-
responder(collection, true);
|
|
19549
|
-
};
|
|
19550
|
-
const onFetch = (initial = false) => {
|
|
19551
|
-
var _a, _b;
|
|
19552
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19553
|
-
const communityMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19554
|
-
if (!initial && communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
19555
|
-
return;
|
|
19556
|
-
const query = createQuery(queryCommunityMembers, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
19557
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
19558
|
-
const data = {
|
|
19559
|
-
loading,
|
|
19560
|
-
error,
|
|
19561
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
19562
|
-
data: communityMembers,
|
|
19563
|
-
};
|
|
19564
|
-
if (result) {
|
|
19565
|
-
data.data = [
|
|
19566
|
-
...new Set([...communityMembers, ...result.map(getResolver('communityUsers'))]),
|
|
19567
|
-
];
|
|
19568
|
-
}
|
|
19569
|
-
pushToCache(cacheKey, data);
|
|
19570
|
-
pushToCache(cacheByCommunityIdKey, data);
|
|
19571
|
-
responder(data);
|
|
19572
|
-
}, queryOptions(policy));
|
|
19573
|
-
};
|
|
19574
|
-
disposers.push(onCommunityLeft(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityUserBanned(realtimeRouter()), onCommunityUserUnbanned(realtimeRouter()), onCommunityUserChanged(realtimeRouter()), onCommunityUserRoleAdded(realtimeRouter()), onCommunityUserRoleRemoved(realtimeRouter()));
|
|
19575
|
-
onFetch(true);
|
|
19576
|
-
return () => {
|
|
19577
|
-
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
19578
|
-
disposers.forEach(fn => fn());
|
|
19579
|
-
};
|
|
19580
|
-
};
|
|
19581
|
-
/* end_public_function */
|
|
19582
|
-
|
|
19583
|
-
var index$9 = /*#__PURE__*/Object.freeze({
|
|
19584
|
-
__proto__: null,
|
|
19585
|
-
addMembers: addMembers,
|
|
19586
|
-
removeMembers: removeMembers,
|
|
19587
|
-
applyFilter: applyFilter,
|
|
19588
|
-
getMembers: getMembers,
|
|
19589
|
-
onCommunityUserAdded: onCommunityUserAdded,
|
|
19590
|
-
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
19591
|
-
onCommunityUserBanned: onCommunityUserBanned,
|
|
19592
|
-
onCommunityUserChanged: onCommunityUserChanged,
|
|
19593
|
-
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
19594
|
-
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
19595
|
-
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
19596
|
-
onCommunityJoined: onCommunityJoined,
|
|
19597
|
-
onCommunityLeft: onCommunityLeft
|
|
19598
|
-
});
|
|
19599
|
-
|
|
19600
19928
|
var index$8 = /*#__PURE__*/Object.freeze({
|
|
19601
19929
|
__proto__: null,
|
|
19602
|
-
Moderation: index$
|
|
19603
|
-
Membership: index$
|
|
19930
|
+
Moderation: index$9,
|
|
19931
|
+
Membership: index$a,
|
|
19604
19932
|
getCommunityByIds: getCommunities$1,
|
|
19605
19933
|
createCommunity: createCommunity,
|
|
19606
19934
|
updateCommunity: updateCommunity,
|