@amityco/ts-sdk-react-native 6.30.4-48268a5.0 → 6.30.5-d50bb81.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/client/api/index.d.ts +2 -0
- package/dist/client/api/index.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 +334 -221
- package/dist/index.esm.js +334 -221
- package/dist/index.umd.js +3 -3
- package/dist/report/api/isReportedByMe.d.ts.map +1 -1
- 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/client/api/index.ts +3 -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/src/report/api/isReportedByMe.ts +5 -3
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"isReportedByMe.d.ts","sourceRoot":"","sources":["../../../src/report/api/isReportedByMe.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"isReportedByMe.d.ts","sourceRoot":"","sources":["../../../src/report/api/isReportedByMe.ts"],"names":[],"mappings":"AAgEA;;;;;;;;;;;;KAYK;AACL,eAAO,MAAM,cAAc,kBACV,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,eACzC,MAAM,KAClB,QAAQ,OAAO,CAqBjB,CAAC"}
|
package/package.json
CHANGED
|
@@ -181,6 +181,8 @@ declare global {
|
|
|
181
181
|
};
|
|
182
182
|
|
|
183
183
|
type LocalCommunityEvents = {
|
|
184
|
+
'local.community.joined': Amity.CommunityMembershipPayload;
|
|
185
|
+
'local.community.left': Amity.CommunityMembershipPayload;
|
|
184
186
|
'local.community.roleAdded': Amity.ProcessedCommunityPayload;
|
|
185
187
|
'local.community.roleRemoved': Amity.ProcessedCommunityPayload;
|
|
186
188
|
'local.community.userAdded': Amity.CommunityMembershipPayload;
|
|
@@ -273,6 +273,9 @@ declare global {
|
|
|
273
273
|
files: Amity.File[];
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
+
type RecommendedCommunityPayload = Amity.CommunityPayload;
|
|
277
|
+
type TrendingCommunityPayload = Amity.CommunityPayload;
|
|
278
|
+
|
|
276
279
|
/**
|
|
277
280
|
* Items that extend from `Amity.CommunityPayload`
|
|
278
281
|
* - communities: `Amity.RawCommunity` -> `Amity.Community` (Added Marker Service related props)
|
|
@@ -133,6 +133,9 @@ declare global {
|
|
|
133
133
|
|
|
134
134
|
type CommunityLiveCollection = Amity.LiveCollectionParams<Omit<QueryCommunities, 'page'>>;
|
|
135
135
|
|
|
136
|
+
type RecommendedCommunityLiveCollection = Amity.LiveCollectionParams<{ limit?: number }>;
|
|
137
|
+
type TrendingCommunityLiveCollection = Amity.LiveCollectionParams<{ limit?: number }>;
|
|
138
|
+
|
|
136
139
|
type SearchCommunityLiveCollection = Amity.LiveCollectionParams<
|
|
137
140
|
Omit<SearchQueryCommunities, 'page'>
|
|
138
141
|
>;
|
|
@@ -142,6 +145,9 @@ declare global {
|
|
|
142
145
|
Pick<QueryCommunities, 'page'>
|
|
143
146
|
>;
|
|
144
147
|
|
|
148
|
+
type RecommendedCommunityLiveCollectionCache = Amity.CommunityLiveCollectionCache;
|
|
149
|
+
type TrendingCommunityLiveCollectionCache = Amity.CommunityLiveCollectionCache;
|
|
150
|
+
|
|
145
151
|
type SearchCommunityLiveCollectionCache = Amity.LiveCollectionCache<
|
|
146
152
|
Amity.Community['communityId'],
|
|
147
153
|
Pick<SearchQueryCommunities, 'page'>
|
package/src/client/api/index.ts
CHANGED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createLocalCommunityMemberEventSubscriber } from './utils';
|
|
2
|
+
|
|
3
|
+
export const onLocalCommunityJoined = (
|
|
4
|
+
callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
|
|
5
|
+
) => createLocalCommunityMemberEventSubscriber('local.community.joined', callback);
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { createLocalCommunityMemberEventSubscriber } from './utils';
|
|
2
|
+
|
|
3
|
+
export const onLocalCommunityLeft = (
|
|
4
|
+
callback: (community: Amity.Community, member: Amity.Membership<'community'>[]) => void,
|
|
5
|
+
) => createLocalCommunityMemberEventSubscriber('local.community.left', callback);
|
|
@@ -35,8 +35,6 @@ function getEventRelatedMember(
|
|
|
35
35
|
return payload.communityUsers;
|
|
36
36
|
}
|
|
37
37
|
|
|
38
|
-
// NOTE: backend returns the one who took the action and the one on whom
|
|
39
|
-
// the action was taken. We need the 2nd one
|
|
40
38
|
if (event === 'community.userRemoved' || event === 'local.community.userRemoved') {
|
|
41
39
|
return payload.communityUsers!.filter(x => x.communityMembership === 'none');
|
|
42
40
|
}
|
|
@@ -13,6 +13,8 @@ import {
|
|
|
13
13
|
onCommunityUserUnbanned,
|
|
14
14
|
onLocalCommunityUserAdded,
|
|
15
15
|
onLocalCommunityUserRemoved,
|
|
16
|
+
onLocalCommunityLeft,
|
|
17
|
+
onLocalCommunityJoined,
|
|
16
18
|
} from '~/communityRepository/communityMembership/events';
|
|
17
19
|
import {
|
|
18
20
|
filterByPropIntersection,
|
|
@@ -84,7 +86,9 @@ export class CommunityMembersLiveCollectionController extends LiveCollectionCont
|
|
|
84
86
|
startSubscription() {
|
|
85
87
|
return this.queryStreamController.subscribeRTE([
|
|
86
88
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
89
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
87
90
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
91
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
88
92
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
89
93
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
90
94
|
{ fn: onCommunityUserRoleAdded, action: EnumCommunityMemberActions.OnCommunityUserRoleAdded },
|
|
@@ -11,6 +11,8 @@ import {
|
|
|
11
11
|
onCommunityUserChanged,
|
|
12
12
|
onCommunityUserRoleRemoved,
|
|
13
13
|
onCommunityUserUnbanned,
|
|
14
|
+
onLocalCommunityLeft,
|
|
15
|
+
onLocalCommunityJoined,
|
|
14
16
|
} from '~/communityRepository/communityMembership/events';
|
|
15
17
|
import { filterByPropIntersection, filterBySearchTerm } from '~/core/query';
|
|
16
18
|
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
@@ -78,7 +80,9 @@ export class SearchCommunityMembersLiveCollectionController extends LiveCollecti
|
|
|
78
80
|
startSubscription() {
|
|
79
81
|
return this.queryStreamController.subscribeRTE([
|
|
80
82
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
83
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
81
84
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
85
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
82
86
|
{ fn: onCommunityUserBanned, action: EnumCommunityMemberActions.OnCommunityUserBanned },
|
|
83
87
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnCommunityUserChanged },
|
|
84
88
|
{
|
package/src/communityRepository/observers/getCommunities/CommunitiesLiveCollectionController.ts
CHANGED
|
@@ -22,8 +22,11 @@ import { EnumCommunityMemberActions } from '~/communityRepository/communityMembe
|
|
|
22
22
|
import {
|
|
23
23
|
onCommunityJoined,
|
|
24
24
|
onCommunityLeft,
|
|
25
|
+
onLocalCommunityJoined,
|
|
26
|
+
onLocalCommunityLeft,
|
|
25
27
|
onCommunityUserChanged,
|
|
26
28
|
} from '~/communityRepository/communityMembership';
|
|
29
|
+
import { isNonNullable } from '~/utils';
|
|
27
30
|
|
|
28
31
|
export class CommunityLiveCollectionController extends LiveCollectionController<
|
|
29
32
|
'community',
|
|
@@ -87,6 +90,8 @@ export class CommunityLiveCollectionController extends LiveCollectionController<
|
|
|
87
90
|
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
88
91
|
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
89
92
|
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
|
|
93
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
94
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
90
95
|
]);
|
|
91
96
|
}
|
|
92
97
|
|
|
@@ -96,8 +101,8 @@ export class CommunityLiveCollectionController extends LiveCollectionController<
|
|
|
96
101
|
|
|
97
102
|
const data = this.applyFilter(
|
|
98
103
|
collection.data
|
|
99
|
-
.map(id => pullFromCache<Amity.Community>(['community', 'get', id])
|
|
100
|
-
.filter(
|
|
104
|
+
.map(id => pullFromCache<Amity.Community>(['community', 'get', id]))
|
|
105
|
+
.filter(isNonNullable)
|
|
101
106
|
.map(({ data }) => data) ?? [],
|
|
102
107
|
);
|
|
103
108
|
|
|
@@ -7,6 +7,8 @@ import {
|
|
|
7
7
|
onCommunityUserChanged,
|
|
8
8
|
onCommunityJoined,
|
|
9
9
|
onCommunityLeft,
|
|
10
|
+
onLocalCommunityJoined,
|
|
11
|
+
onLocalCommunityLeft,
|
|
10
12
|
} from '../communityMembership/events';
|
|
11
13
|
|
|
12
14
|
/* begin_public_function
|
|
@@ -40,6 +42,8 @@ export const getCommunity = (
|
|
|
40
42
|
onCommunityDeleted,
|
|
41
43
|
onCommunityJoined,
|
|
42
44
|
onCommunityLeft,
|
|
45
|
+
onLocalCommunityJoined,
|
|
46
|
+
onLocalCommunityLeft,
|
|
43
47
|
onCommunityUserBanned,
|
|
44
48
|
onCommunityUserUnbanned,
|
|
45
49
|
onCommunityUserChanged,
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { RecommendedCommunitiesPaginationController } from './RecommendedCommunitiesPaginationController';
|
|
4
|
+
import { RecommendedCommunitiesQueryStreamController } from './RecommendedCommunitiesQueryStreamController';
|
|
5
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
6
|
+
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
7
|
+
import { EnumCommunityActions } from './enums';
|
|
8
|
+
import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
|
|
9
|
+
import { onCommunityDeleted, onCommunityUpdated } from '~/communityRepository/events';
|
|
10
|
+
import {
|
|
11
|
+
onCommunityJoined,
|
|
12
|
+
onCommunityLeft,
|
|
13
|
+
onLocalCommunityJoined,
|
|
14
|
+
onLocalCommunityLeft,
|
|
15
|
+
onCommunityUserChanged,
|
|
16
|
+
} from '~/communityRepository/communityMembership';
|
|
17
|
+
import { isNonNullable } from '~/utils';
|
|
18
|
+
|
|
19
|
+
export class RecommendedCommunityLiveCollectionController extends LiveCollectionController<
|
|
20
|
+
'community',
|
|
21
|
+
Amity.RecommendedCommunityLiveCollection,
|
|
22
|
+
Amity.Community,
|
|
23
|
+
RecommendedCommunitiesPaginationController
|
|
24
|
+
> {
|
|
25
|
+
private queryStreamController: RecommendedCommunitiesQueryStreamController;
|
|
26
|
+
|
|
27
|
+
private query: Amity.RecommendedCommunityLiveCollection;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
query: Amity.RecommendedCommunityLiveCollection,
|
|
31
|
+
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
32
|
+
) {
|
|
33
|
+
const queryStreamId = hash(query);
|
|
34
|
+
const cacheKey = ['community', 'collection', queryStreamId];
|
|
35
|
+
const paginationController = new RecommendedCommunitiesPaginationController(query);
|
|
36
|
+
|
|
37
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
38
|
+
|
|
39
|
+
this.query = query;
|
|
40
|
+
this.queryStreamController = new RecommendedCommunitiesQueryStreamController(
|
|
41
|
+
this.query,
|
|
42
|
+
this.cacheKey,
|
|
43
|
+
this.notifyChange.bind(this),
|
|
44
|
+
prepareCommunityPayload,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
this.callback = callback.bind(this);
|
|
48
|
+
this.loadPage({ initial: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected setup() {
|
|
52
|
+
const collection = pullFromCache<Amity.RecommendedCommunityLiveCollectionCache>(
|
|
53
|
+
this.cacheKey,
|
|
54
|
+
)?.data;
|
|
55
|
+
if (!collection) {
|
|
56
|
+
pushToCache(this.cacheKey, {
|
|
57
|
+
data: [],
|
|
58
|
+
params: {},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected async persistModel(queryPayload: Amity.CommunityPayload & Amity.Pagination) {
|
|
64
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected persistQueryStream({
|
|
68
|
+
response,
|
|
69
|
+
direction,
|
|
70
|
+
refresh,
|
|
71
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'community'>) {
|
|
72
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
startSubscription() {
|
|
76
|
+
return this.queryStreamController.subscribeRTE([
|
|
77
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
78
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
79
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
80
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
81
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
|
|
82
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
83
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
88
|
+
const collection = pullFromCache<Amity.RecommendedCommunityLiveCollectionCache>(
|
|
89
|
+
this.cacheKey,
|
|
90
|
+
)?.data;
|
|
91
|
+
if (!collection) return;
|
|
92
|
+
|
|
93
|
+
const data =
|
|
94
|
+
collection.data
|
|
95
|
+
.map(id => pullFromCache<Amity.Community>(['community', 'get', id]))
|
|
96
|
+
.filter(isNonNullable)
|
|
97
|
+
.map(({ data }) => data) ?? [];
|
|
98
|
+
|
|
99
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
100
|
+
|
|
101
|
+
this.callback({
|
|
102
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
103
|
+
data,
|
|
104
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
105
|
+
loading,
|
|
106
|
+
error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { PaginationController } from '~/core/liveCollection/PaginationController';
|
|
2
|
+
import { COLLECTION_DEFAULT_PAGINATION_LIMIT } from '~/utils/constants';
|
|
3
|
+
import { inferIsDeleted } from '~/utils/inferIsDeleted';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* TODO: handle cache receive cache option, and cache policy
|
|
7
|
+
* TODO: check if querybyIds is supported
|
|
8
|
+
*/
|
|
9
|
+
export class RecommendedCommunitiesPaginationController extends PaginationController<
|
|
10
|
+
'community',
|
|
11
|
+
Amity.RecommendedCommunityLiveCollection
|
|
12
|
+
> {
|
|
13
|
+
async getRequest(
|
|
14
|
+
queryParams: Amity.RecommendedCommunityLiveCollection,
|
|
15
|
+
token: string | undefined,
|
|
16
|
+
) {
|
|
17
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, ...params } = queryParams;
|
|
18
|
+
const options = token ? { token } : { limit };
|
|
19
|
+
|
|
20
|
+
const { data: queryResponse } = await this.http.get<Amity.CommunityPayload & Amity.Pagination>(
|
|
21
|
+
`/api/v3/communities/recommended`,
|
|
22
|
+
{
|
|
23
|
+
params: {
|
|
24
|
+
...params,
|
|
25
|
+
options,
|
|
26
|
+
},
|
|
27
|
+
},
|
|
28
|
+
);
|
|
29
|
+
return queryResponse;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import { QueryStreamController } from '~/core/liveCollection/QueryStreamController';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
import { getResolver } from '~/core/model';
|
|
5
|
+
import { getActiveClient } from '~/client';
|
|
6
|
+
import { saveCommunityUsers } from '~/communityRepository/utils/saveCommunityUsers';
|
|
7
|
+
import { EnumCommunityActions } from './enums';
|
|
8
|
+
import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
|
|
9
|
+
|
|
10
|
+
export class RecommendedCommunitiesQueryStreamController extends QueryStreamController<
|
|
11
|
+
Amity.RecommendedCommunityPayload,
|
|
12
|
+
Amity.RecommendedCommunityLiveCollection
|
|
13
|
+
> {
|
|
14
|
+
private notifyChange: (params: Amity.LiveCollectionNotifyParams) => void;
|
|
15
|
+
|
|
16
|
+
private preparePayload: (
|
|
17
|
+
response: Amity.RecommendedCommunityPayload,
|
|
18
|
+
) => Amity.ProcessedCommunityPayload;
|
|
19
|
+
|
|
20
|
+
constructor(
|
|
21
|
+
query: Amity.RecommendedCommunityLiveCollection,
|
|
22
|
+
cacheKey: string[],
|
|
23
|
+
notifyChange: (params: Amity.LiveCollectionNotifyParams) => void,
|
|
24
|
+
preparePayload: (
|
|
25
|
+
response: Amity.RecommendedCommunityPayload,
|
|
26
|
+
) => Amity.ProcessedCommunityPayload,
|
|
27
|
+
) {
|
|
28
|
+
super(query, cacheKey);
|
|
29
|
+
this.notifyChange = notifyChange;
|
|
30
|
+
this.preparePayload = preparePayload;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
async saveToMainDB(response: Amity.RecommendedCommunityPayload) {
|
|
34
|
+
const processedPayload = await this.preparePayload(response);
|
|
35
|
+
|
|
36
|
+
const client = getActiveClient();
|
|
37
|
+
const cachedAt = client.cache && Date.now();
|
|
38
|
+
|
|
39
|
+
if (client.cache) {
|
|
40
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
41
|
+
saveCommunityUsers(response.communities, response.communityUsers);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
appendToQueryStream(
|
|
46
|
+
response: Amity.RecommendedCommunityPayload & Partial<Amity.Pagination>,
|
|
47
|
+
direction: Amity.LiveCollectionPageDirection,
|
|
48
|
+
refresh = false,
|
|
49
|
+
) {
|
|
50
|
+
if (refresh) {
|
|
51
|
+
pushToCache(this.cacheKey, {
|
|
52
|
+
data: response.communities.map(getResolver('community')),
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
const collection = pullFromCache<Amity.RecommendedCommunityLiveCollectionCache>(
|
|
56
|
+
this.cacheKey,
|
|
57
|
+
)?.data;
|
|
58
|
+
|
|
59
|
+
const communities = collection?.data ?? [];
|
|
60
|
+
|
|
61
|
+
pushToCache(this.cacheKey, {
|
|
62
|
+
...collection,
|
|
63
|
+
data: [...new Set([...communities, ...response.communities.map(getResolver('community'))])],
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
reactor(action: EnumCommunityActions | EnumCommunityMemberActions) {
|
|
69
|
+
return (community: Amity.Community) => {
|
|
70
|
+
const collection = pullFromCache<Amity.RecommendedCommunityLiveCollectionCache>(
|
|
71
|
+
this.cacheKey,
|
|
72
|
+
)?.data;
|
|
73
|
+
if (!collection) return;
|
|
74
|
+
|
|
75
|
+
pushToCache(this.cacheKey, collection);
|
|
76
|
+
this.notifyChange({ origin: Amity.LiveDataOrigin.EVENT, loading: false });
|
|
77
|
+
};
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
subscribeRTE(
|
|
81
|
+
createSubscriber: {
|
|
82
|
+
fn: (reactor: (channel: Amity.Community) => void) => Amity.Unsubscriber;
|
|
83
|
+
action: EnumCommunityActions | EnumCommunityMemberActions;
|
|
84
|
+
}[],
|
|
85
|
+
) {
|
|
86
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
87
|
+
}
|
|
88
|
+
}
|
|
@@ -1,18 +1,9 @@
|
|
|
1
|
-
/* eslint-disable no-use-before-define */
|
|
2
|
-
import { getResolver } from '~/core/model';
|
|
3
1
|
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
4
2
|
import { getActiveClient } from '~/client/api';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
8
|
-
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
9
|
-
ENABLE_CACHE_MESSAGE,
|
|
10
|
-
} from '~/utils/constants';
|
|
3
|
+
import { ENABLE_CACHE_MESSAGE } from '~/utils/constants';
|
|
11
4
|
|
|
12
|
-
import { onCommunityUserChanged } from '../communityMembership/events';
|
|
13
5
|
import { getRecommendedCommunities as _getRecommendedCommunities } from '../api/getRecommendedCommunities';
|
|
14
|
-
import {
|
|
15
|
-
import { communityQueryFilter } from '../utils/communityQueryFilter';
|
|
6
|
+
import { RecommendedCommunityLiveCollectionController } from './getRecommendedCommunities/RecommendedCommunitiesLiveCollectionController';
|
|
16
7
|
|
|
17
8
|
/* begin_public_function
|
|
18
9
|
id: community.query.recommended_communities
|
|
@@ -36,7 +27,7 @@ import { communityQueryFilter } from '../utils/communityQueryFilter';
|
|
|
36
27
|
* @category Community Live Collection
|
|
37
28
|
*/
|
|
38
29
|
export const getRecommendedCommunities = (
|
|
39
|
-
params: Amity.
|
|
30
|
+
params: Amity.RecommendedCommunityLiveCollection,
|
|
40
31
|
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
41
32
|
config?: Amity.LiveCollectionConfig,
|
|
42
33
|
) => {
|
|
@@ -49,77 +40,14 @@ export const getRecommendedCommunities = (
|
|
|
49
40
|
const timestamp = Date.now();
|
|
50
41
|
log(`getRecommendedCommunities(tmpid: ${timestamp}) > listen`);
|
|
51
42
|
|
|
52
|
-
const
|
|
43
|
+
const recommendedCommunitiesLiveCollection = new RecommendedCommunityLiveCollectionController(
|
|
44
|
+
params,
|
|
45
|
+
callback,
|
|
46
|
+
);
|
|
47
|
+
const disposers = recommendedCommunitiesLiveCollection.startSubscription();
|
|
53
48
|
|
|
54
|
-
const
|
|
55
|
-
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
49
|
+
const cacheKey = recommendedCommunitiesLiveCollection.getCacheKey();
|
|
56
50
|
|
|
57
|
-
const disposers: Amity.Unsubscriber[] = [];
|
|
58
|
-
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
59
|
-
|
|
60
|
-
const responder = (data: Amity.CommunityLiveCollectionCache, isEventModel = false) => {
|
|
61
|
-
const communities: Amity.Community[] =
|
|
62
|
-
data.data
|
|
63
|
-
.map(communityId => pullFromCache<Amity.Community>(['community', 'get', communityId])!)
|
|
64
|
-
.filter(Boolean)
|
|
65
|
-
.map(({ data }) => data) ?? [];
|
|
66
|
-
|
|
67
|
-
callback({
|
|
68
|
-
onNextPage: onFetch,
|
|
69
|
-
data: isEventModel ? communityQueryFilter(communities, params, userId!) : communities,
|
|
70
|
-
hasNextPage: !!data.params?.page,
|
|
71
|
-
loading: data.loading,
|
|
72
|
-
error: data.error,
|
|
73
|
-
});
|
|
74
|
-
};
|
|
75
|
-
|
|
76
|
-
const realtimeRouter = (_: Amity.CommunityActionType) => (community: Amity.Community) => {
|
|
77
|
-
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
|
|
78
|
-
if (!collection) return;
|
|
79
|
-
|
|
80
|
-
/*
|
|
81
|
-
* Simply update collection and let responder decide what to do with data
|
|
82
|
-
*/
|
|
83
|
-
collection.data = [...new Set([community.communityId, ...collection.data])];
|
|
84
|
-
|
|
85
|
-
pushToCache(cacheKey, collection);
|
|
86
|
-
responder(collection);
|
|
87
|
-
};
|
|
88
|
-
|
|
89
|
-
const onFetch = (initial = false) => {
|
|
90
|
-
const collection = pullFromCache<Amity.CommunityLiveCollectionCache>(cacheKey)?.data;
|
|
91
|
-
|
|
92
|
-
const communities = collection?.data ?? [];
|
|
93
|
-
|
|
94
|
-
if (!initial && communities.length > 0 && !collection?.params.page) return;
|
|
95
|
-
|
|
96
|
-
const query = createQuery(_getRecommendedCommunities, params);
|
|
97
|
-
|
|
98
|
-
runQuery(
|
|
99
|
-
query,
|
|
100
|
-
({ data: result, error, loading }) => {
|
|
101
|
-
const data = {
|
|
102
|
-
loading,
|
|
103
|
-
error,
|
|
104
|
-
params,
|
|
105
|
-
data: communities,
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
if (result) {
|
|
109
|
-
data.data = [...new Set([...communities, ...result.map(getResolver('community'))])];
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
pushToCache(cacheKey, data);
|
|
113
|
-
|
|
114
|
-
responder(data);
|
|
115
|
-
},
|
|
116
|
-
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
117
|
-
);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
disposers.push(onCommunityUserChanged(realtimeRouter('onMemberCountChanged')));
|
|
121
|
-
|
|
122
|
-
onFetch(true);
|
|
123
51
|
disposers.push(() => dropFromCache(cacheKey));
|
|
124
52
|
|
|
125
53
|
return () => {
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
import hash from 'object-hash';
|
|
2
|
+
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { TrendingCommunitiesPaginationController } from './TrendingCommunitiesPaginationController';
|
|
4
|
+
import { TrendingCommunitiesQueryStreamController } from './TrendingCommunitiesQueryStreamController';
|
|
5
|
+
import { LiveCollectionController } from '~/core/liveCollection/LiveCollectionController';
|
|
6
|
+
import { onCommunityDeleted, onCommunityUpdated } from '~/communityRepository/events';
|
|
7
|
+
import { prepareCommunityPayload } from '~/communityRepository/utils';
|
|
8
|
+
import { EnumCommunityActions } from './enums';
|
|
9
|
+
import { EnumCommunityMemberActions } from '~/communityRepository/communityMembership/observers/getMembers/enums';
|
|
10
|
+
import {
|
|
11
|
+
onCommunityJoined,
|
|
12
|
+
onCommunityLeft,
|
|
13
|
+
onLocalCommunityJoined,
|
|
14
|
+
onLocalCommunityLeft,
|
|
15
|
+
onCommunityUserChanged,
|
|
16
|
+
} from '~/communityRepository/communityMembership';
|
|
17
|
+
import { isNonNullable } from '~/utils';
|
|
18
|
+
|
|
19
|
+
export class TrendingCommunityLiveCollectionController extends LiveCollectionController<
|
|
20
|
+
'community',
|
|
21
|
+
Amity.TrendingCommunityLiveCollection,
|
|
22
|
+
Amity.Community,
|
|
23
|
+
TrendingCommunitiesPaginationController
|
|
24
|
+
> {
|
|
25
|
+
private queryStreamController: TrendingCommunitiesQueryStreamController;
|
|
26
|
+
|
|
27
|
+
private query: Amity.TrendingCommunityLiveCollection;
|
|
28
|
+
|
|
29
|
+
constructor(
|
|
30
|
+
query: Amity.TrendingCommunityLiveCollection,
|
|
31
|
+
callback: Amity.LiveCollectionCallback<Amity.Community>,
|
|
32
|
+
) {
|
|
33
|
+
const queryStreamId = hash(query);
|
|
34
|
+
const cacheKey = ['trendingCommunity', 'collection', queryStreamId];
|
|
35
|
+
const paginationController = new TrendingCommunitiesPaginationController(query);
|
|
36
|
+
|
|
37
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
38
|
+
|
|
39
|
+
this.query = query;
|
|
40
|
+
this.queryStreamController = new TrendingCommunitiesQueryStreamController(
|
|
41
|
+
this.query,
|
|
42
|
+
this.cacheKey,
|
|
43
|
+
this.notifyChange.bind(this),
|
|
44
|
+
prepareCommunityPayload,
|
|
45
|
+
);
|
|
46
|
+
|
|
47
|
+
this.callback = callback.bind(this);
|
|
48
|
+
this.loadPage({ initial: true });
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
protected setup() {
|
|
52
|
+
const collection = pullFromCache<Amity.TrendingCommunityLiveCollectionCache>(
|
|
53
|
+
this.cacheKey,
|
|
54
|
+
)?.data;
|
|
55
|
+
if (!collection) {
|
|
56
|
+
pushToCache(this.cacheKey, {
|
|
57
|
+
data: [],
|
|
58
|
+
params: {},
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
protected async persistModel(queryPayload: Amity.TrendingCommunityPayload & Amity.Pagination) {
|
|
64
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
protected persistQueryStream({
|
|
68
|
+
response,
|
|
69
|
+
direction,
|
|
70
|
+
refresh,
|
|
71
|
+
}: Amity.LiveCollectionPersistQueryStreamParams<'community'>) {
|
|
72
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
startSubscription() {
|
|
76
|
+
return this.queryStreamController.subscribeRTE([
|
|
77
|
+
{ fn: onCommunityDeleted, action: EnumCommunityActions.OnCommunityDeleted },
|
|
78
|
+
{ fn: onCommunityUpdated, action: EnumCommunityActions.OnCommunityUpdated },
|
|
79
|
+
{ fn: onCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
80
|
+
{ fn: onCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
81
|
+
{ fn: onCommunityUserChanged, action: EnumCommunityMemberActions.OnMemberCountChanged },
|
|
82
|
+
{ fn: onLocalCommunityJoined, action: EnumCommunityMemberActions.OnCommunityJoined },
|
|
83
|
+
{ fn: onLocalCommunityLeft, action: EnumCommunityMemberActions.OnCommunityLeft },
|
|
84
|
+
]);
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
notifyChange({ origin, loading, error }: Amity.LiveCollectionNotifyParams) {
|
|
88
|
+
const collection = pullFromCache<Amity.TrendingCommunityLiveCollectionCache>(
|
|
89
|
+
this.cacheKey,
|
|
90
|
+
)?.data;
|
|
91
|
+
if (!collection) return;
|
|
92
|
+
|
|
93
|
+
const data =
|
|
94
|
+
collection.data
|
|
95
|
+
.map(id => pullFromCache<Amity.Community>(['community', 'get', id]))
|
|
96
|
+
.filter(isNonNullable)
|
|
97
|
+
.map(({ data }) => data) ?? [];
|
|
98
|
+
|
|
99
|
+
if (!this.shouldNotify(data) && origin === 'event') return;
|
|
100
|
+
|
|
101
|
+
this.callback({
|
|
102
|
+
onNextPage: () => this.loadPage({ direction: Amity.LiveCollectionPageDirection.NEXT }),
|
|
103
|
+
data,
|
|
104
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
105
|
+
loading,
|
|
106
|
+
error,
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
}
|