@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.esm.js
CHANGED
|
@@ -29238,8 +29238,11 @@ function isCurrentUserPartOfCommunity(c, m) {
|
|
|
29238
29238
|
*/
|
|
29239
29239
|
function updateMembershipStatus(communities, communityUsers) {
|
|
29240
29240
|
return communities.map(c => {
|
|
29241
|
-
|
|
29242
|
-
|
|
29241
|
+
if (c.isJoined == null) {
|
|
29242
|
+
const isJoined = communityUsers.some(m => isCurrentUserPartOfCommunity(c, m) && isMember(m.communityMembership));
|
|
29243
|
+
return Object.assign(Object.assign({}, c), { isJoined });
|
|
29244
|
+
}
|
|
29245
|
+
return c;
|
|
29243
29246
|
});
|
|
29244
29247
|
}
|
|
29245
29248
|
|
|
@@ -30518,7 +30521,7 @@ const createMessageReport = async ({ client, referenceId, }) => {
|
|
|
30518
30521
|
return !!payload;
|
|
30519
30522
|
};
|
|
30520
30523
|
const createPostReport = async ({ client, referenceId, }) => {
|
|
30521
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
30524
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(referenceId)}/flag`);
|
|
30522
30525
|
if (client.cache) {
|
|
30523
30526
|
const postPayload = await preparePostPayload(payload);
|
|
30524
30527
|
ingestInCache(postPayload);
|
|
@@ -30536,7 +30539,7 @@ const createUserReport = async ({ client, referenceId, }) => {
|
|
|
30536
30539
|
return !!payload;
|
|
30537
30540
|
};
|
|
30538
30541
|
const createCommentReport = async ({ client, referenceId, }) => {
|
|
30539
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
30542
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(referenceId)}/flag`);
|
|
30540
30543
|
if (client.cache) {
|
|
30541
30544
|
const commentPayload = await prepareCommentPayload(payload);
|
|
30542
30545
|
ingestInCache(commentPayload);
|
|
@@ -30585,7 +30588,7 @@ const deleteMessageReport = async ({ client, referenceId, }) => {
|
|
|
30585
30588
|
return !!payload;
|
|
30586
30589
|
};
|
|
30587
30590
|
const deletePostReport = async ({ client, referenceId, }) => {
|
|
30588
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
30591
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(referenceId)}/unflag`);
|
|
30589
30592
|
if (client.cache) {
|
|
30590
30593
|
const postPayload = await preparePostPayload(payload);
|
|
30591
30594
|
ingestInCache(postPayload);
|
|
@@ -30603,7 +30606,7 @@ const deleteUserReport = async ({ client, referenceId, }) => {
|
|
|
30603
30606
|
return !!payload;
|
|
30604
30607
|
};
|
|
30605
30608
|
const deleteCommentReport = async ({ client, referenceId, }) => {
|
|
30606
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
30609
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(referenceId)}/unflag`);
|
|
30607
30610
|
if (client.cache) {
|
|
30608
30611
|
const commentPayload = await prepareCommentPayload(payload);
|
|
30609
30612
|
ingestInCache(commentPayload);
|
|
@@ -34901,7 +34904,7 @@ const joinCommunity = async (communityId) => {
|
|
|
34901
34904
|
const client = getActiveClient();
|
|
34902
34905
|
client.log('community/joinCommunity', communityId);
|
|
34903
34906
|
const { data: payload } = await client.http.post(`/api/v3/communities/${communityId}/join`);
|
|
34904
|
-
fireEvent('community.joined', payload);
|
|
34907
|
+
fireEvent('local.community.joined', payload);
|
|
34905
34908
|
const data = prepareCommunityPayload(payload);
|
|
34906
34909
|
const cachedAt = client.cache && Date.now();
|
|
34907
34910
|
if (client.cache)
|
|
@@ -34932,7 +34935,7 @@ const leaveCommunity = async (communityId) => {
|
|
|
34932
34935
|
const client = getActiveClient();
|
|
34933
34936
|
client.log('community/leaveCommunity', communityId);
|
|
34934
34937
|
const { data: payload } = await client.http.delete(`/api/v3/communities/${communityId}/leave`);
|
|
34935
|
-
fireEvent('community.left', payload);
|
|
34938
|
+
fireEvent('local.community.left', payload);
|
|
34936
34939
|
const data = prepareCommunityPayload(payload);
|
|
34937
34940
|
const cachedAt = client.cache && Date.now();
|
|
34938
34941
|
if (client.cache)
|
|
@@ -35097,8 +35100,6 @@ function getEventRelatedMember(event, payload) {
|
|
|
35097
35100
|
if (event === 'community.joined' || event === 'community.left') {
|
|
35098
35101
|
return payload.communityUsers;
|
|
35099
35102
|
}
|
|
35100
|
-
// NOTE: backend returns the one who took the action and the one on whom
|
|
35101
|
-
// the action was taken. We need the 2nd one
|
|
35102
35103
|
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
35103
35104
|
return payload.communityUsers.filter(x => x.communityMembership === 'none');
|
|
35104
35105
|
}
|
|
@@ -35373,6 +35374,10 @@ const onCommunityJoined = (callback) => createCommunityMemberEventSubscriber('co
|
|
|
35373
35374
|
*/
|
|
35374
35375
|
const onCommunityLeft = (callback) => createCommunityMemberEventSubscriber('community.left', callback);
|
|
35375
35376
|
|
|
35377
|
+
const onLocalCommunityJoined = (callback) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
|
|
35378
|
+
|
|
35379
|
+
const onLocalCommunityLeft = (callback) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
35380
|
+
|
|
35376
35381
|
/**
|
|
35377
35382
|
* ```js
|
|
35378
35383
|
* import { observeCommunity } from '@amityco/ts-sdk'
|
|
@@ -35474,12 +35479,12 @@ class CommunitiesQueryStreamController$1 extends QueryStreamController {
|
|
|
35474
35479
|
}
|
|
35475
35480
|
}
|
|
35476
35481
|
|
|
35477
|
-
var EnumCommunityActions$
|
|
35482
|
+
var EnumCommunityActions$3;
|
|
35478
35483
|
(function (EnumCommunityActions) {
|
|
35479
35484
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
35480
35485
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
35481
35486
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
35482
|
-
})(EnumCommunityActions$
|
|
35487
|
+
})(EnumCommunityActions$3 || (EnumCommunityActions$3 = {}));
|
|
35483
35488
|
|
|
35484
35489
|
var EnumCommunityMemberActions$1;
|
|
35485
35490
|
(function (EnumCommunityMemberActions) {
|
|
@@ -35758,7 +35763,9 @@ class CommunityMembersLiveCollectionController extends LiveCollectionController
|
|
|
35758
35763
|
startSubscription() {
|
|
35759
35764
|
return this.queryStreamController.subscribeRTE([
|
|
35760
35765
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35766
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
35761
35767
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35768
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
35762
35769
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions$1.OnCommunityUserBanned },
|
|
35763
35770
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnCommunityUserChanged },
|
|
35764
35771
|
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions$1.OnCommunityUserRoleAdded },
|
|
@@ -36018,7 +36025,9 @@ class SearchCommunityMembersLiveCollectionController extends LiveCollectionContr
|
|
|
36018
36025
|
startSubscription() {
|
|
36019
36026
|
return this.queryStreamController.subscribeRTE([
|
|
36020
36027
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
36028
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
36021
36029
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
36030
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
36022
36031
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
36023
36032
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
36024
36033
|
{
|
|
@@ -36133,7 +36142,9 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
36133
36142
|
onLocalCommunityUserAdded: onLocalCommunityUserAdded,
|
|
36134
36143
|
onLocalCommunityUserRemoved: onLocalCommunityUserRemoved,
|
|
36135
36144
|
onCommunityJoined: onCommunityJoined,
|
|
36136
|
-
onCommunityLeft: onCommunityLeft
|
|
36145
|
+
onCommunityLeft: onCommunityLeft,
|
|
36146
|
+
onLocalCommunityJoined: onLocalCommunityJoined,
|
|
36147
|
+
onLocalCommunityLeft: onLocalCommunityLeft
|
|
36137
36148
|
});
|
|
36138
36149
|
|
|
36139
36150
|
class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
@@ -36165,11 +36176,13 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36165
36176
|
}
|
|
36166
36177
|
startSubscription() {
|
|
36167
36178
|
return this.queryStreamController.subscribeRTE([
|
|
36168
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions$
|
|
36169
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions$
|
|
36179
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$3.OnCommunityDeleted },
|
|
36180
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$3.OnCommunityUpdated },
|
|
36170
36181
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36171
36182
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36172
36183
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36184
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36185
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36173
36186
|
]);
|
|
36174
36187
|
}
|
|
36175
36188
|
notifyChange({ origin, loading, error }) {
|
|
@@ -36179,7 +36192,7 @@ class SearchCommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36179
36192
|
return;
|
|
36180
36193
|
const data = this.applyFilter((_b = collection.data
|
|
36181
36194
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36182
|
-
.filter(
|
|
36195
|
+
.filter(isNonNullable)
|
|
36183
36196
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
36184
36197
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36185
36198
|
return;
|
|
@@ -36264,12 +36277,12 @@ class CommunitiesPaginationController extends PaginationController {
|
|
|
36264
36277
|
}
|
|
36265
36278
|
}
|
|
36266
36279
|
|
|
36267
|
-
var EnumCommunityActions;
|
|
36280
|
+
var EnumCommunityActions$2;
|
|
36268
36281
|
(function (EnumCommunityActions) {
|
|
36269
36282
|
EnumCommunityActions["OnCommunityCreated"] = "onCommunityCreated";
|
|
36270
36283
|
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
36271
36284
|
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
36272
|
-
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
36285
|
+
})(EnumCommunityActions$2 || (EnumCommunityActions$2 = {}));
|
|
36273
36286
|
|
|
36274
36287
|
class CommunitiesQueryStreamController extends QueryStreamController {
|
|
36275
36288
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
@@ -36305,7 +36318,7 @@ class CommunitiesQueryStreamController extends QueryStreamController {
|
|
|
36305
36318
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36306
36319
|
if (!collection)
|
|
36307
36320
|
return;
|
|
36308
|
-
if (this.query.displayName && action === EnumCommunityActions.OnCommunityCreated) {
|
|
36321
|
+
if (this.query.displayName && action === EnumCommunityActions$2.OnCommunityCreated) {
|
|
36309
36322
|
return;
|
|
36310
36323
|
}
|
|
36311
36324
|
/*
|
|
@@ -36350,12 +36363,14 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36350
36363
|
}
|
|
36351
36364
|
startSubscription() {
|
|
36352
36365
|
return this.queryStreamController.subscribeRTE([
|
|
36353
|
-
{ fn: onCommunityCreated, action: EnumCommunityActions.OnCommunityCreated },
|
|
36354
|
-
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
36355
|
-
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
36366
|
+
{ fn: onCommunityCreated, action: EnumCommunityActions$2.OnCommunityCreated },
|
|
36367
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$2.OnCommunityDeleted },
|
|
36368
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$2.OnCommunityUpdated },
|
|
36356
36369
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36357
36370
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36358
36371
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36372
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36373
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36359
36374
|
]);
|
|
36360
36375
|
}
|
|
36361
36376
|
notifyChange({ origin, loading, error }) {
|
|
@@ -36365,7 +36380,7 @@ class CommunityLiveCollectionController extends LiveCollectionController {
|
|
|
36365
36380
|
return;
|
|
36366
36381
|
const data = this.applyFilter((_b = collection.data
|
|
36367
36382
|
.map(id => pullFromCache(['community', 'get', id]))
|
|
36368
|
-
.filter(
|
|
36383
|
+
.filter(isNonNullable)
|
|
36369
36384
|
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []);
|
|
36370
36385
|
if (!this.shouldNotify(data) && origin === 'event')
|
|
36371
36386
|
return;
|
|
@@ -36478,6 +36493,8 @@ const getCommunity = (communityId, callback) => {
|
|
|
36478
36493
|
onCommunityDeleted,
|
|
36479
36494
|
onCommunityJoined,
|
|
36480
36495
|
onCommunityLeft,
|
|
36496
|
+
onLocalCommunityJoined,
|
|
36497
|
+
onLocalCommunityLeft,
|
|
36481
36498
|
onCommunityUserBanned,
|
|
36482
36499
|
onCommunityUserUnbanned,
|
|
36483
36500
|
onCommunityUserChanged,
|
|
@@ -36486,71 +36503,128 @@ const getCommunity = (communityId, callback) => {
|
|
|
36486
36503
|
/* end_public_function */
|
|
36487
36504
|
|
|
36488
36505
|
/**
|
|
36489
|
-
*
|
|
36490
|
-
*
|
|
36491
|
-
* const trendingCommunities = await CommunityRepository.getTrendingCommunities()
|
|
36492
|
-
* ```
|
|
36493
|
-
*
|
|
36494
|
-
* Gets a list of top trending {@link Amity.Community} objects
|
|
36495
|
-
*
|
|
36496
|
-
* @param query The query parameters
|
|
36497
|
-
* @returns A list of {@link Amity.Community} objects
|
|
36498
|
-
*
|
|
36499
|
-
* @category Community API
|
|
36500
|
-
* @async
|
|
36501
|
-
* @private
|
|
36506
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
36507
|
+
* TODO: check if querybyIds is supported
|
|
36502
36508
|
*/
|
|
36503
|
-
|
|
36504
|
-
|
|
36505
|
-
|
|
36506
|
-
|
|
36507
|
-
|
|
36508
|
-
|
|
36509
|
-
|
|
36510
|
-
|
|
36511
|
-
const { communities } = data;
|
|
36512
|
-
const cachedAt = client.cache && Date.now();
|
|
36513
|
-
if (client.cache) {
|
|
36514
|
-
ingestInCache(data, { cachedAt });
|
|
36509
|
+
class TrendingCommunitiesPaginationController extends PaginationController {
|
|
36510
|
+
async getRequest(queryParams, token) {
|
|
36511
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
36512
|
+
const options = token ? { token } : { limit };
|
|
36513
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/top-trending`, {
|
|
36514
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
36515
|
+
});
|
|
36516
|
+
return queryResponse;
|
|
36515
36517
|
}
|
|
36516
|
-
|
|
36517
|
-
};
|
|
36518
|
+
}
|
|
36518
36519
|
|
|
36519
|
-
|
|
36520
|
-
|
|
36521
|
-
|
|
36522
|
-
|
|
36523
|
-
|
|
36520
|
+
class TrendingCommunitiesQueryStreamController extends QueryStreamController {
|
|
36521
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
36522
|
+
super(query, cacheKey);
|
|
36523
|
+
this.notifyChange = notifyChange;
|
|
36524
|
+
this.preparePayload = preparePayload;
|
|
36524
36525
|
}
|
|
36525
|
-
|
|
36526
|
-
|
|
36526
|
+
async saveToMainDB(response) {
|
|
36527
|
+
const processedPayload = await this.preparePayload(response);
|
|
36528
|
+
const client = getActiveClient();
|
|
36529
|
+
const cachedAt = client.cache && Date.now();
|
|
36530
|
+
if (client.cache) {
|
|
36531
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
36532
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
36533
|
+
}
|
|
36527
36534
|
}
|
|
36528
|
-
|
|
36529
|
-
|
|
36535
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
36536
|
+
var _a, _b;
|
|
36537
|
+
if (refresh) {
|
|
36538
|
+
pushToCache(this.cacheKey, {
|
|
36539
|
+
data: response.communities.map(getResolver('community')),
|
|
36540
|
+
});
|
|
36541
|
+
}
|
|
36542
|
+
else {
|
|
36543
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36544
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36545
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
36546
|
+
}
|
|
36530
36547
|
}
|
|
36531
|
-
|
|
36532
|
-
|
|
36548
|
+
reactor(action) {
|
|
36549
|
+
return (community) => {
|
|
36550
|
+
var _a;
|
|
36551
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36552
|
+
if (!collection)
|
|
36553
|
+
return;
|
|
36554
|
+
pushToCache(this.cacheKey, collection);
|
|
36555
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
36556
|
+
};
|
|
36533
36557
|
}
|
|
36534
|
-
|
|
36535
|
-
|
|
36536
|
-
communities = communities.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
36558
|
+
subscribeRTE(createSubscriber) {
|
|
36559
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
36537
36560
|
}
|
|
36538
|
-
|
|
36539
|
-
|
|
36540
|
-
|
|
36541
|
-
|
|
36542
|
-
|
|
36543
|
-
|
|
36544
|
-
|
|
36545
|
-
|
|
36546
|
-
|
|
36547
|
-
|
|
36548
|
-
|
|
36561
|
+
}
|
|
36562
|
+
|
|
36563
|
+
var EnumCommunityActions$1;
|
|
36564
|
+
(function (EnumCommunityActions) {
|
|
36565
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
36566
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
36567
|
+
})(EnumCommunityActions$1 || (EnumCommunityActions$1 = {}));
|
|
36568
|
+
|
|
36569
|
+
class TrendingCommunityLiveCollectionController extends LiveCollectionController {
|
|
36570
|
+
constructor(query, callback) {
|
|
36571
|
+
const queryStreamId = hash(query);
|
|
36572
|
+
const cacheKey = ['trendingCommunity', 'collection', queryStreamId];
|
|
36573
|
+
const paginationController = new TrendingCommunitiesPaginationController(query);
|
|
36574
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36575
|
+
this.query = query;
|
|
36576
|
+
this.queryStreamController = new TrendingCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
36577
|
+
this.callback = callback.bind(this);
|
|
36578
|
+
this.loadPage({ initial: true });
|
|
36549
36579
|
}
|
|
36550
|
-
|
|
36551
|
-
|
|
36580
|
+
setup() {
|
|
36581
|
+
var _a;
|
|
36582
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36583
|
+
if (!collection) {
|
|
36584
|
+
pushToCache(this.cacheKey, {
|
|
36585
|
+
data: [],
|
|
36586
|
+
params: {},
|
|
36587
|
+
});
|
|
36588
|
+
}
|
|
36589
|
+
}
|
|
36590
|
+
async persistModel(queryPayload) {
|
|
36591
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
36592
|
+
}
|
|
36593
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
36594
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
36595
|
+
}
|
|
36596
|
+
startSubscription() {
|
|
36597
|
+
return this.queryStreamController.subscribeRTE([
|
|
36598
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions$1.OnCommunityDeleted },
|
|
36599
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions$1.OnCommunityUpdated },
|
|
36600
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36601
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36602
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36603
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36604
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36605
|
+
]);
|
|
36606
|
+
}
|
|
36607
|
+
notifyChange({ origin, loading, error }) {
|
|
36608
|
+
var _a, _b;
|
|
36609
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36610
|
+
if (!collection)
|
|
36611
|
+
return;
|
|
36612
|
+
const data = (_b = collection.data
|
|
36613
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
36614
|
+
.filter(isNonNullable)
|
|
36615
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
36616
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
36617
|
+
return;
|
|
36618
|
+
this.callback({
|
|
36619
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
36620
|
+
data,
|
|
36621
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
36622
|
+
loading,
|
|
36623
|
+
error,
|
|
36624
|
+
});
|
|
36625
|
+
}
|
|
36626
|
+
}
|
|
36552
36627
|
|
|
36553
|
-
/* eslint-disable no-use-before-define */
|
|
36554
36628
|
/* begin_public_function
|
|
36555
36629
|
id: community.query.trending_communities
|
|
36556
36630
|
*/
|
|
@@ -36579,60 +36653,9 @@ const getTrendingCommunities = (params, callback, config) => {
|
|
|
36579
36653
|
}
|
|
36580
36654
|
const timestamp = Date.now();
|
|
36581
36655
|
log(`getTrendingCommunities(tmpid: ${timestamp}) > listen`);
|
|
36582
|
-
const
|
|
36583
|
-
const
|
|
36584
|
-
const
|
|
36585
|
-
const disposers = [];
|
|
36586
|
-
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
36587
|
-
const responder = (data, isEventModel = false) => {
|
|
36588
|
-
var _a, _b;
|
|
36589
|
-
const communities = (_a = data.data
|
|
36590
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
36591
|
-
.filter(Boolean)
|
|
36592
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
36593
|
-
callback({
|
|
36594
|
-
onNextPage: onFetch,
|
|
36595
|
-
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
36596
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
36597
|
-
loading: data.loading,
|
|
36598
|
-
error: data.error,
|
|
36599
|
-
});
|
|
36600
|
-
};
|
|
36601
|
-
const realtimeRouter = (_) => (community) => {
|
|
36602
|
-
var _a;
|
|
36603
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36604
|
-
if (!collection)
|
|
36605
|
-
return;
|
|
36606
|
-
/*
|
|
36607
|
-
* Simply update collection and let responder decide what to do with data
|
|
36608
|
-
*/
|
|
36609
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
36610
|
-
pushToCache(cacheKey, collection);
|
|
36611
|
-
responder(collection);
|
|
36612
|
-
};
|
|
36613
|
-
const onFetch = (initial = false) => {
|
|
36614
|
-
var _a, _b;
|
|
36615
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36616
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36617
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
36618
|
-
return;
|
|
36619
|
-
const query = createQuery(getTrendingCommunities$1, params);
|
|
36620
|
-
runQuery(query, ({ data: result, error, loading }) => {
|
|
36621
|
-
const data = {
|
|
36622
|
-
loading,
|
|
36623
|
-
error,
|
|
36624
|
-
params,
|
|
36625
|
-
data: communities,
|
|
36626
|
-
};
|
|
36627
|
-
if (result) {
|
|
36628
|
-
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
36629
|
-
}
|
|
36630
|
-
pushToCache(cacheKey, data);
|
|
36631
|
-
responder(data);
|
|
36632
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
36633
|
-
};
|
|
36634
|
-
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
36635
|
-
onFetch(true);
|
|
36656
|
+
const trendingCommunitiesLiveCollection = new TrendingCommunityLiveCollectionController(params, callback);
|
|
36657
|
+
const disposers = trendingCommunitiesLiveCollection.startSubscription();
|
|
36658
|
+
const cacheKey = trendingCommunitiesLiveCollection.getCacheKey();
|
|
36636
36659
|
disposers.push(() => dropFromCache(cacheKey));
|
|
36637
36660
|
return () => {
|
|
36638
36661
|
log(`getTrendingCommunities(tmpid: ${timestamp}) > dispose`);
|
|
@@ -36641,39 +36664,128 @@ const getTrendingCommunities = (params, callback, config) => {
|
|
|
36641
36664
|
};
|
|
36642
36665
|
/* end_public_function */
|
|
36643
36666
|
|
|
36644
|
-
/* begin_public_function
|
|
36645
|
-
id: community.query.recommended_communities
|
|
36646
|
-
*/
|
|
36647
36667
|
/**
|
|
36648
|
-
*
|
|
36649
|
-
*
|
|
36650
|
-
* const communities = await CommunityRepository.getRecommendedCommunities()
|
|
36651
|
-
* ```
|
|
36652
|
-
*
|
|
36653
|
-
* Gets a list of recommended {@link Amity.Community} objects
|
|
36654
|
-
*
|
|
36655
|
-
* @param query The query parameters
|
|
36656
|
-
* @returns A list of {@link Amity.Community} objects
|
|
36657
|
-
*
|
|
36658
|
-
* @category Community API
|
|
36659
|
-
* @async
|
|
36660
|
-
* @private
|
|
36668
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
36669
|
+
* TODO: check if querybyIds is supported
|
|
36661
36670
|
*/
|
|
36662
|
-
|
|
36663
|
-
|
|
36664
|
-
|
|
36665
|
-
|
|
36666
|
-
|
|
36667
|
-
|
|
36668
|
-
|
|
36669
|
-
|
|
36670
|
-
const { communities } = data;
|
|
36671
|
-
const cachedAt = client.cache && Date.now();
|
|
36672
|
-
if (client.cache) {
|
|
36673
|
-
ingestInCache(data, { cachedAt });
|
|
36671
|
+
class RecommendedCommunitiesPaginationController extends PaginationController {
|
|
36672
|
+
async getRequest(queryParams, token) {
|
|
36673
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
36674
|
+
const options = token ? { token } : { limit };
|
|
36675
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/communities/recommended`, {
|
|
36676
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
36677
|
+
});
|
|
36678
|
+
return queryResponse;
|
|
36674
36679
|
}
|
|
36675
|
-
|
|
36676
|
-
|
|
36680
|
+
}
|
|
36681
|
+
|
|
36682
|
+
class RecommendedCommunitiesQueryStreamController extends QueryStreamController {
|
|
36683
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
36684
|
+
super(query, cacheKey);
|
|
36685
|
+
this.notifyChange = notifyChange;
|
|
36686
|
+
this.preparePayload = preparePayload;
|
|
36687
|
+
}
|
|
36688
|
+
async saveToMainDB(response) {
|
|
36689
|
+
const processedPayload = await this.preparePayload(response);
|
|
36690
|
+
const client = getActiveClient();
|
|
36691
|
+
const cachedAt = client.cache && Date.now();
|
|
36692
|
+
if (client.cache) {
|
|
36693
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
36694
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
36695
|
+
}
|
|
36696
|
+
}
|
|
36697
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
36698
|
+
var _a, _b;
|
|
36699
|
+
if (refresh) {
|
|
36700
|
+
pushToCache(this.cacheKey, {
|
|
36701
|
+
data: response.communities.map(getResolver('community')),
|
|
36702
|
+
});
|
|
36703
|
+
}
|
|
36704
|
+
else {
|
|
36705
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36706
|
+
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36707
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])] }));
|
|
36708
|
+
}
|
|
36709
|
+
}
|
|
36710
|
+
reactor(action) {
|
|
36711
|
+
return (community) => {
|
|
36712
|
+
var _a;
|
|
36713
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36714
|
+
if (!collection)
|
|
36715
|
+
return;
|
|
36716
|
+
pushToCache(this.cacheKey, collection);
|
|
36717
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
36718
|
+
};
|
|
36719
|
+
}
|
|
36720
|
+
subscribeRTE(createSubscriber) {
|
|
36721
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
36722
|
+
}
|
|
36723
|
+
}
|
|
36724
|
+
|
|
36725
|
+
var EnumCommunityActions;
|
|
36726
|
+
(function (EnumCommunityActions) {
|
|
36727
|
+
EnumCommunityActions["OnCommunityDeleted"] = "onCommunityDeleted";
|
|
36728
|
+
EnumCommunityActions["OnCommunityUpdated"] = "onCommunityUpdated";
|
|
36729
|
+
})(EnumCommunityActions || (EnumCommunityActions = {}));
|
|
36730
|
+
|
|
36731
|
+
class RecommendedCommunityLiveCollectionController extends LiveCollectionController {
|
|
36732
|
+
constructor(query, callback) {
|
|
36733
|
+
const queryStreamId = hash(query);
|
|
36734
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
36735
|
+
const paginationController = new RecommendedCommunitiesPaginationController(query);
|
|
36736
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
36737
|
+
this.query = query;
|
|
36738
|
+
this.queryStreamController = new RecommendedCommunitiesQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommunityPayload);
|
|
36739
|
+
this.callback = callback.bind(this);
|
|
36740
|
+
this.loadPage({ initial: true });
|
|
36741
|
+
}
|
|
36742
|
+
setup() {
|
|
36743
|
+
var _a;
|
|
36744
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36745
|
+
if (!collection) {
|
|
36746
|
+
pushToCache(this.cacheKey, {
|
|
36747
|
+
data: [],
|
|
36748
|
+
params: {},
|
|
36749
|
+
});
|
|
36750
|
+
}
|
|
36751
|
+
}
|
|
36752
|
+
async persistModel(queryPayload) {
|
|
36753
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
36754
|
+
}
|
|
36755
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
36756
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
36757
|
+
}
|
|
36758
|
+
startSubscription() {
|
|
36759
|
+
return this.queryStreamController.subscribeRTE([
|
|
36760
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
36761
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
36762
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36763
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36764
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions$1.OnMemberCountChanged },
|
|
36765
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions$1.OnCommunityJoined },
|
|
36766
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions$1.OnCommunityLeft },
|
|
36767
|
+
]);
|
|
36768
|
+
}
|
|
36769
|
+
notifyChange({ origin, loading, error }) {
|
|
36770
|
+
var _a, _b;
|
|
36771
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36772
|
+
if (!collection)
|
|
36773
|
+
return;
|
|
36774
|
+
const data = (_b = collection.data
|
|
36775
|
+
.map(id => pullFromCache(['community', 'get', id]))
|
|
36776
|
+
.filter(isNonNullable)
|
|
36777
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : [];
|
|
36778
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
36779
|
+
return;
|
|
36780
|
+
this.callback({
|
|
36781
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
36782
|
+
data,
|
|
36783
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
36784
|
+
loading,
|
|
36785
|
+
error,
|
|
36786
|
+
});
|
|
36787
|
+
}
|
|
36788
|
+
}
|
|
36677
36789
|
|
|
36678
36790
|
/* begin_public_function
|
|
36679
36791
|
id: community.query.recommended_communities
|
|
@@ -36703,60 +36815,9 @@ const getRecommendedCommunities = (params, callback, config) => {
|
|
|
36703
36815
|
}
|
|
36704
36816
|
const timestamp = Date.now();
|
|
36705
36817
|
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
36706
|
-
const
|
|
36707
|
-
const
|
|
36708
|
-
const
|
|
36709
|
-
const disposers = [];
|
|
36710
|
-
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
36711
|
-
const responder = (data, isEventModel = false) => {
|
|
36712
|
-
var _a, _b;
|
|
36713
|
-
const communities = (_a = data.data
|
|
36714
|
-
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
36715
|
-
.filter(Boolean)
|
|
36716
|
-
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
36717
|
-
callback({
|
|
36718
|
-
onNextPage: onFetch,
|
|
36719
|
-
data: isEventModel ? communityQueryFilter(communities, params, userId) : communities,
|
|
36720
|
-
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
36721
|
-
loading: data.loading,
|
|
36722
|
-
error: data.error,
|
|
36723
|
-
});
|
|
36724
|
-
};
|
|
36725
|
-
const realtimeRouter = (_) => (community) => {
|
|
36726
|
-
var _a;
|
|
36727
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36728
|
-
if (!collection)
|
|
36729
|
-
return;
|
|
36730
|
-
/*
|
|
36731
|
-
* Simply update collection and let responder decide what to do with data
|
|
36732
|
-
*/
|
|
36733
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
36734
|
-
pushToCache(cacheKey, collection);
|
|
36735
|
-
responder(collection);
|
|
36736
|
-
};
|
|
36737
|
-
const onFetch = (initial = false) => {
|
|
36738
|
-
var _a, _b;
|
|
36739
|
-
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
36740
|
-
const communities = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
36741
|
-
if (!initial && communities.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
36742
|
-
return;
|
|
36743
|
-
const query = createQuery(getRecommendedCommunities$1, params);
|
|
36744
|
-
runQuery(query, ({ data: result, error, loading }) => {
|
|
36745
|
-
const data = {
|
|
36746
|
-
loading,
|
|
36747
|
-
error,
|
|
36748
|
-
params,
|
|
36749
|
-
data: communities,
|
|
36750
|
-
};
|
|
36751
|
-
if (result) {
|
|
36752
|
-
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
36753
|
-
}
|
|
36754
|
-
pushToCache(cacheKey, data);
|
|
36755
|
-
responder(data);
|
|
36756
|
-
}, queryOptions(policy, CACHE_SHORTEN_LIFESPAN));
|
|
36757
|
-
};
|
|
36758
|
-
disposers.push(onCommunityUserChanged(realtimeRouter()));
|
|
36759
|
-
onFetch(true);
|
|
36818
|
+
const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(params, callback);
|
|
36819
|
+
const disposers = recommendedCommunitiesLiveCollection.startSubscription();
|
|
36820
|
+
const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
|
|
36760
36821
|
disposers.push(() => dropFromCache(cacheKey));
|
|
36761
36822
|
return () => {
|
|
36762
36823
|
log(`getRecommendedCommunities(tmpid: ${timestamp}) > dispose`);
|