@amityco/ts-sdk 0.0.1-beta.27 → 0.0.1-beta.28
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.eslintrc.json +1 -0
- package/dist/@types/core/payload.d.ts +12 -10
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -1
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +13 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +26 -3
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/file.d.ts +36 -3
- package/dist/@types/domains/file.d.ts.map +1 -1
- package/dist/@types/domains/follow.d.ts +11 -0
- package/dist/@types/domains/follow.d.ts.map +1 -1
- package/dist/@types/domains/group.d.ts +1 -0
- package/dist/@types/domains/group.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +13 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/global.d.ts +1 -0
- package/dist/@types/global.d.ts.map +1 -1
- package/dist/@types/index.d.ts +2 -2
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/addChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/banChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/createChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannel.d.ts.map +1 -1
- package/dist/channel/api/getChannels.d.ts.map +1 -1
- package/dist/channel/api/joinChannel.d.ts.map +1 -1
- package/dist/channel/api/leaveChannel.d.ts.map +1 -1
- package/dist/channel/api/queryChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/queryChannels.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/removeChannelMembersRole.d.ts.map +1 -1
- package/dist/channel/api/unbanChannelMembers.d.ts.map +1 -1
- package/dist/channel/api/updateChannel.d.ts.map +1 -1
- package/dist/channel/events/index.d.ts +1 -0
- package/dist/channel/events/index.d.ts.map +1 -1
- package/dist/channel/events/onChannelCreated.d.ts.map +1 -1
- package/dist/channel/events/onChannelDeleted.d.ts.map +1 -1
- package/dist/channel/events/onChannelJoined.d.ts.map +1 -1
- package/dist/channel/events/onChannelLeft.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberAdded.d.ts.map +1 -1
- package/dist/channel/events/onChannelMemberRemoved.d.ts.map +1 -1
- package/dist/channel/events/onChannelUpdated.d.ts.map +1 -1
- package/dist/channel/observers/index.d.ts +1 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/observeChannel.d.ts +1 -1
- package/dist/channel/observers/observeChannel.d.ts.map +1 -1
- package/dist/channel/observers/observeChannels.d.ts +17 -0
- package/dist/channel/observers/observeChannels.d.ts.map +1 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts +2 -0
- package/dist/channel/tests/utils/prepareChannelPayload.test.d.ts.map +1 -0
- package/dist/channel/utils/index.d.ts +2 -0
- package/dist/channel/utils/index.d.ts.map +1 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts +3 -0
- package/dist/channel/utils/prepareChannelPayload.d.ts.map +1 -0
- package/dist/client/api/connectClient.d.ts +1 -8
- package/dist/client/api/connectClient.d.ts.map +1 -1
- package/dist/client/api/createClient.d.ts +8 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getFeedSettings.d.ts +16 -0
- package/dist/client/api/getFeedSettings.d.ts.map +1 -0
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/query/query.d.ts +1 -1
- package/dist/core/tests/query/query/runQuery.test.d.ts +2 -0
- package/dist/core/tests/query/query/runQuery.test.d.ts.map +1 -0
- package/dist/file/api/createVideo.d.ts +2 -1
- package/dist/file/api/createVideo.d.ts.map +1 -1
- package/dist/follow/api/queryFollowers.d.ts +1 -5
- package/dist/follow/api/queryFollowers.d.ts.map +1 -1
- package/dist/follow/api/queryFollowings.d.ts +1 -5
- package/dist/follow/api/queryFollowings.d.ts.map +1 -1
- package/dist/follow/observers/index.d.ts +2 -0
- package/dist/follow/observers/index.d.ts.map +1 -1
- package/dist/follow/observers/liveFollowers.d.ts +20 -0
- package/dist/follow/observers/liveFollowers.d.ts.map +1 -0
- package/dist/follow/observers/liveFollowings.d.ts +20 -0
- package/dist/follow/observers/liveFollowings.d.ts.map +1 -0
- package/dist/index.cjs.js +553 -111
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +543 -112
- package/dist/index.umd.js +4 -4
- package/dist/message/api/queryMessages.d.ts +1 -10
- package/dist/message/api/queryMessages.d.ts.map +1 -1
- package/dist/message/observers/index.d.ts +1 -0
- package/dist/message/observers/index.d.ts.map +1 -1
- package/dist/message/observers/liveMessages.d.ts +20 -0
- package/dist/message/observers/liveMessages.d.ts.map +1 -0
- package/dist/message/observers/observeMessages.d.ts +0 -1
- package/dist/message/observers/observeMessages.d.ts.map +1 -1
- package/dist/message/observers/tests/liveMessages.test.d.ts +2 -0
- package/dist/message/observers/tests/liveMessages.test.d.ts.map +1 -0
- package/dist/post/observers/livePosts.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/tests/client.d.ts +5 -2
- package/dist/utils/tests/client.d.ts.map +1 -1
- package/dist/utils/tests/dummy/channel.d.ts +10 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
- package/dist/utils/tests/dummy/index.d.ts +10 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -0
- package/dist/utils/tests/dummy/message.d.ts +8 -0
- package/dist/utils/tests/dummy/message.d.ts.map +1 -0
- package/dist/utils/tests/{dummy.d.ts → dummy/post.d.ts} +3 -2
- package/dist/utils/tests/dummy/post.d.ts.map +1 -0
- package/dist/utils/tests/dummy/user.d.ts +2 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -0
- package/dist/utils/tests/index.d.ts +2 -2
- package/dist/utils/tests/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/core/payload.ts +16 -10
- package/src/@types/domains/channel.ts +16 -1
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/content.ts +34 -3
- package/src/@types/domains/file.ts +42 -3
- package/src/@types/domains/follow.ts +28 -0
- package/src/@types/domains/group.ts +1 -0
- package/src/@types/domains/message.ts +20 -0
- package/src/@types/global.ts +2 -0
- package/src/@types/index.ts +3 -2
- package/src/channel/api/addChannelMembers.ts +6 -5
- package/src/channel/api/addChannelMembersRole.ts +5 -1
- package/src/channel/api/banChannelMembers.ts +7 -3
- package/src/channel/api/createChannel.ts +6 -2
- package/src/channel/api/getChannel.ts +5 -1
- package/src/channel/api/getChannels.ts +5 -1
- package/src/channel/api/joinChannel.ts +5 -1
- package/src/channel/api/leaveChannel.ts +5 -1
- package/src/channel/api/queryChannelMembers.ts +16 -12
- package/src/channel/api/queryChannels.ts +9 -4
- package/src/channel/api/removeChannelMembers.ts +6 -5
- package/src/channel/api/removeChannelMembersRole.ts +5 -1
- package/src/channel/api/unbanChannelMembers.ts +7 -3
- package/src/channel/api/updateChannel.ts +5 -1
- package/src/channel/events/index.ts +1 -0
- package/src/channel/events/onChannelCreated.ts +6 -2
- package/src/channel/events/onChannelDeleted.ts +6 -2
- package/src/channel/events/onChannelJoined.ts +6 -2
- package/src/channel/events/onChannelLeft.ts +6 -2
- package/src/channel/events/onChannelMemberAdded.ts +6 -2
- package/src/channel/events/onChannelMemberRemoved.ts +6 -2
- package/src/channel/events/onChannelUpdated.ts +6 -2
- package/src/channel/observers/index.ts +1 -0
- package/src/channel/observers/observeChannel.ts +1 -11
- package/src/channel/observers/observeChannels.ts +59 -0
- package/src/channel/tests/utils/prepareChannelPayload.test.ts +120 -0
- package/src/channel/utils/index.ts +1 -0
- package/src/channel/utils/prepareChannelPayload.ts +31 -0
- package/src/client/api/connectClient.ts +4 -9
- package/src/client/api/createClient.ts +19 -4
- package/src/client/api/getFeedSettings.ts +29 -0
- package/src/client/api/index.ts +2 -0
- package/src/core/events.ts +2 -1
- package/src/core/query/query.ts +3 -3
- package/src/core/tests/query/query/runQuery.test.ts +182 -0
- package/src/file/api/createVideo.ts +6 -0
- package/src/follow/api/queryFollowers.ts +3 -5
- package/src/follow/api/queryFollowings.ts +3 -5
- package/src/follow/api/utils.ts +7 -3
- package/src/follow/observers/index.ts +3 -0
- package/src/follow/observers/liveFollowers.ts +149 -0
- package/src/follow/observers/liveFollowings.ts +149 -0
- package/src/index.ts +1 -1
- package/src/message/api/queryMessages.ts +3 -10
- package/src/message/observers/index.ts +1 -0
- package/src/message/observers/liveMessages.ts +141 -0
- package/src/message/observers/observeMessages.ts +0 -1
- package/src/message/observers/tests/liveMessages.test.ts +133 -0
- package/src/post/observers/livePosts.ts +2 -1
- package/src/post/tests/api/getPost.test.ts +3 -3
- package/src/post/tests/api/queryPosts.test.ts +4 -4
- package/src/utils/constants.ts +1 -0
- package/src/utils/tests/client.ts +31 -3
- package/src/utils/tests/dummy/channel.ts +52 -0
- package/src/utils/tests/dummy/index.ts +7 -0
- package/src/utils/tests/dummy/message.ts +21 -0
- package/src/utils/tests/dummy/post.ts +31 -0
- package/src/utils/tests/dummy/user.ts +11 -0
- package/src/utils/tests/index.ts +2 -2
- package/dist/utils/tests/dummy.d.ts.map +0 -1
- package/src/utils/tests/dummy.ts +0 -7
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import {
|
|
2
|
+
connectClient,
|
|
3
|
+
disconnectClient,
|
|
4
|
+
channel11,
|
|
5
|
+
channel12,
|
|
6
|
+
channelRaw1,
|
|
7
|
+
channelRaw2,
|
|
8
|
+
channelUser1,
|
|
9
|
+
channelUser2,
|
|
10
|
+
} from '~/utils/tests';
|
|
11
|
+
|
|
12
|
+
import { prepareChannelPayload } from '../../utils';
|
|
13
|
+
|
|
14
|
+
beforeAll(async () => {
|
|
15
|
+
await connectClient();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
afterAll(async () => {
|
|
19
|
+
await disconnectClient();
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
const responseSchema = {
|
|
23
|
+
channels: [],
|
|
24
|
+
channelUsers: [],
|
|
25
|
+
files: [],
|
|
26
|
+
users: [],
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const tests = [
|
|
30
|
+
{
|
|
31
|
+
id: 1,
|
|
32
|
+
desc: 'hasMention: false, unreadCount: 0, if channelUsers is empty',
|
|
33
|
+
before: {
|
|
34
|
+
...responseSchema,
|
|
35
|
+
channels: [channelRaw1],
|
|
36
|
+
},
|
|
37
|
+
after: {
|
|
38
|
+
...responseSchema,
|
|
39
|
+
channels: [channel11],
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
id: 2,
|
|
44
|
+
desc: 'hasMention: false, if channelUser.readToSegment >= channelUser.lastMentionedSegment',
|
|
45
|
+
before: {
|
|
46
|
+
...responseSchema,
|
|
47
|
+
channels: [channelRaw1],
|
|
48
|
+
channelUsers: [channelUser1],
|
|
49
|
+
},
|
|
50
|
+
after: {
|
|
51
|
+
...responseSchema,
|
|
52
|
+
channels: [channel11],
|
|
53
|
+
channelUsers: [channelUser1],
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
id: 3,
|
|
58
|
+
desc: 'unreadCount: 0, if channelUser.readToSegment = channel.messageCount',
|
|
59
|
+
before: {
|
|
60
|
+
...responseSchema,
|
|
61
|
+
channels: [channelRaw1],
|
|
62
|
+
channelUsers: [channelUser1],
|
|
63
|
+
},
|
|
64
|
+
after: {
|
|
65
|
+
...responseSchema,
|
|
66
|
+
channels: [channel11],
|
|
67
|
+
channelUsers: [channelUser1],
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
id: 4,
|
|
72
|
+
desc: 'hasMention: true, if channelUser.readToSegment < channelUser.lastMentionedSegment',
|
|
73
|
+
before: {
|
|
74
|
+
...responseSchema,
|
|
75
|
+
channels: [channelRaw2],
|
|
76
|
+
channelUsers: [channelUser2],
|
|
77
|
+
},
|
|
78
|
+
after: {
|
|
79
|
+
...responseSchema,
|
|
80
|
+
channels: [channel12],
|
|
81
|
+
channelUsers: [channelUser2],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
{
|
|
85
|
+
id: 5,
|
|
86
|
+
desc: 'unreadCount: > 0, if channelUser.readToSegment < channel.messageCount',
|
|
87
|
+
before: {
|
|
88
|
+
...responseSchema,
|
|
89
|
+
channels: [channelRaw2],
|
|
90
|
+
channelUsers: [channelUser2],
|
|
91
|
+
},
|
|
92
|
+
after: {
|
|
93
|
+
...responseSchema,
|
|
94
|
+
channels: [channel12],
|
|
95
|
+
channelUsers: [channelUser2],
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
id: 4,
|
|
100
|
+
desc: 'hasMention: true, unreadCount: > 0, if 4 / 5 ',
|
|
101
|
+
before: {
|
|
102
|
+
...responseSchema,
|
|
103
|
+
channels: [channelRaw2],
|
|
104
|
+
channelUsers: [channelUser2],
|
|
105
|
+
},
|
|
106
|
+
after: {
|
|
107
|
+
...responseSchema,
|
|
108
|
+
channels: [channel12],
|
|
109
|
+
channelUsers: [channelUser2],
|
|
110
|
+
},
|
|
111
|
+
},
|
|
112
|
+
];
|
|
113
|
+
|
|
114
|
+
describe('channel/utils/prepareChannelPayload', () => {
|
|
115
|
+
tests.forEach(({ id, desc, before, after }) => {
|
|
116
|
+
test(`${id} - ${desc}`, () => {
|
|
117
|
+
expect(prepareChannelPayload(before)).toEqual(after);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './prepareChannelPayload';
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
/** @hidden */
|
|
4
|
+
export const prepareChannelPayload = (
|
|
5
|
+
payload: Amity.ChannelPayload,
|
|
6
|
+
): Amity.ChannelPayload<any, Amity.Channel> => {
|
|
7
|
+
const client = getActiveClient();
|
|
8
|
+
|
|
9
|
+
const channels: Amity.Channel[] = payload.channels.map(channel => {
|
|
10
|
+
const channelUser = payload.channelUsers.find(
|
|
11
|
+
channelUser =>
|
|
12
|
+
channelUser.userId === client.userId && channel.channelId === channelUser.channelId,
|
|
13
|
+
)!;
|
|
14
|
+
|
|
15
|
+
const hasMention = channelUser
|
|
16
|
+
? channelUser.readToSegment < channelUser.lastMentionedSegment
|
|
17
|
+
: false;
|
|
18
|
+
const unreadCount =
|
|
19
|
+
channelUser && channelUser.membership === 'member' && channel.messageCount
|
|
20
|
+
? Math.max(0, channel.messageCount - channelUser.readToSegment)
|
|
21
|
+
: 0;
|
|
22
|
+
|
|
23
|
+
return {
|
|
24
|
+
...channel,
|
|
25
|
+
hasMention,
|
|
26
|
+
unreadCount,
|
|
27
|
+
};
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
return { ...payload, channels };
|
|
31
|
+
};
|
|
@@ -3,14 +3,14 @@
|
|
|
3
3
|
import { disconnectClient } from '~/client/api/disconnectClient';
|
|
4
4
|
import { getDeviceId } from '~/core/device';
|
|
5
5
|
import { proxyWebsocketEvents } from '~/core/events';
|
|
6
|
+
import { getNetworkTopic, subscribeTopic } from '~/core/subscription';
|
|
7
|
+
import { onUserDeleted } from '~/user/events/onUserDeleted';
|
|
6
8
|
|
|
7
9
|
import { getActiveClient } from './activeClient';
|
|
8
10
|
import { setActiveUser } from './activeUser';
|
|
9
11
|
|
|
10
12
|
import { getToken } from './getToken';
|
|
11
13
|
import { onClientBanned } from '../events';
|
|
12
|
-
import { getNetworkTopic, subscribeTopic } from '~/core/subscription';
|
|
13
|
-
import { onUserDeleted } from '~/user/events/onUserDeleted';
|
|
14
14
|
|
|
15
15
|
/**
|
|
16
16
|
* ```js
|
|
@@ -33,13 +33,8 @@ import { onUserDeleted } from '~/user/events/onUserDeleted';
|
|
|
33
33
|
* @async
|
|
34
34
|
*/
|
|
35
35
|
export const connectClient = async (
|
|
36
|
-
params:
|
|
37
|
-
|
|
38
|
-
displayName?: Amity.User['displayName'];
|
|
39
|
-
authToken?: string;
|
|
40
|
-
deviceId?: Amity.Device['deviceId'];
|
|
41
|
-
},
|
|
42
|
-
config?: { disableRTE: boolean },
|
|
36
|
+
params: Amity.ConnectClientParams,
|
|
37
|
+
config?: Amity.ConnectClientConfig,
|
|
43
38
|
): Promise<boolean> => {
|
|
44
39
|
const client = getActiveClient();
|
|
45
40
|
client.log('client/api/connectClient', { apiKey: client.apiKey, ...params });
|
|
@@ -12,6 +12,9 @@ import {
|
|
|
12
12
|
import { createEventEmitter } from '~/core/events';
|
|
13
13
|
|
|
14
14
|
import { getActiveClient, setActiveClient } from './activeClient';
|
|
15
|
+
import { getFeedSettings } from './getFeedSettings';
|
|
16
|
+
|
|
17
|
+
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
15
18
|
|
|
16
19
|
/**
|
|
17
20
|
* ```js
|
|
@@ -23,6 +26,7 @@ import { getActiveClient, setActiveClient } from './activeClient';
|
|
|
23
26
|
*
|
|
24
27
|
* @param apiKey for the {@link Amity.Client} instance
|
|
25
28
|
* @param apiRegion endpoint to connect to
|
|
29
|
+
* @param apiEndpoint custom endpoint in case you don't want to use a preset endpoint
|
|
26
30
|
* @param debugSession session's identifier for the client's logger instance
|
|
27
31
|
* @returns A {@link Amity.Client} instance
|
|
28
32
|
*
|
|
@@ -31,7 +35,13 @@ import { getActiveClient, setActiveClient } from './activeClient';
|
|
|
31
35
|
export const createClient = (
|
|
32
36
|
apiKey: string,
|
|
33
37
|
apiRegion: typeof API_REGIONS[keyof typeof API_REGIONS] = API_REGIONS.SG,
|
|
34
|
-
|
|
38
|
+
{
|
|
39
|
+
debugSession = DEFAULT_DEBUG_SESSION,
|
|
40
|
+
apiEndpoint,
|
|
41
|
+
}: {
|
|
42
|
+
debugSession?: string;
|
|
43
|
+
apiEndpoint?: { http?: string; mqtt?: string };
|
|
44
|
+
} = {},
|
|
35
45
|
): Amity.Client => {
|
|
36
46
|
const log = createLogger(debugSession);
|
|
37
47
|
|
|
@@ -40,9 +50,12 @@ export const createClient = (
|
|
|
40
50
|
apiRegion,
|
|
41
51
|
});
|
|
42
52
|
|
|
43
|
-
const
|
|
44
|
-
const
|
|
45
|
-
|
|
53
|
+
const httpEndpoint = apiEndpoint?.http ?? computeUrl('http', apiRegion);
|
|
54
|
+
const mqttEndpoint = apiEndpoint?.mqtt ?? computeUrl('mqtt', apiRegion);
|
|
55
|
+
|
|
56
|
+
const http = createHttpTransport(httpEndpoint);
|
|
57
|
+
const ws = createWebsocketTransport(httpEndpoint);
|
|
58
|
+
const mqtt = createMqttTransport(mqttEndpoint);
|
|
46
59
|
|
|
47
60
|
const emitter = createEventEmitter();
|
|
48
61
|
|
|
@@ -56,6 +69,8 @@ export const createClient = (
|
|
|
56
69
|
mqtt,
|
|
57
70
|
emitter,
|
|
58
71
|
use: () => setActiveClient(client),
|
|
72
|
+
|
|
73
|
+
getFeedSettings,
|
|
59
74
|
};
|
|
60
75
|
|
|
61
76
|
try {
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { getActiveClient } from './activeClient';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* ```js
|
|
5
|
+
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
6
|
+
* const feedSettings = await getFeedSettings()
|
|
7
|
+
* const postFeedSetting = feedSettings.post
|
|
8
|
+
* ```
|
|
9
|
+
*
|
|
10
|
+
* Fetches a {@link Amity.FeedSettings} object
|
|
11
|
+
*
|
|
12
|
+
* @returns A Promise of {@link Amity.FeedSettings} object
|
|
13
|
+
*
|
|
14
|
+
* @category Client API
|
|
15
|
+
* @async
|
|
16
|
+
*/
|
|
17
|
+
export const getFeedSettings = async (): Promise<Amity.FeedSettings> => {
|
|
18
|
+
const client = getActiveClient();
|
|
19
|
+
|
|
20
|
+
const { data } = await client.http.get<Amity.FeedSettingPayload>(
|
|
21
|
+
`/api/v3/network-settings/feed-setting`,
|
|
22
|
+
);
|
|
23
|
+
|
|
24
|
+
return Object.fromEntries(
|
|
25
|
+
data.feedSettings.map(({ feedType, contentSettings }) => {
|
|
26
|
+
return [feedType, contentSettings];
|
|
27
|
+
}),
|
|
28
|
+
);
|
|
29
|
+
};
|
package/src/client/api/index.ts
CHANGED
package/src/core/events.ts
CHANGED
|
@@ -13,8 +13,9 @@ const WS_EVENTS = [
|
|
|
13
13
|
'reconnect_error',
|
|
14
14
|
'reconnect_failed',
|
|
15
15
|
|
|
16
|
+
'v3.channel.didCreate',
|
|
16
17
|
'v3.channel.didUpdate',
|
|
17
|
-
'v3.channel.
|
|
18
|
+
'v3.channel.didDelete',
|
|
18
19
|
'v3.channel.didJoin',
|
|
19
20
|
'v3.channel.didLeave',
|
|
20
21
|
'v3.channel.didAddUsers',
|
package/src/core/query/query.ts
CHANGED
|
@@ -85,7 +85,7 @@ export const isFresh = (model?: Amity.Cachable, lifeSpan = 0) => {
|
|
|
85
85
|
* This wrapper is necessary to create for optimistically calls
|
|
86
86
|
*
|
|
87
87
|
*
|
|
88
|
-
* @param
|
|
88
|
+
* @param func A compatible API function from the ts sdk
|
|
89
89
|
* @param args The arguments to pass to the function passed as `fn`
|
|
90
90
|
* @returns A wrapper containing both the function and its future arguments
|
|
91
91
|
*
|
|
@@ -221,8 +221,8 @@ export const runQuery = <Args extends any[], Returned extends any>(
|
|
|
221
221
|
* the modal key in the param itself
|
|
222
222
|
* For update & delete the first argument is always an id which is of type
|
|
223
223
|
* string, whereas for create the first and only argument is the param object
|
|
224
|
-
*
|
|
225
|
-
* When creating an AmityObject optimistically we need to pass the modal key
|
|
224
|
+
*
|
|
225
|
+
* When creating an AmityObject optimistically we need to pass the modal key
|
|
226
226
|
* on to the server. ex: for create message modal key will be 'messageId`
|
|
227
227
|
*/
|
|
228
228
|
if (typeof args[0] !== 'string') {
|
|
@@ -0,0 +1,182 @@
|
|
|
1
|
+
import { ASCApiError } from '~/core/errors';
|
|
2
|
+
import { disableCache, enableCache, pushToCache } from '~/cache/api';
|
|
3
|
+
import { runQuery, createQuery } from '~/core/query';
|
|
4
|
+
import { createPost, getPost } from '~/post/api';
|
|
5
|
+
import { deleteMessage } from '~/message/api';
|
|
6
|
+
|
|
7
|
+
import { posts, client } from '~/utils/tests';
|
|
8
|
+
|
|
9
|
+
const createPostArgs: Parameters<typeof createPost> = [
|
|
10
|
+
{
|
|
11
|
+
tags: ['a', 'b'],
|
|
12
|
+
data: {
|
|
13
|
+
text: 'hello!',
|
|
14
|
+
},
|
|
15
|
+
targetType: 'user',
|
|
16
|
+
targetId: 'userId1',
|
|
17
|
+
},
|
|
18
|
+
];
|
|
19
|
+
const post = { postId: posts.page1[0] };
|
|
20
|
+
const deletingMsgId = 'deletingId';
|
|
21
|
+
|
|
22
|
+
describe('Core/Query/runQuery', () => {
|
|
23
|
+
test('should call query with arguments', () => {
|
|
24
|
+
const createPostMock = jest.fn().mockResolvedValue('test');
|
|
25
|
+
|
|
26
|
+
const query = createQuery(createPostMock, createPostArgs);
|
|
27
|
+
runQuery(query);
|
|
28
|
+
|
|
29
|
+
expect(createPostMock).toBeCalledTimes(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
test('should call callback with cache when valid', () => {
|
|
33
|
+
enableCache();
|
|
34
|
+
|
|
35
|
+
const callback = jest.fn();
|
|
36
|
+
|
|
37
|
+
const cachedAt = Date.now();
|
|
38
|
+
pushToCache(['post', 'get', post.postId], post, { cachedAt });
|
|
39
|
+
|
|
40
|
+
const query = createQuery(getPost, post.postId);
|
|
41
|
+
runQuery(query, callback);
|
|
42
|
+
|
|
43
|
+
expect(callback).toBeCalled();
|
|
44
|
+
expect(callback).toBeCalledTimes(1);
|
|
45
|
+
expect(callback).toHaveBeenCalledWith({
|
|
46
|
+
cachedAt,
|
|
47
|
+
origin: 'local',
|
|
48
|
+
loading: false,
|
|
49
|
+
data: post,
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
disableCache();
|
|
53
|
+
});
|
|
54
|
+
|
|
55
|
+
test('should call callback with server data for invalid cache', async () => {
|
|
56
|
+
enableCache();
|
|
57
|
+
|
|
58
|
+
const callback = jest.fn();
|
|
59
|
+
client.http.get = jest.fn().mockResolvedValue({ data: { posts: [post] } });
|
|
60
|
+
|
|
61
|
+
// at the time of writing this test, cache is valid for 2 minutes
|
|
62
|
+
const expiredDate = Date.parse('04 Dec 1995 00:12:00 GMT');
|
|
63
|
+
pushToCache(['post', 'get', post.postId], post, { cachedAt: expiredDate });
|
|
64
|
+
|
|
65
|
+
const query = createQuery(getPost, post.postId);
|
|
66
|
+
runQuery(query, callback);
|
|
67
|
+
|
|
68
|
+
expect(callback).toHaveBeenCalledWith({
|
|
69
|
+
cachedAt: expiredDate,
|
|
70
|
+
origin: 'local',
|
|
71
|
+
loading: true,
|
|
72
|
+
data: post,
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
await expect(getPost(post.postId)).resolves.toBeTruthy();
|
|
76
|
+
|
|
77
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
78
|
+
// checking object containing as expiredAt cannot be predicted :D
|
|
79
|
+
expect(callback).toHaveBeenCalledWith(
|
|
80
|
+
expect.objectContaining({
|
|
81
|
+
origin: 'server',
|
|
82
|
+
loading: false,
|
|
83
|
+
data: post,
|
|
84
|
+
}),
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
disableCache();
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
test('should execute mutators optimistically', () => {
|
|
91
|
+
enableCache();
|
|
92
|
+
|
|
93
|
+
const createMessage: any = jest.fn().mockResolvedValue('test');
|
|
94
|
+
// mutators are defined as having a property called optimistically
|
|
95
|
+
createMessage.optimistically = jest.fn();
|
|
96
|
+
|
|
97
|
+
const query = createQuery(createMessage);
|
|
98
|
+
runQuery(query);
|
|
99
|
+
|
|
100
|
+
expect(createMessage.optimistically).toHaveBeenCalled();
|
|
101
|
+
// should call server right after
|
|
102
|
+
expect(createMessage).toHaveBeenCalled();
|
|
103
|
+
|
|
104
|
+
disableCache();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
/*
|
|
108
|
+
* NOTE: del not tested as the args are exactly the same as update
|
|
109
|
+
*
|
|
110
|
+
* Tested due to bug where optimistic args was modifying args for del &
|
|
111
|
+
* update when it does not need to
|
|
112
|
+
*/
|
|
113
|
+
test('should not change args optimistically for update', () => {
|
|
114
|
+
enableCache();
|
|
115
|
+
|
|
116
|
+
client.http.delete = jest.fn().mockResolvedValue(true);
|
|
117
|
+
// 'get', gets called after delete to verify delete
|
|
118
|
+
client.http.get = jest.fn();
|
|
119
|
+
|
|
120
|
+
const query = createQuery(deleteMessage, deletingMsgId);
|
|
121
|
+
runQuery(query);
|
|
122
|
+
|
|
123
|
+
expect(client.http.delete).toHaveBeenCalledWith(`/api/v3/messages/${deletingMsgId}`);
|
|
124
|
+
|
|
125
|
+
disableCache();
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
test('should throw error if optimistic execution fails', async () => {
|
|
129
|
+
enableCache();
|
|
130
|
+
|
|
131
|
+
const callback = jest.fn();
|
|
132
|
+
const createMessage: any = jest.fn().mockResolvedValue('test');
|
|
133
|
+
// mutators are defined as having a property called optimistically
|
|
134
|
+
createMessage.optimistically = jest.fn().mockImplementation(() => {
|
|
135
|
+
throw new Error();
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
const query = createQuery(createMessage);
|
|
139
|
+
runQuery(query, callback);
|
|
140
|
+
|
|
141
|
+
expect(createMessage.optimistically).toThrow();
|
|
142
|
+
expect(callback).toBeCalledWith({
|
|
143
|
+
origin: 'local',
|
|
144
|
+
loading: true,
|
|
145
|
+
data: undefined,
|
|
146
|
+
});
|
|
147
|
+
|
|
148
|
+
disableCache();
|
|
149
|
+
});
|
|
150
|
+
|
|
151
|
+
test('should return error if call to server fails', async () => {
|
|
152
|
+
enableCache();
|
|
153
|
+
|
|
154
|
+
client.http.delete = jest
|
|
155
|
+
.fn()
|
|
156
|
+
.mockRejectedValueOnce(
|
|
157
|
+
new ASCApiError('not found!', Amity.ServerError.ITEM_NOT_FOUND, Amity.ErrorLevel.ERROR),
|
|
158
|
+
);
|
|
159
|
+
const callback = jest.fn();
|
|
160
|
+
|
|
161
|
+
const query = createQuery(deleteMessage, deletingMsgId);
|
|
162
|
+
runQuery(query, callback);
|
|
163
|
+
|
|
164
|
+
expect(callback).toHaveBeenCalledWith({
|
|
165
|
+
origin: 'local',
|
|
166
|
+
loading: true,
|
|
167
|
+
data: undefined,
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
await expect(deleteMessage(deletingMsgId)).rejects.toThrow();
|
|
171
|
+
|
|
172
|
+
expect(callback).toHaveBeenCalledTimes(2);
|
|
173
|
+
expect(callback).toHaveBeenCalledWith(
|
|
174
|
+
expect.objectContaining({
|
|
175
|
+
origin: 'server',
|
|
176
|
+
loading: false,
|
|
177
|
+
}),
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
disableCache();
|
|
181
|
+
});
|
|
182
|
+
});
|
|
@@ -11,6 +11,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
11
11
|
* Creates an {@link Amity.File<'video'>}
|
|
12
12
|
*
|
|
13
13
|
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
14
|
+
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
14
15
|
* @param onProgress The callback to track the upload progress
|
|
15
16
|
* @returns The newly created {@link Amity.File<'video'>}
|
|
16
17
|
*
|
|
@@ -19,6 +20,7 @@ import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
|
19
20
|
*/
|
|
20
21
|
export const createVideo = async (
|
|
21
22
|
formData: FormData,
|
|
23
|
+
feedType?: Amity.ContentFeedType,
|
|
22
24
|
onProgress?: (percent: number) => void,
|
|
23
25
|
): Promise<Amity.Cached<Amity.File<'video'>[]>> => {
|
|
24
26
|
const client = getActiveClient();
|
|
@@ -27,6 +29,10 @@ export const createVideo = async (
|
|
|
27
29
|
if (!formData.getAll('files').length)
|
|
28
30
|
throw new Error('The formData object must have a `files` key.');
|
|
29
31
|
|
|
32
|
+
if (feedType) {
|
|
33
|
+
formData.append('feedType', feedType);
|
|
34
|
+
}
|
|
35
|
+
|
|
30
36
|
const headers =
|
|
31
37
|
'getHeaders' in formData
|
|
32
38
|
? (formData as any).getHeaders()
|
|
@@ -14,11 +14,9 @@ import { queryFollows } from './utils';
|
|
|
14
14
|
* @category Follow API
|
|
15
15
|
* @async
|
|
16
16
|
*/
|
|
17
|
-
export const queryFollowers = async (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
page?: Amity.PageRaw;
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
17
|
+
export const queryFollowers = async (
|
|
18
|
+
query: Amity.QueryFollowers,
|
|
19
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
20
|
queryFollows('followers', query);
|
|
23
21
|
|
|
24
22
|
/**
|
|
@@ -14,11 +14,9 @@ import { queryFollows } from './utils';
|
|
|
14
14
|
* @category Follow API
|
|
15
15
|
* @async
|
|
16
16
|
*/
|
|
17
|
-
export const queryFollowings = async (
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
page?: Amity.PageRaw;
|
|
21
|
-
}): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
17
|
+
export const queryFollowings = async (
|
|
18
|
+
query: Amity.QueryFollowings,
|
|
19
|
+
): Promise<Amity.Cached<Amity.Paged<Amity.FollowStatus, Amity.PageRaw>>> =>
|
|
22
20
|
queryFollows('following', query);
|
|
23
21
|
|
|
24
22
|
/**
|
package/src/follow/api/utils.ts
CHANGED
|
@@ -36,9 +36,9 @@ export const queryFollows = async (
|
|
|
36
36
|
ingestInCache(payload as Amity.FollowersPayload, { cachedAt });
|
|
37
37
|
|
|
38
38
|
const cacheKey = [
|
|
39
|
-
|
|
39
|
+
'follow',
|
|
40
40
|
'query',
|
|
41
|
-
{ ...params, userId, options: { ...page } } as Amity.Serializable,
|
|
41
|
+
{ ...params, userId, options: { ...page }, type: key } as Amity.Serializable,
|
|
42
42
|
];
|
|
43
43
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
44
44
|
}
|
|
@@ -60,7 +60,11 @@ queryFollows.locally = (
|
|
|
60
60
|
|
|
61
61
|
const { page, ...params } = query;
|
|
62
62
|
|
|
63
|
-
const queryKey = [
|
|
63
|
+
const queryKey = [
|
|
64
|
+
'follow',
|
|
65
|
+
'query',
|
|
66
|
+
{ ...params, options: { ...page }, type: key } as Amity.Serializable,
|
|
67
|
+
];
|
|
64
68
|
const { data, cachedAt } =
|
|
65
69
|
pullFromCache<{ follows: string[] } & Amity.Pagination>(queryKey) ?? {};
|
|
66
70
|
|