@amityco/ts-sdk 0.0.1-beta.39 → 0.0.1-beta.40
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 +2 -0
- package/dist/@types/core/events.d.ts +22 -22
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +3 -2
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +87 -34
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +1 -1
- package/dist/@types/domains/client.d.ts +1 -1
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +5 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +11 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +7 -1
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +2 -2
- package/dist/@types/global.d.ts +8 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/cache/api/ingestInCache.d.ts +2 -1
- package/dist/cache/api/ingestInCache.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/unbanChannelMembers.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/onChannelMemberBanned.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberUnbanned.d.ts.map +1 -1
- package/dist/channel/utils/index.d.ts +2 -2
- package/dist/channel/utils/index.d.ts.map +1 -1
- package/dist/comment/api/createComment.d.ts +1 -1
- package/dist/comment/api/createComment.d.ts.map +1 -1
- package/dist/comment/api/deleteComment.d.ts.map +1 -1
- package/dist/comment/api/tests/updateComment.test.d.ts +2 -0
- package/dist/comment/api/tests/updateComment.test.d.ts.map +1 -0
- package/dist/community/api/addCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/addCommunityMembersRoles.d.ts +1 -1
- package/dist/community/api/addCommunityMembersRoles.d.ts.map +1 -1
- package/dist/community/api/deleteCommunity.d.ts.map +1 -1
- package/dist/community/api/joinCommunity.d.ts.map +1 -1
- package/dist/community/api/leaveCommunity.d.ts.map +1 -1
- package/dist/community/api/queryCommunityMembers.d.ts +1 -7
- package/dist/community/api/queryCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembers.d.ts.map +1 -1
- package/dist/community/api/removeCommunityMembersRoles.d.ts +1 -1
- package/dist/community/api/removeCommunityMembersRoles.d.ts.map +1 -1
- package/dist/community/events/index.d.ts +2 -0
- package/dist/community/events/index.d.ts.map +1 -1
- package/dist/community/events/onCommunityUserRoleAdded.d.ts +17 -0
- package/dist/community/events/onCommunityUserRoleAdded.d.ts.map +1 -0
- package/dist/community/events/onCommunityUserRoleRemoved.d.ts +17 -0
- package/dist/community/events/onCommunityUserRoleRemoved.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserRoleAdded.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserRoleAdded.test.d.ts.map +1 -0
- package/dist/community/events/test/onCommunityUserRoleRemoved.test.d.ts +2 -0
- package/dist/community/events/test/onCommunityUserRoleRemoved.test.d.ts.map +1 -0
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/observers/index.d.ts +2 -0
- package/dist/community/observers/index.d.ts.map +1 -1
- package/dist/community/observers/liveCommunity.d.ts +21 -0
- package/dist/community/observers/liveCommunity.d.ts.map +1 -0
- package/dist/community/observers/liveCommunityMembers.d.ts +20 -0
- package/dist/community/observers/liveCommunityMembers.d.ts.map +1 -0
- package/dist/community/observers/tests/liveCommunity.test.d.ts +2 -0
- package/dist/community/observers/tests/liveCommunity.test.d.ts.map +1 -0
- package/dist/community/observers/tests/liveCommunityMembers.test.d.ts +2 -0
- package/dist/community/observers/tests/liveCommunityMembers.test.d.ts.map +1 -0
- package/dist/community/utils/payload.d.ts +3 -5
- package/dist/community/utils/payload.d.ts.map +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts +2 -4
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts +2 -2
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/query.d.ts.map +1 -1
- package/dist/external/api/tests/createUserToken.test.d.ts +2 -0
- package/dist/external/api/tests/createUserToken.test.d.ts.map +1 -0
- package/dist/feed/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/group/utils/withUser.d.ts.map +1 -1
- package/dist/index.cjs.js +481 -200
- package/dist/index.esm.js +477 -200
- package/dist/index.umd.js +4 -4
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/utils/index.d.ts +3 -3
- package/dist/message/utils/index.d.ts.map +1 -1
- package/dist/poll/api/tests/closePoll.test.d.ts +2 -0
- package/dist/poll/api/tests/closePoll.test.d.ts.map +1 -0
- package/dist/poll/api/tests/createPoll.test.d.ts +2 -0
- package/dist/poll/api/tests/createPoll.test.d.ts.map +1 -0
- package/dist/poll/api/tests/getPoll.test.d.ts +2 -0
- package/dist/poll/api/tests/getPoll.test.d.ts.map +1 -0
- package/dist/poll/api/tests/votePoll.test.d.ts +2 -0
- package/dist/poll/api/tests/votePoll.test.d.ts.map +1 -0
- package/dist/post/api/approvePost.d.ts.map +1 -1
- package/dist/post/api/createPost.d.ts.map +1 -1
- package/dist/post/api/declinePost.d.ts.map +1 -1
- package/dist/post/api/deletePost.d.ts.map +1 -1
- package/dist/post/api/getPost.d.ts.map +1 -1
- package/dist/post/api/getPosts.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/api/updatePost.d.ts.map +1 -1
- package/dist/post/events/utils.d.ts.map +1 -1
- package/dist/reaction/api/queryReactions.d.ts.map +1 -1
- package/dist/reaction/api/removeReaction.d.ts.map +1 -1
- package/dist/reaction/events/onReactorAdded.d.ts.map +1 -1
- package/dist/reaction/events/onReactorRemoved.d.ts.map +1 -1
- package/dist/reaction/utils/dispatchReactable.d.ts +1 -1
- package/dist/reaction/utils/dispatchReactable.d.ts.map +1 -1
- package/dist/report/api/createReport.d.ts.map +1 -1
- package/dist/report/api/deleteReport.d.ts.map +1 -1
- package/dist/subChannel/utils/index.d.ts +1 -1
- package/dist/subChannel/utils/index.d.ts.map +1 -1
- package/dist/utils/index.d.ts +2 -2
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +31 -35
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +35 -84
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/feed.d.ts +2 -18
- package/dist/utils/tests/dummy/feed.d.ts.map +1 -1
- package/dist/utils/tests/dummy/member.d.ts +1 -1
- package/dist/utils/tests/dummy/post.d.ts +30 -29
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/dist/version.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/events.ts +22 -20
- package/src/@types/core/model.ts +3 -2
- package/src/@types/core/payload.ts +102 -38
- package/src/@types/domains/channel.ts +1 -1
- package/src/@types/domains/client.ts +1 -1
- package/src/@types/domains/comment.ts +7 -0
- package/src/@types/domains/community.ts +25 -0
- package/src/@types/domains/content.ts +9 -1
- package/src/@types/domains/group.ts +2 -2
- package/src/@types/global.ts +10 -0
- package/src/cache/api/ingestInCache.ts +3 -6
- package/src/cache/api/tests/ingestInCache.test.ts +12 -9
- package/src/channel/api/addChannelMembers.ts +5 -5
- package/src/channel/api/banChannelMembers.ts +1 -3
- package/src/channel/api/getChannel.ts +1 -1
- package/src/channel/api/queryChannelMembers.ts +1 -3
- package/src/channel/api/removeChannelMembers.ts +5 -5
- package/src/channel/api/tests/addChannelMembers.test.ts +4 -3
- package/src/channel/api/tests/createChannel.test.ts +5 -3
- package/src/channel/api/tests/getChannel.test.ts +2 -1
- package/src/channel/api/tests/joinChannel.test.ts +2 -2
- package/src/channel/api/tests/leaveChannel.test.ts +2 -2
- package/src/channel/api/tests/queryChannelMembers.test.ts +2 -5
- package/src/channel/api/tests/queryChannels.test.ts +4 -3
- package/src/channel/api/tests/removeChannelMembers.test.ts +16 -5
- package/src/channel/api/unbanChannelMembers.ts +1 -3
- package/src/channel/events/onChannelJoined.ts +1 -3
- package/src/channel/events/onChannelLeft.ts +1 -3
- package/src/channel/events/onChannelMemberAdded.ts +1 -3
- package/src/channel/events/onChannelMemberBanned.ts +1 -3
- package/src/channel/events/onChannelMemberRemoved.ts +1 -3
- package/src/channel/events/onChannelMemberUnbanned.ts +1 -3
- package/src/channel/observers/tests/liveChannelMembers.test.ts +5 -12
- package/src/channel/observers/tests/liveChannels.test.ts +3 -1
- package/src/channel/utils/index.ts +9 -6
- package/src/comment/api/createComment.ts +18 -2
- package/src/comment/api/deleteComment.ts +19 -2
- package/src/comment/api/tests/createComment.test.ts +169 -9
- package/src/comment/api/tests/updateComment.test.ts +189 -0
- package/src/comment/events/tests/onCommentCreated.test.ts +3 -3
- package/src/comment/events/tests/onCommentDeleted.test.ts +3 -3
- package/src/comment/observers/tests/liveComment.test.ts +18 -2
- package/src/community/api/addCommunityMembers.ts +6 -3
- package/src/community/api/addCommunityMembersRoles.ts +5 -2
- package/src/community/api/createCommunity.ts +5 -5
- package/src/community/api/deleteCommunity.ts +9 -1
- package/src/community/api/getCommunities.ts +2 -2
- package/src/community/api/getCommunity.ts +2 -2
- package/src/community/api/getRecommendedCommunities.ts +2 -2
- package/src/community/api/getTopTrendingCommunities.ts +2 -2
- package/src/community/api/joinCommunity.ts +6 -3
- package/src/community/api/leaveCommunity.ts +6 -3
- package/src/community/api/queryCommunities.ts +3 -3
- package/src/community/api/queryCommunityMembers.ts +3 -7
- package/src/community/api/removeCommunityMembers.ts +7 -3
- package/src/community/api/removeCommunityMembersRoles.ts +5 -2
- package/src/community/api/test/queryCommunityMembers.test.ts +2 -1
- package/src/community/api/test/removeCommunityMemberRole.test.ts +4 -1
- package/src/community/api/updateCommunity.ts +5 -5
- package/src/community/events/index.ts +2 -0
- package/src/community/events/onCommunityUserRoleAdded.ts +20 -0
- package/src/community/events/onCommunityUserRoleRemoved.ts +20 -0
- package/src/community/events/test/onCommunityDeleted.test.ts +8 -1
- package/src/community/events/test/onCommunityUserRoleAdded.test.ts +50 -0
- package/src/community/events/test/onCommunityUserRoleRemoved.test.ts +50 -0
- package/src/community/events/utils.ts +4 -8
- package/src/community/observers/index.ts +4 -0
- package/src/community/observers/liveCommunity.ts +45 -0
- package/src/community/observers/liveCommunityMembers.ts +187 -0
- package/src/community/observers/tests/liveCommunities.test.ts +38 -18
- package/src/community/observers/tests/liveCommunity.test.ts +147 -0
- package/src/community/observers/tests/liveCommunityMembers.test.ts +195 -0
- package/src/community/utils/payload.ts +28 -22
- package/src/core/device.ts +2 -4
- package/src/core/model/idResolvers.ts +4 -3
- package/src/core/model/identifyModel.ts +3 -3
- package/src/core/model/index.ts +1 -0
- package/src/core/query/query.ts +7 -0
- package/src/core/tests/query/query/runQuery.test.ts +8 -3
- package/src/core/tests/subscription.test.ts +80 -2
- package/src/external/api/tests/createUserToken.test.ts +29 -0
- package/src/feed/api/queryGlobalFeed.ts +8 -4
- package/src/group/utils/test/withUsers.test.ts +5 -5
- package/src/group/utils/withUser.ts +20 -14
- package/src/message/api/createMessage.ts +10 -9
- package/src/message/api/getMessage.ts +2 -2
- package/src/message/api/getMessages.ts +1 -1
- package/src/message/api/queryMessages.ts +2 -2
- package/src/message/api/tests/createMessage.test.ts +5 -1
- package/src/message/api/updateMessage.ts +1 -1
- package/src/message/events/onMessageCreated.ts +1 -1
- package/src/message/events/onMessageDeleted.ts +1 -1
- package/src/message/events/onMessageFetched.ts +1 -1
- package/src/message/events/onMessageFlagCleared.ts +1 -1
- package/src/message/events/onMessageFlagged.ts +1 -1
- package/src/message/events/onMessageReactionAdded.ts +1 -1
- package/src/message/events/onMessageReactionRemoved.ts +1 -1
- package/src/message/events/onMessageUnflagged.ts +1 -1
- package/src/message/events/onMessageUpdated.ts +1 -1
- package/src/message/tests/events.test.ts +10 -2
- package/src/message/tests/observers/liveMessage.test.ts +6 -1
- package/src/message/tests/observers/liveMessages.test.ts +16 -3
- package/src/message/utils/index.ts +5 -3
- package/src/poll/api/tests/closePoll.test.ts +50 -0
- package/src/poll/api/tests/createPoll.test.ts +70 -0
- package/src/poll/api/tests/getPoll.test.ts +31 -0
- package/src/poll/api/tests/votePoll.test.ts +41 -0
- package/src/poll/events/onPollDeleted.ts +1 -1
- package/src/poll/events/onPollUpdated.ts +1 -1
- package/src/post/api/approvePost.ts +10 -10
- package/src/post/api/createPost.ts +6 -3
- package/src/post/api/declinePost.ts +11 -11
- package/src/post/api/deletePost.ts +19 -2
- package/src/post/api/getPost.ts +5 -2
- package/src/post/api/getPosts.ts +4 -1
- package/src/post/api/queryPosts.ts +3 -1
- package/src/post/api/tests/queryPosts.test.ts +5 -4
- package/src/post/api/updatePost.ts +4 -1
- package/src/post/events/onPostReactionAdded.ts +1 -1
- package/src/post/events/onPostReactionRemoved.ts +1 -1
- package/src/post/events/utils.ts +12 -2
- package/src/post/observers/tests/livePost.test.ts +10 -3
- package/src/post/observers/tests/livePosts.test.ts +12 -4
- package/src/post/tests/api/getPost.test.ts +13 -3
- package/src/post/tests/api/queryPosts.test.ts +5 -4
- package/src/reaction/api/addReaction.ts +3 -3
- package/src/reaction/api/queryReactions.ts +2 -0
- package/src/reaction/api/removeReaction.ts +4 -3
- package/src/reaction/events/onReactionAdded.ts +3 -3
- package/src/reaction/events/onReactionRemoved.ts +3 -3
- package/src/reaction/events/onReactorAdded.ts +8 -2
- package/src/reaction/events/onReactorRemoved.ts +8 -2
- package/src/reaction/utils/dispatchReactable.ts +1 -1
- package/src/reaction/utils/fetchReference.ts +1 -1
- package/src/report/api/createReport.ts +14 -8
- package/src/report/api/deleteReport.ts +14 -8
- package/src/subChannel/api/createSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannel.ts +1 -1
- package/src/subChannel/api/getSubChannels.ts +1 -1
- package/src/subChannel/api/querySubChannels.ts +2 -2
- package/src/subChannel/api/updateSubChannel.ts +1 -1
- package/src/subChannel/events/onSubChannelCreated.ts +1 -1
- package/src/subChannel/events/onSubChannelDeleted.ts +1 -1
- package/src/subChannel/events/onSubChannelUpdated.ts +1 -1
- package/src/subChannel/utils/index.ts +2 -2
- package/src/user/observers/tests/liveUsers.test.ts +2 -0
- package/src/user/tests/api/getUser.test.ts +17 -3
- package/src/utils/index.ts +2 -2
- package/src/utils/liveObject.ts +1 -1
- package/src/utils/tests/dummy/channel.ts +18 -11
- package/src/utils/tests/dummy/community.ts +68 -6
- package/src/utils/tests/dummy/feed.ts +1 -1
- package/src/utils/tests/dummy/member.ts +1 -1
- package/src/utils/tests/dummy/post.ts +93 -9
- package/src/version.ts +9 -3
|
@@ -4,11 +4,13 @@ import {
|
|
|
4
4
|
client,
|
|
5
5
|
conversationChannelPayload,
|
|
6
6
|
liveChannelPayload,
|
|
7
|
+
rawChannelPayload,
|
|
7
8
|
} from '~/utils/tests';
|
|
8
9
|
import { prepareChannelPayload } from '~/channel/utils';
|
|
10
|
+
|
|
9
11
|
import { createChannel } from '../createChannel';
|
|
10
12
|
|
|
11
|
-
const resPayload = { data:
|
|
13
|
+
const resPayload = { data: rawChannelPayload };
|
|
12
14
|
|
|
13
15
|
describe('createChannel', () => {
|
|
14
16
|
// integration_test_id: 9d80fd54-9e6d-454d-8344-6f9436b8e495
|
|
@@ -18,7 +20,7 @@ describe('createChannel', () => {
|
|
|
18
20
|
const res = await createChannel({ type: 'community' });
|
|
19
21
|
|
|
20
22
|
expect(res).toBeDefined();
|
|
21
|
-
expect(res.data).toStrictEqual(prepareChannelPayload(
|
|
23
|
+
expect(res.data).toStrictEqual(prepareChannelPayload(rawChannelPayload).channels[0]);
|
|
22
24
|
});
|
|
23
25
|
|
|
24
26
|
// integration_test_id: cef520ab-027d-4c5b-836c-a7f63ddc5146
|
|
@@ -51,7 +53,7 @@ describe('createChannel', () => {
|
|
|
51
53
|
const data = pullFromCache(['channel', 'get', channelId]);
|
|
52
54
|
|
|
53
55
|
expect(data).toBeDefined();
|
|
54
|
-
expect(data?.data).toStrictEqual(prepareChannelPayload(
|
|
56
|
+
expect(data?.data).toStrictEqual(prepareChannelPayload(rawChannelPayload).channels[0]);
|
|
55
57
|
|
|
56
58
|
disableCache();
|
|
57
59
|
});
|
|
@@ -5,9 +5,10 @@ import { client, channelQueryResponse } from '~/utils/tests';
|
|
|
5
5
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
6
6
|
import { isInTombstone } from '~/cache/api/isInTombstone';
|
|
7
7
|
|
|
8
|
-
import { getChannel } from '../getChannel';
|
|
9
8
|
import { prepareChannelPayload } from '~/channel/utils';
|
|
10
9
|
|
|
10
|
+
import { getChannel } from '../getChannel';
|
|
11
|
+
|
|
11
12
|
const { channelId } = channelQueryResponse.data.channels[0];
|
|
12
13
|
const channel = prepareChannelPayload(channelQueryResponse.data).channels[0];
|
|
13
14
|
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
disconnectClient,
|
|
9
9
|
channel1,
|
|
10
10
|
user11,
|
|
11
|
-
rawChannelUser,
|
|
12
11
|
channelUserQueryResponse,
|
|
12
|
+
channelUser,
|
|
13
13
|
} from '~/utils/tests';
|
|
14
14
|
|
|
15
15
|
import { joinChannel } from '../joinChannel';
|
|
@@ -32,7 +32,7 @@ describe('joinChannel', () => {
|
|
|
32
32
|
test('it should update cache', async () => {
|
|
33
33
|
enableCache();
|
|
34
34
|
|
|
35
|
-
const expected =
|
|
35
|
+
const expected = channelUser;
|
|
36
36
|
client.http.post = jest.fn().mockResolvedValueOnce(channelUserQueryResponse);
|
|
37
37
|
|
|
38
38
|
const didJoinChannel = await joinChannel(channelId);
|
|
@@ -8,8 +8,8 @@ import {
|
|
|
8
8
|
disconnectClient,
|
|
9
9
|
channel1,
|
|
10
10
|
user11,
|
|
11
|
-
rawChannelUser,
|
|
12
11
|
channelUserQueryResponse,
|
|
12
|
+
channelUser,
|
|
13
13
|
} from '~/utils/tests';
|
|
14
14
|
|
|
15
15
|
import { leaveChannel } from '../leaveChannel';
|
|
@@ -32,7 +32,7 @@ describe('leaveChannel', () => {
|
|
|
32
32
|
test('it should update cache', async () => {
|
|
33
33
|
enableCache();
|
|
34
34
|
|
|
35
|
-
const expected =
|
|
35
|
+
const expected = channelUser;
|
|
36
36
|
client.http.delete = jest.fn().mockResolvedValueOnce(channelUserQueryResponse);
|
|
37
37
|
|
|
38
38
|
const didleaveChannel = await leaveChannel(channelId);
|
|
@@ -4,7 +4,6 @@ import { disableCache, enableCache, pushToCache } from '~/cache/api';
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
6
|
import { prepareChannelPayload } from '~/channel/utils';
|
|
7
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
8
7
|
import { client, channelUserQueryResponse, channelUserModel } from '~/utils/tests';
|
|
9
8
|
|
|
10
9
|
import { queryChannelMembers } from '../queryChannelMembers';
|
|
@@ -63,8 +62,7 @@ describe('queryChannelMembers.locally', () => {
|
|
|
63
62
|
enableCache();
|
|
64
63
|
|
|
65
64
|
const { paging, ...payload } = channelUserQueryResponse.data;
|
|
66
|
-
const
|
|
67
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
65
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
68
66
|
const { channelUsers } = preparedPayload;
|
|
69
67
|
|
|
70
68
|
ingestInCache(preparedPayload);
|
|
@@ -91,8 +89,7 @@ describe('queryChannelMembers.locally', () => {
|
|
|
91
89
|
enableCache();
|
|
92
90
|
|
|
93
91
|
const { paging, ...payload } = channelUserQueryResponse.data;
|
|
94
|
-
const
|
|
95
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
92
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
96
93
|
const { channelUsers } = preparedPayload;
|
|
97
94
|
|
|
98
95
|
// ingest incomplete data
|
|
@@ -126,11 +126,12 @@ describe('queryChannels.locally', () => {
|
|
|
126
126
|
enableCache();
|
|
127
127
|
|
|
128
128
|
const { data } = channelQueryResponse;
|
|
129
|
-
const {
|
|
129
|
+
const { paging, ...payload } = data;
|
|
130
|
+
const { channels: expected } = prepareChannelPayload(payload);
|
|
130
131
|
|
|
131
|
-
ingestInCache(data
|
|
132
|
+
ingestInCache(prepareChannelPayload(data));
|
|
132
133
|
|
|
133
|
-
pushToCache(cacheKey, { channels:
|
|
134
|
+
pushToCache(cacheKey, { channels: payload.channels.map(getResolver('channel')), paging });
|
|
134
135
|
|
|
135
136
|
const { data: received } = queryChannels.locally()!;
|
|
136
137
|
const received2 = queryChannels.locally({ displayName: 'test' })!;
|
|
@@ -8,12 +8,23 @@ import {
|
|
|
8
8
|
rawChannelUser,
|
|
9
9
|
rawChannelUser3,
|
|
10
10
|
channel1,
|
|
11
|
+
channelUser,
|
|
12
|
+
channelUser3,
|
|
13
|
+
connectClient,
|
|
14
|
+
disconnectClient,
|
|
11
15
|
} from '~/utils/tests';
|
|
12
16
|
|
|
13
17
|
import { onChannelMemberRemoved } from '~/channel/events';
|
|
18
|
+
|
|
14
19
|
import { removeChannelMembers } from '../removeChannelMembers';
|
|
15
20
|
|
|
16
21
|
describe('removeChannelMembers', () => {
|
|
22
|
+
beforeAll(connectClient);
|
|
23
|
+
afterAll(disconnectClient);
|
|
24
|
+
|
|
25
|
+
beforeEach(enableCache);
|
|
26
|
+
afterEach(disableCache);
|
|
27
|
+
|
|
17
28
|
const { channelId } = channelUserQueryResponse.data.channels[0];
|
|
18
29
|
const { userId } = rawChannelUser;
|
|
19
30
|
|
|
@@ -36,15 +47,15 @@ describe('removeChannelMembers', () => {
|
|
|
36
47
|
});
|
|
37
48
|
|
|
38
49
|
const recieved = await removeChannelMembers(channelId, [userId]);
|
|
39
|
-
const
|
|
50
|
+
const recievedCache = pullFromCache<Amity.Membership<'channel'>>([
|
|
40
51
|
'channelUsers',
|
|
41
52
|
'get',
|
|
42
53
|
channelUserCacheKey,
|
|
43
54
|
])?.data;
|
|
44
55
|
|
|
45
56
|
expect(recieved).toBe(true);
|
|
46
|
-
expect(
|
|
47
|
-
expect(
|
|
57
|
+
expect(recievedCache).toBeDefined();
|
|
58
|
+
expect(recievedCache).toEqual(channelUser);
|
|
48
59
|
|
|
49
60
|
disableCache();
|
|
50
61
|
});
|
|
@@ -81,8 +92,8 @@ describe('removeChannelMembers', () => {
|
|
|
81
92
|
* Assertion below is required to check if the event handler is called with the right
|
|
82
93
|
* params. It's not enough to check if the handler does not throw
|
|
83
94
|
*/
|
|
84
|
-
expect(callback).toHaveBeenNthCalledWith(1, channel1,
|
|
85
|
-
expect(callback).toHaveBeenNthCalledWith(2, channel1,
|
|
95
|
+
expect(callback).toHaveBeenNthCalledWith(1, channel1, channelUser);
|
|
96
|
+
expect(callback).toHaveBeenNthCalledWith(2, channel1, channelUser3);
|
|
86
97
|
|
|
87
98
|
unsub();
|
|
88
99
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { getActiveClient } from '~/client/api/activeClient';
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
|
-
import { prepareMembershipPayload, withUsers } from '~/group/utils';
|
|
5
4
|
|
|
6
5
|
import { prepareChannelPayload } from '../utils';
|
|
7
6
|
|
|
@@ -33,8 +32,7 @@ export const unbanChannelMembers = async (
|
|
|
33
32
|
},
|
|
34
33
|
);
|
|
35
34
|
|
|
36
|
-
const
|
|
37
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
35
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
38
36
|
|
|
39
37
|
const cachedAt = client.cache && Date.now();
|
|
40
38
|
if (client.cache) ingestInCache(preparedPayload, { cachedAt });
|
|
@@ -3,7 +3,6 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
7
6
|
import { prepareChannelPayload } from '../utils';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -27,8 +26,7 @@ export const onChannelJoined = (
|
|
|
27
26
|
const client = getActiveClient();
|
|
28
27
|
|
|
29
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
30
|
-
const
|
|
31
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
29
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
32
30
|
const { channels, channelUsers } = preparedPayload;
|
|
33
31
|
|
|
34
32
|
ingestInCache(preparedPayload);
|
|
@@ -3,7 +3,6 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
7
6
|
import { prepareChannelPayload } from '../utils';
|
|
8
7
|
|
|
9
8
|
/**
|
|
@@ -27,8 +26,7 @@ export const onChannelLeft = (
|
|
|
27
26
|
const client = getActiveClient();
|
|
28
27
|
|
|
29
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
30
|
-
const
|
|
31
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
29
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
32
30
|
const { channels, channelUsers } = preparedPayload;
|
|
33
31
|
|
|
34
32
|
ingestInCache(preparedPayload);
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
2
2
|
import { getActiveClient } from '~/client/api';
|
|
3
3
|
import { createEventSubscriber } from '~/core/events';
|
|
4
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
5
4
|
|
|
6
5
|
import { prepareChannelPayload } from '../utils';
|
|
7
6
|
|
|
@@ -26,8 +25,7 @@ export const onChannelMemberAdded = (
|
|
|
26
25
|
const client = getActiveClient();
|
|
27
26
|
|
|
28
27
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
29
|
-
const
|
|
30
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
28
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
31
29
|
const { channels, channelUsers } = preparedPayload;
|
|
32
30
|
|
|
33
31
|
ingestInCache(preparedPayload);
|
|
@@ -2,7 +2,6 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
5
|
|
|
7
6
|
import { prepareChannelPayload } from '../utils';
|
|
8
7
|
|
|
@@ -27,8 +26,7 @@ export const onChannelMemberBanned = (
|
|
|
27
26
|
const client = getActiveClient();
|
|
28
27
|
|
|
29
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
30
|
-
const
|
|
31
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
29
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
32
30
|
const { channels, channelUsers } = preparedPayload;
|
|
33
31
|
|
|
34
32
|
ingestInCache(preparedPayload);
|
|
@@ -2,7 +2,6 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
5
|
|
|
7
6
|
import { prepareChannelPayload } from '../utils';
|
|
8
7
|
|
|
@@ -27,8 +26,7 @@ export const onChannelMemberRemoved = (
|
|
|
27
26
|
const client = getActiveClient();
|
|
28
27
|
|
|
29
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
30
|
-
const
|
|
31
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
29
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
32
30
|
const { channels, channelUsers } = preparedPayload;
|
|
33
31
|
|
|
34
32
|
ingestInCache(preparedPayload);
|
|
@@ -2,7 +2,6 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
import { createEventSubscriber } from '~/core/events';
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
6
5
|
|
|
7
6
|
import { prepareChannelPayload } from '../utils';
|
|
8
7
|
|
|
@@ -27,8 +26,7 @@ export const onChannelMemberUnbanned = (
|
|
|
27
26
|
const client = getActiveClient();
|
|
28
27
|
|
|
29
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
30
|
-
const
|
|
31
|
-
const preparedPayload = prepareMembershipPayload(channelPayload, 'channelUsers');
|
|
29
|
+
const preparedPayload = prepareChannelPayload(payload);
|
|
32
30
|
const { channels, channelUsers } = preparedPayload;
|
|
33
31
|
|
|
34
32
|
ingestInCache(preparedPayload);
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { disableCache, enableCache } from '~/cache/api';
|
|
2
|
-
import { prepareMembershipPayload } from '~/group/utils';
|
|
3
2
|
import {
|
|
4
3
|
bannedChannelUser,
|
|
5
4
|
channel1,
|
|
@@ -24,12 +23,13 @@ import {
|
|
|
24
23
|
user13,
|
|
25
24
|
user14,
|
|
26
25
|
} from '~/utils/tests';
|
|
26
|
+
|
|
27
27
|
import { liveChannelMembers } from '../liveChannelMembers';
|
|
28
28
|
import { prepareChannelPayload } from '../../utils';
|
|
29
29
|
|
|
30
30
|
const getSnapshot = (params?: Record<string, any>) => {
|
|
31
31
|
return {
|
|
32
|
-
data: [] as Amity.
|
|
32
|
+
data: [] as Amity.RawMembership<'channel'>[],
|
|
33
33
|
loading: true,
|
|
34
34
|
error: undefined as any,
|
|
35
35
|
...params,
|
|
@@ -117,15 +117,8 @@ describe('liveChannelMembers', () => {
|
|
|
117
117
|
onNextPage();
|
|
118
118
|
await pause();
|
|
119
119
|
|
|
120
|
-
const payload =
|
|
121
|
-
|
|
122
|
-
'channelUsers',
|
|
123
|
-
);
|
|
124
|
-
|
|
125
|
-
const payload2 = prepareMembershipPayload(
|
|
126
|
-
prepareChannelPayload(channelUserQueryResponsePage2.data),
|
|
127
|
-
'channelUsers',
|
|
128
|
-
);
|
|
120
|
+
const payload = prepareChannelPayload(channelUserQueryResponse.data);
|
|
121
|
+
const payload2 = prepareChannelPayload(channelUserQueryResponsePage2.data);
|
|
129
122
|
|
|
130
123
|
const snapshot = getSnapshot();
|
|
131
124
|
snapshot.loading = false;
|
|
@@ -137,7 +130,7 @@ describe('liveChannelMembers', () => {
|
|
|
137
130
|
const events: [
|
|
138
131
|
string,
|
|
139
132
|
keyof Amity.Events,
|
|
140
|
-
Amity.
|
|
133
|
+
Amity.RawMembership<'channel'>,
|
|
141
134
|
Amity.User,
|
|
142
135
|
Amity.Membership<'channel'>[],
|
|
143
136
|
][] = [
|
|
@@ -198,7 +198,7 @@ describe('liveChannels', () => {
|
|
|
198
198
|
describe('events', () => {
|
|
199
199
|
const rawNewChannel = generateRawChannel({ channelId: 'new-channel-id' });
|
|
200
200
|
|
|
201
|
-
const cases: [string, keyof Amity.Events, Amity.
|
|
201
|
+
const cases: [string, keyof Amity.Events, Amity.RawChannel, Amity.Channel[]][] = [
|
|
202
202
|
[
|
|
203
203
|
'it should add new channel to collection onCreate',
|
|
204
204
|
'channel.created',
|
|
@@ -445,6 +445,8 @@ describe('liveChannels', () => {
|
|
|
445
445
|
segment: channelRaw1.messageCount + 1,
|
|
446
446
|
}),
|
|
447
447
|
],
|
|
448
|
+
files: [],
|
|
449
|
+
users: [],
|
|
448
450
|
});
|
|
449
451
|
await pause(500);
|
|
450
452
|
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { pullFromCache } from '~/cache/api';
|
|
2
|
+
import { withUsers } from '~/group/utils';
|
|
2
3
|
|
|
3
4
|
export function convertFromRaw(
|
|
4
|
-
{ _id, ...rest }: Amity.
|
|
5
|
+
{ _id, ...rest }: Amity.RawChannel,
|
|
5
6
|
params: Pick<
|
|
6
7
|
Amity.Channel,
|
|
7
8
|
| 'defaultSubChannelHasUnreadMention'
|
|
@@ -17,7 +18,7 @@ export function convertFromRaw(
|
|
|
17
18
|
};
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
function getSegmentParams(rawChannel: Amity.
|
|
21
|
+
function getSegmentParams(rawChannel: Amity.RawChannel) {
|
|
21
22
|
let cached;
|
|
22
23
|
|
|
23
24
|
try {
|
|
@@ -44,11 +45,13 @@ function getSegmentParams(rawChannel: Amity.ChannelRaw) {
|
|
|
44
45
|
}
|
|
45
46
|
|
|
46
47
|
export const prepareChannelPayload = (
|
|
47
|
-
|
|
48
|
-
): Amity.
|
|
49
|
-
const channels: Amity.Channel[] =
|
|
48
|
+
rawPayload: Amity.ChannelPayload,
|
|
49
|
+
): Amity.ProcessedChannelPayload => {
|
|
50
|
+
const channels: Amity.Channel[] = rawPayload.channels.map(channel =>
|
|
50
51
|
convertFromRaw(channel, getSegmentParams(channel)),
|
|
51
52
|
);
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
const channelUsers: Amity.Membership<'channel'>[] = withUsers(rawPayload.channelUsers);
|
|
55
|
+
|
|
56
|
+
return { ...rawPayload, channels, channelUsers };
|
|
54
57
|
};
|
|
@@ -22,7 +22,13 @@ import { getPost } from '~/post/api/getPost';
|
|
|
22
22
|
export const createComment = async (
|
|
23
23
|
bundle: Pick<
|
|
24
24
|
Amity.Comment<Amity.CommentContentType>,
|
|
25
|
-
|
|
25
|
+
| 'data'
|
|
26
|
+
| 'referenceType'
|
|
27
|
+
| 'referenceId'
|
|
28
|
+
| 'parentId'
|
|
29
|
+
| 'metadata'
|
|
30
|
+
| 'mentionees'
|
|
31
|
+
| 'attachments'
|
|
26
32
|
>,
|
|
27
33
|
): Promise<Amity.Cached<Amity.Comment>> => {
|
|
28
34
|
const client = getActiveClient();
|
|
@@ -35,7 +41,17 @@ export const createComment = async (
|
|
|
35
41
|
|
|
36
42
|
const post = await getPost(bundle.referenceId);
|
|
37
43
|
|
|
38
|
-
fireEvent('post.updated', {
|
|
44
|
+
fireEvent('post.updated', {
|
|
45
|
+
posts: [post.data],
|
|
46
|
+
categories: [],
|
|
47
|
+
comments: [],
|
|
48
|
+
communities: [],
|
|
49
|
+
communityUsers: [],
|
|
50
|
+
feeds: [],
|
|
51
|
+
files: [],
|
|
52
|
+
postChildren: [],
|
|
53
|
+
users: [],
|
|
54
|
+
});
|
|
39
55
|
fireEvent('comment.created', data);
|
|
40
56
|
|
|
41
57
|
const { comments } = data;
|
|
@@ -6,6 +6,7 @@ import { fireEvent } from '~/core/events';
|
|
|
6
6
|
import { getPost } from '~/post/api/getPost';
|
|
7
7
|
import { pushToTombstone } from '~/cache/api/pushToTombstone';
|
|
8
8
|
import { scheduleTask } from '~/core/microtasks';
|
|
9
|
+
|
|
9
10
|
import { getComment } from './getComment';
|
|
10
11
|
|
|
11
12
|
/**
|
|
@@ -47,8 +48,24 @@ export const deleteComment = async (
|
|
|
47
48
|
|
|
48
49
|
const post = await getPost(comment.data.referenceId);
|
|
49
50
|
|
|
50
|
-
fireEvent('post.updated', {
|
|
51
|
-
|
|
51
|
+
fireEvent('post.updated', {
|
|
52
|
+
posts: [post.data],
|
|
53
|
+
categories: [],
|
|
54
|
+
comments: [],
|
|
55
|
+
communities: [],
|
|
56
|
+
communityUsers: [],
|
|
57
|
+
feeds: [],
|
|
58
|
+
files: [],
|
|
59
|
+
postChildren: [],
|
|
60
|
+
users: [],
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
fireEvent('comment.deleted', {
|
|
64
|
+
comments: [deleted],
|
|
65
|
+
commentChildren: [],
|
|
66
|
+
files: [],
|
|
67
|
+
users: [],
|
|
68
|
+
});
|
|
52
69
|
|
|
53
70
|
if (permanent) {
|
|
54
71
|
scheduleTask(() => pushToTombstone('comment', commentId));
|