@amityco/ts-sdk 6.12.2-d74459e.0 → 6.12.2-e855934.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +8 -9
- package/dist/@types/core/marker.d.ts +4 -4
- package/dist/@types/core/marker.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -4
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +17 -17
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/block.d.ts +1 -1
- package/dist/@types/domains/block.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +5 -2
- package/dist/@types/domains/category.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +3 -3
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -1
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +4 -4
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +4 -4
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +2 -2
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/messagePreview.d.ts +2 -2
- package/dist/@types/domains/messagePreview.d.ts.map +1 -1
- package/dist/@types/domains/poll.d.ts +1 -1
- package/dist/@types/domains/poll.d.ts.map +1 -1
- package/dist/@types/domains/post.d.ts +1 -1
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/reaction.d.ts +1 -1
- package/dist/@types/domains/reaction.d.ts.map +1 -1
- package/dist/@types/domains/stream.d.ts +2 -2
- package/dist/@types/domains/stream.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +7 -3
- package/dist/@types/domains/user.d.ts.map +1 -1
- package/dist/cache/api/pushToCache.d.ts +1 -1
- package/dist/cache/api/upsertInCache.d.ts +1 -1
- package/dist/categoryRepository/api/getCategory.d.ts.map +1 -1
- package/dist/categoryRepository/api/queryCategories.d.ts.map +1 -1
- package/dist/categoryRepository/observers/getCategories.d.ts.map +1 -1
- package/dist/channelRepsitory/channelMembership/api/addMembers.d.ts +4 -4
- package/dist/channelRepsitory/channelMembership/api/addMembers.d.ts.map +1 -1
- package/dist/channelRepsitory/channelMembership/api/removeMembers.d.ts +4 -4
- package/dist/channelRepsitory/channelMembership/api/removeMembers.d.ts.map +1 -1
- package/dist/channelRepsitory/channelModeration/api/addRole.d.ts +4 -4
- package/dist/channelRepsitory/channelModeration/api/addRole.d.ts.map +1 -1
- package/dist/channelRepsitory/channelModeration/api/banMembers.d.ts +2 -2
- package/dist/channelRepsitory/channelModeration/api/banMembers.d.ts.map +1 -1
- package/dist/channelRepsitory/channelModeration/api/removeRole.d.ts +4 -4
- package/dist/channelRepsitory/channelModeration/api/removeRole.d.ts.map +1 -1
- package/dist/channelRepsitory/channelModeration/api/unbanMembers.d.ts +2 -2
- package/dist/channelRepsitory/channelModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/channelRepsitory/events/onChannelMemberAdded.d.ts +1 -1
- package/dist/channelRepsitory/events/onChannelMemberBanned.d.ts +1 -1
- package/dist/channelRepsitory/events/onChannelMemberRemoved.d.ts +1 -1
- package/dist/channelRepsitory/events/onChannelMemberUnbanned.d.ts +1 -1
- package/dist/channelRepsitory/observers/tests/getChannel.test.d.ts +2 -0
- package/dist/channelRepsitory/observers/tests/getChannel.test.d.ts.map +1 -0
- package/dist/client/api/getToken.d.ts +3 -3
- package/dist/client/api/getToken.d.ts.map +1 -1
- package/dist/client/utils/setClientToken.d.ts +1 -1
- package/dist/communityRepository/communityMembership/api/addMembers.d.ts +4 -4
- package/dist/communityRepository/communityMembership/api/addMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityMembership/api/removeMembers.d.ts +4 -4
- package/dist/communityRepository/communityMembership/api/removeMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/addRoles.d.ts +4 -4
- package/dist/communityRepository/communityModeration/api/addRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/banMembers.d.ts +2 -2
- package/dist/communityRepository/communityModeration/api/banMembers.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/removeRoles.d.ts +4 -4
- package/dist/communityRepository/communityModeration/api/removeRoles.d.ts.map +1 -1
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts +2 -2
- package/dist/communityRepository/communityModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/core/device.d.ts +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +2 -2
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/external/api/createUserToken.d.ts +2 -2
- package/dist/external/api/createUserToken.d.ts.map +1 -1
- package/dist/group/utils/withUser.d.ts +3 -3
- package/dist/group/utils/withUser.d.ts.map +1 -1
- package/dist/index.cjs.js +206 -126
- package/dist/index.esm.js +206 -126
- package/dist/index.umd.js +4 -4
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/messagePreview/utils/getSubChannelMessagePreviewWithUser.d.ts +1 -1
- package/dist/messageRepository/api/getDeliveredUsers.d.ts +6 -6
- package/dist/messageRepository/api/getDeliveredUsers.d.ts.map +1 -1
- package/dist/messageRepository/api/getReadUsers.d.ts +6 -6
- package/dist/messageRepository/api/getReadUsers.d.ts.map +1 -1
- package/dist/streamRepository/api/getStreams.d.ts +1 -1
- package/dist/streamRepository/api/getStreams.d.ts.map +1 -1
- package/dist/streamRepository/api/queryStreams.d.ts +1 -1
- package/dist/streamRepository/api/queryStreams.d.ts.map +1 -1
- package/dist/userRepository/api/flagUser.d.ts +1 -1
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUser.d.ts.map +1 -1
- package/dist/userRepository/api/getUserByIds.d.ts +1 -1
- package/dist/userRepository/api/getUserByIds.d.ts.map +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts +1 -1
- package/dist/userRepository/api/isUserFlaggedByMe.d.ts.map +1 -1
- package/dist/userRepository/api/queryBlockedUsers.d.ts +5 -5
- package/dist/userRepository/api/queryBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/api/queryUsers.d.ts +6 -6
- package/dist/userRepository/api/queryUsers.d.ts.map +1 -1
- package/dist/userRepository/api/unflagUser.d.ts +1 -1
- package/dist/userRepository/api/unflagUser.d.ts.map +1 -1
- package/dist/userRepository/api/updateUser.d.ts +4 -4
- package/dist/userRepository/api/updateUser.d.ts.map +1 -1
- package/dist/userRepository/events/onUserDeleted.d.ts +2 -2
- package/dist/userRepository/events/onUserDeleted.d.ts.map +1 -1
- package/dist/userRepository/events/onUserFetched.d.ts +2 -2
- package/dist/userRepository/events/onUserFetched.d.ts.map +1 -1
- package/dist/userRepository/events/onUserFlagCleared.d.ts +2 -2
- package/dist/userRepository/events/onUserFlagCleared.d.ts.map +1 -1
- package/dist/userRepository/events/onUserFlagged.d.ts +2 -2
- package/dist/userRepository/events/onUserFlagged.d.ts.map +1 -1
- package/dist/userRepository/events/onUserUnflagged.d.ts +2 -2
- package/dist/userRepository/events/onUserUnflagged.d.ts.map +1 -1
- package/dist/userRepository/events/onUserUpdated.d.ts +2 -2
- package/dist/userRepository/events/onUserUpdated.d.ts.map +1 -1
- package/dist/userRepository/events/utils.d.ts +1 -1
- package/dist/userRepository/events/utils.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers.d.ts +4 -4
- package/dist/userRepository/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/getUser.d.ts +2 -2
- package/dist/userRepository/observers/getUser.d.ts.map +1 -1
- package/dist/userRepository/observers/getUsers.d.ts.map +1 -1
- package/dist/userRepository/observers/observeUser.d.ts +2 -2
- package/dist/userRepository/observers/observeUser.d.ts.map +1 -1
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts +2 -2
- package/dist/userRepository/observers/searchUserByDisplayName.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/blockUser.d.ts +4 -4
- package/dist/userRepository/relationship/block/api/blockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/api/unBlockUser.d.ts +4 -4
- package/dist/userRepository/relationship/block/api/unBlockUser.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts +1 -1
- package/dist/userRepository/relationship/block/observers/getBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts +2 -2
- package/dist/userRepository/relationship/follow/api/acceptFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/acceptMyFollower.d.ts +2 -2
- package/dist/userRepository/relationship/follow/api/acceptMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts +2 -2
- package/dist/userRepository/relationship/follow/api/declineFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/declineMyFollower.d.ts +2 -2
- package/dist/userRepository/relationship/follow/api/declineMyFollower.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/follow.d.ts +2 -2
- package/dist/userRepository/relationship/follow/api/follow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/getFollowInfo.d.ts +4 -4
- package/dist/userRepository/relationship/follow/api/getFollowInfo.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/unfollow.d.ts +3 -3
- package/dist/userRepository/relationship/follow/api/unfollow.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/api/utils.d.ts +1 -1
- package/dist/userRepository/relationship/follow/api/utils.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowers.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/getFollowings.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowInfo.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts +2 -2
- package/dist/userRepository/relationship/follow/observers/observeFollowers.d.ts.map +1 -1
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts +2 -2
- package/dist/userRepository/relationship/follow/observers/observeFollowings.d.ts.map +1 -1
- package/dist/utils/linkedObject/categoryLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/categoryLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +2 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/userLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/userLinkedObject.d.ts.map +1 -0
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/block.d.ts +4 -4
- package/dist/utils/tests/dummy/block.d.ts.map +1 -1
- package/dist/utils/tests/dummy/category.d.ts +7 -0
- package/dist/utils/tests/dummy/category.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +11 -1
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +6 -6
- package/dist/utils/tests/dummy/follow.d.ts +1 -1
- package/dist/utils/tests/dummy/follow.d.ts.map +1 -1
- package/dist/utils/tests/dummy/user.d.ts +5 -1
- package/dist/utils/tests/dummy/user.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/marker.ts +4 -4
- package/src/@types/core/model.ts +4 -4
- package/src/@types/core/payload.ts +17 -17
- package/src/@types/domains/block.ts +1 -1
- package/src/@types/domains/category.ts +6 -2
- package/src/@types/domains/client.ts +3 -3
- package/src/@types/domains/comment.ts +1 -1
- package/src/@types/domains/community.ts +4 -4
- package/src/@types/domains/follow.ts +4 -4
- package/src/@types/domains/group.ts +2 -2
- package/src/@types/domains/messagePreview.ts +2 -2
- package/src/@types/domains/poll.ts +1 -1
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/domains/reaction.ts +1 -1
- package/src/@types/domains/stream.ts +2 -2
- package/src/@types/domains/user.ts +8 -3
- package/src/cache/api/pushToCache.ts +1 -1
- package/src/cache/api/upsertInCache.ts +1 -1
- package/src/categoryRepository/api/getCategory.ts +3 -2
- package/src/categoryRepository/api/queryCategories.ts +7 -1
- package/src/categoryRepository/observers/getCategories.ts +3 -2
- package/src/categoryRepository/observers/tests/getCategories.test.ts +2 -1
- package/src/channelRepsitory/api/createChannel.ts +1 -1
- package/src/channelRepsitory/channelMembership/api/addMembers.ts +4 -4
- package/src/channelRepsitory/channelMembership/api/removeMembers.ts +4 -4
- package/src/channelRepsitory/channelMembership/observers/tests/getMembers.test.ts +1 -1
- package/src/channelRepsitory/channelMembership/observers/tests/searchMembers.test.ts +1 -3
- package/src/channelRepsitory/channelModeration/api/addRole.ts +4 -4
- package/src/channelRepsitory/channelModeration/api/banMembers.ts +2 -2
- package/src/channelRepsitory/channelModeration/api/removeRole.ts +4 -4
- package/src/channelRepsitory/channelModeration/api/unbanMembers.ts +2 -2
- package/src/channelRepsitory/events/onChannelMemberAdded.ts +1 -1
- package/src/channelRepsitory/events/onChannelMemberBanned.ts +1 -1
- package/src/channelRepsitory/events/onChannelMemberRemoved.ts +1 -1
- package/src/channelRepsitory/events/onChannelMemberUnbanned.ts +1 -1
- package/src/channelRepsitory/observers/tests/getChannel.test.ts +73 -0
- package/src/channelRepsitory/observers/tests/getChannels.test.ts +462 -50
- package/src/client/api/getToken.ts +3 -3
- package/src/client/api/login.ts +1 -1
- package/src/communityRepository/communityMembership/api/addMembers.ts +4 -4
- package/src/communityRepository/communityMembership/api/removeMembers.ts +4 -4
- package/src/communityRepository/communityMembership/events/utils.ts +2 -2
- package/src/communityRepository/communityMembership/observers/tests/getMembers.test.ts +1 -1
- package/src/communityRepository/communityModeration/api/addRoles.ts +4 -4
- package/src/communityRepository/communityModeration/api/banMembers.ts +2 -2
- package/src/communityRepository/communityModeration/api/removeRoles.ts +4 -4
- package/src/communityRepository/communityModeration/api/unbanMembers.ts +2 -2
- package/src/core/device.ts +1 -1
- package/src/core/query/filtering.ts +3 -1
- package/src/core/query/tests/filtering.test.ts +2 -2
- package/src/external/api/createUserToken.ts +2 -2
- package/src/group/utils/withUser.ts +8 -4
- package/src/liveStreamPlayer/api/getPlayer.ts +1 -1
- package/src/messagePreview/utils/getChannelMessagePreviewWithUser.ts +1 -1
- package/src/messagePreview/utils/getSubChannelMessagePreviewWithUser.ts +1 -1
- package/src/messageRepository/api/getDeliveredUsers.ts +11 -9
- package/src/messageRepository/api/getReadUsers.ts +11 -9
- package/src/messageRepository/observers/tests/getMessages.test.ts +766 -0
- package/src/streamRepository/api/getStreams.ts +1 -1
- package/src/streamRepository/api/queryStreams.ts +1 -1
- package/src/subChannelRepository/observers/tests/getSubChannels.test.ts +308 -15
- package/src/userRepository/api/flagUser.ts +1 -1
- package/src/userRepository/api/getUser.ts +2 -1
- package/src/userRepository/api/getUserByIds.ts +4 -3
- package/src/userRepository/api/isUserFlaggedByMe.ts +1 -1
- package/src/userRepository/api/queryBlockedUsers.ts +10 -8
- package/src/userRepository/api/queryUsers.ts +12 -10
- package/src/userRepository/api/unflagUser.ts +1 -1
- package/src/userRepository/api/updateUser.ts +6 -6
- package/src/userRepository/events/onUserDeleted.ts +2 -2
- package/src/userRepository/events/onUserFetched.ts +2 -2
- package/src/userRepository/events/onUserFlagCleared.ts +2 -2
- package/src/userRepository/events/onUserFlagged.ts +2 -2
- package/src/userRepository/events/onUserUnflagged.ts +2 -2
- package/src/userRepository/events/onUserUpdated.ts +2 -2
- package/src/userRepository/events/utils.ts +1 -1
- package/src/userRepository/observers/getBlockedUsers.ts +8 -7
- package/src/userRepository/observers/getUser.ts +3 -3
- package/src/userRepository/observers/getUsers.ts +2 -2
- package/src/userRepository/observers/observeUser.ts +9 -6
- package/src/userRepository/observers/searchUserByDisplayName.ts +2 -2
- package/src/userRepository/observers/tests/getUser.test.ts +1 -1
- package/src/userRepository/observers/tests/getUsers.test.ts +12 -11
- package/src/userRepository/observers/tests/searchUserByDisplayName.test.ts +1 -1
- package/src/userRepository/relationship/block/api/blockUser.ts +6 -4
- package/src/userRepository/relationship/block/api/unBlockUser.ts +6 -4
- package/src/userRepository/relationship/block/observers/getBlockedUsers.ts +1 -1
- package/src/userRepository/relationship/follow/api/acceptFollower.ts +2 -2
- package/src/userRepository/relationship/follow/api/acceptMyFollower.ts +2 -2
- package/src/userRepository/relationship/follow/api/declineFollower.ts +2 -2
- package/src/userRepository/relationship/follow/api/declineMyFollower.ts +2 -2
- package/src/userRepository/relationship/follow/api/follow.ts +2 -2
- package/src/userRepository/relationship/follow/api/getFollowInfo.ts +4 -4
- package/src/userRepository/relationship/follow/api/unfollow.ts +3 -3
- package/src/userRepository/relationship/follow/api/utils.ts +1 -1
- package/src/userRepository/relationship/follow/observers/getFollowers.ts +1 -1
- package/src/userRepository/relationship/follow/observers/getFollowings.ts +1 -1
- package/src/userRepository/relationship/follow/observers/observeFollowInfo.ts +1 -1
- package/src/userRepository/relationship/follow/observers/observeFollowers.ts +2 -2
- package/src/userRepository/relationship/follow/observers/observeFollowings.ts +2 -2
- package/src/utils/linkedObject/categoryLinkedObject.ts +40 -0
- package/src/utils/linkedObject/index.ts +4 -0
- package/src/utils/linkedObject/userLinkedObject.ts +36 -0
- package/src/utils/tests/client.ts +1 -0
- package/src/utils/tests/dummy/block.ts +3 -3
- package/src/utils/tests/dummy/category.ts +5 -0
- package/src/utils/tests/dummy/channel.ts +58 -1
- package/src/utils/tests/dummy/community.ts +1 -1
- package/src/utils/tests/dummy/follow.ts +1 -1
- package/src/utils/tests/dummy/user.ts +3 -1
- package/tsconfig.json +18 -23
|
@@ -23,7 +23,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
23
23
|
export const getStreams = async (query?: {
|
|
24
24
|
isLive?: boolean;
|
|
25
25
|
statuses?: Amity.StreamStatus[];
|
|
26
|
-
userPublicIds?: Amity.
|
|
26
|
+
userPublicIds?: Amity.InternalUser['userId'][];
|
|
27
27
|
sortBy?: 'lastCreated' | 'firstCreated';
|
|
28
28
|
isDeleted?: Amity.Stream['isDeleted'];
|
|
29
29
|
page?: Amity.Page;
|
|
@@ -23,7 +23,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
23
23
|
export const queryStreams = async (query?: {
|
|
24
24
|
isLive?: boolean;
|
|
25
25
|
statuses?: Amity.StreamStatus[];
|
|
26
|
-
userPublicIds?: Amity.
|
|
26
|
+
userPublicIds?: Amity.InternalUser['userId'][];
|
|
27
27
|
sortBy?: 'lastCreated' | 'firstCreated';
|
|
28
28
|
isDeleted?: Amity.Stream['isDeleted'];
|
|
29
29
|
page?: Amity.Page;
|
|
@@ -10,6 +10,7 @@ import {
|
|
|
10
10
|
import { getFutureDate, getPastDate } from '~/core/model';
|
|
11
11
|
import * as getSubChannelMarkers from '~/marker/api/getSubChannelMarkers';
|
|
12
12
|
import { getSubChannels } from '../getSubChannels';
|
|
13
|
+
import { ASCApiError } from '~/core/errors';
|
|
13
14
|
|
|
14
15
|
describe('getSubChannels', () => {
|
|
15
16
|
const rawSubChannel = generateRawSubChannel();
|
|
@@ -61,26 +62,28 @@ describe('getSubChannels', () => {
|
|
|
61
62
|
);
|
|
62
63
|
});
|
|
63
64
|
|
|
64
|
-
test('should
|
|
65
|
-
const rawSubChannels = [
|
|
66
|
-
generateRawSubChannel({ isDeleted: true }),
|
|
67
|
-
generateRawSubChannel({ messageFeedId: 'sub-channel-id-2' }),
|
|
68
|
-
];
|
|
65
|
+
test('should error when get invalid sub channels', async () => {
|
|
69
66
|
const callback = jest.fn();
|
|
70
|
-
client.http.get = jest.fn().mockResolvedValue({
|
|
71
|
-
data: {
|
|
72
|
-
messageFeeds: rawSubChannels,
|
|
73
|
-
messages: [],
|
|
74
|
-
users: [],
|
|
75
|
-
files: [],
|
|
76
|
-
paging: {},
|
|
77
|
-
},
|
|
78
|
-
});
|
|
79
67
|
|
|
80
|
-
|
|
68
|
+
const error = new ASCApiError(
|
|
69
|
+
'Channel not found.',
|
|
70
|
+
Amity.ServerError.ITEM_NOT_FOUND,
|
|
71
|
+
Amity.ErrorLevel.ERROR,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
client.http.get = jest.fn().mockRejectedValue(error);
|
|
75
|
+
|
|
76
|
+
getSubChannels({ channelId: rawSubChannel.channelPublicId }, callback);
|
|
81
77
|
await pause();
|
|
82
78
|
|
|
83
79
|
expect(callback).toHaveBeenCalledTimes(2);
|
|
80
|
+
expect(callback).toHaveBeenNthCalledWith(
|
|
81
|
+
1,
|
|
82
|
+
expect.objectContaining({
|
|
83
|
+
data: [],
|
|
84
|
+
loading: true,
|
|
85
|
+
}),
|
|
86
|
+
);
|
|
84
87
|
expect(callback).toHaveBeenNthCalledWith(
|
|
85
88
|
2,
|
|
86
89
|
expect.objectContaining({
|
|
@@ -88,6 +91,7 @@ describe('getSubChannels', () => {
|
|
|
88
91
|
return { ...subChannel, messagePreview: null };
|
|
89
92
|
}),
|
|
90
93
|
loading: false,
|
|
94
|
+
error,
|
|
91
95
|
}),
|
|
92
96
|
);
|
|
93
97
|
});
|
|
@@ -151,6 +155,295 @@ describe('getSubChannels', () => {
|
|
|
151
155
|
);
|
|
152
156
|
});
|
|
153
157
|
|
|
158
|
+
test('when querying two subchannel collections with same channelId but different params, pagination remains functional', async () => {
|
|
159
|
+
const subChannelCase1Page1 = [
|
|
160
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '1' }),
|
|
161
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '2' }),
|
|
162
|
+
];
|
|
163
|
+
const subChannelCase1Page2 = [
|
|
164
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '3' }),
|
|
165
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: '4' }),
|
|
166
|
+
];
|
|
167
|
+
const subChannelCase2Page1 = [
|
|
168
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x6' }),
|
|
169
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x5' }),
|
|
170
|
+
];
|
|
171
|
+
const subChannelCase2Page2 = [
|
|
172
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x4' }),
|
|
173
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x3' }),
|
|
174
|
+
];
|
|
175
|
+
const subChannelCase2Page3 = [
|
|
176
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x2' }),
|
|
177
|
+
generateRawSubChannel({ channelPublicId: 'channel1', name: 'x1' }),
|
|
178
|
+
];
|
|
179
|
+
|
|
180
|
+
const callback = jest.fn();
|
|
181
|
+
const callback2 = jest.fn();
|
|
182
|
+
|
|
183
|
+
client.http.get = jest.fn().mockImplementation((url, params) => {
|
|
184
|
+
if (params.params?.excludeDefaultMessageFeed === true) {
|
|
185
|
+
if (params?.params.options.token === 'eyJiZWZvcmUiOjU1LCJsaW1pdCI6NX0=') {
|
|
186
|
+
return Promise.resolve({
|
|
187
|
+
data: {
|
|
188
|
+
messageFeeds: subChannelCase2Page2,
|
|
189
|
+
messages: [],
|
|
190
|
+
users: [],
|
|
191
|
+
files: [],
|
|
192
|
+
paging: {
|
|
193
|
+
previous: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
194
|
+
next: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
});
|
|
198
|
+
}
|
|
199
|
+
|
|
200
|
+
if (params?.params.options.token === 'eyJiZWZvcmUiOjQ1LCJsaW1pdCI6NX0=') {
|
|
201
|
+
return Promise.resolve({
|
|
202
|
+
data: {
|
|
203
|
+
messageFeeds: subChannelCase2Page3,
|
|
204
|
+
messages: [],
|
|
205
|
+
users: [],
|
|
206
|
+
files: [],
|
|
207
|
+
paging: {
|
|
208
|
+
next: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
});
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
return Promise.resolve({
|
|
215
|
+
data: {
|
|
216
|
+
messageFeeds: subChannelCase2Page1,
|
|
217
|
+
messages: [],
|
|
218
|
+
users: [],
|
|
219
|
+
files: [],
|
|
220
|
+
paging: {
|
|
221
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
222
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
223
|
+
},
|
|
224
|
+
},
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
if (params?.params.options.token === 'eyJiZWZvcmUiOjU1LCJsaW1pdCI6NX0=') {
|
|
228
|
+
return Promise.resolve({
|
|
229
|
+
data: {
|
|
230
|
+
messageFeeds: subChannelCase1Page2,
|
|
231
|
+
messages: [],
|
|
232
|
+
users: [],
|
|
233
|
+
files: [],
|
|
234
|
+
paging: {
|
|
235
|
+
previous: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
236
|
+
next: 'eyJiZWZvcmUiOjQ1LCJsYXN0IjoxMH0=',
|
|
237
|
+
},
|
|
238
|
+
},
|
|
239
|
+
});
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
return Promise.resolve({
|
|
243
|
+
data: {
|
|
244
|
+
messageFeeds: subChannelCase1Page1,
|
|
245
|
+
messages: [],
|
|
246
|
+
users: [],
|
|
247
|
+
files: [],
|
|
248
|
+
paging: {
|
|
249
|
+
previous: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
250
|
+
next: 'eyJiZWZvcmUiOjU1LCJsYXN0IjoxMH0=',
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
getSubChannels({ channelId: 'channel1' }, callback);
|
|
257
|
+
getSubChannels({ channelId: 'channel1', excludeDefaultSubChannel: true }, callback2);
|
|
258
|
+
|
|
259
|
+
await pause();
|
|
260
|
+
|
|
261
|
+
expect(callback).toHaveBeenCalledTimes(4);
|
|
262
|
+
expect(callback).lastCalledWith(
|
|
263
|
+
expect.objectContaining({
|
|
264
|
+
data: [convertSubChannelFromRaw(subChannelCase1Page1[0])],
|
|
265
|
+
loading: false,
|
|
266
|
+
}),
|
|
267
|
+
);
|
|
268
|
+
|
|
269
|
+
expect(callback2).toHaveBeenCalledTimes(4);
|
|
270
|
+
|
|
271
|
+
expect(callback2).not.toHaveBeenCalledWith(
|
|
272
|
+
expect.objectContaining({
|
|
273
|
+
data: [convertSubChannelFromRaw(subChannelCase1Page1[0])],
|
|
274
|
+
loading: false,
|
|
275
|
+
}),
|
|
276
|
+
);
|
|
277
|
+
|
|
278
|
+
expect(callback2).lastCalledWith(
|
|
279
|
+
expect.objectContaining({
|
|
280
|
+
data: [convertSubChannelFromRaw(subChannelCase2Page1[0])],
|
|
281
|
+
loading: false,
|
|
282
|
+
}),
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
callback2.mock.lastCall[0].onNextPage();
|
|
286
|
+
|
|
287
|
+
await pause();
|
|
288
|
+
|
|
289
|
+
callback2.mock.lastCall[0].onNextPage();
|
|
290
|
+
|
|
291
|
+
await pause();
|
|
292
|
+
|
|
293
|
+
expect(callback2).toHaveBeenCalledTimes(10);
|
|
294
|
+
expect(callback2).lastCalledWith(
|
|
295
|
+
expect.objectContaining({
|
|
296
|
+
data: [convertSubChannelFromRaw(subChannelCase2Page3[0])],
|
|
297
|
+
loading: false,
|
|
298
|
+
}),
|
|
299
|
+
);
|
|
300
|
+
|
|
301
|
+
callback.mock.lastCall[0].onNextPage();
|
|
302
|
+
|
|
303
|
+
await pause();
|
|
304
|
+
|
|
305
|
+
expect(callback).toHaveBeenCalledTimes(9);
|
|
306
|
+
expect(callback).lastCalledWith(
|
|
307
|
+
expect.objectContaining({
|
|
308
|
+
data: [convertSubChannelFromRaw(subChannelCase1Page2[0])],
|
|
309
|
+
loading: false,
|
|
310
|
+
}),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
expect(callback).not.toHaveBeenCalledWith(
|
|
314
|
+
expect.objectContaining({
|
|
315
|
+
data: [convertSubChannelFromRaw(subChannelCase2Page3[0])],
|
|
316
|
+
loading: false,
|
|
317
|
+
}),
|
|
318
|
+
);
|
|
319
|
+
});
|
|
320
|
+
|
|
321
|
+
describe('when querying the subchannel collection with specific sort and filter options, results sort correctly', () => {
|
|
322
|
+
const subChannel1 = generateRawSubChannel({ channelId: 'aaaaa' });
|
|
323
|
+
const deletedRawSubChannel = generateRawSubChannel({ channelId: 'aaaaa', isDeleted: true });
|
|
324
|
+
|
|
325
|
+
const filterCases: [
|
|
326
|
+
string,
|
|
327
|
+
Amity.SubChannelLiveCollection,
|
|
328
|
+
Amity.RawSubChannel[],
|
|
329
|
+
Amity.RawSubChannel[],
|
|
330
|
+
][] = [
|
|
331
|
+
[
|
|
332
|
+
'includeDeleted = true',
|
|
333
|
+
{ channelId: 'aaaaa', includeDeleted: true },
|
|
334
|
+
[deletedRawSubChannel, subChannel1],
|
|
335
|
+
[subChannel1],
|
|
336
|
+
],
|
|
337
|
+
[
|
|
338
|
+
'includeDeleted = false',
|
|
339
|
+
{ channelId: 'aaaaa', includeDeleted: false },
|
|
340
|
+
[deletedRawSubChannel, subChannel1],
|
|
341
|
+
[subChannel1],
|
|
342
|
+
],
|
|
343
|
+
];
|
|
344
|
+
|
|
345
|
+
test.each(filterCases)('%s', async (_test, params, responses, expected) => {
|
|
346
|
+
const callback = jest.fn();
|
|
347
|
+
client.http.get = jest.fn().mockResolvedValue({
|
|
348
|
+
data: {
|
|
349
|
+
messageFeeds: responses,
|
|
350
|
+
messages: [],
|
|
351
|
+
users: [],
|
|
352
|
+
files: [],
|
|
353
|
+
paging: {},
|
|
354
|
+
},
|
|
355
|
+
});
|
|
356
|
+
|
|
357
|
+
getSubChannels(params, callback);
|
|
358
|
+
|
|
359
|
+
await pause();
|
|
360
|
+
|
|
361
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
362
|
+
expect(callback).lastCalledWith(
|
|
363
|
+
expect.objectContaining({
|
|
364
|
+
data: expected.map(convertSubChannelFromRaw),
|
|
365
|
+
loading: false,
|
|
366
|
+
}),
|
|
367
|
+
);
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
|
|
371
|
+
test('when querying two subchannel collections with the same channelId but different params, results are distinct', async () => {
|
|
372
|
+
const callback = jest.fn();
|
|
373
|
+
const callback2 = jest.fn();
|
|
374
|
+
const subChannel = generateRawSubChannel({ channelPublicId: 'channel1' });
|
|
375
|
+
const subChannel2 = generateRawSubChannel({
|
|
376
|
+
channelPublicId: 'channel1',
|
|
377
|
+
lastMessageId: 'thisissubchannelforanothercase',
|
|
378
|
+
});
|
|
379
|
+
const defaultSubChannel = generateRawSubChannel({
|
|
380
|
+
channelPublicId: 'channel1',
|
|
381
|
+
lastMessageId: 'thisisdefault',
|
|
382
|
+
});
|
|
383
|
+
|
|
384
|
+
client.http.get = jest.fn().mockImplementation((url, params) => {
|
|
385
|
+
if (params.params?.excludeDefaultMessageFeed === false) {
|
|
386
|
+
return Promise.resolve({
|
|
387
|
+
data: {
|
|
388
|
+
messageFeeds: [defaultSubChannel, subChannel],
|
|
389
|
+
messages: [],
|
|
390
|
+
users: [],
|
|
391
|
+
files: [],
|
|
392
|
+
paging: {},
|
|
393
|
+
},
|
|
394
|
+
});
|
|
395
|
+
}
|
|
396
|
+
return Promise.resolve({
|
|
397
|
+
data: {
|
|
398
|
+
messageFeeds: [subChannel2],
|
|
399
|
+
messages: [],
|
|
400
|
+
users: [],
|
|
401
|
+
files: [],
|
|
402
|
+
paging: {},
|
|
403
|
+
},
|
|
404
|
+
});
|
|
405
|
+
});
|
|
406
|
+
|
|
407
|
+
getSubChannels({ channelId: 'channel1', excludeDefaultSubChannel: false }, callback);
|
|
408
|
+
getSubChannels({ channelId: 'channel1', excludeDefaultSubChannel: true }, callback2);
|
|
409
|
+
|
|
410
|
+
expect(callback).toHaveBeenCalledTimes(1);
|
|
411
|
+
expect(callback).toHaveBeenCalledWith(
|
|
412
|
+
expect.objectContaining({
|
|
413
|
+
data: [],
|
|
414
|
+
error: undefined,
|
|
415
|
+
loading: true,
|
|
416
|
+
}),
|
|
417
|
+
);
|
|
418
|
+
|
|
419
|
+
await pause(100);
|
|
420
|
+
|
|
421
|
+
expect(callback.mock.calls.length).toBe(3);
|
|
422
|
+
expect(callback).toHaveBeenCalledWith(
|
|
423
|
+
expect.objectContaining({
|
|
424
|
+
data: [convertSubChannelFromRaw(subChannel)],
|
|
425
|
+
error: undefined,
|
|
426
|
+
loading: false,
|
|
427
|
+
}),
|
|
428
|
+
);
|
|
429
|
+
expect(callback).lastCalledWith(
|
|
430
|
+
expect.objectContaining({
|
|
431
|
+
data: [convertSubChannelFromRaw(defaultSubChannel)],
|
|
432
|
+
error: undefined,
|
|
433
|
+
loading: false,
|
|
434
|
+
}),
|
|
435
|
+
);
|
|
436
|
+
|
|
437
|
+
expect(callback2.mock.calls.length).toBe(2);
|
|
438
|
+
expect(callback2).lastCalledWith(
|
|
439
|
+
expect.objectContaining({
|
|
440
|
+
data: [convertSubChannelFromRaw(subChannel2)],
|
|
441
|
+
error: undefined,
|
|
442
|
+
loading: false,
|
|
443
|
+
}),
|
|
444
|
+
);
|
|
445
|
+
});
|
|
446
|
+
|
|
154
447
|
describe('events', () => {
|
|
155
448
|
const newRawSubChannel = generateRawSubChannel({
|
|
156
449
|
messageFeedId: 'sub-channel-id-2',
|
|
@@ -18,7 +18,7 @@ import { fireEvent } from '~/core/events';
|
|
|
18
18
|
* @category User API
|
|
19
19
|
* @async
|
|
20
20
|
* */
|
|
21
|
-
export const flagUser = async (userId: Amity.
|
|
21
|
+
export const flagUser = async (userId: Amity.InternalUser['userId']): Promise<boolean> => {
|
|
22
22
|
const client = getActiveClient();
|
|
23
23
|
client.log('user/flagUser', userId);
|
|
24
24
|
|
|
@@ -7,6 +7,7 @@ import { fireEvent } from '~/core/events';
|
|
|
7
7
|
import { isInTombstone } from '~/cache/api/isInTombstone';
|
|
8
8
|
import { checkIfShouldGoesToTombstone } from '~/cache/utils';
|
|
9
9
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
10
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* ```js
|
|
@@ -52,7 +53,7 @@ export const getUser = async (userId: Amity.User['userId']): Promise<Amity.Cache
|
|
|
52
53
|
fireEvent('user.fetched', data);
|
|
53
54
|
|
|
54
55
|
return {
|
|
55
|
-
data: users.find(user => user.userId === userId)
|
|
56
|
+
data: LinkedObject.user(users.find(user => user.userId === userId)!),
|
|
56
57
|
cachedAt,
|
|
57
58
|
};
|
|
58
59
|
};
|
|
@@ -3,6 +3,7 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
import { fireEvent } from '~/core/events';
|
|
6
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
6
7
|
|
|
7
8
|
/* begin_public_function
|
|
8
9
|
id: user.get_by_ids
|
|
@@ -40,7 +41,7 @@ export const getUserByIds = async (
|
|
|
40
41
|
fireEvent('user.fetched', data);
|
|
41
42
|
|
|
42
43
|
return {
|
|
43
|
-
data: data.users,
|
|
44
|
+
data: data.users.map(user => LinkedObject.user(user)),
|
|
44
45
|
cachedAt,
|
|
45
46
|
};
|
|
46
47
|
};
|
|
@@ -61,7 +62,7 @@ export const getUserByIds = async (
|
|
|
61
62
|
*/
|
|
62
63
|
getUserByIds.locally = (
|
|
63
64
|
userIds: Amity.User['userId'][],
|
|
64
|
-
): Amity.Cached<Amity.
|
|
65
|
+
): Amity.Cached<Amity.InternalUser[]> | undefined => {
|
|
65
66
|
const client = getActiveClient();
|
|
66
67
|
client.log('user/getUsers.locally', userIds);
|
|
67
68
|
|
|
@@ -71,7 +72,7 @@ getUserByIds.locally = (
|
|
|
71
72
|
.map(userId => pullFromCache<Amity.User>(['user', 'get', userId])!)
|
|
72
73
|
.filter(Boolean);
|
|
73
74
|
|
|
74
|
-
const users = cached.map(({ data }) => data);
|
|
75
|
+
const users = cached.map(({ data }) => LinkedObject.user(data));
|
|
75
76
|
const oldest = cached.sort((a, b) => (a.cachedAt! < b.cachedAt! ? -1 : 1))?.[0];
|
|
76
77
|
|
|
77
78
|
if (cached?.length < userIds.length) return;
|
|
@@ -16,7 +16,7 @@ import { synchronousWSCall } from '~/core/transports';
|
|
|
16
16
|
* @category Report API
|
|
17
17
|
* @async
|
|
18
18
|
* */
|
|
19
|
-
export const isUserFlaggedByMe = async (userId: Amity.
|
|
19
|
+
export const isUserFlaggedByMe = async (userId: Amity.InternalUser['userId']): Promise<boolean> => {
|
|
20
20
|
const client = getActiveClient();
|
|
21
21
|
client.log('user/isUserFlaggedByMe', userId);
|
|
22
22
|
|
|
@@ -11,7 +11,7 @@ import { toPageRaw } from '~/core/query';
|
|
|
11
11
|
* ```
|
|
12
12
|
*
|
|
13
13
|
* @param query The query parameters
|
|
14
|
-
* @returns A page of {@link Amity.
|
|
14
|
+
* @returns A page of {@link Amity.InternalUser} objects
|
|
15
15
|
*
|
|
16
16
|
* @category Block API
|
|
17
17
|
* @async
|
|
@@ -20,7 +20,7 @@ import { toPageRaw } from '~/core/query';
|
|
|
20
20
|
export const queryBlockedUsers = async (
|
|
21
21
|
query?: Amity.QueryBlockedUser,
|
|
22
22
|
): Promise<
|
|
23
|
-
Amity.Cached<Amity.Paged<Amity.
|
|
23
|
+
Amity.Cached<Amity.Paged<Amity.InternalUser, Amity.PageRaw>> & {
|
|
24
24
|
total: number;
|
|
25
25
|
}
|
|
26
26
|
> => {
|
|
@@ -66,18 +66,18 @@ export const queryBlockedUsers = async (
|
|
|
66
66
|
* const { data: users } = queryBlockedUsers.locally({ page: 'page_token' })
|
|
67
67
|
* ```
|
|
68
68
|
*
|
|
69
|
-
* Queries a paginable list of {@link Amity.
|
|
69
|
+
* Queries a paginable list of {@link Amity.InternalUser} objects from cache
|
|
70
70
|
* Search is performed by displayName such as `.startsWith(search)`
|
|
71
71
|
*
|
|
72
72
|
* @param query The query parameters
|
|
73
|
-
* @returns A page of {@link Amity.
|
|
73
|
+
* @returns A page of {@link Amity.InternalUser} objects
|
|
74
74
|
*
|
|
75
75
|
* @category Block API
|
|
76
76
|
*/
|
|
77
77
|
queryBlockedUsers.locally = (
|
|
78
78
|
query: Parameters<typeof queryBlockedUsers>[0] = {},
|
|
79
79
|
):
|
|
80
|
-
| (Amity.Cached<Amity.Paged<Amity.
|
|
80
|
+
| (Amity.Cached<Amity.Paged<Amity.InternalUser, Amity.PageRaw>> & {
|
|
81
81
|
total: number;
|
|
82
82
|
})
|
|
83
83
|
| undefined => {
|
|
@@ -98,11 +98,13 @@ queryBlockedUsers.locally = (
|
|
|
98
98
|
const cacheKey = ['blockedUsers', 'query', params as Amity.Serializable];
|
|
99
99
|
|
|
100
100
|
const { data, cachedAt } =
|
|
101
|
-
pullFromCache<{ users: Pick<Amity.
|
|
101
|
+
pullFromCache<{ users: Pick<Amity.InternalUser, 'userId'>[] } & Amity.BlockedUserPaged>(
|
|
102
|
+
cacheKey,
|
|
103
|
+
) ?? {};
|
|
102
104
|
|
|
103
|
-
const users: Amity.
|
|
105
|
+
const users: Amity.InternalUser[] =
|
|
104
106
|
data?.users
|
|
105
|
-
.map(userId => pullFromCache<Amity.
|
|
107
|
+
.map(userId => pullFromCache<Amity.InternalUser>(['user', 'get', userId])!)
|
|
106
108
|
.filter(Boolean)
|
|
107
109
|
.map(({ data }) => data) ?? [];
|
|
108
110
|
|
|
@@ -6,6 +6,7 @@ import { pullFromCache, pushToCache } from '~/cache/api';
|
|
|
6
6
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
7
7
|
import { getResolver } from '~/core/model';
|
|
8
8
|
import { fireEvent } from '~/core/events';
|
|
9
|
+
import { LinkedObject } from '~/utils/linkedObject';
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* ```js
|
|
@@ -13,18 +14,18 @@ import { fireEvent } from '~/core/events';
|
|
|
13
14
|
* const { data: users, prevPage, nextPage } = await queryUsers({ displayName: 'foo' })
|
|
14
15
|
* ```
|
|
15
16
|
*
|
|
16
|
-
* Queries a paginable list of {@link Amity.
|
|
17
|
+
* Queries a paginable list of {@link Amity.InternalUser} objects
|
|
17
18
|
* Search is performed by displayName such as `.startsWith(search)`
|
|
18
19
|
*
|
|
19
20
|
* @param query The query parameters
|
|
20
|
-
* @returns A page of {@link Amity.
|
|
21
|
+
* @returns A page of {@link Amity.InternalUser} objects
|
|
21
22
|
*
|
|
22
23
|
* @category User API
|
|
23
24
|
* @async
|
|
24
25
|
*/
|
|
25
26
|
export const queryUsers = async (
|
|
26
27
|
query: Amity.QueryUsers = {},
|
|
27
|
-
): Promise<Amity.Cached<Amity.Paged<Amity.
|
|
28
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.InternalUser>>> => {
|
|
28
29
|
const client = getActiveClient();
|
|
29
30
|
client.log('user/queryUsers', query);
|
|
30
31
|
|
|
@@ -70,7 +71,7 @@ export const queryUsers = async (
|
|
|
70
71
|
const prevPage = toPage(paging.previous);
|
|
71
72
|
const nextPage = toPage(paging.next);
|
|
72
73
|
|
|
73
|
-
return { data: users, cachedAt, prevPage, nextPage };
|
|
74
|
+
return { data: users.map(user => LinkedObject.user(user)), cachedAt, prevPage, nextPage };
|
|
74
75
|
};
|
|
75
76
|
|
|
76
77
|
/**
|
|
@@ -79,17 +80,17 @@ export const queryUsers = async (
|
|
|
79
80
|
* const { data: users } = queryUsers.locally({ keyword: 'foo' })
|
|
80
81
|
* ```
|
|
81
82
|
*
|
|
82
|
-
* Queries a paginable list of {@link Amity.
|
|
83
|
+
* Queries a paginable list of {@link Amity.InternalUser} objects from cache
|
|
83
84
|
* Search is performed by displayName such as `.startsWith(search)`
|
|
84
85
|
*
|
|
85
86
|
* @param query The query parameters
|
|
86
|
-
* @returns A page of {@link Amity.
|
|
87
|
+
* @returns A page of {@link Amity.InternalUser} objects
|
|
87
88
|
*
|
|
88
89
|
* @category User API
|
|
89
90
|
*/
|
|
90
91
|
queryUsers.locally = (
|
|
91
92
|
query: Parameters<typeof queryUsers>[0] = {},
|
|
92
|
-
): Amity.Cached<Amity.Paged<Amity.
|
|
93
|
+
): Amity.Cached<Amity.Paged<Amity.InternalUser>> | undefined => {
|
|
93
94
|
const client = getActiveClient();
|
|
94
95
|
client.log('user/queryUsers.locally', query);
|
|
95
96
|
|
|
@@ -107,11 +108,12 @@ queryUsers.locally = (
|
|
|
107
108
|
];
|
|
108
109
|
|
|
109
110
|
const { data, cachedAt } =
|
|
110
|
-
pullFromCache<{ users: Pick<Amity.
|
|
111
|
+
pullFromCache<{ users: Pick<Amity.InternalUser, 'userId'>[] } & Amity.Pagination>(cacheKey) ??
|
|
112
|
+
{};
|
|
111
113
|
|
|
112
|
-
const users: Amity.
|
|
114
|
+
const users: Amity.InternalUser[] =
|
|
113
115
|
data?.users
|
|
114
|
-
.map(userId => pullFromCache<Amity.
|
|
116
|
+
.map(userId => pullFromCache<Amity.InternalUser>(['user', 'get', userId])!)
|
|
115
117
|
.filter(Boolean)
|
|
116
118
|
.map(({ data }) => data) ?? [];
|
|
117
119
|
|
|
@@ -18,7 +18,7 @@ import { fireEvent } from '~/core/events';
|
|
|
18
18
|
* @category User API
|
|
19
19
|
* @async
|
|
20
20
|
* */
|
|
21
|
-
export const unflagUser = async (userId: Amity.
|
|
21
|
+
export const unflagUser = async (userId: Amity.InternalUser['userId']): Promise<boolean> => {
|
|
22
22
|
const client = getActiveClient();
|
|
23
23
|
client.log('user/unflag', userId);
|
|
24
24
|
|
|
@@ -12,22 +12,22 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
12
12
|
* const updated = await updateUser(userId, { displayName: 'foobar' })
|
|
13
13
|
* ```
|
|
14
14
|
*
|
|
15
|
-
* Updates an {@link Amity.
|
|
15
|
+
* Updates an {@link Amity.InternalUser}
|
|
16
16
|
*
|
|
17
|
-
* @param userId The ID of the {@link Amity.
|
|
17
|
+
* @param userId The ID of the {@link Amity.InternalUser} to update
|
|
18
18
|
* @param patch The patch data to apply
|
|
19
|
-
* @returns the updated {@link Amity.
|
|
19
|
+
* @returns the updated {@link Amity.InternalUser} object
|
|
20
20
|
*
|
|
21
21
|
* @category User API
|
|
22
22
|
* @async
|
|
23
23
|
*/
|
|
24
24
|
export const updateUser = async (
|
|
25
|
-
userId: Amity.
|
|
25
|
+
userId: Amity.InternalUser['userId'],
|
|
26
26
|
patch: Patch<
|
|
27
|
-
Amity.
|
|
27
|
+
Amity.InternalUser,
|
|
28
28
|
'displayName' | 'description' | 'avatarFileId' | 'avatarCustomUrl' | 'metadata'
|
|
29
29
|
>,
|
|
30
|
-
): Promise<Amity.Cached<Amity.
|
|
30
|
+
): Promise<Amity.Cached<Amity.InternalUser>> => {
|
|
31
31
|
const client = getActiveClient();
|
|
32
32
|
client.log('user/updateUser', userId, patch);
|
|
33
33
|
|
|
@@ -8,12 +8,12 @@ import { createUserEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.InternalUser} has been deleted
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
16
|
* @category User Events
|
|
17
17
|
*/
|
|
18
|
-
export const onUserDeleted = (callback: Amity.Listener<Amity.
|
|
18
|
+
export const onUserDeleted = (callback: Amity.Listener<Amity.InternalUser>) =>
|
|
19
19
|
createUserEventSubscriber('user.deleted', callback);
|
|
@@ -8,12 +8,12 @@ import { createUserEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.InternalUser} has been fetched
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
16
|
* @category User Events
|
|
17
17
|
*/
|
|
18
|
-
export const onUserFetched = (callback: Amity.Listener<Amity.
|
|
18
|
+
export const onUserFetched = (callback: Amity.Listener<Amity.InternalUser>) =>
|
|
19
19
|
createUserEventSubscriber('user.fetched', callback);
|
|
@@ -8,12 +8,12 @@ import { createUserEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when flags have been cleared for a {@link Amity.
|
|
11
|
+
* Fired when flags have been cleared for a {@link Amity.InternalUser}
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
16
|
* @category User Events
|
|
17
17
|
*/
|
|
18
|
-
export const onUserFlagCleared = (callback: Amity.Listener<Amity.
|
|
18
|
+
export const onUserFlagCleared = (callback: Amity.Listener<Amity.InternalUser>) =>
|
|
19
19
|
createUserEventSubscriber('user.flagCleared', callback);
|
|
@@ -8,12 +8,12 @@ import { createUserEventSubscriber } from './utils';
|
|
|
8
8
|
* })
|
|
9
9
|
* ```
|
|
10
10
|
*
|
|
11
|
-
* Fired when a {@link Amity.
|
|
11
|
+
* Fired when a {@link Amity.InternalUser} has been flagged
|
|
12
12
|
*
|
|
13
13
|
* @param callback The function to call when the event was fired
|
|
14
14
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
15
15
|
*
|
|
16
16
|
* @category User Events
|
|
17
17
|
*/
|
|
18
|
-
export const onUserFlagged = (callback: Amity.Listener<Amity.
|
|
18
|
+
export const onUserFlagged = (callback: Amity.Listener<Amity.InternalUser>) =>
|
|
19
19
|
createUserEventSubscriber('user.flagged', callback);
|