@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
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { createChannel } from '@amityco/ts-sdk'
|
|
@@ -36,10 +38,12 @@ export const createChannel = async <T extends Amity.ChannelType>(
|
|
|
36
38
|
payload = await client.http.post<Amity.ChannelPayload>('/api/v3/channels', bundle);
|
|
37
39
|
}
|
|
38
40
|
|
|
41
|
+
const data = prepareChannelPayload(payload.data);
|
|
42
|
+
|
|
39
43
|
const cachedAt = client.cache && Date.now();
|
|
40
|
-
if (client.cache) ingestInCache(
|
|
44
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
41
45
|
|
|
42
|
-
const { channels } =
|
|
46
|
+
const { channels } = data;
|
|
43
47
|
return {
|
|
44
48
|
data: channels[0],
|
|
45
49
|
cachedAt,
|
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { getChannel } from '@amityco/ts-sdk'
|
|
@@ -24,10 +26,12 @@ export const getChannel = async (
|
|
|
24
26
|
client.log('channel/getChannel', channelId);
|
|
25
27
|
|
|
26
28
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
27
|
-
const { data } = await client.http.get<Amity.ChannelPayload>(
|
|
29
|
+
const { data: payload } = await client.http.get<Amity.ChannelPayload>(
|
|
28
30
|
`/api/v3/channels/${encodeURIComponent(channelId)}`,
|
|
29
31
|
);
|
|
30
32
|
|
|
33
|
+
const data = prepareChannelPayload(payload);
|
|
34
|
+
|
|
31
35
|
const cachedAt = client.cache && Date.now();
|
|
32
36
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
33
37
|
|
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { pullFromCache } from '~/cache/api';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { getChannels } from '@amityco/ts-sdk'
|
|
@@ -26,10 +28,12 @@ export const getChannels = async (
|
|
|
26
28
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
27
29
|
|
|
28
30
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
29
|
-
const { data } = await client.http.get<Amity.ChannelPayload>(`/api/v3/channels/list`, {
|
|
31
|
+
const { data: payload } = await client.http.get<Amity.ChannelPayload>(`/api/v3/channels/list`, {
|
|
30
32
|
params: { channelIds: encodedChannelIds },
|
|
31
33
|
});
|
|
32
34
|
|
|
35
|
+
const data = prepareChannelPayload(payload);
|
|
36
|
+
|
|
33
37
|
const cachedAt = client.cache && Date.now();
|
|
34
38
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
35
39
|
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { joinChannel } from '@amityco/ts-sdk'
|
|
@@ -20,10 +22,12 @@ export const joinChannel = async (channelId: Amity.Channel['channelId']): Promis
|
|
|
20
22
|
const client = getActiveClient();
|
|
21
23
|
client.log('channel/joinChannel', channelId);
|
|
22
24
|
|
|
23
|
-
const { data } = await client.http.post<Amity.ChannelMembershipPayload>(
|
|
25
|
+
const { data: payload } = await client.http.post<Amity.ChannelMembershipPayload>(
|
|
24
26
|
`/api/v3/channels/${encodeURIComponent(channelId)}/join`,
|
|
25
27
|
);
|
|
26
28
|
|
|
29
|
+
const data = prepareChannelPayload(payload);
|
|
30
|
+
|
|
27
31
|
if (client.cache) ingestInCache(data);
|
|
28
32
|
|
|
29
33
|
const { channelUsers } = data;
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { leaveChannel } from '@amityco/ts-sdk'
|
|
@@ -20,10 +22,12 @@ export const leaveChannel = async (channelId: Amity.Channel['channelId']): Promi
|
|
|
20
22
|
const client = getActiveClient();
|
|
21
23
|
client.log('channel/leaveChannel', channelId);
|
|
22
24
|
|
|
23
|
-
const { data } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
25
|
+
const { data: payload } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
24
26
|
`/api/v3/channels/${encodeURIComponent(channelId)}/leave`,
|
|
25
27
|
);
|
|
26
28
|
|
|
29
|
+
const data = prepareChannelPayload(payload);
|
|
30
|
+
|
|
27
31
|
if (client.cache) ingestInCache(data);
|
|
28
32
|
|
|
29
33
|
const { channelUsers } = data;
|
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { toPage, toToken } from '~/core/query';
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { queryChannelMembers } from '@amityco/ts-sdk'
|
|
@@ -30,24 +32,26 @@ export const queryChannelMembers = async (query: {
|
|
|
30
32
|
|
|
31
33
|
const { page, channelId, ...params } = query ?? {};
|
|
32
34
|
|
|
33
|
-
const { data } = await client.http.get<
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
},
|
|
35
|
+
const { data: queryPayload } = await client.http.get<
|
|
36
|
+
Amity.ChannelMembershipPayload & Amity.Pagination
|
|
37
|
+
>(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
38
|
+
params: {
|
|
39
|
+
...params,
|
|
40
|
+
options: {
|
|
41
|
+
token: toToken(page, 'skiplimit'),
|
|
41
42
|
},
|
|
42
43
|
},
|
|
43
|
-
);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
const { paging, ...payload } = queryPayload;
|
|
47
|
+
|
|
48
|
+
const data = prepareChannelPayload(payload);
|
|
44
49
|
|
|
45
|
-
const {
|
|
46
|
-
const { channelUsers } = payload;
|
|
50
|
+
const { channelUsers } = data;
|
|
47
51
|
|
|
48
52
|
const cachedAt = client.cache && Date.now();
|
|
49
53
|
if (client.cache) {
|
|
50
|
-
ingestInCache(
|
|
54
|
+
ingestInCache(data as Amity.ChannelMembershipPayload);
|
|
51
55
|
}
|
|
52
56
|
|
|
53
57
|
const nextPage = toPage(paging.next);
|
|
@@ -5,6 +5,8 @@ import { pushToCache } from '~/cache/api';
|
|
|
5
5
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
6
6
|
import { getResolver } from '~/core/model';
|
|
7
7
|
|
|
8
|
+
import { prepareChannelPayload } from '../utils';
|
|
9
|
+
|
|
8
10
|
/**
|
|
9
11
|
* ```js
|
|
10
12
|
* import { queryChannels } from '@amityco/ts-sdk'
|
|
@@ -39,7 +41,7 @@ export const queryChannels = async (query?: {
|
|
|
39
41
|
// API-FIX: parameters should be querystring.
|
|
40
42
|
// API-FIX: backend doesnt answer Amity.Response
|
|
41
43
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
42
|
-
const { data } = await client.http.get<Amity.ChannelPayload & Amity.Pagination>(
|
|
44
|
+
const { data: queryPayload } = await client.http.get<Amity.ChannelPayload & Amity.Pagination>(
|
|
43
45
|
`/api/v3/channels`,
|
|
44
46
|
{
|
|
45
47
|
params: {
|
|
@@ -53,13 +55,16 @@ export const queryChannels = async (query?: {
|
|
|
53
55
|
},
|
|
54
56
|
);
|
|
55
57
|
|
|
56
|
-
const { paging, ...payload } =
|
|
57
|
-
|
|
58
|
+
const { paging, ...payload } = queryPayload;
|
|
59
|
+
|
|
60
|
+
const data = prepareChannelPayload(payload);
|
|
61
|
+
|
|
62
|
+
const { channels } = data;
|
|
58
63
|
|
|
59
64
|
const cachedAt = client.cache && Date.now();
|
|
60
65
|
|
|
61
66
|
if (client.cache) {
|
|
62
|
-
ingestInCache(
|
|
67
|
+
ingestInCache(data as Amity.ChannelPayload, { cachedAt });
|
|
63
68
|
|
|
64
69
|
const cacheKey = [
|
|
65
70
|
'channel',
|
|
@@ -3,6 +3,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
import { fireEvent } from '~/core/events';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { removeChannelMembers } from '@amityco/ts-sdk'
|
|
@@ -25,17 +27,16 @@ export const removeChannelMembers = async (
|
|
|
25
27
|
const client = getActiveClient();
|
|
26
28
|
client.log('channel/removeChannelMembers', channelId, userIds);
|
|
27
29
|
|
|
28
|
-
const { data } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
30
|
+
const { data: payload } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
29
31
|
`/api/v3/channels/${encodeURIComponent(channelId)}/users`,
|
|
30
32
|
{ data: { channelId, userIds } },
|
|
31
33
|
);
|
|
32
34
|
|
|
35
|
+
const data = prepareChannelPayload(payload);
|
|
36
|
+
|
|
33
37
|
if (client.cache) ingestInCache(data);
|
|
34
38
|
|
|
35
|
-
fireEvent('v3.channel.didRemoveUsers',
|
|
36
|
-
channels: data.channels,
|
|
37
|
-
channelUsers: data.channelUsers,
|
|
38
|
-
});
|
|
39
|
+
fireEvent('v3.channel.didRemoveUsers', data);
|
|
39
40
|
|
|
40
41
|
const { channelUsers } = data;
|
|
41
42
|
return !!channelUsers.find(
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { removeChannelMembersRole } from '@amityco/ts-sdk'
|
|
@@ -26,11 +28,13 @@ export const removeChannelMembersRole = async (
|
|
|
26
28
|
const client = getActiveClient();
|
|
27
29
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
28
30
|
|
|
29
|
-
const { data } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
31
|
+
const { data: payload } = await client.http.delete<Amity.ChannelMembershipPayload>(
|
|
30
32
|
`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`,
|
|
31
33
|
{ data: { channelId, role: roleId, userIds } },
|
|
32
34
|
);
|
|
33
35
|
|
|
36
|
+
const data = prepareChannelPayload(payload);
|
|
37
|
+
|
|
34
38
|
if (client.cache) ingestInCache(data);
|
|
35
39
|
|
|
36
40
|
const { channelUsers } = data;
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api/activeClient';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { unbanChannelMembers } from '@amityco/ts-sdk'
|
|
@@ -23,17 +25,19 @@ export const unbanChannelMembers = async (
|
|
|
23
25
|
const client = getActiveClient();
|
|
24
26
|
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
25
27
|
|
|
26
|
-
const payload = await client.http.put<Amity.ChannelPayload>(
|
|
28
|
+
const { data: payload } = await client.http.put<Amity.ChannelPayload>(
|
|
27
29
|
`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`,
|
|
28
30
|
{
|
|
29
31
|
userIds,
|
|
30
32
|
},
|
|
31
33
|
);
|
|
32
34
|
|
|
35
|
+
const data = prepareChannelPayload(payload);
|
|
36
|
+
|
|
33
37
|
const cachedAt = client.cache && Date.now();
|
|
34
|
-
if (client.cache) ingestInCache(
|
|
38
|
+
if (client.cache) ingestInCache(data, { cachedAt });
|
|
35
39
|
|
|
36
|
-
const { channelUsers } =
|
|
40
|
+
const { channelUsers } = data;
|
|
37
41
|
return {
|
|
38
42
|
data: channelUsers?.filter(user => user.membership === 'member')!,
|
|
39
43
|
cachedAt,
|
|
@@ -2,6 +2,8 @@ import { getActiveClient } from '~/client/api';
|
|
|
2
2
|
|
|
3
3
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
4
4
|
|
|
5
|
+
import { prepareChannelPayload } from '../utils';
|
|
6
|
+
|
|
5
7
|
/**
|
|
6
8
|
* ```js
|
|
7
9
|
* import { updateChannel } from '@amityco/ts-sdk'
|
|
@@ -24,11 +26,13 @@ export const updateChannel = async (
|
|
|
24
26
|
const client = getActiveClient();
|
|
25
27
|
client.log('channel/updateChannel', channelId, patch);
|
|
26
28
|
|
|
27
|
-
const { data } = await client.http.put<Amity.ChannelPayload>(
|
|
29
|
+
const { data: payload } = await client.http.put<Amity.ChannelPayload>(
|
|
28
30
|
`/api/v3/channels/${encodeURIComponent(channelId)}`,
|
|
29
31
|
patch,
|
|
30
32
|
);
|
|
31
33
|
|
|
34
|
+
const data = prepareChannelPayload(payload);
|
|
35
|
+
|
|
32
36
|
const cachedAt = client.cache && Date.now();
|
|
33
37
|
if (client.cache) ingestInCache(data, { cachedAt });
|
|
34
38
|
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
@@ -22,8 +24,10 @@ export const onChannelCreated = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const data = prepareChannelPayload(payload);
|
|
28
|
+
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callback(data.channels[0]);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return createEventSubscriber(client, 'onChannelCreated', 'v3.channel.didCreate', filter);
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelDeleted } from '@amityco/ts-sdk'
|
|
@@ -22,8 +24,10 @@ export const onChannelDeleted = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const data = prepareChannelPayload(payload);
|
|
28
|
+
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callback(data.channels[0]);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return createEventSubscriber(client, 'onChannelDeleted', 'v3.channel.didDelete', filter);
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelJoined } from '@amityco/ts-sdk'
|
|
@@ -22,8 +24,10 @@ export const onChannelJoined = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const data = prepareChannelPayload(payload);
|
|
28
|
+
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callback(data.channels[0]);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return createEventSubscriber(client, 'onChannelJoined', 'v3.channel.didJoin', filter);
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelLeft } from '@amityco/ts-sdk'
|
|
@@ -22,8 +24,10 @@ export const onChannelLeft = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const data = prepareChannelPayload(payload);
|
|
28
|
+
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callback(data.channels[0]);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return createEventSubscriber(client, 'onChannelLeft', 'v3.channel.didLeave', filter);
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelMemberAdded } from '@amityco/ts-sdk'
|
|
@@ -24,8 +26,10 @@ export const onChannelMemberAdded = (
|
|
|
24
26
|
const client = getActiveClient();
|
|
25
27
|
|
|
26
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const data = prepareChannelPayload(payload);
|
|
30
|
+
|
|
31
|
+
ingestInCache(data);
|
|
32
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelMemberRemoved } from '@amityco/ts-sdk'
|
|
@@ -24,8 +26,10 @@ export const onChannelMemberRemoved = (
|
|
|
24
26
|
const client = getActiveClient();
|
|
25
27
|
|
|
26
28
|
const filter = (payload: Amity.ChannelMembershipPayload) => {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
+
const data = prepareChannelPayload(payload);
|
|
30
|
+
|
|
31
|
+
ingestInCache(data);
|
|
32
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
29
33
|
};
|
|
30
34
|
|
|
31
35
|
return createEventSubscriber(
|
|
@@ -3,6 +3,8 @@ import { createEventSubscriber } from '~/core/events';
|
|
|
3
3
|
|
|
4
4
|
import { ingestInCache } from '~/cache/api/ingestInCache';
|
|
5
5
|
|
|
6
|
+
import { prepareChannelPayload } from '../utils';
|
|
7
|
+
|
|
6
8
|
/**
|
|
7
9
|
* ```js
|
|
8
10
|
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
@@ -22,8 +24,10 @@ export const onChannelUpdated = (callback: Amity.Listener<Amity.Channel>) => {
|
|
|
22
24
|
const client = getActiveClient();
|
|
23
25
|
|
|
24
26
|
const filter = (payload: Amity.ChannelPayload) => {
|
|
25
|
-
|
|
26
|
-
|
|
27
|
+
const data = prepareChannelPayload(payload);
|
|
28
|
+
|
|
29
|
+
ingestInCache(data);
|
|
30
|
+
callback(data.channels[0]);
|
|
27
31
|
};
|
|
28
32
|
|
|
29
33
|
return createEventSubscriber(client, 'onChannelUpdated', 'v3.channel.didUpdate', filter);
|
|
@@ -29,17 +29,7 @@ import {
|
|
|
29
29
|
*
|
|
30
30
|
* @category Channel Observer
|
|
31
31
|
*/
|
|
32
|
-
export const observeChannel = <
|
|
33
|
-
Events extends [
|
|
34
|
-
'onFetch',
|
|
35
|
-
'onUpdate',
|
|
36
|
-
'onDelete',
|
|
37
|
-
'onJoin',
|
|
38
|
-
'onLeft',
|
|
39
|
-
'onMemberAdded',
|
|
40
|
-
'onMemberRemoved',
|
|
41
|
-
],
|
|
42
|
-
>(
|
|
32
|
+
export const observeChannel = <Events extends [Exclude<Amity.ChannelActionType, 'onCreate'>]>(
|
|
43
33
|
channelId: string,
|
|
44
34
|
callback: Amity.ObjectListener<Amity.Snapshot<Amity.Channel>, Events>,
|
|
45
35
|
): Amity.Unsubscriber => {
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { getActiveClient } from '~/client/api';
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
onChannelCreated,
|
|
5
|
+
onChannelUpdated,
|
|
6
|
+
onChannelDeleted,
|
|
7
|
+
onChannelJoined,
|
|
8
|
+
onChannelLeft,
|
|
9
|
+
onChannelMemberAdded,
|
|
10
|
+
onChannelMemberRemoved,
|
|
11
|
+
} from '../events';
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* ```js
|
|
15
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
16
|
+
*
|
|
17
|
+
* let channels = []
|
|
18
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
19
|
+
* ```
|
|
20
|
+
*
|
|
21
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
22
|
+
*
|
|
23
|
+
* @param callback the function to call when new data are available
|
|
24
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
25
|
+
*
|
|
26
|
+
* @category Channel Observer
|
|
27
|
+
*/
|
|
28
|
+
export const observeChannels = (
|
|
29
|
+
callback: Amity.ObjectListener<Amity.Channel, [Exclude<Amity.ChannelActionType, 'onFetch'>]>,
|
|
30
|
+
): Amity.Unsubscriber => {
|
|
31
|
+
const { log } = getActiveClient();
|
|
32
|
+
|
|
33
|
+
const timestamp = Date.now();
|
|
34
|
+
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
35
|
+
|
|
36
|
+
const disposers: Amity.Unsubscriber[] = [];
|
|
37
|
+
|
|
38
|
+
const router = (channel: Amity.Channel, action: Exclude<Amity.ChannelActionType, 'onFetch'>) => {
|
|
39
|
+
if (callback instanceof Function) return callback(channel);
|
|
40
|
+
|
|
41
|
+
callback.onEvent?.(action, channel);
|
|
42
|
+
callback[action]?.(channel);
|
|
43
|
+
};
|
|
44
|
+
|
|
45
|
+
disposers.push(
|
|
46
|
+
onChannelCreated(data => router(data, 'onCreate')),
|
|
47
|
+
onChannelUpdated(data => router(data, 'onUpdate')),
|
|
48
|
+
onChannelDeleted(data => router(data, 'onDelete')),
|
|
49
|
+
onChannelJoined(data => router(data, 'onJoin')),
|
|
50
|
+
onChannelLeft(data => router(data, 'onLeft')),
|
|
51
|
+
onChannelMemberAdded(data => router(data, 'onMemberAdded')),
|
|
52
|
+
onChannelMemberRemoved(data => router(data, 'onMemberRemoved')),
|
|
53
|
+
);
|
|
54
|
+
|
|
55
|
+
return () => {
|
|
56
|
+
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
57
|
+
disposers.forEach(fn => fn());
|
|
58
|
+
};
|
|
59
|
+
};
|