@amityco/ts-sdk 0.0.1-beta.13 → 0.0.1-beta.16
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/README.md +3 -3
- package/dist/@types/core/cache.d.ts +2 -2
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +12 -3
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/paging.d.ts +22 -41
- package/dist/@types/core/paging.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +10 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/query.d.ts +13 -4
- package/dist/@types/core/query.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +0 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -2
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +20 -0
- package/dist/@types/domains/follow.d.ts.map +1 -0
- package/dist/@types/domains/mention.d.ts +23 -0
- package/dist/@types/domains/mention.d.ts.map +1 -0
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/partials.d.ts +0 -10
- package/dist/@types/domains/partials.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -2
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +2 -2
- package/dist/channel/api/createChannel.d.ts +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/client/api/activeUser.d.ts +6 -0
- package/dist/client/api/activeUser.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +3 -3
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/utils/endpoints.d.ts +12 -0
- package/dist/client/utils/endpoints.d.ts.map +1 -0
- package/dist/community/api/getRecommendedCommunities.d.ts +32 -0
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -0
- package/dist/community/api/getTopTrendingCommunities.d.ts +32 -0
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -0
- package/dist/community/api/index.d.ts +2 -0
- package/dist/community/api/index.d.ts.map +1 -1
- package/dist/core/debug.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/microtasks.d.ts +13 -0
- package/dist/core/microtasks.d.ts.map +1 -0
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +5 -16
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +2 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +22 -4
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/follow/api/acceptFollower.d.ts +16 -0
- package/dist/follow/api/acceptFollower.d.ts.map +1 -0
- package/dist/follow/api/declineFollower.d.ts +16 -0
- package/dist/follow/api/declineFollower.d.ts.map +1 -0
- package/dist/follow/api/follow.d.ts +16 -0
- package/dist/follow/api/follow.d.ts.map +1 -0
- package/dist/follow/api/getFollowInfo.d.ts +32 -0
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -0
- package/dist/follow/api/index.d.ts +8 -0
- package/dist/follow/api/index.d.ts.map +1 -0
- package/dist/follow/api/queryFollowers.d.ts +36 -0
- package/dist/follow/api/queryFollowers.d.ts.map +1 -0
- package/dist/follow/api/queryFollowings.d.ts +36 -0
- package/dist/follow/api/queryFollowings.d.ts.map +1 -0
- package/dist/follow/api/unfollow.d.ts +16 -0
- package/dist/follow/api/unfollow.d.ts.map +1 -0
- package/dist/follow/api/utils.d.ts +9 -0
- package/dist/follow/api/utils.d.ts.map +1 -0
- package/dist/follow/events/index.d.ts +9 -0
- package/dist/follow/events/index.d.ts.map +1 -0
- package/dist/follow/events/onFollowInfoUpdated.d.ts +17 -0
- package/dist/follow/events/onFollowInfoUpdated.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestAccepted.d.ts +17 -0
- package/dist/follow/events/onFollowRequestAccepted.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestCanceled.d.ts +17 -0
- package/dist/follow/events/onFollowRequestCanceled.d.ts.map +1 -0
- package/dist/follow/events/onFollowRequestDeclined.d.ts +17 -0
- package/dist/follow/events/onFollowRequestDeclined.d.ts.map +1 -0
- package/dist/follow/events/onFollowerDeleted.d.ts +17 -0
- package/dist/follow/events/onFollowerDeleted.d.ts.map +1 -0
- package/dist/follow/events/onFollowerRequested.d.ts +17 -0
- package/dist/follow/events/onFollowerRequested.d.ts.map +1 -0
- package/dist/follow/events/onUserFollowed.d.ts +17 -0
- package/dist/follow/events/onUserFollowed.d.ts.map +1 -0
- package/dist/follow/events/onUserUnfollowed.d.ts +17 -0
- package/dist/follow/events/onUserUnfollowed.d.ts.map +1 -0
- package/dist/follow/events/utils.d.ts +2 -0
- package/dist/follow/events/utils.d.ts.map +1 -0
- package/dist/follow/observers/index.d.ts +4 -0
- package/dist/follow/observers/index.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowInfo.d.ts +18 -0
- package/dist/follow/observers/observeFollowInfo.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowers.d.ts +18 -0
- package/dist/follow/observers/observeFollowers.d.ts.map +1 -0
- package/dist/follow/observers/observeFollowings.d.ts +18 -0
- package/dist/follow/observers/observeFollowings.d.ts.map +1 -0
- package/dist/index.cjs.js +845 -74
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +823 -74
- package/dist/index.umd.js +5 -5
- package/dist/message/api/createMessage.d.ts +2 -2
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/api/updateMessage.d.ts +2 -2
- package/dist/message/api/updateMessage.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts +3 -3
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/utils/env.d.ts +5 -0
- package/dist/utils/env.d.ts.map +1 -0
- package/dist/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/cache.ts +2 -2
- package/src/@types/core/events.ts +12 -1
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/paging.ts +31 -46
- package/src/@types/core/payload.ts +14 -0
- package/src/@types/core/query.ts +11 -3
- package/src/@types/domains/client.ts +0 -1
- package/src/@types/domains/comment.ts +1 -3
- package/src/@types/domains/follow.ts +25 -0
- package/src/@types/domains/mention.ts +26 -0
- package/src/@types/domains/message.ts +1 -0
- package/src/@types/domains/partials.ts +0 -8
- package/src/@types/domains/post.ts +1 -3
- package/src/@types/index.ts +3 -0
- package/src/channel/api/createChannel.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +2 -1
- package/src/client/api/activeUser.ts +26 -0
- package/src/client/api/connectClient.ts +3 -1
- package/src/client/api/createClient.ts +7 -7
- package/src/client/utils/endpoints.ts +14 -0
- package/src/community/api/getRecommendedCommunities.ts +86 -0
- package/src/community/api/getTopTrendingCommunities.ts +86 -0
- package/src/community/api/index.ts +3 -0
- package/src/community/api/queryCommunityMembers.ts +1 -1
- package/src/core/debug.ts +3 -1
- package/src/core/device.ts +3 -2
- package/src/core/events.ts +3 -1
- package/src/core/microtasks.ts +27 -0
- package/src/core/model/idResolvers.ts +3 -0
- package/src/core/model/identifyModel.ts +2 -0
- package/src/core/model/index.ts +3 -0
- package/src/core/query/paging.ts +16 -51
- package/src/core/query/query.ts +5 -5
- package/src/core/subscription.ts +21 -3
- package/src/feed/api/queryGlobalFeed.ts +58 -5
- package/src/follow/api/acceptFollower.ts +32 -0
- package/src/follow/api/declineFollower.ts +32 -0
- package/src/follow/api/follow.ts +40 -0
- package/src/follow/api/getFollowInfo.ts +75 -0
- package/src/follow/api/index.ts +8 -0
- package/src/follow/api/queryFollowers.ts +42 -0
- package/src/follow/api/queryFollowings.ts +42 -0
- package/src/follow/api/unfollow.ts +32 -0
- package/src/follow/api/utils.ts +77 -0
- package/src/follow/events/index.ts +10 -0
- package/src/follow/events/onFollowInfoUpdated.ts +43 -0
- package/src/follow/events/onFollowRequestAccepted.ts +19 -0
- package/src/follow/events/onFollowRequestCanceled.ts +19 -0
- package/src/follow/events/onFollowRequestDeclined.ts +19 -0
- package/src/follow/events/onFollowerDeleted.ts +19 -0
- package/src/follow/events/onFollowerRequested.ts +19 -0
- package/src/follow/events/onUserFollowed.ts +19 -0
- package/src/follow/events/onUserUnfollowed.ts +19 -0
- package/src/follow/events/utils.ts +38 -0
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/observeFollowInfo.ts +68 -0
- package/src/follow/observers/observeFollowers.ts +78 -0
- package/src/follow/observers/observeFollowings.ts +78 -0
- package/src/index.ts +5 -0
- package/src/message/api/createMessage.ts +2 -2
- package/src/message/api/updateMessage.ts +2 -2
- package/src/post/api/queryPosts.ts +5 -5
- package/src/utils/env.ts +7 -0
- package/src/version.ts +3 -1
- package/dist/core/network.d.ts +0 -11
- package/dist/core/network.d.ts.map +0 -1
- package/src/core/network.ts +0 -14
package/dist/index.esm.js
CHANGED
|
@@ -6,11 +6,14 @@ import io from 'socket.io-client';
|
|
|
6
6
|
import mitt from 'mitt';
|
|
7
7
|
import AsyncStorage from '@react-native-async-storage/async-storage';
|
|
8
8
|
|
|
9
|
-
var _a;
|
|
10
|
-
|
|
11
|
-
const
|
|
9
|
+
var _a$1;
|
|
10
|
+
const theGlobal = globalThis || global || window;
|
|
11
|
+
const { process: safeProcess = {} } = theGlobal;
|
|
12
|
+
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
13
|
+
|
|
14
|
+
var _a, _b;
|
|
15
|
+
const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
|
|
12
16
|
|
|
13
|
-
// @ts-ignore
|
|
14
17
|
/**
|
|
15
18
|
* Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
|
|
16
19
|
*
|
|
@@ -28,7 +31,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
28
31
|
*
|
|
29
32
|
* @hidden
|
|
30
33
|
*/
|
|
31
|
-
const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
|
|
34
|
+
const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
|
|
32
35
|
/**
|
|
33
36
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
34
37
|
*
|
|
@@ -37,7 +40,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
|
|
|
37
40
|
*
|
|
38
41
|
* @hidden
|
|
39
42
|
*/
|
|
40
|
-
const isAfterBeforeRaw = (json) => (
|
|
43
|
+
const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
41
44
|
/**
|
|
42
45
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
43
46
|
*
|
|
@@ -72,7 +75,7 @@ const toToken = (paging, style) => {
|
|
|
72
75
|
limit: paging.limit,
|
|
73
76
|
};
|
|
74
77
|
}
|
|
75
|
-
else if (style === 'afterbefore') {
|
|
78
|
+
else if (style === 'afterbefore' && isAfterBefore(paging)) {
|
|
76
79
|
/*
|
|
77
80
|
Caution: this testing style is only valid because
|
|
78
81
|
our backend expects nothing else than a number as
|
|
@@ -116,7 +119,7 @@ const toToken = (paging, style) => {
|
|
|
116
119
|
*/
|
|
117
120
|
const toPage = (token) => {
|
|
118
121
|
if (!token)
|
|
119
|
-
return
|
|
122
|
+
return undefined;
|
|
120
123
|
// don't try catch, let it throw
|
|
121
124
|
const json = JSON.parse(decode(token));
|
|
122
125
|
if (isSkipLimit(json)) {
|
|
@@ -139,7 +142,7 @@ const toPage = (token) => {
|
|
|
139
142
|
};
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
|
-
return
|
|
145
|
+
return undefined;
|
|
143
146
|
};
|
|
144
147
|
/**
|
|
145
148
|
* Converts a b64 string token into a paging object
|
|
@@ -151,42 +154,13 @@ const toPage = (token) => {
|
|
|
151
154
|
*/
|
|
152
155
|
const toPageRaw = (token) => {
|
|
153
156
|
if (!token)
|
|
154
|
-
return
|
|
157
|
+
return undefined;
|
|
155
158
|
// don't try catch, let it throw
|
|
156
159
|
const json = JSON.parse(decode(token));
|
|
157
160
|
if (isAfterBeforeRaw(json)) {
|
|
158
161
|
return json;
|
|
159
162
|
}
|
|
160
|
-
return
|
|
161
|
-
};
|
|
162
|
-
/**
|
|
163
|
-
* Slices a collection according to its paging
|
|
164
|
-
*
|
|
165
|
-
* @param type the type of collection (for unique id identification with after/before)
|
|
166
|
-
* @param collection the collection to slice
|
|
167
|
-
* @param paging the paging object
|
|
168
|
-
* @returns the sliced collection according to the paging definition
|
|
169
|
-
*
|
|
170
|
-
* @hidden
|
|
171
|
-
*/
|
|
172
|
-
const sliceByPaging = (type, collection, page) => {
|
|
173
|
-
console.log('slice by paging', page);
|
|
174
|
-
if (!page)
|
|
175
|
-
return collection.slice();
|
|
176
|
-
let start = 0;
|
|
177
|
-
let end = undefined;
|
|
178
|
-
// next page behavior
|
|
179
|
-
if (page.after) {
|
|
180
|
-
start = page.after;
|
|
181
|
-
end = start + page.limit;
|
|
182
|
-
// prev page behavior
|
|
183
|
-
}
|
|
184
|
-
else if (page.before) {
|
|
185
|
-
end = page.before + 1;
|
|
186
|
-
start = end > page.limit ? end - page.limit : 0;
|
|
187
|
-
}
|
|
188
|
-
const paged = collection.slice(start, end);
|
|
189
|
-
return paged.length === page.limit ? paged : undefined;
|
|
163
|
+
return undefined;
|
|
190
164
|
};
|
|
191
165
|
|
|
192
166
|
/**
|
|
@@ -499,9 +473,8 @@ const setActiveClient = (client) => {
|
|
|
499
473
|
* @hidden
|
|
500
474
|
*/
|
|
501
475
|
const createLogger = (session) => {
|
|
502
|
-
var _a;
|
|
503
476
|
const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
|
|
504
|
-
&&
|
|
477
|
+
&& !isProduction);
|
|
505
478
|
const logger = debug(session);
|
|
506
479
|
const print = (topic, ...args) => {
|
|
507
480
|
active && logger(topic, args);
|
|
@@ -510,19 +483,18 @@ const createLogger = (session) => {
|
|
|
510
483
|
return print;
|
|
511
484
|
};
|
|
512
485
|
|
|
513
|
-
const
|
|
486
|
+
const API_REGIONS = {
|
|
514
487
|
EU: 'eu',
|
|
515
488
|
SG: 'sg',
|
|
516
489
|
US: 'us',
|
|
517
490
|
};
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
};
|
|
491
|
+
const URLS = {
|
|
492
|
+
http: 'https://api.{region}.amity.co',
|
|
493
|
+
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
494
|
+
};
|
|
495
|
+
function computeUrl(type, region) {
|
|
496
|
+
return URLS[type].replace('{region}', region);
|
|
497
|
+
}
|
|
526
498
|
|
|
527
499
|
/**
|
|
528
500
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
@@ -14728,6 +14700,22 @@ const createMqttTransport = (endpoint) => {
|
|
|
14728
14700
|
};
|
|
14729
14701
|
};
|
|
14730
14702
|
|
|
14703
|
+
let tasks = [];
|
|
14704
|
+
let timer;
|
|
14705
|
+
/**
|
|
14706
|
+
* Add a function to run just before the next tick
|
|
14707
|
+
*
|
|
14708
|
+
* @param task function to schedule for later execution
|
|
14709
|
+
*/
|
|
14710
|
+
const scheduleTask = (task) => {
|
|
14711
|
+
clearTimeout(timer);
|
|
14712
|
+
tasks.push(task);
|
|
14713
|
+
timer = setTimeout(() => {
|
|
14714
|
+
tasks.forEach(fn => fn());
|
|
14715
|
+
tasks = [];
|
|
14716
|
+
}, 0);
|
|
14717
|
+
};
|
|
14718
|
+
|
|
14731
14719
|
// need to sync up the list
|
|
14732
14720
|
const WS_EVENTS = [
|
|
14733
14721
|
'disconnected',
|
|
@@ -14818,7 +14806,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14818
14806
|
*/
|
|
14819
14807
|
const fireEvent = (event, payload) => {
|
|
14820
14808
|
const { emitter } = getActiveClient();
|
|
14821
|
-
|
|
14809
|
+
scheduleTask(() => { emitter.emit(event, payload); });
|
|
14822
14810
|
};
|
|
14823
14811
|
|
|
14824
14812
|
/**
|
|
@@ -14830,21 +14818,21 @@ const fireEvent = (event, payload) => {
|
|
|
14830
14818
|
* Creates a new {@link Amity.Client} instance
|
|
14831
14819
|
*
|
|
14832
14820
|
* @param apiKey for the {@link Amity.Client} instance
|
|
14833
|
-
* @param
|
|
14821
|
+
* @param apiRegion endpoint to connect to
|
|
14834
14822
|
* @param debugSession session's identifier for the client's logger instance
|
|
14835
14823
|
* @returns A {@link Amity.Client} instance
|
|
14836
14824
|
*
|
|
14837
14825
|
* @category Client API
|
|
14838
14826
|
**/
|
|
14839
|
-
const createClient = (apiKey,
|
|
14827
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
|
|
14840
14828
|
const log = createLogger(debugSession);
|
|
14841
14829
|
log('client/api/createClient', {
|
|
14842
14830
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
14843
|
-
|
|
14831
|
+
apiRegion,
|
|
14844
14832
|
});
|
|
14845
|
-
const http = createHttpTransport(
|
|
14846
|
-
const ws = createWebsocketTransport(
|
|
14847
|
-
const mqtt = createMqttTransport(
|
|
14833
|
+
const http = createHttpTransport(computeUrl('http', apiRegion));
|
|
14834
|
+
const ws = createWebsocketTransport(computeUrl('http', apiRegion));
|
|
14835
|
+
const mqtt = createMqttTransport(computeUrl('mqtt', apiRegion));
|
|
14848
14836
|
const emitter = createEventEmitter();
|
|
14849
14837
|
const client = {
|
|
14850
14838
|
version: `${VERSION$1}`,
|
|
@@ -14897,7 +14885,6 @@ const disconnectClient = async () => {
|
|
|
14897
14885
|
};
|
|
14898
14886
|
|
|
14899
14887
|
// TODO: find a way to uniquely identify the device
|
|
14900
|
-
// import { getStorage } from './storage'
|
|
14901
14888
|
/** @hidden */
|
|
14902
14889
|
const VERSION = '11.0.0';
|
|
14903
14890
|
/** @hidden */
|
|
@@ -14912,8 +14899,8 @@ const getDeviceId = () => {
|
|
|
14912
14899
|
/** @hidden */
|
|
14913
14900
|
const getDeviceModel = () => {
|
|
14914
14901
|
var _a, _b;
|
|
14915
|
-
if ((_a =
|
|
14916
|
-
return
|
|
14902
|
+
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
14903
|
+
return safeProcess.versions.node;
|
|
14917
14904
|
if (navigator)
|
|
14918
14905
|
return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
|
|
14919
14906
|
return 'unknown_model';
|
|
@@ -14929,6 +14916,24 @@ const getDeviceInfo = () => {
|
|
|
14929
14916
|
};
|
|
14930
14917
|
};
|
|
14931
14918
|
|
|
14919
|
+
let activeUser = null;
|
|
14920
|
+
/**
|
|
14921
|
+
* for internal use
|
|
14922
|
+
*/
|
|
14923
|
+
const getActiveUser = () => {
|
|
14924
|
+
if (!activeUser) {
|
|
14925
|
+
throw new ASCError('Connect client first', 800000 /* UNKNOWN_ERROR */, "fatal" /* FATAL */);
|
|
14926
|
+
}
|
|
14927
|
+
return activeUser;
|
|
14928
|
+
};
|
|
14929
|
+
const setActiveUser = (user) => {
|
|
14930
|
+
activeUser = {
|
|
14931
|
+
_id: user._id,
|
|
14932
|
+
userId: user.userId,
|
|
14933
|
+
path: user.path,
|
|
14934
|
+
};
|
|
14935
|
+
};
|
|
14936
|
+
|
|
14932
14937
|
/**
|
|
14933
14938
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14934
14939
|
*
|
|
@@ -15076,8 +15081,8 @@ const connectClient = async (params) => {
|
|
|
15076
15081
|
unsubscribe();
|
|
15077
15082
|
});
|
|
15078
15083
|
client.userId = params.userId;
|
|
15079
|
-
client._internalUserId = users[0]._id;
|
|
15080
15084
|
client.accessToken = accessToken;
|
|
15085
|
+
setActiveUser(users[0]);
|
|
15081
15086
|
return client.ws.connected;
|
|
15082
15087
|
};
|
|
15083
15088
|
|
|
@@ -15135,13 +15140,24 @@ const getPostTopic = ({ path }, level = SubscriptionLevels.POST) => {
|
|
|
15135
15140
|
const getCommentTopic = ({ path }) => {
|
|
15136
15141
|
return path;
|
|
15137
15142
|
};
|
|
15143
|
+
const getMyFollowersTopic = () => {
|
|
15144
|
+
const user = getActiveUser();
|
|
15145
|
+
const [networkId] = user.path.split('/user/');
|
|
15146
|
+
return `${networkId}/membership/${user._id}/+/+`;
|
|
15147
|
+
};
|
|
15148
|
+
const getMyFollowingsTopic = () => {
|
|
15149
|
+
const user = getActiveUser();
|
|
15150
|
+
const [networkId] = user.path.split('/user/');
|
|
15151
|
+
return `${networkId}/membership/+/${user._id}/+`;
|
|
15152
|
+
};
|
|
15138
15153
|
let mqttAccessToken;
|
|
15139
15154
|
let mqttUserId;
|
|
15140
15155
|
function subscribeTopic(topic, callback) {
|
|
15141
|
-
const { mqtt, emitter, accessToken
|
|
15142
|
-
|
|
15156
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15157
|
+
const user = getActiveUser();
|
|
15158
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15143
15159
|
mqttAccessToken = accessToken;
|
|
15144
|
-
mqttUserId =
|
|
15160
|
+
mqttUserId = user._id;
|
|
15145
15161
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15146
15162
|
proxyMqttEvents(mqtt, emitter);
|
|
15147
15163
|
}
|
|
@@ -15547,6 +15563,8 @@ const idResolvers = {
|
|
|
15547
15563
|
post: ({ postId }) => postId,
|
|
15548
15564
|
comment: ({ commentId }) => commentId,
|
|
15549
15565
|
stream: ({ streamId }) => streamId,
|
|
15566
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15567
|
+
followCount: ({ userId }) => userId,
|
|
15550
15568
|
};
|
|
15551
15569
|
/**
|
|
15552
15570
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15573,6 +15591,8 @@ const PAYLOAD2MODEL = {
|
|
|
15573
15591
|
postChildren: 'post',
|
|
15574
15592
|
comments: 'comment',
|
|
15575
15593
|
videoStreamings: 'stream',
|
|
15594
|
+
follows: 'follow',
|
|
15595
|
+
followCounts: 'followCount'
|
|
15576
15596
|
};
|
|
15577
15597
|
|
|
15578
15598
|
/**
|
|
@@ -16636,11 +16656,11 @@ const queryPosts = async (query) => {
|
|
|
16636
16656
|
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16637
16657
|
// API-FIX: parameters should be querystring. (1)
|
|
16638
16658
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16639
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16659
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16640
16660
|
, ["page"]);
|
|
16641
16661
|
// API-FIX: parameters should be querystring. (1)
|
|
16642
16662
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16643
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16663
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16644
16664
|
const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
16645
16665
|
token: toToken(page, 'afterbeforeraw'),
|
|
16646
16666
|
} }), });
|
|
@@ -17227,7 +17247,7 @@ const queryCommunityMembers = async (query) => {
|
|
|
17227
17247
|
}
|
|
17228
17248
|
const nextPage = toPage(paging.next);
|
|
17229
17249
|
const prevPage = toPage(paging.previous);
|
|
17230
|
-
return { data: communityUsers, nextPage, prevPage };
|
|
17250
|
+
return { data: communityUsers, cachedAt, nextPage, prevPage };
|
|
17231
17251
|
};
|
|
17232
17252
|
/**
|
|
17233
17253
|
* ```js
|
|
@@ -17354,6 +17374,132 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17354
17374
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && !communityUser.roles.includes(roleId));
|
|
17355
17375
|
};
|
|
17356
17376
|
|
|
17377
|
+
/**
|
|
17378
|
+
* ```js
|
|
17379
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17380
|
+
* const trendingCommunities = await getTopTrendingCommunities()
|
|
17381
|
+
* ```
|
|
17382
|
+
*
|
|
17383
|
+
* Gets a list of top trending {@link Amity.Community} objects
|
|
17384
|
+
*
|
|
17385
|
+
* @param query The query parameters
|
|
17386
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17387
|
+
*
|
|
17388
|
+
* @category Community API
|
|
17389
|
+
* @async
|
|
17390
|
+
*/
|
|
17391
|
+
const getTopTrendingCommunities = async (query) => {
|
|
17392
|
+
const client = getActiveClient();
|
|
17393
|
+
client.log('channel/getTopTrendingCommunities', query);
|
|
17394
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17395
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17396
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17397
|
+
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
17398
|
+
const { communities } = data;
|
|
17399
|
+
const cachedAt = client.cache && Date.now();
|
|
17400
|
+
if (client.cache) {
|
|
17401
|
+
ingestInCache(data, { cachedAt });
|
|
17402
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17403
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17404
|
+
}
|
|
17405
|
+
return { data: communities, cachedAt };
|
|
17406
|
+
};
|
|
17407
|
+
/**
|
|
17408
|
+
* ```js
|
|
17409
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17410
|
+
* const communities = getTopTrendingCommunities.locally()
|
|
17411
|
+
* ```
|
|
17412
|
+
*
|
|
17413
|
+
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
17414
|
+
*
|
|
17415
|
+
* @param query The query parameters
|
|
17416
|
+
* @returns communities
|
|
17417
|
+
*
|
|
17418
|
+
* @category Community API
|
|
17419
|
+
*/
|
|
17420
|
+
getTopTrendingCommunities.locally = (query) => {
|
|
17421
|
+
var _a, _b;
|
|
17422
|
+
const client = getActiveClient();
|
|
17423
|
+
client.log('community/getTopTrendingCommunities.locally', query);
|
|
17424
|
+
if (!client.cache)
|
|
17425
|
+
return;
|
|
17426
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17427
|
+
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17428
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17429
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17430
|
+
return;
|
|
17431
|
+
const communities = data.communities
|
|
17432
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17433
|
+
.filter(Boolean)
|
|
17434
|
+
.map(({ data }) => data);
|
|
17435
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17436
|
+
? { data: communities, cachedAt }
|
|
17437
|
+
: undefined;
|
|
17438
|
+
};
|
|
17439
|
+
|
|
17440
|
+
/**
|
|
17441
|
+
* ```js
|
|
17442
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17443
|
+
* const communities = await getRecommendedCommunities()
|
|
17444
|
+
* ```
|
|
17445
|
+
*
|
|
17446
|
+
* Gets a list of recommended {@link Amity.Community} objects
|
|
17447
|
+
*
|
|
17448
|
+
* @param query The query parameters
|
|
17449
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17450
|
+
*
|
|
17451
|
+
* @category Community API
|
|
17452
|
+
* @async
|
|
17453
|
+
*/
|
|
17454
|
+
const getRecommendedCommunities = async (query) => {
|
|
17455
|
+
const client = getActiveClient();
|
|
17456
|
+
client.log('channel/getRecommendedCommunities', query);
|
|
17457
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17458
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17459
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17460
|
+
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
17461
|
+
const { communities } = data;
|
|
17462
|
+
const cachedAt = client.cache && Date.now();
|
|
17463
|
+
if (client.cache) {
|
|
17464
|
+
ingestInCache(data, { cachedAt });
|
|
17465
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17466
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17467
|
+
}
|
|
17468
|
+
return { data: communities, cachedAt };
|
|
17469
|
+
};
|
|
17470
|
+
/**
|
|
17471
|
+
* ```js
|
|
17472
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17473
|
+
* const communities = getRecommendedCommunities.locally()
|
|
17474
|
+
* ```
|
|
17475
|
+
*
|
|
17476
|
+
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
17477
|
+
*
|
|
17478
|
+
* @param query The query parameters
|
|
17479
|
+
* @returns communities
|
|
17480
|
+
*
|
|
17481
|
+
* @category Community API
|
|
17482
|
+
*/
|
|
17483
|
+
getRecommendedCommunities.locally = (query) => {
|
|
17484
|
+
var _a, _b;
|
|
17485
|
+
const client = getActiveClient();
|
|
17486
|
+
client.log('community/getRecommendedCommunities.locally', query);
|
|
17487
|
+
if (!client.cache)
|
|
17488
|
+
return;
|
|
17489
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17490
|
+
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17491
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17492
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17493
|
+
return;
|
|
17494
|
+
const communities = data.communities
|
|
17495
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17496
|
+
.filter(Boolean)
|
|
17497
|
+
.map(({ data }) => data);
|
|
17498
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17499
|
+
? { data: communities, cachedAt }
|
|
17500
|
+
: undefined;
|
|
17501
|
+
};
|
|
17502
|
+
|
|
17357
17503
|
/**
|
|
17358
17504
|
* ```js
|
|
17359
17505
|
* import { deletePost } from '@amityco/ts-sdk'
|
|
@@ -18745,12 +18891,13 @@ const queryChannelMembers = async (query) => {
|
|
|
18745
18891
|
});
|
|
18746
18892
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18747
18893
|
const { channelUsers } = payload;
|
|
18894
|
+
const cachedAt = client.cache && Date.now();
|
|
18748
18895
|
if (client.cache) {
|
|
18749
18896
|
ingestInCache(payload);
|
|
18750
18897
|
}
|
|
18751
18898
|
const nextPage = toPage(paging.next);
|
|
18752
18899
|
const prevPage = toPage(paging.previous);
|
|
18753
|
-
return { data: channelUsers, nextPage, prevPage };
|
|
18900
|
+
return { data: channelUsers, cachedAt, nextPage, prevPage };
|
|
18754
18901
|
};
|
|
18755
18902
|
/**
|
|
18756
18903
|
* ```js
|
|
@@ -19495,17 +19642,619 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19495
19642
|
const queryGlobalFeed = async (query) => {
|
|
19496
19643
|
const client = getActiveClient();
|
|
19497
19644
|
client.log('feed/queryGlobalFeed', query);
|
|
19498
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19499
|
-
const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19645
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19646
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19500
19647
|
token: toToken(page, 'skiplimit')
|
|
19501
19648
|
} }) });
|
|
19502
19649
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19503
19650
|
const { posts } = payload;
|
|
19504
|
-
|
|
19651
|
+
const cachedAt = client.cache && Date.now();
|
|
19652
|
+
if (client.cache) {
|
|
19505
19653
|
ingestInCache(payload);
|
|
19654
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19655
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19656
|
+
}
|
|
19657
|
+
const nextPage = toPage(paging.next);
|
|
19658
|
+
const prevPage = toPage(paging.previous);
|
|
19659
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19660
|
+
};
|
|
19661
|
+
/**
|
|
19662
|
+
* ```js
|
|
19663
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19664
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19665
|
+
* ```
|
|
19666
|
+
*
|
|
19667
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19668
|
+
*
|
|
19669
|
+
* @param query The query parameters
|
|
19670
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19671
|
+
*
|
|
19672
|
+
* @category Feed API
|
|
19673
|
+
* @async
|
|
19674
|
+
**/
|
|
19675
|
+
queryGlobalFeed.locally = (query) => {
|
|
19676
|
+
var _a, _b;
|
|
19677
|
+
const client = getActiveClient();
|
|
19678
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19679
|
+
if (!client.cache)
|
|
19680
|
+
return;
|
|
19681
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19682
|
+
const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19683
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19684
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19685
|
+
return;
|
|
19686
|
+
const posts = data.posts
|
|
19687
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19688
|
+
.filter(Boolean)
|
|
19689
|
+
.map(({ data }) => data);
|
|
19690
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19691
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19692
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19693
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19694
|
+
: undefined;
|
|
19695
|
+
};
|
|
19696
|
+
|
|
19697
|
+
const queryFollows = async (key, query) => {
|
|
19698
|
+
const client = getActiveClient();
|
|
19699
|
+
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
19700
|
+
const { userId, page } = query, params = __rest(query, ["userId", "page"]);
|
|
19701
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
|
|
19702
|
+
params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
|
|
19703
|
+
});
|
|
19704
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19705
|
+
const { follows } = payload;
|
|
19706
|
+
const cachedAt = client.cache && Date.now();
|
|
19707
|
+
if (client.cache) {
|
|
19708
|
+
ingestInCache(payload, { cachedAt });
|
|
19709
|
+
const cacheKey = [key, 'query', Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) })];
|
|
19710
|
+
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
19711
|
+
}
|
|
19506
19712
|
const nextPage = toPage(paging.next);
|
|
19507
19713
|
const prevPage = toPage(paging.previous);
|
|
19508
|
-
return { data:
|
|
19714
|
+
return { data: follows, cachedAt, prevPage, nextPage };
|
|
19715
|
+
};
|
|
19716
|
+
queryFollows.locally = (key, query) => {
|
|
19717
|
+
var _a, _b;
|
|
19718
|
+
const client = getActiveClient();
|
|
19719
|
+
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
19720
|
+
if (!client.cache)
|
|
19721
|
+
return;
|
|
19722
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
19723
|
+
const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19724
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19725
|
+
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
19726
|
+
return;
|
|
19727
|
+
}
|
|
19728
|
+
const follows = data.follows
|
|
19729
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
19730
|
+
.filter(Boolean)
|
|
19731
|
+
.map(({ data }) => data);
|
|
19732
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19733
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19734
|
+
return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
|
|
19735
|
+
? { data: follows, cachedAt, prevPage, nextPage }
|
|
19736
|
+
: undefined;
|
|
19737
|
+
};
|
|
19738
|
+
|
|
19739
|
+
/**
|
|
19740
|
+
* ```js
|
|
19741
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
19742
|
+
* const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
|
|
19743
|
+
* ```
|
|
19744
|
+
*
|
|
19745
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
19746
|
+
*
|
|
19747
|
+
* @param query The query parameters
|
|
19748
|
+
* @returns followers
|
|
19749
|
+
*
|
|
19750
|
+
* @category Follow API
|
|
19751
|
+
* @async
|
|
19752
|
+
*/
|
|
19753
|
+
const queryFollowers = async (query) => queryFollows('followers', query);
|
|
19754
|
+
/**
|
|
19755
|
+
* ```js
|
|
19756
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
19757
|
+
* const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
|
|
19758
|
+
* ```
|
|
19759
|
+
*
|
|
19760
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
19761
|
+
*
|
|
19762
|
+
* @param query The query parameters
|
|
19763
|
+
* @returns followers
|
|
19764
|
+
*
|
|
19765
|
+
* @category Post API
|
|
19766
|
+
*/
|
|
19767
|
+
queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
19768
|
+
|
|
19769
|
+
/**
|
|
19770
|
+
* ```js
|
|
19771
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
19772
|
+
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
19773
|
+
* ```
|
|
19774
|
+
*
|
|
19775
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
19776
|
+
*
|
|
19777
|
+
* @param query The query parameters
|
|
19778
|
+
* @returns followings
|
|
19779
|
+
*
|
|
19780
|
+
* @category Follow API
|
|
19781
|
+
* @async
|
|
19782
|
+
*/
|
|
19783
|
+
const queryFollowings = async (query) => queryFollows('following', query);
|
|
19784
|
+
/**
|
|
19785
|
+
* ```js
|
|
19786
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
19787
|
+
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
19788
|
+
* ```
|
|
19789
|
+
*
|
|
19790
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
19791
|
+
*
|
|
19792
|
+
* @param query The query parameters
|
|
19793
|
+
* @returns followings
|
|
19794
|
+
*
|
|
19795
|
+
* @category Post API
|
|
19796
|
+
*/
|
|
19797
|
+
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
19798
|
+
|
|
19799
|
+
const getCacheKey = (userId) => ['followInfo', 'get', `${getActiveClient().userId}#${userId}`];
|
|
19800
|
+
/**
|
|
19801
|
+
* ```js
|
|
19802
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
19803
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
19804
|
+
* ```
|
|
19805
|
+
*
|
|
19806
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
19807
|
+
*
|
|
19808
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19809
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
19810
|
+
*
|
|
19811
|
+
* @category Follow API
|
|
19812
|
+
* @async
|
|
19813
|
+
*/
|
|
19814
|
+
const getFollowInfo = async (userId) => {
|
|
19815
|
+
var _a, _b;
|
|
19816
|
+
const client = getActiveClient();
|
|
19817
|
+
client.log('follow/getFollowInfo', userId);
|
|
19818
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
|
|
19819
|
+
const cachedAt = client.cache && Date.now();
|
|
19820
|
+
const followInfo = Object.assign(Object.assign({}, data.followCounts[0]), { status: (_b = (_a = data.follows) === null || _a === void 0 ? void 0 : _a[0]) === null || _b === void 0 ? void 0 : _b.status });
|
|
19821
|
+
if (client.cache) {
|
|
19822
|
+
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
19823
|
+
}
|
|
19824
|
+
return {
|
|
19825
|
+
data: followInfo,
|
|
19826
|
+
cachedAt,
|
|
19827
|
+
};
|
|
19828
|
+
};
|
|
19829
|
+
/**
|
|
19830
|
+
* ```js
|
|
19831
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
19832
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
19833
|
+
* ```
|
|
19834
|
+
*
|
|
19835
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
19836
|
+
*
|
|
19837
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19838
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
19839
|
+
*
|
|
19840
|
+
* @category Follow API
|
|
19841
|
+
*/
|
|
19842
|
+
getFollowInfo.locally = (userId) => {
|
|
19843
|
+
const client = getActiveClient();
|
|
19844
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
19845
|
+
if (!client.cache) {
|
|
19846
|
+
return;
|
|
19847
|
+
}
|
|
19848
|
+
const cached = pullFromCache(getCacheKey(userId));
|
|
19849
|
+
if (!cached) {
|
|
19850
|
+
return;
|
|
19851
|
+
}
|
|
19852
|
+
return {
|
|
19853
|
+
data: cached.data,
|
|
19854
|
+
cachedAt: cached.cachedAt,
|
|
19855
|
+
};
|
|
19856
|
+
};
|
|
19857
|
+
|
|
19858
|
+
/**
|
|
19859
|
+
* ```js
|
|
19860
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
19861
|
+
* const status = await follow('foobar')
|
|
19862
|
+
* ```
|
|
19863
|
+
*
|
|
19864
|
+
* Follow the user
|
|
19865
|
+
*
|
|
19866
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19867
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
19868
|
+
*
|
|
19869
|
+
* @category Follow API
|
|
19870
|
+
* @async
|
|
19871
|
+
*/
|
|
19872
|
+
const follow = async (userId) => {
|
|
19873
|
+
const client = getActiveClient();
|
|
19874
|
+
client.log('follow/follow', userId);
|
|
19875
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
19876
|
+
const cachedAt = client.cache && Date.now();
|
|
19877
|
+
if (client.cache) {
|
|
19878
|
+
ingestInCache(data, { cachedAt });
|
|
19879
|
+
}
|
|
19880
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
|
|
19881
|
+
return {
|
|
19882
|
+
data: data.follows[0],
|
|
19883
|
+
cachedAt,
|
|
19884
|
+
};
|
|
19885
|
+
};
|
|
19886
|
+
|
|
19887
|
+
/**
|
|
19888
|
+
* ```js
|
|
19889
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
19890
|
+
* await unfollow('foobar')
|
|
19891
|
+
* ```
|
|
19892
|
+
*
|
|
19893
|
+
* Cancel the follow request or unfollow the user
|
|
19894
|
+
*
|
|
19895
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19896
|
+
* @returns A success boolean if the user {@link Amity.User} was unfollowed
|
|
19897
|
+
*
|
|
19898
|
+
* @category Follow API
|
|
19899
|
+
* @async
|
|
19900
|
+
*/
|
|
19901
|
+
const unfollow = async (userId) => {
|
|
19902
|
+
const client = getActiveClient();
|
|
19903
|
+
client.log('follow/unfollow', userId);
|
|
19904
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
19905
|
+
if (client.cache) {
|
|
19906
|
+
ingestInCache(data);
|
|
19907
|
+
}
|
|
19908
|
+
fireEvent('follow.unfollowed', data.follows[0]);
|
|
19909
|
+
return true;
|
|
19910
|
+
};
|
|
19911
|
+
|
|
19912
|
+
/**
|
|
19913
|
+
* ```js
|
|
19914
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
19915
|
+
* await acceptFollower('foobar')
|
|
19916
|
+
* ```
|
|
19917
|
+
*
|
|
19918
|
+
* Accept the follow request
|
|
19919
|
+
*
|
|
19920
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
19921
|
+
* @returns A success boolean if the follow request was accepted
|
|
19922
|
+
*
|
|
19923
|
+
* @category Follow API
|
|
19924
|
+
* @async
|
|
19925
|
+
*/
|
|
19926
|
+
const acceptFollower = async (userId) => {
|
|
19927
|
+
const client = getActiveClient();
|
|
19928
|
+
client.log('follow/acceptFollower', userId);
|
|
19929
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
19930
|
+
if (client.cache) {
|
|
19931
|
+
ingestInCache(data);
|
|
19932
|
+
}
|
|
19933
|
+
fireEvent('follow.accepted', data.follows[0]);
|
|
19934
|
+
return true;
|
|
19935
|
+
};
|
|
19936
|
+
|
|
19937
|
+
/**
|
|
19938
|
+
* ```js
|
|
19939
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
19940
|
+
* await declineFollower('foobar')
|
|
19941
|
+
* ```
|
|
19942
|
+
*
|
|
19943
|
+
* Decline the follow request or delete the follower
|
|
19944
|
+
*
|
|
19945
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
19946
|
+
* @returns A success boolean if the follow request was decline
|
|
19947
|
+
*
|
|
19948
|
+
* @category Follow API
|
|
19949
|
+
* @async
|
|
19950
|
+
*/
|
|
19951
|
+
const declineFollower = async (userId) => {
|
|
19952
|
+
const client = getActiveClient();
|
|
19953
|
+
client.log('follow/declineFollower', userId);
|
|
19954
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
19955
|
+
if (client.cache) {
|
|
19956
|
+
ingestInCache(data);
|
|
19957
|
+
}
|
|
19958
|
+
fireEvent('follow.requestDeclined', data.follows[0]);
|
|
19959
|
+
return true;
|
|
19960
|
+
};
|
|
19961
|
+
|
|
19962
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
19963
|
+
const client = getActiveClient();
|
|
19964
|
+
const filter = (payload) => {
|
|
19965
|
+
var _a, _b;
|
|
19966
|
+
if (!client.cache) {
|
|
19967
|
+
callback(payload);
|
|
19968
|
+
}
|
|
19969
|
+
else {
|
|
19970
|
+
ingestInCache({ follows: [payload] });
|
|
19971
|
+
const queries = [
|
|
19972
|
+
...(_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : [],
|
|
19973
|
+
...(_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : [],
|
|
19974
|
+
];
|
|
19975
|
+
queries
|
|
19976
|
+
// @ts-ignore
|
|
19977
|
+
.filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
|
|
19978
|
+
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
19979
|
+
callback(payload);
|
|
19980
|
+
}
|
|
19981
|
+
};
|
|
19982
|
+
return createEventSubscriber(client, event, event, filter);
|
|
19983
|
+
};
|
|
19984
|
+
|
|
19985
|
+
/**
|
|
19986
|
+
* ```js
|
|
19987
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
19988
|
+
* const dispose = onUserFollowed(status => {
|
|
19989
|
+
* // ...
|
|
19990
|
+
* })
|
|
19991
|
+
* ```
|
|
19992
|
+
*
|
|
19993
|
+
* Fired when a user follows another users and confirmation is not required
|
|
19994
|
+
*
|
|
19995
|
+
* @param callback The function to call when the event was fired
|
|
19996
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
19997
|
+
*
|
|
19998
|
+
* @category Follow Events
|
|
19999
|
+
*/
|
|
20000
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
20001
|
+
|
|
20002
|
+
/**
|
|
20003
|
+
* ```js
|
|
20004
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
20005
|
+
* const dispose = onUserFollowed(status => {
|
|
20006
|
+
* // ...
|
|
20007
|
+
* })
|
|
20008
|
+
* ```
|
|
20009
|
+
*
|
|
20010
|
+
* Fired when a user unfollows
|
|
20011
|
+
*
|
|
20012
|
+
* @param callback The function to call when the event was fired
|
|
20013
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20014
|
+
*
|
|
20015
|
+
* @category Follow Events
|
|
20016
|
+
*/
|
|
20017
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
20018
|
+
|
|
20019
|
+
/**
|
|
20020
|
+
* ```js
|
|
20021
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
20022
|
+
* const dispose = onFollowerDeleted(status => {
|
|
20023
|
+
* // ...
|
|
20024
|
+
* })
|
|
20025
|
+
* ```
|
|
20026
|
+
*
|
|
20027
|
+
* Fired when a follower has been deleted
|
|
20028
|
+
*
|
|
20029
|
+
* @param callback The function to call when the event was fired
|
|
20030
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20031
|
+
*
|
|
20032
|
+
* @category Follow Events
|
|
20033
|
+
*/
|
|
20034
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
20035
|
+
|
|
20036
|
+
/**
|
|
20037
|
+
* ```js
|
|
20038
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
20039
|
+
* const dispose = onFollowerRequested(status => {
|
|
20040
|
+
* // ...
|
|
20041
|
+
* })
|
|
20042
|
+
* ```
|
|
20043
|
+
*
|
|
20044
|
+
* Fired when a user follows another users and confirmation is required
|
|
20045
|
+
*
|
|
20046
|
+
* @param callback The function to call when the event was fired
|
|
20047
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20048
|
+
*
|
|
20049
|
+
* @category Follow Events
|
|
20050
|
+
*/
|
|
20051
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
20052
|
+
|
|
20053
|
+
/**
|
|
20054
|
+
* ```js
|
|
20055
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
20056
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
20057
|
+
* // ...
|
|
20058
|
+
* })
|
|
20059
|
+
* ```
|
|
20060
|
+
*
|
|
20061
|
+
* Fired when a follow request has been canceled
|
|
20062
|
+
*
|
|
20063
|
+
* @param callback The function to call when the event was fired
|
|
20064
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20065
|
+
*
|
|
20066
|
+
* @category Follow Events
|
|
20067
|
+
*/
|
|
20068
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
20069
|
+
|
|
20070
|
+
/**
|
|
20071
|
+
* ```js
|
|
20072
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
20073
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
20074
|
+
* // ...
|
|
20075
|
+
* })
|
|
20076
|
+
* ```
|
|
20077
|
+
*
|
|
20078
|
+
* Fired when a follow request has been accepted
|
|
20079
|
+
*
|
|
20080
|
+
* @param callback The function to call when the event was fired
|
|
20081
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20082
|
+
*
|
|
20083
|
+
* @category Follow Events
|
|
20084
|
+
*/
|
|
20085
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
20086
|
+
|
|
20087
|
+
/**
|
|
20088
|
+
* ```js
|
|
20089
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
20090
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
20091
|
+
* // ...
|
|
20092
|
+
* })
|
|
20093
|
+
* ```
|
|
20094
|
+
*
|
|
20095
|
+
* Fired when a follow request has been declined
|
|
20096
|
+
*
|
|
20097
|
+
* @param callback The function to call when the event was fired
|
|
20098
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20099
|
+
*
|
|
20100
|
+
* @category Follow Events
|
|
20101
|
+
*/
|
|
20102
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
20103
|
+
|
|
20104
|
+
/**
|
|
20105
|
+
* ```js
|
|
20106
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
20107
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
20108
|
+
* // ...
|
|
20109
|
+
* })
|
|
20110
|
+
* ```
|
|
20111
|
+
*
|
|
20112
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
20113
|
+
*
|
|
20114
|
+
* @param callback The function to call when the event was fired
|
|
20115
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20116
|
+
*
|
|
20117
|
+
* @category Follow Events
|
|
20118
|
+
*/
|
|
20119
|
+
const onFollowInfoUpdated = (callback) => {
|
|
20120
|
+
const handler = async (payload) => {
|
|
20121
|
+
const [{ data: followInfoFrom }, { data: followInfoTo },] = await Promise.all([getFollowInfo(payload.from), getFollowInfo(payload.to)]);
|
|
20122
|
+
callback(followInfoFrom);
|
|
20123
|
+
callback(followInfoTo);
|
|
20124
|
+
};
|
|
20125
|
+
const disposers = [
|
|
20126
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
20127
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
20128
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
20129
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
20130
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
20131
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
20132
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
20133
|
+
];
|
|
20134
|
+
return () => {
|
|
20135
|
+
disposers.forEach(fn => fn());
|
|
20136
|
+
};
|
|
20137
|
+
};
|
|
20138
|
+
|
|
20139
|
+
/**
|
|
20140
|
+
* ```js
|
|
20141
|
+
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
20142
|
+
*
|
|
20143
|
+
* let followInfo = {}
|
|
20144
|
+
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
20145
|
+
* ```
|
|
20146
|
+
*
|
|
20147
|
+
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
20148
|
+
*
|
|
20149
|
+
* @param userId the ID of the user to observe
|
|
20150
|
+
* @param callback the function to call when new data are available
|
|
20151
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
20152
|
+
*
|
|
20153
|
+
* @category Follow Observer
|
|
20154
|
+
*/
|
|
20155
|
+
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
20156
|
+
const { log } = getActiveClient();
|
|
20157
|
+
const timestamp = Date.now();
|
|
20158
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
20159
|
+
const router = (result, action) => {
|
|
20160
|
+
var _a, _b;
|
|
20161
|
+
if (callback instanceof Function)
|
|
20162
|
+
return callback(result);
|
|
20163
|
+
if (action !== 'onFetch')
|
|
20164
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
20165
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
20166
|
+
};
|
|
20167
|
+
const realtimeRouter = (result, action) => {
|
|
20168
|
+
var _a;
|
|
20169
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
20170
|
+
return;
|
|
20171
|
+
router(result, action);
|
|
20172
|
+
};
|
|
20173
|
+
const disposers = [];
|
|
20174
|
+
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
20175
|
+
runQuery(createQuery(getFollowInfo, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
20176
|
+
return () => {
|
|
20177
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
20178
|
+
disposers.forEach(fn => fn());
|
|
20179
|
+
};
|
|
20180
|
+
};
|
|
20181
|
+
|
|
20182
|
+
/**
|
|
20183
|
+
* ```js
|
|
20184
|
+
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
20185
|
+
*
|
|
20186
|
+
* let followers = []
|
|
20187
|
+
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
20188
|
+
* ```
|
|
20189
|
+
*
|
|
20190
|
+
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
20191
|
+
*
|
|
20192
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20193
|
+
* @param callback the function to call when new data are available
|
|
20194
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20195
|
+
*
|
|
20196
|
+
* @category Follow Observer
|
|
20197
|
+
*/
|
|
20198
|
+
const observeFollowers = (userId, callback) => {
|
|
20199
|
+
const { log } = getActiveClient();
|
|
20200
|
+
const timestamp = Date.now();
|
|
20201
|
+
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
20202
|
+
const disposers = [];
|
|
20203
|
+
const router = (status, action) => {
|
|
20204
|
+
var _a, _b;
|
|
20205
|
+
if (status.from !== userId) {
|
|
20206
|
+
return;
|
|
20207
|
+
}
|
|
20208
|
+
if (callback instanceof Function) {
|
|
20209
|
+
return callback(status);
|
|
20210
|
+
}
|
|
20211
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20212
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20213
|
+
};
|
|
20214
|
+
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
|
|
20215
|
+
return () => {
|
|
20216
|
+
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
20217
|
+
disposers.forEach(fn => fn());
|
|
20218
|
+
};
|
|
20219
|
+
};
|
|
20220
|
+
|
|
20221
|
+
/**
|
|
20222
|
+
* ```js
|
|
20223
|
+
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
20224
|
+
*
|
|
20225
|
+
* let followings = []
|
|
20226
|
+
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
20227
|
+
* ```
|
|
20228
|
+
*
|
|
20229
|
+
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
20230
|
+
*
|
|
20231
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20232
|
+
* @param callback the function to call when new data are available
|
|
20233
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20234
|
+
*
|
|
20235
|
+
* @category Follow Observer
|
|
20236
|
+
*/
|
|
20237
|
+
const observeFollowings = (userId, callback) => {
|
|
20238
|
+
const { log } = getActiveClient();
|
|
20239
|
+
const timestamp = Date.now();
|
|
20240
|
+
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
20241
|
+
const disposers = [];
|
|
20242
|
+
const router = (status, action) => {
|
|
20243
|
+
var _a, _b;
|
|
20244
|
+
if (status.to !== userId) {
|
|
20245
|
+
return;
|
|
20246
|
+
}
|
|
20247
|
+
if (callback instanceof Function) {
|
|
20248
|
+
return callback(status);
|
|
20249
|
+
}
|
|
20250
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20251
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20252
|
+
};
|
|
20253
|
+
disposers.push(onFollowerRequested(x => router(x, 'onRequested')), onFollowRequestAccepted(x => router(x, 'onAccepted')), onFollowRequestDeclined(x => router(x, 'onDeclined')), onFollowRequestCanceled(x => router(x, 'onCanceled')), onUserFollowed(x => router(x, 'onFollowed')), onUserUnfollowed(x => router(x, 'onUnfollowed')), onFollowerDeleted(x => router(x, 'onDeleted')));
|
|
20254
|
+
return () => {
|
|
20255
|
+
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
20256
|
+
disposers.forEach(fn => fn());
|
|
20257
|
+
};
|
|
19509
20258
|
};
|
|
19510
20259
|
|
|
19511
20260
|
/**
|
|
@@ -19966,4 +20715,4 @@ const onStreamRecorded = (callback) => {
|
|
|
19966
20715
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
19967
20716
|
};
|
|
19968
20717
|
|
|
19969
|
-
export { SubscriptionLevels, VERSION$1 as VERSION, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getMessage, getMessages, getPost, getPostTopic, getPosts, getRole, getStream, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserUnflagged, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery,
|
|
20718
|
+
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRole, addReaction, backupCache, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createMessage, createPost, createQuery, createReport, createStream, declineFollower, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMemberAdded, onMemberRemoved, onMessageCreated, onMessageDeleted, onMessageUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRole, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, wipeCache };
|