@amityco/ts-sdk 6.30.4-4fa323d.0 → 6.30.4-c9fbf64.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/events.d.ts +2 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +2 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +8 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/index.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/index.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityJoined.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts +2 -0
- package/dist/communityRepository/communityMembership/events/onLocalCommunityLeft.d.ts.map +1 -0
- package/dist/communityRepository/communityMembership/events/utils.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/observers/getCommunity.d.ts.map +1 -1
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts +13 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts +16 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts +5 -0
- package/dist/communityRepository/observers/getRecommendedCommunities/enums.d.ts.map +1 -0
- package/dist/communityRepository/observers/getRecommendedCommunities.d.ts +1 -1
- package/dist/communityRepository/observers/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts +13 -0
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.d.ts +9 -0
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts +16 -0
- package/dist/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.d.ts.map +1 -0
- package/dist/communityRepository/observers/getTrendingCommunities/enums.d.ts +5 -0
- package/dist/communityRepository/observers/getTrendingCommunities/enums.d.ts.map +1 -0
- package/dist/communityRepository/observers/getTrendingCommunities.d.ts +1 -1
- package/dist/communityRepository/observers/getTrendingCommunities.d.ts.map +1 -1
- package/dist/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.d.ts.map +1 -1
- package/dist/communityRepository/utils/communityWithMembership.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/index.cjs.js +277 -216
- package/dist/index.esm.js +277 -216
- package/dist/index.umd.js +4 -4
- package/package.json +1 -1
- package/src/@types/core/events.ts +2 -0
- package/src/@types/core/payload.ts +3 -0
- package/src/@types/domains/community.ts +6 -0
- package/src/communityRepository/api/joinCommunity.ts +1 -1
- package/src/communityRepository/api/leaveCommunity.ts +1 -1
- package/src/communityRepository/communityMembership/events/index.ts +2 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityJoined.ts +5 -0
- package/src/communityRepository/communityMembership/events/onLocalCommunityLeft.ts +5 -0
- package/src/communityRepository/communityMembership/events/utils.ts +0 -2
- package/src/communityRepository/communityMembership/observers/getMembers/CommunityMembersLiveCollectionController.ts +4 -0
- package/src/communityRepository/communityMembership/observers/searchMembers/SearchCommunityMembersLiveCollectionController.ts +4 -0
- package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts +7 -2
- package/src/communityRepository/observers/getCommunity.ts +4 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController.ts +109 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesPaginationController.ts +31 -0
- package/src/communityRepository/observers/getRecommendedCommunities/RecommendedCommunitiesQueryStreamController.ts +88 -0
- package/src/communityRepository/observers/getRecommendedCommunities/enums.ts +4 -0
- package/src/communityRepository/observers/getRecommendedCommunities.ts +9 -81
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesLiveCollectionController.ts +109 -0
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesPaginationController.ts +28 -0
- package/src/communityRepository/observers/getTrendingCommunities/TrendingCommunitiesQueryStreamController.ts +86 -0
- package/src/communityRepository/observers/getTrendingCommunities/enums.ts +4 -0
- package/src/communityRepository/observers/getTrendingCommunities.ts +10 -82
- package/src/communityRepository/observers/searchCommunities/SearchCommunitiesLiveCollectionController.ts +7 -2
- package/src/communityRepository/utils/communityWithMembership.ts +7 -4
- package/src/report/api/createReport.ts +2 -2
- package/src/report/api/deleteReport.ts +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -13146,8 +13146,11 @@ function isCurrentUserPartOfCommunity(c, m) {
|
|
|
13146
13146
|
*/
|
|
13147
13147
|
function updateMembershipStatus(communities, communityUsers) {
|
|
13148
13148
|
return communities.map(c => {
|
|
13149
|
-
|
|
13150
|
-
|
|
13149
|
+
if (c.isJoined == null) {
|
|
13150
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
13151
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
13152
|
+
}
|
|
13153
|
+
return c;
|
|
13151
13154
|
});
|
|
13152
13155
|
}
|
|
13153
13156
|
|
|
@@ -14426,7 +14429,7 @@ const createMessageReport = async ({ client, referenceId, }) => {
|
|
|
14426
14429
|
return !!payload;
|
|
14427
14430
|
};
|
|
14428
14431
|
const createPostReport = async ({ client, referenceId, }) => {
|
|
14429
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
14432
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(referenceId)}/flag`);
|
|
14430
14433
|
if (client.cache) {
|
|
14431
14434
|
const postPayload = await preparePostPayload(payload);
|
|
14432
14435
|
ingestInCache(postPayload);
|
|
@@ -14444,7 +14447,7 @@ const createUserReport = async ({ client, referenceId, }) => {
|
|
|
14444
14447
|
return !!payload;
|
|
14445
14448
|
};
|
|
14446
14449
|
const createCommentReport = async ({ client, referenceId, }) => {
|
|
14447
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
14450
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(referenceId)}/flag`);
|
|
14448
14451
|
if (client.cache) {
|
|
14449
14452
|
const commentPayload = await prepareCommentPayload(payload);
|
|
14450
14453
|
ingestInCache(commentPayload);
|
|
@@ -14493,7 +14496,7 @@ const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
|
14493
14496
|
return !!payload;
|
|
14494
14497
|
};
|
|
14495
14498
|
const deletePostReport = async ({ client, referenceId, }) => {
|
|
14496
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
14499
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(referenceId)}/unflag`);
|
|
14497
14500
|
if (client.cache) {
|
|
14498
14501
|
const postPayload = await preparePostPayload(payload);
|
|
14499
14502
|
ingestInCache(postPayload);
|
|
@@ -14511,7 +14514,7 @@ const deleteUserReport = async ({ client, referenceId, }) => {
|
|
|
14511
14514
|
return !!payload;
|
|
14512
14515
|
};
|
|
14513
14516
|
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
14514
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
14517
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(referenceId)}/unflag`);
|
|
14515
14518
|
if (client.cache) {
|
|
14516
14519
|
const commentPayload = await prepareCommentPayload(payload);
|
|
14517
14520
|
ingestInCache(commentPayload);
|
|
@@ -18809,7 +18812,7 @@ const joinCommunity = async (communityId) => {
|
|
|
18809
18812
|
const client = getActiveClient();
|
|
18810
18813
|
client.log('community/joinCommunity', communityId);
|
|
18811
18814
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/join`);
|
|
18812
|
-
fireEvent('community.joined', payload);
|
|
18815
|
+
fireEvent('local.community.joined', payload);
|
|
18813
18816
|
const data = prepareCommunityPayload(payload);
|
|
18814
18817
|
const cachedAt = client.cache && Date.now();
|
|
18815
18818
|
if (client.cache)
|
|
@@ -18840,7 +18843,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
18840
18843
|
const client = getActiveClient();
|
|
18841
18844
|
client.log('community/leaveCommunity', communityId);
|
|
18842
18845
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/leave`);
|
|
18843
|
-
fireEvent('community.left', payload);
|
|
18846
|
+
fireEvent('local.community.left', payload);
|
|
18844
18847
|
const data = prepareCommunityPayload(payload);
|
|
18845
18848
|
const cachedAt = client.cache && Date.now();
|
|
18846
18849
|
if (client.cache)
|
|
@@ -19005,8 +19008,6 @@ function getEventRelatedMember(event, payload) {
|
|
|
19005
19008
|
if (event === 'community.joined' || event === 'community.left') {
|
|
19006
19009
|
return payload.communityUsers;
|
|
19007
19010
|
}
|
|
19008
|
-
// NOTE: backend returns the one who took the action and the one on whom
|
|
19009
|
-
// the action was taken. We need the 2nd one
|
|
19010
19011
|
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
19011
19012
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
19012
19013
|
}
|
|
@@ -19281,6 +19282,10 @@ const onCommunityJoined = (callback) => createCommunityMemberEventSubscriber('co
|
|
|
19281
19282
|
*/
|
|
19282
19283
|
const onCommunityLeft = (callback) => createCommunityMemberEventSubscriber('community.left', callback);
|
|
19283
19284
|
|
|
19285
|
+
const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
|
|
19286
|
+
|
|
19287
|
+
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
19288
|
+
|
|
19284
19289
|
/**
|
|
19285
19290
|
* ```js
|
|
19286
19291
|
* import { observeCommunity } from '@amityco/ts-sdk'
|
|
@@ -19382,12 +19387,12 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
|
19382
19387
|
}
|
|
19383
19388
|
}
|
|
19384
19389
|
|
|
19385
|
-
var EnumCommunityActions$
|
|
19390
|
+
var EnumCommunityActions$3;
|
|
19386
19391
|
(function (EnumCommunityActions) {
|
|
19387
19392
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
19388
19393
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
19389
19394
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
19390
|
-
})(EnumCommunityActions$
|
|
19395
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
19391
19396
|
|
|
19392
19397
|
var EnumCommunityMemberActions$1;
|
|
19393
19398
|
(function (EnumCommunityMemberActions) {
|
|
@@ -19666,7 +19671,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
19666
19671
|
startSubscription() {
|
|
19667
19672
|
return this.queryStreamController.subscribeRTE([
|
|
19668
19673
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
19674
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
19669
19675
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
19676
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
19670
19677
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
|
|
19671
19678
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
|
|
19672
19679
|
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
|
|
@@ -19926,7 +19933,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
19926
19933
|
startSubscription() {
|
|
19927
19934
|
return this.queryStreamController.subscribeRTE([
|
|
19928
19935
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
19936
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
19929
19937
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
19938
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
19930
19939
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
19931
19940
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
19932
19941
|
{
|
|
@@ -20041,7 +20050,9 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
20041
20050
|
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
20042
20051
|
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
20043
20052
|
onCommunityJoined: onCommunityJoined,
|
|
20044
|
-
onCommunityLeft: onCommunityLeft
|
|
20053
|
+
onCommunityLeft: onCommunityLeft,
|
|
20054
|
+
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
20055
|
+
onLocalCommunityLeft: onLocalCommunityLeft
|
|
20045
20056
|
});
|
|
20046
20057
|
|
|
20047
20058
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -20073,11 +20084,13 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20073
20084
|
}
|
|
20074
20085
|
startSubscription() {
|
|
20075
20086
|
return this.queryStreamController.subscribeRTE([
|
|
20076
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
20077
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
20087
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
20088
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
20078
20089
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20079
20090
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20080
20091
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
20092
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20093
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20081
20094
|
]);
|
|
20082
20095
|
}
|
|
20083
20096
|
notifyChange({ origin, loading, error }) {
|
|
@@ -20087,7 +20100,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20087
20100
|
return;
|
|
20088
20101
|
const data = this.applyFilter((_b = collection.data
|
|
20089
20102
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
20090
|
-
.filter(
|
|
20103
|
+
.filter(isNonNullable)
|
|
20091
20104
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
20092
20105
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
20093
20106
|
return;
|
|
@@ -20172,12 +20185,12 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
20172
20185
|
}
|
|
20173
20186
|
}
|
|
20174
20187
|
|
|
20175
|
-
var EnumCommunityActions;
|
|
20188
|
+
var EnumCommunityActions$2;
|
|
20176
20189
|
(function (EnumCommunityActions) {
|
|
20177
20190
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
20178
20191
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20179
20192
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20180
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
20193
|
+
})(EnumCommunityActions$2 || (EnumCommunityActions$2 = {}));
|
|
20181
20194
|
|
|
20182
20195
|
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
20183
20196
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -20213,7 +20226,7 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
20213
20226
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20214
20227
|
if (!collection)
|
|
20215
20228
|
return;
|
|
20216
|
-
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
20229
|
+
if (this.query.displayName && action === EnumCommunityActions$2.OnCommunityCreated) {
|
|
20217
20230
|
return;
|
|
20218
20231
|
}
|
|
20219
20232
|
/*
|
|
@@ -20258,12 +20271,14 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20258
20271
|
}
|
|
20259
20272
|
startSubscription() {
|
|
20260
20273
|
return this.queryStreamController.subscribeRTE([
|
|
20261
|
-
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
20262
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
20263
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
20274
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$2.OnCommunityCreated },
|
|
20275
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$2.OnCommunityDeleted },
|
|
20276
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$2.OnCommunityUpdated },
|
|
20264
20277
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20265
20278
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20266
20279
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
20280
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20281
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20267
20282
|
]);
|
|
20268
20283
|
}
|
|
20269
20284
|
notifyChange({ origin, loading, error }) {
|
|
@@ -20273,7 +20288,7 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
20273
20288
|
return;
|
|
20274
20289
|
const data = this.applyFilter((_b = collection.data
|
|
20275
20290
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
20276
|
-
.filter(
|
|
20291
|
+
.filter(isNonNullable)
|
|
20277
20292
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
20278
20293
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
20279
20294
|
return;
|
|
@@ -20386,6 +20401,8 @@ const getCommunity = (communityId, callback) => {
|
|
|
20386
20401
|
onCommunityDeleted,
|
|
20387
20402
|
onCommunityJoined,
|
|
20388
20403
|
onCommunityLeft,
|
|
20404
|
+
onLocalCommunityJoined,
|
|
20405
|
+
onLocalCommunityLeft,
|
|
20389
20406
|
onCommunityUserBanned,
|
|
20390
20407
|
onCommunityUserUnbanned,
|
|
20391
20408
|
onCommunityUserChanged,
|
|
@@ -20394,71 +20411,128 @@ const getCommunity = (communityId, callback) => {
|
|
|
20394
20411
|
/* end_public_function */
|
|
20395
20412
|
|
|
20396
20413
|
/**
|
|
20397
|
-
*
|
|
20398
|
-
*
|
|
20399
|
-
* const trendingCommunities = await CommunityRepository.getTrendingCommunities()
|
|
20400
|
-
* ```
|
|
20401
|
-
*
|
|
20402
|
-
* Gets a list of top trending {@link Amity.Community} objects
|
|
20403
|
-
*
|
|
20404
|
-
* @param query The query parameters
|
|
20405
|
-
* @returns A list of {@link Amity.Community} objects
|
|
20406
|
-
*
|
|
20407
|
-
* @category Community API
|
|
20408
|
-
* @async
|
|
20409
|
-
* @private
|
|
20414
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
20415
|
+
* TODO: check if querybyIds is supported
|
|
20410
20416
|
*/
|
|
20411
|
-
|
|
20412
|
-
|
|
20413
|
-
|
|
20414
|
-
|
|
20415
|
-
|
|
20416
|
-
|
|
20417
|
-
|
|
20418
|
-
|
|
20419
|
-
const { communities } = data;
|
|
20420
|
-
const cachedAt = client.cache && Date.now();
|
|
20421
|
-
if (client.cache) {
|
|
20422
|
-
ingestInCache(data, { cachedAt });
|
|
20417
|
+
class TrendingCommunitiesPaginationController extends PaginationController {
|
|
20418
|
+
async getRequest(queryParams, token) {
|
|
20419
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
20420
|
+
const options = token ? { token } : { limit };
|
|
20421
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/top-trending`, {
|
|
20422
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
20423
|
+
});
|
|
20424
|
+
return queryResponse;
|
|
20423
20425
|
}
|
|
20424
|
-
|
|
20425
|
-
};
|
|
20426
|
+
}
|
|
20426
20427
|
|
|
20427
|
-
|
|
20428
|
-
|
|
20429
|
-
|
|
20430
|
-
|
|
20431
|
-
|
|
20428
|
+
class TrendingCommunitiesQueryStreamController extends QueryStreamController {
|
|
20429
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
20430
|
+
super(query, cacheKey);
|
|
20431
|
+
this.notifyChange = notifyChange;
|
|
20432
|
+
this.preparePayload = preparePayload;
|
|
20432
20433
|
}
|
|
20433
|
-
|
|
20434
|
-
|
|
20434
|
+
async saveToMainDB(response) {
|
|
20435
|
+
const processedPayload = await this.preparePayload(response);
|
|
20436
|
+
const client = getActiveClient();
|
|
20437
|
+
const cachedAt = client.cache && Date.now();
|
|
20438
|
+
if (client.cache) {
|
|
20439
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
20440
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
20441
|
+
}
|
|
20435
20442
|
}
|
|
20436
|
-
|
|
20437
|
-
|
|
20443
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
20444
|
+
var _a, _b;
|
|
20445
|
+
if (refresh) {
|
|
20446
|
+
pushToCache(this.cacheKey, {
|
|
20447
|
+
data: response.communities.map(getResolver('community')),
|
|
20448
|
+
});
|
|
20449
|
+
}
|
|
20450
|
+
else {
|
|
20451
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20452
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
20453
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
20454
|
+
}
|
|
20438
20455
|
}
|
|
20439
|
-
|
|
20440
|
-
|
|
20456
|
+
reactor(action) {
|
|
20457
|
+
return (community) => {
|
|
20458
|
+
var _a;
|
|
20459
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20460
|
+
if (!collection)
|
|
20461
|
+
return;
|
|
20462
|
+
pushToCache(this.cacheKey, collection);
|
|
20463
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
20464
|
+
};
|
|
20441
20465
|
}
|
|
20442
|
-
|
|
20443
|
-
|
|
20444
|
-
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
20466
|
+
subscribeRTE(createSubscriber) {
|
|
20467
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
20445
20468
|
}
|
|
20446
|
-
|
|
20447
|
-
|
|
20448
|
-
|
|
20449
|
-
|
|
20450
|
-
|
|
20451
|
-
|
|
20452
|
-
|
|
20453
|
-
|
|
20454
|
-
|
|
20455
|
-
|
|
20456
|
-
|
|
20469
|
+
}
|
|
20470
|
+
|
|
20471
|
+
var EnumCommunityActions$1;
|
|
20472
|
+
(function (EnumCommunityActions) {
|
|
20473
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20474
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20475
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
20476
|
+
|
|
20477
|
+
class TrendingCommunityLiveCollectionController extends LiveCollectionController {
|
|
20478
|
+
constructor(query, callback) {
|
|
20479
|
+
const queryStreamId = hash__default["default"](query);
|
|
20480
|
+
const cacheKey = ['trendingCommunity', 'collection', queryStreamId];
|
|
20481
|
+
const paginationController = new TrendingCommunitiesPaginationController(query);
|
|
20482
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
20483
|
+
this.query = query;
|
|
20484
|
+
this.queryStreamController = new TrendingCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
20485
|
+
this.callback = callback.bind(this);
|
|
20486
|
+
this.loadPage({ initial: true });
|
|
20457
20487
|
}
|
|
20458
|
-
|
|
20459
|
-
|
|
20488
|
+
setup() {
|
|
20489
|
+
var _a;
|
|
20490
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20491
|
+
if (!collection) {
|
|
20492
|
+
pushToCache(this.cacheKey, {
|
|
20493
|
+
data: [],
|
|
20494
|
+
params: {},
|
|
20495
|
+
});
|
|
20496
|
+
}
|
|
20497
|
+
}
|
|
20498
|
+
async persistModel(queryPayload) {
|
|
20499
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
20500
|
+
}
|
|
20501
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
20502
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
20503
|
+
}
|
|
20504
|
+
startSubscription() {
|
|
20505
|
+
return this.queryStreamController.subscribeRTE([
|
|
20506
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
20507
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
20508
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20509
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20510
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
20511
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20512
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20513
|
+
]);
|
|
20514
|
+
}
|
|
20515
|
+
notifyChange({ origin, loading, error }) {
|
|
20516
|
+
var _a, _b;
|
|
20517
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20518
|
+
if (!collection)
|
|
20519
|
+
return;
|
|
20520
|
+
const data = (_b = collection.data
|
|
20521
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
20522
|
+
.filter(isNonNullable)
|
|
20523
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
20524
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
20525
|
+
return;
|
|
20526
|
+
this.callback({
|
|
20527
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
20528
|
+
data,
|
|
20529
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
20530
|
+
loading,
|
|
20531
|
+
error,
|
|
20532
|
+
});
|
|
20533
|
+
}
|
|
20534
|
+
}
|
|
20460
20535
|
|
|
20461
|
-
/* eslint-disable no-use-before-define */
|
|
20462
20536
|
/* begin_public_function
|
|
20463
20537
|
id: community.query.trending_communities
|
|
20464
20538
|
*/
|
|
@@ -20487,60 +20561,9 @@ const getTrendingCommunities = (params, callback, config) => {
|
|
|
20487
20561
|
}
|
|
20488
20562
|
const timestamp = Date.now();
|
|
20489
20563
|
log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
|
|
20490
|
-
const
|
|
20491
|
-
const
|
|
20492
|
-
const
|
|
20493
|
-
const disposers = [];
|
|
20494
|
-
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
20495
|
-
const responder = (data, isEventModel = false) => {
|
|
20496
|
-
var _a, _b;
|
|
20497
|
-
const communities = (_a = data.data
|
|
20498
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
20499
|
-
.filter(Boolean)
|
|
20500
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
20501
|
-
callback({
|
|
20502
|
-
onNextPage: onFetch,
|
|
20503
|
-
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
20504
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
20505
|
-
loading: data.loading,
|
|
20506
|
-
error: data.error,
|
|
20507
|
-
});
|
|
20508
|
-
};
|
|
20509
|
-
const realtimeRouter = (_) => (community) => {
|
|
20510
|
-
var _a;
|
|
20511
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20512
|
-
if (!collection)
|
|
20513
|
-
return;
|
|
20514
|
-
/*
|
|
20515
|
-
* Simply update collection and let responder decide what to do with data
|
|
20516
|
-
*/
|
|
20517
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
20518
|
-
pushToCache(cacheKey, collection);
|
|
20519
|
-
responder(collection);
|
|
20520
|
-
};
|
|
20521
|
-
const onFetch = (initial = false) => {
|
|
20522
|
-
var _a, _b;
|
|
20523
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20524
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
20525
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
20526
|
-
return;
|
|
20527
|
-
const query = createQuery(getTrendingCommunities$1, params);
|
|
20528
|
-
runQuery(query, ({ data: result, error, loading }) => {
|
|
20529
|
-
const data = {
|
|
20530
|
-
loading,
|
|
20531
|
-
error,
|
|
20532
|
-
params,
|
|
20533
|
-
data: communities,
|
|
20534
|
-
};
|
|
20535
|
-
if (result) {
|
|
20536
|
-
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
20537
|
-
}
|
|
20538
|
-
pushToCache(cacheKey, data);
|
|
20539
|
-
responder(data);
|
|
20540
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
20541
|
-
};
|
|
20542
|
-
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
20543
|
-
onFetch(true);
|
|
20564
|
+
const trendingCommunitiesLiveCollection = new TrendingCommunityLiveCollectionController(params, callback);
|
|
20565
|
+
const disposers = trendingCommunitiesLiveCollection.startSubscription();
|
|
20566
|
+
const cacheKey = trendingCommunitiesLiveCollection.getCacheKey();
|
|
20544
20567
|
disposers.push(() => dropFromCache(cacheKey));
|
|
20545
20568
|
return () => {
|
|
20546
20569
|
log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
|
|
@@ -20549,39 +20572,128 @@ const getTrendingCommunities = (params, callback, config) => {
|
|
|
20549
20572
|
};
|
|
20550
20573
|
/* end_public_function */
|
|
20551
20574
|
|
|
20552
|
-
/* begin_public_function
|
|
20553
|
-
id: community.query.recommended_communities
|
|
20554
|
-
*/
|
|
20555
20575
|
/**
|
|
20556
|
-
*
|
|
20557
|
-
*
|
|
20558
|
-
* const communities = await CommunityRepository.getRecommendedCommunities()
|
|
20559
|
-
* ```
|
|
20560
|
-
*
|
|
20561
|
-
* Gets a list of recommended {@link Amity.Community} objects
|
|
20562
|
-
*
|
|
20563
|
-
* @param query The query parameters
|
|
20564
|
-
* @returns A list of {@link Amity.Community} objects
|
|
20565
|
-
*
|
|
20566
|
-
* @category Community API
|
|
20567
|
-
* @async
|
|
20568
|
-
* @private
|
|
20576
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
20577
|
+
* TODO: check if querybyIds is supported
|
|
20569
20578
|
*/
|
|
20570
|
-
|
|
20571
|
-
|
|
20572
|
-
|
|
20573
|
-
|
|
20574
|
-
|
|
20575
|
-
|
|
20576
|
-
|
|
20577
|
-
|
|
20578
|
-
const { communities } = data;
|
|
20579
|
-
const cachedAt = client.cache && Date.now();
|
|
20580
|
-
if (client.cache) {
|
|
20581
|
-
ingestInCache(data, { cachedAt });
|
|
20579
|
+
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
20580
|
+
async getRequest(queryParams, token) {
|
|
20581
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
20582
|
+
const options = token ? { token } : { limit };
|
|
20583
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/recommended`, {
|
|
20584
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
20585
|
+
});
|
|
20586
|
+
return queryResponse;
|
|
20582
20587
|
}
|
|
20583
|
-
|
|
20584
|
-
|
|
20588
|
+
}
|
|
20589
|
+
|
|
20590
|
+
class RecommendedCommunitiesQueryStreamController extends QueryStreamController {
|
|
20591
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
20592
|
+
super(query, cacheKey);
|
|
20593
|
+
this.notifyChange = notifyChange;
|
|
20594
|
+
this.preparePayload = preparePayload;
|
|
20595
|
+
}
|
|
20596
|
+
async saveToMainDB(response) {
|
|
20597
|
+
const processedPayload = await this.preparePayload(response);
|
|
20598
|
+
const client = getActiveClient();
|
|
20599
|
+
const cachedAt = client.cache && Date.now();
|
|
20600
|
+
if (client.cache) {
|
|
20601
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
20602
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
20603
|
+
}
|
|
20604
|
+
}
|
|
20605
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
20606
|
+
var _a, _b;
|
|
20607
|
+
if (refresh) {
|
|
20608
|
+
pushToCache(this.cacheKey, {
|
|
20609
|
+
data: response.communities.map(getResolver('community')),
|
|
20610
|
+
});
|
|
20611
|
+
}
|
|
20612
|
+
else {
|
|
20613
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20614
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
20615
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
20616
|
+
}
|
|
20617
|
+
}
|
|
20618
|
+
reactor(action) {
|
|
20619
|
+
return (community) => {
|
|
20620
|
+
var _a;
|
|
20621
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20622
|
+
if (!collection)
|
|
20623
|
+
return;
|
|
20624
|
+
pushToCache(this.cacheKey, collection);
|
|
20625
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
20626
|
+
};
|
|
20627
|
+
}
|
|
20628
|
+
subscribeRTE(createSubscriber) {
|
|
20629
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
20630
|
+
}
|
|
20631
|
+
}
|
|
20632
|
+
|
|
20633
|
+
var EnumCommunityActions;
|
|
20634
|
+
(function (EnumCommunityActions) {
|
|
20635
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
20636
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
20637
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
20638
|
+
|
|
20639
|
+
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
20640
|
+
constructor(query, callback) {
|
|
20641
|
+
const queryStreamId = hash__default["default"](query);
|
|
20642
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
20643
|
+
const paginationController = new RecommendedCommunitiesPaginationController(query);
|
|
20644
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
20645
|
+
this.query = query;
|
|
20646
|
+
this.queryStreamController = new RecommendedCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
20647
|
+
this.callback = callback.bind(this);
|
|
20648
|
+
this.loadPage({ initial: true });
|
|
20649
|
+
}
|
|
20650
|
+
setup() {
|
|
20651
|
+
var _a;
|
|
20652
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20653
|
+
if (!collection) {
|
|
20654
|
+
pushToCache(this.cacheKey, {
|
|
20655
|
+
data: [],
|
|
20656
|
+
params: {},
|
|
20657
|
+
});
|
|
20658
|
+
}
|
|
20659
|
+
}
|
|
20660
|
+
async persistModel(queryPayload) {
|
|
20661
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
20662
|
+
}
|
|
20663
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
20664
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
20665
|
+
}
|
|
20666
|
+
startSubscription() {
|
|
20667
|
+
return this.queryStreamController.subscribeRTE([
|
|
20668
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
20669
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
20670
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20671
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20672
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
20673
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
20674
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
20675
|
+
]);
|
|
20676
|
+
}
|
|
20677
|
+
notifyChange({ origin, loading, error }) {
|
|
20678
|
+
var _a, _b;
|
|
20679
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20680
|
+
if (!collection)
|
|
20681
|
+
return;
|
|
20682
|
+
const data = (_b = collection.data
|
|
20683
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
20684
|
+
.filter(isNonNullable)
|
|
20685
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
20686
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
20687
|
+
return;
|
|
20688
|
+
this.callback({
|
|
20689
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
20690
|
+
data,
|
|
20691
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
20692
|
+
loading,
|
|
20693
|
+
error,
|
|
20694
|
+
});
|
|
20695
|
+
}
|
|
20696
|
+
}
|
|
20585
20697
|
|
|
20586
20698
|
/* begin_public_function
|
|
20587
20699
|
id: community.query.recommended_communities
|
|
@@ -20611,60 +20723,9 @@ const getRecommendedCommunities = (params, callback, config) => {
|
|
|
20611
20723
|
}
|
|
20612
20724
|
const timestamp = Date.now();
|
|
20613
20725
|
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
20614
|
-
const
|
|
20615
|
-
const
|
|
20616
|
-
const
|
|
20617
|
-
const disposers = [];
|
|
20618
|
-
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
20619
|
-
const responder = (data, isEventModel = false) => {
|
|
20620
|
-
var _a, _b;
|
|
20621
|
-
const communities = (_a = data.data
|
|
20622
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
20623
|
-
.filter(Boolean)
|
|
20624
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
20625
|
-
callback({
|
|
20626
|
-
onNextPage: onFetch,
|
|
20627
|
-
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
20628
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
20629
|
-
loading: data.loading,
|
|
20630
|
-
error: data.error,
|
|
20631
|
-
});
|
|
20632
|
-
};
|
|
20633
|
-
const realtimeRouter = (_) => (community) => {
|
|
20634
|
-
var _a;
|
|
20635
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20636
|
-
if (!collection)
|
|
20637
|
-
return;
|
|
20638
|
-
/*
|
|
20639
|
-
* Simply update collection and let responder decide what to do with data
|
|
20640
|
-
*/
|
|
20641
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
20642
|
-
pushToCache(cacheKey, collection);
|
|
20643
|
-
responder(collection);
|
|
20644
|
-
};
|
|
20645
|
-
const onFetch = (initial = false) => {
|
|
20646
|
-
var _a, _b;
|
|
20647
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20648
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
20649
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
20650
|
-
return;
|
|
20651
|
-
const query = createQuery(getRecommendedCommunities$1, params);
|
|
20652
|
-
runQuery(query, ({ data: result, error, loading }) => {
|
|
20653
|
-
const data = {
|
|
20654
|
-
loading,
|
|
20655
|
-
error,
|
|
20656
|
-
params,
|
|
20657
|
-
data: communities,
|
|
20658
|
-
};
|
|
20659
|
-
if (result) {
|
|
20660
|
-
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
20661
|
-
}
|
|
20662
|
-
pushToCache(cacheKey, data);
|
|
20663
|
-
responder(data);
|
|
20664
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
20665
|
-
};
|
|
20666
|
-
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
20667
|
-
onFetch(true);
|
|
20726
|
+
const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(params, callback);
|
|
20727
|
+
const disposers = recommendedCommunitiesLiveCollection.startSubscription();
|
|
20728
|
+
const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
|
|
20668
20729
|
disposers.push(() => dropFromCache(cacheKey));
|
|
20669
20730
|
return () => {
|
|
20670
20731
|
log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
|