@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.cjs.js
CHANGED
|
@@ -21,6 +21,60 @@ var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
|
|
|
21
21
|
var io__default = /*#__PURE__*/_interopDefaultLegacy(io);
|
|
22
22
|
var nativeIdGenerator__default = /*#__PURE__*/_interopDefaultLegacy(nativeIdGenerator);
|
|
23
23
|
|
|
24
|
+
const CommunityPostSettings = Object.freeze({
|
|
25
|
+
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
26
|
+
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
27
|
+
ANYONE_CAN_POST: 'ANYONE_CAN_POST',
|
|
28
|
+
});
|
|
29
|
+
const CommunityPostSettingMaps = Object.freeze({
|
|
30
|
+
ONLY_ADMIN_CAN_POST: {
|
|
31
|
+
needApprovalOnPostCreation: false,
|
|
32
|
+
onlyAdminCanPost: true,
|
|
33
|
+
},
|
|
34
|
+
ADMIN_REVIEW_POST_REQUIRED: {
|
|
35
|
+
needApprovalOnPostCreation: true,
|
|
36
|
+
onlyAdminCanPost: false,
|
|
37
|
+
},
|
|
38
|
+
ANYONE_CAN_POST: {
|
|
39
|
+
needApprovalOnPostCreation: false,
|
|
40
|
+
onlyAdminCanPost: false,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
const DefaultCommunityPostSetting = 'ONLY_ADMIN_CAN_POST';
|
|
44
|
+
|
|
45
|
+
const ContentFeedType = Object.freeze({
|
|
46
|
+
STORY: 'story',
|
|
47
|
+
CLIP: 'clip',
|
|
48
|
+
CHAT: 'chat',
|
|
49
|
+
POST: 'post',
|
|
50
|
+
MESSAGE: 'message',
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
const FileType = Object.freeze({
|
|
54
|
+
FILE: 'file',
|
|
55
|
+
IMAGE: 'image',
|
|
56
|
+
VIDEO: 'video',
|
|
57
|
+
});
|
|
58
|
+
const VideoResolution = Object.freeze({
|
|
59
|
+
'1080P': '1080p',
|
|
60
|
+
'720P': '720p',
|
|
61
|
+
'480P': '480p',
|
|
62
|
+
'360P': '360p',
|
|
63
|
+
ORIGINAL: 'original',
|
|
64
|
+
});
|
|
65
|
+
const VideoTranscodingStatus = Object.freeze({
|
|
66
|
+
UPLOADED: 'uploaded',
|
|
67
|
+
TRANSCODING: 'transcoding',
|
|
68
|
+
TRANSCODED: 'transcoded',
|
|
69
|
+
TRANSCODE_FAILED: 'transcodeFailed',
|
|
70
|
+
});
|
|
71
|
+
const VideoSize = Object.freeze({
|
|
72
|
+
LOW: 'low',
|
|
73
|
+
MEDIUM: 'medium',
|
|
74
|
+
HIGH: 'high',
|
|
75
|
+
ORIGINAL: 'original',
|
|
76
|
+
});
|
|
77
|
+
|
|
24
78
|
var _a$1;
|
|
25
79
|
/* eslint-disable no-undef */
|
|
26
80
|
const theGlobal =
|
|
@@ -225,7 +279,7 @@ const CRITERIAS = {
|
|
|
225
279
|
channel: ['channelId', 'rateLimit'],
|
|
226
280
|
channelUsers: ['channelId', 'userId', 'membership'],
|
|
227
281
|
message: ['messageId'],
|
|
228
|
-
community: ['communityId', '
|
|
282
|
+
community: ['communityId', 'postSetting'],
|
|
229
283
|
category: ['categoryId'],
|
|
230
284
|
communityUsers: ['userId', 'communityId', 'communityMembership'],
|
|
231
285
|
post: ['postId', 'feedId'],
|
|
@@ -368,7 +422,7 @@ const isFresh = (model, lifeSpan = 0) => {
|
|
|
368
422
|
* This wrapper is necessary to create for optimistically calls
|
|
369
423
|
*
|
|
370
424
|
*
|
|
371
|
-
* @param
|
|
425
|
+
* @param func A compatible API function from the ts sdk
|
|
372
426
|
* @param args The arguments to pass to the function passed as `fn`
|
|
373
427
|
* @returns A wrapper containing both the function and its future arguments
|
|
374
428
|
*
|
|
@@ -654,8 +708,9 @@ const WS_EVENTS = [
|
|
|
654
708
|
'connect_error',
|
|
655
709
|
'reconnect_error',
|
|
656
710
|
'reconnect_failed',
|
|
711
|
+
'v3.channel.didCreate',
|
|
657
712
|
'v3.channel.didUpdate',
|
|
658
|
-
'v3.channel.
|
|
713
|
+
'v3.channel.didDelete',
|
|
659
714
|
'v3.channel.didJoin',
|
|
660
715
|
'v3.channel.didLeave',
|
|
661
716
|
'v3.channel.didAddUsers',
|
|
@@ -20155,6 +20210,29 @@ const createMqttTransport = (endpoint) => {
|
|
|
20155
20210
|
};
|
|
20156
20211
|
};
|
|
20157
20212
|
|
|
20213
|
+
/**
|
|
20214
|
+
* ```js
|
|
20215
|
+
* import { getFeedSettings } from '@amityco/ts-sdk'
|
|
20216
|
+
* const feedSettings = await getFeedSettings()
|
|
20217
|
+
* const postFeedSetting = feedSettings.post
|
|
20218
|
+
* ```
|
|
20219
|
+
*
|
|
20220
|
+
* Fetches a {@link Amity.FeedSettings} object
|
|
20221
|
+
*
|
|
20222
|
+
* @returns A Promise of {@link Amity.FeedSettings} object
|
|
20223
|
+
*
|
|
20224
|
+
* @category Client API
|
|
20225
|
+
* @async
|
|
20226
|
+
*/
|
|
20227
|
+
const getFeedSettings = async () => {
|
|
20228
|
+
const client = getActiveClient();
|
|
20229
|
+
const { data } = await client.http.get(`/api/v3/network-settings/feed-setting`);
|
|
20230
|
+
return Object.fromEntries(data.feedSettings.map(({ feedType, contentSettings }) => {
|
|
20231
|
+
return [feedType, contentSettings];
|
|
20232
|
+
}));
|
|
20233
|
+
};
|
|
20234
|
+
|
|
20235
|
+
const DEFAULT_DEBUG_SESSION = 'amity';
|
|
20158
20236
|
/**
|
|
20159
20237
|
* ```js
|
|
20160
20238
|
* import { createClient } from '@amityco/ts-sdk'
|
|
@@ -20165,20 +20243,24 @@ const createMqttTransport = (endpoint) => {
|
|
|
20165
20243
|
*
|
|
20166
20244
|
* @param apiKey for the {@link Amity.Client} instance
|
|
20167
20245
|
* @param apiRegion endpoint to connect to
|
|
20246
|
+
* @param apiEndpoint custom endpoint in case you don't want to use a preset endpoint
|
|
20168
20247
|
* @param debugSession session's identifier for the client's logger instance
|
|
20169
20248
|
* @returns A {@link Amity.Client} instance
|
|
20170
20249
|
*
|
|
20171
20250
|
* @category Client API
|
|
20172
20251
|
* */
|
|
20173
|
-
const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession =
|
|
20252
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, } = {}) => {
|
|
20253
|
+
var _a, _b;
|
|
20174
20254
|
const log = createLogger(debugSession);
|
|
20175
20255
|
log('client/api/createClient', {
|
|
20176
20256
|
apiKey: apiKey.replace(/.{5}$/g, 'xxxxx'),
|
|
20177
20257
|
apiRegion,
|
|
20178
20258
|
});
|
|
20179
|
-
const
|
|
20180
|
-
const
|
|
20181
|
-
const
|
|
20259
|
+
const httpEndpoint = (_a = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.http) !== null && _a !== void 0 ? _a : computeUrl('http', apiRegion);
|
|
20260
|
+
const mqttEndpoint = (_b = apiEndpoint === null || apiEndpoint === void 0 ? void 0 : apiEndpoint.mqtt) !== null && _b !== void 0 ? _b : computeUrl('mqtt', apiRegion);
|
|
20261
|
+
const http = createHttpTransport(httpEndpoint);
|
|
20262
|
+
const ws = createWebsocketTransport(httpEndpoint);
|
|
20263
|
+
const mqtt = createMqttTransport(mqttEndpoint);
|
|
20182
20264
|
const emitter = createEventEmitter();
|
|
20183
20265
|
const client = {
|
|
20184
20266
|
version: `${VERSION$1}`,
|
|
@@ -20189,11 +20271,12 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, debugSession = 'amity'
|
|
|
20189
20271
|
mqtt,
|
|
20190
20272
|
emitter,
|
|
20191
20273
|
use: () => setActiveClient(client),
|
|
20274
|
+
getFeedSettings,
|
|
20192
20275
|
};
|
|
20193
20276
|
try {
|
|
20194
20277
|
getActiveClient();
|
|
20195
20278
|
}
|
|
20196
|
-
catch (
|
|
20279
|
+
catch (_c) {
|
|
20197
20280
|
setActiveClient(client);
|
|
20198
20281
|
}
|
|
20199
20282
|
return client;
|
|
@@ -20262,6 +20345,58 @@ const getDeviceInfo = () => {
|
|
|
20262
20345
|
};
|
|
20263
20346
|
};
|
|
20264
20347
|
|
|
20348
|
+
/**
|
|
20349
|
+
* Ingest a payload (v3) into the cache
|
|
20350
|
+
*
|
|
20351
|
+
* @param payload a "backend v3" payload object
|
|
20352
|
+
* @param order the order of the keys to process (in case of need)
|
|
20353
|
+
*
|
|
20354
|
+
* @category Cache
|
|
20355
|
+
* @hidden
|
|
20356
|
+
*/
|
|
20357
|
+
const ingestInCache = (payload = {}, options) => {
|
|
20358
|
+
Object.entries(payload).forEach(([key, models]) => {
|
|
20359
|
+
const type = PAYLOAD2MODEL[key];
|
|
20360
|
+
if (!type)
|
|
20361
|
+
return;
|
|
20362
|
+
const resolver = getResolver(type);
|
|
20363
|
+
models.forEach(model => {
|
|
20364
|
+
upsertInCache(
|
|
20365
|
+
// eslint-disable @typescript-eslint no-explicit-any
|
|
20366
|
+
[type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20367
|
+
model, options);
|
|
20368
|
+
});
|
|
20369
|
+
});
|
|
20370
|
+
};
|
|
20371
|
+
|
|
20372
|
+
const createUserEventSubscriber = (event, callback) => {
|
|
20373
|
+
const client = getActiveClient();
|
|
20374
|
+
const filter = (payload) => {
|
|
20375
|
+
if (client.cache) {
|
|
20376
|
+
ingestInCache(payload);
|
|
20377
|
+
}
|
|
20378
|
+
callback(payload.users[0]);
|
|
20379
|
+
};
|
|
20380
|
+
return createEventSubscriber(client, event, event, filter);
|
|
20381
|
+
};
|
|
20382
|
+
|
|
20383
|
+
/**
|
|
20384
|
+
* ```js
|
|
20385
|
+
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20386
|
+
* const dispose = onUserDeleted(user => {
|
|
20387
|
+
* // ...
|
|
20388
|
+
* })
|
|
20389
|
+
* ```
|
|
20390
|
+
*
|
|
20391
|
+
* Fired when a {@link Amity.User} has been deleted
|
|
20392
|
+
*
|
|
20393
|
+
* @param callback The function to call when the event was fired
|
|
20394
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20395
|
+
*
|
|
20396
|
+
* @category User Events
|
|
20397
|
+
*/
|
|
20398
|
+
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20399
|
+
|
|
20265
20400
|
/**
|
|
20266
20401
|
* Retrieves a pair of {@link Amity.Tokens} necessary for connection
|
|
20267
20402
|
*
|
|
@@ -20362,58 +20497,6 @@ const onClientBanned = (callback) => {
|
|
|
20362
20497
|
});
|
|
20363
20498
|
};
|
|
20364
20499
|
|
|
20365
|
-
/**
|
|
20366
|
-
* Ingest a payload (v3) into the cache
|
|
20367
|
-
*
|
|
20368
|
-
* @param payload a "backend v3" payload object
|
|
20369
|
-
* @param order the order of the keys to process (in case of need)
|
|
20370
|
-
*
|
|
20371
|
-
* @category Cache
|
|
20372
|
-
* @hidden
|
|
20373
|
-
*/
|
|
20374
|
-
const ingestInCache = (payload = {}, options) => {
|
|
20375
|
-
Object.entries(payload).forEach(([key, models]) => {
|
|
20376
|
-
const type = PAYLOAD2MODEL[key];
|
|
20377
|
-
if (!type)
|
|
20378
|
-
return;
|
|
20379
|
-
const resolver = getResolver(type);
|
|
20380
|
-
models.forEach(model => {
|
|
20381
|
-
upsertInCache(
|
|
20382
|
-
// eslint-disable @typescript-eslint no-explicit-any
|
|
20383
|
-
[type, 'get', resolver(model)], // this 'any' cannot be avoided, sorry.
|
|
20384
|
-
model, options);
|
|
20385
|
-
});
|
|
20386
|
-
});
|
|
20387
|
-
};
|
|
20388
|
-
|
|
20389
|
-
const createUserEventSubscriber = (event, callback) => {
|
|
20390
|
-
const client = getActiveClient();
|
|
20391
|
-
const filter = (payload) => {
|
|
20392
|
-
if (client.cache) {
|
|
20393
|
-
ingestInCache(payload);
|
|
20394
|
-
}
|
|
20395
|
-
callback(payload.users[0]);
|
|
20396
|
-
};
|
|
20397
|
-
return createEventSubscriber(client, event, event, filter);
|
|
20398
|
-
};
|
|
20399
|
-
|
|
20400
|
-
/**
|
|
20401
|
-
* ```js
|
|
20402
|
-
* import { onUserDeleted } from '@amityco/ts-sdk'
|
|
20403
|
-
* const dispose = onUserDeleted(user => {
|
|
20404
|
-
* // ...
|
|
20405
|
-
* })
|
|
20406
|
-
* ```
|
|
20407
|
-
*
|
|
20408
|
-
* Fired when a {@link Amity.User} has been deleted
|
|
20409
|
-
*
|
|
20410
|
-
* @param callback The function to call when the event was fired
|
|
20411
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20412
|
-
*
|
|
20413
|
-
* @category User Events
|
|
20414
|
-
*/
|
|
20415
|
-
const onUserDeleted = (callback) => createUserEventSubscriber('user.deleted', callback);
|
|
20416
|
-
|
|
20417
20500
|
/* eslint-disable no-param-reassign */
|
|
20418
20501
|
/**
|
|
20419
20502
|
* ```js
|
|
@@ -20981,17 +21064,21 @@ const fileUrlWithSize = (fileUrl, size) => {
|
|
|
20981
21064
|
* Creates an {@link Amity.File<'video'>}
|
|
20982
21065
|
*
|
|
20983
21066
|
* @param formData The data necessary to create a new {@link Amity.File<'video'>}
|
|
21067
|
+
* @param feedType The {@link Amity.File<'video'>} feed type
|
|
20984
21068
|
* @param onProgress The callback to track the upload progress
|
|
20985
21069
|
* @returns The newly created {@link Amity.File<'video'>}
|
|
20986
21070
|
*
|
|
20987
21071
|
* @category File API
|
|
20988
21072
|
* @async
|
|
20989
21073
|
*/
|
|
20990
|
-
const createVideo = async (formData, onProgress) => {
|
|
21074
|
+
const createVideo = async (formData, feedType, onProgress) => {
|
|
20991
21075
|
const client = getActiveClient();
|
|
20992
21076
|
client.log('file/createVideo', formData);
|
|
20993
21077
|
if (!formData.getAll('files').length)
|
|
20994
21078
|
throw new Error('The formData object must have a `files` key.');
|
|
21079
|
+
if (feedType) {
|
|
21080
|
+
formData.append('feedType', feedType);
|
|
21081
|
+
}
|
|
20995
21082
|
const headers = 'getHeaders' in formData
|
|
20996
21083
|
? formData.getHeaders()
|
|
20997
21084
|
: { 'content-type': 'multipart/form-data' };
|
|
@@ -21874,6 +21961,33 @@ const updatePost = async (postId, patch) => {
|
|
|
21874
21961
|
};
|
|
21875
21962
|
};
|
|
21876
21963
|
|
|
21964
|
+
const getMatchPostSetting = (value) => {
|
|
21965
|
+
var _a;
|
|
21966
|
+
return (_a = Object.keys(CommunityPostSettingMaps).find(key => value.needApprovalOnPostCreation ===
|
|
21967
|
+
CommunityPostSettingMaps[key].needApprovalOnPostCreation &&
|
|
21968
|
+
value.onlyAdminCanPost === CommunityPostSettingMaps[key].onlyAdminCanPost)) !== null && _a !== void 0 ? _a : DefaultCommunityPostSetting;
|
|
21969
|
+
};
|
|
21970
|
+
/*
|
|
21971
|
+
* Unpack community payload by mapping payload field to postSetting value.
|
|
21972
|
+
*/
|
|
21973
|
+
const unpackCommunityPayload = (_a) => {
|
|
21974
|
+
var { communities } = _a, restPayload = __rest(_a, ["communities"]);
|
|
21975
|
+
return (Object.assign({ communities: communities.map((_a) => {
|
|
21976
|
+
var { needApprovalOnPostCreation, onlyAdminCanPost } = _a, restCommunityPayload = __rest(_a, ["needApprovalOnPostCreation", "onlyAdminCanPost"]);
|
|
21977
|
+
return (Object.assign({ postSetting: getMatchPostSetting({
|
|
21978
|
+
needApprovalOnPostCreation,
|
|
21979
|
+
onlyAdminCanPost,
|
|
21980
|
+
}) }, restCommunityPayload));
|
|
21981
|
+
}) }, restPayload));
|
|
21982
|
+
};
|
|
21983
|
+
/*
|
|
21984
|
+
* Repack community payload by mapping postSetting to the actual value.
|
|
21985
|
+
*/
|
|
21986
|
+
const packCommunityPayload = (_a) => {
|
|
21987
|
+
var { postSetting = undefined } = _a, restParam = __rest(_a, ["postSetting"]);
|
|
21988
|
+
return (Object.assign(Object.assign({}, restParam), (postSetting ? CommunityPostSettingMaps[postSetting] : undefined)));
|
|
21989
|
+
};
|
|
21990
|
+
|
|
21877
21991
|
/**
|
|
21878
21992
|
* ```js
|
|
21879
21993
|
* import { queryCommunities } from '@amityco/ts-sdk'
|
|
@@ -21903,10 +22017,11 @@ const queryCommunities = async (query) => {
|
|
|
21903
22017
|
} }),
|
|
21904
22018
|
});
|
|
21905
22019
|
const { paging } = data, payload = __rest(data, ["paging"]);
|
|
21906
|
-
const
|
|
22020
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
22021
|
+
const { communities } = unpackedPayload;
|
|
21907
22022
|
const cachedAt = client.cache && Date.now();
|
|
21908
22023
|
if (client.cache) {
|
|
21909
|
-
ingestInCache(
|
|
22024
|
+
ingestInCache(unpackedPayload, { cachedAt });
|
|
21910
22025
|
const cacheKey = [
|
|
21911
22026
|
'community',
|
|
21912
22027
|
'query',
|
|
@@ -21955,9 +22070,10 @@ const getCommunities = async (communityIds) => {
|
|
|
21955
22070
|
const client = getActiveClient();
|
|
21956
22071
|
client.log('community/getCommunities', communityIds);
|
|
21957
22072
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
21958
|
-
const { data } = await client.http.get(`/api/v3/communities/list`, {
|
|
22073
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/list`, {
|
|
21959
22074
|
params: { communityIds },
|
|
21960
22075
|
});
|
|
22076
|
+
const data = unpackCommunityPayload(payload);
|
|
21961
22077
|
const cachedAt = client.cache && Date.now();
|
|
21962
22078
|
if (client.cache)
|
|
21963
22079
|
ingestInCache(data, { cachedAt });
|
|
@@ -22016,7 +22132,8 @@ const getCommunity = async (communityId) => {
|
|
|
22016
22132
|
const client = getActiveClient();
|
|
22017
22133
|
client.log('community/getCommunity', communityId);
|
|
22018
22134
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
22019
|
-
const { data } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22135
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/${communityId}`);
|
|
22136
|
+
const data = unpackCommunityPayload(payload);
|
|
22020
22137
|
const cachedAt = client.cache && Date.now();
|
|
22021
22138
|
if (client.cache)
|
|
22022
22139
|
ingestInCache(data, { cachedAt });
|
|
@@ -22070,7 +22187,8 @@ getCommunity.locally = (communityId) => {
|
|
|
22070
22187
|
const createCommunity = async (bundle) => {
|
|
22071
22188
|
const client = getActiveClient();
|
|
22072
22189
|
client.log('user/createCommunity', bundle);
|
|
22073
|
-
const { data } = await client.http.post('/api/v3/communities/', bundle);
|
|
22190
|
+
const { data: payload } = await client.http.post('/api/v3/communities/', packCommunityPayload(bundle));
|
|
22191
|
+
const data = unpackCommunityPayload(payload);
|
|
22074
22192
|
const cachedAt = client.cache && Date.now();
|
|
22075
22193
|
if (client.cache)
|
|
22076
22194
|
ingestInCache(data, { cachedAt });
|
|
@@ -22100,7 +22218,8 @@ const createCommunity = async (bundle) => {
|
|
|
22100
22218
|
const updateCommunity = async (communityId, patch) => {
|
|
22101
22219
|
const client = getActiveClient();
|
|
22102
22220
|
client.log('community/updateCommunity', communityId, patch);
|
|
22103
|
-
const { data } = await client.http.put(`/api/v3/communities/${communityId}`, patch);
|
|
22221
|
+
const { data: payload } = await client.http.put(`/api/v3/communities/${communityId}`, packCommunityPayload(patch));
|
|
22222
|
+
const data = unpackCommunityPayload(payload);
|
|
22104
22223
|
const cachedAt = client.cache && Date.now();
|
|
22105
22224
|
if (client.cache)
|
|
22106
22225
|
ingestInCache(data, { cachedAt });
|
|
@@ -22366,7 +22485,8 @@ const getTopTrendingCommunities = async (query) => {
|
|
|
22366
22485
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22367
22486
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22368
22487
|
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22369
|
-
const { data } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22488
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/top-trending`, { params: { options: { limit } } });
|
|
22489
|
+
const data = unpackCommunityPayload(payload);
|
|
22370
22490
|
const { communities } = data;
|
|
22371
22491
|
const cachedAt = client.cache && Date.now();
|
|
22372
22492
|
if (client.cache) {
|
|
@@ -22428,8 +22548,9 @@ const getRecommendedCommunities = async (query) => {
|
|
|
22428
22548
|
client.log('channel/getRecommendedCommunities', query);
|
|
22429
22549
|
const { limit = 5 } = query !== null && query !== void 0 ? query : {};
|
|
22430
22550
|
// API-FIX: backend doesnt answer Amity.Response
|
|
22431
|
-
// const { data } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22432
|
-
const { data } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22551
|
+
// const { data: payload } = await client.http.get<Amity.Response<CommunityPayload>>(
|
|
22552
|
+
const { data: payload } = await client.http.get(`/api/v3/communities/recommended`, { params: { options: { limit } } });
|
|
22553
|
+
const data = unpackCommunityPayload(payload);
|
|
22433
22554
|
const { communities } = data;
|
|
22434
22555
|
const cachedAt = client.cache && Date.now();
|
|
22435
22556
|
if (client.cache) {
|
|
@@ -23765,7 +23886,8 @@ const onReactorRemoved = (referenceType, referenceId, callback) => {
|
|
|
23765
23886
|
};
|
|
23766
23887
|
|
|
23767
23888
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
23768
|
-
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
23889
|
+
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
23890
|
+
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
23769
23891
|
|
|
23770
23892
|
/**
|
|
23771
23893
|
* ```js
|
|
@@ -23967,6 +24089,23 @@ const isReportedByMe = async (referenceType, referenceId) => {
|
|
|
23967
24089
|
return (_b = result !== null && result !== void 0 ? result : isFlagByMe) !== null && _b !== void 0 ? _b : false;
|
|
23968
24090
|
};
|
|
23969
24091
|
|
|
24092
|
+
/** @hidden */
|
|
24093
|
+
const prepareChannelPayload = (payload) => {
|
|
24094
|
+
const client = getActiveClient();
|
|
24095
|
+
const channels = payload.channels.map(channel => {
|
|
24096
|
+
const channelUser = payload.channelUsers.find(channelUser => channelUser.userId === client.userId && channel.channelId === channelUser.channelId);
|
|
24097
|
+
const hasMention = channelUser
|
|
24098
|
+
? channelUser.readToSegment < channelUser.lastMentionedSegment
|
|
24099
|
+
: false;
|
|
24100
|
+
const unreadCount = channelUser && channelUser.membership === 'member' && channel.messageCount
|
|
24101
|
+
? Math.max(0, channel.messageCount - channelUser.readToSegment)
|
|
24102
|
+
: 0;
|
|
24103
|
+
return Object.assign(Object.assign({}, channel), { hasMention,
|
|
24104
|
+
unreadCount });
|
|
24105
|
+
});
|
|
24106
|
+
return Object.assign(Object.assign({}, payload), { channels });
|
|
24107
|
+
};
|
|
24108
|
+
|
|
23970
24109
|
/**
|
|
23971
24110
|
* ```js
|
|
23972
24111
|
* import { queryChannels } from '@amityco/ts-sdk'
|
|
@@ -23990,16 +24129,17 @@ const queryChannels = async (query) => {
|
|
|
23990
24129
|
// API-FIX: parameters should be querystring.
|
|
23991
24130
|
// API-FIX: backend doesnt answer Amity.Response
|
|
23992
24131
|
// const { data } = await client.http.get<Amity.Response<Amity.Paged<ChannelPayload>>>(
|
|
23993
|
-
const { data } = await client.http.get(`/api/v3/channels`, {
|
|
24132
|
+
const { data: queryPayload } = await client.http.get(`/api/v3/channels`, {
|
|
23994
24133
|
params: Object.assign(Object.assign({}, params), { keyword: displayName, filter: membership, options: {
|
|
23995
24134
|
token: toToken(page, 'skiplimit'),
|
|
23996
24135
|
} }),
|
|
23997
24136
|
});
|
|
23998
|
-
const { paging } =
|
|
23999
|
-
const
|
|
24137
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24138
|
+
const data = prepareChannelPayload(payload);
|
|
24139
|
+
const { channels } = data;
|
|
24000
24140
|
const cachedAt = client.cache && Date.now();
|
|
24001
24141
|
if (client.cache) {
|
|
24002
|
-
ingestInCache(
|
|
24142
|
+
ingestInCache(data, { cachedAt });
|
|
24003
24143
|
const cacheKey = [
|
|
24004
24144
|
'channel',
|
|
24005
24145
|
'query',
|
|
@@ -24049,9 +24189,10 @@ const getChannels = async (channelIds) => {
|
|
|
24049
24189
|
client.log('channel/getChannels', channelIds);
|
|
24050
24190
|
const encodedChannelIds = channelIds.map(channelId => encodeURIComponent(channelId));
|
|
24051
24191
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24052
|
-
const { data } = await client.http.get(`/api/v3/channels/list`, {
|
|
24192
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/list`, {
|
|
24053
24193
|
params: { channelIds: encodedChannelIds },
|
|
24054
24194
|
});
|
|
24195
|
+
const data = prepareChannelPayload(payload);
|
|
24055
24196
|
const cachedAt = client.cache && Date.now();
|
|
24056
24197
|
if (client.cache)
|
|
24057
24198
|
ingestInCache(data, { cachedAt });
|
|
@@ -24110,7 +24251,8 @@ const getChannel = async (channelId) => {
|
|
|
24110
24251
|
const client = getActiveClient();
|
|
24111
24252
|
client.log('channel/getChannel', channelId);
|
|
24112
24253
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24113
|
-
const { data } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
24254
|
+
const { data: payload } = await client.http.get(`/api/v3/channels/${encodeURIComponent(channelId)}`);
|
|
24255
|
+
const data = prepareChannelPayload(payload);
|
|
24114
24256
|
const cachedAt = client.cache && Date.now();
|
|
24115
24257
|
if (client.cache)
|
|
24116
24258
|
ingestInCache(data, { cachedAt });
|
|
@@ -24171,10 +24313,11 @@ const createChannel = async (bundle) => {
|
|
|
24171
24313
|
else {
|
|
24172
24314
|
payload = await client.http.post('/api/v3/channels', bundle);
|
|
24173
24315
|
}
|
|
24316
|
+
const data = prepareChannelPayload(payload.data);
|
|
24174
24317
|
const cachedAt = client.cache && Date.now();
|
|
24175
24318
|
if (client.cache)
|
|
24176
|
-
ingestInCache(
|
|
24177
|
-
const { channels } =
|
|
24319
|
+
ingestInCache(data, { cachedAt });
|
|
24320
|
+
const { channels } = data;
|
|
24178
24321
|
return {
|
|
24179
24322
|
data: channels[0],
|
|
24180
24323
|
cachedAt,
|
|
@@ -24199,7 +24342,8 @@ const createChannel = async (bundle) => {
|
|
|
24199
24342
|
const updateChannel = async (channelId, patch) => {
|
|
24200
24343
|
const client = getActiveClient();
|
|
24201
24344
|
client.log('channel/updateChannel', channelId, patch);
|
|
24202
|
-
const { data } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24345
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}`, patch);
|
|
24346
|
+
const data = prepareChannelPayload(payload);
|
|
24203
24347
|
const cachedAt = client.cache && Date.now();
|
|
24204
24348
|
if (client.cache)
|
|
24205
24349
|
ingestInCache(data, { cachedAt });
|
|
@@ -24250,7 +24394,8 @@ const deleteChannel = async (channelId) => {
|
|
|
24250
24394
|
const joinChannel = async (channelId) => {
|
|
24251
24395
|
const client = getActiveClient();
|
|
24252
24396
|
client.log('channel/joinChannel', channelId);
|
|
24253
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24397
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/join`);
|
|
24398
|
+
const data = prepareChannelPayload(payload);
|
|
24254
24399
|
if (client.cache)
|
|
24255
24400
|
ingestInCache(data);
|
|
24256
24401
|
const { channelUsers } = data;
|
|
@@ -24274,7 +24419,8 @@ const joinChannel = async (channelId) => {
|
|
|
24274
24419
|
const leaveChannel = async (channelId) => {
|
|
24275
24420
|
const client = getActiveClient();
|
|
24276
24421
|
client.log('channel/leaveChannel', channelId);
|
|
24277
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24422
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/leave`);
|
|
24423
|
+
const data = prepareChannelPayload(payload);
|
|
24278
24424
|
if (client.cache)
|
|
24279
24425
|
ingestInCache(data);
|
|
24280
24426
|
const { channelUsers } = data;
|
|
@@ -24299,16 +24445,17 @@ const queryChannelMembers = async (query) => {
|
|
|
24299
24445
|
const client = getActiveClient();
|
|
24300
24446
|
client.log('channel/queryChannelMembers', query);
|
|
24301
24447
|
const _a = query !== null && query !== void 0 ? query : {}, { page, channelId } = _a, params = __rest(_a, ["page", "channelId"]);
|
|
24302
|
-
const { data } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24448
|
+
const { data: queryPayload } = await client.http.get(`/api/v4/channels/${encodeURIComponent(channelId)}/users`, {
|
|
24303
24449
|
params: Object.assign(Object.assign({}, params), { options: {
|
|
24304
24450
|
token: toToken(page, 'skiplimit'),
|
|
24305
24451
|
} }),
|
|
24306
24452
|
});
|
|
24307
|
-
const { paging } =
|
|
24308
|
-
const
|
|
24453
|
+
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
24454
|
+
const data = prepareChannelPayload(payload);
|
|
24455
|
+
const { channelUsers } = data;
|
|
24309
24456
|
const cachedAt = client.cache && Date.now();
|
|
24310
24457
|
if (client.cache) {
|
|
24311
|
-
ingestInCache(
|
|
24458
|
+
ingestInCache(data);
|
|
24312
24459
|
}
|
|
24313
24460
|
const nextPage = toPage(paging.next);
|
|
24314
24461
|
const prevPage = toPage(paging.previous);
|
|
@@ -24351,13 +24498,11 @@ queryChannelMembers.locally = (query) => {
|
|
|
24351
24498
|
const addChannelMembers = async (channelId, userIds) => {
|
|
24352
24499
|
const client = getActiveClient();
|
|
24353
24500
|
client.log('channel/addChannelMembers', channelId, userIds);
|
|
24354
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24501
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { channelId, userIds });
|
|
24502
|
+
const data = prepareChannelPayload(payload);
|
|
24355
24503
|
if (client.cache)
|
|
24356
24504
|
ingestInCache(data);
|
|
24357
|
-
fireEvent('v3.channel.didAddUsers',
|
|
24358
|
-
channels: data.channels,
|
|
24359
|
-
channelUsers: data.channelUsers,
|
|
24360
|
-
});
|
|
24505
|
+
fireEvent('v3.channel.didAddUsers', data);
|
|
24361
24506
|
const { channelUsers } = data;
|
|
24362
24507
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership === 'member');
|
|
24363
24508
|
};
|
|
@@ -24380,13 +24525,11 @@ const addChannelMembers = async (channelId, userIds) => {
|
|
|
24380
24525
|
const removeChannelMembers = async (channelId, userIds) => {
|
|
24381
24526
|
const client = getActiveClient();
|
|
24382
24527
|
client.log('channel/removeChannelMembers', channelId, userIds);
|
|
24383
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24528
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users`, { data: { channelId, userIds } });
|
|
24529
|
+
const data = prepareChannelPayload(payload);
|
|
24384
24530
|
if (client.cache)
|
|
24385
24531
|
ingestInCache(data);
|
|
24386
|
-
fireEvent('v3.channel.didRemoveUsers',
|
|
24387
|
-
channels: data.channels,
|
|
24388
|
-
channelUsers: data.channelUsers,
|
|
24389
|
-
});
|
|
24532
|
+
fireEvent('v3.channel.didRemoveUsers', data);
|
|
24390
24533
|
const { channelUsers } = data;
|
|
24391
24534
|
return !!channelUsers.find(channelUser => channelUser.channelId === channelId && channelUser.membership !== 'member');
|
|
24392
24535
|
};
|
|
@@ -24410,7 +24553,8 @@ const removeChannelMembers = async (channelId, userIds) => {
|
|
|
24410
24553
|
const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24411
24554
|
const client = getActiveClient();
|
|
24412
24555
|
client.log('channel/addChannelMembersRole', channelId, roleId, userIds);
|
|
24413
|
-
const { data } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24556
|
+
const { data: payload } = await client.http.post(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { channelId, role: roleId, userIds });
|
|
24557
|
+
const data = prepareChannelPayload(payload);
|
|
24414
24558
|
if (client.cache)
|
|
24415
24559
|
ingestInCache(data);
|
|
24416
24560
|
const { channelUsers } = data;
|
|
@@ -24436,7 +24580,8 @@ const addChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24436
24580
|
const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
24437
24581
|
const client = getActiveClient();
|
|
24438
24582
|
client.log('channel/removeChannelMembersRole', channelId, roleId, userIds);
|
|
24439
|
-
const { data } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24583
|
+
const { data: payload } = await client.http.delete(`/api/v3/channels/${encodeURIComponent(channelId)}/users/roles`, { data: { channelId, role: roleId, userIds } });
|
|
24584
|
+
const data = prepareChannelPayload(payload);
|
|
24440
24585
|
if (client.cache)
|
|
24441
24586
|
ingestInCache(data);
|
|
24442
24587
|
const { channelUsers } = data;
|
|
@@ -24460,13 +24605,14 @@ const removeChannelMembersRole = async (channelId, roleId, userIds) => {
|
|
|
24460
24605
|
const banChannelMembers = async (channelId, userIds) => {
|
|
24461
24606
|
const client = getActiveClient();
|
|
24462
24607
|
client.log('channel/banChannelMembers', { userIds, channelId });
|
|
24463
|
-
const payload = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
24608
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${channelId}/users/ban`, {
|
|
24464
24609
|
userIds,
|
|
24465
24610
|
});
|
|
24611
|
+
const data = prepareChannelPayload(payload);
|
|
24466
24612
|
const cachedAt = client.cache && Date.now();
|
|
24467
24613
|
if (client.cache)
|
|
24468
|
-
ingestInCache(
|
|
24469
|
-
const { channelUsers } =
|
|
24614
|
+
ingestInCache(data, { cachedAt });
|
|
24615
|
+
const { channelUsers } = data;
|
|
24470
24616
|
return {
|
|
24471
24617
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
24472
24618
|
cachedAt,
|
|
@@ -24490,19 +24636,45 @@ const banChannelMembers = async (channelId, userIds) => {
|
|
|
24490
24636
|
const unbanChannelMembers = async (channelId, userIds) => {
|
|
24491
24637
|
const client = getActiveClient();
|
|
24492
24638
|
client.log('channel/unbanChannelMembers', { userIds, channelId });
|
|
24493
|
-
const payload = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
24639
|
+
const { data: payload } = await client.http.put(`/api/v3/channels/${encodeURIComponent(channelId)}/users/unban`, {
|
|
24494
24640
|
userIds,
|
|
24495
24641
|
});
|
|
24642
|
+
const data = prepareChannelPayload(payload);
|
|
24496
24643
|
const cachedAt = client.cache && Date.now();
|
|
24497
24644
|
if (client.cache)
|
|
24498
|
-
ingestInCache(
|
|
24499
|
-
const { channelUsers } =
|
|
24645
|
+
ingestInCache(data, { cachedAt });
|
|
24646
|
+
const { channelUsers } = data;
|
|
24500
24647
|
return {
|
|
24501
24648
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
24502
24649
|
cachedAt,
|
|
24503
24650
|
};
|
|
24504
24651
|
};
|
|
24505
24652
|
|
|
24653
|
+
/**
|
|
24654
|
+
* ```js
|
|
24655
|
+
* import { onChannelCreated } from '@amityco/ts-sdk'
|
|
24656
|
+
* const dispose = onChannelCreated(channel => {
|
|
24657
|
+
* // ...
|
|
24658
|
+
* })
|
|
24659
|
+
* ```
|
|
24660
|
+
*
|
|
24661
|
+
* Fired when any {@link Amity.Channel} have been created
|
|
24662
|
+
*
|
|
24663
|
+
* @param callback The function to call when the event was fired
|
|
24664
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24665
|
+
*
|
|
24666
|
+
* @category Channel Events
|
|
24667
|
+
*/
|
|
24668
|
+
const onChannelCreated = (callback) => {
|
|
24669
|
+
const client = getActiveClient();
|
|
24670
|
+
const filter = (payload) => {
|
|
24671
|
+
const data = prepareChannelPayload(payload);
|
|
24672
|
+
ingestInCache(data);
|
|
24673
|
+
callback(data.channels[0]);
|
|
24674
|
+
};
|
|
24675
|
+
return createEventSubscriber(client, 'onChannelCreated', 'v3.channel.didCreate', filter);
|
|
24676
|
+
};
|
|
24677
|
+
|
|
24506
24678
|
/**
|
|
24507
24679
|
* ```js
|
|
24508
24680
|
* import { onChannelUpdated } from '@amityco/ts-sdk'
|
|
@@ -24521,8 +24693,9 @@ const unbanChannelMembers = async (channelId, userIds) => {
|
|
|
24521
24693
|
const onChannelUpdated = (callback) => {
|
|
24522
24694
|
const client = getActiveClient();
|
|
24523
24695
|
const filter = (payload) => {
|
|
24524
|
-
|
|
24525
|
-
|
|
24696
|
+
const data = prepareChannelPayload(payload);
|
|
24697
|
+
ingestInCache(data);
|
|
24698
|
+
callback(data.channels[0]);
|
|
24526
24699
|
};
|
|
24527
24700
|
return createEventSubscriber(client, 'onChannelUpdated', 'v3.channel.didUpdate', filter);
|
|
24528
24701
|
};
|
|
@@ -24545,8 +24718,9 @@ const onChannelUpdated = (callback) => {
|
|
|
24545
24718
|
const onChannelDeleted = (callback) => {
|
|
24546
24719
|
const client = getActiveClient();
|
|
24547
24720
|
const filter = (payload) => {
|
|
24548
|
-
|
|
24549
|
-
|
|
24721
|
+
const data = prepareChannelPayload(payload);
|
|
24722
|
+
ingestInCache(data);
|
|
24723
|
+
callback(data.channels[0]);
|
|
24550
24724
|
};
|
|
24551
24725
|
return createEventSubscriber(client, 'onChannelDeleted', 'v3.channel.didDelete', filter);
|
|
24552
24726
|
};
|
|
@@ -24569,8 +24743,9 @@ const onChannelDeleted = (callback) => {
|
|
|
24569
24743
|
const onChannelJoined = (callback) => {
|
|
24570
24744
|
const client = getActiveClient();
|
|
24571
24745
|
const filter = (payload) => {
|
|
24572
|
-
|
|
24573
|
-
|
|
24746
|
+
const data = prepareChannelPayload(payload);
|
|
24747
|
+
ingestInCache(data);
|
|
24748
|
+
callback(data.channels[0]);
|
|
24574
24749
|
};
|
|
24575
24750
|
return createEventSubscriber(client, 'onChannelJoined', 'v3.channel.didJoin', filter);
|
|
24576
24751
|
};
|
|
@@ -24593,8 +24768,9 @@ const onChannelJoined = (callback) => {
|
|
|
24593
24768
|
const onChannelLeft = (callback) => {
|
|
24594
24769
|
const client = getActiveClient();
|
|
24595
24770
|
const filter = (payload) => {
|
|
24596
|
-
|
|
24597
|
-
|
|
24771
|
+
const data = prepareChannelPayload(payload);
|
|
24772
|
+
ingestInCache(data);
|
|
24773
|
+
callback(data.channels[0]);
|
|
24598
24774
|
};
|
|
24599
24775
|
return createEventSubscriber(client, 'onChannelLeft', 'v3.channel.didLeave', filter);
|
|
24600
24776
|
};
|
|
@@ -24617,8 +24793,9 @@ const onChannelLeft = (callback) => {
|
|
|
24617
24793
|
const onChannelMemberAdded = (callback) => {
|
|
24618
24794
|
const client = getActiveClient();
|
|
24619
24795
|
const filter = (payload) => {
|
|
24620
|
-
|
|
24621
|
-
|
|
24796
|
+
const data = prepareChannelPayload(payload);
|
|
24797
|
+
ingestInCache(data);
|
|
24798
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
24622
24799
|
};
|
|
24623
24800
|
return createEventSubscriber(client, 'onChannelMemberAdded', 'v3.channel.didAddUsers', filter);
|
|
24624
24801
|
};
|
|
@@ -24641,8 +24818,9 @@ const onChannelMemberAdded = (callback) => {
|
|
|
24641
24818
|
const onChannelMemberRemoved = (callback) => {
|
|
24642
24819
|
const client = getActiveClient();
|
|
24643
24820
|
const filter = (payload) => {
|
|
24644
|
-
|
|
24645
|
-
|
|
24821
|
+
const data = prepareChannelPayload(payload);
|
|
24822
|
+
ingestInCache(data);
|
|
24823
|
+
callback(data.channels[0], data.channelUsers[0]);
|
|
24646
24824
|
};
|
|
24647
24825
|
return createEventSubscriber(client, 'onChannelMemberRemoved', 'v3.channel.didRemoveUsers', filter);
|
|
24648
24826
|
};
|
|
@@ -24688,6 +24866,159 @@ const observeChannel = (channelId, callback) => {
|
|
|
24688
24866
|
};
|
|
24689
24867
|
};
|
|
24690
24868
|
|
|
24869
|
+
/**
|
|
24870
|
+
* ```js
|
|
24871
|
+
* import { observeChannels } from '@amityco/ts-sdk'
|
|
24872
|
+
*
|
|
24873
|
+
* let channels = []
|
|
24874
|
+
* const unsub = observeChannels(channel => merge(channels, channel))
|
|
24875
|
+
* ```
|
|
24876
|
+
*
|
|
24877
|
+
* Observe all mutations on a list of {@link Amity.Channel} for a current user
|
|
24878
|
+
*
|
|
24879
|
+
* @param callback the function to call when new data are available
|
|
24880
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
24881
|
+
*
|
|
24882
|
+
* @category Channel Observer
|
|
24883
|
+
*/
|
|
24884
|
+
const observeChannels = (callback) => {
|
|
24885
|
+
const { log } = getActiveClient();
|
|
24886
|
+
const timestamp = Date.now();
|
|
24887
|
+
log(`observeChannels(tmpid: ${timestamp}) > listen`);
|
|
24888
|
+
const disposers = [];
|
|
24889
|
+
const router = (channel, action) => {
|
|
24890
|
+
var _a, _b;
|
|
24891
|
+
if (callback instanceof Function)
|
|
24892
|
+
return callback(channel);
|
|
24893
|
+
(_a = callback.onEvent) === null || _a === void 0 ? void 0 : _a.call(callback, action, channel);
|
|
24894
|
+
(_b = callback[action]) === null || _b === void 0 ? void 0 : _b.call(callback, channel);
|
|
24895
|
+
};
|
|
24896
|
+
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')));
|
|
24897
|
+
return () => {
|
|
24898
|
+
log(`observeChannels(tmpid: ${timestamp}) > dispose`);
|
|
24899
|
+
disposers.forEach(fn => fn());
|
|
24900
|
+
};
|
|
24901
|
+
};
|
|
24902
|
+
|
|
24903
|
+
/**
|
|
24904
|
+
* ```js
|
|
24905
|
+
* import { liveChannels } from '@amityco/ts-sdk'
|
|
24906
|
+
*
|
|
24907
|
+
* let channels = []
|
|
24908
|
+
* const unsub = liveChannels({
|
|
24909
|
+
* displayName: Amity.Channel['displayName'],
|
|
24910
|
+
* }, response => merge(channels, response.data))
|
|
24911
|
+
* ```
|
|
24912
|
+
*
|
|
24913
|
+
* Observe all mutations on a list of {@link Amity.Channel}s
|
|
24914
|
+
*
|
|
24915
|
+
* @param params for querying channels
|
|
24916
|
+
* @param callback the function to call when new data are available
|
|
24917
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
24918
|
+
*
|
|
24919
|
+
* @category Channel Live Collection
|
|
24920
|
+
*/
|
|
24921
|
+
const liveChannels = (params, callback, config) => {
|
|
24922
|
+
const { log, cache } = getActiveClient();
|
|
24923
|
+
if (!cache) {
|
|
24924
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24925
|
+
}
|
|
24926
|
+
const timestamp = Date.now();
|
|
24927
|
+
log(`liveChannels(tmpid: ${timestamp}) > listen`);
|
|
24928
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
24929
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
24930
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
24931
|
+
const disposers = [];
|
|
24932
|
+
const cacheKey = ['channel', 'collection', {}];
|
|
24933
|
+
const responder = (data) => {
|
|
24934
|
+
var _a, _b;
|
|
24935
|
+
let channels = (_a = data.data
|
|
24936
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
24937
|
+
.filter(Boolean)
|
|
24938
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
24939
|
+
channels = filterByPropEquality(channels, 'isDeleted', params.isDeleted);
|
|
24940
|
+
channels = filterByPropEquality(channels, 'displayName', params.displayName);
|
|
24941
|
+
if (params.types) {
|
|
24942
|
+
channels = channels.filter(c => { var _a; return (_a = params.types) === null || _a === void 0 ? void 0 : _a.includes(c.type); });
|
|
24943
|
+
}
|
|
24944
|
+
if (params.tags) {
|
|
24945
|
+
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); }); });
|
|
24946
|
+
}
|
|
24947
|
+
if (params.excludeTags) {
|
|
24948
|
+
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); })); });
|
|
24949
|
+
}
|
|
24950
|
+
const sortBy = params.sortBy || 'lastCreated';
|
|
24951
|
+
if (sortBy === 'lastCreated' || sortBy === 'firstCreated') {
|
|
24952
|
+
channels = channels.sort(sortBy === 'lastCreated' ? sortByLastCreated : sortByFirstCreated);
|
|
24953
|
+
}
|
|
24954
|
+
/*
|
|
24955
|
+
* The server returns channels with empty | null displayName's first before
|
|
24956
|
+
* returning sorted list of channels with displayNames
|
|
24957
|
+
*
|
|
24958
|
+
* This section needs to be updated as displayNames can be null as well
|
|
24959
|
+
*/
|
|
24960
|
+
if (sortBy === 'displayName') {
|
|
24961
|
+
channels = channels
|
|
24962
|
+
// this needs to be aligned with the backend data type
|
|
24963
|
+
.map(c => (c.displayName ? c : Object.assign(Object.assign({}, c), { displayName: '' })))
|
|
24964
|
+
// @ts-ignore
|
|
24965
|
+
.sort(sortByDisplayName);
|
|
24966
|
+
}
|
|
24967
|
+
callback({
|
|
24968
|
+
onNextPage: onFetch,
|
|
24969
|
+
data: channels,
|
|
24970
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
24971
|
+
loading: data.loading,
|
|
24972
|
+
error: data.error,
|
|
24973
|
+
});
|
|
24974
|
+
};
|
|
24975
|
+
const realtimeRouter = (channel, action) => {
|
|
24976
|
+
var _a;
|
|
24977
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24978
|
+
if (!collection)
|
|
24979
|
+
return;
|
|
24980
|
+
if (action === 'onCreate') {
|
|
24981
|
+
collection.data = [...new Set([channel.channelId, ...collection.data])];
|
|
24982
|
+
/*
|
|
24983
|
+
* if the filter isDeleted is set, only collection item must be updated and not
|
|
24984
|
+
* the collection
|
|
24985
|
+
*/
|
|
24986
|
+
}
|
|
24987
|
+
else if (action === 'onDelete' && !params.isDeleted) {
|
|
24988
|
+
collection.data = collection.data.filter(c => c !== channel.channelId);
|
|
24989
|
+
}
|
|
24990
|
+
pushToCache(cacheKey, collection);
|
|
24991
|
+
responder(collection);
|
|
24992
|
+
};
|
|
24993
|
+
const onFetch = () => {
|
|
24994
|
+
var _a, _b, _c;
|
|
24995
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24996
|
+
const channels = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24997
|
+
if (channels.length > 0 && !(collection === null || collection === void 0 ? void 0 : collection.params.page))
|
|
24998
|
+
return;
|
|
24999
|
+
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 } }));
|
|
25000
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
25001
|
+
const data = {
|
|
25002
|
+
loading,
|
|
25003
|
+
error,
|
|
25004
|
+
params: { page },
|
|
25005
|
+
data: channels,
|
|
25006
|
+
};
|
|
25007
|
+
if (result) {
|
|
25008
|
+
data.data = [...new Set([...channels, ...result.map(getResolver('channel'))])];
|
|
25009
|
+
}
|
|
25010
|
+
pushToCache(cacheKey, data);
|
|
25011
|
+
responder(data);
|
|
25012
|
+
}, queryOptions(policy));
|
|
25013
|
+
};
|
|
25014
|
+
disposers.push(onChannelCreated(channel => realtimeRouter(channel, 'onCreate')), onChannelDeleted(channel => realtimeRouter(channel, 'onDelete')), onChannelUpdated(channel => realtimeRouter(channel, 'onUpdate')));
|
|
25015
|
+
onFetch();
|
|
25016
|
+
return () => {
|
|
25017
|
+
log(`liveChannels(tmpid: ${timestamp}) > dispose`);
|
|
25018
|
+
disposers.forEach(fn => fn());
|
|
25019
|
+
};
|
|
25020
|
+
};
|
|
25021
|
+
|
|
24691
25022
|
/**
|
|
24692
25023
|
* ```js
|
|
24693
25024
|
* import { onMessageCreated } from '@amityco/ts-sdk'
|
|
@@ -24820,7 +25151,6 @@ const observeMessage = (messageId, callback, policy = 'cache_then_server') => {
|
|
|
24820
25151
|
*
|
|
24821
25152
|
* Observe all mutations on a list of {@link Amity.Message} for a given {@link Amity.Channel} object
|
|
24822
25153
|
*
|
|
24823
|
-
* @param client the client to observe the message with
|
|
24824
25154
|
* @param channelId the ID of the channel where to observe the messages
|
|
24825
25155
|
* @param callback the function to call when new data are available
|
|
24826
25156
|
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
@@ -24848,19 +25178,112 @@ const observeMessages = (channelId, callback) => {
|
|
|
24848
25178
|
};
|
|
24849
25179
|
};
|
|
24850
25180
|
|
|
25181
|
+
/**
|
|
25182
|
+
* ```js
|
|
25183
|
+
* import { liveMessages } from '@amityco/ts-sdk'
|
|
25184
|
+
*
|
|
25185
|
+
* let messages = []
|
|
25186
|
+
* const unsub = liveMessages({
|
|
25187
|
+
* channelId: Amity.Channel['channelId'];
|
|
25188
|
+
* }, response => merge(messages, response.data))
|
|
25189
|
+
* ```
|
|
25190
|
+
*
|
|
25191
|
+
* Observe all mutations on a list of {@link Amity.Message} for a given target object
|
|
25192
|
+
*
|
|
25193
|
+
* @param params for querying memssages from a channel
|
|
25194
|
+
* @param callback the function to call when new data are available
|
|
25195
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
25196
|
+
*
|
|
25197
|
+
* @category Messages Live Collection
|
|
25198
|
+
*/
|
|
25199
|
+
const liveMessages = (params, callback, config) => {
|
|
25200
|
+
const { log, cache } = getActiveClient();
|
|
25201
|
+
if (!cache) {
|
|
25202
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
25203
|
+
}
|
|
25204
|
+
const timestamp = Date.now();
|
|
25205
|
+
log(`liveMessages(tmpid: ${timestamp}) > listen`);
|
|
25206
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
25207
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
25208
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
25209
|
+
const disposers = [];
|
|
25210
|
+
const cacheKey = ['message', 'collection', { channelId: params.channelId }];
|
|
25211
|
+
const responder = (data) => {
|
|
25212
|
+
var _a, _b;
|
|
25213
|
+
let messages = (_a = data.data
|
|
25214
|
+
.map(messageId => pullFromCache(['message', 'get', messageId]))
|
|
25215
|
+
.filter(Boolean)
|
|
25216
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
25217
|
+
/*
|
|
25218
|
+
* for cases when message is deleted via RTE, this flag is used to get
|
|
25219
|
+
* items fro cache that are deleted | !deleted
|
|
25220
|
+
*/
|
|
25221
|
+
messages = filterByPropEquality(messages, 'isDeleted', params.isDeleted);
|
|
25222
|
+
callback({
|
|
25223
|
+
onNextPage: onFetch,
|
|
25224
|
+
data: messages,
|
|
25225
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
25226
|
+
loading: data.loading,
|
|
25227
|
+
error: data.error,
|
|
25228
|
+
});
|
|
25229
|
+
};
|
|
25230
|
+
const realtimeRouter = (message, action) => {
|
|
25231
|
+
var _a;
|
|
25232
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25233
|
+
if (params.channelId !== message.channelId || !collection)
|
|
25234
|
+
return;
|
|
25235
|
+
if (action === 'onCreate') {
|
|
25236
|
+
collection.data = [...new Set([message.messageId, ...collection.data])];
|
|
25237
|
+
}
|
|
25238
|
+
else if (['onDelete'].includes(action)) {
|
|
25239
|
+
collection.data = collection.data.filter(m => m !== message.messageId);
|
|
25240
|
+
}
|
|
25241
|
+
pushToCache(cacheKey, collection);
|
|
25242
|
+
responder(collection);
|
|
25243
|
+
};
|
|
25244
|
+
const onFetch = () => {
|
|
25245
|
+
var _a, _b, _c, _d, _e;
|
|
25246
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25247
|
+
const messages = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
25248
|
+
if (messages.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
25249
|
+
return;
|
|
25250
|
+
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 } }));
|
|
25251
|
+
runQuery(query, ({ data: result, error, loading, prevPage: page }) => {
|
|
25252
|
+
const data = {
|
|
25253
|
+
loading,
|
|
25254
|
+
error,
|
|
25255
|
+
params: { page },
|
|
25256
|
+
data: messages,
|
|
25257
|
+
};
|
|
25258
|
+
if (result) {
|
|
25259
|
+
data.data = [...new Set([...messages, ...result.map(getResolver('message'))])];
|
|
25260
|
+
}
|
|
25261
|
+
pushToCache(cacheKey, data);
|
|
25262
|
+
responder(data);
|
|
25263
|
+
}, queryOptions(policy));
|
|
25264
|
+
};
|
|
25265
|
+
disposers.push(onMessageCreated(message => realtimeRouter(message, 'onCreate')), onMessageDeleted(message => realtimeRouter(message, 'onDelete')), onMessageUpdated(message => realtimeRouter(message, 'onUpdate')));
|
|
25266
|
+
onFetch();
|
|
25267
|
+
return () => {
|
|
25268
|
+
log(`liveMessages(tmpid: ${timestamp}) > dispose`);
|
|
25269
|
+
disposers.forEach(fn => fn());
|
|
25270
|
+
};
|
|
25271
|
+
};
|
|
25272
|
+
|
|
24851
25273
|
const createCommunityEventSubscriber = (event, callback) => {
|
|
24852
25274
|
const client = getActiveClient();
|
|
24853
25275
|
const filter = (payload) => {
|
|
25276
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
24854
25277
|
if (!client.cache) {
|
|
24855
25278
|
// TODO: here we are missing specific properties here!
|
|
24856
|
-
callback(
|
|
25279
|
+
callback(unpackedPayload.communities[0]);
|
|
24857
25280
|
}
|
|
24858
25281
|
else {
|
|
24859
|
-
ingestInCache(
|
|
25282
|
+
ingestInCache(unpackedPayload);
|
|
24860
25283
|
const community = pullFromCache([
|
|
24861
25284
|
'community',
|
|
24862
25285
|
'get',
|
|
24863
|
-
|
|
25286
|
+
unpackedPayload.communities[0].communityId,
|
|
24864
25287
|
]);
|
|
24865
25288
|
callback(community.data);
|
|
24866
25289
|
}
|
|
@@ -24896,21 +25319,22 @@ function getEventRelatedMember(event, payload) {
|
|
|
24896
25319
|
const createCommunityMemberEventSubscriber = (event, callback) => {
|
|
24897
25320
|
const client = getActiveClient();
|
|
24898
25321
|
const filter = (payload) => {
|
|
25322
|
+
const unpackedPayload = unpackCommunityPayload(payload);
|
|
24899
25323
|
if (!client.cache) {
|
|
24900
25324
|
// TODO: here we are missing specific properties here!
|
|
24901
|
-
callback(
|
|
25325
|
+
callback(unpackedPayload.communities[0], getEventRelatedMember(event, unpackedPayload));
|
|
24902
25326
|
}
|
|
24903
25327
|
else {
|
|
24904
|
-
ingestInCache(
|
|
25328
|
+
ingestInCache(unpackedPayload);
|
|
24905
25329
|
const community = pullFromCache([
|
|
24906
25330
|
'community',
|
|
24907
25331
|
'get',
|
|
24908
|
-
|
|
25332
|
+
unpackedPayload.communities[0].communityId,
|
|
24909
25333
|
]);
|
|
24910
25334
|
const member = pullFromCache([
|
|
24911
25335
|
'communityUsers',
|
|
24912
25336
|
'get',
|
|
24913
|
-
getResolver('communityUsers')(getEventRelatedMember(event,
|
|
25337
|
+
getResolver('communityUsers')(getEventRelatedMember(event, unpackedPayload)),
|
|
24914
25338
|
]);
|
|
24915
25339
|
callback(community.data, member.data);
|
|
24916
25340
|
}
|
|
@@ -25335,9 +25759,9 @@ const queryFollows = async (key, query) => {
|
|
|
25335
25759
|
if (client.cache) {
|
|
25336
25760
|
ingestInCache(payload, { cachedAt });
|
|
25337
25761
|
const cacheKey = [
|
|
25338
|
-
|
|
25762
|
+
'follow',
|
|
25339
25763
|
'query',
|
|
25340
|
-
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page) }),
|
|
25764
|
+
Object.assign(Object.assign({}, params), { userId, options: Object.assign({}, page), type: key }),
|
|
25341
25765
|
];
|
|
25342
25766
|
pushToCache(cacheKey, { follows: follows.map(getResolver('follow')), paging });
|
|
25343
25767
|
}
|
|
@@ -25352,7 +25776,11 @@ queryFollows.locally = (key, query) => {
|
|
|
25352
25776
|
if (!client.cache)
|
|
25353
25777
|
return;
|
|
25354
25778
|
const { page } = query, params = __rest(query, ["page"]);
|
|
25355
|
-
const queryKey = [
|
|
25779
|
+
const queryKey = [
|
|
25780
|
+
'follow',
|
|
25781
|
+
'query',
|
|
25782
|
+
Object.assign(Object.assign({}, params), { options: Object.assign({}, page), type: key }),
|
|
25783
|
+
];
|
|
25356
25784
|
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
25357
25785
|
if (!(data === null || data === void 0 ? void 0 : data.follows.length)) {
|
|
25358
25786
|
return;
|
|
@@ -25898,6 +26326,186 @@ const observeFollowings = (userId, callback) => {
|
|
|
25898
26326
|
};
|
|
25899
26327
|
};
|
|
25900
26328
|
|
|
26329
|
+
/**
|
|
26330
|
+
* ```js
|
|
26331
|
+
* import { liveFollowers } from '@amityco/ts-sdk'
|
|
26332
|
+
*
|
|
26333
|
+
* let followers = []
|
|
26334
|
+
* const unsub = liveFollowers({
|
|
26335
|
+
* userId: Amity.User['userId'];
|
|
26336
|
+
* }, response => merge(followers, response.data))
|
|
26337
|
+
* ```
|
|
26338
|
+
*
|
|
26339
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followers for a given userId
|
|
26340
|
+
*
|
|
26341
|
+
* @param userId the user
|
|
26342
|
+
* @param callback the function to call when new data are available
|
|
26343
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
26344
|
+
*
|
|
26345
|
+
* @category Followers Live Collection
|
|
26346
|
+
*/
|
|
26347
|
+
const liveFollowers = (params, callback, config) => {
|
|
26348
|
+
const { log, cache } = getActiveClient();
|
|
26349
|
+
if (!cache) {
|
|
26350
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
26351
|
+
}
|
|
26352
|
+
const timestamp = Date.now();
|
|
26353
|
+
log(`liveFollowers(tmpid: ${timestamp}) > listen`);
|
|
26354
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
26355
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
26356
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
26357
|
+
const disposers = [];
|
|
26358
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'follower' }];
|
|
26359
|
+
const responder = (data) => {
|
|
26360
|
+
var _a, _b;
|
|
26361
|
+
let followers = (_a = data.data
|
|
26362
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26363
|
+
.filter(Boolean)
|
|
26364
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26365
|
+
if (params.status && params.status !== 'all') {
|
|
26366
|
+
followers = filterByPropEquality(followers, 'status', params.status);
|
|
26367
|
+
}
|
|
26368
|
+
callback({
|
|
26369
|
+
onNextPage: onFetch,
|
|
26370
|
+
data: followers,
|
|
26371
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26372
|
+
loading: data.loading,
|
|
26373
|
+
error: data.error,
|
|
26374
|
+
});
|
|
26375
|
+
};
|
|
26376
|
+
const realtimeRouter = (followStatus, action) => {
|
|
26377
|
+
var _a;
|
|
26378
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26379
|
+
if (params.userId !== followStatus.to || !collection)
|
|
26380
|
+
return;
|
|
26381
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26382
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26383
|
+
}
|
|
26384
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26385
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26386
|
+
}
|
|
26387
|
+
pushToCache(cacheKey, collection);
|
|
26388
|
+
responder(collection);
|
|
26389
|
+
};
|
|
26390
|
+
const onFetch = () => {
|
|
26391
|
+
var _a, _b, _c, _d, _e;
|
|
26392
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26393
|
+
const followers = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26394
|
+
if (followers.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26395
|
+
return;
|
|
26396
|
+
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 } }));
|
|
26397
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26398
|
+
const data = {
|
|
26399
|
+
loading,
|
|
26400
|
+
error,
|
|
26401
|
+
params: { page },
|
|
26402
|
+
data: followers,
|
|
26403
|
+
};
|
|
26404
|
+
if (result) {
|
|
26405
|
+
data.data = [...new Set([...followers, ...result.map(getResolver('follow'))])];
|
|
26406
|
+
}
|
|
26407
|
+
pushToCache(cacheKey, data);
|
|
26408
|
+
responder(data);
|
|
26409
|
+
}, queryOptions(policy));
|
|
26410
|
+
};
|
|
26411
|
+
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')));
|
|
26412
|
+
onFetch();
|
|
26413
|
+
return () => {
|
|
26414
|
+
log(`liveFollowers(tmpid: ${timestamp}) > dispose`);
|
|
26415
|
+
disposers.forEach(fn => fn());
|
|
26416
|
+
};
|
|
26417
|
+
};
|
|
26418
|
+
|
|
26419
|
+
/**
|
|
26420
|
+
* ```js
|
|
26421
|
+
* import { liveFollowings } from '@amityco/ts-sdk'
|
|
26422
|
+
*
|
|
26423
|
+
* let followings = []
|
|
26424
|
+
* const unsub = liveFollowings({
|
|
26425
|
+
* userId: Amity.User['userId'];
|
|
26426
|
+
* }, response => merge(followings, response.data))
|
|
26427
|
+
* ```
|
|
26428
|
+
*
|
|
26429
|
+
* Observe all mutations on a list of {@link Amity.FollowStatus} followings for a given userId
|
|
26430
|
+
*
|
|
26431
|
+
* @param userId the user
|
|
26432
|
+
* @param callback the function to call when new data are available
|
|
26433
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
26434
|
+
*
|
|
26435
|
+
* @category Followings Live Collection
|
|
26436
|
+
*/
|
|
26437
|
+
const liveFollowings = (params, callback, config) => {
|
|
26438
|
+
const { log, cache } = getActiveClient();
|
|
26439
|
+
if (!cache) {
|
|
26440
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
26441
|
+
}
|
|
26442
|
+
const timestamp = Date.now();
|
|
26443
|
+
log(`liveFollowings(tmpid: ${timestamp}) > listen`);
|
|
26444
|
+
const { limit: queryLimit } = params, queryParams = __rest(params, ["limit"]);
|
|
26445
|
+
const limit = queryLimit !== null && queryLimit !== void 0 ? queryLimit : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
26446
|
+
const { policy = COLLECTION_DEFAULT_CACHING_POLICY } = config !== null && config !== void 0 ? config : {};
|
|
26447
|
+
const disposers = [];
|
|
26448
|
+
const cacheKey = ['follow', 'collection', { userId: params.userId, type: 'following' }];
|
|
26449
|
+
const responder = (data) => {
|
|
26450
|
+
var _a, _b;
|
|
26451
|
+
let followings = (_a = data.data
|
|
26452
|
+
.map(key => pullFromCache(['follow', 'get', key]))
|
|
26453
|
+
.filter(Boolean)
|
|
26454
|
+
.map(({ data }) => data)) !== null && _a !== void 0 ? _a : [];
|
|
26455
|
+
if (params.status && params.status !== 'all') {
|
|
26456
|
+
followings = filterByPropEquality(followings, 'status', params.status);
|
|
26457
|
+
}
|
|
26458
|
+
callback({
|
|
26459
|
+
onNextPage: onFetch,
|
|
26460
|
+
data: followings,
|
|
26461
|
+
hasNextPage: !!((_b = data.params) === null || _b === void 0 ? void 0 : _b.page),
|
|
26462
|
+
loading: data.loading,
|
|
26463
|
+
error: data.error,
|
|
26464
|
+
});
|
|
26465
|
+
};
|
|
26466
|
+
const realtimeRouter = (followStatus, action) => {
|
|
26467
|
+
var _a;
|
|
26468
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26469
|
+
if (params.userId !== followStatus.from || !collection)
|
|
26470
|
+
return;
|
|
26471
|
+
if (['onDeclined', 'onCanceled', 'onUnfollowed', 'onDeleted'].includes(action)) {
|
|
26472
|
+
collection.data = collection.data.filter(p => p !== getResolver('follow')(followStatus));
|
|
26473
|
+
}
|
|
26474
|
+
else if (['onRequested', 'onAccepted', 'onFollowed'].includes(action)) {
|
|
26475
|
+
collection.data = [...new Set([getResolver('follow')(followStatus), ...collection.data])];
|
|
26476
|
+
}
|
|
26477
|
+
pushToCache(cacheKey, collection);
|
|
26478
|
+
responder(collection);
|
|
26479
|
+
};
|
|
26480
|
+
const onFetch = () => {
|
|
26481
|
+
var _a, _b, _c, _d, _e;
|
|
26482
|
+
const collection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26483
|
+
const followings = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26484
|
+
if (followings.length > 0 && !((_c = collection === null || collection === void 0 ? void 0 : collection.params) === null || _c === void 0 ? void 0 : _c.page))
|
|
26485
|
+
return;
|
|
26486
|
+
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 } }));
|
|
26487
|
+
runQuery(query, ({ data: result, error, loading, nextPage: page }) => {
|
|
26488
|
+
const data = {
|
|
26489
|
+
loading,
|
|
26490
|
+
error,
|
|
26491
|
+
params: { page },
|
|
26492
|
+
data: followings,
|
|
26493
|
+
};
|
|
26494
|
+
if (result) {
|
|
26495
|
+
data.data = [...new Set([...followings, ...result.map(getResolver('follow'))])];
|
|
26496
|
+
}
|
|
26497
|
+
pushToCache(cacheKey, data);
|
|
26498
|
+
responder(data);
|
|
26499
|
+
}, queryOptions(policy));
|
|
26500
|
+
};
|
|
26501
|
+
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')));
|
|
26502
|
+
onFetch();
|
|
26503
|
+
return () => {
|
|
26504
|
+
log(`liveFollowings(tmpid: ${timestamp}) > dispose`);
|
|
26505
|
+
disposers.forEach(fn => fn());
|
|
26506
|
+
};
|
|
26507
|
+
};
|
|
26508
|
+
|
|
25901
26509
|
/**
|
|
25902
26510
|
* ```js
|
|
25903
26511
|
* import { observePosts } from '@amityco/ts-sdk'
|
|
@@ -26006,7 +26614,7 @@ const observePost = (postId, callback, policy = 'cache_then_server') => {
|
|
|
26006
26614
|
const livePosts = (params, callback, config) => {
|
|
26007
26615
|
const { log, cache } = getActiveClient();
|
|
26008
26616
|
if (!cache) {
|
|
26009
|
-
console.log(
|
|
26617
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
26010
26618
|
}
|
|
26011
26619
|
const timestamp = Date.now();
|
|
26012
26620
|
log(`livePosts(tmpid: ${timestamp}) > listen`);
|
|
@@ -26845,7 +27453,15 @@ const createUserToken = async (apiKey, apiRegion, params) => {
|
|
|
26845
27453
|
};
|
|
26846
27454
|
|
|
26847
27455
|
exports.API_REGIONS = API_REGIONS;
|
|
27456
|
+
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
27457
|
+
exports.CommunityPostSettings = CommunityPostSettings;
|
|
27458
|
+
exports.ContentFeedType = ContentFeedType;
|
|
27459
|
+
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
27460
|
+
exports.FileType = FileType;
|
|
26848
27461
|
exports.VERSION = VERSION$1;
|
|
27462
|
+
exports.VideoResolution = VideoResolution;
|
|
27463
|
+
exports.VideoSize = VideoSize;
|
|
27464
|
+
exports.VideoTranscodingStatus = VideoTranscodingStatus;
|
|
26849
27465
|
exports.acceptFollower = acceptFollower;
|
|
26850
27466
|
exports.addChannelMembers = addChannelMembers;
|
|
26851
27467
|
exports.addChannelMembersRole = addChannelMembersRole;
|
|
@@ -26900,6 +27516,7 @@ exports.getComments = getComments;
|
|
|
26900
27516
|
exports.getCommunities = getCommunities;
|
|
26901
27517
|
exports.getCommunity = getCommunity;
|
|
26902
27518
|
exports.getCommunityTopic = getCommunityTopic;
|
|
27519
|
+
exports.getFeedSettings = getFeedSettings;
|
|
26903
27520
|
exports.getFile = getFile;
|
|
26904
27521
|
exports.getFollowInfo = getFollowInfo;
|
|
26905
27522
|
exports.getMessage = getMessage;
|
|
@@ -26934,11 +27551,16 @@ exports.joinChannel = joinChannel;
|
|
|
26934
27551
|
exports.joinCommunity = joinCommunity;
|
|
26935
27552
|
exports.leaveChannel = leaveChannel;
|
|
26936
27553
|
exports.leaveCommunity = leaveCommunity;
|
|
27554
|
+
exports.liveChannels = liveChannels;
|
|
26937
27555
|
exports.liveComments = liveComments;
|
|
27556
|
+
exports.liveFollowers = liveFollowers;
|
|
27557
|
+
exports.liveFollowings = liveFollowings;
|
|
27558
|
+
exports.liveMessages = liveMessages;
|
|
26938
27559
|
exports.livePosts = livePosts;
|
|
26939
27560
|
exports.liveReactions = liveReactions;
|
|
26940
27561
|
exports.mergeInCache = mergeInCache;
|
|
26941
27562
|
exports.observeChannel = observeChannel;
|
|
27563
|
+
exports.observeChannels = observeChannels;
|
|
26942
27564
|
exports.observeComment = observeComment;
|
|
26943
27565
|
exports.observeComments = observeComments;
|
|
26944
27566
|
exports.observeCommunity = observeCommunity;
|
|
@@ -26952,6 +27574,7 @@ exports.observePoll = observePoll;
|
|
|
26952
27574
|
exports.observePost = observePost;
|
|
26953
27575
|
exports.observePosts = observePosts;
|
|
26954
27576
|
exports.observeUser = observeUser;
|
|
27577
|
+
exports.onChannelCreated = onChannelCreated;
|
|
26955
27578
|
exports.onChannelDeleted = onChannelDeleted;
|
|
26956
27579
|
exports.onChannelJoined = onChannelJoined;
|
|
26957
27580
|
exports.onChannelLeft = onChannelLeft;
|