@amityco/ts-sdk 0.0.1-beta.41.1 → 0.0.1-beta.42.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/model.d.ts +3 -1
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/domains/category.d.ts +1 -1
- package/dist/@types/domains/category.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 +1 -1
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +1 -1
- package/dist/@types/domains/message.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/subChannel.d.ts +1 -1
- package/dist/@types/domains/subChannel.d.ts.map +1 -1
- package/dist/cache/utils/index.d.ts +1 -0
- package/dist/cache/utils/index.d.ts.map +1 -1
- package/dist/category/api/queryCategories.d.ts.map +1 -1
- package/dist/category/observers/liveCategories.d.ts.map +1 -1
- package/dist/channel/observers/liveChannel.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts.map +1 -1
- package/dist/comment/api/queryComments.d.ts.map +1 -1
- package/dist/comment/api/tests/queryComments.test.d.ts +2 -0
- package/dist/comment/api/tests/queryComments.test.d.ts.map +1 -0
- package/dist/comment/observers/liveComments.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/observers/liveCommunities.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/identifyModel.d.ts.map +1 -1
- package/dist/core/model/index.d.ts +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/follow/api/getFollowInfo.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +1 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowInfo.d.ts +21 -0
- package/dist/follow/observers/liveFollowInfo.d.ts.map +1 -0
- package/dist/follow/observers/tests/liveFollowInfo.test.d.ts +2 -0
- package/dist/follow/observers/tests/liveFollowInfo.test.d.ts.map +1 -0
- package/dist/index.cjs.js +112 -63
- package/dist/index.esm.js +112 -64
- package/dist/index.umd.js +4 -4
- package/dist/message/api/createMessage.d.ts +2 -1
- package/dist/message/api/createMessage.d.ts.map +1 -1
- package/dist/message/observers/liveMessages.d.ts.map +1 -1
- package/dist/message/utils/index.d.ts +3 -2
- package/dist/message/utils/index.d.ts.map +1 -1
- package/dist/post/api/queryPosts.d.ts.map +1 -1
- package/dist/post/observers/livePosts.d.ts.map +1 -1
- package/dist/subChannel/api/querySubChannels.d.ts.map +1 -1
- package/dist/subChannel/observers/liveSubChannels.d.ts.map +1 -1
- package/dist/utils/constants.d.ts +1 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/liveObject.d.ts +1 -1
- package/dist/utils/liveObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/comment.d.ts +77 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -0
- package/dist/utils/tests/dummy/community.d.ts +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts +0 -12
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/model.ts +3 -1
- package/src/@types/domains/category.ts +1 -1
- package/src/@types/domains/comment.ts +1 -1
- package/src/@types/domains/community.ts +1 -1
- package/src/@types/domains/message.ts +1 -1
- package/src/@types/domains/post.ts +1 -1
- package/src/@types/domains/subChannel.ts +1 -1
- package/src/cache/utils/index.ts +5 -2
- package/src/category/api/queryCategories.ts +2 -1
- package/src/category/observers/liveCategories.ts +3 -1
- package/src/category/observers/tests/liveCategories.test.ts +1 -3
- package/src/channel/api/tests/addChannelMembers.test.ts +13 -0
- package/src/channel/api/tests/queryChannelMembers.test.ts +1 -0
- package/src/channel/api/tests/removeChannelMembers.test.ts +9 -2
- package/src/channel/observers/liveChannel.ts +16 -1
- package/src/channel/observers/liveChannels.ts +11 -9
- package/src/comment/api/queryComments.ts +2 -1
- package/src/comment/api/tests/createComment.test.ts +17 -112
- package/src/comment/api/tests/queryComments.test.ts +147 -0
- package/src/comment/api/tests/updateComment.test.ts +14 -85
- package/src/comment/observers/liveComments.ts +12 -7
- package/src/community/api/queryCommunities.ts +2 -1
- package/src/community/api/test/queryCommunity.test.ts +30 -0
- package/src/community/observers/liveCommunities.ts +13 -7
- package/src/community/observers/tests/liveCommunities.test.ts +2 -2
- package/src/core/model/idResolvers.ts +1 -0
- package/src/core/model/identifyModel.ts +2 -1
- package/src/core/model/index.ts +11 -2
- package/src/follow/api/getFollowInfo.ts +4 -8
- package/src/follow/observers/index.ts +1 -0
- package/src/follow/observers/liveFollowInfo.ts +29 -0
- package/src/follow/observers/tests/liveFollowInfo.test.ts +198 -0
- package/src/message/api/createMessage.ts +17 -5
- package/src/message/api/tests/createMessage.test.ts +36 -5
- package/src/message/api/tests/deleteMessage.test.ts +10 -3
- package/src/message/api/tests/getMessage.test.ts +9 -3
- package/src/message/api/tests/queryMessages.test.ts +30 -0
- package/src/message/api/tests/updateMessage.test.ts +9 -2
- package/src/message/observers/liveMessages.ts +15 -15
- package/src/message/tests/observers/liveMessages.test.ts +2 -2
- package/src/message/utils/index.ts +10 -1
- package/src/post/api/queryPosts.ts +2 -1
- package/src/post/api/tests/queryPosts.test.ts +30 -0
- package/src/post/observers/livePosts.ts +16 -11
- package/src/post/observers/tests/livePosts.test.ts +4 -5
- package/src/reaction/api/tests/addReaction.test.ts +13 -0
- package/src/reaction/api/tests/removeReaction.test.ts +13 -0
- package/src/subChannel/api/querySubChannels.ts +2 -1
- package/src/subChannel/observers/liveSubChannels.ts +6 -5
- package/src/subChannel/observers/tests/liveSubChannels.test.ts +5 -2
- package/src/utils/constants.ts +2 -1
- package/src/utils/liveObject.ts +1 -4
- package/src/utils/tests/dummy/comment.ts +268 -0
- package/src/utils/tests/dummy/index.ts +1 -0
- package/src/utils/tests/dummy/post.ts +0 -114
- package/dist/post/tests/api/getPost.test.d.ts +0 -2
- package/dist/post/tests/api/getPost.test.d.ts.map +0 -1
- package/dist/post/tests/api/queryPosts.test.d.ts +0 -2
- package/dist/post/tests/api/queryPosts.test.d.ts.map +0 -1
- package/src/post/tests/api/getPost.test.ts +0 -98
- package/src/post/tests/api/queryPosts.test.ts +0 -123
|
@@ -65,6 +65,36 @@ describe('queryPosts', () => {
|
|
|
65
65
|
|
|
66
66
|
disableCache();
|
|
67
67
|
});
|
|
68
|
+
|
|
69
|
+
test('it should set isDeleted to undefined if includeDeleted is true', async () => {
|
|
70
|
+
const mockFn = jest.fn();
|
|
71
|
+
client.http.get = mockFn.mockResolvedValue(postQueryResponse);
|
|
72
|
+
|
|
73
|
+
await queryPosts({ ...params, includeDeleted: true });
|
|
74
|
+
|
|
75
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
76
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBeUndefined();
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
test('it should set isDeleted to false if includeDeleted is false', async () => {
|
|
80
|
+
const mockFn = jest.fn();
|
|
81
|
+
client.http.get = mockFn.mockResolvedValue(postQueryResponse);
|
|
82
|
+
|
|
83
|
+
await queryPosts({ ...params, includeDeleted: false });
|
|
84
|
+
|
|
85
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
86
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBe(false);
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
test('it should set isDeleted to undefined if includeDeleted is undefined', async () => {
|
|
90
|
+
const mockFn = jest.fn();
|
|
91
|
+
client.http.get = mockFn.mockResolvedValue(postQueryResponse);
|
|
92
|
+
|
|
93
|
+
await queryPosts({ ...params, includeDeleted: true });
|
|
94
|
+
|
|
95
|
+
expect(mockFn.mock.lastCall).toHaveLength(2);
|
|
96
|
+
expect(mockFn.mock.lastCall[1].params.isDeleted).toBeUndefined();
|
|
97
|
+
});
|
|
68
98
|
});
|
|
69
99
|
|
|
70
100
|
describe('queryPosts.locally', () => {
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/* eslint-disable no-use-before-define */
|
|
2
2
|
import { getResolver } from '~/core/model';
|
|
3
3
|
import { getActiveClient } from '~/client/api';
|
|
4
|
-
import {
|
|
4
|
+
import { dropFromCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
5
|
+
|
|
5
6
|
import {
|
|
6
7
|
createQuery,
|
|
7
|
-
runQuery,
|
|
8
|
-
queryOptions,
|
|
9
|
-
filterByPropEquality,
|
|
10
8
|
filterByFeedType,
|
|
9
|
+
filterByPropEquality,
|
|
10
|
+
queryOptions,
|
|
11
|
+
runQuery,
|
|
11
12
|
sortByFirstCreated,
|
|
12
13
|
sortByLastCreated,
|
|
13
14
|
} from '~/core/query';
|
|
@@ -18,16 +19,17 @@ import {
|
|
|
18
19
|
ENABLE_CACHE_MESSAGE,
|
|
19
20
|
} from '~/utils/constants';
|
|
20
21
|
|
|
22
|
+
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
21
23
|
import {
|
|
22
|
-
onPostCreated,
|
|
23
|
-
onPostUpdated,
|
|
24
|
-
onPostDeleted,
|
|
25
24
|
onPostApproved,
|
|
25
|
+
onPostCreated,
|
|
26
26
|
onPostDeclined,
|
|
27
|
+
onPostDeleted,
|
|
27
28
|
onPostFlagged,
|
|
28
|
-
onPostUnflagged,
|
|
29
29
|
onPostReactionAdded,
|
|
30
30
|
onPostReactionRemoved,
|
|
31
|
+
onPostUnflagged,
|
|
32
|
+
onPostUpdated,
|
|
31
33
|
} from '../events';
|
|
32
34
|
import { queryPosts } from '../api';
|
|
33
35
|
|
|
@@ -84,11 +86,13 @@ export const livePosts = (
|
|
|
84
86
|
.filter(Boolean)
|
|
85
87
|
.map(({ data }) => data) ?? [];
|
|
86
88
|
|
|
87
|
-
posts = filterByPropEquality(posts, 'isDeleted', params.isDeleted);
|
|
88
|
-
|
|
89
89
|
const sortBy = params.sortBy ? params.sortBy : 'lastCreated';
|
|
90
90
|
posts = posts.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
91
91
|
|
|
92
|
+
if (params.includeDeleted === false) {
|
|
93
|
+
posts = filterByPropEquality(posts, 'isDeleted', false);
|
|
94
|
+
}
|
|
95
|
+
|
|
92
96
|
if (params.tags) {
|
|
93
97
|
posts = posts.filter(p => p.tags?.some(t => params.tags?.includes(t)));
|
|
94
98
|
}
|
|
@@ -157,7 +161,7 @@ export const livePosts = (
|
|
|
157
161
|
|
|
158
162
|
responder(data);
|
|
159
163
|
},
|
|
160
|
-
queryOptions(policy),
|
|
164
|
+
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
161
165
|
);
|
|
162
166
|
};
|
|
163
167
|
|
|
@@ -179,5 +183,6 @@ export const livePosts = (
|
|
|
179
183
|
return () => {
|
|
180
184
|
log(`livePosts(tmpid: ${timestamp}) > dispose`);
|
|
181
185
|
disposers.forEach(fn => fn());
|
|
186
|
+
dropFromCache(cacheKey);
|
|
182
187
|
};
|
|
183
188
|
};
|
|
@@ -65,8 +65,7 @@ describe('livePosts', () => {
|
|
|
65
65
|
});
|
|
66
66
|
|
|
67
67
|
const filters: [string, Amity.PostLiveCollection, number?][] = [
|
|
68
|
-
['not deleted', { ...params,
|
|
69
|
-
['deleted', { ...params, isDeleted: true }, 1],
|
|
68
|
+
['not deleted', { ...params, includeDeleted: false }],
|
|
70
69
|
['tags', { ...params, tags: ['test_tag'] }, 1],
|
|
71
70
|
];
|
|
72
71
|
|
|
@@ -153,7 +152,7 @@ describe('livePosts', () => {
|
|
|
153
152
|
'it should remove post in collection onDelete',
|
|
154
153
|
'post.deleted',
|
|
155
154
|
{ ...post11, isDeleted: true },
|
|
156
|
-
{ ...params,
|
|
155
|
+
{ ...params, includeDeleted: false },
|
|
157
156
|
],
|
|
158
157
|
['it should remove post in collection onDeclined', 'post.declined', post11, params],
|
|
159
158
|
];
|
|
@@ -266,10 +265,10 @@ describe('livePosts', () => {
|
|
|
266
265
|
const callback = jest.fn();
|
|
267
266
|
client.http.get = jest.fn().mockResolvedValue(postQueryResponsePage2);
|
|
268
267
|
|
|
269
|
-
livePosts({ ...params,
|
|
268
|
+
livePosts({ ...params, includeDeleted: true }, callback);
|
|
270
269
|
|
|
271
270
|
await pause();
|
|
272
|
-
const payload = postQueryResponsePage2.data.posts
|
|
271
|
+
const payload = postQueryResponsePage2.data.posts;
|
|
273
272
|
const snapshot = getSnapshot();
|
|
274
273
|
|
|
275
274
|
snapshot.data = payload;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASCApiError } from '~/core/errors';
|
|
1
2
|
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
3
|
|
|
3
4
|
import { onMessageUpdated } from '~/message/events';
|
|
@@ -9,6 +10,7 @@ import { UNSYNCED_OBJECT_CACHED_AT_VALUE } from '~/utils/constants';
|
|
|
9
10
|
const cacheKey = ['message', 'get', message.messageId];
|
|
10
11
|
|
|
11
12
|
describe('addReaction', () => {
|
|
13
|
+
// integration_test_id: 6252e6ed-afd7-460f-a285-f95650ec513a
|
|
12
14
|
test('it should add a reaction', async () => {
|
|
13
15
|
client.http.post = jest.fn().mockResolvedValue({ data: { addedId: 'reactionId' } });
|
|
14
16
|
|
|
@@ -17,6 +19,17 @@ describe('addReaction', () => {
|
|
|
17
19
|
expect(success).toEqual(true);
|
|
18
20
|
});
|
|
19
21
|
|
|
22
|
+
// integration_test_id: ddc6da15-cfa3-4f54-ad52-be50c2841d6e
|
|
23
|
+
test('it should throw 400400 when resource not found', async () => {
|
|
24
|
+
client.http.post = jest
|
|
25
|
+
.fn()
|
|
26
|
+
.mockRejectedValueOnce(
|
|
27
|
+
new ASCApiError('not found!', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
await expect(addReaction('message', message.messageId, 'like')).rejects.toThrow();
|
|
31
|
+
});
|
|
32
|
+
|
|
20
33
|
test('it should update cache after adding reaction', async () => {
|
|
21
34
|
enableCache();
|
|
22
35
|
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { ASCApiError } from '~/core/errors';
|
|
1
2
|
import { disableCache, enableCache, pullFromCache, pushToCache } from '~/cache/api';
|
|
2
3
|
|
|
3
4
|
import { onMessageUpdated } from '~/message/events';
|
|
@@ -15,6 +16,7 @@ const message = {
|
|
|
15
16
|
const cacheKey = ['message', 'get', message.messageId];
|
|
16
17
|
|
|
17
18
|
describe('removeReaction', () => {
|
|
19
|
+
// integration_test_id: dda62dbf-7649-4f1e-b264-0f79984ae1c8
|
|
18
20
|
test('it should remove a reaction', async () => {
|
|
19
21
|
client.http.delete = jest.fn().mockResolvedValue({ data: { removedId: 'reactionId' } });
|
|
20
22
|
|
|
@@ -23,6 +25,17 @@ describe('removeReaction', () => {
|
|
|
23
25
|
expect(success).toEqual(true);
|
|
24
26
|
});
|
|
25
27
|
|
|
28
|
+
// integration_test_id: b5ab2716-044c-488a-839e-4a7517e58ca9
|
|
29
|
+
test('it should throw 400400 when resource not found', async () => {
|
|
30
|
+
client.http.delete = jest
|
|
31
|
+
.fn()
|
|
32
|
+
.mockRejectedValueOnce(
|
|
33
|
+
new ASCApiError('not found!', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
await expect(removeReaction('message', message.messageId, 'like')).rejects.toThrow();
|
|
37
|
+
});
|
|
38
|
+
|
|
26
39
|
test('it should update cache after adding reaction', async () => {
|
|
27
40
|
enableCache();
|
|
28
41
|
|
|
@@ -29,13 +29,14 @@ export const querySubChannels = async (
|
|
|
29
29
|
const client = getActiveClient();
|
|
30
30
|
client.log('channel/querySubChannels', query);
|
|
31
31
|
|
|
32
|
-
const { page = { limit: 10 }, channelId, ...params } = convertQueryParams(query);
|
|
32
|
+
const { page = { limit: 10 }, channelId, includeDeleted, ...params } = convertQueryParams(query);
|
|
33
33
|
|
|
34
34
|
const response = await client.http.get<Amity.SubChannelPayload & Amity.Pagination>(
|
|
35
35
|
`/api/v5/message-feeds/channel/${channelId}`,
|
|
36
36
|
{
|
|
37
37
|
params: {
|
|
38
38
|
...params,
|
|
39
|
+
isDeleted: includeDeleted === false ? false : undefined,
|
|
39
40
|
options: {
|
|
40
41
|
token: toToken(page, 'skiplimit'),
|
|
41
42
|
},
|
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
import { getActiveClient } from '~/client/api';
|
|
3
3
|
import {
|
|
4
4
|
createQuery,
|
|
5
|
-
runQuery,
|
|
6
|
-
queryOptions,
|
|
7
5
|
filterByPropEquality,
|
|
6
|
+
queryOptions,
|
|
7
|
+
runQuery,
|
|
8
8
|
sortByLastActivity,
|
|
9
9
|
} from '~/core/query';
|
|
10
10
|
import {
|
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
} from '~/utils/constants';
|
|
15
15
|
import { onSubChannelFetched } from '~/subChannel/events/onSubChannelFetched';
|
|
16
16
|
import { isCollectionOutdated, merge } from '~/utils';
|
|
17
|
+
import { CACHE_SHORTEN_LIFESPAN } from '~/cache/utils';
|
|
17
18
|
import { onSubChannelCreated, onSubChannelDeleted, onSubChannelUpdated } from '../events';
|
|
18
19
|
import { querySubChannels } from '../api';
|
|
19
20
|
|
|
@@ -58,8 +59,8 @@ export const liveSubChannels = (
|
|
|
58
59
|
const responder = (data: Amity.SubChannelLiveCollectionCache) => {
|
|
59
60
|
let subChannels: Amity.SubChannel[] = data.data;
|
|
60
61
|
|
|
61
|
-
if (params.
|
|
62
|
-
subChannels = filterByPropEquality(subChannels, 'isDeleted',
|
|
62
|
+
if (params.includeDeleted === false) {
|
|
63
|
+
subChannels = filterByPropEquality(subChannels, 'isDeleted', false);
|
|
63
64
|
}
|
|
64
65
|
|
|
65
66
|
subChannels.sort(sortByLastActivity);
|
|
@@ -117,7 +118,7 @@ export const liveSubChannels = (
|
|
|
117
118
|
|
|
118
119
|
responder(snapshot);
|
|
119
120
|
},
|
|
120
|
-
queryOptions(policy),
|
|
121
|
+
queryOptions(policy, CACHE_SHORTEN_LIFESPAN),
|
|
121
122
|
);
|
|
122
123
|
};
|
|
123
124
|
|
|
@@ -68,7 +68,7 @@ describe('liveSubChannels', () => {
|
|
|
68
68
|
},
|
|
69
69
|
});
|
|
70
70
|
|
|
71
|
-
liveSubChannels({ channelId: rawSubChannel.channelPublicId,
|
|
71
|
+
liveSubChannels({ channelId: rawSubChannel.channelPublicId, includeDeleted: false }, callback);
|
|
72
72
|
await pause();
|
|
73
73
|
|
|
74
74
|
expect(callback).toHaveBeenCalledTimes(2);
|
|
@@ -178,7 +178,10 @@ describe('liveSubChannels', () => {
|
|
|
178
178
|
const callback = jest.fn();
|
|
179
179
|
client.http.get = jest.fn().mockResolvedValue(response);
|
|
180
180
|
|
|
181
|
-
liveSubChannels(
|
|
181
|
+
liveSubChannels(
|
|
182
|
+
{ channelId: rawSubChannel.channelPublicId, includeDeleted: false },
|
|
183
|
+
callback,
|
|
184
|
+
);
|
|
182
185
|
await pause();
|
|
183
186
|
if (event === 'local.message-feed.fetched') {
|
|
184
187
|
pushToCache(
|
package/src/utils/constants.ts
CHANGED
|
@@ -6,5 +6,6 @@ export const LIVE_OBJECT_ENABLE_CACHE_MESSAGE =
|
|
|
6
6
|
export const UNSYNCED_OBJECT_CACHED_AT_MESSAGE =
|
|
7
7
|
'Observing unsynced object is not supported by Live Object.';
|
|
8
8
|
export const UNSYNCED_OBJECT_CACHED_AT_VALUE = -5;
|
|
9
|
-
export const
|
|
9
|
+
export const SECOND = 1000;
|
|
10
|
+
export const MINUTE = 60 * SECOND;
|
|
10
11
|
export const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
package/src/utils/liveObject.ts
CHANGED
|
@@ -8,10 +8,7 @@ import { hasUpdates } from '~/core/model';
|
|
|
8
8
|
import { createQuery, runQuery } from '~/core/query';
|
|
9
9
|
import { ASCApiError } from '~/core/errors';
|
|
10
10
|
|
|
11
|
-
export const liveObject = <
|
|
12
|
-
T extends Exclude<Amity.Models[Amity.Domain], Amity.Reaction | Amity.FollowCount>,
|
|
13
|
-
K extends keyof T,
|
|
14
|
-
>(
|
|
11
|
+
export const liveObject = <T extends Amity.Models[Amity.Domain], K extends keyof T>(
|
|
15
12
|
id: T[K],
|
|
16
13
|
callback: Amity.LiveObjectCallback<T>,
|
|
17
14
|
key: K,
|
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
import { createComment, queryComments } from '~/comment/api';
|
|
2
|
+
import { file11 } from './file';
|
|
3
|
+
import { post11, post12 } from './post';
|
|
4
|
+
import { user11, user12 } from './user';
|
|
5
|
+
|
|
6
|
+
export function generateComment(params?: Partial<Amity.Comment>): Amity.Comment {
|
|
7
|
+
return {
|
|
8
|
+
path: '',
|
|
9
|
+
referenceType: 'post',
|
|
10
|
+
dataType: 'text',
|
|
11
|
+
dataTypes: ['text'],
|
|
12
|
+
rootId: 'test',
|
|
13
|
+
data: {
|
|
14
|
+
text: 'yellow new world',
|
|
15
|
+
},
|
|
16
|
+
childrenNumber: 0,
|
|
17
|
+
isDeleted: false,
|
|
18
|
+
editedAt: '2022-10-31T05:57:45.661Z',
|
|
19
|
+
updatedAt: '2022-10-31T05:57:45.670Z',
|
|
20
|
+
createdAt: '2022-10-31T05:57:45.661Z',
|
|
21
|
+
segmentNumber: 2,
|
|
22
|
+
commentId: 'comment11',
|
|
23
|
+
userId: 'test',
|
|
24
|
+
referenceId: 'postId11',
|
|
25
|
+
flagCount: 0,
|
|
26
|
+
hashFlag: null,
|
|
27
|
+
children: [],
|
|
28
|
+
mentionees: [],
|
|
29
|
+
reactions: {},
|
|
30
|
+
reactionsCount: 0,
|
|
31
|
+
attachments: [],
|
|
32
|
+
...params,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export const comment11: Amity.Comment = generateComment();
|
|
37
|
+
|
|
38
|
+
export const imageComment11: Amity.Comment = generateComment({
|
|
39
|
+
dataTypes: ['image'],
|
|
40
|
+
data: { text: '' },
|
|
41
|
+
attachments: [
|
|
42
|
+
{
|
|
43
|
+
type: 'image',
|
|
44
|
+
fileId: file11.fileId,
|
|
45
|
+
},
|
|
46
|
+
],
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
export const textImageComment11: Amity.Comment = generateComment({
|
|
50
|
+
dataTypes: ['image', 'text'],
|
|
51
|
+
data: { text: 'test' },
|
|
52
|
+
attachments: [
|
|
53
|
+
{
|
|
54
|
+
type: 'image',
|
|
55
|
+
fileId: file11.fileId,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
export const textMentionComment11: Amity.Comment = generateComment({
|
|
61
|
+
mentionees: [
|
|
62
|
+
{
|
|
63
|
+
type: 'user',
|
|
64
|
+
userIds: [user11._id, user12._id],
|
|
65
|
+
},
|
|
66
|
+
],
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
export const comment12: Amity.Comment = generateComment({
|
|
70
|
+
commentId: 'comment12',
|
|
71
|
+
parentId: comment11.commentId,
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
export const imageComment12: Amity.Comment = generateComment({
|
|
75
|
+
...imageComment11,
|
|
76
|
+
commentId: comment12.commentId,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
export const textImageComment12: Amity.Comment = generateComment({
|
|
80
|
+
...textImageComment11,
|
|
81
|
+
commentId: comment12.commentId,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
export const textCommentPayload: Amity.CommentPayload = {
|
|
85
|
+
comments: [comment11],
|
|
86
|
+
users: [user11],
|
|
87
|
+
commentChildren: [],
|
|
88
|
+
files: [],
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const comment12Payload: Amity.CommentPayload = {
|
|
92
|
+
comments: [comment12, imageComment12, textImageComment12],
|
|
93
|
+
users: [user11],
|
|
94
|
+
commentChildren: [],
|
|
95
|
+
files: [file11],
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
export const imageCommentPayload: Amity.CommentPayload = {
|
|
99
|
+
comments: [imageComment11],
|
|
100
|
+
users: [user11],
|
|
101
|
+
commentChildren: [],
|
|
102
|
+
files: [file11],
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export const textImageCommentPayload: Amity.CommentPayload = {
|
|
106
|
+
comments: [textImageComment11],
|
|
107
|
+
users: [user11, user12],
|
|
108
|
+
commentChildren: [],
|
|
109
|
+
files: [file11],
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
export const textCommentMentionPayload: Amity.CommentPayload = {
|
|
113
|
+
comments: [textMentionComment11],
|
|
114
|
+
commentChildren: [],
|
|
115
|
+
users: [user11],
|
|
116
|
+
files: [],
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
export const postPayload: Amity.ProcessedPostPayload = {
|
|
120
|
+
posts: [post11],
|
|
121
|
+
users: [user11],
|
|
122
|
+
files: [file11],
|
|
123
|
+
comments: [comment11],
|
|
124
|
+
communityUsers: [],
|
|
125
|
+
categories: [],
|
|
126
|
+
communities: [],
|
|
127
|
+
feeds: [],
|
|
128
|
+
postChildren: [],
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
export const textAndImageCommentMixedPayload: Amity.CommentPayload = {
|
|
132
|
+
comments: [comment11, imageComment11, textImageComment11],
|
|
133
|
+
users: [user11],
|
|
134
|
+
commentChildren: [],
|
|
135
|
+
files: [file11],
|
|
136
|
+
};
|
|
137
|
+
|
|
138
|
+
export const deletedCommentPayload: Amity.CommentPayload = {
|
|
139
|
+
comments: [
|
|
140
|
+
{
|
|
141
|
+
...comment11,
|
|
142
|
+
isDeleted: true,
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
...imageComment11,
|
|
146
|
+
isDeleted: true,
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
...textImageComment11,
|
|
150
|
+
isDeleted: true,
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
users: [user11],
|
|
154
|
+
commentChildren: [],
|
|
155
|
+
files: [file11],
|
|
156
|
+
};
|
|
157
|
+
|
|
158
|
+
// Response - BE
|
|
159
|
+
export const textCommentResponse = {
|
|
160
|
+
data: {
|
|
161
|
+
...textCommentPayload,
|
|
162
|
+
files: [],
|
|
163
|
+
commentChildren: [],
|
|
164
|
+
paging: {},
|
|
165
|
+
},
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const imageCommentResponse = {
|
|
169
|
+
data: {
|
|
170
|
+
...imageCommentPayload,
|
|
171
|
+
files: [],
|
|
172
|
+
commentChildren: [],
|
|
173
|
+
paging: {},
|
|
174
|
+
},
|
|
175
|
+
};
|
|
176
|
+
|
|
177
|
+
export const textImageCommentResponse = {
|
|
178
|
+
data: {
|
|
179
|
+
...textImageCommentPayload,
|
|
180
|
+
files: [],
|
|
181
|
+
commentChildren: [],
|
|
182
|
+
paging: {},
|
|
183
|
+
},
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const textMentionCommentResponse = {
|
|
187
|
+
data: {
|
|
188
|
+
...textCommentMentionPayload,
|
|
189
|
+
files: [],
|
|
190
|
+
commentChildren: [],
|
|
191
|
+
paging: {},
|
|
192
|
+
},
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
export const textCommentParentIdResponse = {
|
|
196
|
+
data: {
|
|
197
|
+
...comment12Payload,
|
|
198
|
+
files: [],
|
|
199
|
+
commentChildren: [],
|
|
200
|
+
paging: {},
|
|
201
|
+
},
|
|
202
|
+
};
|
|
203
|
+
|
|
204
|
+
export const deletedCommentResponse = {
|
|
205
|
+
data: {
|
|
206
|
+
...deletedCommentPayload,
|
|
207
|
+
files: [],
|
|
208
|
+
commentChildren: [],
|
|
209
|
+
paging: {},
|
|
210
|
+
},
|
|
211
|
+
};
|
|
212
|
+
|
|
213
|
+
// Payload Query
|
|
214
|
+
export const textCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
215
|
+
referenceId: post11.postId,
|
|
216
|
+
referenceType: 'post',
|
|
217
|
+
data: {
|
|
218
|
+
text: 'test',
|
|
219
|
+
},
|
|
220
|
+
};
|
|
221
|
+
|
|
222
|
+
export const textCommentParentIdRequestPayload: Parameters<typeof createComment>[0] = {
|
|
223
|
+
referenceId: post11.postId,
|
|
224
|
+
referenceType: 'post',
|
|
225
|
+
parentId: comment11.commentId,
|
|
226
|
+
data: {
|
|
227
|
+
text: 'test',
|
|
228
|
+
},
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
export const imageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
232
|
+
referenceId: post11.postId,
|
|
233
|
+
referenceType: 'post',
|
|
234
|
+
attachments: [
|
|
235
|
+
{
|
|
236
|
+
type: 'image',
|
|
237
|
+
fileId: file11.fileId,
|
|
238
|
+
},
|
|
239
|
+
],
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
export const textImageCommentRequestPayload: Parameters<typeof createComment>[0] = {
|
|
243
|
+
referenceId: post11.postId,
|
|
244
|
+
referenceType: 'post',
|
|
245
|
+
data: {
|
|
246
|
+
text: 'test',
|
|
247
|
+
},
|
|
248
|
+
attachments: [
|
|
249
|
+
{
|
|
250
|
+
type: 'image',
|
|
251
|
+
fileId: file11.fileId,
|
|
252
|
+
},
|
|
253
|
+
],
|
|
254
|
+
};
|
|
255
|
+
|
|
256
|
+
export const textCommentWithMentionRequestPayload: Parameters<typeof createComment>[0] = {
|
|
257
|
+
referenceId: post11.postId,
|
|
258
|
+
referenceType: 'post',
|
|
259
|
+
data: {
|
|
260
|
+
text: 'test',
|
|
261
|
+
},
|
|
262
|
+
mentionees: [
|
|
263
|
+
{
|
|
264
|
+
type: 'user',
|
|
265
|
+
userIds: [user11._id, user12._id],
|
|
266
|
+
},
|
|
267
|
+
],
|
|
268
|
+
};
|