@amityco/ts-sdk-react-native 6.23.1-d8b4c4c.0 → 6.24.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.env +26 -26
- package/dist/@types/core/events.d.ts +0 -2
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +2 -4
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +1 -2
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -15
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +3 -19
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/client/api/secureLogout.d.ts +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/queryCommunities.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts +0 -1
- package/dist/communityRepository/communityMembership/observers/index.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities.d.ts +1 -1
- package/dist/communityRepository/utils/payload.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/index.cjs.js +463 -842
- package/dist/index.esm.js +438 -817
- package/dist/index.umd.js +4 -4
- package/dist/streamRepository/api/createStream.d.ts +4 -4
- package/dist/streamRepository/api/createStream.d.ts.map +1 -1
- package/dist/streamRepository/api/deleteStream.d.ts +4 -4
- package/dist/streamRepository/api/deleteStream.d.ts.map +1 -1
- package/dist/streamRepository/api/disposeStream.d.ts +4 -4
- package/dist/streamRepository/api/disposeStream.d.ts.map +1 -1
- package/dist/streamRepository/api/getStreams.d.ts +39 -0
- package/dist/streamRepository/api/getStreams.d.ts.map +1 -0
- package/dist/streamRepository/api/queryStreams.d.ts +4 -4
- package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/api/updateStream.d.ts.map +1 -1
- package/dist/streamRepository/events/index.d.ts +0 -2
- package/dist/streamRepository/events/index.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamRecorded.d.ts +2 -2
- package/dist/streamRepository/events/onStreamRecorded.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStarted.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStarted.d.ts.map +1 -1
- package/dist/streamRepository/events/onStreamStopped.d.ts +2 -2
- package/dist/streamRepository/events/onStreamStopped.d.ts.map +1 -1
- package/dist/streamRepository/internalApi/queryStreams.d.ts +3 -3
- package/dist/streamRepository/internalApi/queryStreams.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreamById.d.ts +0 -1
- package/dist/streamRepository/observers/getStreamById.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams.d.ts +17 -0
- package/dist/streamRepository/observers/getStreams.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +0 -1
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +0 -3
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +1 -5
- package/src/@types/core/model.ts +2 -4
- package/src/@types/core/payload.ts +1 -2
- package/src/@types/domains/community.ts +1 -25
- package/src/@types/domains/stream.ts +3 -23
- package/src/client/api/secureLogout.ts +1 -1
- package/src/communityRepository/api/createCommunity.ts +2 -5
- package/src/communityRepository/api/getCommunities.ts +1 -5
- package/src/communityRepository/api/getCommunity.ts +1 -5
- package/src/communityRepository/api/queryCommunities.ts +2 -2
- package/src/communityRepository/api/updateCommunity.ts +1 -5
- package/src/communityRepository/communityMembership/observers/getMembers.ts +128 -15
- package/src/communityRepository/communityMembership/observers/index.ts +0 -1
- package/src/communityRepository/observers/getCommunities.ts +150 -7
- package/src/communityRepository/observers/searchCommunities.ts +1 -1
- package/src/communityRepository/utils/payload.ts +1 -35
- package/src/core/model/idResolvers.ts +0 -1
- package/src/core/model/index.ts +0 -1
- package/src/streamRepository/api/createStream.ts +5 -8
- package/src/streamRepository/api/deleteStream.ts +4 -6
- package/src/streamRepository/api/disposeStream.ts +5 -5
- package/src/streamRepository/api/getStreams.ts +81 -0
- package/src/streamRepository/api/queryStreams.ts +4 -4
- package/src/streamRepository/api/updateStream.ts +1 -2
- package/src/streamRepository/events/index.ts +0 -2
- package/src/streamRepository/events/onStreamRecorded.ts +2 -4
- package/src/streamRepository/events/onStreamStarted.ts +2 -4
- package/src/streamRepository/events/onStreamStopped.ts +2 -4
- package/src/streamRepository/internalApi/queryStreams.ts +3 -3
- package/src/streamRepository/observers/getStreamById.ts +5 -18
- package/src/streamRepository/observers/getStreams.ts +152 -0
- package/src/streamRepository/observers/tests/getStreamById.test.ts +1 -1
- package/src/utils/linkedObject/index.ts +0 -2
- package/src/utils/liveObject.ts +0 -3
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts +0 -14
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts +0 -9
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts +0 -15
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts +0 -10
- package/dist/communityRepository/communityMembership/observers/getMembers/enums.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts +0 -14
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts +0 -9
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts +0 -15
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts +0 -10
- package/dist/communityRepository/communityMembership/observers/searchMembers/enums.d.ts.map +0 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts +0 -20
- package/dist/communityRepository/communityMembership/observers/searchMembers.d.ts.map +0 -1
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts +0 -2
- package/dist/communityRepository/utils/saveCommunityUsers.d.ts.map +0 -1
- package/dist/streamRepository/events/onStreamFlagged.d.ts +0 -17
- package/dist/streamRepository/events/onStreamFlagged.d.ts.map +0 -1
- package/dist/streamRepository/events/onStreamTerminated.d.ts +0 -17
- package/dist/streamRepository/events/onStreamTerminated.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts +0 -14
- package/dist/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +0 -14
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts +0 -15
- package/dist/streamRepository/observers/getStreams/GetStreamsQueryStreamController.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts +0 -2
- package/dist/streamRepository/observers/getStreams/getStreams.d.ts.map +0 -1
- package/dist/streamRepository/observers/getStreams/index.d.ts +0 -2
- package/dist/streamRepository/observers/getStreams/index.d.ts.map +0 -1
- package/dist/utils/linkedObject/streamLinkedObject.d.ts +0 -2
- package/dist/utils/linkedObject/streamLinkedObject.d.ts.map +0 -1
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +0 -152
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersPaginationController.ts +0 -26
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersQueryStreamController.ts +0 -114
- package/src/communityRepository/communityMembership/observers/getMembers/enums.ts +0 -9
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +0 -130
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersPaginationController.ts +0 -29
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersQueryStreamController.ts +0 -105
- package/src/communityRepository/communityMembership/observers/searchMembers/enums.ts +0 -9
- package/src/communityRepository/communityMembership/observers/searchMembers.ts +0 -60
- package/src/communityRepository/utils/saveCommunityUsers.ts +0 -16
- package/src/streamRepository/events/onStreamFlagged.ts +0 -37
- package/src/streamRepository/events/onStreamTerminated.ts +0 -37
- package/src/streamRepository/observers/getStreams/GetStreamsLiveCollectionController.ts +0 -114
- package/src/streamRepository/observers/getStreams/GetStreamsPageController.ts +0 -23
- package/src/streamRepository/observers/getStreams/GetStreamsQueryStreamController.ts +0 -83
- package/src/streamRepository/observers/getStreams/getStreams.ts +0 -32
- package/src/streamRepository/observers/getStreams/index.ts +0 -1
- package/src/utils/linkedObject/streamLinkedObject.ts +0 -11
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.
|
|
121
|
-
return 'v6.
|
|
120
|
+
// the string ''v6.24.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
121
|
+
return 'v6.24.0-cjs';
|
|
122
122
|
}
|
|
123
123
|
catch (error) {
|
|
124
124
|
return '__dev__';
|
|
@@ -546,7 +546,6 @@ const idResolvers = {
|
|
|
546
546
|
reaction: ({ referenceType, referenceId }) => `${referenceType}#${referenceId}`,
|
|
547
547
|
reactor: ({ reactionId }) => reactionId,
|
|
548
548
|
stream: ({ streamId }) => streamId,
|
|
549
|
-
streamModeration: ({ streamId }) => streamId,
|
|
550
549
|
follow: ({ from, to }) => `${from}#${to}`,
|
|
551
550
|
followInfo: ({ userId }) => userId,
|
|
552
551
|
followCount: ({ userId }) => userId,
|
|
@@ -596,7 +595,6 @@ const PAYLOAD2MODEL = {
|
|
|
596
595
|
reactors: 'reactor',
|
|
597
596
|
reactions: 'reaction',
|
|
598
597
|
videoStreamings: 'stream',
|
|
599
|
-
videoStreamModerations: 'streamModeration',
|
|
600
598
|
follows: 'follow',
|
|
601
599
|
followCounts: 'followCount',
|
|
602
600
|
feeds: 'feed',
|
|
@@ -5271,13 +5269,6 @@ const storyLinkedObject = (story) => {
|
|
|
5271
5269
|
} });
|
|
5272
5270
|
};
|
|
5273
5271
|
|
|
5274
|
-
const streamLinkedObject = (stream) => {
|
|
5275
|
-
return Object.assign(Object.assign({}, stream), { get moderation() {
|
|
5276
|
-
var _a;
|
|
5277
|
-
return (_a = pullFromCache(['streamModeration', 'get', stream.streamId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5278
|
-
} });
|
|
5279
|
-
};
|
|
5280
|
-
|
|
5281
5272
|
const categoryLinkedObject = (category) => {
|
|
5282
5273
|
return Object.assign(Object.assign({}, category), { get avatar() {
|
|
5283
5274
|
var _a;
|
|
@@ -5746,7 +5737,6 @@ const LinkedObject = {
|
|
|
5746
5737
|
post: postLinkedObject,
|
|
5747
5738
|
user: userLinkedObject,
|
|
5748
5739
|
category: categoryLinkedObject,
|
|
5749
|
-
stream: streamLinkedObject,
|
|
5750
5740
|
story: storyLinkedObject,
|
|
5751
5741
|
storyTarget: storyTargetLinkedObject,
|
|
5752
5742
|
message: messageLinkedObject,
|
|
@@ -9116,7 +9106,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
9116
9106
|
*/
|
|
9117
9107
|
/**
|
|
9118
9108
|
* ```js
|
|
9119
|
-
* import { Client } from '@amityco/ts-sdk
|
|
9109
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
9120
9110
|
* const success = await Client.secureLogout()
|
|
9121
9111
|
* ```
|
|
9122
9112
|
*
|
|
@@ -9472,9 +9462,6 @@ function isEqual(x, y) {
|
|
|
9472
9462
|
}));
|
|
9473
9463
|
}
|
|
9474
9464
|
|
|
9475
|
-
/**
|
|
9476
|
-
* @deprecated This function is deprecated
|
|
9477
|
-
*/
|
|
9478
9465
|
const liveObject = (id, callback, key, fetcher, eventHandlers, options) => {
|
|
9479
9466
|
const { forceDispatch, callbackDataSelector, callbackFilter } = Object.assign({ forceDispatch: false, callbackDataSelector: (data) => data }, options);
|
|
9480
9467
|
const { cache } = getActiveClient();
|
|
@@ -17549,7 +17536,7 @@ const getMembers$1 = (params, callback, config) => {
|
|
|
17549
17536
|
*
|
|
17550
17537
|
* @category Channel Live Collection
|
|
17551
17538
|
*/
|
|
17552
|
-
const searchMembers
|
|
17539
|
+
const searchMembers = (params, callback, config) => {
|
|
17553
17540
|
return getMembers$1(params, callback);
|
|
17554
17541
|
};
|
|
17555
17542
|
/* end_public_function */
|
|
@@ -17560,7 +17547,7 @@ var index$d = /*#__PURE__*/Object.freeze({
|
|
|
17560
17547
|
removeMembers: removeMembers$1,
|
|
17561
17548
|
applyFilter: applyFilter$1,
|
|
17562
17549
|
getMembers: getMembers$1,
|
|
17563
|
-
searchMembers: searchMembers
|
|
17550
|
+
searchMembers: searchMembers
|
|
17564
17551
|
});
|
|
17565
17552
|
|
|
17566
17553
|
/* begin_public_function
|
|
@@ -17803,30 +17790,12 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
17803
17790
|
prepareChannelPayload: prepareChannelPayload
|
|
17804
17791
|
});
|
|
17805
17792
|
|
|
17806
|
-
const saveCommunityUsers = (communities, communityUsers) => {
|
|
17807
|
-
if (communities.length === 0 || communityUsers.length === 0)
|
|
17808
|
-
return;
|
|
17809
|
-
communities.forEach(({ communityId }) => {
|
|
17810
|
-
const collection = communityUsers.filter(({ communityId: userCommunityId }) => communityId === userCommunityId);
|
|
17811
|
-
pushToCache(['communityUsers', 'collection', communityId], collection);
|
|
17812
|
-
});
|
|
17813
|
-
};
|
|
17814
|
-
|
|
17815
17793
|
const getMatchPostSetting = (value) => {
|
|
17816
17794
|
var _a;
|
|
17817
17795
|
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
17818
17796
|
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
17819
17797
|
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
17820
17798
|
};
|
|
17821
|
-
const convertCommunityUsersToUniqueObject = (communityUsers) => {
|
|
17822
|
-
if (!communityUsers)
|
|
17823
|
-
return communityUsers;
|
|
17824
|
-
const result = {};
|
|
17825
|
-
communityUsers.forEach(user => {
|
|
17826
|
-
result[user.userId] = user;
|
|
17827
|
-
});
|
|
17828
|
-
return result;
|
|
17829
|
-
};
|
|
17830
17799
|
const prepareCommunityPayload = (rawPayload) => {
|
|
17831
17800
|
// Unpack community payload by mapping payload field to postSetting value.
|
|
17832
17801
|
const communities = rawPayload.communities.map((_a) => {
|
|
@@ -17836,18 +17805,7 @@ const prepareCommunityPayload = (rawPayload) => {
|
|
|
17836
17805
|
onlyAdminCanPost,
|
|
17837
17806
|
}) }, restCommunityPayload));
|
|
17838
17807
|
});
|
|
17839
|
-
const
|
|
17840
|
-
var _a;
|
|
17841
|
-
const users = (_a = pullFromCache([
|
|
17842
|
-
'communityUsers',
|
|
17843
|
-
'collection',
|
|
17844
|
-
communityId,
|
|
17845
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17846
|
-
if (!users)
|
|
17847
|
-
return acc;
|
|
17848
|
-
return Object.assign(Object.assign({}, convertCommunityUsersToUniqueObject(users)), acc);
|
|
17849
|
-
}, convertCommunityUsersToUniqueObject(rawPayload.communityUsers));
|
|
17850
|
-
const communityUsers = withUsers(Object.values(mergeCommunityUsers));
|
|
17808
|
+
const communityUsers = withUsers(rawPayload.communityUsers);
|
|
17851
17809
|
const communityWithMembershipStatus = updateMembershipStatus(communities, communityUsers);
|
|
17852
17810
|
return Object.assign(Object.assign({}, rawPayload), { communities: communityWithMembershipStatus, communityUsers });
|
|
17853
17811
|
};
|
|
@@ -17881,10 +17839,8 @@ const getCommunities$1 = async (communityIds) => {
|
|
|
17881
17839
|
});
|
|
17882
17840
|
const data = prepareCommunityPayload(payload);
|
|
17883
17841
|
const cachedAt = client.cache && Date.now();
|
|
17884
|
-
if (client.cache)
|
|
17842
|
+
if (client.cache)
|
|
17885
17843
|
ingestInCache(data, { cachedAt });
|
|
17886
|
-
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17887
|
-
}
|
|
17888
17844
|
return {
|
|
17889
17845
|
data: data.communities,
|
|
17890
17846
|
cachedAt,
|
|
@@ -17946,10 +17902,8 @@ const createCommunity = async (bundle) => {
|
|
|
17946
17902
|
fireEvent('community.created', payload);
|
|
17947
17903
|
const data = prepareCommunityPayload(payload);
|
|
17948
17904
|
const cachedAt = client.cache && Date.now();
|
|
17949
|
-
if (client.cache)
|
|
17905
|
+
if (client.cache)
|
|
17950
17906
|
ingestInCache(data, { cachedAt });
|
|
17951
|
-
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17952
|
-
}
|
|
17953
17907
|
const { communities } = data;
|
|
17954
17908
|
return {
|
|
17955
17909
|
data: communities[0],
|
|
@@ -17983,10 +17937,8 @@ const updateCommunity = async (communityId, patch) => {
|
|
|
17983
17937
|
fireEvent('community.updated', payload);
|
|
17984
17938
|
const data = prepareCommunityPayload(payload);
|
|
17985
17939
|
const cachedAt = client.cache && Date.now();
|
|
17986
|
-
if (client.cache)
|
|
17940
|
+
if (client.cache)
|
|
17987
17941
|
ingestInCache(data, { cachedAt });
|
|
17988
|
-
saveCommunityUsers(data.communities, data.communityUsers);
|
|
17989
|
-
}
|
|
17990
17942
|
const { communities } = data;
|
|
17991
17943
|
return {
|
|
17992
17944
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -18016,10 +17968,8 @@ const getCommunity$1 = async (communityId) => {
|
|
|
18016
17968
|
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
18017
17969
|
const data = prepareCommunityPayload(payload);
|
|
18018
17970
|
const cachedAt = client.cache && Date.now();
|
|
18019
|
-
if (client.cache)
|
|
17971
|
+
if (client.cache)
|
|
18020
17972
|
ingestInCache(data, { cachedAt });
|
|
18021
|
-
saveCommunityUsers(data.communities, data.communityUsers);
|
|
18022
|
-
}
|
|
18023
17973
|
const { communities } = data;
|
|
18024
17974
|
return {
|
|
18025
17975
|
data: communities.find(community => community.communityId === communityId),
|
|
@@ -18562,7 +18512,7 @@ const observeCommunity = (communityId, callback) => {
|
|
|
18562
18512
|
* TODO: handle cache receive cache option, and cache policy
|
|
18563
18513
|
* TODO: check if querybyIds is supported
|
|
18564
18514
|
*/
|
|
18565
|
-
class CommunitiesPaginationController
|
|
18515
|
+
class CommunitiesPaginationController extends PaginationController {
|
|
18566
18516
|
async getRequest(queryParams, token) {
|
|
18567
18517
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
18568
18518
|
const options = token ? { token } : { limit };
|
|
@@ -18573,7 +18523,7 @@ class CommunitiesPaginationController$1 extends PaginationController {
|
|
|
18573
18523
|
}
|
|
18574
18524
|
}
|
|
18575
18525
|
|
|
18576
|
-
class CommunitiesQueryStreamController
|
|
18526
|
+
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
18577
18527
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
18578
18528
|
super(query, cacheKey);
|
|
18579
18529
|
this.notifyChange = notifyChange;
|
|
@@ -18615,22 +18565,22 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
|
18615
18565
|
}
|
|
18616
18566
|
}
|
|
18617
18567
|
|
|
18618
|
-
var EnumCommunityActions
|
|
18568
|
+
var EnumCommunityActions;
|
|
18619
18569
|
(function (EnumCommunityActions) {
|
|
18620
18570
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
18621
18571
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
18622
18572
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
18623
|
-
})(EnumCommunityActions
|
|
18573
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
18624
18574
|
|
|
18625
18575
|
/* eslint-disable no-use-before-define */
|
|
18626
18576
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
18627
18577
|
constructor(query, callback) {
|
|
18628
18578
|
const queryStreamId = hash__default["default"](query);
|
|
18629
18579
|
const cacheKey = ['community', 'collection', queryStreamId];
|
|
18630
|
-
const paginationController = new CommunitiesPaginationController
|
|
18580
|
+
const paginationController = new CommunitiesPaginationController(query);
|
|
18631
18581
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
18632
18582
|
this.query = query;
|
|
18633
|
-
this.queryStreamController = new CommunitiesQueryStreamController
|
|
18583
|
+
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
18634
18584
|
this.callback = callback.bind(this);
|
|
18635
18585
|
this.loadPage({ initial: true });
|
|
18636
18586
|
}
|
|
@@ -18652,8 +18602,8 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18652
18602
|
}
|
|
18653
18603
|
startSubscription() {
|
|
18654
18604
|
return this.queryStreamController.subscribeRTE([
|
|
18655
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions
|
|
18656
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions
|
|
18605
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
18606
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
18657
18607
|
]);
|
|
18658
18608
|
}
|
|
18659
18609
|
notifyChange({ origin, loading, error }) {
|
|
@@ -18699,7 +18649,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18699
18649
|
*/
|
|
18700
18650
|
/**
|
|
18701
18651
|
* ```js
|
|
18702
|
-
* import { CommunityRepository } from '@amityco/ts-sdk
|
|
18652
|
+
* import { CommunityRepository } from '@amityco/ts-sdk'
|
|
18703
18653
|
*
|
|
18704
18654
|
* let communities = []
|
|
18705
18655
|
* const unsub = CommunityRepository.searchCommunities({
|
|
@@ -18734,163 +18684,50 @@ const searchCommunities = (params, callback, config) => {
|
|
|
18734
18684
|
/* end_public_function */
|
|
18735
18685
|
|
|
18736
18686
|
/**
|
|
18737
|
-
*
|
|
18738
|
-
*
|
|
18687
|
+
* ```js
|
|
18688
|
+
* import { queryCommunities } from '@amityco/ts-sdk-react-native'
|
|
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
|
|
18739
18700
|
*/
|
|
18740
|
-
|
|
18741
|
-
|
|
18742
|
-
|
|
18743
|
-
|
|
18744
|
-
|
|
18745
|
-
|
|
18746
|
-
|
|
18747
|
-
|
|
18748
|
-
|
|
18749
|
-
|
|
18750
|
-
|
|
18751
|
-
|
|
18752
|
-
(
|
|
18753
|
-
|
|
18754
|
-
|
|
18755
|
-
|
|
18756
|
-
}
|
|
18757
|
-
|
|
18758
|
-
|
|
18759
|
-
|
|
18760
|
-
|
|
18761
|
-
|
|
18762
|
-
|
|
18763
|
-
|
|
18764
|
-
|
|
18765
|
-
const
|
|
18766
|
-
|
|
18767
|
-
const cachedAt = client.cache && Date.now();
|
|
18768
|
-
if (client.cache) {
|
|
18769
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
18770
|
-
}
|
|
18771
|
-
}
|
|
18772
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
18773
|
-
var _a, _b;
|
|
18774
|
-
if (refresh) {
|
|
18775
|
-
pushToCache(this.cacheKey, {
|
|
18776
|
-
data: response.communities.map(getResolver('community')),
|
|
18777
|
-
});
|
|
18778
|
-
}
|
|
18779
|
-
else {
|
|
18780
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18781
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18782
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
18783
|
-
}
|
|
18784
|
-
}
|
|
18785
|
-
reactor(action) {
|
|
18786
|
-
return (community) => {
|
|
18787
|
-
var _a;
|
|
18788
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18789
|
-
if (!collection)
|
|
18790
|
-
return;
|
|
18791
|
-
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
18792
|
-
return;
|
|
18793
|
-
}
|
|
18794
|
-
/*
|
|
18795
|
-
* Simply update collection and let responder decide what to do with data
|
|
18796
|
-
*/
|
|
18797
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
18798
|
-
pushToCache(this.cacheKey, collection);
|
|
18799
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
18800
|
-
};
|
|
18801
|
-
}
|
|
18802
|
-
subscribeRTE(createSubscriber) {
|
|
18803
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
18804
|
-
}
|
|
18805
|
-
}
|
|
18806
|
-
|
|
18807
|
-
/* eslint-disable no-use-before-define */
|
|
18808
|
-
class CommunityLiveCollectionController extends LiveCollectionController {
|
|
18809
|
-
constructor(query, callback) {
|
|
18810
|
-
const queryStreamId = hash__default["default"](query);
|
|
18811
|
-
const cacheKey = ['community', 'collection', queryStreamId];
|
|
18812
|
-
const paginationController = new CommunitiesPaginationController(query);
|
|
18813
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
18814
|
-
this.query = query;
|
|
18815
|
-
this.queryStreamController = new CommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
18816
|
-
this.callback = callback.bind(this);
|
|
18817
|
-
this.loadPage({ initial: true });
|
|
18818
|
-
}
|
|
18819
|
-
setup() {
|
|
18820
|
-
var _a;
|
|
18821
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18822
|
-
if (!collection) {
|
|
18823
|
-
pushToCache(this.cacheKey, {
|
|
18824
|
-
data: [],
|
|
18825
|
-
params: {},
|
|
18826
|
-
});
|
|
18827
|
-
}
|
|
18828
|
-
}
|
|
18829
|
-
async persistModel(queryPayload) {
|
|
18830
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
18831
|
-
}
|
|
18832
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
18833
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
18834
|
-
}
|
|
18835
|
-
startSubscription() {
|
|
18836
|
-
return this.queryStreamController.subscribeRTE([
|
|
18837
|
-
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
18838
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
18839
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
18840
|
-
]);
|
|
18841
|
-
}
|
|
18842
|
-
notifyChange({ origin, loading, error }) {
|
|
18843
|
-
var _a, _b;
|
|
18844
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18845
|
-
if (!collection)
|
|
18846
|
-
return;
|
|
18847
|
-
const data = this.applyFilter((_b = collection.data
|
|
18848
|
-
.map(id => pullFromCache(['community', 'get', id]))
|
|
18849
|
-
.filter(Boolean)
|
|
18850
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
18851
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
18852
|
-
return;
|
|
18853
|
-
this.callback({
|
|
18854
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
18855
|
-
data,
|
|
18856
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
18857
|
-
loading,
|
|
18858
|
-
error,
|
|
18859
|
-
});
|
|
18860
|
-
}
|
|
18861
|
-
applyFilter(data) {
|
|
18862
|
-
const { userId } = getActiveClient();
|
|
18863
|
-
let communities = data;
|
|
18864
|
-
if (this.query.includeDeleted) {
|
|
18865
|
-
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18866
|
-
}
|
|
18867
|
-
if (this.query.categoryId) {
|
|
18868
|
-
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(this.query.categoryId); });
|
|
18869
|
-
}
|
|
18870
|
-
if (this.query.tags) {
|
|
18871
|
-
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); }); });
|
|
18872
|
-
}
|
|
18873
|
-
if (this.query.membership && userId) {
|
|
18874
|
-
communities = filterByCommunityMembership(communities, this.query.membership, userId);
|
|
18875
|
-
}
|
|
18876
|
-
if (!this.query.displayName) {
|
|
18877
|
-
const sortFn = (() => {
|
|
18878
|
-
switch (this.query.sortBy) {
|
|
18879
|
-
case 'firstCreated':
|
|
18880
|
-
return sortByFirstCreated;
|
|
18881
|
-
case 'lastCreated':
|
|
18882
|
-
return sortByLastCreated;
|
|
18883
|
-
case 'displayName':
|
|
18884
|
-
return sortByDisplayName;
|
|
18885
|
-
default:
|
|
18886
|
-
return sortByLastCreated;
|
|
18887
|
-
}
|
|
18888
|
-
})();
|
|
18889
|
-
communities = communities.sort(sortFn);
|
|
18890
|
-
}
|
|
18891
|
-
return communities;
|
|
18701
|
+
const queryCommunities = async (query) => {
|
|
18702
|
+
const client = getActiveClient();
|
|
18703
|
+
client.log('channel/queryCommunities', query);
|
|
18704
|
+
// safe decapsulation
|
|
18705
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page, limit = 10 } = _a, params = __rest(_a, ["page", "limit"]);
|
|
18706
|
+
const _b = params !== null && params !== void 0 ? params : {}, { displayName, membership, includeDeleted } = _b, restParams = __rest(_b, ["displayName", "membership", "includeDeleted"]);
|
|
18707
|
+
const options = (() => {
|
|
18708
|
+
if (page)
|
|
18709
|
+
return { token: page };
|
|
18710
|
+
if (limit)
|
|
18711
|
+
return { limit };
|
|
18712
|
+
return undefined;
|
|
18713
|
+
})();
|
|
18714
|
+
// API-FIX: parameters should be querystring.
|
|
18715
|
+
// API-FIX: backend doesn't answer Amity.Response
|
|
18716
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<CommunityPayload>>>(
|
|
18717
|
+
const { data } = await client.http.get(`/api/v3/communities`, {
|
|
18718
|
+
params: Object.assign(Object.assign({}, restParams), { isDeleted: inferIsDeleted(includeDeleted), keyword: displayName, filter: membership, options }),
|
|
18719
|
+
});
|
|
18720
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18721
|
+
const unpackedPayload = prepareCommunityPayload(payload);
|
|
18722
|
+
const { communities } = unpackedPayload;
|
|
18723
|
+
const cachedAt = client.cache && Date.now();
|
|
18724
|
+
if (client.cache) {
|
|
18725
|
+
ingestInCache(unpackedPayload, { cachedAt });
|
|
18726
|
+
const cacheKey = ['community', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
18727
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')), paging });
|
|
18892
18728
|
}
|
|
18893
|
-
}
|
|
18729
|
+
return { data: communities, cachedAt, paging };
|
|
18730
|
+
};
|
|
18894
18731
|
|
|
18895
18732
|
/* begin_public_function
|
|
18896
18733
|
id: community.query
|
|
@@ -18914,41 +18751,124 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
18914
18751
|
* @category Community Live Collection
|
|
18915
18752
|
*/
|
|
18916
18753
|
const getCommunities = (params, callback, config) => {
|
|
18917
|
-
const { log, cache } = getActiveClient();
|
|
18754
|
+
const { log, cache, userId } = getActiveClient();
|
|
18918
18755
|
if (!cache) {
|
|
18919
18756
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
18920
18757
|
}
|
|
18921
18758
|
const timestamp = Date.now();
|
|
18922
18759
|
log(`getCommunities(tmpid: ${timestamp}) > listen`);
|
|
18923
|
-
const
|
|
18924
|
-
const
|
|
18925
|
-
const
|
|
18926
|
-
disposers
|
|
18927
|
-
|
|
18928
|
-
|
|
18929
|
-
|
|
18760
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
18761
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
18762
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
18763
|
+
const disposers = [];
|
|
18764
|
+
const cacheKey = ['community', 'collection', queryParams];
|
|
18765
|
+
const responder = (data) => {
|
|
18766
|
+
var _a, _b;
|
|
18767
|
+
let communities = (_a = data.data
|
|
18768
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
18769
|
+
.filter(Boolean)
|
|
18770
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
18771
|
+
communities = filterByStringComparePartially(communities, 'displayName', params.displayName);
|
|
18772
|
+
if (!params.includeDeleted) {
|
|
18773
|
+
communities = filterByPropEquality(communities, 'isDeleted', false);
|
|
18774
|
+
}
|
|
18775
|
+
if (params.categoryId) {
|
|
18776
|
+
communities = communities.filter(c => { var _a; return (_a = c.categoryIds) === null || _a === void 0 ? void 0 : _a.includes(params.categoryId); });
|
|
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); }); });
|
|
18780
|
+
}
|
|
18781
|
+
if (params.membership && userId) {
|
|
18782
|
+
communities = filterByCommunityMembership(communities, params.membership, userId);
|
|
18783
|
+
}
|
|
18784
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
18785
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
18786
|
+
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
18787
|
+
}
|
|
18788
|
+
/*
|
|
18789
|
+
* The server returns communities with empty | null displayName's first before
|
|
18790
|
+
* returning sorted list of communities with displayNames
|
|
18791
|
+
*
|
|
18792
|
+
* This section needs to be updated as displayNames can be null as well
|
|
18793
|
+
*/
|
|
18794
|
+
if (sortBy === 'displayName') {
|
|
18795
|
+
communities = communities
|
|
18796
|
+
// this needs to be aligned with the backend data type
|
|
18797
|
+
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
18798
|
+
// @ts-ignore
|
|
18799
|
+
.sort(sortByDisplayName);
|
|
18800
|
+
}
|
|
18801
|
+
callback({
|
|
18802
|
+
onNextPage: onFetch,
|
|
18803
|
+
data: communities,
|
|
18804
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
18805
|
+
loading: data.loading,
|
|
18806
|
+
error: data.error,
|
|
18807
|
+
});
|
|
18930
18808
|
};
|
|
18931
|
-
|
|
18932
|
-
|
|
18933
|
-
|
|
18934
|
-
|
|
18935
|
-
|
|
18936
|
-
|
|
18937
|
-
|
|
18938
|
-
|
|
18939
|
-
|
|
18940
|
-
|
|
18941
|
-
|
|
18942
|
-
|
|
18943
|
-
|
|
18944
|
-
|
|
18945
|
-
|
|
18946
|
-
|
|
18947
|
-
|
|
18948
|
-
|
|
18949
|
-
|
|
18950
|
-
|
|
18951
|
-
|
|
18809
|
+
const realtimeRouter = (_) => (community) => {
|
|
18810
|
+
var _a;
|
|
18811
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18812
|
+
if (!collection)
|
|
18813
|
+
return;
|
|
18814
|
+
/*
|
|
18815
|
+
* Simply update collection and let responder decide what to do with data
|
|
18816
|
+
*/
|
|
18817
|
+
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
18818
|
+
pushToCache(cacheKey, collection);
|
|
18819
|
+
responder(collection);
|
|
18820
|
+
};
|
|
18821
|
+
const onFetch = (initial = false) => {
|
|
18822
|
+
var _a, _b;
|
|
18823
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18824
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
18825
|
+
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
18826
|
+
return;
|
|
18827
|
+
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 }));
|
|
18828
|
+
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
18829
|
+
const data = {
|
|
18830
|
+
loading,
|
|
18831
|
+
error,
|
|
18832
|
+
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
18833
|
+
data: communities,
|
|
18834
|
+
};
|
|
18835
|
+
if (result) {
|
|
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);
|
|
18846
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
18847
|
+
return () => {
|
|
18848
|
+
log(`getCommunities(tmpid: ${timestamp}) > dispose`);
|
|
18849
|
+
disposers.forEach(fn => fn());
|
|
18850
|
+
};
|
|
18851
|
+
};
|
|
18852
|
+
/* end_public_function */
|
|
18853
|
+
|
|
18854
|
+
/* begin_public_function
|
|
18855
|
+
id: community.get
|
|
18856
|
+
*/
|
|
18857
|
+
/**
|
|
18858
|
+
* ```js
|
|
18859
|
+
* import { CommunityRepository } from '@amityco/ts-sdk-react-native';
|
|
18860
|
+
*
|
|
18861
|
+
* let community;
|
|
18862
|
+
*
|
|
18863
|
+
* const unsub = CommunityRepository.getCommunity(communityId, response => {
|
|
18864
|
+
* community = response.data;
|
|
18865
|
+
* });
|
|
18866
|
+
* ```
|
|
18867
|
+
*
|
|
18868
|
+
* Observe all mutation on a given {@link Amity.Community}
|
|
18869
|
+
*
|
|
18870
|
+
* @param communityId the ID of the message to observe
|
|
18871
|
+
* @param callback the function to call when new data are available
|
|
18952
18872
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community
|
|
18953
18873
|
*
|
|
18954
18874
|
* @category Community Live Object
|
|
@@ -19451,187 +19371,87 @@ const removeMembers = async (communityId, userIds) => {
|
|
|
19451
19371
|
/* end_public_function */
|
|
19452
19372
|
|
|
19453
19373
|
/**
|
|
19454
|
-
*
|
|
19455
|
-
*
|
|
19456
|
-
|
|
19457
|
-
|
|
19458
|
-
|
|
19459
|
-
|
|
19460
|
-
|
|
19461
|
-
|
|
19462
|
-
|
|
19463
|
-
|
|
19464
|
-
|
|
19465
|
-
|
|
19466
|
-
|
|
19467
|
-
|
|
19468
|
-
|
|
19469
|
-
(
|
|
19470
|
-
|
|
19471
|
-
|
|
19472
|
-
|
|
19473
|
-
|
|
19474
|
-
|
|
19475
|
-
|
|
19476
|
-
|
|
19477
|
-
})(
|
|
19478
|
-
|
|
19479
|
-
|
|
19480
|
-
|
|
19481
|
-
|
|
19482
|
-
|
|
19483
|
-
|
|
19484
|
-
|
|
19485
|
-
|
|
19486
|
-
|
|
19487
|
-
const
|
|
19488
|
-
|
|
19489
|
-
|
|
19490
|
-
|
|
19491
|
-
}
|
|
19492
|
-
}
|
|
19493
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
19494
|
-
var _a, _b;
|
|
19495
|
-
if (refresh) {
|
|
19496
|
-
pushToCache(this.cacheKey, {
|
|
19497
|
-
data: response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19498
|
-
});
|
|
19499
|
-
}
|
|
19500
|
-
else {
|
|
19501
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19502
|
-
const communityUsers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
19503
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [
|
|
19504
|
-
...new Set([
|
|
19505
|
-
...communityUsers,
|
|
19506
|
-
...response.communityUsers.map(({ communityId, userId }) => getResolver('communityUsers')({ communityId, userId })),
|
|
19507
|
-
]),
|
|
19508
|
-
] }));
|
|
19509
|
-
}
|
|
19510
|
-
}
|
|
19511
|
-
reactor(action) {
|
|
19512
|
-
return (community, communityMembers) => {
|
|
19513
|
-
var _a;
|
|
19514
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19515
|
-
if (!collection)
|
|
19516
|
-
return;
|
|
19517
|
-
if (action === EnumCommunityMemberActions$1.OnCommunityUserRoleAdded &&
|
|
19518
|
-
this.query.sortBy === 'displayName') {
|
|
19519
|
-
return;
|
|
19520
|
-
}
|
|
19521
|
-
communityMembers.forEach(communityMember => {
|
|
19522
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
19523
|
-
communityId: this.query.communityId,
|
|
19524
|
-
userId: communityMember.userId,
|
|
19525
|
-
});
|
|
19526
|
-
if (communityMember.communityMembership === 'none') {
|
|
19527
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
19528
|
-
}
|
|
19529
|
-
else if (!collection.data.includes(communityMemberCacheId)) {
|
|
19530
|
-
collection.data = [communityMemberCacheId, ...collection.data];
|
|
19531
|
-
}
|
|
19532
|
-
});
|
|
19533
|
-
pushToCache(this.cacheKey, collection);
|
|
19534
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19535
|
-
};
|
|
19536
|
-
}
|
|
19537
|
-
subscribeRTE(createSubscriber) {
|
|
19538
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19539
|
-
}
|
|
19540
|
-
}
|
|
19541
|
-
|
|
19542
|
-
/* eslint-disable no-use-before-define */
|
|
19543
|
-
class CommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
19544
|
-
constructor(query, callback) {
|
|
19545
|
-
const queryStreamId = hash__default["default"](query);
|
|
19546
|
-
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
19547
|
-
const paginationController = new CommunityMembersPaginationController(query);
|
|
19548
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19549
|
-
this.query = query;
|
|
19550
|
-
this.queryStreamController = new CommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19551
|
-
this.callback = callback.bind(this);
|
|
19552
|
-
this.loadPage({ initial: true });
|
|
19553
|
-
}
|
|
19554
|
-
setup() {
|
|
19555
|
-
var _a;
|
|
19556
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19557
|
-
if (!collection) {
|
|
19558
|
-
pushToCache(this.cacheKey, {
|
|
19559
|
-
data: [],
|
|
19560
|
-
params: {},
|
|
19561
|
-
});
|
|
19562
|
-
}
|
|
19563
|
-
}
|
|
19564
|
-
async persistModel(queryPayload) {
|
|
19565
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
19566
|
-
}
|
|
19567
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
19568
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
19569
|
-
}
|
|
19570
|
-
startSubscription() {
|
|
19571
|
-
return this.queryStreamController.subscribeRTE([
|
|
19572
|
-
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
19573
|
-
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
19574
|
-
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
|
|
19575
|
-
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
|
|
19576
|
-
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
|
|
19577
|
-
{
|
|
19578
|
-
fn: onCommunityUserRoleRemoved,
|
|
19579
|
-
action: EnumCommunityMemberActions$1.OnCommunityUserRoleRemoved,
|
|
19580
|
-
},
|
|
19581
|
-
{ fn: onCommunityUserUnbanned, action: EnumCommunityMemberActions$1.OnCommunityUserUnbanned },
|
|
19582
|
-
]);
|
|
19583
|
-
}
|
|
19584
|
-
notifyChange({ origin, loading, error }) {
|
|
19585
|
-
var _a, _b;
|
|
19586
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19587
|
-
if (!collection)
|
|
19588
|
-
return;
|
|
19589
|
-
const data = this.applyFilter((_b = collection.data
|
|
19590
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19591
|
-
.filter(isNonNullable)
|
|
19592
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19593
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
19594
|
-
return;
|
|
19595
|
-
this.callback({
|
|
19596
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
19597
|
-
data,
|
|
19598
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
19599
|
-
loading,
|
|
19600
|
-
error,
|
|
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,
|
|
19601
19411
|
});
|
|
19602
19412
|
}
|
|
19603
|
-
|
|
19604
|
-
|
|
19605
|
-
|
|
19606
|
-
|
|
19607
|
-
|
|
19608
|
-
|
|
19609
|
-
|
|
19610
|
-
|
|
19611
|
-
|
|
19612
|
-
|
|
19613
|
-
|
|
19614
|
-
|
|
19615
|
-
|
|
19616
|
-
|
|
19617
|
-
|
|
19618
|
-
|
|
19619
|
-
|
|
19620
|
-
|
|
19621
|
-
|
|
19622
|
-
|
|
19623
|
-
|
|
19624
|
-
|
|
19625
|
-
|
|
19626
|
-
|
|
19627
|
-
|
|
19628
|
-
|
|
19629
|
-
|
|
19630
|
-
|
|
19631
|
-
|
|
19632
|
-
|
|
19633
|
-
}
|
|
19634
|
-
|
|
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
|
+
};
|
|
19635
19455
|
|
|
19636
19456
|
/*
|
|
19637
19457
|
* Exported for testing
|
|
@@ -19680,215 +19500,79 @@ const getMembers = (params, callback, config) => {
|
|
|
19680
19500
|
}
|
|
19681
19501
|
const timestamp = Date.now();
|
|
19682
19502
|
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
19683
|
-
const
|
|
19684
|
-
|
|
19685
|
-
|
|
19686
|
-
|
|
19687
|
-
const
|
|
19688
|
-
const
|
|
19689
|
-
|
|
19690
|
-
|
|
19691
|
-
|
|
19692
|
-
|
|
19693
|
-
|
|
19694
|
-
disposers.forEach(fn => fn());
|
|
19695
|
-
};
|
|
19696
|
-
};
|
|
19697
|
-
/* end_public_function */
|
|
19698
|
-
|
|
19699
|
-
/**
|
|
19700
|
-
* TODO: handle cache receive cache option, and cache policy
|
|
19701
|
-
* TODO: check if querybyIds is supported
|
|
19702
|
-
*/
|
|
19703
|
-
class SearchCommunityMembersPaginationController extends PaginationController {
|
|
19704
|
-
async getRequest(queryParams, token) {
|
|
19705
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
19706
|
-
const options = token ? { token } : { limit };
|
|
19707
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/communities/${params.communityId}/users`, {
|
|
19708
|
-
params: Object.assign(Object.assign({}, params), { options }),
|
|
19709
|
-
});
|
|
19710
|
-
return queryResponse;
|
|
19711
|
-
}
|
|
19712
|
-
}
|
|
19713
|
-
|
|
19714
|
-
class SearchCommunityMembersQueryStreamController extends QueryStreamController {
|
|
19715
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
19716
|
-
super(query, cacheKey);
|
|
19717
|
-
this.notifyChange = notifyChange;
|
|
19718
|
-
this.preparePayload = preparePayload;
|
|
19719
|
-
}
|
|
19720
|
-
async saveToMainDB(response) {
|
|
19721
|
-
const processedPayload = await this.preparePayload(response);
|
|
19722
|
-
const client = getActiveClient();
|
|
19723
|
-
const cachedAt = client.cache && Date.now();
|
|
19724
|
-
if (client.cache) {
|
|
19725
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
19726
|
-
}
|
|
19727
|
-
}
|
|
19728
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
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) => {
|
|
19729
19514
|
var _a, _b;
|
|
19730
|
-
|
|
19731
|
-
|
|
19732
|
-
|
|
19733
|
-
});
|
|
19734
|
-
|
|
19735
|
-
|
|
19736
|
-
|
|
19737
|
-
|
|
19738
|
-
|
|
19739
|
-
|
|
19740
|
-
|
|
19741
|
-
|
|
19742
|
-
|
|
19743
|
-
] }));
|
|
19744
|
-
}
|
|
19745
|
-
}
|
|
19746
|
-
reactor(action) {
|
|
19747
|
-
return (community, communityMembers) => {
|
|
19748
|
-
var _a;
|
|
19749
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19750
|
-
if (!collection)
|
|
19751
|
-
return;
|
|
19752
|
-
communityMembers.forEach(communityMember => {
|
|
19753
|
-
const communityMemberCacheId = getResolver('communityUsers')({
|
|
19754
|
-
communityId: this.query.communityId,
|
|
19755
|
-
userId: communityMember.userId,
|
|
19756
|
-
});
|
|
19757
|
-
if (communityMember.communityMembership === 'none') {
|
|
19758
|
-
collection.data = collection.data.filter(m => m !== communityMemberCacheId);
|
|
19759
|
-
}
|
|
19760
|
-
});
|
|
19761
|
-
pushToCache(this.cacheKey, collection);
|
|
19762
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
19763
|
-
};
|
|
19764
|
-
}
|
|
19765
|
-
subscribeRTE(createSubscriber) {
|
|
19766
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
19767
|
-
}
|
|
19768
|
-
}
|
|
19769
|
-
|
|
19770
|
-
var EnumCommunityMemberActions;
|
|
19771
|
-
(function (EnumCommunityMemberActions) {
|
|
19772
|
-
EnumCommunityMemberActions["OnCommunityJoined"] = "onCommunityJoined";
|
|
19773
|
-
EnumCommunityMemberActions["OnCommunityLeft"] = "onCommunityLeft";
|
|
19774
|
-
EnumCommunityMemberActions["OnCommunityUserBanned"] = "onCommunityUserBanned";
|
|
19775
|
-
EnumCommunityMemberActions["OnCommunityUserChanged"] = "onCommunityUserChanged";
|
|
19776
|
-
EnumCommunityMemberActions["OnCommunityUserRoleAdded"] = "onCommunityUserRoleAdded";
|
|
19777
|
-
EnumCommunityMemberActions["OnCommunityUserRoleRemoved"] = "onCommunityUserRoleRemoved";
|
|
19778
|
-
EnumCommunityMemberActions["OnCommunityUserUnbanned"] = "onCommunityUserUnbanned";
|
|
19779
|
-
})(EnumCommunityMemberActions || (EnumCommunityMemberActions = {}));
|
|
19780
|
-
|
|
19781
|
-
/* eslint-disable no-use-before-define */
|
|
19782
|
-
class SearchCommunityMembersLiveCollectionController extends LiveCollectionController {
|
|
19783
|
-
constructor(query, callback) {
|
|
19784
|
-
const queryStreamId = hash__default["default"](query);
|
|
19785
|
-
const cacheKey = ['communityUsers', 'collection', queryStreamId];
|
|
19786
|
-
const paginationController = new SearchCommunityMembersPaginationController(query);
|
|
19787
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
19788
|
-
this.query = query;
|
|
19789
|
-
this.queryStreamController = new SearchCommunityMembersQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
19790
|
-
this.callback = callback.bind(this);
|
|
19791
|
-
this.loadPage({ initial: true });
|
|
19792
|
-
}
|
|
19793
|
-
setup() {
|
|
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) => {
|
|
19794
19528
|
var _a;
|
|
19795
|
-
const collection = (_a = pullFromCache(
|
|
19529
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
19796
19530
|
if (!collection) {
|
|
19797
|
-
|
|
19798
|
-
data: [],
|
|
19799
|
-
params: {},
|
|
19800
|
-
});
|
|
19531
|
+
return;
|
|
19801
19532
|
}
|
|
19802
|
-
|
|
19803
|
-
|
|
19804
|
-
|
|
19805
|
-
|
|
19806
|
-
|
|
19807
|
-
|
|
19808
|
-
|
|
19809
|
-
|
|
19810
|
-
|
|
19811
|
-
|
|
19812
|
-
|
|
19813
|
-
|
|
19814
|
-
|
|
19815
|
-
|
|
19816
|
-
|
|
19817
|
-
|
|
19818
|
-
|
|
19819
|
-
|
|
19820
|
-
]);
|
|
19821
|
-
}
|
|
19822
|
-
notifyChange({ origin, loading, error }) {
|
|
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) => {
|
|
19823
19551
|
var _a, _b;
|
|
19824
|
-
const collection = (_a = pullFromCache(
|
|
19825
|
-
|
|
19826
|
-
|
|
19827
|
-
const data = this.applyFilter((_b = collection.data
|
|
19828
|
-
.map(id => pullFromCache(['communityUsers', 'get', id]))
|
|
19829
|
-
.filter(isNonNullable)
|
|
19830
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
19831
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
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))
|
|
19832
19555
|
return;
|
|
19833
|
-
|
|
19834
|
-
|
|
19835
|
-
data
|
|
19836
|
-
|
|
19837
|
-
|
|
19838
|
-
|
|
19839
|
-
|
|
19840
|
-
|
|
19841
|
-
|
|
19842
|
-
|
|
19843
|
-
|
|
19844
|
-
|
|
19845
|
-
|
|
19846
|
-
|
|
19847
|
-
|
|
19848
|
-
|
|
19849
|
-
|
|
19850
|
-
|
|
19851
|
-
|
|
19852
|
-
|
|
19853
|
-
}
|
|
19854
|
-
}
|
|
19855
|
-
|
|
19856
|
-
/* begin_public_function
|
|
19857
|
-
id: community.membership.query
|
|
19858
|
-
*/
|
|
19859
|
-
/**
|
|
19860
|
-
* ```js
|
|
19861
|
-
* import { searchMembers } from '@amityco/ts-sdk-react-native'
|
|
19862
|
-
*
|
|
19863
|
-
* let communityMembers = []
|
|
19864
|
-
* const unsub = searchMembers({
|
|
19865
|
-
* communityId: Amity.Community['communityId'],
|
|
19866
|
-
* }, response => merge(communityMembers, response.data))
|
|
19867
|
-
* ```
|
|
19868
|
-
*
|
|
19869
|
-
* Observe all mutations on a list of {@link Amity.CommunityUser}s
|
|
19870
|
-
*
|
|
19871
|
-
* @param params for querying community users
|
|
19872
|
-
* @param callback the function to call when new data are available
|
|
19873
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the community users
|
|
19874
|
-
*
|
|
19875
|
-
* @category Community Live Collection
|
|
19876
|
-
*/
|
|
19877
|
-
const searchMembers = (params, callback, config) => {
|
|
19878
|
-
const { log, cache } = getActiveClient();
|
|
19879
|
-
if (!cache) {
|
|
19880
|
-
console.log(ENABLE_CACHE_MESSAGE);
|
|
19881
|
-
}
|
|
19882
|
-
const timestamp = Date.now();
|
|
19883
|
-
log(`getMembers(tmpid: ${timestamp}) > listen`);
|
|
19884
|
-
const searchCommunityMemberLiveCollection = new SearchCommunityMembersLiveCollectionController(params, resp => {
|
|
19885
|
-
callback(resp);
|
|
19886
|
-
});
|
|
19887
|
-
const disposers = searchCommunityMemberLiveCollection.startSubscription();
|
|
19888
|
-
const cacheKey = searchCommunityMemberLiveCollection.getCacheKey();
|
|
19889
|
-
disposers.push(() => {
|
|
19890
|
-
dropFromCache(cacheKey);
|
|
19891
|
-
});
|
|
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);
|
|
19892
19576
|
return () => {
|
|
19893
19577
|
log(`getMembers(tmpid: ${timestamp}) > dispose`);
|
|
19894
19578
|
disposers.forEach(fn => fn());
|
|
@@ -19902,7 +19586,6 @@ var index$9 = /*#__PURE__*/Object.freeze({
|
|
|
19902
19586
|
removeMembers: removeMembers,
|
|
19903
19587
|
applyFilter: applyFilter,
|
|
19904
19588
|
getMembers: getMembers,
|
|
19905
|
-
searchMembers: searchMembers,
|
|
19906
19589
|
onCommunityUserAdded: onCommunityUserAdded,
|
|
19907
19590
|
onCommunityUserRemoved: onCommunityUserRemoved,
|
|
19908
19591
|
onCommunityUserBanned: onCommunityUserBanned,
|
|
@@ -22060,10 +21743,10 @@ var index$4 = /*#__PURE__*/Object.freeze({
|
|
|
22060
21743
|
* const created = await createStream({ title: 'my stream', 'thumbnailFileId': fileId })
|
|
22061
21744
|
* ```
|
|
22062
21745
|
*
|
|
22063
|
-
* Creates an {@link Amity.
|
|
21746
|
+
* Creates an {@link Amity.Stream}
|
|
22064
21747
|
*
|
|
22065
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
22066
|
-
* @returns The newly created {@link Amity.
|
|
21748
|
+
* @param bundle The data necessary to create a new {@link Amity.Stream}
|
|
21749
|
+
* @returns The newly created {@link Amity.Stream}
|
|
22067
21750
|
*
|
|
22068
21751
|
* @category Stream API
|
|
22069
21752
|
* @async
|
|
@@ -22077,7 +21760,7 @@ const createStream = async (bundle) => {
|
|
|
22077
21760
|
ingestInCache(data, { cachedAt });
|
|
22078
21761
|
const { videoStreamings } = data;
|
|
22079
21762
|
return {
|
|
22080
|
-
data:
|
|
21763
|
+
data: videoStreamings[0],
|
|
22081
21764
|
cachedAt,
|
|
22082
21765
|
};
|
|
22083
21766
|
};
|
|
@@ -22110,7 +21793,7 @@ const updateStream = async (streamId, patch) => {
|
|
|
22110
21793
|
ingestInCache(data, { cachedAt });
|
|
22111
21794
|
const { videoStreamings } = data;
|
|
22112
21795
|
return {
|
|
22113
|
-
data:
|
|
21796
|
+
data: videoStreamings.find(stream => stream.streamId === streamId),
|
|
22114
21797
|
cachedAt,
|
|
22115
21798
|
};
|
|
22116
21799
|
};
|
|
@@ -22184,10 +21867,10 @@ getStream.locally = (streamId) => {
|
|
|
22184
21867
|
* const success = await deleteStream(streamId)
|
|
22185
21868
|
* ```
|
|
22186
21869
|
*
|
|
22187
|
-
* Deletes a {@link Amity.
|
|
21870
|
+
* Deletes a {@link Amity.Stream}
|
|
22188
21871
|
*
|
|
22189
|
-
* @param streamId The {@link Amity.
|
|
22190
|
-
* @return A success boolean if the {@link Amity.
|
|
21872
|
+
* @param streamId The {@link Amity.Stream} ID to delete
|
|
21873
|
+
* @return A success boolean if the {@link Amity.Stream} was deleted
|
|
22191
21874
|
*
|
|
22192
21875
|
* @category Stream API
|
|
22193
21876
|
* @async
|
|
@@ -22212,11 +21895,11 @@ const deleteStream = async (streamId) => {
|
|
|
22212
21895
|
* const stream = await disposeStream(streamId)
|
|
22213
21896
|
* ```
|
|
22214
21897
|
*
|
|
22215
|
-
* Dispose a {@link Amity.
|
|
21898
|
+
* Dispose a {@link Amity.Stream}.
|
|
22216
21899
|
* Streaming status will be updated to "ended" and streaming url will be invalidated
|
|
22217
21900
|
*
|
|
22218
|
-
* @param streamId The {@link Amity.
|
|
22219
|
-
* @returns the associated {@link Amity.
|
|
21901
|
+
* @param streamId The {@link Amity.Stream} ID to dispose
|
|
21902
|
+
* @returns the associated {@link Amity.Stream} object
|
|
22220
21903
|
*
|
|
22221
21904
|
* @category Stream API
|
|
22222
21905
|
* @async
|
|
@@ -22247,15 +21930,15 @@ const disposeStream = async (streamId) => {
|
|
|
22247
21930
|
* const streams = await getStreams()
|
|
22248
21931
|
* ```
|
|
22249
21932
|
*
|
|
22250
|
-
* Queries a paginable list of {@link Amity.
|
|
21933
|
+
* Queries a paginable list of {@link Amity.Stream} objects
|
|
22251
21934
|
*
|
|
22252
21935
|
* @param query The query parameters
|
|
22253
|
-
* @returns A page of {@link Amity.
|
|
21936
|
+
* @returns A page of {@link Amity.Stream} objects
|
|
22254
21937
|
*
|
|
22255
21938
|
* @category Stream API
|
|
22256
21939
|
* @async
|
|
22257
21940
|
*/
|
|
22258
|
-
const queryStreams = async (query) => {
|
|
21941
|
+
const queryStreams$1 = async (query) => {
|
|
22259
21942
|
const client = getActiveClient();
|
|
22260
21943
|
client.log('stream/queryStreams', query);
|
|
22261
21944
|
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
@@ -22285,7 +21968,7 @@ const queryStreams = async (query) => {
|
|
|
22285
21968
|
* })
|
|
22286
21969
|
* ```
|
|
22287
21970
|
*
|
|
22288
|
-
* Fired when a {@link Amity.
|
|
21971
|
+
* Fired when a {@link Amity.Stream} has started airing
|
|
22289
21972
|
*
|
|
22290
21973
|
* @param callback The function to call when the event was fired
|
|
22291
21974
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
@@ -22309,7 +21992,7 @@ const onStreamStarted = (callback) => {
|
|
|
22309
21992
|
* })
|
|
22310
21993
|
* ```
|
|
22311
21994
|
*
|
|
22312
|
-
* Fired when a {@link Amity.
|
|
21995
|
+
* Fired when a {@link Amity.Stream} has stopped airing
|
|
22313
21996
|
*
|
|
22314
21997
|
* @param callback The function to call when the event was fired
|
|
22315
21998
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
@@ -22333,7 +22016,7 @@ const onStreamStopped = (callback) => {
|
|
|
22333
22016
|
* })
|
|
22334
22017
|
* ```
|
|
22335
22018
|
*
|
|
22336
|
-
* Fired when the recordings of a {@link Amity.
|
|
22019
|
+
* Fired when the recordings of a {@link Amity.Stream} are available
|
|
22337
22020
|
*
|
|
22338
22021
|
* @param callback The function to call when the event was fired
|
|
22339
22022
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
@@ -22349,54 +22032,6 @@ const onStreamRecorded = (callback) => {
|
|
|
22349
22032
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'v3.video-streaming.didRecord', filter);
|
|
22350
22033
|
};
|
|
22351
22034
|
|
|
22352
|
-
/**
|
|
22353
|
-
* ```js
|
|
22354
|
-
* import { onStreamFlagged } from '@amityco/ts-sdk-react-native'
|
|
22355
|
-
* const dispose = onStreamFlagged(stream => {
|
|
22356
|
-
* // ...
|
|
22357
|
-
* })
|
|
22358
|
-
* ```
|
|
22359
|
-
*
|
|
22360
|
-
* Fired when a {@link Amity.InternalStream} has started airing
|
|
22361
|
-
*
|
|
22362
|
-
* @param callback The function to call when the event was fired
|
|
22363
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22364
|
-
*
|
|
22365
|
-
* @category Stream Events
|
|
22366
|
-
*/
|
|
22367
|
-
const onStreamFlagged = (callback) => {
|
|
22368
|
-
const client = getActiveClient();
|
|
22369
|
-
const filter = (payload) => {
|
|
22370
|
-
ingestInCache(payload);
|
|
22371
|
-
callback(payload.videoStreamings[0]);
|
|
22372
|
-
};
|
|
22373
|
-
return createEventSubscriber(client, 'stream/onStreamFlagged', 'v3.video-streaming.didFlag', filter);
|
|
22374
|
-
};
|
|
22375
|
-
|
|
22376
|
-
/**
|
|
22377
|
-
* ```js
|
|
22378
|
-
* import { onStreamTerminated } from '@amityco/ts-sdk-react-native'
|
|
22379
|
-
* const dispose = onStreamTerminated(stream => {
|
|
22380
|
-
* // ...
|
|
22381
|
-
* })
|
|
22382
|
-
* ```
|
|
22383
|
-
*
|
|
22384
|
-
* Fired when a {@link Amity.InternalStream} has started airing
|
|
22385
|
-
*
|
|
22386
|
-
* @param callback The function to call when the event was fired
|
|
22387
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
22388
|
-
*
|
|
22389
|
-
* @category Stream Events
|
|
22390
|
-
*/
|
|
22391
|
-
const onStreamTerminated = (callback) => {
|
|
22392
|
-
const client = getActiveClient();
|
|
22393
|
-
const filter = (payload) => {
|
|
22394
|
-
ingestInCache(payload);
|
|
22395
|
-
callback(payload.videoStreamings[0]);
|
|
22396
|
-
};
|
|
22397
|
-
return createEventSubscriber(client, 'stream/onStreamTerminated', 'v3.video-streaming.didTerminate', filter);
|
|
22398
|
-
};
|
|
22399
|
-
|
|
22400
22035
|
/* eslint-disable no-use-before-define */
|
|
22401
22036
|
/* begin_public_function
|
|
22402
22037
|
id: stream.get
|
|
@@ -22411,22 +22046,15 @@ const onStreamTerminated = (callback) => {
|
|
|
22411
22046
|
* Fetches a {@link Amity.Stream} object
|
|
22412
22047
|
*
|
|
22413
22048
|
* @param streamId the ID of the {@link Amity.Stream} to get
|
|
22414
|
-
* @param callback
|
|
22415
22049
|
* @returns the associated {@link Amity.Stream} object
|
|
22416
22050
|
*
|
|
22417
22051
|
* @category Stream Live Object
|
|
22418
22052
|
*/
|
|
22419
22053
|
const getStreamById = (streamId, callback) => {
|
|
22420
|
-
|
|
22421
|
-
const { data } = snapshot;
|
|
22422
|
-
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.stream(snapshot.data) : data }));
|
|
22423
|
-
};
|
|
22424
|
-
return liveObject(streamId, reactor, 'streamId', getStream, [
|
|
22054
|
+
return liveObject(streamId, callback, 'streamId', getStream, [
|
|
22425
22055
|
onStreamRecorded,
|
|
22426
22056
|
onStreamStarted,
|
|
22427
22057
|
onStreamStopped,
|
|
22428
|
-
onStreamFlagged,
|
|
22429
|
-
onStreamTerminated,
|
|
22430
22058
|
]);
|
|
22431
22059
|
};
|
|
22432
22060
|
/* end_public_function */
|
|
@@ -22452,150 +22080,145 @@ getStreamById.locally = (streamId) => {
|
|
|
22452
22080
|
if (!cached)
|
|
22453
22081
|
return;
|
|
22454
22082
|
return {
|
|
22455
|
-
data:
|
|
22083
|
+
data: cached.data,
|
|
22456
22084
|
cachedAt: cached.cachedAt,
|
|
22457
22085
|
};
|
|
22458
22086
|
};
|
|
22459
22087
|
|
|
22460
|
-
|
|
22461
|
-
|
|
22462
|
-
|
|
22463
|
-
|
|
22464
|
-
|
|
22465
|
-
|
|
22466
|
-
|
|
22467
|
-
|
|
22468
|
-
|
|
22469
|
-
}
|
|
22470
|
-
|
|
22471
|
-
|
|
22472
|
-
|
|
22473
|
-
|
|
22474
|
-
|
|
22475
|
-
|
|
22476
|
-
|
|
22477
|
-
|
|
22478
|
-
|
|
22479
|
-
|
|
22480
|
-
|
|
22481
|
-
|
|
22482
|
-
|
|
22483
|
-
|
|
22484
|
-
|
|
22485
|
-
|
|
22486
|
-
|
|
22487
|
-
|
|
22488
|
-
|
|
22489
|
-
|
|
22490
|
-
|
|
22491
|
-
|
|
22492
|
-
|
|
22493
|
-
|
|
22494
|
-
|
|
22495
|
-
|
|
22496
|
-
|
|
22497
|
-
|
|
22498
|
-
|
|
22499
|
-
|
|
22500
|
-
|
|
22501
|
-
reactor(action) {
|
|
22502
|
-
return (payload) => {
|
|
22503
|
-
var _a;
|
|
22504
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22505
|
-
if (!collection)
|
|
22506
|
-
return;
|
|
22507
|
-
collection.data = [...new Set([payload.streamId, ...collection.data])];
|
|
22508
|
-
pushToCache(this.cacheKey, collection);
|
|
22509
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
22510
|
-
};
|
|
22511
|
-
}
|
|
22512
|
-
subscribeRTE(createSubscriber) {
|
|
22513
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
22514
|
-
}
|
|
22515
|
-
}
|
|
22516
|
-
|
|
22517
|
-
class GetStreamsLiveCollectionController extends LiveCollectionController {
|
|
22518
|
-
constructor(query, callback) {
|
|
22519
|
-
const queryStreamId = hash__default["default"](query);
|
|
22520
|
-
const cacheKey = ['streams', 'collection', queryStreamId];
|
|
22521
|
-
const paginationController = new GetStreamsPageController(query);
|
|
22522
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22523
|
-
this.applyFilter = (data) => {
|
|
22524
|
-
let streams = filterByPropEquality(data, 'isDeleted', this.query.isDeleted);
|
|
22525
|
-
streams = streams.sort(this.query.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
22526
|
-
return streams;
|
|
22527
|
-
};
|
|
22528
|
-
this.query = query;
|
|
22529
|
-
this.queryStreamController = new GetStreamsQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), paginationController);
|
|
22530
|
-
this.paginationController = paginationController;
|
|
22531
|
-
this.callback = callback.bind(this);
|
|
22532
|
-
this.loadPage({ initial: true });
|
|
22533
|
-
}
|
|
22534
|
-
notifyChange({ origin, loading, error }) {
|
|
22535
|
-
var _a;
|
|
22536
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22537
|
-
if (!collection)
|
|
22538
|
-
return;
|
|
22539
|
-
let data = collection.data
|
|
22540
|
-
.map(streamId => pullFromCache(['stream', 'get', streamId]))
|
|
22541
|
-
.filter(Boolean)
|
|
22542
|
-
.map(stream => LinkedObject.stream(stream.data));
|
|
22543
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
22544
|
-
return;
|
|
22545
|
-
data = this.applyFilter(data);
|
|
22546
|
-
this.callback({
|
|
22547
|
-
onNextPage: () => this.loadPage({ initial: false, direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22548
|
-
data,
|
|
22549
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22550
|
-
loading,
|
|
22551
|
-
error,
|
|
22552
|
-
});
|
|
22553
|
-
}
|
|
22554
|
-
startSubscription() {
|
|
22555
|
-
return this.queryStreamController.subscribeRTE([
|
|
22556
|
-
{ fn: onStreamRecorded, action: 'onStreamRecorded' },
|
|
22557
|
-
{ fn: onStreamStarted, action: 'onStreamStarted' },
|
|
22558
|
-
{ fn: onStreamStopped, action: 'onStreamStopped' },
|
|
22559
|
-
{ fn: onStreamFlagged, action: 'onStreamFlagged' },
|
|
22560
|
-
{ fn: onStreamTerminated, action: 'onStreamTerminated' },
|
|
22561
|
-
]);
|
|
22562
|
-
}
|
|
22563
|
-
setup() {
|
|
22564
|
-
var _a;
|
|
22565
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22566
|
-
if (!collection) {
|
|
22567
|
-
pushToCache(this.cacheKey, {
|
|
22568
|
-
data: [],
|
|
22569
|
-
params: {},
|
|
22570
|
-
});
|
|
22571
|
-
}
|
|
22572
|
-
}
|
|
22573
|
-
persistModel(response) {
|
|
22574
|
-
this.queryStreamController.saveToMainDB(response);
|
|
22575
|
-
}
|
|
22576
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
22577
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22578
|
-
}
|
|
22579
|
-
}
|
|
22088
|
+
/* begin_public_function
|
|
22089
|
+
id: stream.query
|
|
22090
|
+
*/
|
|
22091
|
+
/**
|
|
22092
|
+
* ```js
|
|
22093
|
+
* import { getStreams } from '@amityco/ts-sdk-react-native'
|
|
22094
|
+
* const streams = await getStreams()
|
|
22095
|
+
* ```
|
|
22096
|
+
*
|
|
22097
|
+
* Queries a paginable list of {@link Amity.Stream} objects
|
|
22098
|
+
*
|
|
22099
|
+
* @param query The query parameters
|
|
22100
|
+
* @returns A page of {@link Amity.Stream} objects
|
|
22101
|
+
*
|
|
22102
|
+
* @category Stream API
|
|
22103
|
+
* @async
|
|
22104
|
+
*/
|
|
22105
|
+
const queryStreams = async (query) => {
|
|
22106
|
+
const client = getActiveClient();
|
|
22107
|
+
client.log('stream/queryStreams', query);
|
|
22108
|
+
const _a = query !== null && query !== void 0 ? query : {}, { page, limit } = _a, params = __rest(_a, ["page", "limit"]);
|
|
22109
|
+
const options = (() => {
|
|
22110
|
+
if (page)
|
|
22111
|
+
return { token: page };
|
|
22112
|
+
if (limit)
|
|
22113
|
+
return { limit };
|
|
22114
|
+
return undefined;
|
|
22115
|
+
})();
|
|
22116
|
+
const { data } = await client.http.get(`/api/v3/video-streaming`, {
|
|
22117
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
22118
|
+
});
|
|
22119
|
+
// API-FIX: backend to response Amity.Response: const { paging, videoStreamings } = unwrapPayload(data)
|
|
22120
|
+
// API-FIX: seems returned data has a results identifier on top of data, like no other apis, and this is beautiful
|
|
22121
|
+
const { paging, results: payload } = data;
|
|
22122
|
+
const { videoStreamings } = payload;
|
|
22123
|
+
const cachedAt = client.cache && Date.now();
|
|
22124
|
+
if (client.cache)
|
|
22125
|
+
ingestInCache(payload, { cachedAt });
|
|
22126
|
+
return { data: videoStreamings, cachedAt, paging };
|
|
22127
|
+
};
|
|
22128
|
+
/* end_public_function */
|
|
22580
22129
|
|
|
22130
|
+
/* begin_public_function
|
|
22131
|
+
id: stream.query
|
|
22132
|
+
*/
|
|
22133
|
+
/**
|
|
22134
|
+
* ```js
|
|
22135
|
+
* import { StreamRepository } from '@amityco/ts-sdk-react-native'
|
|
22136
|
+
* const streams = await StreamRepository.getStreams()
|
|
22137
|
+
* ```
|
|
22138
|
+
*
|
|
22139
|
+
* Observe all mutations on a list of {@link Amity.Stream}s
|
|
22140
|
+
*
|
|
22141
|
+
* @param params for querying streams
|
|
22142
|
+
* @param callback the function to call when new data are available
|
|
22143
|
+
* @param config
|
|
22144
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the streams
|
|
22145
|
+
*
|
|
22146
|
+
* @category Stream Live Collection
|
|
22147
|
+
*/
|
|
22581
22148
|
const getStreams = (params, callback, config) => {
|
|
22582
|
-
const { log, cache
|
|
22149
|
+
const { log, cache } = getActiveClient();
|
|
22583
22150
|
if (!cache) {
|
|
22584
22151
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
22585
22152
|
}
|
|
22586
22153
|
const timestamp = Date.now();
|
|
22587
22154
|
log(`getStreams(tmpid: ${timestamp}) > listen`);
|
|
22588
|
-
const
|
|
22589
|
-
const
|
|
22590
|
-
const
|
|
22591
|
-
disposers
|
|
22592
|
-
|
|
22593
|
-
|
|
22155
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
22156
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
22157
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
22158
|
+
const disposers = [];
|
|
22159
|
+
const cacheKey = ['streams', 'collection', params];
|
|
22160
|
+
const applyFilter = (data) => {
|
|
22161
|
+
let streams = filterByPropEquality(data, 'isDeleted', params.isDeleted);
|
|
22162
|
+
streams = streams.sort(params.sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
22163
|
+
return streams;
|
|
22164
|
+
};
|
|
22165
|
+
const responder = (data, isEventModel = false) => {
|
|
22166
|
+
var _a, _b;
|
|
22167
|
+
const streams = (_a = data.data
|
|
22168
|
+
.map(streamId => {
|
|
22169
|
+
return pullFromCache(['stream', 'get', streamId]);
|
|
22170
|
+
})
|
|
22171
|
+
.filter(Boolean)
|
|
22172
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
22173
|
+
callback({
|
|
22174
|
+
onNextPage: onFetch,
|
|
22175
|
+
/*
|
|
22176
|
+
* Only apply filter to RTE Model
|
|
22177
|
+
*/
|
|
22178
|
+
data: isEventModel ? applyFilter(streams) : streams,
|
|
22179
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
22180
|
+
loading: data.loading,
|
|
22181
|
+
error: data.error,
|
|
22182
|
+
});
|
|
22183
|
+
};
|
|
22184
|
+
const realtimeRouter = (_) => (stream) => {
|
|
22185
|
+
var _a;
|
|
22186
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22187
|
+
if (!collection)
|
|
22188
|
+
return;
|
|
22189
|
+
collection.data = [...new Set([stream.streamId, ...collection.data])];
|
|
22190
|
+
pushToCache(cacheKey, collection);
|
|
22191
|
+
responder(collection, true);
|
|
22192
|
+
};
|
|
22193
|
+
const onFetch = (initial = false) => {
|
|
22194
|
+
var _a, _b;
|
|
22195
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22196
|
+
const streams = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22197
|
+
if (!initial && streams.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
22198
|
+
return;
|
|
22199
|
+
const query = createQuery(queryStreams, Object.assign(Object.assign({}, queryParams), { limit: initial ? limit : undefined, page: !initial ? collection === null || collection === void 0 ? void 0 : collection.params.page : undefined }));
|
|
22200
|
+
runQuery(query, ({ data: result, error, loading, paging }) => {
|
|
22201
|
+
const data = {
|
|
22202
|
+
loading,
|
|
22203
|
+
error,
|
|
22204
|
+
params: { page: paging === null || paging === void 0 ? void 0 : paging.next },
|
|
22205
|
+
data: streams,
|
|
22206
|
+
};
|
|
22207
|
+
if (result) {
|
|
22208
|
+
data.data = [...new Set([...streams, ...result.map(getResolver('stream'))])];
|
|
22209
|
+
}
|
|
22210
|
+
pushToCache(cacheKey, data);
|
|
22211
|
+
responder(data);
|
|
22212
|
+
}, queryOptions(policy));
|
|
22213
|
+
};
|
|
22214
|
+
disposers.push(onStreamRecorded(realtimeRouter()), onStreamStarted(realtimeRouter()), onStreamStopped(realtimeRouter()));
|
|
22215
|
+
onFetch(true);
|
|
22594
22216
|
return () => {
|
|
22595
22217
|
log(`getStreams(tmpid: ${timestamp}) > dispose`);
|
|
22596
22218
|
disposers.forEach(fn => fn());
|
|
22597
22219
|
};
|
|
22598
|
-
};
|
|
22220
|
+
};
|
|
22221
|
+
/* end_public_function */
|
|
22599
22222
|
|
|
22600
22223
|
var index$3 = /*#__PURE__*/Object.freeze({
|
|
22601
22224
|
__proto__: null,
|
|
@@ -22603,13 +22226,11 @@ var index$3 = /*#__PURE__*/Object.freeze({
|
|
|
22603
22226
|
updateStream: updateStream,
|
|
22604
22227
|
deleteStream: deleteStream,
|
|
22605
22228
|
disposeStream: disposeStream,
|
|
22606
|
-
queryStreams: queryStreams,
|
|
22229
|
+
queryStreams: queryStreams$1,
|
|
22607
22230
|
getStream: getStream,
|
|
22608
22231
|
onStreamStarted: onStreamStarted,
|
|
22609
22232
|
onStreamStopped: onStreamStopped,
|
|
22610
22233
|
onStreamRecorded: onStreamRecorded,
|
|
22611
|
-
onStreamFlagged: onStreamFlagged,
|
|
22612
|
-
onStreamTerminated: onStreamTerminated,
|
|
22613
22234
|
getStreamById: getStreamById,
|
|
22614
22235
|
getStreams: getStreams
|
|
22615
22236
|
});
|
|
@@ -22942,7 +22563,7 @@ var index$2 = /*#__PURE__*/Object.freeze({
|
|
|
22942
22563
|
getPoll: getPoll
|
|
22943
22564
|
});
|
|
22944
22565
|
|
|
22945
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
22566
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
|
|
22946
22567
|
/*
|
|
22947
22568
|
* The crypto algorithm used for importing key and signing string
|
|
22948
22569
|
*/
|