@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.cjs.js
CHANGED
|
@@ -19,11 +19,14 @@ var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
|
19
19
|
var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
20
20
|
var AsyncStorage__default = /*#__PURE__*/_interopDefaultLegacy(AsyncStorage);
|
|
21
21
|
|
|
22
|
-
var _a;
|
|
23
|
-
|
|
24
|
-
const
|
|
22
|
+
var _a$1;
|
|
23
|
+
const theGlobal = globalThis || global || window;
|
|
24
|
+
const { process: safeProcess = {} } = theGlobal;
|
|
25
|
+
const isProduction = ((_a$1 = safeProcess.env) === null || _a$1 === void 0 ? void 0 : _a$1.NODE_ENV) === 'production';
|
|
26
|
+
|
|
27
|
+
var _a, _b;
|
|
28
|
+
const VERSION$1 = (_b = (_a = safeProcess.env) === null || _a === void 0 ? void 0 : _a.VERSION) !== null && _b !== void 0 ? _b : '__dev__';
|
|
25
29
|
|
|
26
|
-
// @ts-ignore
|
|
27
30
|
/**
|
|
28
31
|
* Type guard to find if the a given decoded backend token uses "skip/limit" pagination style
|
|
29
32
|
*
|
|
@@ -41,7 +44,7 @@ const isSkipLimit = (json) => (['skip', 'limit'].some(prop => prop in json));
|
|
|
41
44
|
*
|
|
42
45
|
* @hidden
|
|
43
46
|
*/
|
|
44
|
-
const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop => prop in json));
|
|
47
|
+
const isAfterBefore = (json) => (['after', 'before', 'first', 'last', 'limit'].some(prop => prop in json));
|
|
45
48
|
/**
|
|
46
49
|
* Type guard to find if the a given decoded backend token uses v4 or newer "after/before" pagination style
|
|
47
50
|
*
|
|
@@ -50,7 +53,7 @@ const isAfterBefore = (json) => (['after', 'before', 'first', 'last'].some(prop
|
|
|
50
53
|
*
|
|
51
54
|
* @hidden
|
|
52
55
|
*/
|
|
53
|
-
const isAfterBeforeRaw = (json) => (
|
|
56
|
+
const isAfterBeforeRaw = (json) => ('limit' in json);
|
|
54
57
|
/**
|
|
55
58
|
* Type guard to find if the a given object is wrapped around Amity.Paged<>
|
|
56
59
|
*
|
|
@@ -85,7 +88,7 @@ const toToken = (paging, style) => {
|
|
|
85
88
|
limit: paging.limit,
|
|
86
89
|
};
|
|
87
90
|
}
|
|
88
|
-
else if (style === 'afterbefore') {
|
|
91
|
+
else if (style === 'afterbefore' && isAfterBefore(paging)) {
|
|
89
92
|
/*
|
|
90
93
|
Caution: this testing style is only valid because
|
|
91
94
|
our backend expects nothing else than a number as
|
|
@@ -129,7 +132,7 @@ const toToken = (paging, style) => {
|
|
|
129
132
|
*/
|
|
130
133
|
const toPage = (token) => {
|
|
131
134
|
if (!token)
|
|
132
|
-
return
|
|
135
|
+
return undefined;
|
|
133
136
|
// don't try catch, let it throw
|
|
134
137
|
const json = JSON.parse(jsBase64.decode(token));
|
|
135
138
|
if (isSkipLimit(json)) {
|
|
@@ -152,7 +155,7 @@ const toPage = (token) => {
|
|
|
152
155
|
};
|
|
153
156
|
}
|
|
154
157
|
}
|
|
155
|
-
return
|
|
158
|
+
return undefined;
|
|
156
159
|
};
|
|
157
160
|
/**
|
|
158
161
|
* Converts a b64 string token into a paging object
|
|
@@ -164,42 +167,13 @@ const toPage = (token) => {
|
|
|
164
167
|
*/
|
|
165
168
|
const toPageRaw = (token) => {
|
|
166
169
|
if (!token)
|
|
167
|
-
return
|
|
170
|
+
return undefined;
|
|
168
171
|
// don't try catch, let it throw
|
|
169
172
|
const json = JSON.parse(jsBase64.decode(token));
|
|
170
173
|
if (isAfterBeforeRaw(json)) {
|
|
171
174
|
return json;
|
|
172
175
|
}
|
|
173
|
-
return
|
|
174
|
-
};
|
|
175
|
-
/**
|
|
176
|
-
* Slices a collection according to its paging
|
|
177
|
-
*
|
|
178
|
-
* @param type the type of collection (for unique id identification with after/before)
|
|
179
|
-
* @param collection the collection to slice
|
|
180
|
-
* @param paging the paging object
|
|
181
|
-
* @returns the sliced collection according to the paging definition
|
|
182
|
-
*
|
|
183
|
-
* @hidden
|
|
184
|
-
*/
|
|
185
|
-
const sliceByPaging = (type, collection, page) => {
|
|
186
|
-
console.log('slice by paging', page);
|
|
187
|
-
if (!page)
|
|
188
|
-
return collection.slice();
|
|
189
|
-
let start = 0;
|
|
190
|
-
let end = undefined;
|
|
191
|
-
// next page behavior
|
|
192
|
-
if (page.after) {
|
|
193
|
-
start = page.after;
|
|
194
|
-
end = start + page.limit;
|
|
195
|
-
// prev page behavior
|
|
196
|
-
}
|
|
197
|
-
else if (page.before) {
|
|
198
|
-
end = page.before + 1;
|
|
199
|
-
start = end > page.limit ? end - page.limit : 0;
|
|
200
|
-
}
|
|
201
|
-
const paged = collection.slice(start, end);
|
|
202
|
-
return paged.length === page.limit ? paged : undefined;
|
|
176
|
+
return undefined;
|
|
203
177
|
};
|
|
204
178
|
|
|
205
179
|
/**
|
|
@@ -512,9 +486,8 @@ const setActiveClient = (client) => {
|
|
|
512
486
|
* @hidden
|
|
513
487
|
*/
|
|
514
488
|
const createLogger = (session) => {
|
|
515
|
-
var _a;
|
|
516
489
|
const active = (`${session === null || session === void 0 ? void 0 : session.trim()}`.length > 0
|
|
517
|
-
&&
|
|
490
|
+
&& !isProduction);
|
|
518
491
|
const logger = debug__default['default'](session);
|
|
519
492
|
const print = (topic, ...args) => {
|
|
520
493
|
active && logger(topic, args);
|
|
@@ -523,19 +496,18 @@ const createLogger = (session) => {
|
|
|
523
496
|
return print;
|
|
524
497
|
};
|
|
525
498
|
|
|
526
|
-
const
|
|
499
|
+
const API_REGIONS = {
|
|
527
500
|
EU: 'eu',
|
|
528
501
|
SG: 'sg',
|
|
529
502
|
US: 'us',
|
|
530
503
|
};
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
};
|
|
504
|
+
const URLS = {
|
|
505
|
+
http: 'https://api.{region}.amity.co',
|
|
506
|
+
mqtt: 'wss://sse.{region}.amity.co:443/mqtt',
|
|
507
|
+
};
|
|
508
|
+
function computeUrl(type, region) {
|
|
509
|
+
return URLS[type].replace('{region}', region);
|
|
510
|
+
}
|
|
539
511
|
|
|
540
512
|
/**
|
|
541
513
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
@@ -14741,6 +14713,22 @@ const createMqttTransport = (endpoint) => {
|
|
|
14741
14713
|
};
|
|
14742
14714
|
};
|
|
14743
14715
|
|
|
14716
|
+
let tasks = [];
|
|
14717
|
+
let timer;
|
|
14718
|
+
/**
|
|
14719
|
+
* Add a function to run just before the next tick
|
|
14720
|
+
*
|
|
14721
|
+
* @param task function to schedule for later execution
|
|
14722
|
+
*/
|
|
14723
|
+
const scheduleTask = (task) => {
|
|
14724
|
+
clearTimeout(timer);
|
|
14725
|
+
tasks.push(task);
|
|
14726
|
+
timer = setTimeout(() => {
|
|
14727
|
+
tasks.forEach(fn => fn());
|
|
14728
|
+
tasks = [];
|
|
14729
|
+
}, 0);
|
|
14730
|
+
};
|
|
14731
|
+
|
|
14744
14732
|
// need to sync up the list
|
|
14745
14733
|
const WS_EVENTS = [
|
|
14746
14734
|
'disconnected',
|
|
@@ -14831,7 +14819,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
14831
14819
|
*/
|
|
14832
14820
|
const fireEvent = (event, payload) => {
|
|
14833
14821
|
const { emitter } = getActiveClient();
|
|
14834
|
-
|
|
14822
|
+
scheduleTask(() => { emitter.emit(event, payload); });
|
|
14835
14823
|
};
|
|
14836
14824
|
|
|
14837
14825
|
/**
|
|
@@ -14843,21 +14831,21 @@ const fireEvent = (event, payload) => {
|
|
|
14843
14831
|
* Creates a new {@link Amity.Client} instance
|
|
14844
14832
|
*
|
|
14845
14833
|
* @param apiKey for the {@link Amity.Client} instance
|
|
14846
|
-
* @param
|
|
14834
|
+
* @param apiRegion endpoint to connect to
|
|
14847
14835
|
* @param debugSession session's identifier for the client's logger instance
|
|
14848
14836
|
* @returns A {@link Amity.Client} instance
|
|
14849
14837
|
*
|
|
14850
14838
|
* @category Client API
|
|
14851
14839
|
**/
|
|
14852
|
-
const createClient = (apiKey,
|
|
14840
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity') => {
|
|
14853
14841
|
const log = createLogger(debugSession);
|
|
14854
14842
|
log('client/api/createClient', {
|
|
14855
14843
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
14856
|
-
|
|
14844
|
+
apiRegion,
|
|
14857
14845
|
});
|
|
14858
|
-
const http = createHttpTransport(
|
|
14859
|
-
const ws = createWebsocketTransport(
|
|
14860
|
-
const mqtt = createMqttTransport(
|
|
14846
|
+
const http = createHttpTransport(computeUrl('http', apiRegion));
|
|
14847
|
+
const ws = createWebsocketTransport(computeUrl('http', apiRegion));
|
|
14848
|
+
const mqtt = createMqttTransport(computeUrl('mqtt', apiRegion));
|
|
14861
14849
|
const emitter = createEventEmitter();
|
|
14862
14850
|
const client = {
|
|
14863
14851
|
version: `${VERSION$1}`,
|
|
@@ -14910,7 +14898,6 @@ const disconnectClient = async () => {
|
|
|
14910
14898
|
};
|
|
14911
14899
|
|
|
14912
14900
|
// TODO: find a way to uniquely identify the device
|
|
14913
|
-
// import { getStorage } from './storage'
|
|
14914
14901
|
/** @hidden */
|
|
14915
14902
|
const VERSION = '11.0.0';
|
|
14916
14903
|
/** @hidden */
|
|
@@ -14925,8 +14912,8 @@ const getDeviceId = () => {
|
|
|
14925
14912
|
/** @hidden */
|
|
14926
14913
|
const getDeviceModel = () => {
|
|
14927
14914
|
var _a, _b;
|
|
14928
|
-
if ((_a =
|
|
14929
|
-
return
|
|
14915
|
+
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
14916
|
+
return safeProcess.versions.node;
|
|
14930
14917
|
if (navigator)
|
|
14931
14918
|
return `${navigator.product.toLowerCase()}#${(_b = navigator.userAgent) !== null && _b !== void 0 ? _b : 'unknown_agent'}`;
|
|
14932
14919
|
return 'unknown_model';
|
|
@@ -14942,6 +14929,24 @@ const getDeviceInfo = () => {
|
|
|
14942
14929
|
};
|
|
14943
14930
|
};
|
|
14944
14931
|
|
|
14932
|
+
let activeUser = null;
|
|
14933
|
+
/**
|
|
14934
|
+
* for internal use
|
|
14935
|
+
*/
|
|
14936
|
+
const getActiveUser = () => {
|
|
14937
|
+
if (!activeUser) {
|
|
14938
|
+
throw new ASCError('Connect client first', 800000 /* UNKNOWN_ERROR */, "fatal" /* FATAL */);
|
|
14939
|
+
}
|
|
14940
|
+
return activeUser;
|
|
14941
|
+
};
|
|
14942
|
+
const setActiveUser = (user) => {
|
|
14943
|
+
activeUser = {
|
|
14944
|
+
_id: user._id,
|
|
14945
|
+
userId: user.userId,
|
|
14946
|
+
path: user.path,
|
|
14947
|
+
};
|
|
14948
|
+
};
|
|
14949
|
+
|
|
14945
14950
|
/**
|
|
14946
14951
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14947
14952
|
*
|
|
@@ -15089,8 +15094,8 @@ const connectClient = async (params) => {
|
|
|
15089
15094
|
unsubscribe();
|
|
15090
15095
|
});
|
|
15091
15096
|
client.userId = params.userId;
|
|
15092
|
-
client._internalUserId = users[0]._id;
|
|
15093
15097
|
client.accessToken = accessToken;
|
|
15098
|
+
setActiveUser(users[0]);
|
|
15094
15099
|
return client.ws.connected;
|
|
15095
15100
|
};
|
|
15096
15101
|
|
|
@@ -15148,13 +15153,24 @@ const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
|
15148
15153
|
const getCommentTopic = ({ path }) => {
|
|
15149
15154
|
return path;
|
|
15150
15155
|
};
|
|
15156
|
+
const getMyFollowersTopic = () => {
|
|
15157
|
+
const user = getActiveUser();
|
|
15158
|
+
const [networkId] = user.path.split('/user/');
|
|
15159
|
+
return `${networkId}/membership/${user._id}/+/+`;
|
|
15160
|
+
};
|
|
15161
|
+
const getMyFollowingsTopic = () => {
|
|
15162
|
+
const user = getActiveUser();
|
|
15163
|
+
const [networkId] = user.path.split('/user/');
|
|
15164
|
+
return `${networkId}/membership/+/${user._id}/+`;
|
|
15165
|
+
};
|
|
15151
15166
|
let mqttAccessToken;
|
|
15152
15167
|
let mqttUserId;
|
|
15153
15168
|
function subscribeTopic(topic, callback) {
|
|
15154
|
-
const { mqtt, emitter, accessToken
|
|
15155
|
-
|
|
15169
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15170
|
+
const user = getActiveUser();
|
|
15171
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15156
15172
|
mqttAccessToken = accessToken;
|
|
15157
|
-
mqttUserId =
|
|
15173
|
+
mqttUserId = user._id;
|
|
15158
15174
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15159
15175
|
proxyMqttEvents(mqtt, emitter);
|
|
15160
15176
|
}
|
|
@@ -15560,6 +15576,8 @@ const idResolvers = {
|
|
|
15560
15576
|
post: ({ postId }) => postId,
|
|
15561
15577
|
comment: ({ commentId }) => commentId,
|
|
15562
15578
|
stream: ({ streamId }) => streamId,
|
|
15579
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15580
|
+
followCount: ({ userId }) => userId,
|
|
15563
15581
|
};
|
|
15564
15582
|
/**
|
|
15565
15583
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15586,6 +15604,8 @@ const PAYLOAD2MODEL = {
|
|
|
15586
15604
|
postChildren: 'post',
|
|
15587
15605
|
comments: 'comment',
|
|
15588
15606
|
videoStreamings: 'stream',
|
|
15607
|
+
follows: 'follow',
|
|
15608
|
+
followCounts: 'followCount'
|
|
15589
15609
|
};
|
|
15590
15610
|
|
|
15591
15611
|
/**
|
|
@@ -16649,11 +16669,11 @@ const queryPosts = async (query) => {
|
|
|
16649
16669
|
const { page = { limit: 10 } } = query, params = __rest(query
|
|
16650
16670
|
// API-FIX: parameters should be querystring. (1)
|
|
16651
16671
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16652
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16672
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16653
16673
|
, ["page"]);
|
|
16654
16674
|
// API-FIX: parameters should be querystring. (1)
|
|
16655
16675
|
// API-FIX: backend should answer Amity.Response (2)
|
|
16656
|
-
// const { data } = await client.http.get<Amity.Response<Amity.
|
|
16676
|
+
// const { data } = await client.http.get<Amity.Response<Amity.PagedResponse<Amity.PostPayload>>>(
|
|
16657
16677
|
const { data } = await client.http.get(`/api/v4/posts`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
16658
16678
|
token: toToken(page, 'afterbeforeraw'),
|
|
16659
16679
|
} }), });
|
|
@@ -17240,7 +17260,7 @@ const queryCommunityMembers = async (query) => {
|
|
|
17240
17260
|
}
|
|
17241
17261
|
const nextPage = toPage(paging.next);
|
|
17242
17262
|
const prevPage = toPage(paging.previous);
|
|
17243
|
-
return { data: communityUsers, nextPage, prevPage };
|
|
17263
|
+
return { data: communityUsers, cachedAt, nextPage, prevPage };
|
|
17244
17264
|
};
|
|
17245
17265
|
/**
|
|
17246
17266
|
* ```js
|
|
@@ -17367,6 +17387,132 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17367
17387
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && !communityUser.roles.includes(roleId));
|
|
17368
17388
|
};
|
|
17369
17389
|
|
|
17390
|
+
/**
|
|
17391
|
+
* ```js
|
|
17392
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17393
|
+
* const trendingCommunities = await getTopTrendingCommunities()
|
|
17394
|
+
* ```
|
|
17395
|
+
*
|
|
17396
|
+
* Gets a list of top trending {@link Amity.Community} objects
|
|
17397
|
+
*
|
|
17398
|
+
* @param query The query parameters
|
|
17399
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17400
|
+
*
|
|
17401
|
+
* @category Community API
|
|
17402
|
+
* @async
|
|
17403
|
+
*/
|
|
17404
|
+
const getTopTrendingCommunities = async (query) => {
|
|
17405
|
+
const client = getActiveClient();
|
|
17406
|
+
client.log('channel/getTopTrendingCommunities', query);
|
|
17407
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17408
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17409
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17410
|
+
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
17411
|
+
const { communities } = data;
|
|
17412
|
+
const cachedAt = client.cache && Date.now();
|
|
17413
|
+
if (client.cache) {
|
|
17414
|
+
ingestInCache(data, { cachedAt });
|
|
17415
|
+
const cacheKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17416
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17417
|
+
}
|
|
17418
|
+
return { data: communities, cachedAt };
|
|
17419
|
+
};
|
|
17420
|
+
/**
|
|
17421
|
+
* ```js
|
|
17422
|
+
* import { getTopTrendingCommunities } from '@amityco/ts-sdk'
|
|
17423
|
+
* const communities = getTopTrendingCommunities.locally()
|
|
17424
|
+
* ```
|
|
17425
|
+
*
|
|
17426
|
+
* Gets a list of top trending {@link Amity.Community} objects from cache
|
|
17427
|
+
*
|
|
17428
|
+
* @param query The query parameters
|
|
17429
|
+
* @returns communities
|
|
17430
|
+
*
|
|
17431
|
+
* @category Community API
|
|
17432
|
+
*/
|
|
17433
|
+
getTopTrendingCommunities.locally = (query) => {
|
|
17434
|
+
var _a, _b;
|
|
17435
|
+
const client = getActiveClient();
|
|
17436
|
+
client.log('community/getTopTrendingCommunities.locally', query);
|
|
17437
|
+
if (!client.cache)
|
|
17438
|
+
return;
|
|
17439
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17440
|
+
const queryKey = ['community', 'top-trending', { params: { options: { limit } } }];
|
|
17441
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17442
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17443
|
+
return;
|
|
17444
|
+
const communities = data.communities
|
|
17445
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17446
|
+
.filter(Boolean)
|
|
17447
|
+
.map(({ data }) => data);
|
|
17448
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17449
|
+
? { data: communities, cachedAt }
|
|
17450
|
+
: undefined;
|
|
17451
|
+
};
|
|
17452
|
+
|
|
17453
|
+
/**
|
|
17454
|
+
* ```js
|
|
17455
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17456
|
+
* const communities = await getRecommendedCommunities()
|
|
17457
|
+
* ```
|
|
17458
|
+
*
|
|
17459
|
+
* Gets a list of recommended {@link Amity.Community} objects
|
|
17460
|
+
*
|
|
17461
|
+
* @param query The query parameters
|
|
17462
|
+
* @returns A list of {@link Amity.Community} objects
|
|
17463
|
+
*
|
|
17464
|
+
* @category Community API
|
|
17465
|
+
* @async
|
|
17466
|
+
*/
|
|
17467
|
+
const getRecommendedCommunities = async (query) => {
|
|
17468
|
+
const client = getActiveClient();
|
|
17469
|
+
client.log('channel/getRecommendedCommunities', query);
|
|
17470
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17471
|
+
// API-FIX: backend doesnt answer Amity.Response
|
|
17472
|
+
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
17473
|
+
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
17474
|
+
const { communities } = data;
|
|
17475
|
+
const cachedAt = client.cache && Date.now();
|
|
17476
|
+
if (client.cache) {
|
|
17477
|
+
ingestInCache(data, { cachedAt });
|
|
17478
|
+
const cacheKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17479
|
+
pushToCache(cacheKey, { communities: communities.map(getResolver('community')) });
|
|
17480
|
+
}
|
|
17481
|
+
return { data: communities, cachedAt };
|
|
17482
|
+
};
|
|
17483
|
+
/**
|
|
17484
|
+
* ```js
|
|
17485
|
+
* import { getRecommendedCommunities } from '@amityco/ts-sdk'
|
|
17486
|
+
* const communities = getRecommendedCommunities.locally()
|
|
17487
|
+
* ```
|
|
17488
|
+
*
|
|
17489
|
+
* Gets a list of recommended {@link Amity.Community} objects from cache
|
|
17490
|
+
*
|
|
17491
|
+
* @param query The query parameters
|
|
17492
|
+
* @returns communities
|
|
17493
|
+
*
|
|
17494
|
+
* @category Community API
|
|
17495
|
+
*/
|
|
17496
|
+
getRecommendedCommunities.locally = (query) => {
|
|
17497
|
+
var _a, _b;
|
|
17498
|
+
const client = getActiveClient();
|
|
17499
|
+
client.log('community/getRecommendedCommunities.locally', query);
|
|
17500
|
+
if (!client.cache)
|
|
17501
|
+
return;
|
|
17502
|
+
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
17503
|
+
const queryKey = ['community', 'recommended', { params: { options: { limit } } }];
|
|
17504
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
17505
|
+
if (!(data === null || data === void 0 ? void 0 : data.communities.length))
|
|
17506
|
+
return;
|
|
17507
|
+
const communities = data.communities
|
|
17508
|
+
.map(communityId => pullFromCache(['community', 'get', communityId]))
|
|
17509
|
+
.filter(Boolean)
|
|
17510
|
+
.map(({ data }) => data);
|
|
17511
|
+
return communities.length === ((_b = data === null || data === void 0 ? void 0 : data.communities) === null || _b === void 0 ? void 0 : _b.length)
|
|
17512
|
+
? { data: communities, cachedAt }
|
|
17513
|
+
: undefined;
|
|
17514
|
+
};
|
|
17515
|
+
|
|
17370
17516
|
/**
|
|
17371
17517
|
* ```js
|
|
17372
17518
|
* import { deletePost } from '@amityco/ts-sdk'
|
|
@@ -18758,12 +18904,13 @@ const queryChannelMembers = async (query) => {
|
|
|
18758
18904
|
});
|
|
18759
18905
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
18760
18906
|
const { channelUsers } = payload;
|
|
18907
|
+
const cachedAt = client.cache && Date.now();
|
|
18761
18908
|
if (client.cache) {
|
|
18762
18909
|
ingestInCache(payload);
|
|
18763
18910
|
}
|
|
18764
18911
|
const nextPage = toPage(paging.next);
|
|
18765
18912
|
const prevPage = toPage(paging.previous);
|
|
18766
|
-
return { data: channelUsers, nextPage, prevPage };
|
|
18913
|
+
return { data: channelUsers, cachedAt, nextPage, prevPage };
|
|
18767
18914
|
};
|
|
18768
18915
|
/**
|
|
18769
18916
|
* ```js
|
|
@@ -19508,17 +19655,619 @@ const observeCommunity = (communityId, callback) => {
|
|
|
19508
19655
|
const queryGlobalFeed = async (query) => {
|
|
19509
19656
|
const client = getActiveClient();
|
|
19510
19657
|
client.log('feed/queryGlobalFeed', query);
|
|
19511
|
-
const _a = query !== null && query !== void 0 ? query : {}, { page } = _a, params = __rest(_a, ["page"]);
|
|
19512
|
-
const { data } = await client.http.get(`/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19658
|
+
const _a = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _a, params = __rest(_a, ["useCustomRanking", "page"]);
|
|
19659
|
+
const { data } = await client.http.get(useCustomRanking ? `/api/v5/me/global-feeds` : `/api/v4/me/global-feeds`, { params: Object.assign(Object.assign({}, params), { options: {
|
|
19513
19660
|
token: toToken(page, 'skiplimit')
|
|
19514
19661
|
} }) });
|
|
19515
19662
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19516
19663
|
const { posts } = payload;
|
|
19517
|
-
|
|
19664
|
+
const cachedAt = client.cache && Date.now();
|
|
19665
|
+
if (client.cache) {
|
|
19518
19666
|
ingestInCache(payload);
|
|
19667
|
+
const cacheKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19668
|
+
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
19669
|
+
}
|
|
19670
|
+
const nextPage = toPage(paging.next);
|
|
19671
|
+
const prevPage = toPage(paging.previous);
|
|
19672
|
+
return { data: posts, cachedAt, prevPage, nextPage };
|
|
19673
|
+
};
|
|
19674
|
+
/**
|
|
19675
|
+
* ```js
|
|
19676
|
+
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
19677
|
+
* const posts = await queryGlobalFeed.locally()
|
|
19678
|
+
* ```
|
|
19679
|
+
*
|
|
19680
|
+
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
19681
|
+
*
|
|
19682
|
+
* @param query The query parameters
|
|
19683
|
+
* @returns A page of {@link Amity.Post} objects
|
|
19684
|
+
*
|
|
19685
|
+
* @category Feed API
|
|
19686
|
+
* @async
|
|
19687
|
+
**/
|
|
19688
|
+
queryGlobalFeed.locally = (query) => {
|
|
19689
|
+
var _a, _b;
|
|
19690
|
+
const client = getActiveClient();
|
|
19691
|
+
client.log('post/queryGlobalFeed.locally', query);
|
|
19692
|
+
if (!client.cache)
|
|
19693
|
+
return;
|
|
19694
|
+
const _c = query !== null && query !== void 0 ? query : {}, { useCustomRanking, page } = _c, params = __rest(_c, ["useCustomRanking", "page"]);
|
|
19695
|
+
const queryKey = ['globalFeed', 'query', Object.assign(Object.assign({}, params), { useCustomRanking, options: Object.assign({}, page) })];
|
|
19696
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19697
|
+
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
19698
|
+
return;
|
|
19699
|
+
const posts = data.posts
|
|
19700
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
19701
|
+
.filter(Boolean)
|
|
19702
|
+
.map(({ data }) => data);
|
|
19703
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19704
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19705
|
+
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
19706
|
+
? { data: posts, cachedAt, prevPage, nextPage }
|
|
19707
|
+
: undefined;
|
|
19708
|
+
};
|
|
19709
|
+
|
|
19710
|
+
const queryFollows = async (key, query) => {
|
|
19711
|
+
const client = getActiveClient();
|
|
19712
|
+
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
19713
|
+
const { userId, page } = query, params = __rest(query, ["userId", "page"]);
|
|
19714
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/${key}` : `/api/v4/users/${userId}/${key}`, {
|
|
19715
|
+
params: Object.assign(Object.assign({}, params), { token: toToken(page, 'skiplimit') }),
|
|
19716
|
+
});
|
|
19717
|
+
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
19718
|
+
const { follows } = payload;
|
|
19719
|
+
const cachedAt = client.cache && Date.now();
|
|
19720
|
+
if (client.cache) {
|
|
19721
|
+
ingestInCache(payload, { cachedAt });
|
|
19722
|
+
const cacheKey = [key, 'query', Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) })];
|
|
19723
|
+
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
19724
|
+
}
|
|
19519
19725
|
const nextPage = toPage(paging.next);
|
|
19520
19726
|
const prevPage = toPage(paging.previous);
|
|
19521
|
-
return { data:
|
|
19727
|
+
return { data: follows, cachedAt, prevPage, nextPage };
|
|
19728
|
+
};
|
|
19729
|
+
queryFollows.locally = (key, query) => {
|
|
19730
|
+
var _a, _b;
|
|
19731
|
+
const client = getActiveClient();
|
|
19732
|
+
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
19733
|
+
if (!client.cache)
|
|
19734
|
+
return;
|
|
19735
|
+
const { page } = query, params = __rest(query, ["page"]);
|
|
19736
|
+
const queryKey = [key, 'query', Object.assign(Object.assign({}, params), { options: Object.assign({}, page) })];
|
|
19737
|
+
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
19738
|
+
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
19739
|
+
return;
|
|
19740
|
+
}
|
|
19741
|
+
const follows = data.follows
|
|
19742
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
19743
|
+
.filter(Boolean)
|
|
19744
|
+
.map(({ data }) => data);
|
|
19745
|
+
const prevPage = toPage(data === null || data === void 0 ? void 0 : data.paging.previous);
|
|
19746
|
+
const nextPage = toPage(data === null || data === void 0 ? void 0 : data.paging.next);
|
|
19747
|
+
return follows.length === ((_b = data === null || data === void 0 ? void 0 : data.follows) === null || _b === void 0 ? void 0 : _b.length)
|
|
19748
|
+
? { data: follows, cachedAt, prevPage, nextPage }
|
|
19749
|
+
: undefined;
|
|
19750
|
+
};
|
|
19751
|
+
|
|
19752
|
+
/**
|
|
19753
|
+
* ```js
|
|
19754
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
19755
|
+
* const { data: followers, prevPage, nextPage } = await queryFollowers({ userId })
|
|
19756
|
+
* ```
|
|
19757
|
+
*
|
|
19758
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
19759
|
+
*
|
|
19760
|
+
* @param query The query parameters
|
|
19761
|
+
* @returns followers
|
|
19762
|
+
*
|
|
19763
|
+
* @category Follow API
|
|
19764
|
+
* @async
|
|
19765
|
+
*/
|
|
19766
|
+
const queryFollowers = async (query) => queryFollows('followers', query);
|
|
19767
|
+
/**
|
|
19768
|
+
* ```js
|
|
19769
|
+
* import { queryFollowers } from '@amityco/ts-sdk'
|
|
19770
|
+
* const { data: followers, prevPage, nextPage } = queryFollowers.locally({ userId })
|
|
19771
|
+
* ```
|
|
19772
|
+
*
|
|
19773
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
19774
|
+
*
|
|
19775
|
+
* @param query The query parameters
|
|
19776
|
+
* @returns followers
|
|
19777
|
+
*
|
|
19778
|
+
* @category Post API
|
|
19779
|
+
*/
|
|
19780
|
+
queryFollowers.locally = (query) => queryFollows.locally('followers', query);
|
|
19781
|
+
|
|
19782
|
+
/**
|
|
19783
|
+
* ```js
|
|
19784
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
19785
|
+
* const { data: followings, prevPage, nextPage } = await queryFollowings({ userId })
|
|
19786
|
+
* ```
|
|
19787
|
+
*
|
|
19788
|
+
* Queries a paginable list of {@link Amity.FollowStatus}
|
|
19789
|
+
*
|
|
19790
|
+
* @param query The query parameters
|
|
19791
|
+
* @returns followings
|
|
19792
|
+
*
|
|
19793
|
+
* @category Follow API
|
|
19794
|
+
* @async
|
|
19795
|
+
*/
|
|
19796
|
+
const queryFollowings = async (query) => queryFollows('following', query);
|
|
19797
|
+
/**
|
|
19798
|
+
* ```js
|
|
19799
|
+
* import { queryFollowings } from '@amityco/ts-sdk'
|
|
19800
|
+
* const { data: followings, prevPage, nextPage } = queryFollowings.locally({ userId })
|
|
19801
|
+
* ```
|
|
19802
|
+
*
|
|
19803
|
+
* Queries a paginable list of {@link Amity.FollowStatus} objects from cache
|
|
19804
|
+
*
|
|
19805
|
+
* @param query The query parameters
|
|
19806
|
+
* @returns followings
|
|
19807
|
+
*
|
|
19808
|
+
* @category Post API
|
|
19809
|
+
*/
|
|
19810
|
+
queryFollowings.locally = (query) => queryFollows.locally('following', query);
|
|
19811
|
+
|
|
19812
|
+
const getCacheKey = (userId) => ['followInfo', 'get', `${getActiveClient().userId}#${userId}`];
|
|
19813
|
+
/**
|
|
19814
|
+
* ```js
|
|
19815
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
19816
|
+
* const { data: followInfo } = await getFollowInfo('foobar')
|
|
19817
|
+
* ```
|
|
19818
|
+
*
|
|
19819
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user
|
|
19820
|
+
*
|
|
19821
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19822
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
19823
|
+
*
|
|
19824
|
+
* @category Follow API
|
|
19825
|
+
* @async
|
|
19826
|
+
*/
|
|
19827
|
+
const getFollowInfo = async (userId) => {
|
|
19828
|
+
var _a, _b;
|
|
19829
|
+
const client = getActiveClient();
|
|
19830
|
+
client.log('follow/getFollowInfo', userId);
|
|
19831
|
+
const { data } = await client.http.get(client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`);
|
|
19832
|
+
const cachedAt = client.cache && Date.now();
|
|
19833
|
+
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 });
|
|
19834
|
+
if (client.cache) {
|
|
19835
|
+
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
19836
|
+
}
|
|
19837
|
+
return {
|
|
19838
|
+
data: followInfo,
|
|
19839
|
+
cachedAt,
|
|
19840
|
+
};
|
|
19841
|
+
};
|
|
19842
|
+
/**
|
|
19843
|
+
* ```js
|
|
19844
|
+
* import { getFollowInfo } from '@amityco/ts-sdk'
|
|
19845
|
+
* const { data: followInfo } = getFollowInfo.locally('foobar')
|
|
19846
|
+
* ```
|
|
19847
|
+
*
|
|
19848
|
+
* Fetches the number of followers, followings, pending requests and the follow status for current user from cache
|
|
19849
|
+
*
|
|
19850
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19851
|
+
* @returns the associated {@link Amity.FollowInfo} object
|
|
19852
|
+
*
|
|
19853
|
+
* @category Follow API
|
|
19854
|
+
*/
|
|
19855
|
+
getFollowInfo.locally = (userId) => {
|
|
19856
|
+
const client = getActiveClient();
|
|
19857
|
+
client.log('follow/getFollowInfo.locally', userId);
|
|
19858
|
+
if (!client.cache) {
|
|
19859
|
+
return;
|
|
19860
|
+
}
|
|
19861
|
+
const cached = pullFromCache(getCacheKey(userId));
|
|
19862
|
+
if (!cached) {
|
|
19863
|
+
return;
|
|
19864
|
+
}
|
|
19865
|
+
return {
|
|
19866
|
+
data: cached.data,
|
|
19867
|
+
cachedAt: cached.cachedAt,
|
|
19868
|
+
};
|
|
19869
|
+
};
|
|
19870
|
+
|
|
19871
|
+
/**
|
|
19872
|
+
* ```js
|
|
19873
|
+
* import { follow } from '@amityco/ts-sdk'
|
|
19874
|
+
* const status = await follow('foobar')
|
|
19875
|
+
* ```
|
|
19876
|
+
*
|
|
19877
|
+
* Follow the user
|
|
19878
|
+
*
|
|
19879
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19880
|
+
* @returns the status {@link Amity.FollowStatus}
|
|
19881
|
+
*
|
|
19882
|
+
* @category Follow API
|
|
19883
|
+
* @async
|
|
19884
|
+
*/
|
|
19885
|
+
const follow = async (userId) => {
|
|
19886
|
+
const client = getActiveClient();
|
|
19887
|
+
client.log('follow/follow', userId);
|
|
19888
|
+
const { data } = await client.http.post(`/api/v4/me/following/${userId}`);
|
|
19889
|
+
const cachedAt = client.cache && Date.now();
|
|
19890
|
+
if (client.cache) {
|
|
19891
|
+
ingestInCache(data, { cachedAt });
|
|
19892
|
+
}
|
|
19893
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data.follows[0]);
|
|
19894
|
+
return {
|
|
19895
|
+
data: data.follows[0],
|
|
19896
|
+
cachedAt,
|
|
19897
|
+
};
|
|
19898
|
+
};
|
|
19899
|
+
|
|
19900
|
+
/**
|
|
19901
|
+
* ```js
|
|
19902
|
+
* import { unfollow } from '@amityco/ts-sdk'
|
|
19903
|
+
* await unfollow('foobar')
|
|
19904
|
+
* ```
|
|
19905
|
+
*
|
|
19906
|
+
* Cancel the follow request or unfollow the user
|
|
19907
|
+
*
|
|
19908
|
+
* @param userId the ID of the {@link Amity.User}
|
|
19909
|
+
* @returns A success boolean if the user {@link Amity.User} was unfollowed
|
|
19910
|
+
*
|
|
19911
|
+
* @category Follow API
|
|
19912
|
+
* @async
|
|
19913
|
+
*/
|
|
19914
|
+
const unfollow = async (userId) => {
|
|
19915
|
+
const client = getActiveClient();
|
|
19916
|
+
client.log('follow/unfollow', userId);
|
|
19917
|
+
const { data } = await client.http.delete(`/api/v4/me/following/${userId}`);
|
|
19918
|
+
if (client.cache) {
|
|
19919
|
+
ingestInCache(data);
|
|
19920
|
+
}
|
|
19921
|
+
fireEvent('follow.unfollowed', data.follows[0]);
|
|
19922
|
+
return true;
|
|
19923
|
+
};
|
|
19924
|
+
|
|
19925
|
+
/**
|
|
19926
|
+
* ```js
|
|
19927
|
+
* import { acceptFollower } from '@amityco/ts-sdk'
|
|
19928
|
+
* await acceptFollower('foobar')
|
|
19929
|
+
* ```
|
|
19930
|
+
*
|
|
19931
|
+
* Accept the follow request
|
|
19932
|
+
*
|
|
19933
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
19934
|
+
* @returns A success boolean if the follow request was accepted
|
|
19935
|
+
*
|
|
19936
|
+
* @category Follow API
|
|
19937
|
+
* @async
|
|
19938
|
+
*/
|
|
19939
|
+
const acceptFollower = async (userId) => {
|
|
19940
|
+
const client = getActiveClient();
|
|
19941
|
+
client.log('follow/acceptFollower', userId);
|
|
19942
|
+
const { data } = await client.http.post(`/api/v4/me/followers/${userId}`);
|
|
19943
|
+
if (client.cache) {
|
|
19944
|
+
ingestInCache(data);
|
|
19945
|
+
}
|
|
19946
|
+
fireEvent('follow.accepted', data.follows[0]);
|
|
19947
|
+
return true;
|
|
19948
|
+
};
|
|
19949
|
+
|
|
19950
|
+
/**
|
|
19951
|
+
* ```js
|
|
19952
|
+
* import { declineFollower } from '@amityco/ts-sdk'
|
|
19953
|
+
* await declineFollower('foobar')
|
|
19954
|
+
* ```
|
|
19955
|
+
*
|
|
19956
|
+
* Decline the follow request or delete the follower
|
|
19957
|
+
*
|
|
19958
|
+
* @param userId the ID of the {@link Amity.User} follower
|
|
19959
|
+
* @returns A success boolean if the follow request was decline
|
|
19960
|
+
*
|
|
19961
|
+
* @category Follow API
|
|
19962
|
+
* @async
|
|
19963
|
+
*/
|
|
19964
|
+
const declineFollower = async (userId) => {
|
|
19965
|
+
const client = getActiveClient();
|
|
19966
|
+
client.log('follow/declineFollower', userId);
|
|
19967
|
+
const { data } = await client.http.delete(`/api/v4/me/followers/${userId}`);
|
|
19968
|
+
if (client.cache) {
|
|
19969
|
+
ingestInCache(data);
|
|
19970
|
+
}
|
|
19971
|
+
fireEvent('follow.requestDeclined', data.follows[0]);
|
|
19972
|
+
return true;
|
|
19973
|
+
};
|
|
19974
|
+
|
|
19975
|
+
const createFollowEventSubscriber = (event, callback) => {
|
|
19976
|
+
const client = getActiveClient();
|
|
19977
|
+
const filter = (payload) => {
|
|
19978
|
+
var _a, _b;
|
|
19979
|
+
if (!client.cache) {
|
|
19980
|
+
callback(payload);
|
|
19981
|
+
}
|
|
19982
|
+
else {
|
|
19983
|
+
ingestInCache({ follows: [payload] });
|
|
19984
|
+
const queries = [
|
|
19985
|
+
...(_a = queryCache(['followers', 'query'])) !== null && _a !== void 0 ? _a : [],
|
|
19986
|
+
...(_b = queryCache(['followings', 'query'])) !== null && _b !== void 0 ? _b : [],
|
|
19987
|
+
];
|
|
19988
|
+
queries
|
|
19989
|
+
// @ts-ignore
|
|
19990
|
+
.filter(({ key }) => key[2].userId === payload.from || key[2].userId === payload.to)
|
|
19991
|
+
.forEach(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
19992
|
+
callback(payload);
|
|
19993
|
+
}
|
|
19994
|
+
};
|
|
19995
|
+
return createEventSubscriber(client, event, event, filter);
|
|
19996
|
+
};
|
|
19997
|
+
|
|
19998
|
+
/**
|
|
19999
|
+
* ```js
|
|
20000
|
+
* import { onUserFollowed } from '@amityco/ts-sdk'
|
|
20001
|
+
* const dispose = onUserFollowed(status => {
|
|
20002
|
+
* // ...
|
|
20003
|
+
* })
|
|
20004
|
+
* ```
|
|
20005
|
+
*
|
|
20006
|
+
* Fired when a user follows another users and confirmation is not required
|
|
20007
|
+
*
|
|
20008
|
+
* @param callback The function to call when the event was fired
|
|
20009
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20010
|
+
*
|
|
20011
|
+
* @category Follow Events
|
|
20012
|
+
*/
|
|
20013
|
+
const onUserFollowed = (callback) => createFollowEventSubscriber('follow.created', callback);
|
|
20014
|
+
|
|
20015
|
+
/**
|
|
20016
|
+
* ```js
|
|
20017
|
+
* import { onUserUnfollowed } from '@amityco/ts-sdk'
|
|
20018
|
+
* const dispose = onUserFollowed(status => {
|
|
20019
|
+
* // ...
|
|
20020
|
+
* })
|
|
20021
|
+
* ```
|
|
20022
|
+
*
|
|
20023
|
+
* Fired when a user unfollows
|
|
20024
|
+
*
|
|
20025
|
+
* @param callback The function to call when the event was fired
|
|
20026
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20027
|
+
*
|
|
20028
|
+
* @category Follow Events
|
|
20029
|
+
*/
|
|
20030
|
+
const onUserUnfollowed = (callback) => createFollowEventSubscriber('follow.unfollowed', callback);
|
|
20031
|
+
|
|
20032
|
+
/**
|
|
20033
|
+
* ```js
|
|
20034
|
+
* import { onFollowerDeleted } from '@amityco/ts-sdk'
|
|
20035
|
+
* const dispose = onFollowerDeleted(status => {
|
|
20036
|
+
* // ...
|
|
20037
|
+
* })
|
|
20038
|
+
* ```
|
|
20039
|
+
*
|
|
20040
|
+
* Fired when a follower has been deleted
|
|
20041
|
+
*
|
|
20042
|
+
* @param callback The function to call when the event was fired
|
|
20043
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20044
|
+
*
|
|
20045
|
+
* @category Follow Events
|
|
20046
|
+
*/
|
|
20047
|
+
const onFollowerDeleted = (callback) => createFollowEventSubscriber('follow.followerDeleted', callback);
|
|
20048
|
+
|
|
20049
|
+
/**
|
|
20050
|
+
* ```js
|
|
20051
|
+
* import { onFollowerRequested } from '@amityco/ts-sdk'
|
|
20052
|
+
* const dispose = onFollowerRequested(status => {
|
|
20053
|
+
* // ...
|
|
20054
|
+
* })
|
|
20055
|
+
* ```
|
|
20056
|
+
*
|
|
20057
|
+
* Fired when a user follows another users and confirmation is required
|
|
20058
|
+
*
|
|
20059
|
+
* @param callback The function to call when the event was fired
|
|
20060
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20061
|
+
*
|
|
20062
|
+
* @category Follow Events
|
|
20063
|
+
*/
|
|
20064
|
+
const onFollowerRequested = (callback) => createFollowEventSubscriber('follow.requested', callback);
|
|
20065
|
+
|
|
20066
|
+
/**
|
|
20067
|
+
* ```js
|
|
20068
|
+
* import { onFollowRequestCanceled } from '@amityco/ts-sdk'
|
|
20069
|
+
* const dispose = onFollowRequestCanceled(status => {
|
|
20070
|
+
* // ...
|
|
20071
|
+
* })
|
|
20072
|
+
* ```
|
|
20073
|
+
*
|
|
20074
|
+
* Fired when a follow request has been canceled
|
|
20075
|
+
*
|
|
20076
|
+
* @param callback The function to call when the event was fired
|
|
20077
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20078
|
+
*
|
|
20079
|
+
* @category Follow Events
|
|
20080
|
+
*/
|
|
20081
|
+
const onFollowRequestCanceled = (callback) => createFollowEventSubscriber('follow.requestCanceled', callback);
|
|
20082
|
+
|
|
20083
|
+
/**
|
|
20084
|
+
* ```js
|
|
20085
|
+
* import { onFollowRequestAccepted } from '@amityco/ts-sdk'
|
|
20086
|
+
* const dispose = onFollowRequestAccepted(status => {
|
|
20087
|
+
* // ...
|
|
20088
|
+
* })
|
|
20089
|
+
* ```
|
|
20090
|
+
*
|
|
20091
|
+
* Fired when a follow request has been accepted
|
|
20092
|
+
*
|
|
20093
|
+
* @param callback The function to call when the event was fired
|
|
20094
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20095
|
+
*
|
|
20096
|
+
* @category Follow Events
|
|
20097
|
+
*/
|
|
20098
|
+
const onFollowRequestAccepted = (callback) => createFollowEventSubscriber('follow.accepted', callback);
|
|
20099
|
+
|
|
20100
|
+
/**
|
|
20101
|
+
* ```js
|
|
20102
|
+
* import { onFollowRequestDeclined } from '@amityco/ts-sdk'
|
|
20103
|
+
* const dispose = onFollowRequestDeclined(status => {
|
|
20104
|
+
* // ...
|
|
20105
|
+
* })
|
|
20106
|
+
* ```
|
|
20107
|
+
*
|
|
20108
|
+
* Fired when a follow request has been declined
|
|
20109
|
+
*
|
|
20110
|
+
* @param callback The function to call when the event was fired
|
|
20111
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20112
|
+
*
|
|
20113
|
+
* @category Follow Events
|
|
20114
|
+
*/
|
|
20115
|
+
const onFollowRequestDeclined = (callback) => createFollowEventSubscriber('follow.requestDeclined', callback);
|
|
20116
|
+
|
|
20117
|
+
/**
|
|
20118
|
+
* ```js
|
|
20119
|
+
* import { onFollowInfoUpdated } from '@amityco/ts-sdk'
|
|
20120
|
+
* const dispose = onFollowInfoUpdated(followInfo => {
|
|
20121
|
+
* // ...
|
|
20122
|
+
* })
|
|
20123
|
+
* ```
|
|
20124
|
+
*
|
|
20125
|
+
* Fired when a {@link Amity.FollowInfo} has been updated
|
|
20126
|
+
*
|
|
20127
|
+
* @param callback The function to call when the event was fired
|
|
20128
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20129
|
+
*
|
|
20130
|
+
* @category Follow Events
|
|
20131
|
+
*/
|
|
20132
|
+
const onFollowInfoUpdated = (callback) => {
|
|
20133
|
+
const handler = async (payload) => {
|
|
20134
|
+
const [{ data: followInfoFrom }, { data: followInfoTo },] = await Promise.all([getFollowInfo(payload.from), getFollowInfo(payload.to)]);
|
|
20135
|
+
callback(followInfoFrom);
|
|
20136
|
+
callback(followInfoTo);
|
|
20137
|
+
};
|
|
20138
|
+
const disposers = [
|
|
20139
|
+
createFollowEventSubscriber('follow.created', handler),
|
|
20140
|
+
createFollowEventSubscriber('follow.requested', handler),
|
|
20141
|
+
createFollowEventSubscriber('follow.accepted', handler),
|
|
20142
|
+
createFollowEventSubscriber('follow.unfollowed', handler),
|
|
20143
|
+
createFollowEventSubscriber('follow.requestCanceled', handler),
|
|
20144
|
+
createFollowEventSubscriber('follow.requestDeclined', handler),
|
|
20145
|
+
createFollowEventSubscriber('follow.followerDeleted', handler),
|
|
20146
|
+
];
|
|
20147
|
+
return () => {
|
|
20148
|
+
disposers.forEach(fn => fn());
|
|
20149
|
+
};
|
|
20150
|
+
};
|
|
20151
|
+
|
|
20152
|
+
/**
|
|
20153
|
+
* ```js
|
|
20154
|
+
* import { observeFollowInfo } from '@amityco/ts-sdk'
|
|
20155
|
+
*
|
|
20156
|
+
* let followInfo = {}
|
|
20157
|
+
* const dispose = observeFollowInfo(userId, updated => followInfo = updated)
|
|
20158
|
+
* ```
|
|
20159
|
+
*
|
|
20160
|
+
* Observe all mutation on a given {@link Amity.FollowInfo}
|
|
20161
|
+
*
|
|
20162
|
+
* @param userId the ID of the user to observe
|
|
20163
|
+
* @param callback the function to call when new data are available
|
|
20164
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the post
|
|
20165
|
+
*
|
|
20166
|
+
* @category Follow Observer
|
|
20167
|
+
*/
|
|
20168
|
+
const observeFollowInfo = (userId, callback, policy = 'cache_then_server') => {
|
|
20169
|
+
const { log } = getActiveClient();
|
|
20170
|
+
const timestamp = Date.now();
|
|
20171
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > listen`);
|
|
20172
|
+
const router = (result, action) => {
|
|
20173
|
+
var _a, _b;
|
|
20174
|
+
if (callback instanceof Function)
|
|
20175
|
+
return callback(result);
|
|
20176
|
+
if (action !== 'onFetch')
|
|
20177
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, result);
|
|
20178
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, result);
|
|
20179
|
+
};
|
|
20180
|
+
const realtimeRouter = (result, action) => {
|
|
20181
|
+
var _a;
|
|
20182
|
+
if (((_a = result.data) === null || _a === void 0 ? void 0 : _a.userId) !== userId)
|
|
20183
|
+
return;
|
|
20184
|
+
router(result, action);
|
|
20185
|
+
};
|
|
20186
|
+
const disposers = [];
|
|
20187
|
+
disposers.push(onFollowInfoUpdated(data => realtimeRouter({ data, loading: false, origin: 'event' }, 'onUpdate')));
|
|
20188
|
+
runQuery(createQuery(getFollowInfo, userId), result => (result.data || result.error) && router(result, 'onFetch'), queryOptions(policy));
|
|
20189
|
+
return () => {
|
|
20190
|
+
log(`observeFollowInfo(tmpid: ${timestamp}) > dispose`);
|
|
20191
|
+
disposers.forEach(fn => fn());
|
|
20192
|
+
};
|
|
20193
|
+
};
|
|
20194
|
+
|
|
20195
|
+
/**
|
|
20196
|
+
* ```js
|
|
20197
|
+
* import { observeFollowers } from '@amityco/ts-sdk'
|
|
20198
|
+
*
|
|
20199
|
+
* let followers = []
|
|
20200
|
+
* const unsub = observeFollowers('userId', follower => merge(followers, follower))
|
|
20201
|
+
* ```
|
|
20202
|
+
*
|
|
20203
|
+
* Observe all mutations on a list of followers {@link Amity.FollowStatus} for a given user
|
|
20204
|
+
*
|
|
20205
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20206
|
+
* @param callback the function to call when new data are available
|
|
20207
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20208
|
+
*
|
|
20209
|
+
* @category Follow Observer
|
|
20210
|
+
*/
|
|
20211
|
+
const observeFollowers = (userId, callback) => {
|
|
20212
|
+
const { log } = getActiveClient();
|
|
20213
|
+
const timestamp = Date.now();
|
|
20214
|
+
log(`observeFollowers(tmpid: ${timestamp}) > listen`);
|
|
20215
|
+
const disposers = [];
|
|
20216
|
+
const router = (status, action) => {
|
|
20217
|
+
var _a, _b;
|
|
20218
|
+
if (status.from !== userId) {
|
|
20219
|
+
return;
|
|
20220
|
+
}
|
|
20221
|
+
if (callback instanceof Function) {
|
|
20222
|
+
return callback(status);
|
|
20223
|
+
}
|
|
20224
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20225
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20226
|
+
};
|
|
20227
|
+
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')));
|
|
20228
|
+
return () => {
|
|
20229
|
+
log(`observeFollowers(tmpid: ${timestamp}) > dispose`);
|
|
20230
|
+
disposers.forEach(fn => fn());
|
|
20231
|
+
};
|
|
20232
|
+
};
|
|
20233
|
+
|
|
20234
|
+
/**
|
|
20235
|
+
* ```js
|
|
20236
|
+
* import { observeFollowings } from '@amityco/ts-sdk'
|
|
20237
|
+
*
|
|
20238
|
+
* let followings = []
|
|
20239
|
+
* const unsub = observeFollowers('userId', follower => merge(followings, following))
|
|
20240
|
+
* ```
|
|
20241
|
+
*
|
|
20242
|
+
* Observe all mutations on a list of followings {@link Amity.FollowStatus} for a given user
|
|
20243
|
+
*
|
|
20244
|
+
* @param userId the ID of the {@link Amity.User}
|
|
20245
|
+
* @param callback the function to call when new data are available
|
|
20246
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
20247
|
+
*
|
|
20248
|
+
* @category Follow Observer
|
|
20249
|
+
*/
|
|
20250
|
+
const observeFollowings = (userId, callback) => {
|
|
20251
|
+
const { log } = getActiveClient();
|
|
20252
|
+
const timestamp = Date.now();
|
|
20253
|
+
log(`observeFollowings(tmpid: ${timestamp}) > listen`);
|
|
20254
|
+
const disposers = [];
|
|
20255
|
+
const router = (status, action) => {
|
|
20256
|
+
var _a, _b;
|
|
20257
|
+
if (status.to !== userId) {
|
|
20258
|
+
return;
|
|
20259
|
+
}
|
|
20260
|
+
if (callback instanceof Function) {
|
|
20261
|
+
return callback(status);
|
|
20262
|
+
}
|
|
20263
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, status);
|
|
20264
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, status);
|
|
20265
|
+
};
|
|
20266
|
+
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')));
|
|
20267
|
+
return () => {
|
|
20268
|
+
log(`observeFollowings(tmpid: ${timestamp}) > dispose`);
|
|
20269
|
+
disposers.forEach(fn => fn());
|
|
20270
|
+
};
|
|
19522
20271
|
};
|
|
19523
20272
|
|
|
19524
20273
|
/**
|
|
@@ -19979,7 +20728,9 @@ const onStreamRecorded = (callback) => {
|
|
|
19979
20728
|
return createEventSubscriber(client, 'stream/onStreamRecorded', 'video-streaming.didRecord', filter);
|
|
19980
20729
|
};
|
|
19981
20730
|
|
|
20731
|
+
exports.API_REGIONS = API_REGIONS;
|
|
19982
20732
|
exports.VERSION = VERSION$1;
|
|
20733
|
+
exports.acceptFollower = acceptFollower;
|
|
19983
20734
|
exports.addChannelMembers = addChannelMembers;
|
|
19984
20735
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
19985
20736
|
exports.addCommunityMembers = addCommunityMembers;
|
|
@@ -19997,6 +20748,7 @@ exports.createPost = createPost;
|
|
|
19997
20748
|
exports.createQuery = createQuery;
|
|
19998
20749
|
exports.createReport = createReport;
|
|
19999
20750
|
exports.createStream = createStream;
|
|
20751
|
+
exports.declineFollower = declineFollower;
|
|
20000
20752
|
exports.deleteChannel = deleteChannel;
|
|
20001
20753
|
exports.deleteComment = deleteComment;
|
|
20002
20754
|
exports.deleteCommunity = deleteCommunity;
|
|
@@ -20012,6 +20764,7 @@ exports.dropFromCache = dropFromCache;
|
|
|
20012
20764
|
exports.enableCache = enableCache;
|
|
20013
20765
|
exports.fileUrlWithSize = fileUrlWithSize;
|
|
20014
20766
|
exports.filterByPropEquality = filterByPropEquality;
|
|
20767
|
+
exports.follow = follow;
|
|
20015
20768
|
exports.getActiveClient = getActiveClient;
|
|
20016
20769
|
exports.getChannel = getChannel;
|
|
20017
20770
|
exports.getChannels = getChannels;
|
|
@@ -20022,13 +20775,18 @@ exports.getCommunities = getCommunities;
|
|
|
20022
20775
|
exports.getCommunity = getCommunity;
|
|
20023
20776
|
exports.getCommunityTopic = getCommunityTopic;
|
|
20024
20777
|
exports.getFile = getFile;
|
|
20778
|
+
exports.getFollowInfo = getFollowInfo;
|
|
20025
20779
|
exports.getMessage = getMessage;
|
|
20026
20780
|
exports.getMessages = getMessages;
|
|
20781
|
+
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
20782
|
+
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
20027
20783
|
exports.getPost = getPost;
|
|
20028
20784
|
exports.getPostTopic = getPostTopic;
|
|
20029
20785
|
exports.getPosts = getPosts;
|
|
20786
|
+
exports.getRecommendedCommunities = getRecommendedCommunities;
|
|
20030
20787
|
exports.getRole = getRole;
|
|
20031
20788
|
exports.getStream = getStream;
|
|
20789
|
+
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
20032
20790
|
exports.getUser = getUser;
|
|
20033
20791
|
exports.getUserTopic = getUserTopic;
|
|
20034
20792
|
exports.getUsers = getUsers;
|
|
@@ -20054,6 +20812,9 @@ exports.observeComment = observeComment;
|
|
|
20054
20812
|
exports.observeComments = observeComments;
|
|
20055
20813
|
exports.observeCommunity = observeCommunity;
|
|
20056
20814
|
exports.observeFile = observeFile;
|
|
20815
|
+
exports.observeFollowInfo = observeFollowInfo;
|
|
20816
|
+
exports.observeFollowers = observeFollowers;
|
|
20817
|
+
exports.observeFollowings = observeFollowings;
|
|
20057
20818
|
exports.observeMessage = observeMessage;
|
|
20058
20819
|
exports.observeMessages = observeMessages;
|
|
20059
20820
|
exports.observePost = observePost;
|
|
@@ -20082,6 +20843,12 @@ exports.onCommunityUserBanned = onCommunityUserBanned;
|
|
|
20082
20843
|
exports.onCommunityUserRemoved = onCommunityUserRemoved;
|
|
20083
20844
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
20084
20845
|
exports.onConnectionError = onConnectionError;
|
|
20846
|
+
exports.onFollowInfoUpdated = onFollowInfoUpdated;
|
|
20847
|
+
exports.onFollowRequestAccepted = onFollowRequestAccepted;
|
|
20848
|
+
exports.onFollowRequestCanceled = onFollowRequestCanceled;
|
|
20849
|
+
exports.onFollowRequestDeclined = onFollowRequestDeclined;
|
|
20850
|
+
exports.onFollowerDeleted = onFollowerDeleted;
|
|
20851
|
+
exports.onFollowerRequested = onFollowerRequested;
|
|
20085
20852
|
exports.onMemberAdded = onMemberAdded;
|
|
20086
20853
|
exports.onMemberRemoved = onMemberRemoved;
|
|
20087
20854
|
exports.onMessageCreated = onMessageCreated;
|
|
@@ -20102,7 +20869,9 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
20102
20869
|
exports.onStreamStopped = onStreamStopped;
|
|
20103
20870
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
20104
20871
|
exports.onUserFlagged = onUserFlagged;
|
|
20872
|
+
exports.onUserFollowed = onUserFollowed;
|
|
20105
20873
|
exports.onUserUnflagged = onUserUnflagged;
|
|
20874
|
+
exports.onUserUnfollowed = onUserUnfollowed;
|
|
20106
20875
|
exports.onUserUpdated = onUserUpdated;
|
|
20107
20876
|
exports.pullFromCache = pullFromCache;
|
|
20108
20877
|
exports.pushToCache = pushToCache;
|
|
@@ -20112,6 +20881,8 @@ exports.queryChannels = queryChannels;
|
|
|
20112
20881
|
exports.queryComments = queryComments;
|
|
20113
20882
|
exports.queryCommunities = queryCommunities;
|
|
20114
20883
|
exports.queryCommunityMembers = queryCommunityMembers;
|
|
20884
|
+
exports.queryFollowers = queryFollowers;
|
|
20885
|
+
exports.queryFollowings = queryFollowings;
|
|
20115
20886
|
exports.queryGlobalFeed = queryGlobalFeed;
|
|
20116
20887
|
exports.queryMessages = queryMessages;
|
|
20117
20888
|
exports.queryOptions = queryOptions;
|
|
@@ -20126,7 +20897,6 @@ exports.removeCommunityMembersRole = removeCommunityMembersRole;
|
|
|
20126
20897
|
exports.removeReaction = removeReaction;
|
|
20127
20898
|
exports.restoreCache = restoreCache;
|
|
20128
20899
|
exports.runQuery = runQuery;
|
|
20129
|
-
exports.sliceByPaging = sliceByPaging;
|
|
20130
20900
|
exports.sortByChannelSegment = sortByChannelSegment;
|
|
20131
20901
|
exports.sortByDisplayName = sortByDisplayName;
|
|
20132
20902
|
exports.sortByFirstCreated = sortByFirstCreated;
|
|
@@ -20137,6 +20907,7 @@ exports.subscribeTopic = subscribeTopic;
|
|
|
20137
20907
|
exports.toPage = toPage;
|
|
20138
20908
|
exports.toPageRaw = toPageRaw;
|
|
20139
20909
|
exports.toToken = toToken;
|
|
20910
|
+
exports.unfollow = unfollow;
|
|
20140
20911
|
exports.updateChannel = updateChannel;
|
|
20141
20912
|
exports.updateComment = updateComment;
|
|
20142
20913
|
exports.updateCommunity = updateCommunity;
|