@amityco/ts-sdk 0.0.1-beta.24 → 0.0.1-beta.27
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 +4 -1
- package/dist/@types/core/events.d.ts +12 -8
- 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 +3 -5
- package/dist/@types/core/payload.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/follow.d.ts +2 -1
- package/dist/@types/domains/follow.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/index.d.ts +1 -0
- 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/banChannelMembers.d.ts +16 -0
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -0
- package/dist/channel/api/index.d.ts +2 -0
- package/dist/channel/api/index.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/unbanChannelMembers.d.ts +16 -0
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +1 -1
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +1 -1
- package/dist/client/api/createClient.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 +1 -1
- 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.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/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 +4 -4
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +4 -4
- 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/index.cjs.js +18341 -17625
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +18329 -17626
- package/dist/index.umd.js +4 -19
- package/dist/poll/api/closePoll.d.ts.map +1 -1
- package/dist/poll/api/deletePoll.d.ts.map +1 -1
- package/dist/poll/api/votePoll.d.ts.map +1 -1
- package/dist/poll/events/index.d.ts +3 -0
- package/dist/poll/events/index.d.ts.map +1 -0
- package/dist/poll/events/onPollDeleted.d.ts +17 -0
- package/dist/poll/events/onPollDeleted.d.ts.map +1 -0
- package/dist/poll/events/onPollUpdated.d.ts +17 -0
- package/dist/poll/events/onPollUpdated.d.ts.map +1 -0
- package/dist/poll/observers/index.d.ts +2 -0
- package/dist/poll/observers/index.d.ts.map +1 -0
- package/dist/poll/observers/observePoll.d.ts +18 -0
- package/dist/poll/observers/observePoll.d.ts.map +1 -0
- package/dist/post/api/approvePost.d.ts +17 -0
- package/dist/post/api/approvePost.d.ts.map +1 -0
- package/dist/post/api/declinePost.d.ts +17 -0
- package/dist/post/api/declinePost.d.ts.map +1 -0
- package/dist/post/api/index.d.ts +2 -0
- package/dist/post/api/index.d.ts.map +1 -1
- 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/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- 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 +3 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/tests/client.d.ts +3 -0
- package/dist/utils/tests/client.d.ts.map +1 -0
- package/dist/utils/tests/dummy.d.ts +8 -0
- package/dist/utils/tests/dummy.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 +13 -8
- package/src/@types/core/live.ts +28 -0
- package/src/@types/core/paging.ts +1 -1
- package/src/@types/core/payload.ts +5 -6
- package/src/@types/domains/comment.ts +31 -0
- package/src/@types/domains/follow.ts +3 -1
- package/src/@types/domains/post.ts +37 -0
- package/src/@types/domains/reaction.ts +17 -0
- package/src/@types/index.ts +1 -0
- package/src/channel/api/banChannelMembers.ts +41 -0
- package/src/channel/api/index.ts +3 -0
- package/src/channel/api/unbanChannelMembers.ts +41 -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/query/query.ts +15 -2
- package/src/core/tests/query/filtering.test.ts +11 -0
- package/src/core/tests/query/query.test.ts +19 -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 -4
- package/src/follow/api/queryFollowings.ts +5 -4
- package/src/follow/api/unfollow.ts +1 -1
- package/src/follow/api/utils.ts +10 -10
- package/src/follow/events/utils.ts +9 -6
- package/src/index.ts +3 -0
- package/src/poll/api/closePoll.ts +3 -0
- package/src/poll/api/deletePoll.ts +3 -0
- package/src/poll/api/votePoll.ts +3 -0
- package/src/poll/events/index.ts +2 -0
- package/src/poll/events/onPollDeleted.ts +31 -0
- package/src/poll/events/onPollUpdated.ts +31 -0
- package/src/poll/observers/index.ts +1 -0
- package/src/poll/observers/observePoll.ts +67 -0
- package/src/post/api/approvePost.ts +48 -0
- package/src/post/api/declinePost.ts +48 -0
- package/src/post/api/index.ts +3 -0
- package/src/post/api/queryPosts.ts +3 -12
- package/src/post/observers/index.ts +1 -0
- package/src/post/observers/livePosts.ts +170 -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/report/api/createReport.ts +7 -1
- package/src/report/api/deleteReport.ts +7 -1
- package/src/utils/constants.ts +2 -0
- package/src/utils/tests/client.ts +5 -0
- package/src/utils/tests/dummy.ts +7 -0
- package/src/utils/tests/index.ts +2 -0
- package/tsconfig.json +23 -22
|
@@ -112,17 +112,16 @@ declare global {
|
|
|
112
112
|
|
|
113
113
|
type GlobalFeedPayload = Amity.PostPayload;
|
|
114
114
|
|
|
115
|
-
type FollowersPayload = {
|
|
116
|
-
follows: Amity.FollowStatus[];
|
|
117
|
-
} & UserPayload;
|
|
118
|
-
|
|
119
115
|
type FollowStatusPayload = {
|
|
120
116
|
follows: Amity.FollowStatus[];
|
|
121
117
|
};
|
|
122
118
|
|
|
123
|
-
type
|
|
124
|
-
follows: Amity.FollowStatus[];
|
|
119
|
+
type FollowInfoMePayload = {
|
|
125
120
|
followCounts: Amity.FollowCount[];
|
|
126
121
|
};
|
|
122
|
+
|
|
123
|
+
type FollowersPayload = Amity.FollowStatusPayload & UserPayload;
|
|
124
|
+
|
|
125
|
+
type FollowInfoPayload = FollowInfoMePayload & Amity.FollowStatusPayload;
|
|
127
126
|
}
|
|
128
127
|
}
|
|
@@ -5,6 +5,16 @@ declare global {
|
|
|
5
5
|
type CommentContentType = 'text';
|
|
6
6
|
type CommentReferenceType = 'content' | 'post';
|
|
7
7
|
|
|
8
|
+
type CommentActionType =
|
|
9
|
+
| 'onFetch'
|
|
10
|
+
| 'onCreate'
|
|
11
|
+
| 'onUpdate'
|
|
12
|
+
| 'onDelete'
|
|
13
|
+
| 'onFlagged'
|
|
14
|
+
| 'onUnflagged'
|
|
15
|
+
| 'onReactionAdded'
|
|
16
|
+
| 'onReactionRemoved';
|
|
17
|
+
|
|
8
18
|
type Comment<T extends CommentContentType = any> = {
|
|
9
19
|
commentId: string;
|
|
10
20
|
userId: string;
|
|
@@ -23,5 +33,26 @@ declare global {
|
|
|
23
33
|
Amity.SoftDelete &
|
|
24
34
|
Amity.Subscribable &
|
|
25
35
|
Amity.Mentionable<'user'>;
|
|
36
|
+
|
|
37
|
+
type QueryComments = {
|
|
38
|
+
referenceType: Amity.Comment['referenceType'];
|
|
39
|
+
referenceId: Amity.Comment['referenceId'];
|
|
40
|
+
sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated';
|
|
41
|
+
parentId?: Amity.Comment['commentId'] | null;
|
|
42
|
+
hasFlag?: boolean;
|
|
43
|
+
isDeleted?: Amity.Comment['isDeleted'];
|
|
44
|
+
page?: Amity.Page;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
type CommentLiveCollection = Amity.LiveCollectionParams<
|
|
48
|
+
Omit<QueryComments, 'sortBy' | 'page'> & {
|
|
49
|
+
sortBy?: 'lastCreated' | 'firstCreated';
|
|
50
|
+
}
|
|
51
|
+
>;
|
|
52
|
+
|
|
53
|
+
type CommentLiveCollectionCache = Amity.LiveCollectionCache<
|
|
54
|
+
Amity.Comment['commentId'],
|
|
55
|
+
Pick<QueryComments, 'page'>
|
|
56
|
+
>;
|
|
26
57
|
}
|
|
27
58
|
}
|
|
@@ -2,10 +2,12 @@ export {};
|
|
|
2
2
|
|
|
3
3
|
declare global {
|
|
4
4
|
namespace Amity {
|
|
5
|
+
type FollowStatusType = 'all' | 'pending' | 'accepted' | 'none';
|
|
6
|
+
|
|
5
7
|
type FollowStatus = {
|
|
6
8
|
from: Amity.User['userId'];
|
|
7
9
|
to: Amity.User['userId'];
|
|
8
|
-
status:
|
|
10
|
+
status: Exclude<FollowStatusType, 'all'>;
|
|
9
11
|
} & Amity.CreatedAt &
|
|
10
12
|
Amity.UpdatedAt;
|
|
11
13
|
|
|
@@ -7,6 +7,18 @@ declare global {
|
|
|
7
7
|
|
|
8
8
|
type PostContentType = 'text' | 'image' | 'file' | 'video' | 'liveStream' | 'poll';
|
|
9
9
|
|
|
10
|
+
type PostActionType =
|
|
11
|
+
| 'onFetch'
|
|
12
|
+
| 'onCreate'
|
|
13
|
+
| 'onUpdate'
|
|
14
|
+
| 'onDelete'
|
|
15
|
+
| 'onApproved'
|
|
16
|
+
| 'onDeclined'
|
|
17
|
+
| 'onFlagged'
|
|
18
|
+
| 'onUnflagged'
|
|
19
|
+
| 'onReactionAdded'
|
|
20
|
+
| 'onReactionRemoved';
|
|
21
|
+
|
|
10
22
|
type Post<T extends PostContentType = any> = {
|
|
11
23
|
postId: string;
|
|
12
24
|
postedUserId: Amity.User['userId']; // API-FIX: it should be "userId"
|
|
@@ -29,5 +41,30 @@ declare global {
|
|
|
29
41
|
Amity.SoftDelete &
|
|
30
42
|
Amity.Subscribable &
|
|
31
43
|
Amity.Mentionable<'user'>;
|
|
44
|
+
|
|
45
|
+
type QueryPosts = {
|
|
46
|
+
targetId: string;
|
|
47
|
+
targetType: Amity.Post['targetType'];
|
|
48
|
+
sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated';
|
|
49
|
+
dataType?: string;
|
|
50
|
+
isDeleted?: Amity.Post['isDeleted'];
|
|
51
|
+
hasFlag?: boolean;
|
|
52
|
+
feedType?: 'reviewing' | 'published';
|
|
53
|
+
tags?: Amity.Taggable['tags'];
|
|
54
|
+
matchingOnlyParentPost?: boolean;
|
|
55
|
+
page?: Amity.PageRaw;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
// Omit sortBy explained in asc-3398
|
|
59
|
+
type PostLiveCollection = Amity.LiveCollectionParams<
|
|
60
|
+
Omit<QueryPosts, 'sortBy' | 'page'> & {
|
|
61
|
+
sortBy?: 'lastCreated' | 'firstCreated';
|
|
62
|
+
}
|
|
63
|
+
>;
|
|
64
|
+
|
|
65
|
+
type PostLiveCollectionCache = Amity.LiveCollectionCache<
|
|
66
|
+
Amity.Post['postId'],
|
|
67
|
+
Pick<QueryPosts, 'page'>
|
|
68
|
+
>;
|
|
32
69
|
}
|
|
33
70
|
}
|
|
@@ -4,6 +4,8 @@ declare global {
|
|
|
4
4
|
namespace Amity {
|
|
5
5
|
type ReactableType = 'message' | 'post' | 'comment';
|
|
6
6
|
|
|
7
|
+
type ReactionActionType = 'onAdded' | 'onRemoved';
|
|
8
|
+
|
|
7
9
|
type Reactor = {
|
|
8
10
|
reactionId: string;
|
|
9
11
|
reactionName: string;
|
|
@@ -19,11 +21,26 @@ declare global {
|
|
|
19
21
|
|
|
20
22
|
latestReaction?: Amity.Reaction & {
|
|
21
23
|
eventName: 'add' | 'remove';
|
|
24
|
+
userDisplayName: string;
|
|
22
25
|
};
|
|
23
26
|
};
|
|
24
27
|
|
|
25
28
|
type ReactionQuery = {
|
|
26
29
|
reactors: Reactor[];
|
|
27
30
|
} & Amity.Relationship<ReactableType>;
|
|
31
|
+
|
|
32
|
+
type QueryReactions = {
|
|
33
|
+
referenceId: Amity.Reaction['referenceId'];
|
|
34
|
+
referenceType: Amity.Reaction['referenceType'];
|
|
35
|
+
reactionName?: Amity.Reaction['reactionName'];
|
|
36
|
+
page?: Amity.Page<string>;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
type ReactionLiveCollection = Amity.LiveCollectionParams<Omit<QueryReactions, 'page'>>;
|
|
40
|
+
|
|
41
|
+
type ReactionLiveCollectionCache = Amity.LiveCollectionCache<
|
|
42
|
+
Amity.Reactor['reactionId'],
|
|
43
|
+
Pick<QueryReactions, 'page'>
|
|
44
|
+
>;
|
|
28
45
|
}
|
|
29
46
|
}
|
package/src/@types/index.ts
CHANGED
|
@@ -8,6 +8,7 @@ import './core/events'; // sdk events definitions
|
|
|
8
8
|
import './core/paging'; // createQuery, runQuery
|
|
9
9
|
import './core/query'; // createQuery, runQuery
|
|
10
10
|
import './core/cache'; // cache.pull('user', ...)
|
|
11
|
+
import './core/live';
|
|
11
12
|
|
|
12
13
|
// domains
|
|
13
14
|
import './domains/client'; // client definition
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { banChannelMembers } from '@amityco/ts-sdk'
|
|
8
|
+
*
|
|
9
|
+
* await banChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param channelId of {@link Amity.Channel} from which the users should be banned
|
|
13
|
+
* @param userIds of the {@link Amity.User}'s to be banned
|
|
14
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
15
|
+
*
|
|
16
|
+
* @category Channel API
|
|
17
|
+
* @async
|
|
18
|
+
* */
|
|
19
|
+
export const banChannelMembers = async (
|
|
20
|
+
channelId: Amity.Channel['channelId'],
|
|
21
|
+
userIds: Amity.User['userId'][],
|
|
22
|
+
): Promise<Amity.Cached<Amity.Membership<'channel'>[]>> => {
|
|
23
|
+
const client = getActiveClient();
|
|
24
|
+
client.log('channel/banChannelMembers', { userIds, channelId });
|
|
25
|
+
|
|
26
|
+
const payload = await client.http.put<Amity.ChannelPayload>(
|
|
27
|
+
`/api/v3/channels/${channelId}/users/ban`,
|
|
28
|
+
{
|
|
29
|
+
userIds,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const cachedAt = client.cache && Date.now();
|
|
34
|
+
if (client.cache) ingestInCache(payload.data, { cachedAt });
|
|
35
|
+
|
|
36
|
+
const { channelUsers } = payload.data;
|
|
37
|
+
return {
|
|
38
|
+
data: channelUsers?.filter(user => user.membership === 'banned')!,
|
|
39
|
+
cachedAt,
|
|
40
|
+
};
|
|
41
|
+
};
|
package/src/channel/api/index.ts
CHANGED
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
|
+
|
|
3
|
+
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* ```js
|
|
7
|
+
* import { unbanChannelMembers } from '@amityco/ts-sdk'
|
|
8
|
+
*
|
|
9
|
+
* await unbanChannelMembers('channel-id-1', ['userId1', 'userId2'])
|
|
10
|
+
* ```
|
|
11
|
+
*
|
|
12
|
+
* @param channelId of {@link Amity.Channel} where the users should be unbanned
|
|
13
|
+
* @param userIds of the {@link Amity.User}'s to be unbanned
|
|
14
|
+
* @returns the updated {@link Amity.Membership}'s object
|
|
15
|
+
*
|
|
16
|
+
* @category Channel API
|
|
17
|
+
* @async
|
|
18
|
+
* */
|
|
19
|
+
export const unbanChannelMembers = async (
|
|
20
|
+
channelId: Amity.Channel['channelId'],
|
|
21
|
+
userIds: Amity.User['userId'][],
|
|
22
|
+
): Promise<Amity.Cached<Amity.Membership<'channel'>[]>> => {
|
|
23
|
+
const client = getActiveClient();
|
|
24
|
+
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
25
|
+
|
|
26
|
+
const payload = await client.http.put<Amity.ChannelPayload>(
|
|
27
|
+
`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`,
|
|
28
|
+
{
|
|
29
|
+
userIds,
|
|
30
|
+
},
|
|
31
|
+
);
|
|
32
|
+
|
|
33
|
+
const cachedAt = client.cache && Date.now();
|
|
34
|
+
if (client.cache) ingestInCache(payload.data, { cachedAt });
|
|
35
|
+
|
|
36
|
+
const { channelUsers } = payload.data;
|
|
37
|
+
return {
|
|
38
|
+
data: channelUsers?.filter(user => user.membership === 'member')!,
|
|
39
|
+
cachedAt,
|
|
40
|
+
};
|
|
41
|
+
};
|
|
@@ -19,15 +19,9 @@ import { getResolver } from '~/core/model';
|
|
|
19
19
|
* @category Comment API
|
|
20
20
|
* @async
|
|
21
21
|
*/
|
|
22
|
-
export const queryComments = async (
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
sortBy?: 'lastCreated' | 'firstCreated' | 'lastUpdated' | 'firstUpdated';
|
|
26
|
-
parentId?: Amity.Comment['commentId'] | null;
|
|
27
|
-
hasFlag?: boolean;
|
|
28
|
-
isDeleted?: Amity.Comment['isDeleted'];
|
|
29
|
-
page?: Amity.Page;
|
|
30
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.Comment>>> => {
|
|
22
|
+
export const queryComments = async (
|
|
23
|
+
query: Amity.QueryComments,
|
|
24
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.Comment>>> => {
|
|
31
25
|
const client = getActiveClient();
|
|
32
26
|
client.log('comment/queryComments', query);
|
|
33
27
|
|
|
@@ -0,0 +1,172 @@
|
|
|
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 {
|
|
6
|
+
createQuery,
|
|
7
|
+
runQuery,
|
|
8
|
+
queryOptions,
|
|
9
|
+
filterByPropEquality,
|
|
10
|
+
sortByFirstCreated,
|
|
11
|
+
sortByLastCreated,
|
|
12
|
+
} from '~/core/query';
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
COLLECTION_DEFAULT_CACHING_POLICY,
|
|
16
|
+
COLLECTION_DEFAULT_PAGINATION_LIMIT,
|
|
17
|
+
} from '~/utils/constants';
|
|
18
|
+
|
|
19
|
+
import {
|
|
20
|
+
onCommentCreated,
|
|
21
|
+
onCommentUpdated,
|
|
22
|
+
onCommentDeleted,
|
|
23
|
+
onCommentFlagged,
|
|
24
|
+
onCommentUnflagged,
|
|
25
|
+
onCommentReactionAdded,
|
|
26
|
+
onCommentReactionRemoved,
|
|
27
|
+
} from '../events';
|
|
28
|
+
import { queryComments } from '../api';
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* ```js
|
|
32
|
+
* import { liveComments } from '@amityco/ts-sdk'
|
|
33
|
+
*
|
|
34
|
+
* let comments = []
|
|
35
|
+
* const unsub = liveComments({
|
|
36
|
+
* referenceType: Amity.Comment['referenceType'];
|
|
37
|
+
* referenceId: Amity.Comment['referenceId'];
|
|
38
|
+
* }, response => merge(comments, response.data))
|
|
39
|
+
* ```
|
|
40
|
+
*
|
|
41
|
+
* Observe all mutations on a list of {@link Amity.Comment} for a given target object
|
|
42
|
+
*
|
|
43
|
+
* @param referenceType the type of the target
|
|
44
|
+
* @param referenceId the ID of the target
|
|
45
|
+
* @param callback the function to call when new data are available
|
|
46
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
47
|
+
*
|
|
48
|
+
* @category Comments Live Collection
|
|
49
|
+
*/
|
|
50
|
+
export const liveComments = (
|
|
51
|
+
params: Amity.CommentLiveCollection,
|
|
52
|
+
callback: Amity.LiveCollectionCallback<Amity.Comment>,
|
|
53
|
+
config?: Amity.LiveCollectionConfig,
|
|
54
|
+
): Amity.Unsubscriber => {
|
|
55
|
+
const { log, cache } = getActiveClient();
|
|
56
|
+
|
|
57
|
+
if (!cache) {
|
|
58
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
const timestamp = Date.now();
|
|
62
|
+
log(`liveComments(tmpid: ${timestamp}) > listen`);
|
|
63
|
+
|
|
64
|
+
const { limit: queryLimit, ...queryParams } = params;
|
|
65
|
+
|
|
66
|
+
const limit = queryLimit ?? COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
67
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config ?? {};
|
|
68
|
+
|
|
69
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
70
|
+
const cacheKey = [
|
|
71
|
+
'comment',
|
|
72
|
+
'collection',
|
|
73
|
+
{ referenceId: params.referenceType, referenceType: params.referenceId },
|
|
74
|
+
];
|
|
75
|
+
|
|
76
|
+
const responder = (data: Amity.CommentLiveCollectionCache) => {
|
|
77
|
+
let comments: Amity.Comment[] =
|
|
78
|
+
data.data
|
|
79
|
+
.map(commentId => pullFromCache<Amity.Comment>(['comment', 'get', commentId])!)
|
|
80
|
+
.filter(Boolean)
|
|
81
|
+
.map(({ data }) => data) ?? [];
|
|
82
|
+
|
|
83
|
+
comments = filterByPropEquality(comments, 'isDeleted', params.isDeleted);
|
|
84
|
+
|
|
85
|
+
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
86
|
+
|
|
87
|
+
comments = comments.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
88
|
+
|
|
89
|
+
callback({
|
|
90
|
+
onNextPage: onFetch,
|
|
91
|
+
data: comments,
|
|
92
|
+
hasNextPage: !!data.params?.page,
|
|
93
|
+
loading: data.loading,
|
|
94
|
+
error: data.error,
|
|
95
|
+
});
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
const realtimeRouter = (comment: Amity.Comment, action: Amity.CommentActionType) => {
|
|
99
|
+
const collection = pullFromCache<Amity.CommentLiveCollectionCache>(cacheKey)?.data;
|
|
100
|
+
|
|
101
|
+
if (
|
|
102
|
+
params.referenceId !== comment.referenceId ||
|
|
103
|
+
params.referenceType !== comment.referenceType ||
|
|
104
|
+
!collection
|
|
105
|
+
)
|
|
106
|
+
return;
|
|
107
|
+
|
|
108
|
+
if (action === 'onCreate') {
|
|
109
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
110
|
+
} else if (action === 'onDelete') {
|
|
111
|
+
collection.data = collection.data.filter(p => p !== comment.commentId);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
pushToCache(cacheKey, collection);
|
|
115
|
+
|
|
116
|
+
responder(collection);
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const onFetch = () => {
|
|
120
|
+
const collection = pullFromCache<Amity.CommentLiveCollectionCache>(cacheKey)?.data;
|
|
121
|
+
|
|
122
|
+
const comments = collection?.data ?? [];
|
|
123
|
+
|
|
124
|
+
if (comments.length > 0 && !collection?.params?.page) return;
|
|
125
|
+
|
|
126
|
+
const query = createQuery(queryComments, {
|
|
127
|
+
...queryParams,
|
|
128
|
+
page: collection?.params?.page ?? { limit },
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
runQuery(
|
|
132
|
+
query,
|
|
133
|
+
({ data: result, error, loading, prevPage, nextPage }) => {
|
|
134
|
+
// depend on sortBy value we have two different pagination type
|
|
135
|
+
const page = queryParams.sortBy ? nextPage : prevPage;
|
|
136
|
+
|
|
137
|
+
const data = {
|
|
138
|
+
loading,
|
|
139
|
+
error,
|
|
140
|
+
params: { page },
|
|
141
|
+
data: comments,
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
if (result) {
|
|
145
|
+
data.data = [...new Set([...comments, ...result.map(getResolver('comment'))])];
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
pushToCache(cacheKey, data);
|
|
149
|
+
|
|
150
|
+
responder(data);
|
|
151
|
+
},
|
|
152
|
+
queryOptions(policy),
|
|
153
|
+
);
|
|
154
|
+
};
|
|
155
|
+
|
|
156
|
+
disposers.push(
|
|
157
|
+
onCommentCreated(comment => realtimeRouter(comment, 'onCreate')),
|
|
158
|
+
onCommentUpdated(comment => realtimeRouter(comment, 'onUpdate')),
|
|
159
|
+
onCommentDeleted(comment => realtimeRouter(comment, 'onDelete')),
|
|
160
|
+
onCommentFlagged(comment => realtimeRouter(comment, 'onFlagged')),
|
|
161
|
+
onCommentUnflagged(comment => realtimeRouter(comment, 'onUnflagged')),
|
|
162
|
+
onCommentReactionAdded(comment => realtimeRouter(comment, 'onReactionAdded')),
|
|
163
|
+
onCommentReactionRemoved(comment => realtimeRouter(comment, 'onReactionRemoved')),
|
|
164
|
+
);
|
|
165
|
+
|
|
166
|
+
onFetch();
|
|
167
|
+
|
|
168
|
+
return () => {
|
|
169
|
+
log(`liveComments(tmpid: ${timestamp}) > dispose`);
|
|
170
|
+
disposers.forEach(fn => fn());
|
|
171
|
+
};
|
|
172
|
+
};
|
|
@@ -48,17 +48,7 @@ export const observeComments = (
|
|
|
48
48
|
|
|
49
49
|
const disposers: Amity.Unsubscriber[] = [];
|
|
50
50
|
|
|
51
|
-
const router = (
|
|
52
|
-
comment: Amity.Comment,
|
|
53
|
-
action:
|
|
54
|
-
| 'onCreate'
|
|
55
|
-
| 'onUpdate'
|
|
56
|
-
| 'onDelete'
|
|
57
|
-
| 'onFlagged'
|
|
58
|
-
| 'onUnflagged'
|
|
59
|
-
| 'onReactionAdded'
|
|
60
|
-
| 'onReactionRemoved',
|
|
61
|
-
) => {
|
|
51
|
+
const router = (comment: Amity.Comment, action: Exclude<Amity.CommentActionType, 'onFetch'>) => {
|
|
62
52
|
if (comment.referenceId !== postId) return;
|
|
63
53
|
|
|
64
54
|
if (callback instanceof Function) return callback(comment);
|
package/src/core/query/query.ts
CHANGED
|
@@ -215,8 +215,21 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
215
215
|
if (isMutator(func)) {
|
|
216
216
|
// @ts-ignore
|
|
217
217
|
const modelKey = local && local.data && identifyModelKey(local.data);
|
|
218
|
-
|
|
219
|
-
|
|
218
|
+
if (modelKey) {
|
|
219
|
+
/*
|
|
220
|
+
* modal key is only required for create as update and delete queries pass
|
|
221
|
+
* the modal key in the param itself
|
|
222
|
+
* For update & delete the first argument is always an id which is of type
|
|
223
|
+
* string, whereas for create the first and only argument is the param object
|
|
224
|
+
*
|
|
225
|
+
* When creating an AmityObject optimistically we need to pass the modal key
|
|
226
|
+
* on to the server. ex: for create message modal key will be 'messageId`
|
|
227
|
+
*/
|
|
228
|
+
if (typeof args[0] !== 'string') {
|
|
229
|
+
// @ts-ignore
|
|
230
|
+
optimisticArgs = [{ ...args[0], [modelKey]: local.data[modelKey] }];
|
|
231
|
+
}
|
|
232
|
+
}
|
|
220
233
|
}
|
|
221
234
|
|
|
222
235
|
func(...optimisticArgs)
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { filterByPropEquality } from '~/core/query';
|
|
2
|
+
|
|
3
|
+
describe('Core/Query/Filtering', () => {
|
|
4
|
+
test('check filterByPropEquality', () => {
|
|
5
|
+
const prop = 'prop';
|
|
6
|
+
const collection = [{ [prop]: 'value' }];
|
|
7
|
+
|
|
8
|
+
expect(filterByPropEquality(collection, prop, 'value')).toStrictEqual(collection);
|
|
9
|
+
expect(filterByPropEquality(collection, prop, 'otherValue')).toStrictEqual([]);
|
|
10
|
+
});
|
|
11
|
+
});
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { isFetcher } from '~/core/query';
|
|
2
|
+
|
|
3
|
+
type isFetcherMockType = jest.Mock<any, any> & {
|
|
4
|
+
locally?: jest.Mock<any, any>;
|
|
5
|
+
};
|
|
6
|
+
|
|
7
|
+
describe('Core/Query/Query', () => {
|
|
8
|
+
const isFetcherMock: isFetcherMockType = jest.fn();
|
|
9
|
+
|
|
10
|
+
test('isFetcher without locally', () => {
|
|
11
|
+
expect(isFetcher(isFetcherMock)).toBe(false);
|
|
12
|
+
});
|
|
13
|
+
|
|
14
|
+
test('isFetcher with locally', () => {
|
|
15
|
+
isFetcherMock.locally = jest.fn();
|
|
16
|
+
|
|
17
|
+
expect(isFetcher(isFetcherMock)).toBe(true);
|
|
18
|
+
});
|
|
19
|
+
});
|
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 });
|
|
@@ -16,9 +16,10 @@ import { queryFollows } from './utils';
|
|
|
16
16
|
*/
|
|
17
17
|
export const queryFollowers = async (query: {
|
|
18
18
|
userId: Amity.User['userId'];
|
|
19
|
-
status?:
|
|
20
|
-
page?: Amity.
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> =>
|
|
19
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
20
|
+
page?: Amity.PageRaw;
|
|
21
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
|
+
queryFollows('followers', query);
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* ```js
|
|
@@ -35,5 +36,5 @@ export const queryFollowers = async (query: {
|
|
|
35
36
|
*/
|
|
36
37
|
queryFollowers.locally = (
|
|
37
38
|
query: Parameters<typeof queryFollowers>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
39
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
40
|
queryFollows.locally('followers', query);
|
|
@@ -16,9 +16,10 @@ import { queryFollows } from './utils';
|
|
|
16
16
|
*/
|
|
17
17
|
export const queryFollowings = async (query: {
|
|
18
18
|
userId: Amity.User['userId'];
|
|
19
|
-
status?: Exclude<Amity.
|
|
20
|
-
page?: Amity.
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus>>> =>
|
|
19
|
+
status?: Exclude<Amity.FollowStatusType, 'none'>;
|
|
20
|
+
page?: Amity.PageRaw;
|
|
21
|
+
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
|
+
queryFollows('following', query);
|
|
22
23
|
|
|
23
24
|
/**
|
|
24
25
|
* ```js
|
|
@@ -35,5 +36,5 @@ export const queryFollowings = async (query: {
|
|
|
35
36
|
*/
|
|
36
37
|
queryFollowings.locally = (
|
|
37
38
|
query: Parameters<typeof queryFollowings>[0],
|
|
38
|
-
): Amity.Cached<Amity.Paged<Amity.FollowStatus>> | undefined =>
|
|
39
|
+
): Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>> | undefined =>
|
|
39
40
|
queryFollows.locally('following', query);
|