@amityco/ts-sdk 0.0.1-beta.25 → 0.0.1-beta.28
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/.eslintrc.json +5 -1
- package/dist/@types/core/events.d.ts +7 -7
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/live.d.ts +23 -0
- package/dist/@types/core/live.d.ts.map +1 -0
- package/dist/@types/core/paging.d.ts +1 -1
- package/dist/@types/core/paging.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +15 -15
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +13 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +14 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +26 -3
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +36 -3
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +13 -1
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +1 -0
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +13 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +17 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +10 -0
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/@types/global.d.ts +1 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/@types/index.d.ts +3 -2
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/cache/api/ingestInCache.d.ts +1 -1
- package/dist/cache/api/ingestInCache.d.ts.map +1 -1
- package/dist/cache/api/mergeInCache.d.ts +1 -1
- package/dist/cache/api/mergeInCache.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts +3 -3
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts +16 -0
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/index.d.ts +2 -0
- package/dist/channel/api/index.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts +6 -6
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/unbanChannelMembers.d.ts +16 -0
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/index.d.ts +1 -0
- package/dist/channel/events/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/observers/index.d.ts +1 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/observeChannel.d.ts +1 -1
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/channel/observers/observeChannels.d.ts +17 -0
- package/dist/channel/observers/observeChannels.d.ts.map +1 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts +2 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts.map +1 -0
- package/dist/channel/utils/index.d.ts +2 -0
- package/dist/channel/utils/index.d.ts.map +1 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts +3 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +1 -8
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +8 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getFeedSettings.d.ts +16 -0
- package/dist/client/api/getFeedSettings.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts +1 -9
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/comment/observers/index.d.ts +1 -0
- package/dist/comment/observers/index.d.ts.map +1 -1
- package/dist/comment/observers/liveComments.d.ts +22 -0
- package/dist/comment/observers/liveComments.d.ts.map +1 -0
- package/dist/comment/observers/observeComments.d.ts.map +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/community/api/getTopTrendingCommunities.d.ts +1 -1
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts +7 -7
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/core/debug.d.ts +1 -1
- package/dist/core/debug.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/query/paging.d.ts +2 -2
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +2 -2
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/core/tests/query/filtering.test.d.ts +2 -0
- package/dist/core/tests/query/filtering.test.d.ts.map +1 -0
- package/dist/core/tests/query/query/runQuery.test.d.ts +2 -0
- package/dist/core/tests/query/query/runQuery.test.d.ts.map +1 -0
- package/dist/core/tests/query/query.test.d.ts +2 -0
- package/dist/core/tests/query/query.test.d.ts.map +1 -0
- package/dist/core/transports/ws.d.ts +1 -1
- package/dist/core/transports/ws.d.ts.map +1 -1
- package/dist/external/api/createUserToken.d.ts +1 -1
- package/dist/external/api/createUserToken.d.ts.map +1 -1
- package/dist/feed/api/queryGlobalFeed.d.ts +4 -4
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/file/api/createVideo.d.ts +2 -1
- package/dist/file/api/createVideo.d.ts.map +1 -1
- package/dist/follow/api/follow.d.ts.map +1 -1
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
- package/dist/follow/api/queryFollowers.d.ts +2 -6
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +2 -6
- package/dist/follow/api/queryFollowings.d.ts.map +1 -1
- package/dist/follow/api/utils.d.ts +4 -4
- package/dist/follow/api/utils.d.ts.map +1 -1
- package/dist/follow/events/utils.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +2 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowers.d.ts +20 -0
- package/dist/follow/observers/liveFollowers.d.ts.map +1 -0
- package/dist/follow/observers/liveFollowings.d.ts +20 -0
- package/dist/follow/observers/liveFollowings.d.ts.map +1 -0
- package/dist/index.cjs.js +18706 -17726
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +18688 -17727
- package/dist/index.umd.js +4 -19
- package/dist/message/api/queryMessages.d.ts +1 -10
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/observers/index.d.ts +1 -0
- package/dist/message/observers/index.d.ts.map +1 -1
- package/dist/message/observers/liveMessages.d.ts +20 -0
- package/dist/message/observers/liveMessages.d.ts.map +1 -0
- package/dist/message/observers/observeMessages.d.ts +0 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/message/observers/tests/liveMessages.test.d.ts +2 -0
- package/dist/message/observers/tests/liveMessages.test.d.ts.map +1 -0
- package/dist/post/api/queryPosts.d.ts +1 -12
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/observers/index.d.ts +1 -0
- package/dist/post/observers/index.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts +22 -0
- package/dist/post/observers/livePosts.d.ts.map +1 -0
- package/dist/post/observers/observePosts.d.ts.map +1 -1
- package/dist/post/tests/api/getPost.test.d.ts +2 -0
- package/dist/post/tests/api/getPost.test.d.ts.map +1 -0
- package/dist/post/tests/api/queryPosts.test.d.ts +2 -0
- package/dist/post/tests/api/queryPosts.test.d.ts.map +1 -0
- package/dist/reaction/api/queryReactions.d.ts +1 -6
- package/dist/reaction/api/queryReactions.d.ts.map +1 -1
- package/dist/reaction/events/index.d.ts +3 -0
- package/dist/reaction/events/index.d.ts.map +1 -1
- package/dist/reaction/events/onReactorAdded.d.ts +19 -0
- package/dist/reaction/events/onReactorAdded.d.ts.map +1 -0
- package/dist/reaction/events/onReactorRemoved.d.ts +19 -0
- package/dist/reaction/events/onReactorRemoved.d.ts.map +1 -0
- package/dist/reaction/observers/index.d.ts +2 -0
- package/dist/reaction/observers/index.d.ts.map +1 -0
- package/dist/reaction/observers/liveReactions.d.ts +22 -0
- package/dist/reaction/observers/liveReactions.d.ts.map +1 -0
- package/dist/role/api/queryRoles.d.ts +4 -4
- package/dist/role/api/queryRoles.d.ts.map +1 -1
- package/dist/stream/api/queryStreams.d.ts +6 -6
- package/dist/stream/api/queryStreams.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/tests/client.d.ts +6 -0
- package/dist/utils/tests/client.d.ts.map +1 -0
- package/dist/utils/tests/dummy/channel.d.ts +10 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
- package/dist/utils/tests/dummy/index.d.ts +10 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +8 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts +9 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -0
- package/dist/utils/tests/dummy/user.d.ts +2 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -0
- package/dist/utils/tests/index.d.ts +3 -0
- package/dist/utils/tests/index.d.ts.map +1 -0
- package/jest.config.ts +15 -0
- package/package.json +21 -16
- package/src/@types/core/events.ts +7 -7
- package/src/@types/core/live.ts +28 -0
- package/src/@types/core/paging.ts +1 -1
- package/src/@types/core/payload.ts +21 -16
- package/src/@types/domains/channel.ts +16 -1
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/comment.ts +31 -0
- package/src/@types/domains/content.ts +34 -3
- package/src/@types/domains/file.ts +42 -3
- package/src/@types/domains/follow.ts +31 -1
- package/src/@types/domains/group.ts +1 -0
- package/src/@types/domains/message.ts +20 -0
- package/src/@types/domains/post.ts +37 -0
- package/src/@types/domains/reaction.ts +17 -0
- package/src/@types/global.ts +2 -0
- package/src/@types/index.ts +4 -2
- package/src/channel/api/addChannelMembers.ts +6 -5
- package/src/channel/api/addChannelMembersRole.ts +5 -1
- package/src/channel/api/banChannelMembers.ts +45 -0
- package/src/channel/api/createChannel.ts +6 -2
- package/src/channel/api/getChannel.ts +5 -1
- package/src/channel/api/getChannels.ts +5 -1
- package/src/channel/api/index.ts +3 -0
- package/src/channel/api/joinChannel.ts +5 -1
- package/src/channel/api/leaveChannel.ts +5 -1
- package/src/channel/api/queryChannelMembers.ts +16 -12
- package/src/channel/api/queryChannels.ts +9 -4
- package/src/channel/api/removeChannelMembers.ts +6 -5
- package/src/channel/api/removeChannelMembersRole.ts +5 -1
- package/src/channel/api/unbanChannelMembers.ts +45 -0
- package/src/channel/api/updateChannel.ts +5 -1
- package/src/channel/events/index.ts +1 -0
- package/src/channel/events/onChannelCreated.ts +6 -2
- package/src/channel/events/onChannelDeleted.ts +6 -2
- package/src/channel/events/onChannelJoined.ts +6 -2
- package/src/channel/events/onChannelLeft.ts +6 -2
- package/src/channel/events/onChannelMemberAdded.ts +6 -2
- package/src/channel/events/onChannelMemberRemoved.ts +6 -2
- package/src/channel/events/onChannelUpdated.ts +6 -2
- package/src/channel/observers/index.ts +1 -0
- package/src/channel/observers/observeChannel.ts +1 -11
- package/src/channel/observers/observeChannels.ts +59 -0
- package/src/channel/tests/utils/prepareChannelPayload.test.ts +120 -0
- package/src/channel/utils/index.ts +1 -0
- package/src/channel/utils/prepareChannelPayload.ts +31 -0
- package/src/client/api/connectClient.ts +4 -9
- package/src/client/api/createClient.ts +19 -4
- package/src/client/api/getFeedSettings.ts +29 -0
- package/src/client/api/index.ts +2 -0
- package/src/comment/api/queryComments.ts +3 -9
- package/src/comment/observers/index.ts +1 -0
- package/src/comment/observers/liveComments.ts +172 -0
- package/src/comment/observers/observeComments.ts +1 -11
- package/src/core/events.ts +2 -1
- package/src/core/query/query.ts +16 -3
- package/src/core/tests/query/filtering.test.ts +11 -0
- package/src/core/tests/query/query/runQuery.test.ts +182 -0
- package/src/core/tests/query/query.test.ts +19 -0
- package/src/file/api/createVideo.ts +6 -0
- package/src/follow/api/acceptFollower.ts +1 -1
- package/src/follow/api/declineFollower.ts +1 -1
- package/src/follow/api/follow.ts +1 -4
- package/src/follow/api/getFollowInfo.ts +8 -5
- package/src/follow/api/queryFollowers.ts +5 -6
- package/src/follow/api/queryFollowings.ts +5 -6
- package/src/follow/api/unfollow.ts +1 -1
- package/src/follow/api/utils.ts +17 -13
- package/src/follow/events/utils.ts +9 -6
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/liveFollowers.ts +149 -0
- package/src/follow/observers/liveFollowings.ts +149 -0
- package/src/index.ts +2 -1
- package/src/message/api/queryMessages.ts +3 -10
- package/src/message/observers/index.ts +1 -0
- package/src/message/observers/liveMessages.ts +141 -0
- package/src/message/observers/observeMessages.ts +0 -1
- package/src/message/observers/tests/liveMessages.test.ts +133 -0
- package/src/post/api/queryPosts.ts +3 -12
- package/src/post/observers/index.ts +1 -0
- package/src/post/observers/livePosts.ts +171 -0
- package/src/post/observers/observePosts.ts +1 -13
- package/src/post/tests/api/getPost.test.ts +88 -0
- package/src/post/tests/api/queryPosts.test.ts +23 -0
- package/src/reaction/api/queryReactions.ts +14 -14
- package/src/reaction/events/index.ts +4 -0
- package/src/reaction/events/onReactorAdded.ts +80 -0
- package/src/reaction/events/onReactorRemoved.ts +85 -0
- package/src/reaction/observers/index.ts +1 -0
- package/src/reaction/observers/liveReactions.ts +142 -0
- package/src/utils/constants.ts +3 -0
- package/src/utils/tests/client.ts +33 -0
- package/src/utils/tests/dummy/channel.ts +52 -0
- package/src/utils/tests/dummy/index.ts +7 -0
- package/src/utils/tests/dummy/message.ts +21 -0
- package/src/utils/tests/dummy/post.ts +31 -0
- package/src/utils/tests/dummy/user.ts +11 -0
- package/src/utils/tests/index.ts +2 -0
- package/tsconfig.json +23 -22
package/src/follow/api/follow.ts
CHANGED
|
@@ -32,10 +32,7 @@ export const follow = async (
|
|
|
32
32
|
ingestInCache(data, { cachedAt });
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
-
fireEvent(
|
|
36
|
-
data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested',
|
|
37
|
-
data.follows[0],
|
|
38
|
-
);
|
|
35
|
+
fireEvent(data.follows[0].status === 'accepted' ? 'follow.created' : 'follow.requested', data);
|
|
39
36
|
|
|
40
37
|
return {
|
|
41
38
|
data: data.follows[0],
|
|
@@ -27,15 +27,18 @@ export const getFollowInfo = async (
|
|
|
27
27
|
const client = getActiveClient();
|
|
28
28
|
client.log('follow/getFollowInfo', userId);
|
|
29
29
|
|
|
30
|
-
const { data } = await client.http.get<Amity.FollowInfoPayload>(
|
|
30
|
+
const { data } = await client.http.get<Amity.FollowInfoMePayload | Amity.FollowInfoPayload>(
|
|
31
31
|
client.userId === userId ? `/api/v4/me/followInfo` : `/api/v4/users/${userId}/followInfo`,
|
|
32
32
|
);
|
|
33
33
|
|
|
34
34
|
const cachedAt = client.cache && Date.now();
|
|
35
|
-
const followInfo =
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
const followInfo =
|
|
36
|
+
'follows' in data
|
|
37
|
+
? {
|
|
38
|
+
...data.followCounts[0],
|
|
39
|
+
status: data.follows?.[0]?.status,
|
|
40
|
+
}
|
|
41
|
+
: data.followCounts[0];
|
|
39
42
|
|
|
40
43
|
if (client.cache) {
|
|
41
44
|
pushToCache(getCacheKey(userId), followInfo, { cachedAt });
|
|
@@ -14,11 +14,10 @@ import { queryFollows } from './utils';
|
|
|
14
14
|
* @category Follow API
|
|
15
15
|
* @async
|
|
16
16
|
*/
|
|
17
|
-
export const queryFollowers = async (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> => queryFollows('followers', query);
|
|
17
|
+
export const queryFollowers = async (
|
|
18
|
+
query: Amity.QueryFollowers,
|
|
19
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
20
|
+
queryFollows('followers', query);
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* ```js
|
|
@@ -35,5 +34,5 @@ export const queryFollowers = async (query: {
|
|
|
35
34
|
*/
|
|
36
35
|
queryFollowers.locally = (
|
|
37
36
|
query: Parameters<typeof queryFollowers>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
37
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
38
|
queryFollows.locally('followers', query);
|
|
@@ -14,11 +14,10 @@ import { queryFollows } from './utils';
|
|
|
14
14
|
* @category Follow API
|
|
15
15
|
* @async
|
|
16
16
|
*/
|
|
17
|
-
export const queryFollowings = async (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> => queryFollows('following', query);
|
|
17
|
+
export const queryFollowings = async (
|
|
18
|
+
query: Amity.QueryFollowings,
|
|
19
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
20
|
+
queryFollows('following', query);
|
|
22
21
|
|
|
23
22
|
/**
|
|
24
23
|
* ```js
|
|
@@ -35,5 +34,5 @@ export const queryFollowings = async (query: {
|
|
|
35
34
|
*/
|
|
36
35
|
queryFollowings.locally = (
|
|
37
36
|
query: Parameters<typeof queryFollowings>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
37
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
38
|
queryFollows.locally('following', query);
|
package/src/follow/api/utils.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api';
|
|
2
|
-
import {
|
|
2
|
+
import { toPageRaw, toToken } from '~/core/query';
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { pullFromCache, pushToCache } from '~/cache/api';
|
|
5
5
|
import { getResolver } from '~/core/model';
|
|
@@ -8,10 +8,10 @@ export const queryFollows = async (
|
|
|
8
8
|
key: 'followers' | 'following',
|
|
9
9
|
query: {
|
|
10
10
|
userId: Amity.User['userId'];
|
|
11
|
-
status?:
|
|
12
|
-
page?: Amity.
|
|
11
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
12
|
+
page?: Amity.PageRaw;
|
|
13
13
|
},
|
|
14
|
-
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> => {
|
|
14
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> => {
|
|
15
15
|
const client = getActiveClient();
|
|
16
16
|
client.log(`follow/queryF${key.substring(1)}`, query);
|
|
17
17
|
|
|
@@ -22,7 +22,7 @@ export const queryFollows = async (
|
|
|
22
22
|
{
|
|
23
23
|
params: {
|
|
24
24
|
...params,
|
|
25
|
-
token: toToken(page, '
|
|
25
|
+
token: toToken(page, 'afterbeforeraw'),
|
|
26
26
|
},
|
|
27
27
|
},
|
|
28
28
|
);
|
|
@@ -36,15 +36,15 @@ export const queryFollows = async (
|
|
|
36
36
|
ingestInCache(payload as Amity.FollowersPayload, { cachedAt });
|
|
37
37
|
|
|
38
38
|
const cacheKey = [
|
|
39
|
-
|
|
39
|
+
'follow',
|
|
40
40
|
'query',
|
|
41
|
-
{ ...params, userId, options: { ...page } } as Amity.Serializable,
|
|
41
|
+
{ ...params, userId, options: { ...page }, type: key } as Amity.Serializable,
|
|
42
42
|
];
|
|
43
43
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
44
44
|
}
|
|
45
45
|
|
|
46
|
-
const nextPage =
|
|
47
|
-
const prevPage =
|
|
46
|
+
const nextPage = toPageRaw(paging.next);
|
|
47
|
+
const prevPage = toPageRaw(paging.previous);
|
|
48
48
|
|
|
49
49
|
return { data: follows, cachedAt, prevPage, nextPage };
|
|
50
50
|
};
|
|
@@ -52,7 +52,7 @@ export const queryFollows = async (
|
|
|
52
52
|
queryFollows.locally = (
|
|
53
53
|
key: Parameters<typeof queryFollows>[0],
|
|
54
54
|
query: Parameters<typeof queryFollows>[1],
|
|
55
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined => {
|
|
55
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined => {
|
|
56
56
|
const client = getActiveClient();
|
|
57
57
|
client.log(`follow/queryF${key.substring(1)}.locally`, query);
|
|
58
58
|
|
|
@@ -60,7 +60,11 @@ queryFollows.locally = (
|
|
|
60
60
|
|
|
61
61
|
const { page, ...params } = query;
|
|
62
62
|
|
|
63
|
-
const queryKey = [
|
|
63
|
+
const queryKey = [
|
|
64
|
+
'follow',
|
|
65
|
+
'query',
|
|
66
|
+
{ ...params, options: { ...page }, type: key } as Amity.Serializable,
|
|
67
|
+
];
|
|
64
68
|
const { data, cachedAt } =
|
|
65
69
|
pullFromCache<{ follows: string[] } & Amity.Pagination>(queryKey) ?? {};
|
|
66
70
|
|
|
@@ -73,8 +77,8 @@ queryFollows.locally = (
|
|
|
73
77
|
.filter(Boolean)
|
|
74
78
|
.map(({ data }) => data);
|
|
75
79
|
|
|
76
|
-
const prevPage =
|
|
77
|
-
const nextPage =
|
|
80
|
+
const prevPage = toPageRaw(data?.paging.previous);
|
|
81
|
+
const nextPage = toPageRaw(data?.paging.next);
|
|
78
82
|
|
|
79
83
|
return follows.length === data?.follows?.length
|
|
80
84
|
? { data: follows, cachedAt, prevPage, nextPage }
|
|
@@ -9,11 +9,11 @@ export const createFollowEventSubscriber = (
|
|
|
9
9
|
) => {
|
|
10
10
|
const client = getActiveClient();
|
|
11
11
|
|
|
12
|
-
const filter = (payload: Amity.
|
|
12
|
+
const filter = (payload: Amity.FollowersPayload | Amity.FollowStatusPayload) => {
|
|
13
13
|
if (!client.cache) {
|
|
14
|
-
callback(payload);
|
|
14
|
+
callback(payload.follows[0]);
|
|
15
15
|
} else {
|
|
16
|
-
ingestInCache(
|
|
16
|
+
ingestInCache(payload);
|
|
17
17
|
|
|
18
18
|
const queries = [
|
|
19
19
|
...(queryCache(['followers', 'query']) ?? []),
|
|
@@ -21,11 +21,14 @@ export const createFollowEventSubscriber = (
|
|
|
21
21
|
];
|
|
22
22
|
|
|
23
23
|
queries
|
|
24
|
-
|
|
25
|
-
|
|
24
|
+
.filter(
|
|
25
|
+
({ key }) =>
|
|
26
|
+
// @ts-ignore
|
|
27
|
+
key[2].userId === payload.follows[0].from || key[2].userId === payload.follows[0].to,
|
|
28
|
+
)
|
|
26
29
|
.forEach(({ key, data }) => upsertInCache(key, data as any, { cachedAt: -1 }));
|
|
27
30
|
|
|
28
|
-
callback(payload);
|
|
31
|
+
callback(payload.follows[0]);
|
|
29
32
|
}
|
|
30
33
|
};
|
|
31
34
|
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { getActiveClient } from '~/client/api';
|
|
4
|
+
import { pushToCache, pullFromCache } from '~/cache/api';
|
|
5
|
+
import { createQuery, runQuery, queryOptions, filterByPropEquality } from '~/core/query';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
9
|
+
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
10
|
+
} from '~/utils/constants';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
onFollowerRequested,
|
|
14
|
+
onFollowRequestAccepted,
|
|
15
|
+
onFollowRequestDeclined,
|
|
16
|
+
onFollowRequestCanceled,
|
|
17
|
+
onUserFollowed,
|
|
18
|
+
onUserUnfollowed,
|
|
19
|
+
onFollowerDeleted,
|
|
20
|
+
} from '../events';
|
|
21
|
+
import { queryFollowers } from '../api';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ```js
|
|
25
|
+
* import { liveFollowers } from '@amityco/ts-sdk'
|
|
26
|
+
*
|
|
27
|
+
* let followers = []
|
|
28
|
+
* const unsub = liveFollowers({
|
|
29
|
+
* userId: Amity.User['userId'];
|
|
30
|
+
* }, response => merge(followers, response.data))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
|
|
34
|
+
*
|
|
35
|
+
* @param userId the user
|
|
36
|
+
* @param callback the function to call when new data are available
|
|
37
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
38
|
+
*
|
|
39
|
+
* @category Followers Live Collection
|
|
40
|
+
*/
|
|
41
|
+
export const liveFollowers = (
|
|
42
|
+
params: Amity.FollowerLiveCollection,
|
|
43
|
+
callback: Amity.LiveCollectionCallback<Amity.FollowStatus>,
|
|
44
|
+
config?: Amity.LiveCollectionConfig,
|
|
45
|
+
): Amity.Unsubscriber => {
|
|
46
|
+
const { log, cache } = getActiveClient();
|
|
47
|
+
|
|
48
|
+
if (!cache) {
|
|
49
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const timestamp = Date.now();
|
|
53
|
+
log(`liveFollowers(tmpid: ${timestamp}) > listen`);
|
|
54
|
+
|
|
55
|
+
const { limit: queryLimit, ...queryParams } = params;
|
|
56
|
+
|
|
57
|
+
const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
58
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
59
|
+
|
|
60
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
61
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
62
|
+
|
|
63
|
+
const responder = (data: Amity.FollowerLiveCollectionCache) => {
|
|
64
|
+
let followers: Amity.FollowStatus[] =
|
|
65
|
+
data.data
|
|
66
|
+
.map(key => pullFromCache<Amity.FollowStatus>(['follow', 'get', key])!)
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.map(({ data }) => data) ?? [];
|
|
69
|
+
|
|
70
|
+
if (params.status) {
|
|
71
|
+
followers = filterByPropEquality(followers, 'status', params.status);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
callback({
|
|
75
|
+
onNextPage: onFetch,
|
|
76
|
+
data: followers,
|
|
77
|
+
hasNextPage: !!data.params?.page,
|
|
78
|
+
loading: data.loading,
|
|
79
|
+
error: data.error,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const realtimeRouter = (followStatus: Amity.FollowStatus, action: Amity.FollowActionType) => {
|
|
84
|
+
const collection = pullFromCache<Amity.FollowerLiveCollectionCache>(cacheKey)?.data;
|
|
85
|
+
|
|
86
|
+
if (params.userId !== followStatus.to || !collection) return;
|
|
87
|
+
|
|
88
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
89
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
90
|
+
} else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
91
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pushToCache(cacheKey, collection);
|
|
95
|
+
|
|
96
|
+
responder(collection);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const onFetch = () => {
|
|
100
|
+
const collection = pullFromCache<Amity.FollowerLiveCollectionCache>(cacheKey)?.data;
|
|
101
|
+
|
|
102
|
+
const followers = collection?.data ?? [];
|
|
103
|
+
|
|
104
|
+
if (followers.length > 0 && !collection?.params?.page) return;
|
|
105
|
+
|
|
106
|
+
const query = createQuery(queryFollowers, {
|
|
107
|
+
...queryParams,
|
|
108
|
+
page: collection?.params?.page ?? { limit },
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
runQuery(
|
|
112
|
+
query,
|
|
113
|
+
({ data: result, error, loading, nextPage: page }) => {
|
|
114
|
+
const data = {
|
|
115
|
+
loading,
|
|
116
|
+
error,
|
|
117
|
+
params: { page },
|
|
118
|
+
data: followers,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (result) {
|
|
122
|
+
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
pushToCache(cacheKey, data);
|
|
126
|
+
|
|
127
|
+
responder(data);
|
|
128
|
+
},
|
|
129
|
+
queryOptions(policy),
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
disposers.push(
|
|
134
|
+
onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')),
|
|
135
|
+
onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')),
|
|
136
|
+
onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')),
|
|
137
|
+
onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')),
|
|
138
|
+
onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')),
|
|
139
|
+
onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')),
|
|
140
|
+
onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
onFetch();
|
|
144
|
+
|
|
145
|
+
return () => {
|
|
146
|
+
log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
|
|
147
|
+
disposers.forEach(fn => fn());
|
|
148
|
+
};
|
|
149
|
+
};
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
/* eslint-disable no-use-before-define */
|
|
2
|
+
import { getResolver } from '~/core/model';
|
|
3
|
+
import { getActiveClient } from '~/client/api';
|
|
4
|
+
import { pushToCache, pullFromCache } from '~/cache/api';
|
|
5
|
+
import { createQuery, runQuery, queryOptions, filterByPropEquality } from '~/core/query';
|
|
6
|
+
|
|
7
|
+
import {
|
|
8
|
+
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
9
|
+
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
10
|
+
} from '~/utils/constants';
|
|
11
|
+
|
|
12
|
+
import {
|
|
13
|
+
onFollowerRequested,
|
|
14
|
+
onFollowRequestAccepted,
|
|
15
|
+
onFollowRequestDeclined,
|
|
16
|
+
onFollowRequestCanceled,
|
|
17
|
+
onUserFollowed,
|
|
18
|
+
onUserUnfollowed,
|
|
19
|
+
onFollowerDeleted,
|
|
20
|
+
} from '../events';
|
|
21
|
+
import { queryFollowings } from '../api';
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* ```js
|
|
25
|
+
* import { liveFollowings } from '@amityco/ts-sdk'
|
|
26
|
+
*
|
|
27
|
+
* let followings = []
|
|
28
|
+
* const unsub = liveFollowings({
|
|
29
|
+
* userId: Amity.User['userId'];
|
|
30
|
+
* }, response => merge(followings, response.data))
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
|
|
34
|
+
*
|
|
35
|
+
* @param userId the user
|
|
36
|
+
* @param callback the function to call when new data are available
|
|
37
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
38
|
+
*
|
|
39
|
+
* @category Followings Live Collection
|
|
40
|
+
*/
|
|
41
|
+
export const liveFollowings = (
|
|
42
|
+
params: Amity.FollowingLiveCollection,
|
|
43
|
+
callback: Amity.LiveCollectionCallback<Amity.FollowStatus>,
|
|
44
|
+
config?: Amity.LiveCollectionConfig,
|
|
45
|
+
): Amity.Unsubscriber => {
|
|
46
|
+
const { log, cache } = getActiveClient();
|
|
47
|
+
|
|
48
|
+
if (!cache) {
|
|
49
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const timestamp = Date.now();
|
|
53
|
+
log(`liveFollowings(tmpid: ${timestamp}) > listen`);
|
|
54
|
+
|
|
55
|
+
const { limit: queryLimit, ...queryParams } = params;
|
|
56
|
+
|
|
57
|
+
const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
58
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
59
|
+
|
|
60
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
61
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
62
|
+
|
|
63
|
+
const responder = (data: Amity.FollowingLiveCollectionCache) => {
|
|
64
|
+
let followings: Amity.FollowStatus[] =
|
|
65
|
+
data.data
|
|
66
|
+
.map(key => pullFromCache<Amity.FollowStatus>(['follow', 'get', key])!)
|
|
67
|
+
.filter(Boolean)
|
|
68
|
+
.map(({ data }) => data) ?? [];
|
|
69
|
+
|
|
70
|
+
if (params.status) {
|
|
71
|
+
followings = filterByPropEquality(followings, 'status', params.status);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
callback({
|
|
75
|
+
onNextPage: onFetch,
|
|
76
|
+
data: followings,
|
|
77
|
+
hasNextPage: !!data.params?.page,
|
|
78
|
+
loading: data.loading,
|
|
79
|
+
error: data.error,
|
|
80
|
+
});
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const realtimeRouter = (followStatus: Amity.FollowStatus, action: Amity.FollowActionType) => {
|
|
84
|
+
const collection = pullFromCache<Amity.FollowingLiveCollectionCache>(cacheKey)?.data;
|
|
85
|
+
|
|
86
|
+
if (params.userId !== followStatus.from || !collection) return;
|
|
87
|
+
|
|
88
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
89
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
90
|
+
} else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
91
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
pushToCache(cacheKey, collection);
|
|
95
|
+
|
|
96
|
+
responder(collection);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
const onFetch = () => {
|
|
100
|
+
const collection = pullFromCache<Amity.FollowingLiveCollectionCache>(cacheKey)?.data;
|
|
101
|
+
|
|
102
|
+
const followings = collection?.data ?? [];
|
|
103
|
+
|
|
104
|
+
if (followings.length > 0 && !collection?.params?.page) return;
|
|
105
|
+
|
|
106
|
+
const query = createQuery(queryFollowings, {
|
|
107
|
+
...queryParams,
|
|
108
|
+
page: collection?.params?.page ?? { limit },
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
runQuery(
|
|
112
|
+
query,
|
|
113
|
+
({ data: result, error, loading, nextPage: page }) => {
|
|
114
|
+
const data = {
|
|
115
|
+
loading,
|
|
116
|
+
error,
|
|
117
|
+
params: { page },
|
|
118
|
+
data: followings,
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
if (result) {
|
|
122
|
+
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
pushToCache(cacheKey, data);
|
|
126
|
+
|
|
127
|
+
responder(data);
|
|
128
|
+
},
|
|
129
|
+
queryOptions(policy),
|
|
130
|
+
);
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
disposers.push(
|
|
134
|
+
onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')),
|
|
135
|
+
onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')),
|
|
136
|
+
onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')),
|
|
137
|
+
onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')),
|
|
138
|
+
onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')),
|
|
139
|
+
onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')),
|
|
140
|
+
onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
onFetch();
|
|
144
|
+
|
|
145
|
+
return () => {
|
|
146
|
+
log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
|
|
147
|
+
disposers.forEach(fn => fn());
|
|
148
|
+
};
|
|
149
|
+
};
|
package/src/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
// types
|
|
2
|
-
|
|
2
|
+
export * from './@types';
|
|
3
3
|
|
|
4
4
|
export * from './version';
|
|
5
5
|
|
|
@@ -25,6 +25,7 @@ export * from './role/api';
|
|
|
25
25
|
// // asc partials
|
|
26
26
|
export * from './reaction/api';
|
|
27
27
|
export * from './reaction/events';
|
|
28
|
+
export * from './reaction/observers';
|
|
28
29
|
|
|
29
30
|
export * from './report/api';
|
|
30
31
|
|
|
@@ -19,16 +19,9 @@ import { getResolver } from '~/core/model';
|
|
|
19
19
|
* @category Message API
|
|
20
20
|
* @async
|
|
21
21
|
*/
|
|
22
|
-
export const queryMessages = async (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
parentId?: Amity.Message['parentId'];
|
|
26
|
-
filterByParentId?: boolean;
|
|
27
|
-
isDeleted?: boolean;
|
|
28
|
-
tags?: Amity.Taggable['tags'];
|
|
29
|
-
excludeTags?: Amity.Taggable['tags'];
|
|
30
|
-
page?: Amity.Page;
|
|
31
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.Message>>> => {
|
|
22
|
+
export const queryMessages = async (
|
|
23
|
+
query: Amity.QueryMessages,
|
|
24
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.Message>>> => {
|
|
32
25
|
const client = getActiveClient();
|
|
33
26
|
client.log('message/queryMessages', query);
|
|
34
27
|
|