@amityco/ts-sdk 0.0.1-beta.15 → 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/dist/@types/core/cache.d.ts +1 -1
- package/dist/@types/core/cache.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +10 -1
- 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 +10 -10
- 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 +5 -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/follow.d.ts +20 -0
- package/dist/@types/domains/follow.d.ts.map +1 -0
- package/dist/@types/index.d.ts +1 -0
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +3 -3
- package/dist/channel/api/createChannel.d.ts +1 -1
- package/dist/channel/api/queryChannels.d.ts +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/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/community/api/queryCommunities.d.ts +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- 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 +3 -3
- package/dist/core/query/paging.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 +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 +752 -8
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +731 -9
- package/dist/index.umd.js +5 -5
- package/dist/post/api/queryPosts.d.ts +2 -2
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/role/api/queryRoles.d.ts +1 -1
- package/dist/stream/api/queryStreams.d.ts +1 -1
- package/package.json +1 -1
- package/src/@types/core/cache.ts +1 -1
- package/src/@types/core/events.ts +11 -0
- package/src/@types/core/model.ts +6 -0
- package/src/@types/core/paging.ts +9 -9
- package/src/@types/core/payload.ts +14 -0
- package/src/@types/core/query.ts +8 -4
- package/src/@types/domains/client.ts +0 -1
- package/src/@types/domains/follow.ts +25 -0
- package/src/@types/index.ts +1 -0
- package/src/channel/api/createChannel.ts +1 -1
- package/src/client/api/activeUser.ts +26 -0
- package/src/client/api/connectClient.ts +3 -1
- 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/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 +10 -10
- package/src/core/subscription.ts +21 -3
- 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 +4 -0
- package/src/post/api/queryPosts.ts +2 -2
package/dist/index.cjs.js
CHANGED
|
@@ -132,7 +132,7 @@ const toToken = (paging, style) => {
|
|
|
132
132
|
*/
|
|
133
133
|
const toPage = (token) => {
|
|
134
134
|
if (!token)
|
|
135
|
-
return
|
|
135
|
+
return undefined;
|
|
136
136
|
// don't try catch, let it throw
|
|
137
137
|
const json = JSON.parse(jsBase64.decode(token));
|
|
138
138
|
if (isSkipLimit(json)) {
|
|
@@ -155,7 +155,7 @@ const toPage = (token) => {
|
|
|
155
155
|
};
|
|
156
156
|
}
|
|
157
157
|
}
|
|
158
|
-
return
|
|
158
|
+
return undefined;
|
|
159
159
|
};
|
|
160
160
|
/**
|
|
161
161
|
* Converts a b64 string token into a paging object
|
|
@@ -167,13 +167,13 @@ const toPage = (token) => {
|
|
|
167
167
|
*/
|
|
168
168
|
const toPageRaw = (token) => {
|
|
169
169
|
if (!token)
|
|
170
|
-
return
|
|
170
|
+
return undefined;
|
|
171
171
|
// don't try catch, let it throw
|
|
172
172
|
const json = JSON.parse(jsBase64.decode(token));
|
|
173
173
|
if (isAfterBeforeRaw(json)) {
|
|
174
174
|
return json;
|
|
175
175
|
}
|
|
176
|
-
return
|
|
176
|
+
return undefined;
|
|
177
177
|
};
|
|
178
178
|
|
|
179
179
|
/**
|
|
@@ -14929,6 +14929,24 @@ const getDeviceInfo = () => {
|
|
|
14929
14929
|
};
|
|
14930
14930
|
};
|
|
14931
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
|
+
|
|
14932
14950
|
/**
|
|
14933
14951
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
14934
14952
|
*
|
|
@@ -15076,8 +15094,8 @@ const connectClient = async (params) => {
|
|
|
15076
15094
|
unsubscribe();
|
|
15077
15095
|
});
|
|
15078
15096
|
client.userId = params.userId;
|
|
15079
|
-
client._internalUserId = users[0]._id;
|
|
15080
15097
|
client.accessToken = accessToken;
|
|
15098
|
+
setActiveUser(users[0]);
|
|
15081
15099
|
return client.ws.connected;
|
|
15082
15100
|
};
|
|
15083
15101
|
|
|
@@ -15135,13 +15153,24 @@ const getPostTopic = ({ path }, level = exports.SubscriptionLevels.POST) => {
|
|
|
15135
15153
|
const getCommentTopic = ({ path }) => {
|
|
15136
15154
|
return path;
|
|
15137
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
|
+
};
|
|
15138
15166
|
let mqttAccessToken;
|
|
15139
15167
|
let mqttUserId;
|
|
15140
15168
|
function subscribeTopic(topic, callback) {
|
|
15141
|
-
const { mqtt, emitter, accessToken
|
|
15142
|
-
|
|
15169
|
+
const { mqtt, emitter, accessToken } = getActiveClient();
|
|
15170
|
+
const user = getActiveUser();
|
|
15171
|
+
if (mqttAccessToken !== accessToken || mqttUserId !== user._id) {
|
|
15143
15172
|
mqttAccessToken = accessToken;
|
|
15144
|
-
mqttUserId =
|
|
15173
|
+
mqttUserId = user._id;
|
|
15145
15174
|
mqtt.connect({ accessToken: mqttAccessToken, userId: mqttUserId });
|
|
15146
15175
|
proxyMqttEvents(mqtt, emitter);
|
|
15147
15176
|
}
|
|
@@ -15547,6 +15576,8 @@ const idResolvers = {
|
|
|
15547
15576
|
post: ({ postId }) => postId,
|
|
15548
15577
|
comment: ({ commentId }) => commentId,
|
|
15549
15578
|
stream: ({ streamId }) => streamId,
|
|
15579
|
+
follow: ({ from, to }) => `${from}#${to}`,
|
|
15580
|
+
followCount: ({ userId }) => userId,
|
|
15550
15581
|
};
|
|
15551
15582
|
/**
|
|
15552
15583
|
* Retrieve the id resolver matching a domain name
|
|
@@ -15573,6 +15604,8 @@ const PAYLOAD2MODEL = {
|
|
|
15573
15604
|
postChildren: 'post',
|
|
15574
15605
|
comments: 'comment',
|
|
15575
15606
|
videoStreamings: 'stream',
|
|
15607
|
+
follows: 'follow',
|
|
15608
|
+
followCounts: 'followCount'
|
|
15576
15609
|
};
|
|
15577
15610
|
|
|
15578
15611
|
/**
|
|
@@ -17354,6 +17387,132 @@ const removeCommunityMembersRole = async (communityId, roleId, userIds) => {
|
|
|
17354
17387
|
return !!communityUsers.find(communityUser => communityUser.communityId === communityId && !communityUser.roles.includes(roleId));
|
|
17355
17388
|
};
|
|
17356
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
|
+
|
|
17357
17516
|
/**
|
|
17358
17517
|
* ```js
|
|
17359
17518
|
* import { deletePost } from '@amityco/ts-sdk'
|
|
@@ -19548,6 +19707,569 @@ queryGlobalFeed.locally = (query) => {
|
|
|
19548
19707
|
: undefined;
|
|
19549
19708
|
};
|
|
19550
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
|
+
}
|
|
19725
|
+
const nextPage = toPage(paging.next);
|
|
19726
|
+
const prevPage = toPage(paging.previous);
|
|
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
|
+
};
|
|
20271
|
+
};
|
|
20272
|
+
|
|
19551
20273
|
/**
|
|
19552
20274
|
* ```js
|
|
19553
20275
|
* import { observePosts } from '@amityco/ts-sdk'
|
|
@@ -20008,6 +20730,7 @@ const onStreamRecorded = (callback) => {
|
|
|
20008
20730
|
|
|
20009
20731
|
exports.API_REGIONS = API_REGIONS;
|
|
20010
20732
|
exports.VERSION = VERSION$1;
|
|
20733
|
+
exports.acceptFollower = acceptFollower;
|
|
20011
20734
|
exports.addChannelMembers = addChannelMembers;
|
|
20012
20735
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
20013
20736
|
exports.addCommunityMembers = addCommunityMembers;
|
|
@@ -20025,6 +20748,7 @@ exports.createPost = createPost;
|
|
|
20025
20748
|
exports.createQuery = createQuery;
|
|
20026
20749
|
exports.createReport = createReport;
|
|
20027
20750
|
exports.createStream = createStream;
|
|
20751
|
+
exports.declineFollower = declineFollower;
|
|
20028
20752
|
exports.deleteChannel = deleteChannel;
|
|
20029
20753
|
exports.deleteComment = deleteComment;
|
|
20030
20754
|
exports.deleteCommunity = deleteCommunity;
|
|
@@ -20040,6 +20764,7 @@ exports.dropFromCache = dropFromCache;
|
|
|
20040
20764
|
exports.enableCache = enableCache;
|
|
20041
20765
|
exports.fileUrlWithSize = fileUrlWithSize;
|
|
20042
20766
|
exports.filterByPropEquality = filterByPropEquality;
|
|
20767
|
+
exports.follow = follow;
|
|
20043
20768
|
exports.getActiveClient = getActiveClient;
|
|
20044
20769
|
exports.getChannel = getChannel;
|
|
20045
20770
|
exports.getChannels = getChannels;
|
|
@@ -20050,13 +20775,18 @@ exports.getCommunities = getCommunities;
|
|
|
20050
20775
|
exports.getCommunity = getCommunity;
|
|
20051
20776
|
exports.getCommunityTopic = getCommunityTopic;
|
|
20052
20777
|
exports.getFile = getFile;
|
|
20778
|
+
exports.getFollowInfo = getFollowInfo;
|
|
20053
20779
|
exports.getMessage = getMessage;
|
|
20054
20780
|
exports.getMessages = getMessages;
|
|
20781
|
+
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
20782
|
+
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
20055
20783
|
exports.getPost = getPost;
|
|
20056
20784
|
exports.getPostTopic = getPostTopic;
|
|
20057
20785
|
exports.getPosts = getPosts;
|
|
20786
|
+
exports.getRecommendedCommunities = getRecommendedCommunities;
|
|
20058
20787
|
exports.getRole = getRole;
|
|
20059
20788
|
exports.getStream = getStream;
|
|
20789
|
+
exports.getTopTrendingCommunities = getTopTrendingCommunities;
|
|
20060
20790
|
exports.getUser = getUser;
|
|
20061
20791
|
exports.getUserTopic = getUserTopic;
|
|
20062
20792
|
exports.getUsers = getUsers;
|
|
@@ -20082,6 +20812,9 @@ exports.observeComment = observeComment;
|
|
|
20082
20812
|
exports.observeComments = observeComments;
|
|
20083
20813
|
exports.observeCommunity = observeCommunity;
|
|
20084
20814
|
exports.observeFile = observeFile;
|
|
20815
|
+
exports.observeFollowInfo = observeFollowInfo;
|
|
20816
|
+
exports.observeFollowers = observeFollowers;
|
|
20817
|
+
exports.observeFollowings = observeFollowings;
|
|
20085
20818
|
exports.observeMessage = observeMessage;
|
|
20086
20819
|
exports.observeMessages = observeMessages;
|
|
20087
20820
|
exports.observePost = observePost;
|
|
@@ -20110,6 +20843,12 @@ exports.onCommunityUserBanned = onCommunityUserBanned;
|
|
|
20110
20843
|
exports.onCommunityUserRemoved = onCommunityUserRemoved;
|
|
20111
20844
|
exports.onCommunityUserUnbanned = onCommunityUserUnbanned;
|
|
20112
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;
|
|
20113
20852
|
exports.onMemberAdded = onMemberAdded;
|
|
20114
20853
|
exports.onMemberRemoved = onMemberRemoved;
|
|
20115
20854
|
exports.onMessageCreated = onMessageCreated;
|
|
@@ -20130,7 +20869,9 @@ exports.onStreamStarted = onStreamStarted;
|
|
|
20130
20869
|
exports.onStreamStopped = onStreamStopped;
|
|
20131
20870
|
exports.onUserFlagCleared = onUserFlagCleared;
|
|
20132
20871
|
exports.onUserFlagged = onUserFlagged;
|
|
20872
|
+
exports.onUserFollowed = onUserFollowed;
|
|
20133
20873
|
exports.onUserUnflagged = onUserUnflagged;
|
|
20874
|
+
exports.onUserUnfollowed = onUserUnfollowed;
|
|
20134
20875
|
exports.onUserUpdated = onUserUpdated;
|
|
20135
20876
|
exports.pullFromCache = pullFromCache;
|
|
20136
20877
|
exports.pushToCache = pushToCache;
|
|
@@ -20140,6 +20881,8 @@ exports.queryChannels = queryChannels;
|
|
|
20140
20881
|
exports.queryComments = queryComments;
|
|
20141
20882
|
exports.queryCommunities = queryCommunities;
|
|
20142
20883
|
exports.queryCommunityMembers = queryCommunityMembers;
|
|
20884
|
+
exports.queryFollowers = queryFollowers;
|
|
20885
|
+
exports.queryFollowings = queryFollowings;
|
|
20143
20886
|
exports.queryGlobalFeed = queryGlobalFeed;
|
|
20144
20887
|
exports.queryMessages = queryMessages;
|
|
20145
20888
|
exports.queryOptions = queryOptions;
|
|
@@ -20164,6 +20907,7 @@ exports.subscribeTopic = subscribeTopic;
|
|
|
20164
20907
|
exports.toPage = toPage;
|
|
20165
20908
|
exports.toPageRaw = toPageRaw;
|
|
20166
20909
|
exports.toToken = toToken;
|
|
20910
|
+
exports.unfollow = unfollow;
|
|
20167
20911
|
exports.updateChannel = updateChannel;
|
|
20168
20912
|
exports.updateComment = updateComment;
|
|
20169
20913
|
exports.updateCommunity = updateCommunity;
|