@amityco/ts-sdk 0.0.1-beta.27 → 0.0.1-beta.29
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 +15 -13
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +17 -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/community.d.ts +24 -2
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +27 -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 +3 -3
- 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 +1 -10
- 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 +2 -0
- package/dist/channel/observers/index.d.ts.map +1 -1
- package/dist/channel/observers/liveChannels.d.ts +20 -0
- package/dist/channel/observers/liveChannels.d.ts.map +1 -0
- 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/observers/tests/liveChannels.test.d.ts +2 -0
- package/dist/channel/observers/tests/liveChannels.test.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/community/api/createCommunity.d.ts +1 -1
- package/dist/community/api/createCommunity.d.ts.map +1 -1
- package/dist/community/api/getCommunities.d.ts.map +1 -1
- package/dist/community/api/getCommunity.d.ts.map +1 -1
- package/dist/community/api/getRecommendedCommunities.d.ts.map +1 -1
- package/dist/community/api/getTopTrendingCommunities.d.ts.map +1 -1
- package/dist/community/api/queryCommunities.d.ts.map +1 -1
- package/dist/community/api/updateCommunity.d.ts +1 -1
- package/dist/community/api/updateCommunity.d.ts.map +1 -1
- package/dist/community/events/utils.d.ts.map +1 -1
- package/dist/community/utils/index.d.ts +2 -0
- package/dist/community/utils/index.d.ts.map +1 -0
- package/dist/community/utils/payload.d.ts +11 -0
- package/dist/community/utils/payload.d.ts.map +1 -0
- 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/follow/tests/observers/liveFollowers.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowers.test.d.ts.map +1 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts +2 -0
- package/dist/follow/tests/observers/liveFollowings.test.d.ts.map +1 -0
- package/dist/index.cjs.js +751 -128
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +737 -129
- 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 +33 -0
- package/dist/utils/tests/dummy/channel.d.ts.map +1 -0
- package/dist/utils/tests/dummy/follow.d.ts +12 -0
- package/dist/utils/tests/dummy/follow.d.ts.map +1 -0
- package/dist/utils/tests/dummy/index.d.ts +11 -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 +5 -0
- package/dist/utils/tests/dummy/user.d.ts.map +1 -0
- package/dist/utils/tests/index.d.ts +3 -2
- package/dist/utils/tests/index.d.ts.map +1 -1
- package/dist/utils/tests/utils.d.ts +2 -0
- package/dist/utils/tests/utils.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/@types/core/payload.ts +19 -13
- package/src/@types/domains/channel.ts +34 -1
- package/src/@types/domains/client.ts +17 -0
- package/src/@types/domains/community.ts +27 -2
- package/src/@types/domains/content.ts +35 -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 +4 -3
- 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 +12 -14
- 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 +2 -0
- package/src/channel/observers/liveChannels.ts +178 -0
- package/src/channel/observers/observeChannel.ts +1 -11
- package/src/channel/observers/observeChannels.ts +59 -0
- package/src/channel/observers/tests/liveChannels.test.ts +173 -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/community/api/createCommunity.ts +9 -3
- package/src/community/api/getCommunities.ts +10 -3
- package/src/community/api/getCommunity.ts +5 -1
- package/src/community/api/getRecommendedCommunities.ts +5 -2
- package/src/community/api/getTopTrendingCommunities.ts +4 -1
- package/src/community/api/queryCommunities.ts +5 -2
- package/src/community/api/updateCommunity.ts +7 -3
- package/src/community/events/utils.ts +13 -7
- package/src/community/utils/index.ts +1 -0
- package/src/community/utils/payload.ts +44 -0
- package/src/core/events.ts +2 -1
- package/src/core/model/identifyModel.ts +1 -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/follow/tests/observers/liveFollowers.test.ts +240 -0
- package/src/follow/tests/observers/liveFollowings.test.ts +239 -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 +313 -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 +96 -0
- package/src/utils/tests/dummy/follow.ts +60 -0
- package/src/utils/tests/dummy/index.ts +8 -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 +26 -0
- package/src/utils/tests/index.ts +3 -2
- package/src/utils/tests/utils.ts +3 -0
- package/dist/utils/tests/dummy.d.ts.map +0 -1
- package/src/utils/tests/dummy.ts +0 -7
package/dist/index.esm.js
CHANGED
|
@@ -7,6 +7,60 @@ import HttpAgent, { HttpsAgent } from 'agentkeepalive';
|
|
|
7
7
|
import io from 'socket.io-client';
|
|
8
8
|
import nativeIdGenerator from 'react-native-uuid';
|
|
9
9
|
|
|
10
|
+
const CommunityPostSettings = Object.freeze({
|
|
11
|
+
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
12
|
+
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
13
|
+
ANYONE_CAN_POST: 'ANYONE_CAN_POST',
|
|
14
|
+
});
|
|
15
|
+
const CommunityPostSettingMaps = Object.freeze({
|
|
16
|
+
ONLY_ADMIN_CAN_POST: {
|
|
17
|
+
needApprovalOnPostCreation: false,
|
|
18
|
+
onlyAdminCanPost: true,
|
|
19
|
+
},
|
|
20
|
+
ADMIN_REVIEW_POST_REQUIRED: {
|
|
21
|
+
needApprovalOnPostCreation: true,
|
|
22
|
+
onlyAdminCanPost: false,
|
|
23
|
+
},
|
|
24
|
+
ANYONE_CAN_POST: {
|
|
25
|
+
needApprovalOnPostCreation: false,
|
|
26
|
+
onlyAdminCanPost: false,
|
|
27
|
+
},
|
|
28
|
+
});
|
|
29
|
+
const DefaultCommunityPostSetting = 'ONLY_ADMIN_CAN_POST';
|
|
30
|
+
|
|
31
|
+
const ContentFeedType = Object.freeze({
|
|
32
|
+
STORY: 'story',
|
|
33
|
+
CLIP: 'clip',
|
|
34
|
+
CHAT: 'chat',
|
|
35
|
+
POST: 'post',
|
|
36
|
+
MESSAGE: 'message',
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const FileType = Object.freeze({
|
|
40
|
+
FILE: 'file',
|
|
41
|
+
IMAGE: 'image',
|
|
42
|
+
VIDEO: 'video',
|
|
43
|
+
});
|
|
44
|
+
const VideoResolution = Object.freeze({
|
|
45
|
+
'1080P': '1080p',
|
|
46
|
+
'720P': '720p',
|
|
47
|
+
'480P': '480p',
|
|
48
|
+
'360P': '360p',
|
|
49
|
+
ORIGINAL: 'original',
|
|
50
|
+
});
|
|
51
|
+
const VideoTranscodingStatus = Object.freeze({
|
|
52
|
+
UPLOADED: 'uploaded',
|
|
53
|
+
TRANSCODING: 'transcoding',
|
|
54
|
+
TRANSCODED: 'transcoded',
|
|
55
|
+
TRANSCODE_FAILED: 'transcodeFailed',
|
|
56
|
+
});
|
|
57
|
+
const VideoSize = Object.freeze({
|
|
58
|
+
LOW: 'low',
|
|
59
|
+
MEDIUM: 'medium',
|
|
60
|
+
HIGH: 'high',
|
|
61
|
+
ORIGINAL: 'original',
|
|
62
|
+
});
|
|
63
|
+
|
|
10
64
|
var _a$1;
|
|
11
65
|
/* eslint-disable no-undef */
|
|
12
66
|
const theGlobal =
|
|
@@ -211,7 +265,7 @@ const CRITERIAS = {
|
|
|
211
265
|
channel: ['channelId', 'rateLimit'],
|
|
212
266
|
channelUsers: ['channelId', 'userId', 'membership'],
|
|
213
267
|
message: ['messageId'],
|
|
214
|
-
community: ['communityId', '
|
|
268
|
+
community: ['communityId', 'postSetting'],
|
|
215
269
|
category: ['categoryId'],
|
|
216
270
|
communityUsers: ['userId', 'communityId', 'communityMembership'],
|
|
217
271
|
post: ['postId', 'feedId'],
|
|
@@ -354,7 +408,7 @@ const isFresh = (model, lifeSpan = 0) => {
|
|
|
354
408
|
* This wrapper is necessary to create for optimistically calls
|
|
355
409
|
*
|
|
356
410
|
*
|
|
357
|
-
* @param
|
|
411
|
+
* @param func A compatible API function from the ts sdk
|
|
358
412
|
* @param args The arguments to pass to the function passed as `fn`
|
|
359
413
|
* @returns A wrapper containing both the function and its future arguments
|
|
360
414
|
*
|
|
@@ -640,8 +694,9 @@ const WS_EVENTS = [
|
|
|
640
694
|
'connect_error',
|
|
641
695
|
'reconnect_error',
|
|
642
696
|
'reconnect_failed',
|
|
697
|
+
'v3.channel.didCreate',
|
|
643
698
|
'v3.channel.didUpdate',
|
|
644
|
-
'v3.channel.
|
|
699
|
+
'v3.channel.didDelete',
|
|
645
700
|
'v3.channel.didJoin',
|
|
646
701
|
'v3.channel.didLeave',
|
|
647
702
|
'v3.channel.didAddUsers',
|
|
@@ -20141,6 +20196,29 @@ const createMqttTransport = (endpoint) => {
|
|
|
20141
20196
|
};
|
|
20142
20197
|
};
|
|
20143
20198
|
|
|
20199
|
+
/**
|
|
20200
|
+
* ```js
|
|
20201
|
+
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
20202
|
+
* const feedSettings = await getFeedSettings()
|
|
20203
|
+
* const postFeedSetting = feedSettings.post
|
|
20204
|
+
* ```
|
|
20205
|
+
*
|
|
20206
|
+
* Fetches a {@link Amity.FeedSettings} object
|
|
20207
|
+
*
|
|
20208
|
+
* @returns A Promise of {@link Amity.FeedSettings} object
|
|
20209
|
+
*
|
|
20210
|
+
* @category Client API
|
|
20211
|
+
* @async
|
|
20212
|
+
*/
|
|
20213
|
+
const getFeedSettings = async () => {
|
|
20214
|
+
const client = getActiveClient();
|
|
20215
|
+
const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
|
|
20216
|
+
return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
|
|
20217
|
+
return [feedType, contentSettings];
|
|
20218
|
+
}));
|
|
20219
|
+
};
|
|
20220
|
+
|
|
20221
|
+
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
20144
20222
|
/**
|
|
20145
20223
|
* ```js
|
|
20146
20224
|
* import { createClient } from '@amityco/ts-sdk'
|
|
@@ -20151,20 +20229,24 @@ const createMqttTransport = (endpoint) => {
|
|
|
20151
20229
|
*
|
|
20152
20230
|
* @param apiKey for the {@link Amity.Client} instance
|
|
20153
20231
|
* @param apiRegion endpoint to connect to
|
|
20232
|
+
* @param apiEndpoint custom endpoint in case you don't want to use a preset endpoint
|
|
20154
20233
|
* @param debugSession session's identifier for the client's logger instance
|
|
20155
20234
|
* @returns A {@link Amity.Client} instance
|
|
20156
20235
|
*
|
|
20157
20236
|
* @category Client API
|
|
20158
20237
|
* */
|
|
20159
|
-
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession =
|
|
20238
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, } = {}) => {
|
|
20239
|
+
var _a, _b;
|
|
20160
20240
|
const log = createLogger(debugSession);
|
|
20161
20241
|
log('client/api/createClient', {
|
|
20162
20242
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
20163
20243
|
apiRegion,
|
|
20164
20244
|
});
|
|
20165
|
-
const
|
|
20166
|
-
const
|
|
20167
|
-
const
|
|
20245
|
+
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
20246
|
+
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
20247
|
+
const http = createHttpTransport(httpEndpoint);
|
|
20248
|
+
const ws = createWebsocketTransport(httpEndpoint);
|
|
20249
|
+
const mqtt = createMqttTransport(mqttEndpoint);
|
|
20168
20250
|
const emitter = createEventEmitter();
|
|
20169
20251
|
const client = {
|
|
20170
20252
|
version: `${VERSION$1}`,
|
|
@@ -20175,11 +20257,12 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity'
|
|
|
20175
20257
|
mqtt,
|
|
20176
20258
|
emitter,
|
|
20177
20259
|
use: () => setActiveClient(client),
|
|
20260
|
+
getFeedSettings,
|
|
20178
20261
|
};
|
|
20179
20262
|
try {
|
|
20180
20263
|
getActiveClient();
|
|
20181
20264
|
}
|
|
20182
|
-
catch (
|
|
20265
|
+
catch (_c) {
|
|
20183
20266
|
setActiveClient(client);
|
|
20184
20267
|
}
|
|
20185
20268
|
return client;
|
|
@@ -20248,6 +20331,58 @@ const getDeviceInfo = () => {
|
|
|
20248
20331
|
};
|
|
20249
20332
|
};
|
|
20250
20333
|
|
|
20334
|
+
/**
|
|
20335
|
+
* Ingest a payload (v3) into the cache
|
|
20336
|
+
*
|
|
20337
|
+
* @param payload a "backend v3" payload object
|
|
20338
|
+
* @param order the order of the keys to process (in case of need)
|
|
20339
|
+
*
|
|
20340
|
+
* @category Cache
|
|
20341
|
+
* @hidden
|
|
20342
|
+
*/
|
|
20343
|
+
const ingestInCache = (payload = {}, options) => {
|
|
20344
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
20345
|
+
const type = PAYLOAD2MODEL[key];
|
|
20346
|
+
if (!type)
|
|
20347
|
+
return;
|
|
20348
|
+
const resolver = getResolver(type);
|
|
20349
|
+
models.forEach(model => {
|
|
20350
|
+
upsertInCache(
|
|
20351
|
+
// eslint-disable @typescript-eslint no-explicit-any
|
|
20352
|
+
[type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20353
|
+
model, options);
|
|
20354
|
+
});
|
|
20355
|
+
});
|
|
20356
|
+
};
|
|
20357
|
+
|
|
20358
|
+
const createUserEventSubscriber = (event, callback) => {
|
|
20359
|
+
const client = getActiveClient();
|
|
20360
|
+
const filter = (payload) => {
|
|
20361
|
+
if (client.cache) {
|
|
20362
|
+
ingestInCache(payload);
|
|
20363
|
+
}
|
|
20364
|
+
callback(payload.users[0]);
|
|
20365
|
+
};
|
|
20366
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20367
|
+
};
|
|
20368
|
+
|
|
20369
|
+
/**
|
|
20370
|
+
* ```js
|
|
20371
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20372
|
+
* const dispose = onUserDeleted(user => {
|
|
20373
|
+
* // ...
|
|
20374
|
+
* })
|
|
20375
|
+
* ```
|
|
20376
|
+
*
|
|
20377
|
+
* Fired when a {@link Amity.User} has been deleted
|
|
20378
|
+
*
|
|
20379
|
+
* @param callback The function to call when the event was fired
|
|
20380
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20381
|
+
*
|
|
20382
|
+
* @category User Events
|
|
20383
|
+
*/
|
|
20384
|
+
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20385
|
+
|
|
20251
20386
|
/**
|
|
20252
20387
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
20253
20388
|
*
|
|
@@ -20348,58 +20483,6 @@ const onClientBanned = (callback) => {
|
|
|
20348
20483
|
});
|
|
20349
20484
|
};
|
|
20350
20485
|
|
|
20351
|
-
/**
|
|
20352
|
-
* Ingest a payload (v3) into the cache
|
|
20353
|
-
*
|
|
20354
|
-
* @param payload a "backend v3" payload object
|
|
20355
|
-
* @param order the order of the keys to process (in case of need)
|
|
20356
|
-
*
|
|
20357
|
-
* @category Cache
|
|
20358
|
-
* @hidden
|
|
20359
|
-
*/
|
|
20360
|
-
const ingestInCache = (payload = {}, options) => {
|
|
20361
|
-
Object.entries(payload).forEach(([key, models]) => {
|
|
20362
|
-
const type = PAYLOAD2MODEL[key];
|
|
20363
|
-
if (!type)
|
|
20364
|
-
return;
|
|
20365
|
-
const resolver = getResolver(type);
|
|
20366
|
-
models.forEach(model => {
|
|
20367
|
-
upsertInCache(
|
|
20368
|
-
// eslint-disable @typescript-eslint no-explicit-any
|
|
20369
|
-
[type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20370
|
-
model, options);
|
|
20371
|
-
});
|
|
20372
|
-
});
|
|
20373
|
-
};
|
|
20374
|
-
|
|
20375
|
-
const createUserEventSubscriber = (event, callback) => {
|
|
20376
|
-
const client = getActiveClient();
|
|
20377
|
-
const filter = (payload) => {
|
|
20378
|
-
if (client.cache) {
|
|
20379
|
-
ingestInCache(payload);
|
|
20380
|
-
}
|
|
20381
|
-
callback(payload.users[0]);
|
|
20382
|
-
};
|
|
20383
|
-
return createEventSubscriber(client, event, event, filter);
|
|
20384
|
-
};
|
|
20385
|
-
|
|
20386
|
-
/**
|
|
20387
|
-
* ```js
|
|
20388
|
-
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20389
|
-
* const dispose = onUserDeleted(user => {
|
|
20390
|
-
* // ...
|
|
20391
|
-
* })
|
|
20392
|
-
* ```
|
|
20393
|
-
*
|
|
20394
|
-
* Fired when a {@link Amity.User} has been deleted
|
|
20395
|
-
*
|
|
20396
|
-
* @param callback The function to call when the event was fired
|
|
20397
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20398
|
-
*
|
|
20399
|
-
* @category User Events
|
|
20400
|
-
*/
|
|
20401
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20402
|
-
|
|
20403
20486
|
/* eslint-disable no-param-reassign */
|
|
20404
20487
|
/**
|
|
20405
20488
|
* ```js
|
|
@@ -20967,17 +21050,21 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
20967
21050
|
* Creates an {@link Amity.File<'video'>}
|
|
20968
21051
|
*
|
|
20969
21052
|
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
21053
|
+
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
20970
21054
|
* @param onProgress The callback to track the upload progress
|
|
20971
21055
|
* @returns The newly created {@link Amity.File<'video'>}
|
|
20972
21056
|
*
|
|
20973
21057
|
* @category File API
|
|
20974
21058
|
* @async
|
|
20975
21059
|
*/
|
|
20976
|
-
const createVideo = async (formData, onProgress) => {
|
|
21060
|
+
const createVideo = async (formData, feedType, onProgress) => {
|
|
20977
21061
|
const client = getActiveClient();
|
|
20978
21062
|
client.log('file/createVideo', formData);
|
|
20979
21063
|
if (!formData.getAll('files').length)
|
|
20980
21064
|
throw new Error('The formData object must have a `files` key.');
|
|
21065
|
+
if (feedType) {
|
|
21066
|
+
formData.append('feedType', feedType);
|
|
21067
|
+
}
|
|
20981
21068
|
const headers = 'getHeaders' in formData
|
|
20982
21069
|
? formData.getHeaders()
|
|
20983
21070
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -21860,6 +21947,33 @@ const updatePost = async (postId, patch) => {
|
|
|
21860
21947
|
};
|
|
21861
21948
|
};
|
|
21862
21949
|
|
|
21950
|
+
const getMatchPostSetting = (value) => {
|
|
21951
|
+
var _a;
|
|
21952
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
21953
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
21954
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
21955
|
+
};
|
|
21956
|
+
/*
|
|
21957
|
+
* Unpack community payload by mapping payload field to postSetting value.
|
|
21958
|
+
*/
|
|
21959
|
+
const unpackCommunityPayload = (_a) => {
|
|
21960
|
+
var { communities } = _a, restPayload = __rest(_a, ["communities"]);
|
|
21961
|
+
return (Object.assign({ communities: communities.map((_a) => {
|
|
21962
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
21963
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
21964
|
+
needApprovalOnPostCreation,
|
|
21965
|
+
onlyAdminCanPost,
|
|
21966
|
+
}) }, restCommunityPayload));
|
|
21967
|
+
}) }, restPayload));
|
|
21968
|
+
};
|
|
21969
|
+
/*
|
|
21970
|
+
* Repack community payload by mapping postSetting to the actual value.
|
|
21971
|
+
*/
|
|
21972
|
+
const packCommunityPayload = (_a) => {
|
|
21973
|
+
var { postSetting = undefined } = _a, restParam = __rest(_a, ["postSetting"]);
|
|
21974
|
+
return (Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)));
|
|
21975
|
+
};
|
|
21976
|
+
|
|
21863
21977
|
/**
|
|
21864
21978
|
* ```js
|
|
21865
21979
|
* import { queryCommunities } from '@amityco/ts-sdk'
|
|
@@ -21889,10 +22003,11 @@ const queryCommunities = async (query) => {
|
|
|
21889
22003
|
} }),
|
|
21890
22004
|
});
|
|
21891
22005
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21892
|
-
const
|
|
22006
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
22007
|
+
const { communities } = unpackedPayload;
|
|
21893
22008
|
const cachedAt = client.cache && Date.now();
|
|
21894
22009
|
if (client.cache) {
|
|
21895
|
-
ingestInCache(
|
|
22010
|
+
ingestInCache(unpackedPayload, { cachedAt });
|
|
21896
22011
|
const cacheKey = [
|
|
21897
22012
|
'community',
|
|
21898
22013
|
'query',
|
|
@@ -21941,9 +22056,10 @@ const getCommunities = async (communityIds) => {
|
|
|
21941
22056
|
const client = getActiveClient();
|
|
21942
22057
|
client.log('community/getCommunities', communityIds);
|
|
21943
22058
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
21944
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
22059
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
21945
22060
|
params: { communityIds },
|
|
21946
22061
|
});
|
|
22062
|
+
const data = unpackCommunityPayload(payload);
|
|
21947
22063
|
const cachedAt = client.cache && Date.now();
|
|
21948
22064
|
if (client.cache)
|
|
21949
22065
|
ingestInCache(data, { cachedAt });
|
|
@@ -22002,7 +22118,8 @@ const getCommunity = async (communityId) => {
|
|
|
22002
22118
|
const client = getActiveClient();
|
|
22003
22119
|
client.log('community/getCommunity', communityId);
|
|
22004
22120
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22005
|
-
const { data } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22121
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22122
|
+
const data = unpackCommunityPayload(payload);
|
|
22006
22123
|
const cachedAt = client.cache && Date.now();
|
|
22007
22124
|
if (client.cache)
|
|
22008
22125
|
ingestInCache(data, { cachedAt });
|
|
@@ -22056,7 +22173,8 @@ getCommunity.locally = (communityId) => {
|
|
|
22056
22173
|
const createCommunity = async (bundle) => {
|
|
22057
22174
|
const client = getActiveClient();
|
|
22058
22175
|
client.log('user/createCommunity', bundle);
|
|
22059
|
-
const { data } = await client.http.post('/api/v3/communities/', bundle);
|
|
22176
|
+
const { data: payload } = await client.http.post('/api/v3/communities/', packCommunityPayload(bundle));
|
|
22177
|
+
const data = unpackCommunityPayload(payload);
|
|
22060
22178
|
const cachedAt = client.cache && Date.now();
|
|
22061
22179
|
if (client.cache)
|
|
22062
22180
|
ingestInCache(data, { cachedAt });
|
|
@@ -22086,7 +22204,8 @@ const createCommunity = async (bundle) => {
|
|
|
22086
22204
|
const updateCommunity = async (communityId, patch) => {
|
|
22087
22205
|
const client = getActiveClient();
|
|
22088
22206
|
client.log('community/updateCommunity', communityId, patch);
|
|
22089
|
-
const { data } = await client.http.put(`/api/v3/communities/${communityId}`, patch);
|
|
22207
|
+
const { data: payload } = await client.http.put(`/api/v3/communities/${communityId}`, packCommunityPayload(patch));
|
|
22208
|
+
const data = unpackCommunityPayload(payload);
|
|
22090
22209
|
const cachedAt = client.cache && Date.now();
|
|
22091
22210
|
if (client.cache)
|
|
22092
22211
|
ingestInCache(data, { cachedAt });
|
|
@@ -22352,7 +22471,8 @@ const getTopTrendingCommunities = async (query) => {
|
|
|
22352
22471
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22353
22472
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22354
22473
|
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22355
|
-
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22474
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22475
|
+
const data = unpackCommunityPayload(payload);
|
|
22356
22476
|
const { communities } = data;
|
|
22357
22477
|
const cachedAt = client.cache && Date.now();
|
|
22358
22478
|
if (client.cache) {
|
|
@@ -22414,8 +22534,9 @@ const getRecommendedCommunities = async (query) => {
|
|
|
22414
22534
|
client.log('channel/getRecommendedCommunities', query);
|
|
22415
22535
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22416
22536
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22417
|
-
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22418
|
-
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22537
|
+
// const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22538
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22539
|
+
const data = unpackCommunityPayload(payload);
|
|
22419
22540
|
const { communities } = data;
|
|
22420
22541
|
const cachedAt = client.cache && Date.now();
|
|
22421
22542
|
if (client.cache) {
|
|
@@ -23751,7 +23872,8 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
23751
23872
|
};
|
|
23752
23873
|
|
|
23753
23874
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
23754
|
-
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
23875
|
+
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
23876
|
+
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
23755
23877
|
|
|
23756
23878
|
/**
|
|
23757
23879
|
* ```js
|
|
@@ -23953,6 +24075,23 @@ const isReportedByMe = async (referenceType, referenceId) => {
|
|
|
23953
24075
|
return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
|
|
23954
24076
|
};
|
|
23955
24077
|
|
|
24078
|
+
/** @hidden */
|
|
24079
|
+
const prepareChannelPayload = (payload) => {
|
|
24080
|
+
const client = getActiveClient();
|
|
24081
|
+
const channels = payload.channels.map(channel => {
|
|
24082
|
+
const channelUser = payload.channelUsers.find(channelUser => channelUser.userId === client.userId && channel.channelId === channelUser.channelId);
|
|
24083
|
+
const hasMention = channelUser
|
|
24084
|
+
? channelUser.readToSegment < channelUser.lastMentionedSegment
|
|
24085
|
+
: false;
|
|
24086
|
+
const unreadCount = channelUser && channelUser.membership === 'member' && channel.messageCount
|
|
24087
|
+
? Math.max(0, channel.messageCount - channelUser.readToSegment)
|
|
24088
|
+
: 0;
|
|
24089
|
+
return Object.assign(Object.assign({}, channel), { hasMention,
|
|
24090
|
+
unreadCount });
|
|
24091
|
+
});
|
|
24092
|
+
return Object.assign(Object.assign({}, payload), { channels });
|
|
24093
|
+
};
|
|
24094
|
+
|
|
23956
24095
|
/**
|
|
23957
24096
|
* ```js
|
|
23958
24097
|
* import { queryChannels } from '@amityco/ts-sdk'
|
|
@@ -23976,16 +24115,17 @@ const queryChannels = async (query) => {
|
|
|
23976
24115
|
// API-FIX: parameters should be querystring.
|
|
23977
24116
|
// API-FIX: backend doesnt answer Amity.Response
|
|
23978
24117
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
23979
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
24118
|
+
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
23980
24119
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
23981
24120
|
token: toToken(page, 'skiplimit'),
|
|
23982
24121
|
} }),
|
|
23983
24122
|
});
|
|
23984
|
-
const { paging } =
|
|
23985
|
-
const
|
|
24123
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24124
|
+
const data = prepareChannelPayload(payload);
|
|
24125
|
+
const { channels } = data;
|
|
23986
24126
|
const cachedAt = client.cache && Date.now();
|
|
23987
24127
|
if (client.cache) {
|
|
23988
|
-
ingestInCache(
|
|
24128
|
+
ingestInCache(data, { cachedAt });
|
|
23989
24129
|
const cacheKey = [
|
|
23990
24130
|
'channel',
|
|
23991
24131
|
'query',
|
|
@@ -24035,9 +24175,10 @@ const getChannels = async (channelIds) => {
|
|
|
24035
24175
|
client.log('channel/getChannels', channelIds);
|
|
24036
24176
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
24037
24177
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24038
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
24178
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/list`, {
|
|
24039
24179
|
params: { channelIds: encodedChannelIds },
|
|
24040
24180
|
});
|
|
24181
|
+
const data = prepareChannelPayload(payload);
|
|
24041
24182
|
const cachedAt = client.cache && Date.now();
|
|
24042
24183
|
if (client.cache)
|
|
24043
24184
|
ingestInCache(data, { cachedAt });
|
|
@@ -24096,7 +24237,8 @@ const getChannel = async (channelId) => {
|
|
|
24096
24237
|
const client = getActiveClient();
|
|
24097
24238
|
client.log('channel/getChannel', channelId);
|
|
24098
24239
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24099
|
-
const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
24240
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
24241
|
+
const data = prepareChannelPayload(payload);
|
|
24100
24242
|
const cachedAt = client.cache && Date.now();
|
|
24101
24243
|
if (client.cache)
|
|
24102
24244
|
ingestInCache(data, { cachedAt });
|
|
@@ -24157,10 +24299,11 @@ const createChannel = async (bundle) => {
|
|
|
24157
24299
|
else {
|
|
24158
24300
|
payload = await client.http.post('/api/v3/channels', bundle);
|
|
24159
24301
|
}
|
|
24302
|
+
const data = prepareChannelPayload(payload.data);
|
|
24160
24303
|
const cachedAt = client.cache && Date.now();
|
|
24161
24304
|
if (client.cache)
|
|
24162
|
-
ingestInCache(
|
|
24163
|
-
const { channels } =
|
|
24305
|
+
ingestInCache(data, { cachedAt });
|
|
24306
|
+
const { channels } = data;
|
|
24164
24307
|
return {
|
|
24165
24308
|
data: channels[0],
|
|
24166
24309
|
cachedAt,
|
|
@@ -24185,7 +24328,8 @@ const createChannel = async (bundle) => {
|
|
|
24185
24328
|
const updateChannel = async (channelId, patch) => {
|
|
24186
24329
|
const client = getActiveClient();
|
|
24187
24330
|
client.log('channel/updateChannel', channelId, patch);
|
|
24188
|
-
const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24331
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24332
|
+
const data = prepareChannelPayload(payload);
|
|
24189
24333
|
const cachedAt = client.cache && Date.now();
|
|
24190
24334
|
if (client.cache)
|
|
24191
24335
|
ingestInCache(data, { cachedAt });
|
|
@@ -24236,7 +24380,8 @@ const deleteChannel = async (channelId) => {
|
|
|
24236
24380
|
const joinChannel = async (channelId) => {
|
|
24237
24381
|
const client = getActiveClient();
|
|
24238
24382
|
client.log('channel/joinChannel', channelId);
|
|
24239
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24383
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24384
|
+
const data = prepareChannelPayload(payload);
|
|
24240
24385
|
if (client.cache)
|
|
24241
24386
|
ingestInCache(data);
|
|
24242
24387
|
const { channelUsers } = data;
|
|
@@ -24260,7 +24405,8 @@ const joinChannel = async (channelId) => {
|
|
|
24260
24405
|
const leaveChannel = async (channelId) => {
|
|
24261
24406
|
const client = getActiveClient();
|
|
24262
24407
|
client.log('channel/leaveChannel', channelId);
|
|
24263
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24408
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24409
|
+
const data = prepareChannelPayload(payload);
|
|
24264
24410
|
if (client.cache)
|
|
24265
24411
|
ingestInCache(data);
|
|
24266
24412
|
const { channelUsers } = data;
|
|
@@ -24285,16 +24431,17 @@ const queryChannelMembers = async (query) => {
|
|
|
24285
24431
|
const client = getActiveClient();
|
|
24286
24432
|
client.log('channel/queryChannelMembers', query);
|
|
24287
24433
|
const _a = query !== null && query !== void 0 ? query : {}, { page, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
|
|
24288
|
-
const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24434
|
+
const { data: queryPayload } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24289
24435
|
params: Object.assign(Object.assign({}, params), { options: {
|
|
24290
24436
|
token: toToken(page, 'skiplimit'),
|
|
24291
24437
|
} }),
|
|
24292
24438
|
});
|
|
24293
|
-
const { paging } =
|
|
24294
|
-
const
|
|
24439
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24440
|
+
const data = prepareChannelPayload(payload);
|
|
24441
|
+
const { channelUsers } = data;
|
|
24295
24442
|
const cachedAt = client.cache && Date.now();
|
|
24296
24443
|
if (client.cache) {
|
|
24297
|
-
ingestInCache(
|
|
24444
|
+
ingestInCache(data);
|
|
24298
24445
|
}
|
|
24299
24446
|
const nextPage = toPage(paging.next);
|
|
24300
24447
|
const prevPage = toPage(paging.previous);
|
|
@@ -24337,13 +24484,11 @@ queryChannelMembers.locally = (query) => {
|
|
|
24337
24484
|
const addChannelMembers = async (channelId, userIds) => {
|
|
24338
24485
|
const client = getActiveClient();
|
|
24339
24486
|
client.log('channel/addChannelMembers', channelId, userIds);
|
|
24340
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24487
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24488
|
+
const data = prepareChannelPayload(payload);
|
|
24341
24489
|
if (client.cache)
|
|
24342
24490
|
ingestInCache(data);
|
|
24343
|
-
fireEvent('v3.channel.didAddUsers',
|
|
24344
|
-
channels: data.channels,
|
|
24345
|
-
channelUsers: data.channelUsers,
|
|
24346
|
-
});
|
|
24491
|
+
fireEvent('v3.channel.didAddUsers', data);
|
|
24347
24492
|
const { channelUsers } = data;
|
|
24348
24493
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
24349
24494
|
};
|
|
@@ -24366,13 +24511,11 @@ const addChannelMembers = async (channelId, userIds) => {
|
|
|
24366
24511
|
const removeChannelMembers = async (channelId, userIds) => {
|
|
24367
24512
|
const client = getActiveClient();
|
|
24368
24513
|
client.log('channel/removeChannelMembers', channelId, userIds);
|
|
24369
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24514
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24515
|
+
const data = prepareChannelPayload(payload);
|
|
24370
24516
|
if (client.cache)
|
|
24371
24517
|
ingestInCache(data);
|
|
24372
|
-
fireEvent('v3.channel.didRemoveUsers',
|
|
24373
|
-
channels: data.channels,
|
|
24374
|
-
channelUsers: data.channelUsers,
|
|
24375
|
-
});
|
|
24518
|
+
fireEvent('v3.channel.didRemoveUsers', data);
|
|
24376
24519
|
const { channelUsers } = data;
|
|
24377
24520
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
24378
24521
|
};
|
|
@@ -24396,7 +24539,8 @@ const removeChannelMembers = async (channelId, userIds) => {
|
|
|
24396
24539
|
const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24397
24540
|
const client = getActiveClient();
|
|
24398
24541
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
|
|
24399
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24542
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24543
|
+
const data = prepareChannelPayload(payload);
|
|
24400
24544
|
if (client.cache)
|
|
24401
24545
|
ingestInCache(data);
|
|
24402
24546
|
const { channelUsers } = data;
|
|
@@ -24422,7 +24566,8 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24422
24566
|
const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24423
24567
|
const client = getActiveClient();
|
|
24424
24568
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
24425
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24569
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24570
|
+
const data = prepareChannelPayload(payload);
|
|
24426
24571
|
if (client.cache)
|
|
24427
24572
|
ingestInCache(data);
|
|
24428
24573
|
const { channelUsers } = data;
|
|
@@ -24446,13 +24591,14 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24446
24591
|
const banChannelMembers = async (channelId, userIds) => {
|
|
24447
24592
|
const client = getActiveClient();
|
|
24448
24593
|
client.log('channel/banChannelMembers', { userIds, channelId });
|
|
24449
|
-
const payload = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
24594
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
24450
24595
|
userIds,
|
|
24451
24596
|
});
|
|
24597
|
+
const data = prepareChannelPayload(payload);
|
|
24452
24598
|
const cachedAt = client.cache && Date.now();
|
|
24453
24599
|
if (client.cache)
|
|
24454
|
-
ingestInCache(
|
|
24455
|
-
const { channelUsers } =
|
|
24600
|
+
ingestInCache(data, { cachedAt });
|
|
24601
|
+
const { channelUsers } = data;
|
|
24456
24602
|
return {
|
|
24457
24603
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
24458
24604
|
cachedAt,
|
|
@@ -24476,19 +24622,45 @@ const banChannelMembers = async (channelId, userIds) => {
|
|
|
24476
24622
|
const unbanChannelMembers = async (channelId, userIds) => {
|
|
24477
24623
|
const client = getActiveClient();
|
|
24478
24624
|
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
24479
|
-
const payload = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
24625
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
24480
24626
|
userIds,
|
|
24481
24627
|
});
|
|
24628
|
+
const data = prepareChannelPayload(payload);
|
|
24482
24629
|
const cachedAt = client.cache && Date.now();
|
|
24483
24630
|
if (client.cache)
|
|
24484
|
-
ingestInCache(
|
|
24485
|
-
const { channelUsers } =
|
|
24631
|
+
ingestInCache(data, { cachedAt });
|
|
24632
|
+
const { channelUsers } = data;
|
|
24486
24633
|
return {
|
|
24487
24634
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
24488
24635
|
cachedAt,
|
|
24489
24636
|
};
|
|
24490
24637
|
};
|
|
24491
24638
|
|
|
24639
|
+
/**
|
|
24640
|
+
* ```js
|
|
24641
|
+
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
24642
|
+
* const dispose = onChannelCreated(channel => {
|
|
24643
|
+
* // ...
|
|
24644
|
+
* })
|
|
24645
|
+
* ```
|
|
24646
|
+
*
|
|
24647
|
+
* Fired when any {@link Amity.Channel} have been created
|
|
24648
|
+
*
|
|
24649
|
+
* @param callback The function to call when the event was fired
|
|
24650
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24651
|
+
*
|
|
24652
|
+
* @category Channel Events
|
|
24653
|
+
*/
|
|
24654
|
+
const onChannelCreated = (callback) => {
|
|
24655
|
+
const client = getActiveClient();
|
|
24656
|
+
const filter = (payload) => {
|
|
24657
|
+
const data = prepareChannelPayload(payload);
|
|
24658
|
+
ingestInCache(data);
|
|
24659
|
+
callback(data.channels[0]);
|
|
24660
|
+
};
|
|
24661
|
+
return createEventSubscriber(client, 'onChannelCreated', 'v3.channel.didCreate', filter);
|
|
24662
|
+
};
|
|
24663
|
+
|
|
24492
24664
|
/**
|
|
24493
24665
|
* ```js
|
|
24494
24666
|
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
@@ -24507,8 +24679,9 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
24507
24679
|
const onChannelUpdated = (callback) => {
|
|
24508
24680
|
const client = getActiveClient();
|
|
24509
24681
|
const filter = (payload) => {
|
|
24510
|
-
|
|
24511
|
-
|
|
24682
|
+
const data = prepareChannelPayload(payload);
|
|
24683
|
+
ingestInCache(data);
|
|
24684
|
+
callback(data.channels[0]);
|
|
24512
24685
|
};
|
|
24513
24686
|
return createEventSubscriber(client, 'onChannelUpdated', 'v3.channel.didUpdate', filter);
|
|
24514
24687
|
};
|
|
@@ -24531,8 +24704,9 @@ const onChannelUpdated = (callback) => {
|
|
|
24531
24704
|
const onChannelDeleted = (callback) => {
|
|
24532
24705
|
const client = getActiveClient();
|
|
24533
24706
|
const filter = (payload) => {
|
|
24534
|
-
|
|
24535
|
-
|
|
24707
|
+
const data = prepareChannelPayload(payload);
|
|
24708
|
+
ingestInCache(data);
|
|
24709
|
+
callback(data.channels[0]);
|
|
24536
24710
|
};
|
|
24537
24711
|
return createEventSubscriber(client, 'onChannelDeleted', 'v3.channel.didDelete', filter);
|
|
24538
24712
|
};
|
|
@@ -24555,8 +24729,9 @@ const onChannelDeleted = (callback) => {
|
|
|
24555
24729
|
const onChannelJoined = (callback) => {
|
|
24556
24730
|
const client = getActiveClient();
|
|
24557
24731
|
const filter = (payload) => {
|
|
24558
|
-
|
|
24559
|
-
|
|
24732
|
+
const data = prepareChannelPayload(payload);
|
|
24733
|
+
ingestInCache(data);
|
|
24734
|
+
callback(data.channels[0]);
|
|
24560
24735
|
};
|
|
24561
24736
|
return createEventSubscriber(client, 'onChannelJoined', 'v3.channel.didJoin', filter);
|
|
24562
24737
|
};
|
|
@@ -24579,8 +24754,9 @@ const onChannelJoined = (callback) => {
|
|
|
24579
24754
|
const onChannelLeft = (callback) => {
|
|
24580
24755
|
const client = getActiveClient();
|
|
24581
24756
|
const filter = (payload) => {
|
|
24582
|
-
|
|
24583
|
-
|
|
24757
|
+
const data = prepareChannelPayload(payload);
|
|
24758
|
+
ingestInCache(data);
|
|
24759
|
+
callback(data.channels[0]);
|
|
24584
24760
|
};
|
|
24585
24761
|
return createEventSubscriber(client, 'onChannelLeft', 'v3.channel.didLeave', filter);
|
|
24586
24762
|
};
|
|
@@ -24603,8 +24779,9 @@ const onChannelLeft = (callback) => {
|
|
|
24603
24779
|
const onChannelMemberAdded = (callback) => {
|
|
24604
24780
|
const client = getActiveClient();
|
|
24605
24781
|
const filter = (payload) => {
|
|
24606
|
-
|
|
24607
|
-
|
|
24782
|
+
const data = prepareChannelPayload(payload);
|
|
24783
|
+
ingestInCache(data);
|
|
24784
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
24608
24785
|
};
|
|
24609
24786
|
return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
|
|
24610
24787
|
};
|
|
@@ -24627,8 +24804,9 @@ const onChannelMemberAdded = (callback) => {
|
|
|
24627
24804
|
const onChannelMemberRemoved = (callback) => {
|
|
24628
24805
|
const client = getActiveClient();
|
|
24629
24806
|
const filter = (payload) => {
|
|
24630
|
-
|
|
24631
|
-
|
|
24807
|
+
const data = prepareChannelPayload(payload);
|
|
24808
|
+
ingestInCache(data);
|
|
24809
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
24632
24810
|
};
|
|
24633
24811
|
return createEventSubscriber(client, 'onChannelMemberRemoved', 'v3.channel.didRemoveUsers', filter);
|
|
24634
24812
|
};
|
|
@@ -24674,6 +24852,159 @@ const observeChannel = (channelId, callback) => {
|
|
|
24674
24852
|
};
|
|
24675
24853
|
};
|
|
24676
24854
|
|
|
24855
|
+
/**
|
|
24856
|
+
* ```js
|
|
24857
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
24858
|
+
*
|
|
24859
|
+
* let channels = []
|
|
24860
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
24861
|
+
* ```
|
|
24862
|
+
*
|
|
24863
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
24864
|
+
*
|
|
24865
|
+
* @param callback the function to call when new data are available
|
|
24866
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
24867
|
+
*
|
|
24868
|
+
* @category Channel Observer
|
|
24869
|
+
*/
|
|
24870
|
+
const observeChannels = (callback) => {
|
|
24871
|
+
const { log } = getActiveClient();
|
|
24872
|
+
const timestamp = Date.now();
|
|
24873
|
+
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
24874
|
+
const disposers = [];
|
|
24875
|
+
const router = (channel, action) => {
|
|
24876
|
+
var _a, _b;
|
|
24877
|
+
if (callback instanceof Function)
|
|
24878
|
+
return callback(channel);
|
|
24879
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
24880
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
24881
|
+
};
|
|
24882
|
+
disposers.push(onChannelCreated(data => router(data, 'onCreate')), onChannelUpdated(data => router(data, 'onUpdate')), onChannelDeleted(data => router(data, 'onDelete')), onChannelJoined(data => router(data, 'onJoin')), onChannelLeft(data => router(data, 'onLeft')), onChannelMemberAdded(data => router(data, 'onMemberAdded')), onChannelMemberRemoved(data => router(data, 'onMemberRemoved')));
|
|
24883
|
+
return () => {
|
|
24884
|
+
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
24885
|
+
disposers.forEach(fn => fn());
|
|
24886
|
+
};
|
|
24887
|
+
};
|
|
24888
|
+
|
|
24889
|
+
/**
|
|
24890
|
+
* ```js
|
|
24891
|
+
* import { liveChannels } from '@amityco/ts-sdk'
|
|
24892
|
+
*
|
|
24893
|
+
* let channels = []
|
|
24894
|
+
* const unsub = liveChannels({
|
|
24895
|
+
* displayName: Amity.Channel['displayName'],
|
|
24896
|
+
* }, response => merge(channels, response.data))
|
|
24897
|
+
* ```
|
|
24898
|
+
*
|
|
24899
|
+
* Observe all mutations on a list of {@link Amity.Channel}s
|
|
24900
|
+
*
|
|
24901
|
+
* @param params for querying channels
|
|
24902
|
+
* @param callback the function to call when new data are available
|
|
24903
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
24904
|
+
*
|
|
24905
|
+
* @category Channel Live Collection
|
|
24906
|
+
*/
|
|
24907
|
+
const liveChannels = (params, callback, config) => {
|
|
24908
|
+
const { log, cache } = getActiveClient();
|
|
24909
|
+
if (!cache) {
|
|
24910
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24911
|
+
}
|
|
24912
|
+
const timestamp = Date.now();
|
|
24913
|
+
log(`liveChannels(tmpid: ${timestamp}) > listen`);
|
|
24914
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
24915
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
24916
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
24917
|
+
const disposers = [];
|
|
24918
|
+
const cacheKey = ['channel', 'collection', {}];
|
|
24919
|
+
const responder = (data) => {
|
|
24920
|
+
var _a, _b;
|
|
24921
|
+
let channels = (_a = data.data
|
|
24922
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
24923
|
+
.filter(Boolean)
|
|
24924
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
24925
|
+
channels = filterByPropEquality(channels, 'isDeleted', params.isDeleted);
|
|
24926
|
+
channels = filterByPropEquality(channels, 'displayName', params.displayName);
|
|
24927
|
+
if (params.types) {
|
|
24928
|
+
channels = channels.filter(c => { var _a; return (_a = params.types) === null || _a === void 0 ? void 0 : _a.includes(c.type); });
|
|
24929
|
+
}
|
|
24930
|
+
if (params.tags) {
|
|
24931
|
+
channels = channels.filter(c => { var _a; return (_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.tags) === null || _a === void 0 ? void 0 : _a.includes(t); }); });
|
|
24932
|
+
}
|
|
24933
|
+
if (params.excludeTags) {
|
|
24934
|
+
channels = channels.filter(c => { var _a; return !((_a = c.tags) === null || _a === void 0 ? void 0 : _a.some(t => { var _a; return (_a = params.excludeTags) === null || _a === void 0 ? void 0 : _a.includes(t); })); });
|
|
24935
|
+
}
|
|
24936
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
24937
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
24938
|
+
channels = channels.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
24939
|
+
}
|
|
24940
|
+
/*
|
|
24941
|
+
* The server returns channels with empty | null displayName's first before
|
|
24942
|
+
* returning sorted list of channels with displayNames
|
|
24943
|
+
*
|
|
24944
|
+
* This section needs to be updated as displayNames can be null as well
|
|
24945
|
+
*/
|
|
24946
|
+
if (sortBy === 'displayName') {
|
|
24947
|
+
channels = channels
|
|
24948
|
+
// this needs to be aligned with the backend data type
|
|
24949
|
+
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
24950
|
+
// @ts-ignore
|
|
24951
|
+
.sort(sortByDisplayName);
|
|
24952
|
+
}
|
|
24953
|
+
callback({
|
|
24954
|
+
onNextPage: onFetch,
|
|
24955
|
+
data: channels,
|
|
24956
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
24957
|
+
loading: data.loading,
|
|
24958
|
+
error: data.error,
|
|
24959
|
+
});
|
|
24960
|
+
};
|
|
24961
|
+
const realtimeRouter = (channel, action) => {
|
|
24962
|
+
var _a;
|
|
24963
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24964
|
+
if (!collection)
|
|
24965
|
+
return;
|
|
24966
|
+
if (action === 'onCreate') {
|
|
24967
|
+
collection.data = [...new Set([channel.channelId, ...collection.data])];
|
|
24968
|
+
/*
|
|
24969
|
+
* if the filter isDeleted is set, only collection item must be updated and not
|
|
24970
|
+
* the collection
|
|
24971
|
+
*/
|
|
24972
|
+
}
|
|
24973
|
+
else if (action === 'onDelete' && !params.isDeleted) {
|
|
24974
|
+
collection.data = collection.data.filter(c => c !== channel.channelId);
|
|
24975
|
+
}
|
|
24976
|
+
pushToCache(cacheKey, collection);
|
|
24977
|
+
responder(collection);
|
|
24978
|
+
};
|
|
24979
|
+
const onFetch = () => {
|
|
24980
|
+
var _a, _b, _c;
|
|
24981
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24982
|
+
const channels = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24983
|
+
if (channels.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
24984
|
+
return;
|
|
24985
|
+
const query = createQuery(queryChannels, Object.assign(Object.assign({}, queryParams), { page: (_c = collection === null || collection === void 0 ? void 0 : collection.params.page) !== null && _c !== void 0 ? _c : { limit } }));
|
|
24986
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
24987
|
+
const data = {
|
|
24988
|
+
loading,
|
|
24989
|
+
error,
|
|
24990
|
+
params: { page },
|
|
24991
|
+
data: channels,
|
|
24992
|
+
};
|
|
24993
|
+
if (result) {
|
|
24994
|
+
data.data = [...new Set([...channels, ...result.map(getResolver('channel'))])];
|
|
24995
|
+
}
|
|
24996
|
+
pushToCache(cacheKey, data);
|
|
24997
|
+
responder(data);
|
|
24998
|
+
}, queryOptions(policy));
|
|
24999
|
+
};
|
|
25000
|
+
disposers.push(onChannelCreated(channel => realtimeRouter(channel, 'onCreate')), onChannelDeleted(channel => realtimeRouter(channel, 'onDelete')), onChannelUpdated(channel => realtimeRouter(channel, 'onUpdate')));
|
|
25001
|
+
onFetch();
|
|
25002
|
+
return () => {
|
|
25003
|
+
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
25004
|
+
disposers.forEach(fn => fn());
|
|
25005
|
+
};
|
|
25006
|
+
};
|
|
25007
|
+
|
|
24677
25008
|
/**
|
|
24678
25009
|
* ```js
|
|
24679
25010
|
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
@@ -24806,7 +25137,6 @@ const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
|
24806
25137
|
*
|
|
24807
25138
|
* Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.Channel} object
|
|
24808
25139
|
*
|
|
24809
|
-
* @param client the client to observe the message with
|
|
24810
25140
|
* @param channelId the ID of the channel where to observe the messages
|
|
24811
25141
|
* @param callback the function to call when new data are available
|
|
24812
25142
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
@@ -24834,19 +25164,112 @@ const observeMessages = (channelId, callback) => {
|
|
|
24834
25164
|
};
|
|
24835
25165
|
};
|
|
24836
25166
|
|
|
25167
|
+
/**
|
|
25168
|
+
* ```js
|
|
25169
|
+
* import { liveMessages } from '@amityco/ts-sdk'
|
|
25170
|
+
*
|
|
25171
|
+
* let messages = []
|
|
25172
|
+
* const unsub = liveMessages({
|
|
25173
|
+
* channelId: Amity.Channel['channelId'];
|
|
25174
|
+
* }, response => merge(messages, response.data))
|
|
25175
|
+
* ```
|
|
25176
|
+
*
|
|
25177
|
+
* Observe all mutations on a list of {@link Amity.Message} for a given target object
|
|
25178
|
+
*
|
|
25179
|
+
* @param params for querying memssages from a channel
|
|
25180
|
+
* @param callback the function to call when new data are available
|
|
25181
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
25182
|
+
*
|
|
25183
|
+
* @category Messages Live Collection
|
|
25184
|
+
*/
|
|
25185
|
+
const liveMessages = (params, callback, config) => {
|
|
25186
|
+
const { log, cache } = getActiveClient();
|
|
25187
|
+
if (!cache) {
|
|
25188
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25189
|
+
}
|
|
25190
|
+
const timestamp = Date.now();
|
|
25191
|
+
log(`liveMessages(tmpid: ${timestamp}) > listen`);
|
|
25192
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
25193
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
25194
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
25195
|
+
const disposers = [];
|
|
25196
|
+
const cacheKey = ['message', 'collection', { channelId: params.channelId }];
|
|
25197
|
+
const responder = (data) => {
|
|
25198
|
+
var _a, _b;
|
|
25199
|
+
let messages = (_a = data.data
|
|
25200
|
+
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
25201
|
+
.filter(Boolean)
|
|
25202
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
25203
|
+
/*
|
|
25204
|
+
* for cases when message is deleted via RTE, this flag is used to get
|
|
25205
|
+
* items fro cache that are deleted | !deleted
|
|
25206
|
+
*/
|
|
25207
|
+
messages = filterByPropEquality(messages, 'isDeleted', params.isDeleted);
|
|
25208
|
+
callback({
|
|
25209
|
+
onNextPage: onFetch,
|
|
25210
|
+
data: messages,
|
|
25211
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
25212
|
+
loading: data.loading,
|
|
25213
|
+
error: data.error,
|
|
25214
|
+
});
|
|
25215
|
+
};
|
|
25216
|
+
const realtimeRouter = (message, action) => {
|
|
25217
|
+
var _a;
|
|
25218
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25219
|
+
if (params.channelId !== message.channelId || !collection)
|
|
25220
|
+
return;
|
|
25221
|
+
if (action === 'onCreate') {
|
|
25222
|
+
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
25223
|
+
}
|
|
25224
|
+
else if (['onDelete'].includes(action)) {
|
|
25225
|
+
collection.data = collection.data.filter(m => m !== message.messageId);
|
|
25226
|
+
}
|
|
25227
|
+
pushToCache(cacheKey, collection);
|
|
25228
|
+
responder(collection);
|
|
25229
|
+
};
|
|
25230
|
+
const onFetch = () => {
|
|
25231
|
+
var _a, _b, _c, _d, _e;
|
|
25232
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25233
|
+
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25234
|
+
if (messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
25235
|
+
return;
|
|
25236
|
+
const query = createQuery(queryMessages, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
25237
|
+
runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
|
|
25238
|
+
const data = {
|
|
25239
|
+
loading,
|
|
25240
|
+
error,
|
|
25241
|
+
params: { page },
|
|
25242
|
+
data: messages,
|
|
25243
|
+
};
|
|
25244
|
+
if (result) {
|
|
25245
|
+
data.data = [...new Set([...messages, ...result.map(getResolver('message'))])];
|
|
25246
|
+
}
|
|
25247
|
+
pushToCache(cacheKey, data);
|
|
25248
|
+
responder(data);
|
|
25249
|
+
}, queryOptions(policy));
|
|
25250
|
+
};
|
|
25251
|
+
disposers.push(onMessageCreated(message => realtimeRouter(message, 'onCreate')), onMessageDeleted(message => realtimeRouter(message, 'onDelete')), onMessageUpdated(message => realtimeRouter(message, 'onUpdate')));
|
|
25252
|
+
onFetch();
|
|
25253
|
+
return () => {
|
|
25254
|
+
log(`liveMessages(tmpid: ${timestamp}) > dispose`);
|
|
25255
|
+
disposers.forEach(fn => fn());
|
|
25256
|
+
};
|
|
25257
|
+
};
|
|
25258
|
+
|
|
24837
25259
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
24838
25260
|
const client = getActiveClient();
|
|
24839
25261
|
const filter = (payload) => {
|
|
25262
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
24840
25263
|
if (!client.cache) {
|
|
24841
25264
|
// TODO: here we are missing specific properties here!
|
|
24842
|
-
callback(
|
|
25265
|
+
callback(unpackedPayload.communities[0]);
|
|
24843
25266
|
}
|
|
24844
25267
|
else {
|
|
24845
|
-
ingestInCache(
|
|
25268
|
+
ingestInCache(unpackedPayload);
|
|
24846
25269
|
const community = pullFromCache([
|
|
24847
25270
|
'community',
|
|
24848
25271
|
'get',
|
|
24849
|
-
|
|
25272
|
+
unpackedPayload.communities[0].communityId,
|
|
24850
25273
|
]);
|
|
24851
25274
|
callback(community.data);
|
|
24852
25275
|
}
|
|
@@ -24882,21 +25305,22 @@ function getEventRelatedMember(event, payload) {
|
|
|
24882
25305
|
const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
24883
25306
|
const client = getActiveClient();
|
|
24884
25307
|
const filter = (payload) => {
|
|
25308
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
24885
25309
|
if (!client.cache) {
|
|
24886
25310
|
// TODO: here we are missing specific properties here!
|
|
24887
|
-
callback(
|
|
25311
|
+
callback(unpackedPayload.communities[0], getEventRelatedMember(event, unpackedPayload));
|
|
24888
25312
|
}
|
|
24889
25313
|
else {
|
|
24890
|
-
ingestInCache(
|
|
25314
|
+
ingestInCache(unpackedPayload);
|
|
24891
25315
|
const community = pullFromCache([
|
|
24892
25316
|
'community',
|
|
24893
25317
|
'get',
|
|
24894
|
-
|
|
25318
|
+
unpackedPayload.communities[0].communityId,
|
|
24895
25319
|
]);
|
|
24896
25320
|
const member = pullFromCache([
|
|
24897
25321
|
'communityUsers',
|
|
24898
25322
|
'get',
|
|
24899
|
-
getResolver('communityUsers')(getEventRelatedMember(event,
|
|
25323
|
+
getResolver('communityUsers')(getEventRelatedMember(event, unpackedPayload)),
|
|
24900
25324
|
]);
|
|
24901
25325
|
callback(community.data, member.data);
|
|
24902
25326
|
}
|
|
@@ -25321,9 +25745,9 @@ const queryFollows = async (key, query) => {
|
|
|
25321
25745
|
if (client.cache) {
|
|
25322
25746
|
ingestInCache(payload, { cachedAt });
|
|
25323
25747
|
const cacheKey = [
|
|
25324
|
-
|
|
25748
|
+
'follow',
|
|
25325
25749
|
'query',
|
|
25326
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
25750
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
25327
25751
|
];
|
|
25328
25752
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
25329
25753
|
}
|
|
@@ -25338,7 +25762,11 @@ queryFollows.locally = (key, query) => {
|
|
|
25338
25762
|
if (!client.cache)
|
|
25339
25763
|
return;
|
|
25340
25764
|
const { page } = query, params = __rest(query, ["page"]);
|
|
25341
|
-
const queryKey = [
|
|
25765
|
+
const queryKey = [
|
|
25766
|
+
'follow',
|
|
25767
|
+
'query',
|
|
25768
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page), type: key }),
|
|
25769
|
+
];
|
|
25342
25770
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
25343
25771
|
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
25344
25772
|
return;
|
|
@@ -25884,6 +26312,186 @@ const observeFollowings = (userId, callback) => {
|
|
|
25884
26312
|
};
|
|
25885
26313
|
};
|
|
25886
26314
|
|
|
26315
|
+
/**
|
|
26316
|
+
* ```js
|
|
26317
|
+
* import { liveFollowers } from '@amityco/ts-sdk'
|
|
26318
|
+
*
|
|
26319
|
+
* let followers = []
|
|
26320
|
+
* const unsub = liveFollowers({
|
|
26321
|
+
* userId: Amity.User['userId'];
|
|
26322
|
+
* }, response => merge(followers, response.data))
|
|
26323
|
+
* ```
|
|
26324
|
+
*
|
|
26325
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
|
|
26326
|
+
*
|
|
26327
|
+
* @param userId the user
|
|
26328
|
+
* @param callback the function to call when new data are available
|
|
26329
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
26330
|
+
*
|
|
26331
|
+
* @category Followers Live Collection
|
|
26332
|
+
*/
|
|
26333
|
+
const liveFollowers = (params, callback, config) => {
|
|
26334
|
+
const { log, cache } = getActiveClient();
|
|
26335
|
+
if (!cache) {
|
|
26336
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
26337
|
+
}
|
|
26338
|
+
const timestamp = Date.now();
|
|
26339
|
+
log(`liveFollowers(tmpid: ${timestamp}) > listen`);
|
|
26340
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
26341
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
26342
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
26343
|
+
const disposers = [];
|
|
26344
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
26345
|
+
const responder = (data) => {
|
|
26346
|
+
var _a, _b;
|
|
26347
|
+
let followers = (_a = data.data
|
|
26348
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26349
|
+
.filter(Boolean)
|
|
26350
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26351
|
+
if (params.status && params.status !== 'all') {
|
|
26352
|
+
followers = filterByPropEquality(followers, 'status', params.status);
|
|
26353
|
+
}
|
|
26354
|
+
callback({
|
|
26355
|
+
onNextPage: onFetch,
|
|
26356
|
+
data: followers,
|
|
26357
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26358
|
+
loading: data.loading,
|
|
26359
|
+
error: data.error,
|
|
26360
|
+
});
|
|
26361
|
+
};
|
|
26362
|
+
const realtimeRouter = (followStatus, action) => {
|
|
26363
|
+
var _a;
|
|
26364
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26365
|
+
if (params.userId !== followStatus.to || !collection)
|
|
26366
|
+
return;
|
|
26367
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26368
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26369
|
+
}
|
|
26370
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26371
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26372
|
+
}
|
|
26373
|
+
pushToCache(cacheKey, collection);
|
|
26374
|
+
responder(collection);
|
|
26375
|
+
};
|
|
26376
|
+
const onFetch = () => {
|
|
26377
|
+
var _a, _b, _c, _d, _e;
|
|
26378
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26379
|
+
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26380
|
+
if (followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26381
|
+
return;
|
|
26382
|
+
const query = createQuery(queryFollowers, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
26383
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26384
|
+
const data = {
|
|
26385
|
+
loading,
|
|
26386
|
+
error,
|
|
26387
|
+
params: { page },
|
|
26388
|
+
data: followers,
|
|
26389
|
+
};
|
|
26390
|
+
if (result) {
|
|
26391
|
+
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
26392
|
+
}
|
|
26393
|
+
pushToCache(cacheKey, data);
|
|
26394
|
+
responder(data);
|
|
26395
|
+
}, queryOptions(policy));
|
|
26396
|
+
};
|
|
26397
|
+
disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
|
|
26398
|
+
onFetch();
|
|
26399
|
+
return () => {
|
|
26400
|
+
log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26401
|
+
disposers.forEach(fn => fn());
|
|
26402
|
+
};
|
|
26403
|
+
};
|
|
26404
|
+
|
|
26405
|
+
/**
|
|
26406
|
+
* ```js
|
|
26407
|
+
* import { liveFollowings } from '@amityco/ts-sdk'
|
|
26408
|
+
*
|
|
26409
|
+
* let followings = []
|
|
26410
|
+
* const unsub = liveFollowings({
|
|
26411
|
+
* userId: Amity.User['userId'];
|
|
26412
|
+
* }, response => merge(followings, response.data))
|
|
26413
|
+
* ```
|
|
26414
|
+
*
|
|
26415
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
|
|
26416
|
+
*
|
|
26417
|
+
* @param userId the user
|
|
26418
|
+
* @param callback the function to call when new data are available
|
|
26419
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
26420
|
+
*
|
|
26421
|
+
* @category Followings Live Collection
|
|
26422
|
+
*/
|
|
26423
|
+
const liveFollowings = (params, callback, config) => {
|
|
26424
|
+
const { log, cache } = getActiveClient();
|
|
26425
|
+
if (!cache) {
|
|
26426
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
26427
|
+
}
|
|
26428
|
+
const timestamp = Date.now();
|
|
26429
|
+
log(`liveFollowings(tmpid: ${timestamp}) > listen`);
|
|
26430
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
26431
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
26432
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
26433
|
+
const disposers = [];
|
|
26434
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
26435
|
+
const responder = (data) => {
|
|
26436
|
+
var _a, _b;
|
|
26437
|
+
let followings = (_a = data.data
|
|
26438
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26439
|
+
.filter(Boolean)
|
|
26440
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26441
|
+
if (params.status && params.status !== 'all') {
|
|
26442
|
+
followings = filterByPropEquality(followings, 'status', params.status);
|
|
26443
|
+
}
|
|
26444
|
+
callback({
|
|
26445
|
+
onNextPage: onFetch,
|
|
26446
|
+
data: followings,
|
|
26447
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26448
|
+
loading: data.loading,
|
|
26449
|
+
error: data.error,
|
|
26450
|
+
});
|
|
26451
|
+
};
|
|
26452
|
+
const realtimeRouter = (followStatus, action) => {
|
|
26453
|
+
var _a;
|
|
26454
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26455
|
+
if (params.userId !== followStatus.from || !collection)
|
|
26456
|
+
return;
|
|
26457
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26458
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26459
|
+
}
|
|
26460
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26461
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26462
|
+
}
|
|
26463
|
+
pushToCache(cacheKey, collection);
|
|
26464
|
+
responder(collection);
|
|
26465
|
+
};
|
|
26466
|
+
const onFetch = () => {
|
|
26467
|
+
var _a, _b, _c, _d, _e;
|
|
26468
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26469
|
+
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26470
|
+
if (followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26471
|
+
return;
|
|
26472
|
+
const query = createQuery(queryFollowings, Object.assign(Object.assign({}, queryParams), { page: (_e = (_d = collection === null || collection === void 0 ? void 0 : collection.params) === null || _d === void 0 ? void 0 : _d.page) !== null && _e !== void 0 ? _e : { limit } }));
|
|
26473
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26474
|
+
const data = {
|
|
26475
|
+
loading,
|
|
26476
|
+
error,
|
|
26477
|
+
params: { page },
|
|
26478
|
+
data: followings,
|
|
26479
|
+
};
|
|
26480
|
+
if (result) {
|
|
26481
|
+
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
26482
|
+
}
|
|
26483
|
+
pushToCache(cacheKey, data);
|
|
26484
|
+
responder(data);
|
|
26485
|
+
}, queryOptions(policy));
|
|
26486
|
+
};
|
|
26487
|
+
disposers.push(onFollowerRequested(followStatus => realtimeRouter(followStatus, 'onRequested')), onFollowRequestAccepted(followStatus => realtimeRouter(followStatus, 'onAccepted')), onFollowRequestDeclined(followStatus => realtimeRouter(followStatus, 'onDeclined')), onFollowRequestCanceled(followStatus => realtimeRouter(followStatus, 'onCanceled')), onUserFollowed(followStatus => realtimeRouter(followStatus, 'onFollowed')), onUserUnfollowed(followStatus => realtimeRouter(followStatus, 'onUnfollowed')), onFollowerDeleted(followStatus => realtimeRouter(followStatus, 'onDeleted')));
|
|
26488
|
+
onFetch();
|
|
26489
|
+
return () => {
|
|
26490
|
+
log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
|
|
26491
|
+
disposers.forEach(fn => fn());
|
|
26492
|
+
};
|
|
26493
|
+
};
|
|
26494
|
+
|
|
25887
26495
|
/**
|
|
25888
26496
|
* ```js
|
|
25889
26497
|
* import { observePosts } from '@amityco/ts-sdk'
|
|
@@ -25992,7 +26600,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
25992
26600
|
const livePosts = (params, callback, config) => {
|
|
25993
26601
|
const { log, cache } = getActiveClient();
|
|
25994
26602
|
if (!cache) {
|
|
25995
|
-
console.log(
|
|
26603
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25996
26604
|
}
|
|
25997
26605
|
const timestamp = Date.now();
|
|
25998
26606
|
log(`livePosts(tmpid: ${timestamp}) > listen`);
|
|
@@ -26830,4 +27438,4 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
26830
27438
|
return { accessToken: data.accessToken };
|
|
26831
27439
|
};
|
|
26832
27440
|
|
|
26833
|
-
export { API_REGIONS, SubscriptionLevels, VERSION$1 as VERSION, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, banChannelMembers, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveComments, livePosts, liveReactions, mergeInCache, observeChannel, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionAdded, onReactionRemoved, onReactorAdded, onReactorRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unbanChannelMembers, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
|
|
27441
|
+
export { API_REGIONS, CommunityPostSettingMaps, CommunityPostSettings, ContentFeedType, DefaultCommunityPostSetting, FileType, SubscriptionLevels, VERSION$1 as VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, acceptFollower, addChannelMembers, addChannelMembersRole, addCommunityMembers, addCommunityMembersRoles, addReaction, approvePost, backupCache, banChannelMembers, closePoll, connectClient, createChannel, createClient, createComment, createCommunity, createFile, createImage, createMessage, createPoll, createPost, createQuery, createReport, createStream, createUserToken, createVideo, declineFollower, declinePost, deleteChannel, deleteComment, deleteCommunity, deleteFile, deleteMessage, deletePoll, deletePost, deleteReport, deleteStream, disableCache, disconnectClient, disposeStream, dropFromCache, enableCache, fileUrlWithSize, filterByPropEquality, follow, getActiveClient, getCategory, getChannel, getChannels, getComment, getCommentTopic, getComments, getCommunities, getCommunity, getCommunityTopic, getFeedSettings, getFile, getFollowInfo, getMessage, getMessages, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPoll, getPost, getPostTopic, getPosts, getRecommendedCommunities, getRole, getStream, getTopTrendingCommunities, getUser, getUserTopic, getUsers, isAfterBefore, isAfterBeforeRaw, isCachable, isConnected, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkipLimit, joinChannel, joinCommunity, leaveChannel, leaveCommunity, liveChannels, liveComments, liveFollowers, liveFollowings, liveMessages, livePosts, liveReactions, mergeInCache, observeChannel, observeChannels, observeComment, observeComments, observeCommunity, observeFile, observeFollowInfo, observeFollowers, observeFollowings, observeMessage, observeMessages, observePoll, observePost, observePosts, observeUser, onChannelCreated, onChannelDeleted, onChannelJoined, onChannelLeft, onChannelMemberAdded, onChannelMemberRemoved, onChannelUpdated, onClientBanned, onClientDisconnected, onCommentCreated, onCommentDeleted, onCommentFlagged, onCommentReactionAdded, onCommentReactionRemoved, onCommentUnflagged, onCommentUpdated, onCommunityCreated, onCommunityDeleted, onCommunityJoined, onCommunityLeft, onCommunityUpdated, onCommunityUserAdded, onCommunityUserBanned, onCommunityUserRemoved, onCommunityUserUnbanned, onConnectionError, onFollowInfoUpdated, onFollowRequestAccepted, onFollowRequestCanceled, onFollowRequestDeclined, onFollowerDeleted, onFollowerRequested, onMessageCreated, onMessageDeleted, onMessageUpdated, onPollDeleted, onPollUpdated, onPostApproved, onPostCreated, onPostDeclined, onPostDeleted, onPostFlagged, onPostReactionAdded, onPostReactionRemoved, onPostUnflagged, onPostUpdated, onReactionAdded, onReactionRemoved, onReactorAdded, onReactorRemoved, onStreamRecorded, onStreamStarted, onStreamStopped, onUserDeleted, onUserFlagCleared, onUserFlagged, onUserFollowed, onUserUnflagged, onUserUnfollowed, onUserUpdated, pullFromCache, pushToCache, queryCache, queryCategories, queryChannelMembers, queryChannels, queryComments, queryCommunities, queryCommunityMembers, queryFollowers, queryFollowings, queryGlobalFeed, queryMessages, queryOptions, queryPosts, queryReactions, queryRoles, queryStreams, queryUsers, removeChannelMembers, removeChannelMembersRole, removeCommunityMembers, removeCommunityMembersRoles, removeReaction, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByLastActivity, sortByLastCreated, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, unbanChannelMembers, unfollow, updateChannel, updateComment, updateCommunity, updateMessage, updatePost, updateStream, updateUser, upsertInCache, votePoll, wipeCache };
|