@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.esm.js
CHANGED
|
@@ -83,8 +83,8 @@ const PostContentType = Object.freeze({
|
|
|
83
83
|
|
|
84
84
|
function getVersion() {
|
|
85
85
|
try {
|
|
86
|
-
// the string ''v6.24.
|
|
87
|
-
return 'v6.24.
|
|
86
|
+
// the string ''v6.24.1-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
87
|
+
return 'v6.24.1-esm';
|
|
88
88
|
}
|
|
89
89
|
catch (error) {
|
|
90
90
|
return '__dev__';
|
|
@@ -24776,7 +24776,8 @@ const registerEventListeners = () => {
|
|
|
24776
24776
|
events.push("resume" /* Amity.MarkerSyncEvent.RESUME */);
|
|
24777
24777
|
}), onMessageCreatedMqtt(message => {
|
|
24778
24778
|
// only conversation, community and broadcast types can sync
|
|
24779
|
-
|
|
24779
|
+
const client = getActiveClient();
|
|
24780
|
+
if (isUnreadCountSupport(message) && message.creatorId !== client.userId)
|
|
24780
24781
|
events.push("new message" /* Amity.MarkerSyncEvent.NEW_MESSAGE */);
|
|
24781
24782
|
}), 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(() =>
|
|
24782
24783
|
/*
|
|
@@ -25177,7 +25178,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
25177
25178
|
*/
|
|
25178
25179
|
/**
|
|
25179
25180
|
* ```js
|
|
25180
|
-
* import { Client } from '@amityco/ts-sdk'
|
|
25181
|
+
* import { Client } from '@amityco/ts-sdk-react-native'
|
|
25181
25182
|
* const success = await Client.secureLogout()
|
|
25182
25183
|
* ```
|
|
25183
25184
|
*
|
|
@@ -25533,6 +25534,9 @@ function isEqual(x, y) {
|
|
|
25533
25534
|
}));
|
|
25534
25535
|
}
|
|
25535
25536
|
|
|
25537
|
+
/**
|
|
25538
|
+
* @deprecated This function is deprecated
|
|
25539
|
+
*/
|
|
25536
25540
|
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
25537
25541
|
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
25538
25542
|
const { cache } = getActiveClient();
|
|
@@ -27883,8 +27887,10 @@ getFile.locally = (fileId) => {
|
|
|
27883
27887
|
const uploadFile = async (formData, onProgress) => {
|
|
27884
27888
|
const client = getActiveClient();
|
|
27885
27889
|
client.log('file/uploadFile', formData);
|
|
27886
|
-
|
|
27890
|
+
const files = formData.getAll('files');
|
|
27891
|
+
if (!files.length)
|
|
27887
27892
|
throw new Error('The formData object must have a `files` key.');
|
|
27893
|
+
formData.append('preferredFilename', files[0].name);
|
|
27888
27894
|
const headers = 'getHeaders' in formData
|
|
27889
27895
|
? formData.getHeaders()
|
|
27890
27896
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -27966,8 +27972,10 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
27966
27972
|
const uploadVideo = async (formData, feedType, onProgress) => {
|
|
27967
27973
|
const client = getActiveClient();
|
|
27968
27974
|
client.log('file/uploadVideo', formData);
|
|
27969
|
-
|
|
27975
|
+
const files = formData.getAll('files');
|
|
27976
|
+
if (!files.length)
|
|
27970
27977
|
throw new Error('The formData object must have a `files` key.');
|
|
27978
|
+
formData.append('preferredFilename', files[0].name);
|
|
27971
27979
|
if (feedType) {
|
|
27972
27980
|
formData.append('feedType', feedType);
|
|
27973
27981
|
}
|
|
@@ -28013,8 +28021,10 @@ const uploadVideo = async (formData, feedType, onProgress) => {
|
|
|
28013
28021
|
const uploadImage = async (formData, onProgress) => {
|
|
28014
28022
|
const client = getActiveClient();
|
|
28015
28023
|
client.log('file/uploadImage', formData);
|
|
28016
|
-
|
|
28024
|
+
const files = formData.getAll('files');
|
|
28025
|
+
if (!files.length)
|
|
28017
28026
|
throw new Error('The formData object must have a `files` key.');
|
|
28027
|
+
formData.append('preferredFilename', files[0].name);
|
|
28018
28028
|
const headers = 'getHeaders' in formData
|
|
28019
28029
|
? formData.getHeaders()
|
|
28020
28030
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -28054,8 +28064,10 @@ const uploadImage = async (formData, onProgress) => {
|
|
|
28054
28064
|
const createImage = async (formData, onProgress) => {
|
|
28055
28065
|
const client = getActiveClient();
|
|
28056
28066
|
client.log('file/createImage', formData);
|
|
28057
|
-
|
|
28067
|
+
const files = formData.getAll('files');
|
|
28068
|
+
if (!files.length)
|
|
28058
28069
|
throw new Error('The formData object must have a `files` key.');
|
|
28070
|
+
formData.append('preferredFilename', files[0].name);
|
|
28059
28071
|
const headers = 'getHeaders' in formData
|
|
28060
28072
|
? formData.getHeaders()
|
|
28061
28073
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -28095,8 +28107,10 @@ const createImage = async (formData, onProgress) => {
|
|
|
28095
28107
|
const createFile = async (formData, onProgress) => {
|
|
28096
28108
|
const client = getActiveClient();
|
|
28097
28109
|
client.log('file/createFile', formData);
|
|
28098
|
-
|
|
28110
|
+
const files = formData.getAll('files');
|
|
28111
|
+
if (!files.length)
|
|
28099
28112
|
throw new Error('The formData object must have a `files` key.');
|
|
28113
|
+
formData.append('preferredFilename', files[0].name);
|
|
28100
28114
|
const headers = 'getHeaders' in formData
|
|
28101
28115
|
? formData.getHeaders()
|
|
28102
28116
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -28136,8 +28150,10 @@ const createFile = async (formData, onProgress) => {
|
|
|
28136
28150
|
const createVideo = async (formData, feedType, onProgress) => {
|
|
28137
28151
|
const client = getActiveClient();
|
|
28138
28152
|
client.log('file/createVideo', formData);
|
|
28139
|
-
|
|
28153
|
+
const files = formData.getAll('files');
|
|
28154
|
+
if (!files.length)
|
|
28140
28155
|
throw new Error('The formData object must have a `files` key.');
|
|
28156
|
+
formData.append('preferredFilename', files[0].name);
|
|
28141
28157
|
if (feedType) {
|
|
28142
28158
|
formData.append('feedType', feedType);
|
|
28143
28159
|
}
|
|
@@ -29089,7 +29105,10 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
29089
29105
|
comments[0].parentId,
|
|
29090
29106
|
]);
|
|
29091
29107
|
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
29092
|
-
|
|
29108
|
+
// Skip to update parent childComment if current comment already exists
|
|
29109
|
+
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
29110
|
+
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])] }));
|
|
29111
|
+
}
|
|
29093
29112
|
}
|
|
29094
29113
|
}
|
|
29095
29114
|
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; });
|
|
@@ -33607,7 +33626,7 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
33607
33626
|
*
|
|
33608
33627
|
* @category Channel Live Collection
|
|
33609
33628
|
*/
|
|
33610
|
-
const searchMembers = (params, callback, config) => {
|
|
33629
|
+
const searchMembers$1 = (params, callback, config) => {
|
|
33611
33630
|
return getMembers$1(params, callback);
|
|
33612
33631
|
};
|
|
33613
33632
|
/* end_public_function */
|
|
@@ -33618,7 +33637,7 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
33618
33637
|
removeMembers: removeMembers$1,
|
|
33619
33638
|
applyFilter: applyFilter$1,
|
|
33620
33639
|
getMembers: getMembers$1,
|
|
33621
|
-
searchMembers: searchMembers
|
|
33640
|
+
searchMembers: searchMembers$1
|
|
33622
33641
|
});
|
|
33623
33642
|
|
|
33624
33643
|
/* begin_public_function
|
|
@@ -33861,12 +33880,30 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
33861
33880
|
prepareChannelPayload: prepareChannelPayload
|
|
33862
33881
|
});
|
|
33863
33882
|
|
|
33883
|
+
const saveCommunityUsers = (communities, communityUsers) => {
|
|
33884
|
+
if (communities.length === 0 || communityUsers.length === 0)
|
|
33885
|
+
return;
|
|
33886
|
+
communities.forEach(({ communityId }) => {
|
|
33887
|
+
const collection = communityUsers.filter(({ communityId: userCommunityId }) => communityId === userCommunityId);
|
|
33888
|
+
pushToCache(['communityUsers', 'collection', communityId], collection);
|
|
33889
|
+
});
|
|
33890
|
+
};
|
|
33891
|
+
|
|
33864
33892
|
const getMatchPostSetting = (value) => {
|
|
33865
33893
|
var _a;
|
|
33866
33894
|
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
33867
33895
|
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
33868
33896
|
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
33869
33897
|
};
|
|
33898
|
+
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
33899
|
+
if (!communityUsers)
|
|
33900
|
+
return communityUsers;
|
|
33901
|
+
const result = {};
|
|
33902
|
+
communityUsers.forEach(user => {
|
|
33903
|
+
result[`${user.userId}#${user.communityId}`] = user;
|
|
33904
|
+
});
|
|
33905
|
+
return result;
|
|
33906
|
+
};
|
|
33870
33907
|
const prepareCommunityPayload = (rawPayload) => {
|
|
33871
33908
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
33872
33909
|
const communities = rawPayload.communities.map((_a) => {
|
|
@@ -33876,7 +33913,18 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
33876
33913
|
onlyAdminCanPost,
|
|
33877
33914
|
}) }, restCommunityPayload));
|
|
33878
33915
|
});
|
|
33879
|
-
const
|
|
33916
|
+
const mergeCommunityUsers = communities.reduce((acc, { communityId }) => {
|
|
33917
|
+
var _a;
|
|
33918
|
+
const users = (_a = pullFromCache([
|
|
33919
|
+
'communityUsers',
|
|
33920
|
+
'collection',
|
|
33921
|
+
communityId,
|
|
33922
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33923
|
+
if (!users)
|
|
33924
|
+
return acc;
|
|
33925
|
+
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
33926
|
+
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
33927
|
+
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
33880
33928
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
33881
33929
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
33882
33930
|
};
|
|
@@ -33910,8 +33958,10 @@ const getCommunities$1 = async (communityIds) => {
|
|
|
33910
33958
|
});
|
|
33911
33959
|
const data = prepareCommunityPayload(payload);
|
|
33912
33960
|
const cachedAt = client.cache && Date.now();
|
|
33913
|
-
if (client.cache)
|
|
33961
|
+
if (client.cache) {
|
|
33914
33962
|
ingestInCache(data, { cachedAt });
|
|
33963
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
33964
|
+
}
|
|
33915
33965
|
return {
|
|
33916
33966
|
data: data.communities,
|
|
33917
33967
|
cachedAt,
|
|
@@ -33973,8 +34023,10 @@ const createCommunity = async (bundle) => {
|
|
|
33973
34023
|
fireEvent('community.created', payload);
|
|
33974
34024
|
const data = prepareCommunityPayload(payload);
|
|
33975
34025
|
const cachedAt = client.cache && Date.now();
|
|
33976
|
-
if (client.cache)
|
|
34026
|
+
if (client.cache) {
|
|
33977
34027
|
ingestInCache(data, { cachedAt });
|
|
34028
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
34029
|
+
}
|
|
33978
34030
|
const { communities } = data;
|
|
33979
34031
|
return {
|
|
33980
34032
|
data: communities[0],
|
|
@@ -34008,8 +34060,10 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
34008
34060
|
fireEvent('community.updated', payload);
|
|
34009
34061
|
const data = prepareCommunityPayload(payload);
|
|
34010
34062
|
const cachedAt = client.cache && Date.now();
|
|
34011
|
-
if (client.cache)
|
|
34063
|
+
if (client.cache) {
|
|
34012
34064
|
ingestInCache(data, { cachedAt });
|
|
34065
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
34066
|
+
}
|
|
34013
34067
|
const { communities } = data;
|
|
34014
34068
|
return {
|
|
34015
34069
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -34039,8 +34093,10 @@ const getCommunity$1 = async (communityId) => {
|
|
|
34039
34093
|
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
34040
34094
|
const data = prepareCommunityPayload(payload);
|
|
34041
34095
|
const cachedAt = client.cache && Date.now();
|
|
34042
|
-
if (client.cache)
|
|
34096
|
+
if (client.cache) {
|
|
34043
34097
|
ingestInCache(data, { cachedAt });
|
|
34098
|
+
saveCommunityUsers(data.communities, data.communityUsers);
|
|
34099
|
+
}
|
|
34044
34100
|
const { communities } = data;
|
|
34045
34101
|
return {
|
|
34046
34102
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -34583,7 +34639,7 @@ const observeCommunity = (communityId, callback) => {
|
|
|
34583
34639
|
* TODO: handle cache receive cache option, and cache policy
|
|
34584
34640
|
* TODO: check if querybyIds is supported
|
|
34585
34641
|
*/
|
|
34586
|
-
class CommunitiesPaginationController extends PaginationController {
|
|
34642
|
+
class CommunitiesPaginationController$1 extends PaginationController {
|
|
34587
34643
|
async getRequest(queryParams, token) {
|
|
34588
34644
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34589
34645
|
const options = token ? { token } : { limit };
|
|
@@ -34594,7 +34650,7 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
34594
34650
|
}
|
|
34595
34651
|
}
|
|
34596
34652
|
|
|
34597
|
-
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
34653
|
+
class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
34598
34654
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34599
34655
|
super(query, cacheKey);
|
|
34600
34656
|
this.notifyChange = notifyChange;
|
|
@@ -34636,22 +34692,412 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
34636
34692
|
}
|
|
34637
34693
|
}
|
|
34638
34694
|
|
|
34639
|
-
var EnumCommunityActions;
|
|
34695
|
+
var EnumCommunityActions$1;
|
|
34640
34696
|
(function (EnumCommunityActions) {
|
|
34641
34697
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
34642
34698
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
34643
34699
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
34644
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
34700
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
34701
|
+
|
|
34702
|
+
var EnumCommunityMemberActions$1;
|
|
34703
|
+
(function (EnumCommunityMemberActions) {
|
|
34704
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
34705
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
34706
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
34707
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
34708
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
34709
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
34710
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
34711
|
+
EnumCommunityMemberActions["OnMemberCountChanged"] = "OnMemberCountChanged";
|
|
34712
|
+
})(EnumCommunityMemberActions$1 || (EnumCommunityMemberActions$1 = {}));
|
|
34713
|
+
|
|
34714
|
+
/* begin_public_function
|
|
34715
|
+
id: community.membership.add_members
|
|
34716
|
+
*/
|
|
34717
|
+
/**
|
|
34718
|
+
* ```js
|
|
34719
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
34720
|
+
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
34721
|
+
* ```
|
|
34722
|
+
*
|
|
34723
|
+
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
34724
|
+
*
|
|
34725
|
+
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
34726
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
34727
|
+
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
34728
|
+
*
|
|
34729
|
+
* @category Community API
|
|
34730
|
+
* @async
|
|
34731
|
+
*/
|
|
34732
|
+
const addMembers = async (communityId, userIds) => {
|
|
34733
|
+
const client = getActiveClient();
|
|
34734
|
+
client.log('community/moderation/addMembers', communityId, userIds);
|
|
34735
|
+
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
34736
|
+
fireEvent('community.userAdded', payload);
|
|
34737
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34738
|
+
if (client.cache)
|
|
34739
|
+
ingestInCache(data);
|
|
34740
|
+
const { communityUsers } = data;
|
|
34741
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
34742
|
+
};
|
|
34743
|
+
/* end_public_function */
|
|
34744
|
+
|
|
34745
|
+
/* begin_public_function
|
|
34746
|
+
id: community.membership.remove_member
|
|
34747
|
+
*/
|
|
34748
|
+
/**
|
|
34749
|
+
* ```js
|
|
34750
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
34751
|
+
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
34752
|
+
* ```
|
|
34753
|
+
*
|
|
34754
|
+
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
34755
|
+
*
|
|
34756
|
+
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
34757
|
+
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
34758
|
+
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
34759
|
+
*
|
|
34760
|
+
* @category Community API
|
|
34761
|
+
* @async
|
|
34762
|
+
*/
|
|
34763
|
+
const removeMembers = async (communityId, userIds) => {
|
|
34764
|
+
const client = getActiveClient();
|
|
34765
|
+
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
34766
|
+
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
34767
|
+
fireEvent('community.userRemoved', payload);
|
|
34768
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
34769
|
+
if (client.cache)
|
|
34770
|
+
ingestInCache(data);
|
|
34771
|
+
const { communityUsers } = data;
|
|
34772
|
+
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
34773
|
+
};
|
|
34774
|
+
/* end_public_function */
|
|
34775
|
+
|
|
34776
|
+
/**
|
|
34777
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
34778
|
+
* TODO: check if querybyIds is supported
|
|
34779
|
+
*/
|
|
34780
|
+
class CommunityMembersPaginationController extends PaginationController {
|
|
34781
|
+
async getRequest(queryParams, token) {
|
|
34782
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
34783
|
+
const options = token ? { token } : { limit };
|
|
34784
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
34785
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
34786
|
+
});
|
|
34787
|
+
return queryResponse;
|
|
34788
|
+
}
|
|
34789
|
+
}
|
|
34790
|
+
|
|
34791
|
+
class CommunityMembersQueryStreamController extends QueryStreamController {
|
|
34792
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
34793
|
+
super(query, cacheKey);
|
|
34794
|
+
this.notifyChange = notifyChange;
|
|
34795
|
+
this.preparePayload = preparePayload;
|
|
34796
|
+
}
|
|
34797
|
+
async saveToMainDB(response) {
|
|
34798
|
+
const processedPayload = await this.preparePayload(response);
|
|
34799
|
+
const client = getActiveClient();
|
|
34800
|
+
const cachedAt = client.cache && Date.now();
|
|
34801
|
+
if (client.cache) {
|
|
34802
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
34803
|
+
}
|
|
34804
|
+
}
|
|
34805
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
34806
|
+
var _a, _b;
|
|
34807
|
+
if (refresh) {
|
|
34808
|
+
pushToCache(this.cacheKey, {
|
|
34809
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34810
|
+
});
|
|
34811
|
+
}
|
|
34812
|
+
else {
|
|
34813
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34814
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34815
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
34816
|
+
...new Set([
|
|
34817
|
+
...communityUsers,
|
|
34818
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
34819
|
+
]),
|
|
34820
|
+
] }));
|
|
34821
|
+
}
|
|
34822
|
+
}
|
|
34823
|
+
reactor(action) {
|
|
34824
|
+
return (community, communityMembers) => {
|
|
34825
|
+
var _a;
|
|
34826
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34827
|
+
if (!collection)
|
|
34828
|
+
return;
|
|
34829
|
+
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
34830
|
+
this.query.sortBy === 'displayName') {
|
|
34831
|
+
return;
|
|
34832
|
+
}
|
|
34833
|
+
communityMembers.forEach(communityMember => {
|
|
34834
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
34835
|
+
communityId: this.query.communityId,
|
|
34836
|
+
userId: communityMember.userId,
|
|
34837
|
+
});
|
|
34838
|
+
if (communityMember.communityMembership === 'none') {
|
|
34839
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
34840
|
+
}
|
|
34841
|
+
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
34842
|
+
collection.data = [communityMemberCacheId, ...collection.data];
|
|
34843
|
+
}
|
|
34844
|
+
});
|
|
34845
|
+
pushToCache(this.cacheKey, collection);
|
|
34846
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
34847
|
+
};
|
|
34848
|
+
}
|
|
34849
|
+
subscribeRTE(createSubscriber) {
|
|
34850
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
34851
|
+
}
|
|
34852
|
+
}
|
|
34853
|
+
|
|
34854
|
+
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
34855
|
+
constructor(query, callback) {
|
|
34856
|
+
const queryStreamId = hash(query);
|
|
34857
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
34858
|
+
const paginationController = new CommunityMembersPaginationController(query);
|
|
34859
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
34860
|
+
this.query = query;
|
|
34861
|
+
this.queryStreamController = new CommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
34862
|
+
this.callback = callback.bind(this);
|
|
34863
|
+
this.loadPage({ initial: true });
|
|
34864
|
+
}
|
|
34865
|
+
setup() {
|
|
34866
|
+
var _a;
|
|
34867
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34868
|
+
if (!collection) {
|
|
34869
|
+
pushToCache(this.cacheKey, {
|
|
34870
|
+
data: [],
|
|
34871
|
+
params: {},
|
|
34872
|
+
});
|
|
34873
|
+
}
|
|
34874
|
+
}
|
|
34875
|
+
async persistModel(queryPayload) {
|
|
34876
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
34877
|
+
}
|
|
34878
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
34879
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
34880
|
+
}
|
|
34881
|
+
startSubscription() {
|
|
34882
|
+
return this.queryStreamController.subscribeRTE([
|
|
34883
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
34884
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
34885
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
|
|
34886
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
|
|
34887
|
+
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
|
|
34888
|
+
{
|
|
34889
|
+
fn: onCommunityUserRoleRemoved,
|
|
34890
|
+
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
34891
|
+
},
|
|
34892
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
34893
|
+
]);
|
|
34894
|
+
}
|
|
34895
|
+
notifyChange({ origin, loading, error }) {
|
|
34896
|
+
var _a, _b;
|
|
34897
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34898
|
+
if (!collection)
|
|
34899
|
+
return;
|
|
34900
|
+
const data = this.applyFilter((_b = collection.data
|
|
34901
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
34902
|
+
.filter(isNonNullable)
|
|
34903
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
34904
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
34905
|
+
return;
|
|
34906
|
+
this.callback({
|
|
34907
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
34908
|
+
data,
|
|
34909
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
34910
|
+
loading,
|
|
34911
|
+
error,
|
|
34912
|
+
});
|
|
34913
|
+
}
|
|
34914
|
+
applyFilter(data) {
|
|
34915
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
34916
|
+
if (this.query.memberships) {
|
|
34917
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
34918
|
+
const memberships = this.query.memberships || [];
|
|
34919
|
+
return memberships.includes(communityMembership);
|
|
34920
|
+
});
|
|
34921
|
+
}
|
|
34922
|
+
if (this.query.search) {
|
|
34923
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
34924
|
+
}
|
|
34925
|
+
switch (this.query.sortBy) {
|
|
34926
|
+
case 'firstCreated':
|
|
34927
|
+
communityMembers = communityMembers.sort(sortByFirstCreated);
|
|
34928
|
+
break;
|
|
34929
|
+
case 'displayName':
|
|
34930
|
+
communityMembers = communityMembers.sort((a, b) => {
|
|
34931
|
+
var _a, _b, _c, _d;
|
|
34932
|
+
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)) {
|
|
34933
|
+
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);
|
|
34934
|
+
}
|
|
34935
|
+
return 0;
|
|
34936
|
+
});
|
|
34937
|
+
break;
|
|
34938
|
+
case 'lastCreated':
|
|
34939
|
+
default:
|
|
34940
|
+
communityMembers = communityMembers.sort(sortByLastCreated);
|
|
34941
|
+
break;
|
|
34942
|
+
}
|
|
34943
|
+
return communityMembers;
|
|
34944
|
+
}
|
|
34945
|
+
}
|
|
34946
|
+
|
|
34947
|
+
/*
|
|
34948
|
+
* Exported for testing
|
|
34949
|
+
* @hidden
|
|
34950
|
+
*/
|
|
34951
|
+
const applyFilter = (data, params) => {
|
|
34952
|
+
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
34953
|
+
if (params.memberships) {
|
|
34954
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
34955
|
+
const membership = params.memberships;
|
|
34956
|
+
return membership.includes(communityMembership);
|
|
34957
|
+
});
|
|
34958
|
+
}
|
|
34959
|
+
if (params.search) {
|
|
34960
|
+
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
34961
|
+
}
|
|
34962
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
34963
|
+
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
34964
|
+
return communityMembers;
|
|
34965
|
+
};
|
|
34966
|
+
/* begin_public_function
|
|
34967
|
+
id: community.membership.query
|
|
34968
|
+
*/
|
|
34969
|
+
/**
|
|
34970
|
+
* ```js
|
|
34971
|
+
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
34972
|
+
*
|
|
34973
|
+
* let communityMembers = []
|
|
34974
|
+
* const unsub = getMembers({
|
|
34975
|
+
* communityId: Amity.Community['communityId'],
|
|
34976
|
+
* }, response => merge(communityMembers, response.data))
|
|
34977
|
+
* ```
|
|
34978
|
+
*
|
|
34979
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
34980
|
+
*
|
|
34981
|
+
* @param params for querying community users
|
|
34982
|
+
* @param callback the function to call when new data are available
|
|
34983
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
34984
|
+
*
|
|
34985
|
+
* @category Community Live Collection
|
|
34986
|
+
*/
|
|
34987
|
+
const getMembers = (params, callback, config) => {
|
|
34988
|
+
const { log, cache } = getActiveClient();
|
|
34989
|
+
if (!cache) {
|
|
34990
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
34991
|
+
}
|
|
34992
|
+
const timestamp = Date.now();
|
|
34993
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
34994
|
+
const communityMemberLiveCollection = new CommunityMembersLiveCollectionController(params, resp => {
|
|
34995
|
+
console.log('resp', resp);
|
|
34996
|
+
callback(resp);
|
|
34997
|
+
});
|
|
34998
|
+
const disposers = communityMemberLiveCollection.startSubscription();
|
|
34999
|
+
const cacheKey = communityMemberLiveCollection.getCacheKey();
|
|
35000
|
+
disposers.push(() => {
|
|
35001
|
+
dropFromCache(cacheKey);
|
|
35002
|
+
});
|
|
35003
|
+
return () => {
|
|
35004
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35005
|
+
disposers.forEach(fn => fn());
|
|
35006
|
+
};
|
|
35007
|
+
};
|
|
35008
|
+
/* end_public_function */
|
|
35009
|
+
|
|
35010
|
+
/**
|
|
35011
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35012
|
+
* TODO: check if querybyIds is supported
|
|
35013
|
+
*/
|
|
35014
|
+
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
35015
|
+
async getRequest(queryParams, token) {
|
|
35016
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35017
|
+
const options = token ? { token } : { limit };
|
|
35018
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35019
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
35020
|
+
});
|
|
35021
|
+
return queryResponse;
|
|
35022
|
+
}
|
|
35023
|
+
}
|
|
35024
|
+
|
|
35025
|
+
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
35026
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35027
|
+
super(query, cacheKey);
|
|
35028
|
+
this.notifyChange = notifyChange;
|
|
35029
|
+
this.preparePayload = preparePayload;
|
|
35030
|
+
}
|
|
35031
|
+
async saveToMainDB(response) {
|
|
35032
|
+
const processedPayload = await this.preparePayload(response);
|
|
35033
|
+
const client = getActiveClient();
|
|
35034
|
+
const cachedAt = client.cache && Date.now();
|
|
35035
|
+
if (client.cache) {
|
|
35036
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35037
|
+
}
|
|
35038
|
+
}
|
|
35039
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
35040
|
+
var _a, _b;
|
|
35041
|
+
if (refresh) {
|
|
35042
|
+
pushToCache(this.cacheKey, {
|
|
35043
|
+
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35044
|
+
});
|
|
35045
|
+
}
|
|
35046
|
+
else {
|
|
35047
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35048
|
+
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35049
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
35050
|
+
...new Set([
|
|
35051
|
+
...communityUsers,
|
|
35052
|
+
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35053
|
+
]),
|
|
35054
|
+
] }));
|
|
35055
|
+
}
|
|
35056
|
+
}
|
|
35057
|
+
reactor(action) {
|
|
35058
|
+
return (community, communityMembers) => {
|
|
35059
|
+
var _a;
|
|
35060
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35061
|
+
if (!collection)
|
|
35062
|
+
return;
|
|
35063
|
+
communityMembers.forEach(communityMember => {
|
|
35064
|
+
const communityMemberCacheId = getResolver('communityUsers')({
|
|
35065
|
+
communityId: this.query.communityId,
|
|
35066
|
+
userId: communityMember.userId,
|
|
35067
|
+
});
|
|
35068
|
+
if (communityMember.communityMembership === 'none') {
|
|
35069
|
+
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
35070
|
+
}
|
|
35071
|
+
});
|
|
35072
|
+
pushToCache(this.cacheKey, collection);
|
|
35073
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35074
|
+
};
|
|
35075
|
+
}
|
|
35076
|
+
subscribeRTE(createSubscriber) {
|
|
35077
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35078
|
+
}
|
|
35079
|
+
}
|
|
35080
|
+
|
|
35081
|
+
var EnumCommunityMemberActions;
|
|
35082
|
+
(function (EnumCommunityMemberActions) {
|
|
35083
|
+
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
35084
|
+
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
35085
|
+
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
35086
|
+
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
35087
|
+
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
35088
|
+
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
35089
|
+
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
35090
|
+
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
34645
35091
|
|
|
34646
35092
|
/* eslint-disable no-use-before-define */
|
|
34647
|
-
class
|
|
35093
|
+
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
34648
35094
|
constructor(query, callback) {
|
|
34649
35095
|
const queryStreamId = hash(query);
|
|
34650
|
-
const cacheKey = ['
|
|
34651
|
-
const paginationController = new
|
|
35096
|
+
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
35097
|
+
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
34652
35098
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
34653
35099
|
this.query = query;
|
|
34654
|
-
this.queryStreamController = new
|
|
35100
|
+
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
34655
35101
|
this.callback = callback.bind(this);
|
|
34656
35102
|
this.loadPage({ initial: true });
|
|
34657
35103
|
}
|
|
@@ -34673,8 +35119,146 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
34673
35119
|
}
|
|
34674
35120
|
startSubscription() {
|
|
34675
35121
|
return this.queryStreamController.subscribeRTE([
|
|
34676
|
-
{ fn:
|
|
34677
|
-
{ fn:
|
|
35122
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
35123
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
35124
|
+
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
35125
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
35126
|
+
{
|
|
35127
|
+
fn: onCommunityUserRoleRemoved,
|
|
35128
|
+
action: EnumCommunityMemberActions.OnCommunityUserRoleRemoved,
|
|
35129
|
+
},
|
|
35130
|
+
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions.OnCommunityUserUnbanned },
|
|
35131
|
+
]);
|
|
35132
|
+
}
|
|
35133
|
+
notifyChange({ origin, loading, error }) {
|
|
35134
|
+
var _a, _b;
|
|
35135
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35136
|
+
if (!collection)
|
|
35137
|
+
return;
|
|
35138
|
+
const data = this.applyFilter((_b = collection.data
|
|
35139
|
+
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
35140
|
+
.filter(isNonNullable)
|
|
35141
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35142
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35143
|
+
return;
|
|
35144
|
+
this.callback({
|
|
35145
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35146
|
+
data,
|
|
35147
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35148
|
+
loading,
|
|
35149
|
+
error,
|
|
35150
|
+
});
|
|
35151
|
+
}
|
|
35152
|
+
applyFilter(data) {
|
|
35153
|
+
let communityMembers = filterByPropIntersection(data, 'roles', this.query.roles);
|
|
35154
|
+
if (this.query.memberships) {
|
|
35155
|
+
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35156
|
+
const memberships = this.query.memberships || [];
|
|
35157
|
+
return memberships.includes(communityMembership);
|
|
35158
|
+
});
|
|
35159
|
+
}
|
|
35160
|
+
if (this.query.search) {
|
|
35161
|
+
communityMembers = filterBySearchTerm(communityMembers, this.query.search);
|
|
35162
|
+
}
|
|
35163
|
+
return communityMembers;
|
|
35164
|
+
}
|
|
35165
|
+
}
|
|
35166
|
+
|
|
35167
|
+
/* begin_public_function
|
|
35168
|
+
id: community.membership.query
|
|
35169
|
+
*/
|
|
35170
|
+
/**
|
|
35171
|
+
* ```js
|
|
35172
|
+
* import { searchMembers } from '@amityco/ts-sdk-react-native'
|
|
35173
|
+
*
|
|
35174
|
+
* let communityMembers = []
|
|
35175
|
+
* const unsub = searchMembers({
|
|
35176
|
+
* communityId: Amity.Community['communityId'],
|
|
35177
|
+
* }, response => merge(communityMembers, response.data))
|
|
35178
|
+
* ```
|
|
35179
|
+
*
|
|
35180
|
+
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
35181
|
+
*
|
|
35182
|
+
* @param params for querying community users
|
|
35183
|
+
* @param callback the function to call when new data are available
|
|
35184
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
35185
|
+
*
|
|
35186
|
+
* @category Community Live Collection
|
|
35187
|
+
*/
|
|
35188
|
+
const searchMembers = (params, callback, config) => {
|
|
35189
|
+
const { log, cache } = getActiveClient();
|
|
35190
|
+
if (!cache) {
|
|
35191
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
35192
|
+
}
|
|
35193
|
+
const timestamp = Date.now();
|
|
35194
|
+
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
35195
|
+
const searchCommunityMemberLiveCollection = new SearchCommunityMembersLiveCollectionController(params, resp => {
|
|
35196
|
+
callback(resp);
|
|
35197
|
+
});
|
|
35198
|
+
const disposers = searchCommunityMemberLiveCollection.startSubscription();
|
|
35199
|
+
const cacheKey = searchCommunityMemberLiveCollection.getCacheKey();
|
|
35200
|
+
disposers.push(() => {
|
|
35201
|
+
dropFromCache(cacheKey);
|
|
35202
|
+
});
|
|
35203
|
+
return () => {
|
|
35204
|
+
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35205
|
+
disposers.forEach(fn => fn());
|
|
35206
|
+
};
|
|
35207
|
+
};
|
|
35208
|
+
/* end_public_function */
|
|
35209
|
+
|
|
35210
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
35211
|
+
__proto__: null,
|
|
35212
|
+
addMembers: addMembers,
|
|
35213
|
+
removeMembers: removeMembers,
|
|
35214
|
+
applyFilter: applyFilter,
|
|
35215
|
+
getMembers: getMembers,
|
|
35216
|
+
searchMembers: searchMembers,
|
|
35217
|
+
onCommunityUserAdded: onCommunityUserAdded,
|
|
35218
|
+
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
35219
|
+
onCommunityUserBanned: onCommunityUserBanned,
|
|
35220
|
+
onCommunityUserChanged: onCommunityUserChanged,
|
|
35221
|
+
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
35222
|
+
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
35223
|
+
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
35224
|
+
onCommunityJoined: onCommunityJoined,
|
|
35225
|
+
onCommunityLeft: onCommunityLeft
|
|
35226
|
+
});
|
|
35227
|
+
|
|
35228
|
+
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
35229
|
+
constructor(query, callback) {
|
|
35230
|
+
const queryStreamId = hash(query);
|
|
35231
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
35232
|
+
const paginationController = new CommunitiesPaginationController$1(query);
|
|
35233
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35234
|
+
this.query = query;
|
|
35235
|
+
this.queryStreamController = new CommunitiesQueryStreamController$1(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
35236
|
+
this.callback = callback.bind(this);
|
|
35237
|
+
this.loadPage({ initial: true });
|
|
35238
|
+
}
|
|
35239
|
+
setup() {
|
|
35240
|
+
var _a;
|
|
35241
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35242
|
+
if (!collection) {
|
|
35243
|
+
pushToCache(this.cacheKey, {
|
|
35244
|
+
data: [],
|
|
35245
|
+
params: {},
|
|
35246
|
+
});
|
|
35247
|
+
}
|
|
35248
|
+
}
|
|
35249
|
+
async persistModel(queryPayload) {
|
|
35250
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
35251
|
+
}
|
|
35252
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
35253
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
35254
|
+
}
|
|
35255
|
+
startSubscription() {
|
|
35256
|
+
return this.queryStreamController.subscribeRTE([
|
|
35257
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
35258
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
35259
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35260
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35261
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
34678
35262
|
]);
|
|
34679
35263
|
}
|
|
34680
35264
|
notifyChange({ origin, loading, error }) {
|
|
@@ -34720,7 +35304,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
34720
35304
|
*/
|
|
34721
35305
|
/**
|
|
34722
35306
|
* ```js
|
|
34723
|
-
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
35307
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
34724
35308
|
*
|
|
34725
35309
|
* let communities = []
|
|
34726
35310
|
* const unsub = CommunityRepository.searchCommunities({
|
|
@@ -34755,50 +35339,166 @@ const searchCommunities = (params, callback, config) => {
|
|
|
34755
35339
|
/* end_public_function */
|
|
34756
35340
|
|
|
34757
35341
|
/**
|
|
34758
|
-
*
|
|
34759
|
-
*
|
|
34760
|
-
* const communities = await queryCommunities()
|
|
34761
|
-
* ```
|
|
34762
|
-
*
|
|
34763
|
-
* Queries a paginable list of {@link Amity.Community} objects
|
|
34764
|
-
* Search is performed by displayName such as `.startsWith(search)`
|
|
34765
|
-
*
|
|
34766
|
-
* @param query The query parameters
|
|
34767
|
-
* @returns A page of {@link Amity.Community} objects
|
|
34768
|
-
*
|
|
34769
|
-
* @category Community API
|
|
34770
|
-
* @async
|
|
35342
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
35343
|
+
* TODO: check if querybyIds is supported
|
|
34771
35344
|
*/
|
|
34772
|
-
|
|
34773
|
-
|
|
34774
|
-
|
|
34775
|
-
|
|
34776
|
-
|
|
34777
|
-
|
|
34778
|
-
|
|
34779
|
-
|
|
34780
|
-
return { token: page };
|
|
34781
|
-
if (limit)
|
|
34782
|
-
return { limit };
|
|
34783
|
-
return undefined;
|
|
34784
|
-
})();
|
|
34785
|
-
// API-FIX: parameters should be querystring.
|
|
34786
|
-
// API-FIX: backend doesn't answer Amity.Response
|
|
34787
|
-
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
34788
|
-
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
34789
|
-
params: Object.assign(Object.assign({}, restParams), { isDeleted: inferIsDeleted(includeDeleted), keyword: displayName, filter: membership, options }),
|
|
34790
|
-
});
|
|
34791
|
-
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
34792
|
-
const unpackedPayload = prepareCommunityPayload(payload);
|
|
34793
|
-
const { communities } = unpackedPayload;
|
|
34794
|
-
const cachedAt = client.cache && Date.now();
|
|
34795
|
-
if (client.cache) {
|
|
34796
|
-
ingestInCache(unpackedPayload, { cachedAt });
|
|
34797
|
-
const cacheKey = ['community', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
34798
|
-
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
35345
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
35346
|
+
async getRequest(queryParams, token) {
|
|
35347
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
35348
|
+
const options = token ? { token } : { limit };
|
|
35349
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities`, {
|
|
35350
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(params.includeDeleted), keyword: params.displayName, filter: params.membership, options }),
|
|
35351
|
+
});
|
|
35352
|
+
return queryResponse;
|
|
34799
35353
|
}
|
|
34800
|
-
|
|
34801
|
-
|
|
35354
|
+
}
|
|
35355
|
+
|
|
35356
|
+
var EnumCommunityActions;
|
|
35357
|
+
(function (EnumCommunityActions) {
|
|
35358
|
+
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35359
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35360
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35361
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
35362
|
+
|
|
35363
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
35364
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
35365
|
+
super(query, cacheKey);
|
|
35366
|
+
this.notifyChange = notifyChange;
|
|
35367
|
+
this.preparePayload = preparePayload;
|
|
35368
|
+
}
|
|
35369
|
+
async saveToMainDB(response) {
|
|
35370
|
+
const processedPayload = await this.preparePayload(response);
|
|
35371
|
+
const client = getActiveClient();
|
|
35372
|
+
const cachedAt = client.cache && Date.now();
|
|
35373
|
+
if (client.cache) {
|
|
35374
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
35375
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
35376
|
+
}
|
|
35377
|
+
}
|
|
35378
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
35379
|
+
var _a, _b;
|
|
35380
|
+
if (refresh) {
|
|
35381
|
+
pushToCache(this.cacheKey, {
|
|
35382
|
+
data: response.communities.map(getResolver('community')),
|
|
35383
|
+
});
|
|
35384
|
+
}
|
|
35385
|
+
else {
|
|
35386
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35387
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35388
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
35389
|
+
}
|
|
35390
|
+
}
|
|
35391
|
+
reactor(action) {
|
|
35392
|
+
return (community) => {
|
|
35393
|
+
var _a;
|
|
35394
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35395
|
+
if (!collection)
|
|
35396
|
+
return;
|
|
35397
|
+
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
35398
|
+
return;
|
|
35399
|
+
}
|
|
35400
|
+
/*
|
|
35401
|
+
* Simply update a collection and let responder decide what to do with data
|
|
35402
|
+
*/
|
|
35403
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
35404
|
+
pushToCache(this.cacheKey, collection);
|
|
35405
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
35406
|
+
};
|
|
35407
|
+
}
|
|
35408
|
+
subscribeRTE(createSubscriber) {
|
|
35409
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
35410
|
+
}
|
|
35411
|
+
}
|
|
35412
|
+
|
|
35413
|
+
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
35414
|
+
constructor(query, callback) {
|
|
35415
|
+
const queryStreamId = hash(query);
|
|
35416
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
35417
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
35418
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
35419
|
+
this.query = query;
|
|
35420
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
35421
|
+
this.callback = callback.bind(this);
|
|
35422
|
+
this.loadPage({ initial: true });
|
|
35423
|
+
}
|
|
35424
|
+
setup() {
|
|
35425
|
+
var _a;
|
|
35426
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35427
|
+
if (!collection) {
|
|
35428
|
+
pushToCache(this.cacheKey, {
|
|
35429
|
+
data: [],
|
|
35430
|
+
params: {},
|
|
35431
|
+
});
|
|
35432
|
+
}
|
|
35433
|
+
}
|
|
35434
|
+
async persistModel(queryPayload) {
|
|
35435
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
35436
|
+
}
|
|
35437
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
35438
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
35439
|
+
}
|
|
35440
|
+
startSubscription() {
|
|
35441
|
+
return this.queryStreamController.subscribeRTE([
|
|
35442
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
35443
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
35444
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
35445
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35446
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35447
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
35448
|
+
]);
|
|
35449
|
+
}
|
|
35450
|
+
notifyChange({ origin, loading, error }) {
|
|
35451
|
+
var _a, _b;
|
|
35452
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35453
|
+
if (!collection)
|
|
35454
|
+
return;
|
|
35455
|
+
const data = this.applyFilter((_b = collection.data
|
|
35456
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
35457
|
+
.filter(Boolean)
|
|
35458
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
35459
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
35460
|
+
return;
|
|
35461
|
+
this.callback({
|
|
35462
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
35463
|
+
data,
|
|
35464
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
35465
|
+
loading,
|
|
35466
|
+
error,
|
|
35467
|
+
});
|
|
35468
|
+
}
|
|
35469
|
+
applyFilter(data) {
|
|
35470
|
+
const { userId } = getActiveClient();
|
|
35471
|
+
let communities = data;
|
|
35472
|
+
if (this.query.includeDeleted) {
|
|
35473
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
35474
|
+
}
|
|
35475
|
+
if (this.query.categoryId) {
|
|
35476
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
35477
|
+
}
|
|
35478
|
+
if (this.query.tags) {
|
|
35479
|
+
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); }); });
|
|
35480
|
+
}
|
|
35481
|
+
if (this.query.membership && userId) {
|
|
35482
|
+
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
35483
|
+
}
|
|
35484
|
+
if (!this.query.displayName) {
|
|
35485
|
+
const sortFn = (() => {
|
|
35486
|
+
switch (this.query.sortBy) {
|
|
35487
|
+
case 'firstCreated':
|
|
35488
|
+
return sortByFirstCreated;
|
|
35489
|
+
case 'lastCreated':
|
|
35490
|
+
return sortByLastCreated;
|
|
35491
|
+
case 'displayName':
|
|
35492
|
+
return sortByDisplayName;
|
|
35493
|
+
default:
|
|
35494
|
+
return sortByLastCreated;
|
|
35495
|
+
}
|
|
35496
|
+
})();
|
|
35497
|
+
communities = communities.sort(sortFn);
|
|
35498
|
+
}
|
|
35499
|
+
return communities;
|
|
35500
|
+
}
|
|
35501
|
+
}
|
|
34802
35502
|
|
|
34803
35503
|
/* begin_public_function
|
|
34804
35504
|
id: community.query
|
|
@@ -34822,98 +35522,15 @@ const queryCommunities = async (query) => {
|
|
|
34822
35522
|
* @category Community Live Collection
|
|
34823
35523
|
*/
|
|
34824
35524
|
const getCommunities = (params, callback, config) => {
|
|
34825
|
-
const { log, cache
|
|
35525
|
+
const { log, cache } = getActiveClient();
|
|
34826
35526
|
if (!cache) {
|
|
34827
35527
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
34828
35528
|
}
|
|
34829
35529
|
const timestamp = Date.now();
|
|
34830
35530
|
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
34831
|
-
const
|
|
34832
|
-
const
|
|
34833
|
-
const
|
|
34834
|
-
const disposers = [];
|
|
34835
|
-
const cacheKey = ['community', 'collection', queryParams];
|
|
34836
|
-
const responder = (data) => {
|
|
34837
|
-
var _a, _b;
|
|
34838
|
-
let communities = (_a = data.data
|
|
34839
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
34840
|
-
.filter(Boolean)
|
|
34841
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
34842
|
-
communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
|
|
34843
|
-
if (!params.includeDeleted) {
|
|
34844
|
-
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
34845
|
-
}
|
|
34846
|
-
if (params.categoryId) {
|
|
34847
|
-
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
|
|
34848
|
-
}
|
|
34849
|
-
if (params.tags) {
|
|
34850
|
-
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); }); });
|
|
34851
|
-
}
|
|
34852
|
-
if (params.membership && userId) {
|
|
34853
|
-
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
34854
|
-
}
|
|
34855
|
-
const sortBy = params.sortBy || 'lastCreated';
|
|
34856
|
-
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
34857
|
-
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
34858
|
-
}
|
|
34859
|
-
/*
|
|
34860
|
-
* The server returns communities with empty | null displayName's first before
|
|
34861
|
-
* returning sorted list of communities with displayNames
|
|
34862
|
-
*
|
|
34863
|
-
* This section needs to be updated as displayNames can be null as well
|
|
34864
|
-
*/
|
|
34865
|
-
if (sortBy === 'displayName') {
|
|
34866
|
-
communities = communities
|
|
34867
|
-
// this needs to be aligned with the backend data type
|
|
34868
|
-
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
34869
|
-
// @ts-ignore
|
|
34870
|
-
.sort(sortByDisplayName);
|
|
34871
|
-
}
|
|
34872
|
-
callback({
|
|
34873
|
-
onNextPage: onFetch,
|
|
34874
|
-
data: communities,
|
|
34875
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
34876
|
-
loading: data.loading,
|
|
34877
|
-
error: data.error,
|
|
34878
|
-
});
|
|
34879
|
-
};
|
|
34880
|
-
const realtimeRouter = (_) => (community) => {
|
|
34881
|
-
var _a;
|
|
34882
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34883
|
-
if (!collection)
|
|
34884
|
-
return;
|
|
34885
|
-
/*
|
|
34886
|
-
* Simply update collection and let responder decide what to do with data
|
|
34887
|
-
*/
|
|
34888
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
34889
|
-
pushToCache(cacheKey, collection);
|
|
34890
|
-
responder(collection);
|
|
34891
|
-
};
|
|
34892
|
-
const onFetch = (initial = false) => {
|
|
34893
|
-
var _a, _b;
|
|
34894
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
34895
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
34896
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
34897
|
-
return;
|
|
34898
|
-
const query = createQuery(queryCommunities, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
34899
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
34900
|
-
const data = {
|
|
34901
|
-
loading,
|
|
34902
|
-
error,
|
|
34903
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
34904
|
-
data: communities,
|
|
34905
|
-
};
|
|
34906
|
-
if (result) {
|
|
34907
|
-
data.data = initial
|
|
34908
|
-
? result.map(getResolver('community'))
|
|
34909
|
-
: [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
34910
|
-
}
|
|
34911
|
-
pushToCache(cacheKey, data);
|
|
34912
|
-
responder(data);
|
|
34913
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
34914
|
-
};
|
|
34915
|
-
disposers.push(onCommunityCreated(realtimeRouter()), onCommunityDeleted(realtimeRouter()), onCommunityUpdated(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityLeft(realtimeRouter()), onCommunityUserChanged(realtimeRouter()));
|
|
34916
|
-
onFetch(true);
|
|
35531
|
+
const communitiesLiveCollection = new CommunityLiveCollectionController(params, callback);
|
|
35532
|
+
const disposers = communitiesLiveCollection.startSubscription();
|
|
35533
|
+
const cacheKey = communitiesLiveCollection.getCacheKey();
|
|
34917
35534
|
disposers.push(() => dropFromCache(cacheKey));
|
|
34918
35535
|
return () => {
|
|
34919
35536
|
log(`getCommunities(tmpid: ${timestamp}) > dispose`);
|
|
@@ -35371,7 +35988,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
35371
35988
|
};
|
|
35372
35989
|
/* end_public_function */
|
|
35373
35990
|
|
|
35374
|
-
var index$
|
|
35991
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
35375
35992
|
__proto__: null,
|
|
35376
35993
|
addRoles: addRoles,
|
|
35377
35994
|
removeRoles: removeRoles,
|
|
@@ -35379,299 +35996,10 @@ var index$a = /*#__PURE__*/Object.freeze({
|
|
|
35379
35996
|
unbanMembers: unbanMembers
|
|
35380
35997
|
});
|
|
35381
35998
|
|
|
35382
|
-
/* begin_public_function
|
|
35383
|
-
id: community.membership.add_members
|
|
35384
|
-
*/
|
|
35385
|
-
/**
|
|
35386
|
-
* ```js
|
|
35387
|
-
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
35388
|
-
* const updated = await CommunityRepository.moderation.addMembers(communityId, ['foo', 'bar'])
|
|
35389
|
-
* ```
|
|
35390
|
-
*
|
|
35391
|
-
* Adds a list of {@link Amity.InternalUser} to a {@link Amity.Community} to add users to
|
|
35392
|
-
*
|
|
35393
|
-
* @param communityId The ID of the {@link Amity.Community} to perform
|
|
35394
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to add
|
|
35395
|
-
* @returns A success boolean if the {@link Amity.InternalUser} were added to the {@link Amity.Community}
|
|
35396
|
-
*
|
|
35397
|
-
* @category Community API
|
|
35398
|
-
* @async
|
|
35399
|
-
*/
|
|
35400
|
-
const addMembers = async (communityId, userIds) => {
|
|
35401
|
-
const client = getActiveClient();
|
|
35402
|
-
client.log('community/moderation/addMembers', communityId, userIds);
|
|
35403
|
-
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/users`, { communityId, userIds });
|
|
35404
|
-
fireEvent('community.userAdded', payload);
|
|
35405
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35406
|
-
if (client.cache)
|
|
35407
|
-
ingestInCache(data);
|
|
35408
|
-
const { communityUsers } = data;
|
|
35409
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership === 'member');
|
|
35410
|
-
};
|
|
35411
|
-
/* end_public_function */
|
|
35412
|
-
|
|
35413
|
-
/* begin_public_function
|
|
35414
|
-
id: community.membership.remove_member
|
|
35415
|
-
*/
|
|
35416
|
-
/**
|
|
35417
|
-
* ```js
|
|
35418
|
-
* import { CommunityRepository } from '@amityco/ts-sdk-react-native'
|
|
35419
|
-
* const updated = await CommunityRepository.moderation.removeMembers(communityId, ['foo', 'bar'])
|
|
35420
|
-
* ```
|
|
35421
|
-
*
|
|
35422
|
-
* Removes a list of {@link Amity.InternalUser} from a {@link Amity.Community}
|
|
35423
|
-
*
|
|
35424
|
-
* @param communityId The ID of the {@link Amity.Community} to edit
|
|
35425
|
-
* @param userIds The list of IDs {@link Amity.InternalUser} to remove
|
|
35426
|
-
* @returns A success boolean if the list of {@link Amity.InternalUser} were removed from the {@link Amity.Community}
|
|
35427
|
-
*
|
|
35428
|
-
* @category Community API
|
|
35429
|
-
* @async
|
|
35430
|
-
*/
|
|
35431
|
-
const removeMembers = async (communityId, userIds) => {
|
|
35432
|
-
const client = getActiveClient();
|
|
35433
|
-
client.log('community/moderation/removeMembers', communityId, userIds);
|
|
35434
|
-
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/users`, { data: { communityId, userIds } });
|
|
35435
|
-
fireEvent('community.userRemoved', payload);
|
|
35436
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
35437
|
-
if (client.cache)
|
|
35438
|
-
ingestInCache(data);
|
|
35439
|
-
const { communityUsers } = data;
|
|
35440
|
-
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && communityUser.communityMembership !== 'member');
|
|
35441
|
-
};
|
|
35442
|
-
/* end_public_function */
|
|
35443
|
-
|
|
35444
|
-
/**
|
|
35445
|
-
* ```js
|
|
35446
|
-
* import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
|
|
35447
|
-
* const communityMembers = await queryCommunityMembers({ communityId: 'foo' })
|
|
35448
|
-
* ```
|
|
35449
|
-
*
|
|
35450
|
-
* Queries a paginable list of {@link Amity.CommunityUser} objects
|
|
35451
|
-
*
|
|
35452
|
-
* @param query The query parameters
|
|
35453
|
-
* @returns A page of {@link Amity.CommunityUser} objects
|
|
35454
|
-
*
|
|
35455
|
-
* @category Community API
|
|
35456
|
-
* @async
|
|
35457
|
-
* */
|
|
35458
|
-
const queryCommunityMembers = async (query) => {
|
|
35459
|
-
const client = getActiveClient();
|
|
35460
|
-
client.log('community/queryCommunityMembers', query);
|
|
35461
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
|
|
35462
|
-
const options = (() => {
|
|
35463
|
-
if (page)
|
|
35464
|
-
return { token: page };
|
|
35465
|
-
if (limit)
|
|
35466
|
-
return { limit };
|
|
35467
|
-
return undefined;
|
|
35468
|
-
})();
|
|
35469
|
-
const { data: queryPayload } = await client.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
35470
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
35471
|
-
});
|
|
35472
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
35473
|
-
const preparedPayload = prepareMembershipPayload(payload, 'communityUsers');
|
|
35474
|
-
const { communityUsers } = preparedPayload;
|
|
35475
|
-
const cachedAt = client.cache && Date.now();
|
|
35476
|
-
if (client.cache) {
|
|
35477
|
-
ingestInCache(preparedPayload, { cachedAt });
|
|
35478
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
35479
|
-
pushToCache(cacheKey, {
|
|
35480
|
-
communityUsers: communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
35481
|
-
paging,
|
|
35482
|
-
});
|
|
35483
|
-
}
|
|
35484
|
-
return { data: communityUsers, cachedAt, paging };
|
|
35485
|
-
};
|
|
35486
|
-
/**
|
|
35487
|
-
* ```js
|
|
35488
|
-
* import { queryCommunityMembers } from '@amityco/ts-sdk-react-native'
|
|
35489
|
-
* const communityMembers = await queryCommunityMembers(query)
|
|
35490
|
-
* ```
|
|
35491
|
-
*
|
|
35492
|
-
* Queries a paginable list of {@link Amity.InternalPost} objects from cache
|
|
35493
|
-
*
|
|
35494
|
-
* @param query The query parameters
|
|
35495
|
-
* @returns posts
|
|
35496
|
-
*
|
|
35497
|
-
* @category Post API
|
|
35498
|
-
*/
|
|
35499
|
-
queryCommunityMembers.locally = (query) => {
|
|
35500
|
-
var _a, _b;
|
|
35501
|
-
const client = getActiveClient();
|
|
35502
|
-
client.log('community/queryCommunityMembers', query);
|
|
35503
|
-
if (!client.cache)
|
|
35504
|
-
return;
|
|
35505
|
-
const _c = query !== null && query !== void 0 ? query : {}, { page, limit } = _c, params = __rest(_c, ["page", "limit"]);
|
|
35506
|
-
const options = (() => {
|
|
35507
|
-
if (page)
|
|
35508
|
-
return { token: page };
|
|
35509
|
-
if (limit)
|
|
35510
|
-
return { limit };
|
|
35511
|
-
return undefined;
|
|
35512
|
-
})();
|
|
35513
|
-
const cacheKey = ['communityUsers', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
35514
|
-
const { data, cachedAt } = (_a = pullFromCache(cacheKey)) !== null && _a !== void 0 ? _a : {};
|
|
35515
|
-
if (!(data === null || data === void 0 ? void 0 : data.communityUsers.length))
|
|
35516
|
-
return;
|
|
35517
|
-
const communityUsers = data.communityUsers
|
|
35518
|
-
.map(key => pullFromCache(['communityUsers', 'get', key]))
|
|
35519
|
-
.filter(Boolean)
|
|
35520
|
-
.map(({ data }) => data);
|
|
35521
|
-
const { paging } = data;
|
|
35522
|
-
return communityUsers.length === ((_b = data === null || data === void 0 ? void 0 : data.communityUsers) === null || _b === void 0 ? void 0 : _b.length)
|
|
35523
|
-
? { data: communityUsers, cachedAt, paging }
|
|
35524
|
-
: undefined;
|
|
35525
|
-
};
|
|
35526
|
-
|
|
35527
|
-
/*
|
|
35528
|
-
* Exported for testing
|
|
35529
|
-
* @hidden
|
|
35530
|
-
*/
|
|
35531
|
-
const applyFilter = (data, params) => {
|
|
35532
|
-
let communityMembers = filterByPropIntersection(data, 'roles', params.roles);
|
|
35533
|
-
if (params.memberships) {
|
|
35534
|
-
communityMembers = communityMembers.filter(({ communityMembership }) => {
|
|
35535
|
-
const membership = params.memberships;
|
|
35536
|
-
return membership.includes(communityMembership);
|
|
35537
|
-
});
|
|
35538
|
-
}
|
|
35539
|
-
if (params.search) {
|
|
35540
|
-
communityMembers = filterBySearchTerm(communityMembers, params.search);
|
|
35541
|
-
}
|
|
35542
|
-
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
35543
|
-
communityMembers = communityMembers.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
35544
|
-
return communityMembers;
|
|
35545
|
-
};
|
|
35546
|
-
/* begin_public_function
|
|
35547
|
-
id: community.membership.query
|
|
35548
|
-
*/
|
|
35549
|
-
/**
|
|
35550
|
-
* ```js
|
|
35551
|
-
* import { getMembers } from '@amityco/ts-sdk-react-native'
|
|
35552
|
-
*
|
|
35553
|
-
* let communityMembers = []
|
|
35554
|
-
* const unsub = getMembers({
|
|
35555
|
-
* communityId: Amity.Community['communityId'],
|
|
35556
|
-
* }, response => merge(communityMembers, response.data))
|
|
35557
|
-
* ```
|
|
35558
|
-
*
|
|
35559
|
-
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
35560
|
-
*
|
|
35561
|
-
* @param params for querying community users
|
|
35562
|
-
* @param callback the function to call when new data are available
|
|
35563
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
35564
|
-
*
|
|
35565
|
-
* @category Community Live Collection
|
|
35566
|
-
*/
|
|
35567
|
-
const getMembers = (params, callback, config) => {
|
|
35568
|
-
const { log, cache } = getActiveClient();
|
|
35569
|
-
if (!cache) {
|
|
35570
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
35571
|
-
}
|
|
35572
|
-
const timestamp = Date.now();
|
|
35573
|
-
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
35574
|
-
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
35575
|
-
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
35576
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
35577
|
-
const disposers = [];
|
|
35578
|
-
const cacheKey = ['communityUsers', 'collection', queryParams];
|
|
35579
|
-
const cacheByCommunityIdKey = [
|
|
35580
|
-
'communityUsers',
|
|
35581
|
-
'collection',
|
|
35582
|
-
{ communityId: params.communityId },
|
|
35583
|
-
];
|
|
35584
|
-
const responder = (data, isEventModel = false) => {
|
|
35585
|
-
var _a, _b;
|
|
35586
|
-
const communityMembers = (_a = data.data
|
|
35587
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
35588
|
-
.filter(Boolean)
|
|
35589
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
35590
|
-
callback({
|
|
35591
|
-
onNextPage: onFetch,
|
|
35592
|
-
data: isEventModel ? applyFilter(communityMembers, params) : communityMembers,
|
|
35593
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
35594
|
-
loading: data.loading,
|
|
35595
|
-
error: data.error,
|
|
35596
|
-
});
|
|
35597
|
-
};
|
|
35598
|
-
const realtimeRouter = (_) => (_, communityMembers) => {
|
|
35599
|
-
var _a;
|
|
35600
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35601
|
-
if (!collection) {
|
|
35602
|
-
return;
|
|
35603
|
-
}
|
|
35604
|
-
const communityMemberCacheIds = communityMembers
|
|
35605
|
-
.map(communityMember => {
|
|
35606
|
-
if (params.communityId !== communityMember.communityId) {
|
|
35607
|
-
return;
|
|
35608
|
-
}
|
|
35609
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
35610
|
-
communityId: params.communityId,
|
|
35611
|
-
userId: communityMember.userId,
|
|
35612
|
-
});
|
|
35613
|
-
return communityMemberCacheId;
|
|
35614
|
-
})
|
|
35615
|
-
.filter(isNonNullable);
|
|
35616
|
-
collection.data = [...new Set([...communityMemberCacheIds, ...collection.data])];
|
|
35617
|
-
pushToCache(cacheKey, collection);
|
|
35618
|
-
pushToCache(cacheByCommunityIdKey, collection);
|
|
35619
|
-
responder(collection, true);
|
|
35620
|
-
};
|
|
35621
|
-
const onFetch = (initial = false) => {
|
|
35622
|
-
var _a, _b;
|
|
35623
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
35624
|
-
const communityMembers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
35625
|
-
if (!initial && communityMembers.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
35626
|
-
return;
|
|
35627
|
-
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 }));
|
|
35628
|
-
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
35629
|
-
const data = {
|
|
35630
|
-
loading,
|
|
35631
|
-
error,
|
|
35632
|
-
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
35633
|
-
data: communityMembers,
|
|
35634
|
-
};
|
|
35635
|
-
if (result) {
|
|
35636
|
-
data.data = [
|
|
35637
|
-
...new Set([...communityMembers, ...result.map(getResolver('communityUsers'))]),
|
|
35638
|
-
];
|
|
35639
|
-
}
|
|
35640
|
-
pushToCache(cacheKey, data);
|
|
35641
|
-
pushToCache(cacheByCommunityIdKey, data);
|
|
35642
|
-
responder(data);
|
|
35643
|
-
}, queryOptions(policy));
|
|
35644
|
-
};
|
|
35645
|
-
disposers.push(onCommunityLeft(realtimeRouter()), onCommunityJoined(realtimeRouter()), onCommunityUserBanned(realtimeRouter()), onCommunityUserUnbanned(realtimeRouter()), onCommunityUserChanged(realtimeRouter()), onCommunityUserRoleAdded(realtimeRouter()), onCommunityUserRoleRemoved(realtimeRouter()));
|
|
35646
|
-
onFetch(true);
|
|
35647
|
-
return () => {
|
|
35648
|
-
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
35649
|
-
disposers.forEach(fn => fn());
|
|
35650
|
-
};
|
|
35651
|
-
};
|
|
35652
|
-
/* end_public_function */
|
|
35653
|
-
|
|
35654
|
-
var index$9 = /*#__PURE__*/Object.freeze({
|
|
35655
|
-
__proto__: null,
|
|
35656
|
-
addMembers: addMembers,
|
|
35657
|
-
removeMembers: removeMembers,
|
|
35658
|
-
applyFilter: applyFilter,
|
|
35659
|
-
getMembers: getMembers,
|
|
35660
|
-
onCommunityUserAdded: onCommunityUserAdded,
|
|
35661
|
-
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
35662
|
-
onCommunityUserBanned: onCommunityUserBanned,
|
|
35663
|
-
onCommunityUserChanged: onCommunityUserChanged,
|
|
35664
|
-
onCommunityUserUnbanned: onCommunityUserUnbanned,
|
|
35665
|
-
onCommunityUserRoleAdded: onCommunityUserRoleAdded,
|
|
35666
|
-
onCommunityUserRoleRemoved: onCommunityUserRoleRemoved,
|
|
35667
|
-
onCommunityJoined: onCommunityJoined,
|
|
35668
|
-
onCommunityLeft: onCommunityLeft
|
|
35669
|
-
});
|
|
35670
|
-
|
|
35671
35999
|
var index$8 = /*#__PURE__*/Object.freeze({
|
|
35672
36000
|
__proto__: null,
|
|
35673
|
-
Moderation: index$
|
|
35674
|
-
Membership: index$
|
|
36001
|
+
Moderation: index$9,
|
|
36002
|
+
Membership: index$a,
|
|
35675
36003
|
getCommunityByIds: getCommunities$1,
|
|
35676
36004
|
createCommunity: createCommunity,
|
|
35677
36005
|
updateCommunity: updateCommunity,
|