@amityco/ts-sdk 7.22.0 → 7.22.1-002438d.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/errors.d.ts +2 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +7 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +3 -2
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/block.d.ts +5 -0
- package/dist/@types/domains/block.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +20 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +25 -2
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +14 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +16 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/notificationSettings.d.ts +101 -0
- package/dist/@types/domains/notificationSettings.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/sharableContentType.d.ts +9 -0
- package/dist/@types/domains/sharableContentType.d.ts.map +1 -0
- package/dist/@types/index.d.ts +3 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +2 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsService.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsService.d.ts.map +1 -1
- package/dist/channelRepository/api/archiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/archiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts +13 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts.map +1 -0
- package/dist/channelRepository/api/index.d.ts +3 -0
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/api/unarchiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/unarchiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/updateChannel.d.ts +1 -1
- package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/banMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/muteMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unmuteMembers.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +2 -0
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelArchived.d.ts +10 -0
- package/dist/channelRepository/events/onChannelArchived.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelUnarchived.d.ts +11 -0
- package/dist/channelRepository/events/onChannelUnarchived.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts +12 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts +11 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts +13 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts +20 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts +2 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/autoSubscription.d.ts +47 -0
- package/dist/client/api/autoSubscription.d.ts.map +1 -0
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getCoreUserSettings.d.ts +16 -0
- package/dist/client/api/getCoreUserSettings.d.ts.map +1 -0
- package/dist/client/api/getShareableLinkConfiguration.d.ts +2 -2
- package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +4 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/notifications.d.ts +27 -0
- package/dist/client/api/notifications.d.ts.map +1 -0
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/client/api/tests/ShareableLinkConfiguration.test.d.ts +2 -0
- package/dist/client/api/tests/ShareableLinkConfiguration.test.d.ts.map +1 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts +2 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts.map +1 -0
- package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/autoSubscriptionManager.d.ts +21 -0
- package/dist/client/utils/autoSubscriptionManager.d.ts.map +1 -0
- package/dist/client/utils/subscribeGlobalTopic.d.ts +6 -1
- package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts +2 -0
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.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/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +32 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +1 -0
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +3 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts +13 -0
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts.map +1 -0
- package/dist/feedRepository/index.d.ts +2 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts +17 -0
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts +12 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts +19 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +1 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts.map +1 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts.map +1 -0
- package/dist/index.cjs.js +2149 -355
- package/dist/index.esm.js +2146 -356
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/updateChannelMessagePreviewCache.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +1 -0
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts +12 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts +10 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts +8 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts +2 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts +24 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts +2 -0
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts +2 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/setup.d.ts +6 -0
- package/dist/postRepository/tests/integration/setup.d.ts.map +1 -0
- package/dist/reactionRepository/internalApi/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/internalApi/removeReaction.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +1 -1
- package/dist/userRepository/api/getAllBlockedUsers.d.ts.map +1 -1
- package/dist/userRepository/api/getAllBlockingUsers.d.ts +20 -0
- package/dist/userRepository/api/getAllBlockingUsers.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +1 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/tests/integration/getAllBlockingUsers.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/getAllBlockingUsers.integration.test.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +4 -3
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts +13 -0
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers/PaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getBlockingUsers/PaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers/QueryStreamController.d.ts +16 -0
- package/dist/userRepository/observers/getBlockingUsers/QueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers.d.ts +17 -0
- package/dist/userRepository/observers/getBlockingUsers.d.ts.map +1 -0
- package/dist/userRepository/observers/index.d.ts +1 -0
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/observers/tests/integrations/getBlockingUsers.integration.test.d.ts +2 -0
- package/dist/userRepository/observers/tests/integrations/getBlockingUsers.integration.test.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/enum/index.d.ts +5 -0
- package/dist/userRepository/relationship/block/enum/index.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/index.d.ts +3 -0
- package/dist/userRepository/relationship/block/events/index.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/onUserDidBlock.d.ts +20 -0
- package/dist/userRepository/relationship/block/events/onUserDidBlock.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/onUserDidUnblock.d.ts +20 -0
- package/dist/userRepository/relationship/block/events/onUserDidUnblock.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/index.d.ts +1 -0
- package/dist/userRepository/relationship/block/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/utils/blockRealtimeOnLoginHandler.d.ts +12 -0
- package/dist/userRepository/relationship/block/utils/blockRealtimeOnLoginHandler.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/utils/createBlockEventSubscriber.d.ts +11 -0
- package/dist/userRepository/relationship/block/utils/createBlockEventSubscriber.d.ts.map +1 -0
- package/dist/userRepository/services/BlockedUserSyncEngine/blockedUserSyncEngine.d.ts +13 -13
- package/dist/userRepository/services/BlockedUserSyncEngine/blockedUserSyncEngine.d.ts.map +1 -1
- package/dist/userRepository/services/BlockingUserSyncEngine/blockingUserSyncEngine.d.ts +56 -0
- package/dist/userRepository/services/BlockingUserSyncEngine/blockingUserSyncEngine.d.ts.map +1 -0
- package/dist/userRepository/services/BlockingUserSyncEngine/blockingUserSyncEngineOnLoginHandler.d.ts +3 -0
- package/dist/userRepository/services/BlockingUserSyncEngine/blockingUserSyncEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareBlockingUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareBlockingUserPayload.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/block.d.ts +16 -0
- package/dist/utils/tests/dummy/block.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -28,6 +28,13 @@ exports.MembershipAcceptanceTypeEnum = void 0;
|
|
|
28
28
|
MembershipAcceptanceTypeEnum["AUTOMATIC"] = "automatic";
|
|
29
29
|
MembershipAcceptanceTypeEnum["INVITATION"] = "invitation";
|
|
30
30
|
})(exports.MembershipAcceptanceTypeEnum || (exports.MembershipAcceptanceTypeEnum = {}));
|
|
31
|
+
exports.AmityAutoSubscription = void 0;
|
|
32
|
+
(function (AmityAutoSubscription) {
|
|
33
|
+
AmityAutoSubscription["CHAT"] = "chat";
|
|
34
|
+
AmityAutoSubscription["NETWORK"] = "network";
|
|
35
|
+
AmityAutoSubscription["LIVESTREAM"] = "livestream";
|
|
36
|
+
AmityAutoSubscription["BLOCK"] = "block";
|
|
37
|
+
})(exports.AmityAutoSubscription || (exports.AmityAutoSubscription = {}));
|
|
31
38
|
|
|
32
39
|
exports.UserTypeEnum = void 0;
|
|
33
40
|
(function (UserTypeEnum) {
|
|
@@ -74,6 +81,13 @@ exports.FileAccessTypeEnum = void 0;
|
|
|
74
81
|
FileAccessTypeEnum["NETWORK"] = "network";
|
|
75
82
|
})(exports.FileAccessTypeEnum || (exports.FileAccessTypeEnum = {}));
|
|
76
83
|
|
|
84
|
+
exports.AmityChannelNotificationModeEnum = void 0;
|
|
85
|
+
(function (AmityChannelNotificationModeEnum) {
|
|
86
|
+
AmityChannelNotificationModeEnum["Default"] = "default";
|
|
87
|
+
AmityChannelNotificationModeEnum["Silent"] = "silent";
|
|
88
|
+
AmityChannelNotificationModeEnum["Subscribe"] = "subscribe";
|
|
89
|
+
})(exports.AmityChannelNotificationModeEnum || (exports.AmityChannelNotificationModeEnum = {}));
|
|
90
|
+
|
|
77
91
|
const CommunityPostSettings = Object.freeze({
|
|
78
92
|
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
79
93
|
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
@@ -249,12 +263,54 @@ exports.AmityEventOrderOption = void 0;
|
|
|
249
263
|
AmityEventOrderOption["Descending"] = "desc";
|
|
250
264
|
})(exports.AmityEventOrderOption || (exports.AmityEventOrderOption = {}));
|
|
251
265
|
|
|
266
|
+
exports.AmitySharableContentType = void 0;
|
|
267
|
+
(function (AmitySharableContentType) {
|
|
268
|
+
AmitySharableContentType["POST"] = "post";
|
|
269
|
+
AmitySharableContentType["COMMUNITY"] = "community";
|
|
270
|
+
AmitySharableContentType["USER"] = "user";
|
|
271
|
+
AmitySharableContentType["LIVESTREAM"] = "livestream";
|
|
272
|
+
AmitySharableContentType["EVENT"] = "event";
|
|
273
|
+
})(exports.AmitySharableContentType || (exports.AmitySharableContentType = {}));
|
|
274
|
+
|
|
252
275
|
exports.AnalyticsSourceTypeEnum = void 0;
|
|
253
276
|
(function (AnalyticsSourceTypeEnum) {
|
|
254
277
|
AnalyticsSourceTypeEnum["POST"] = "post";
|
|
255
278
|
AnalyticsSourceTypeEnum["ROOM"] = "room";
|
|
256
279
|
})(exports.AnalyticsSourceTypeEnum || (exports.AnalyticsSourceTypeEnum = {}));
|
|
257
280
|
|
|
281
|
+
exports.UserNotificationModuleNameEnum = void 0;
|
|
282
|
+
(function (UserNotificationModuleNameEnum) {
|
|
283
|
+
UserNotificationModuleNameEnum["CHAT"] = "chat";
|
|
284
|
+
UserNotificationModuleNameEnum["SOCIAL"] = "social";
|
|
285
|
+
UserNotificationModuleNameEnum["VIDEO_STREAMING"] = "video-streaming";
|
|
286
|
+
})(exports.UserNotificationModuleNameEnum || (exports.UserNotificationModuleNameEnum = {}));
|
|
287
|
+
exports.CommunityNotificationEventNameEnum = void 0;
|
|
288
|
+
(function (CommunityNotificationEventNameEnum) {
|
|
289
|
+
CommunityNotificationEventNameEnum["POST_CREATED"] = "post.created";
|
|
290
|
+
CommunityNotificationEventNameEnum["POST_REACTED"] = "post.reacted";
|
|
291
|
+
CommunityNotificationEventNameEnum["COMMENT_CREATED"] = "comment.created";
|
|
292
|
+
CommunityNotificationEventNameEnum["COMMENT_REPLIED"] = "comment.replied";
|
|
293
|
+
CommunityNotificationEventNameEnum["COMMENT_REACTED"] = "comment.reacted";
|
|
294
|
+
CommunityNotificationEventNameEnum["STORY_CREATED"] = "story.created";
|
|
295
|
+
CommunityNotificationEventNameEnum["STORY_REACTED"] = "story.reacted";
|
|
296
|
+
CommunityNotificationEventNameEnum["STORY_COMMENT_CREATED"] = "story-comment.created";
|
|
297
|
+
CommunityNotificationEventNameEnum["LIVESTREAM_START"] = "video-streaming.didStart";
|
|
298
|
+
})(exports.CommunityNotificationEventNameEnum || (exports.CommunityNotificationEventNameEnum = {}));
|
|
299
|
+
exports.NotificationSettingsLevelEnum = void 0;
|
|
300
|
+
(function (NotificationSettingsLevelEnum) {
|
|
301
|
+
NotificationSettingsLevelEnum["USER"] = "user";
|
|
302
|
+
NotificationSettingsLevelEnum["COMMUNITY"] = "community";
|
|
303
|
+
NotificationSettingsLevelEnum["CHANNEL"] = "channel";
|
|
304
|
+
})(exports.NotificationSettingsLevelEnum || (exports.NotificationSettingsLevelEnum = {}));
|
|
305
|
+
/**
|
|
306
|
+
* `NOT` variant is intentionally excluded from public API (internal server-side use only).
|
|
307
|
+
*/
|
|
308
|
+
exports.NotificationRolesFilterTypeEnum = void 0;
|
|
309
|
+
(function (NotificationRolesFilterTypeEnum) {
|
|
310
|
+
NotificationRolesFilterTypeEnum["ALL"] = "all";
|
|
311
|
+
NotificationRolesFilterTypeEnum["ONLY"] = "only";
|
|
312
|
+
})(exports.NotificationRolesFilterTypeEnum || (exports.NotificationRolesFilterTypeEnum = {}));
|
|
313
|
+
|
|
258
314
|
function getVersion() {
|
|
259
315
|
try {
|
|
260
316
|
// the string ''v7.22.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -267,6 +323,7 @@ function getVersion() {
|
|
|
267
323
|
const VERSION = getVersion();
|
|
268
324
|
|
|
269
325
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
326
|
+
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
270
327
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
271
328
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
272
329
|
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
@@ -279,6 +336,9 @@ const DAY = 24 * HOUR;
|
|
|
279
336
|
const WEEK = 7 * DAY;
|
|
280
337
|
const YEAR = 365 * DAY;
|
|
281
338
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
339
|
+
const API_ENDPOINTS = {
|
|
340
|
+
forYouFeed: '/api/v1/feeds/for-you',
|
|
341
|
+
};
|
|
282
342
|
|
|
283
343
|
// cache constants
|
|
284
344
|
const CACHE_KEY_GET = 'get';
|
|
@@ -659,6 +719,95 @@ function createSnapshot(data, options) {
|
|
|
659
719
|
return Object.assign(Object.assign({}, options), { data });
|
|
660
720
|
}
|
|
661
721
|
|
|
722
|
+
/* eslint-disable max-classes-per-file */
|
|
723
|
+
/**
|
|
724
|
+
* Generic ASC error
|
|
725
|
+
* @category Errors
|
|
726
|
+
*/
|
|
727
|
+
class ASCError extends Error {
|
|
728
|
+
/**
|
|
729
|
+
* @param message A custom error message
|
|
730
|
+
* @param code A normalized error code
|
|
731
|
+
* @param level A normalized failure level descriptor
|
|
732
|
+
*/
|
|
733
|
+
constructor(message, code, level) {
|
|
734
|
+
super(`Amity SDK (${code}): ${message}`);
|
|
735
|
+
this.code = code;
|
|
736
|
+
this.level = level;
|
|
737
|
+
this.type = 'ASC';
|
|
738
|
+
this.timestamp = Date.now();
|
|
739
|
+
if (Error.captureStackTrace)
|
|
740
|
+
Error.captureStackTrace(this, ASCError);
|
|
741
|
+
}
|
|
742
|
+
}
|
|
743
|
+
/**
|
|
744
|
+
* API level error
|
|
745
|
+
* @category Errors
|
|
746
|
+
*/
|
|
747
|
+
class ASCApiError extends ASCError {
|
|
748
|
+
/**
|
|
749
|
+
* @param code A normalized error code
|
|
750
|
+
* @param level A normalized failure level descriptor
|
|
751
|
+
*/
|
|
752
|
+
// eslint-disable-next-line no-useless-constructor
|
|
753
|
+
constructor(message, code, level) {
|
|
754
|
+
super(message, code, level);
|
|
755
|
+
}
|
|
756
|
+
}
|
|
757
|
+
/**
|
|
758
|
+
* Unexpected error
|
|
759
|
+
* @category Errors
|
|
760
|
+
*/
|
|
761
|
+
class ASCUnknownError extends ASCError {
|
|
762
|
+
/**
|
|
763
|
+
* @param code A normalized error code
|
|
764
|
+
* @param level A normalized failure level descriptor
|
|
765
|
+
*/
|
|
766
|
+
constructor(code = 800000 /* Amity.ClientError.UNKNOWN_ERROR */, level = "fatal" /* Amity.ErrorLevel.FATAL */) {
|
|
767
|
+
super('Unexpected error', code, level);
|
|
768
|
+
}
|
|
769
|
+
}
|
|
770
|
+
/**
|
|
771
|
+
* Network related error
|
|
772
|
+
* @category Errors
|
|
773
|
+
*/
|
|
774
|
+
class ASCConnectionError extends ASCError {
|
|
775
|
+
/**
|
|
776
|
+
* @param message A custom error message
|
|
777
|
+
*/
|
|
778
|
+
constructor(event, message = 'SDK client is having connection issues') {
|
|
779
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
780
|
+
? 800211 /* Amity.ClientError.DISCONNECTED */
|
|
781
|
+
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
782
|
+
this.event = event;
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
let activeClient = null;
|
|
787
|
+
/**
|
|
788
|
+
* Get the active client
|
|
789
|
+
*
|
|
790
|
+
* @returns the active client instance
|
|
791
|
+
*
|
|
792
|
+
* @hidden
|
|
793
|
+
*/
|
|
794
|
+
const getActiveClient = () => {
|
|
795
|
+
if (!activeClient) {
|
|
796
|
+
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
797
|
+
}
|
|
798
|
+
return activeClient;
|
|
799
|
+
};
|
|
800
|
+
/**
|
|
801
|
+
* Sets the active client
|
|
802
|
+
*
|
|
803
|
+
* @param client the client to assume as currently active client
|
|
804
|
+
*
|
|
805
|
+
* @hidden
|
|
806
|
+
*/
|
|
807
|
+
const setActiveClient = (client) => {
|
|
808
|
+
activeClient = client;
|
|
809
|
+
};
|
|
810
|
+
|
|
662
811
|
/** @hidden */
|
|
663
812
|
const idResolvers = {
|
|
664
813
|
user: ({ userId }) => userId,
|
|
@@ -667,6 +816,7 @@ const idResolvers = {
|
|
|
667
816
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
668
817
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
669
818
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
819
|
+
archivedChannel: ({ channelId }) => channelId,
|
|
670
820
|
message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
|
|
671
821
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
672
822
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
@@ -708,6 +858,7 @@ const idResolvers = {
|
|
|
708
858
|
event: ({ eventId }) => eventId,
|
|
709
859
|
eventResponse: ({ userId }) => userId,
|
|
710
860
|
product: ({ productId }) => productId,
|
|
861
|
+
feedMetadata: ({ postId }) => postId,
|
|
711
862
|
};
|
|
712
863
|
/**
|
|
713
864
|
* Retrieve the id resolver matching a domain name
|
|
@@ -730,6 +881,7 @@ const PAYLOAD2MODEL = {
|
|
|
730
881
|
channels: 'channel',
|
|
731
882
|
messageFeeds: 'subChannel',
|
|
732
883
|
channelUsers: 'channelUsers',
|
|
884
|
+
archives: 'archivedChannel',
|
|
733
885
|
messages: 'message',
|
|
734
886
|
messagePreviewChannel: 'messagePreviewChannel',
|
|
735
887
|
messagePreviewSubChannel: 'messagePreviewSubChannel',
|
|
@@ -768,6 +920,7 @@ const PAYLOAD2MODEL = {
|
|
|
768
920
|
viewers: 'viewer',
|
|
769
921
|
eventResponses: 'eventResponse',
|
|
770
922
|
products: 'product',
|
|
923
|
+
feedMetadata: 'feedMetadata',
|
|
771
924
|
};
|
|
772
925
|
/** hidden */
|
|
773
926
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -782,95 +935,6 @@ function getFutureDate(date = new Date().toISOString()) {
|
|
|
782
935
|
return new Date(new Date(date).getTime() + 1).toISOString();
|
|
783
936
|
}
|
|
784
937
|
|
|
785
|
-
/* eslint-disable max-classes-per-file */
|
|
786
|
-
/**
|
|
787
|
-
* Generic ASC error
|
|
788
|
-
* @category Errors
|
|
789
|
-
*/
|
|
790
|
-
class ASCError extends Error {
|
|
791
|
-
/**
|
|
792
|
-
* @param message A custom error message
|
|
793
|
-
* @param code A normalized error code
|
|
794
|
-
* @param level A normalized failure level descriptor
|
|
795
|
-
*/
|
|
796
|
-
constructor(message, code, level) {
|
|
797
|
-
super(`Amity SDK (${code}): ${message}`);
|
|
798
|
-
this.code = code;
|
|
799
|
-
this.level = level;
|
|
800
|
-
this.type = 'ASC';
|
|
801
|
-
this.timestamp = Date.now();
|
|
802
|
-
if (Error.captureStackTrace)
|
|
803
|
-
Error.captureStackTrace(this, ASCError);
|
|
804
|
-
}
|
|
805
|
-
}
|
|
806
|
-
/**
|
|
807
|
-
* API level error
|
|
808
|
-
* @category Errors
|
|
809
|
-
*/
|
|
810
|
-
class ASCApiError extends ASCError {
|
|
811
|
-
/**
|
|
812
|
-
* @param code A normalized error code
|
|
813
|
-
* @param level A normalized failure level descriptor
|
|
814
|
-
*/
|
|
815
|
-
// eslint-disable-next-line no-useless-constructor
|
|
816
|
-
constructor(message, code, level) {
|
|
817
|
-
super(message, code, level);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
/**
|
|
821
|
-
* Unexpected error
|
|
822
|
-
* @category Errors
|
|
823
|
-
*/
|
|
824
|
-
class ASCUnknownError extends ASCError {
|
|
825
|
-
/**
|
|
826
|
-
* @param code A normalized error code
|
|
827
|
-
* @param level A normalized failure level descriptor
|
|
828
|
-
*/
|
|
829
|
-
constructor(code = 800000 /* Amity.ClientError.UNKNOWN_ERROR */, level = "fatal" /* Amity.ErrorLevel.FATAL */) {
|
|
830
|
-
super('Unexpected error', code, level);
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
/**
|
|
834
|
-
* Network related error
|
|
835
|
-
* @category Errors
|
|
836
|
-
*/
|
|
837
|
-
class ASCConnectionError extends ASCError {
|
|
838
|
-
/**
|
|
839
|
-
* @param message A custom error message
|
|
840
|
-
*/
|
|
841
|
-
constructor(event, message = 'SDK client is having connection issues') {
|
|
842
|
-
super(`${message} (${event})`, event === 'disconnected'
|
|
843
|
-
? 800211 /* Amity.ClientError.DISCONNECTED */
|
|
844
|
-
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
845
|
-
this.event = event;
|
|
846
|
-
}
|
|
847
|
-
}
|
|
848
|
-
|
|
849
|
-
let activeClient = null;
|
|
850
|
-
/**
|
|
851
|
-
* Get the active client
|
|
852
|
-
*
|
|
853
|
-
* @returns the active client instance
|
|
854
|
-
*
|
|
855
|
-
* @hidden
|
|
856
|
-
*/
|
|
857
|
-
const getActiveClient = () => {
|
|
858
|
-
if (!activeClient) {
|
|
859
|
-
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
860
|
-
}
|
|
861
|
-
return activeClient;
|
|
862
|
-
};
|
|
863
|
-
/**
|
|
864
|
-
* Sets the active client
|
|
865
|
-
*
|
|
866
|
-
* @param client the client to assume as currently active client
|
|
867
|
-
*
|
|
868
|
-
* @hidden
|
|
869
|
-
*/
|
|
870
|
-
const setActiveClient = (client) => {
|
|
871
|
-
activeClient = client;
|
|
872
|
-
};
|
|
873
|
-
|
|
874
938
|
/**
|
|
875
939
|
* ```js
|
|
876
940
|
* import { enableCache } from '@amityco/ts-sdk'
|
|
@@ -1378,6 +1442,65 @@ const filterBySearchTerm = (collection, searchTerm) => {
|
|
|
1378
1442
|
return m.user && ((_a = m.user.displayName) === null || _a === void 0 ? void 0 : _a.match(containsMatcher));
|
|
1379
1443
|
});
|
|
1380
1444
|
};
|
|
1445
|
+
/**
|
|
1446
|
+
* The ids of users in a block relationship with the current user — in BOTH
|
|
1447
|
+
* directions — derived synchronously from the local follow cache. For every
|
|
1448
|
+
* `status === 'blocked'` row that involves the current user, the OTHER party
|
|
1449
|
+
* is collected: `from === me` (users I blocked, outgoing) contributes `to`;
|
|
1450
|
+
* `to === me` (users who blocked me, incoming) contributes `from`.
|
|
1451
|
+
*
|
|
1452
|
+
* @returns a set of block-related user ids (both directions)
|
|
1453
|
+
*
|
|
1454
|
+
* @hidden
|
|
1455
|
+
*/
|
|
1456
|
+
const getBlockUsersId = () => {
|
|
1457
|
+
var _a;
|
|
1458
|
+
const { userId } = getActiveClient();
|
|
1459
|
+
const ids = new Set();
|
|
1460
|
+
((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
1461
|
+
.map(entry => entry.data)
|
|
1462
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && (follow.from === userId || follow.to === userId))
|
|
1463
|
+
.forEach(follow => {
|
|
1464
|
+
ids.add(follow.from === userId ? follow.to : follow.from);
|
|
1465
|
+
});
|
|
1466
|
+
return ids;
|
|
1467
|
+
};
|
|
1468
|
+
/**
|
|
1469
|
+
* Filter out posts whose author or any mentionee is in a block relationship
|
|
1470
|
+
* with the current user, in either direction (see {@link getBlockUsersId}).
|
|
1471
|
+
*
|
|
1472
|
+
* @param collection the post collection to filter
|
|
1473
|
+
* @returns a filtered collection excluding posts involving block-related users
|
|
1474
|
+
*
|
|
1475
|
+
* @hidden
|
|
1476
|
+
*/
|
|
1477
|
+
const filterPostsByBlockUsers = (collection) => {
|
|
1478
|
+
const blockUsersId = getBlockUsersId();
|
|
1479
|
+
if (blockUsersId.size === 0)
|
|
1480
|
+
return collection;
|
|
1481
|
+
return collection.filter(post => {
|
|
1482
|
+
var _a, _b;
|
|
1483
|
+
if (blockUsersId.has(post.postedUserId))
|
|
1484
|
+
return false;
|
|
1485
|
+
const mentionedUserIds = (_b = (_a = post.mentionees) === null || _a === void 0 ? void 0 : _a.flatMap(mention => (mention.type === 'user' ? mention.userIds : []))) !== null && _b !== void 0 ? _b : [];
|
|
1486
|
+
return !mentionedUserIds.some(id => blockUsersId.has(id));
|
|
1487
|
+
});
|
|
1488
|
+
};
|
|
1489
|
+
/**
|
|
1490
|
+
* Filter out comments whose creator is in a block relationship with the
|
|
1491
|
+
* current user, in either direction (see {@link getBlockUsersId}).
|
|
1492
|
+
*
|
|
1493
|
+
* @param collection the comment collection to filter
|
|
1494
|
+
* @returns a filtered collection excluding comments from block-related users
|
|
1495
|
+
*
|
|
1496
|
+
* @hidden
|
|
1497
|
+
*/
|
|
1498
|
+
const filterCommentsByBlockUsers = (collection) => {
|
|
1499
|
+
const blockUsersId = getBlockUsersId();
|
|
1500
|
+
if (blockUsersId.size === 0)
|
|
1501
|
+
return collection;
|
|
1502
|
+
return collection.filter(comment => !blockUsersId.has(comment.userId));
|
|
1503
|
+
};
|
|
1381
1504
|
|
|
1382
1505
|
// Note:
|
|
1383
1506
|
// this file should contain a suite of sorting utilities to help the
|
|
@@ -1848,13 +1971,13 @@ class NetworkActivitiesWatcher {
|
|
|
1848
1971
|
this._listener.clear();
|
|
1849
1972
|
}
|
|
1850
1973
|
}
|
|
1851
|
-
let instance$
|
|
1974
|
+
let instance$b;
|
|
1852
1975
|
var NetworkActivitiesWatcher$1 = {
|
|
1853
1976
|
getInstance: () => {
|
|
1854
|
-
if (!instance$
|
|
1855
|
-
instance$
|
|
1977
|
+
if (!instance$b) {
|
|
1978
|
+
instance$b = new NetworkActivitiesWatcher();
|
|
1856
1979
|
}
|
|
1857
|
-
return instance$
|
|
1980
|
+
return instance$b;
|
|
1858
1981
|
},
|
|
1859
1982
|
};
|
|
1860
1983
|
|
|
@@ -4602,18 +4725,149 @@ walker=walker.next;}if(i===n&&walker!==null){return walker.value;}};Yallist.prot
|
|
|
4602
4725
|
walker=walker.prev;}if(i===n&&walker!==null){return walker.value;}};Yallist.prototype.map=function(fn,thisp){thisp=thisp||this;var res=new Yallist();for(var walker=this.head;walker!==null;){res.push(fn.call(thisp,walker.value,this));walker=walker.next;}return res;};Yallist.prototype.mapReverse=function(fn,thisp){thisp=thisp||this;var res=new Yallist();for(var walker=this.tail;walker!==null;){res.push(fn.call(thisp,walker.value,this));walker=walker.prev;}return res;};Yallist.prototype.reduce=function(fn,initial){var acc;var walker=this.head;if(arguments.length>1){acc=initial;}else if(this.head){walker=this.head.next;acc=this.head.value;}else {throw new TypeError('Reduce of empty list with no initial value');}for(var i=0;walker!==null;i++){acc=fn(acc,walker.value,i);walker=walker.next;}return acc;};Yallist.prototype.reduceReverse=function(fn,initial){var acc;var walker=this.tail;if(arguments.length>1){acc=initial;}else if(this.tail){walker=this.tail.prev;acc=this.tail.value;}else {throw new TypeError('Reduce of empty list with no initial value');}for(var i=this.length-1;walker!==null;i--){acc=fn(acc,walker.value,i);walker=walker.prev;}return acc;};Yallist.prototype.toArray=function(){var arr=new Array(this.length);for(var i=0,walker=this.head;walker!==null;i++){arr[i]=walker.value;walker=walker.next;}return arr;};Yallist.prototype.toArrayReverse=function(){var arr=new Array(this.length);for(var i=0,walker=this.tail;walker!==null;i++){arr[i]=walker.value;walker=walker.prev;}return arr;};Yallist.prototype.slice=function(from,to){to=to||this.length;if(to<0){to+=this.length;}from=from||0;if(from<0){from+=this.length;}var ret=new Yallist();if(to<from||to<0){return ret;}if(from<0){from=0;}if(to>this.length){to=this.length;}for(var i=0,walker=this.head;walker!==null&&i<from;i++){walker=walker.next;}for(;walker!==null&&i<to;i++,walker=walker.next){ret.push(walker.value);}return ret;};Yallist.prototype.sliceReverse=function(from,to){to=to||this.length;if(to<0){to+=this.length;}from=from||0;if(from<0){from+=this.length;}var ret=new Yallist();if(to<from||to<0){return ret;}if(from<0){from=0;}if(to>this.length){to=this.length;}for(var i=this.length,walker=this.tail;walker!==null&&i>to;i--){walker=walker.prev;}for(;walker!==null&&i>from;i--,walker=walker.prev){ret.push(walker.value);}return ret;};Yallist.prototype.splice=function(start,deleteCount){if(start>this.length){start=this.length-1;}if(start<0){start=this.length+start;}for(var i=0,walker=this.head;walker!==null&&i<start;i++){walker=walker.next;}var ret=[];for(var i=0;walker&&i<deleteCount;i++){ret.push(walker.value);walker=this.removeNode(walker);}if(walker===null){walker=this.tail;}if(walker!==this.head&&walker!==this.tail){walker=walker.prev;}for(var i=0;i<(arguments.length<=2?0:arguments.length-2);i++){walker=insert(this,walker,i+2<2||arguments.length<=i+2?undefined:arguments[i+2]);}return ret;};Yallist.prototype.reverse=function(){var head=this.head;var tail=this.tail;for(var walker=head;walker!==null;walker=walker.prev){var p=walker.prev;walker.prev=walker.next;walker.next=p;}this.head=tail;this.tail=head;return this;};function insert(self,node,value){var inserted=node===self.head?new Node(value,null,node,self):new Node(value,node,node.next,self);if(inserted.next===null){self.tail=inserted;}if(inserted.prev===null){self.head=inserted;}self.length++;return inserted;}function push(self,item){self.tail=new Node(item,self.tail,null,self);if(!self.head){self.head=self.tail;}self.length++;}function unshift(self,item){self.head=new Node(item,null,self.head,self);if(!self.tail){self.tail=self.head;}self.length++;}function Node(value,prev,next,list){if(!(this instanceof Node)){return new Node(value,prev,next,list);}this.list=list;this.value=value;if(prev){prev.next=this;this.prev=prev;}else {this.prev=null;}if(next){next.prev=this;this.next=next;}else {this.next=null;}}try{// add if support for Symbol.iterator is present
|
|
4603
4726
|
require('./iterator.js')(Yallist);}catch(er){}},{"./iterator.js":82}]},{},[12])(12);});})(mqtt$1);var mqtt = /*@__PURE__*/getDefaultExportFromCjs(mqtt$1.exports);
|
|
4604
4727
|
|
|
4728
|
+
class SessionWatcher {
|
|
4729
|
+
constructor() {
|
|
4730
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
4731
|
+
this._listener = new Map();
|
|
4732
|
+
}
|
|
4733
|
+
onSessionStateChange(callback) {
|
|
4734
|
+
this._listener.set(callback, callback);
|
|
4735
|
+
return () => {
|
|
4736
|
+
this._listener.delete(callback);
|
|
4737
|
+
};
|
|
4738
|
+
}
|
|
4739
|
+
setSessionState(state, reason) {
|
|
4740
|
+
if (this._sessionState === state)
|
|
4741
|
+
return;
|
|
4742
|
+
this._sessionState = state;
|
|
4743
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
4744
|
+
}
|
|
4745
|
+
destroy() {
|
|
4746
|
+
this._listener.clear();
|
|
4747
|
+
}
|
|
4748
|
+
}
|
|
4749
|
+
let instance$a;
|
|
4750
|
+
var SessionWatcher$1 = {
|
|
4751
|
+
getInstance: () => {
|
|
4752
|
+
if (!instance$a) {
|
|
4753
|
+
instance$a = new SessionWatcher();
|
|
4754
|
+
}
|
|
4755
|
+
return instance$a;
|
|
4756
|
+
},
|
|
4757
|
+
};
|
|
4758
|
+
|
|
4759
|
+
/**
|
|
4760
|
+
* ```js
|
|
4761
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
4762
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
4763
|
+
* // ...
|
|
4764
|
+
* })
|
|
4765
|
+
* ```
|
|
4766
|
+
*
|
|
4767
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
4768
|
+
*
|
|
4769
|
+
* @param callback The function to call when the event was fired
|
|
4770
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
4771
|
+
*
|
|
4772
|
+
* @category Client Events
|
|
4773
|
+
*/
|
|
4774
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
4775
|
+
|
|
4776
|
+
const TOPICS = {
|
|
4777
|
+
[exports.AmityAutoSubscription.NETWORK]: [getNetworkTopic],
|
|
4778
|
+
[exports.AmityAutoSubscription.CHAT]: [
|
|
4779
|
+
getSmartFeedChannelTopic,
|
|
4780
|
+
getSmartFeedSubChannelTopic,
|
|
4781
|
+
getSmartFeedMessageTopic,
|
|
4782
|
+
],
|
|
4783
|
+
[exports.AmityAutoSubscription.LIVESTREAM]: [getLiveStreamTopic],
|
|
4784
|
+
[exports.AmityAutoSubscription.BLOCK]: [getMyFollowersTopic, getMyFollowingsTopic],
|
|
4785
|
+
};
|
|
4786
|
+
const DEFAULT_TOPICS = [
|
|
4787
|
+
exports.AmityAutoSubscription.CHAT,
|
|
4788
|
+
exports.AmityAutoSubscription.NETWORK,
|
|
4789
|
+
exports.AmityAutoSubscription.LIVESTREAM,
|
|
4790
|
+
exports.AmityAutoSubscription.BLOCK,
|
|
4791
|
+
];
|
|
4792
|
+
const ALL_FEATURES = Object.values(exports.AmityAutoSubscription);
|
|
4793
|
+
/** Ref-counted, reconnect-resilient registry of the managed auto-subscriptions. */
|
|
4794
|
+
class AutoSubscriptionManager {
|
|
4795
|
+
constructor() {
|
|
4796
|
+
this.refCountByFeature = new Map();
|
|
4797
|
+
this.disposers = new Map();
|
|
4798
|
+
this.seed();
|
|
4799
|
+
}
|
|
4800
|
+
seed() {
|
|
4801
|
+
this.refCountByFeature.clear();
|
|
4802
|
+
DEFAULT_TOPICS.forEach(feature => this.refCountByFeature.set(feature, 1));
|
|
4803
|
+
}
|
|
4804
|
+
isActive(feature) {
|
|
4805
|
+
var _a;
|
|
4806
|
+
return ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
4807
|
+
}
|
|
4808
|
+
subscribeTopics(feature) {
|
|
4809
|
+
this.unsubscribeTopics(feature);
|
|
4810
|
+
this.disposers.set(feature, TOPICS[feature].map(buildTopic => subscribeTopic(buildTopic())));
|
|
4811
|
+
}
|
|
4812
|
+
unsubscribeTopics(feature) {
|
|
4813
|
+
var _a;
|
|
4814
|
+
((_a = this.disposers.get(feature)) !== null && _a !== void 0 ? _a : []).forEach(dispose => dispose());
|
|
4815
|
+
this.disposers.delete(feature);
|
|
4816
|
+
}
|
|
4817
|
+
/** Subscribe every enabled handle's topics, converging the broker to the registry. Called on each (re)connect. */
|
|
4818
|
+
initialize() {
|
|
4819
|
+
ALL_FEATURES.forEach(feature => {
|
|
4820
|
+
if (this.isActive(feature))
|
|
4821
|
+
this.subscribeTopics(feature);
|
|
4822
|
+
});
|
|
4823
|
+
}
|
|
4824
|
+
subscribe(feature) {
|
|
4825
|
+
var _a;
|
|
4826
|
+
const next = ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
4827
|
+
this.refCountByFeature.set(feature, next);
|
|
4828
|
+
if (next === 1)
|
|
4829
|
+
this.subscribeTopics(feature);
|
|
4830
|
+
}
|
|
4831
|
+
unsubscribe(feature) {
|
|
4832
|
+
var _a;
|
|
4833
|
+
const next = Math.max(0, ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
4834
|
+
this.refCountByFeature.set(feature, next);
|
|
4835
|
+
if (next === 0)
|
|
4836
|
+
this.unsubscribeTopics(feature);
|
|
4837
|
+
}
|
|
4838
|
+
subscriptions() {
|
|
4839
|
+
return ALL_FEATURES.map(feature => ({
|
|
4840
|
+
feature,
|
|
4841
|
+
isActive: this.isActive(feature),
|
|
4842
|
+
isSystem: true,
|
|
4843
|
+
topicCount: TOPICS[feature].length,
|
|
4844
|
+
}));
|
|
4845
|
+
}
|
|
4846
|
+
reset() {
|
|
4847
|
+
ALL_FEATURES.forEach(feature => this.unsubscribeTopics(feature));
|
|
4848
|
+
this.disposers.clear();
|
|
4849
|
+
this.seed();
|
|
4850
|
+
}
|
|
4851
|
+
}
|
|
4852
|
+
let instance$9 = null;
|
|
4853
|
+
const getAutoSubscriptionManager = () => {
|
|
4854
|
+
if (!instance$9)
|
|
4855
|
+
instance$9 = new AutoSubscriptionManager();
|
|
4856
|
+
return instance$9;
|
|
4857
|
+
};
|
|
4858
|
+
/** Resets the registry to its default baseline when the session ends. */
|
|
4859
|
+
const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
|
|
4860
|
+
if (state !== "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
4861
|
+
getAutoSubscriptionManager().reset();
|
|
4862
|
+
});
|
|
4863
|
+
|
|
4864
|
+
/**
|
|
4865
|
+
* (Re)subscribes the managed auto-subscription registry on every (re)connect.
|
|
4866
|
+
* The hardcoded topic list was promoted to the toggleable, ref-counted registry
|
|
4867
|
+
* in {@link getAutoSubscriptionManager} — see `client.manageAutoSubscriptions`.
|
|
4868
|
+
*/
|
|
4605
4869
|
const subscribeGlobalTopic = () => {
|
|
4606
|
-
|
|
4607
|
-
subscribeTopic(getNetworkTopic()),
|
|
4608
|
-
subscribeTopic(getSmartFeedChannelTopic()),
|
|
4609
|
-
subscribeTopic(getSmartFeedSubChannelTopic()),
|
|
4610
|
-
subscribeTopic(getSmartFeedMessageTopic()),
|
|
4611
|
-
// subscribing to user topic is necessary to handle ban event
|
|
4612
|
-
subscribeTopic(getUserTopic(getActiveUser())),
|
|
4613
|
-
subscribeTopic(getMarkerUserFeedTopic()),
|
|
4614
|
-
subscribeTopic(getLiveStreamTopic()),
|
|
4615
|
-
];
|
|
4616
|
-
return () => disposers.forEach(fn => fn());
|
|
4870
|
+
getAutoSubscriptionManager().initialize();
|
|
4617
4871
|
};
|
|
4618
4872
|
|
|
4619
4873
|
class OnMemoryStorage {
|
|
@@ -5133,8 +5387,12 @@ const getChannelMessagePreviewWithUser = (channel) => {
|
|
|
5133
5387
|
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
5134
5388
|
};
|
|
5135
5389
|
|
|
5390
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
5391
|
+
return new Date(dateString).getTime();
|
|
5392
|
+
};
|
|
5393
|
+
|
|
5136
5394
|
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
5137
|
-
var _a
|
|
5395
|
+
var _a;
|
|
5138
5396
|
const withMessageFeedInfo = (messagePreview) => {
|
|
5139
5397
|
var _a;
|
|
5140
5398
|
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
@@ -5156,10 +5414,26 @@ const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
|
5156
5414
|
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
5157
5415
|
};
|
|
5158
5416
|
};
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5417
|
+
// Skip server previews older than what's cached — the cache may carry a newer
|
|
5418
|
+
// preview written by handleMessageCreated from an MQTT message that the server
|
|
5419
|
+
// payload hasn't surfaced yet. Mirrors isLastestMessageOnChannel.
|
|
5420
|
+
const newPreviews = ((_a = rawPayload.messagePreviews) !== null && _a !== void 0 ? _a : [])
|
|
5421
|
+
.map(withMessageFeedInfo)
|
|
5422
|
+
.filter(preview => {
|
|
5423
|
+
var _a;
|
|
5424
|
+
const cached = (_a = pullFromCache([
|
|
5425
|
+
'messagePreviewChannel',
|
|
5426
|
+
'get',
|
|
5427
|
+
preview.channelId,
|
|
5428
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5429
|
+
if (!cached)
|
|
5430
|
+
return true;
|
|
5431
|
+
return (convertDateStringToTimestamp(cached.createdAt) <=
|
|
5432
|
+
convertDateStringToTimestamp(preview.createdAt));
|
|
5433
|
+
});
|
|
5434
|
+
if (newPreviews.length === 0)
|
|
5435
|
+
return;
|
|
5436
|
+
ingestInCache({ messagePreviewChannel: newPreviews });
|
|
5163
5437
|
};
|
|
5164
5438
|
|
|
5165
5439
|
const getSubChannelMessagePreview = (subChannelId) => {
|
|
@@ -5787,10 +6061,6 @@ getSubChannel$1.locally = (subChannelId) => {
|
|
|
5787
6061
|
};
|
|
5788
6062
|
};
|
|
5789
6063
|
|
|
5790
|
-
const convertDateStringToTimestamp = (dateString) => {
|
|
5791
|
-
return new Date(dateString).getTime();
|
|
5792
|
-
};
|
|
5793
|
-
|
|
5794
6064
|
const getMessagePreviewSetting$1 = async () => {
|
|
5795
6065
|
const client = getActiveClient();
|
|
5796
6066
|
return client.getMessagePreviewSetting(false);
|
|
@@ -5998,24 +6268,41 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
5998
6268
|
});
|
|
5999
6269
|
};
|
|
6000
6270
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
6271
|
+
var _a, _b;
|
|
6001
6272
|
const channelsUnread = [];
|
|
6002
6273
|
for (let i = 0; i < channels.length; i += 1) {
|
|
6003
6274
|
if (isUnreadCountSupport(channels[i])) {
|
|
6004
6275
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
6005
6276
|
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
6006
|
-
|
|
6277
|
+
// readToSegment, lastMentionedSegment and lastSegment are monotonically non-decreasing;
|
|
6278
|
+
// prefer cached values when ahead of the server so a refetch returning stale data cannot
|
|
6279
|
+
const cached = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
6280
|
+
const lastSegment = Math.max((_b = cached === null || cached === void 0 ? void 0 : cached.lastSegment) !== null && _b !== void 0 ? _b : 0, channels[i].messageCount);
|
|
6007
6281
|
let readToSegment = null;
|
|
6008
6282
|
let lastMentionedSegment = null;
|
|
6283
|
+
let unreadCount = 0;
|
|
6009
6284
|
let isMentioned = false;
|
|
6010
6285
|
if (channelUser) {
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6286
|
+
const serverRead = channelUser.readToSegment;
|
|
6287
|
+
const serverMention = channelUser.lastMentionedSegment;
|
|
6288
|
+
readToSegment =
|
|
6289
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.readToSegment) === 'number' &&
|
|
6290
|
+
(typeof serverRead !== 'number' || cached.readToSegment > serverRead)
|
|
6291
|
+
? cached.readToSegment
|
|
6292
|
+
: serverRead !== null && serverRead !== void 0 ? serverRead : null;
|
|
6293
|
+
lastMentionedSegment =
|
|
6294
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.lastMentionedSegment) === 'number' &&
|
|
6295
|
+
(typeof serverMention !== 'number' || cached.lastMentionedSegment > serverMention)
|
|
6296
|
+
? cached.lastMentionedSegment
|
|
6297
|
+
: serverMention !== null && serverMention !== void 0 ? serverMention : null;
|
|
6298
|
+
const readForCalc = readToSegment !== null && readToSegment !== void 0 ? readToSegment : 0;
|
|
6299
|
+
unreadCount = Math.max(lastSegment - readForCalc, 0);
|
|
6300
|
+
isMentioned =
|
|
6301
|
+
typeof lastMentionedSegment === 'number' && readForCalc < lastMentionedSegment;
|
|
6015
6302
|
}
|
|
6016
6303
|
const cacheChannelUnread = {
|
|
6017
6304
|
channelId: channels[i].channelId,
|
|
6018
|
-
lastSegment
|
|
6305
|
+
lastSegment,
|
|
6019
6306
|
readToSegment,
|
|
6020
6307
|
lastMentionedSegment,
|
|
6021
6308
|
unreadCount,
|
|
@@ -6025,6 +6312,8 @@ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
|
6025
6312
|
pushToCache(cacheKey, cacheChannelUnread);
|
|
6026
6313
|
channelsUnread.push(cacheChannelUnread);
|
|
6027
6314
|
}
|
|
6315
|
+
}
|
|
6316
|
+
if (channelsUnread.length > 0) {
|
|
6028
6317
|
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
6029
6318
|
}
|
|
6030
6319
|
};
|
|
@@ -6724,7 +7013,7 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6724
7013
|
const client = getActiveClient();
|
|
6725
7014
|
const filter = async (payload) => {
|
|
6726
7015
|
const { channels, channelUsers } = payload;
|
|
6727
|
-
|
|
7016
|
+
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
6728
7017
|
};
|
|
6729
7018
|
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
|
|
6730
7019
|
}
|
|
@@ -6732,6 +7021,39 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6732
7021
|
return () => dispose$1(callback);
|
|
6733
7022
|
};
|
|
6734
7023
|
|
|
7024
|
+
/**
|
|
7025
|
+
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
7026
|
+
*
|
|
7027
|
+
* @param callback The function to call when the event was fired
|
|
7028
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7029
|
+
*
|
|
7030
|
+
* @category Channel Events
|
|
7031
|
+
*/
|
|
7032
|
+
const onChannelArchived = (callback) => {
|
|
7033
|
+
const client = getActiveClient();
|
|
7034
|
+
const filter = async (payload) => {
|
|
7035
|
+
callback(payload);
|
|
7036
|
+
};
|
|
7037
|
+
return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
|
|
7038
|
+
};
|
|
7039
|
+
|
|
7040
|
+
/**
|
|
7041
|
+
* Fired when a previously archived {@link Amity.Channel} has been unarchived
|
|
7042
|
+
* by the active user.
|
|
7043
|
+
*
|
|
7044
|
+
* @param callback The function to call when the event was fired
|
|
7045
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7046
|
+
*
|
|
7047
|
+
* @category Channel Events
|
|
7048
|
+
*/
|
|
7049
|
+
const onChannelUnarchived = (callback) => {
|
|
7050
|
+
const client = getActiveClient();
|
|
7051
|
+
const filter = async (payload) => {
|
|
7052
|
+
callback(payload);
|
|
7053
|
+
};
|
|
7054
|
+
return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
|
|
7055
|
+
};
|
|
7056
|
+
|
|
6735
7057
|
const callbacks = [];
|
|
6736
7058
|
let mainDisposer = null;
|
|
6737
7059
|
const dispose = (cb) => {
|
|
@@ -6845,6 +7167,17 @@ const channelLinkedObject = (channel) => {
|
|
|
6845
7167
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
6846
7168
|
previewMembers,
|
|
6847
7169
|
myMembership: (callback) => getMyMembership(channel.channelId, callback),
|
|
7170
|
+
get avatar() {
|
|
7171
|
+
var _a;
|
|
7172
|
+
if (!channel.avatarFileId)
|
|
7173
|
+
return undefined;
|
|
7174
|
+
const avatar = (_a = pullFromCache([
|
|
7175
|
+
'file',
|
|
7176
|
+
'get',
|
|
7177
|
+
`${channel.avatarFileId}`,
|
|
7178
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7179
|
+
return avatar;
|
|
7180
|
+
},
|
|
6848
7181
|
});
|
|
6849
7182
|
};
|
|
6850
7183
|
|
|
@@ -6943,54 +7276,6 @@ getChannelByIds$1.locally = (channelIds) => {
|
|
|
6943
7276
|
};
|
|
6944
7277
|
};
|
|
6945
7278
|
|
|
6946
|
-
class SessionWatcher {
|
|
6947
|
-
constructor() {
|
|
6948
|
-
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
6949
|
-
this._listener = new Map();
|
|
6950
|
-
}
|
|
6951
|
-
onSessionStateChange(callback) {
|
|
6952
|
-
this._listener.set(callback, callback);
|
|
6953
|
-
return () => {
|
|
6954
|
-
this._listener.delete(callback);
|
|
6955
|
-
};
|
|
6956
|
-
}
|
|
6957
|
-
setSessionState(state, reason) {
|
|
6958
|
-
if (this._sessionState === state)
|
|
6959
|
-
return;
|
|
6960
|
-
this._sessionState = state;
|
|
6961
|
-
this._listener.forEach(cb => cb(state, reason));
|
|
6962
|
-
}
|
|
6963
|
-
destroy() {
|
|
6964
|
-
this._listener.clear();
|
|
6965
|
-
}
|
|
6966
|
-
}
|
|
6967
|
-
let instance$8;
|
|
6968
|
-
var SessionWatcher$1 = {
|
|
6969
|
-
getInstance: () => {
|
|
6970
|
-
if (!instance$8) {
|
|
6971
|
-
instance$8 = new SessionWatcher();
|
|
6972
|
-
}
|
|
6973
|
-
return instance$8;
|
|
6974
|
-
},
|
|
6975
|
-
};
|
|
6976
|
-
|
|
6977
|
-
/**
|
|
6978
|
-
* ```js
|
|
6979
|
-
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
6980
|
-
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
6981
|
-
* // ...
|
|
6982
|
-
* })
|
|
6983
|
-
* ```
|
|
6984
|
-
*
|
|
6985
|
-
* Fired when any {@link Amity.Client} has a session state change
|
|
6986
|
-
*
|
|
6987
|
-
* @param callback The function to call when the event was fired
|
|
6988
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
6989
|
-
*
|
|
6990
|
-
* @category Client Events
|
|
6991
|
-
*/
|
|
6992
|
-
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
6993
|
-
|
|
6994
7279
|
const setIntervalTask = (handler, timeout) => {
|
|
6995
7280
|
const timer = setInterval(handler, timeout);
|
|
6996
7281
|
return () => clearInterval(timer);
|
|
@@ -7254,6 +7539,26 @@ const getSocialSettings = async () => {
|
|
|
7254
7539
|
return data.socialNetworkSetting;
|
|
7255
7540
|
};
|
|
7256
7541
|
|
|
7542
|
+
/**
|
|
7543
|
+
* ```js
|
|
7544
|
+
* import { createClient } from '@amityco/ts-sdk'
|
|
7545
|
+
* const client = createClient(apiKey, apiRegion)
|
|
7546
|
+
* const userSettings = await client.getCoreUserSettings()
|
|
7547
|
+
* ```
|
|
7548
|
+
*
|
|
7549
|
+
* Fetches a {@link Amity.CoreUserSettings} object
|
|
7550
|
+
*
|
|
7551
|
+
* @returns A Promise of {@link Amity.CoreUserSettings} object
|
|
7552
|
+
*
|
|
7553
|
+
* @category Client API
|
|
7554
|
+
* @async
|
|
7555
|
+
*/
|
|
7556
|
+
const getCoreUserSettings = async () => {
|
|
7557
|
+
const client = getActiveClient();
|
|
7558
|
+
const { data } = await client.http.get(`/api/v3/network-settings/users`);
|
|
7559
|
+
return data;
|
|
7560
|
+
};
|
|
7561
|
+
|
|
7257
7562
|
/* begin_public_function
|
|
7258
7563
|
id: client.getProductCatalogueSetting
|
|
7259
7564
|
*/
|
|
@@ -7784,7 +8089,7 @@ class AnalyticsEventSyncer {
|
|
|
7784
8089
|
|
|
7785
8090
|
class AnalyticsEventCapturer {
|
|
7786
8091
|
constructor() {
|
|
7787
|
-
this._expireTime = 5 *
|
|
8092
|
+
this._expireTime = 5 * SECOND$1;
|
|
7788
8093
|
this._poolLimit = 1000;
|
|
7789
8094
|
this._recentViewed = {};
|
|
7790
8095
|
this._recentHighPriorityViewed = {};
|
|
@@ -7838,12 +8143,36 @@ class AnalyticsEventCapturer {
|
|
|
7838
8143
|
}
|
|
7839
8144
|
markPostAsViewed(postId) {
|
|
7840
8145
|
this.markAs({
|
|
7841
|
-
uniqueId: postId
|
|
8146
|
+
uniqueId: `post.${postId}`,
|
|
7842
8147
|
contentId: postId,
|
|
7843
8148
|
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
7844
8149
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
7845
8150
|
});
|
|
7846
8151
|
}
|
|
8152
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8153
|
+
var _a;
|
|
8154
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8155
|
+
const metadata = {};
|
|
8156
|
+
if (feedRenderPosition !== undefined)
|
|
8157
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
8158
|
+
if (cached) {
|
|
8159
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
8160
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
8161
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
8162
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
8163
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
8164
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
8165
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
8166
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
8167
|
+
}
|
|
8168
|
+
this.markAs({
|
|
8169
|
+
uniqueId: `post.${postId}.meaningfulView`,
|
|
8170
|
+
contentId: postId,
|
|
8171
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
8172
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
8173
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
8174
|
+
});
|
|
8175
|
+
}
|
|
7847
8176
|
markStory(story, activityType) {
|
|
7848
8177
|
if (!story.expiresAt)
|
|
7849
8178
|
return;
|
|
@@ -7983,6 +8312,12 @@ class AnalyticsEngine {
|
|
|
7983
8312
|
this._eventCapturer.markPostAsViewed(postId);
|
|
7984
8313
|
}
|
|
7985
8314
|
}
|
|
8315
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8316
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
8317
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8318
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
8319
|
+
}
|
|
8320
|
+
}
|
|
7986
8321
|
markStoryAsViewed(story) {
|
|
7987
8322
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
7988
8323
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -8034,13 +8369,13 @@ class AnalyticsEngine {
|
|
|
8034
8369
|
this._eventCapturer.resetAllBuckets();
|
|
8035
8370
|
}
|
|
8036
8371
|
}
|
|
8037
|
-
let instance$
|
|
8372
|
+
let instance$8;
|
|
8038
8373
|
var AnalyticsEngine$1 = {
|
|
8039
8374
|
getInstance: () => {
|
|
8040
|
-
if (!instance$
|
|
8041
|
-
instance$
|
|
8375
|
+
if (!instance$8) {
|
|
8376
|
+
instance$8 = new AnalyticsEngine();
|
|
8042
8377
|
}
|
|
8043
|
-
return instance$
|
|
8378
|
+
return instance$8;
|
|
8044
8379
|
},
|
|
8045
8380
|
};
|
|
8046
8381
|
|
|
@@ -8207,9 +8542,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
8207
8542
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
8208
8543
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
8209
8544
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8210
|
-
if (
|
|
8211
|
-
channelUnread
|
|
8212
|
-
segment > channelUnread.readToSegment) {
|
|
8545
|
+
if (channelUnread &&
|
|
8546
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
8213
8547
|
channelUnread.readToSegment = segment;
|
|
8214
8548
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
8215
8549
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -8268,12 +8602,12 @@ class MessageReadReceiptSyncEngine {
|
|
|
8268
8602
|
}
|
|
8269
8603
|
}
|
|
8270
8604
|
}
|
|
8271
|
-
let instance$
|
|
8605
|
+
let instance$7 = null;
|
|
8272
8606
|
var ReadReceiptSyncEngine = {
|
|
8273
8607
|
getInstance: () => {
|
|
8274
|
-
if (!instance$
|
|
8275
|
-
instance$
|
|
8276
|
-
return instance$
|
|
8608
|
+
if (!instance$7)
|
|
8609
|
+
instance$7 = new MessageReadReceiptSyncEngine();
|
|
8610
|
+
return instance$7;
|
|
8277
8611
|
},
|
|
8278
8612
|
};
|
|
8279
8613
|
|
|
@@ -8527,12 +8861,12 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
8527
8861
|
}
|
|
8528
8862
|
}
|
|
8529
8863
|
}
|
|
8530
|
-
let instance$
|
|
8864
|
+
let instance$6 = null;
|
|
8531
8865
|
var LegacyReadReceiptSyncEngine = {
|
|
8532
8866
|
getInstance: () => {
|
|
8533
|
-
if (!instance$
|
|
8534
|
-
instance$
|
|
8535
|
-
return instance$
|
|
8867
|
+
if (!instance$6)
|
|
8868
|
+
instance$6 = new LegacyMessageReadReceiptSyncEngine();
|
|
8869
|
+
return instance$6;
|
|
8536
8870
|
},
|
|
8537
8871
|
};
|
|
8538
8872
|
|
|
@@ -8778,12 +9112,12 @@ class ObjectResolverEngine {
|
|
|
8778
9112
|
this.stopResolver();
|
|
8779
9113
|
}
|
|
8780
9114
|
}
|
|
8781
|
-
let instance$
|
|
9115
|
+
let instance$5 = null;
|
|
8782
9116
|
var ObjectResolverEngine$1 = {
|
|
8783
9117
|
getInstance: () => {
|
|
8784
|
-
if (!instance$
|
|
8785
|
-
instance$
|
|
8786
|
-
return instance$
|
|
9118
|
+
if (!instance$5)
|
|
9119
|
+
instance$5 = new ObjectResolverEngine();
|
|
9120
|
+
return instance$5;
|
|
8787
9121
|
},
|
|
8788
9122
|
};
|
|
8789
9123
|
|
|
@@ -8933,13 +9267,13 @@ class LiveReactionSyncEngine {
|
|
|
8933
9267
|
this.stopReactionsSync();
|
|
8934
9268
|
}
|
|
8935
9269
|
}
|
|
8936
|
-
let instance$
|
|
9270
|
+
let instance$4;
|
|
8937
9271
|
var ReactionSyncEngine = {
|
|
8938
9272
|
getInstance: () => {
|
|
8939
|
-
if (!instance$
|
|
8940
|
-
instance$
|
|
9273
|
+
if (!instance$4) {
|
|
9274
|
+
instance$4 = new LiveReactionSyncEngine();
|
|
8941
9275
|
}
|
|
8942
|
-
return instance$
|
|
9276
|
+
return instance$4;
|
|
8943
9277
|
},
|
|
8944
9278
|
};
|
|
8945
9279
|
|
|
@@ -8969,19 +9303,20 @@ function prepareBlockedUserPayload(response) {
|
|
|
8969
9303
|
}), users: users.map(convertRawUserToInternalUser) });
|
|
8970
9304
|
}
|
|
8971
9305
|
|
|
8972
|
-
const BLOCK_LIST_LIMIT = 100;
|
|
8973
|
-
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
9306
|
+
const BLOCK_LIST_LIMIT$1 = 100;
|
|
9307
|
+
const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
|
|
8974
9308
|
/**
|
|
8975
9309
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8976
9310
|
* of blocked users. Provides a lazy `ensureFetched()` gate for the
|
|
8977
9311
|
* `getAllBlockedUsers()` API.
|
|
8978
9312
|
*
|
|
8979
9313
|
* Key behaviours:
|
|
8980
|
-
* - `
|
|
8981
|
-
* - `
|
|
9314
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
9315
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
8982
9316
|
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
8983
9317
|
* - `lastFetchedAt` is only updated on successful fetch
|
|
8984
|
-
* -
|
|
9318
|
+
* - reads query the follow cache live, so block/unblock changes are reflected
|
|
9319
|
+
* even within the TTL window
|
|
8985
9320
|
*
|
|
8986
9321
|
* @internal
|
|
8987
9322
|
*/
|
|
@@ -8989,12 +9324,7 @@ class BlockedUserSyncEngine {
|
|
|
8989
9324
|
constructor() {
|
|
8990
9325
|
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
8991
9326
|
this.lastFetchedAt = null;
|
|
8992
|
-
/** Ordered list of userId strings from the most recent successful fetch. */
|
|
8993
|
-
this.blockedUserIds = [];
|
|
8994
9327
|
}
|
|
8995
|
-
// ---------------------------------------------------------------------------
|
|
8996
|
-
// SessionComponent lifecycle
|
|
8997
|
-
// ---------------------------------------------------------------------------
|
|
8998
9328
|
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockedUsers(). */
|
|
8999
9329
|
// eslint-disable-next-line class-methods-use-this
|
|
9000
9330
|
onSessionEstablished() {
|
|
@@ -9003,24 +9333,17 @@ class BlockedUserSyncEngine {
|
|
|
9003
9333
|
/** Resets state so the next session starts with a cold cache. */
|
|
9004
9334
|
onSessionDestroyed() {
|
|
9005
9335
|
this.lastFetchedAt = null;
|
|
9006
|
-
this.blockedUserIds = [];
|
|
9007
9336
|
}
|
|
9008
9337
|
/** No-op for this engine. */
|
|
9009
9338
|
// eslint-disable-next-line class-methods-use-this
|
|
9010
9339
|
onTokenExpired() {
|
|
9011
9340
|
// intentionally empty
|
|
9012
9341
|
}
|
|
9013
|
-
// ---------------------------------------------------------------------------
|
|
9014
|
-
// Cache helpers
|
|
9015
|
-
// ---------------------------------------------------------------------------
|
|
9016
9342
|
isCacheExpired() {
|
|
9017
9343
|
if (this.lastFetchedAt === null)
|
|
9018
9344
|
return true;
|
|
9019
|
-
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
9345
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$1;
|
|
9020
9346
|
}
|
|
9021
|
-
// ---------------------------------------------------------------------------
|
|
9022
|
-
// Core fetch gate
|
|
9023
|
-
// ---------------------------------------------------------------------------
|
|
9024
9347
|
/**
|
|
9025
9348
|
* Ensures the local store is populated with fresh blocked-user data.
|
|
9026
9349
|
*
|
|
@@ -9036,52 +9359,50 @@ class BlockedUserSyncEngine {
|
|
|
9036
9359
|
if (!this.isCacheExpired())
|
|
9037
9360
|
return;
|
|
9038
9361
|
const client = getActiveClient();
|
|
9039
|
-
const { data } = await client.http.get('/api/v4/me/user-blocks', { params: { options: { limit: BLOCK_LIST_LIMIT }, isDeleted: false } });
|
|
9362
|
+
const { data } = await client.http.get('/api/v4/me/user-blocks', { params: { options: { limit: BLOCK_LIST_LIMIT$1 }, isDeleted: false } });
|
|
9040
9363
|
const cachedAt = client.cache && Date.now();
|
|
9041
9364
|
const payload = prepareBlockedUserPayload(data);
|
|
9042
9365
|
if (client.cache) {
|
|
9043
9366
|
ingestInCache(payload, { cachedAt });
|
|
9044
9367
|
}
|
|
9045
|
-
// Keep the ordered list of blocked user IDs for getCachedUsers()
|
|
9046
|
-
this.blockedUserIds = payload.users.map(u => u.userId);
|
|
9047
9368
|
// Only update timestamp on success — failure leaves it unchanged so the
|
|
9048
9369
|
// next call retries.
|
|
9049
9370
|
this.lastFetchedAt = Date.now();
|
|
9050
9371
|
}
|
|
9051
|
-
// ---------------------------------------------------------------------------
|
|
9052
|
-
// Local store read
|
|
9053
|
-
// ---------------------------------------------------------------------------
|
|
9054
9372
|
/**
|
|
9055
|
-
* Returns blocked
|
|
9056
|
-
*
|
|
9057
|
-
*
|
|
9058
|
-
*
|
|
9059
|
-
* - Hard limit of 100 results
|
|
9373
|
+
* Returns the blocked users by querying the follow cache live — the outgoing
|
|
9374
|
+
* direction (`from === me`, `status === 'blocked'`). Reading the cache (not a
|
|
9375
|
+
* fetched snapshot) means `blockUser()` / `unblockUser()` changes are reflected
|
|
9376
|
+
* even within the TTL window.
|
|
9060
9377
|
*
|
|
9061
|
-
*
|
|
9062
|
-
*
|
|
9378
|
+
* Applies the spec-mandated query:
|
|
9379
|
+
* - filter `from === currentUserId`, `status === 'blocked'`, blocked user not deleted
|
|
9380
|
+
* - sort by `updatedAt` DESC
|
|
9381
|
+
* - hard limit of 100 results
|
|
9063
9382
|
*/
|
|
9383
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9064
9384
|
getCachedUsers() {
|
|
9385
|
+
var _a;
|
|
9065
9386
|
const client = getActiveClient();
|
|
9066
|
-
if (!client.cache)
|
|
9067
|
-
// No cache available — fall back to the in-memory list from the last fetch
|
|
9387
|
+
if (!client.cache)
|
|
9068
9388
|
return [];
|
|
9069
|
-
}
|
|
9070
|
-
return
|
|
9071
|
-
.map(
|
|
9389
|
+
const { userId } = client;
|
|
9390
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
9391
|
+
.map(entry => entry.data)
|
|
9392
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && follow.from === userId)
|
|
9393
|
+
.sort((a, b) => { var _a, _b; return (((_a = a.updatedAt) !== null && _a !== void 0 ? _a : '') < ((_b = b.updatedAt) !== null && _b !== void 0 ? _b : '') ? 1 : -1); })
|
|
9394
|
+
.map(follow => { var _a; return (_a = pullFromCache(['user', 'get', follow.to])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
9072
9395
|
.filter((user) => user != null && user.isDeleted !== true)
|
|
9073
|
-
.slice(0, BLOCK_LIST_LIMIT)
|
|
9396
|
+
.slice(0, BLOCK_LIST_LIMIT$1)
|
|
9397
|
+
.map(userLinkedObject);
|
|
9074
9398
|
}
|
|
9075
9399
|
}
|
|
9076
|
-
|
|
9077
|
-
// Module-level singleton
|
|
9078
|
-
// ---------------------------------------------------------------------------
|
|
9079
|
-
let instance$2 = null;
|
|
9400
|
+
let instance$3 = null;
|
|
9080
9401
|
var BlockedUserSyncEngine$1 = {
|
|
9081
9402
|
getInstance: () => {
|
|
9082
|
-
if (!instance$
|
|
9083
|
-
instance$
|
|
9084
|
-
return instance$
|
|
9403
|
+
if (!instance$3)
|
|
9404
|
+
instance$3 = new BlockedUserSyncEngine();
|
|
9405
|
+
return instance$3;
|
|
9085
9406
|
},
|
|
9086
9407
|
};
|
|
9087
9408
|
|
|
@@ -9103,6 +9424,277 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
9103
9424
|
};
|
|
9104
9425
|
};
|
|
9105
9426
|
|
|
9427
|
+
function prepareBlockingUserPayload(response) {
|
|
9428
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9429
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
9430
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
9431
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
9432
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
9433
|
+
}
|
|
9434
|
+
|
|
9435
|
+
const BLOCK_LIST_LIMIT = 100;
|
|
9436
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
9437
|
+
/**
|
|
9438
|
+
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
9439
|
+
* of blocking users (the "blocked-by" list — users who blocked the current
|
|
9440
|
+
* user). Provides a lazy `ensureFetched()` gate for the `getAllBlockingUsers()`
|
|
9441
|
+
* API. Directional inverse of {@link BlockedUserSyncEngine}.
|
|
9442
|
+
*
|
|
9443
|
+
* Key behaviours:
|
|
9444
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
9445
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
9446
|
+
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
9447
|
+
* - `lastFetchedAt` is only updated on successful fetch
|
|
9448
|
+
* - reads query the follow cache live, so block/unblock changes are reflected
|
|
9449
|
+
* even within the TTL window
|
|
9450
|
+
*
|
|
9451
|
+
* @internal
|
|
9452
|
+
*/
|
|
9453
|
+
class BlockingUserSyncEngine {
|
|
9454
|
+
constructor() {
|
|
9455
|
+
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
9456
|
+
this.lastFetchedAt = null;
|
|
9457
|
+
}
|
|
9458
|
+
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockingUsers(). */
|
|
9459
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9460
|
+
onSessionEstablished() {
|
|
9461
|
+
// intentionally empty
|
|
9462
|
+
}
|
|
9463
|
+
/** Resets state so the next session starts with a cold cache. */
|
|
9464
|
+
onSessionDestroyed() {
|
|
9465
|
+
this.lastFetchedAt = null;
|
|
9466
|
+
}
|
|
9467
|
+
/** No-op for this engine. */
|
|
9468
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9469
|
+
onTokenExpired() {
|
|
9470
|
+
// intentionally empty
|
|
9471
|
+
}
|
|
9472
|
+
isCacheExpired() {
|
|
9473
|
+
if (this.lastFetchedAt === null)
|
|
9474
|
+
return true;
|
|
9475
|
+
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
9476
|
+
}
|
|
9477
|
+
/**
|
|
9478
|
+
* Ensures the local store is populated with fresh blocking-user data.
|
|
9479
|
+
*
|
|
9480
|
+
* - If the cache is still within the 5-minute TTL window: resolves immediately
|
|
9481
|
+
* (no server call).
|
|
9482
|
+
* - If the cache is expired (or never fetched): fetches from the server,
|
|
9483
|
+
* persists the payload to the cache, and updates `lastFetchedAt`.
|
|
9484
|
+
*
|
|
9485
|
+
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
|
|
9486
|
+
* updated, so the next call will retry.
|
|
9487
|
+
*/
|
|
9488
|
+
async ensureFetched() {
|
|
9489
|
+
if (!this.isCacheExpired())
|
|
9490
|
+
return;
|
|
9491
|
+
const client = getActiveClient();
|
|
9492
|
+
const { data } = await client.http.get('/api/v4/me/blockers', { params: { options: { limit: BLOCK_LIST_LIMIT }, isDeleted: false } });
|
|
9493
|
+
const cachedAt = client.cache && Date.now();
|
|
9494
|
+
const payload = prepareBlockingUserPayload(data);
|
|
9495
|
+
if (client.cache) {
|
|
9496
|
+
ingestInCache(payload, { cachedAt });
|
|
9497
|
+
}
|
|
9498
|
+
// Only update timestamp on success — failure leaves it unchanged so the
|
|
9499
|
+
// next call retries.
|
|
9500
|
+
this.lastFetchedAt = Date.now();
|
|
9501
|
+
}
|
|
9502
|
+
/**
|
|
9503
|
+
* Returns the "blocked-by" users by querying the follow cache live — the
|
|
9504
|
+
* incoming direction (`to === me`, `status === 'blocked'`). Reading the cache
|
|
9505
|
+
* (not a fetched snapshot) means RTE `user.didBlock` / `user.didUnblock`
|
|
9506
|
+
* changes are reflected even within the TTL window.
|
|
9507
|
+
*
|
|
9508
|
+
* Applies the spec-mandated query (REQ-012/013/014):
|
|
9509
|
+
* - filter `to === currentUserId`, `status === 'blocked'`, blocker not deleted
|
|
9510
|
+
* - sort by `updatedAt` DESC
|
|
9511
|
+
* - hard limit of 100 results
|
|
9512
|
+
*/
|
|
9513
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9514
|
+
getCachedUsers() {
|
|
9515
|
+
var _a;
|
|
9516
|
+
const client = getActiveClient();
|
|
9517
|
+
if (!client.cache)
|
|
9518
|
+
return [];
|
|
9519
|
+
const { userId } = client;
|
|
9520
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
9521
|
+
.map(entry => entry.data)
|
|
9522
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && follow.to === userId)
|
|
9523
|
+
.sort((a, b) => { var _a, _b; return (((_a = a.updatedAt) !== null && _a !== void 0 ? _a : '') < ((_b = b.updatedAt) !== null && _b !== void 0 ? _b : '') ? 1 : -1); })
|
|
9524
|
+
.map(follow => { var _a; return (_a = pullFromCache(['user', 'get', follow.from])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
9525
|
+
.filter((user) => user != null && user.isDeleted !== true)
|
|
9526
|
+
.slice(0, BLOCK_LIST_LIMIT)
|
|
9527
|
+
.map(userLinkedObject);
|
|
9528
|
+
}
|
|
9529
|
+
}
|
|
9530
|
+
let instance$2 = null;
|
|
9531
|
+
var BlockingUserSyncEngine$1 = {
|
|
9532
|
+
getInstance: () => {
|
|
9533
|
+
if (!instance$2)
|
|
9534
|
+
instance$2 = new BlockingUserSyncEngine();
|
|
9535
|
+
return instance$2;
|
|
9536
|
+
},
|
|
9537
|
+
};
|
|
9538
|
+
|
|
9539
|
+
var blockingUserSyncEngineOnLoginHandler = () => {
|
|
9540
|
+
const blockingUserSyncEngine = BlockingUserSyncEngine$1.getInstance();
|
|
9541
|
+
onSessionStateChange(state => {
|
|
9542
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
9543
|
+
blockingUserSyncEngine.onSessionEstablished();
|
|
9544
|
+
}
|
|
9545
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
9546
|
+
blockingUserSyncEngine.onTokenExpired();
|
|
9547
|
+
}
|
|
9548
|
+
else {
|
|
9549
|
+
blockingUserSyncEngine.onSessionDestroyed();
|
|
9550
|
+
}
|
|
9551
|
+
});
|
|
9552
|
+
return () => {
|
|
9553
|
+
blockingUserSyncEngine.onSessionDestroyed();
|
|
9554
|
+
};
|
|
9555
|
+
};
|
|
9556
|
+
|
|
9557
|
+
function prepareFollowersPayload(response) {
|
|
9558
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9559
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9560
|
+
}
|
|
9561
|
+
function prepareFollowingsPayload(response) {
|
|
9562
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9563
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9564
|
+
}
|
|
9565
|
+
function prepareFollowStatusPayload(response) {
|
|
9566
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
9567
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
9568
|
+
}
|
|
9569
|
+
|
|
9570
|
+
/**
|
|
9571
|
+
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
9572
|
+
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
9573
|
+
* the block-relationship rows (`['follow', 'get', from#to]`) and user rows are
|
|
9574
|
+
* kept current, then forwards the affected {@link Amity.FollowStatus} to the
|
|
9575
|
+
* caller.
|
|
9576
|
+
*
|
|
9577
|
+
* @hidden
|
|
9578
|
+
*/
|
|
9579
|
+
const createBlockEventSubscriber = (event, callback) => {
|
|
9580
|
+
const client = getActiveClient();
|
|
9581
|
+
const filter = (data) => {
|
|
9582
|
+
const payload = prepareFollowersPayload(data);
|
|
9583
|
+
if (client.cache) {
|
|
9584
|
+
ingestInCache(payload);
|
|
9585
|
+
}
|
|
9586
|
+
callback(payload.follows[0]);
|
|
9587
|
+
};
|
|
9588
|
+
return createEventSubscriber(client, event, event, filter);
|
|
9589
|
+
};
|
|
9590
|
+
|
|
9591
|
+
/**
|
|
9592
|
+
* ```js
|
|
9593
|
+
* import { onUserDidBlock } from '@amityco/ts-sdk'
|
|
9594
|
+
* const dispose = onUserDidBlock(status => {
|
|
9595
|
+
* // ...
|
|
9596
|
+
* })
|
|
9597
|
+
* ```
|
|
9598
|
+
*
|
|
9599
|
+
* Fired when a block relationship is created in real time — either a user
|
|
9600
|
+
* blocks the current user (incoming) or the current user blocks someone on
|
|
9601
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
9602
|
+
* before the callback runs.
|
|
9603
|
+
*
|
|
9604
|
+
* @param callback The function to call when the event was fired
|
|
9605
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9606
|
+
*
|
|
9607
|
+
* @category Block Events
|
|
9608
|
+
*/
|
|
9609
|
+
const onUserDidBlock = (callback) => createBlockEventSubscriber('user.didBlock', callback);
|
|
9610
|
+
|
|
9611
|
+
/**
|
|
9612
|
+
* ```js
|
|
9613
|
+
* import { onUserDidUnblock } from '@amityco/ts-sdk'
|
|
9614
|
+
* const dispose = onUserDidUnblock(status => {
|
|
9615
|
+
* // ...
|
|
9616
|
+
* })
|
|
9617
|
+
* ```
|
|
9618
|
+
*
|
|
9619
|
+
* Fired when a block relationship is removed in real time — either a user
|
|
9620
|
+
* unblocks the current user (incoming) or the current user unblocks someone on
|
|
9621
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
9622
|
+
* before the callback runs.
|
|
9623
|
+
*
|
|
9624
|
+
* @param callback The function to call when the event was fired
|
|
9625
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9626
|
+
*
|
|
9627
|
+
* @category Block Events
|
|
9628
|
+
*/
|
|
9629
|
+
const onUserDidUnblock = (callback) => createBlockEventSubscriber('user.didUnblock', callback);
|
|
9630
|
+
|
|
9631
|
+
/**
|
|
9632
|
+
* Keeps the follow cache current for incoming/outgoing block changes for the
|
|
9633
|
+
* whole session — the ingest happens as a side effect inside
|
|
9634
|
+
* createBlockEventSubscriber, so the one-shot `getAllBlockedUsers()` /
|
|
9635
|
+
* `getAllBlockingUsers()` reflect RTE block/unblock within the TTL window.
|
|
9636
|
+
*
|
|
9637
|
+
* Registered via `setupLoginSubscriptions`; the returned unsubscriber is torn
|
|
9638
|
+
* down on logout.
|
|
9639
|
+
*/
|
|
9640
|
+
var blockRealtimeOnLoginHandler = () => {
|
|
9641
|
+
const disposers = [onUserDidBlock(() => { }), onUserDidUnblock(() => { })];
|
|
9642
|
+
return () => disposers.forEach(dispose => dispose());
|
|
9643
|
+
};
|
|
9644
|
+
|
|
9645
|
+
class CursorController {
|
|
9646
|
+
constructor(networkId, userId) {
|
|
9647
|
+
this.networkId = networkId;
|
|
9648
|
+
this.userId = userId;
|
|
9649
|
+
}
|
|
9650
|
+
static current() {
|
|
9651
|
+
try {
|
|
9652
|
+
const user = getCurrentUser();
|
|
9653
|
+
if (!user)
|
|
9654
|
+
return null;
|
|
9655
|
+
const networkId = getNetworkId(user);
|
|
9656
|
+
const { userId } = user;
|
|
9657
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
9658
|
+
}
|
|
9659
|
+
catch (_a) {
|
|
9660
|
+
return null;
|
|
9661
|
+
}
|
|
9662
|
+
}
|
|
9663
|
+
static isExpired(expiredAt) {
|
|
9664
|
+
return Date.now() >= expiredAt;
|
|
9665
|
+
}
|
|
9666
|
+
static clearOnLogout() {
|
|
9667
|
+
return onSessionStateChange(state => {
|
|
9668
|
+
var _a;
|
|
9669
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
9670
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
9671
|
+
});
|
|
9672
|
+
}
|
|
9673
|
+
get key() {
|
|
9674
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
9675
|
+
}
|
|
9676
|
+
async get() {
|
|
9677
|
+
const raw = await getItem(this.key);
|
|
9678
|
+
if (!raw)
|
|
9679
|
+
return null;
|
|
9680
|
+
try {
|
|
9681
|
+
const parsed = JSON.parse(raw);
|
|
9682
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
9683
|
+
return null;
|
|
9684
|
+
return { cursor: parsed.cursor, expiredAt: parsed.expiredAt };
|
|
9685
|
+
}
|
|
9686
|
+
catch (_a) {
|
|
9687
|
+
return null;
|
|
9688
|
+
}
|
|
9689
|
+
}
|
|
9690
|
+
async set(value) {
|
|
9691
|
+
await setItem(this.key, JSON.stringify(value));
|
|
9692
|
+
}
|
|
9693
|
+
async clear() {
|
|
9694
|
+
await setItem(this.key, '');
|
|
9695
|
+
}
|
|
9696
|
+
}
|
|
9697
|
+
|
|
9106
9698
|
const EVENTS = [
|
|
9107
9699
|
'disconnected',
|
|
9108
9700
|
'error',
|
|
@@ -9292,7 +9884,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
9292
9884
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9293
9885
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9294
9886
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
9295
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler());
|
|
9887
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
9296
9888
|
if (client.useLegacyUnreadCount) {
|
|
9297
9889
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9298
9890
|
}
|
|
@@ -9991,16 +10583,13 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
9991
10583
|
}
|
|
9992
10584
|
if (client.useLegacyUnreadCount) {
|
|
9993
10585
|
rawPayload.messages.forEach(message => {
|
|
9994
|
-
var _a, _b;
|
|
10586
|
+
var _a, _b, _c;
|
|
9995
10587
|
const channelUnread = (_a = pullFromCache([
|
|
9996
10588
|
'channelUnread',
|
|
9997
10589
|
'get',
|
|
9998
10590
|
message.channelId,
|
|
9999
10591
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
10000
|
-
if (!channelUnread ||
|
|
10001
|
-
channelUnread.lastSegment >= message.segment ||
|
|
10002
|
-
typeof channelUnread.readToSegment !== 'number' ||
|
|
10003
|
-
typeof channelUnread.lastMentionedSegment !== 'number')
|
|
10592
|
+
if (!channelUnread || channelUnread.lastSegment >= message.segment)
|
|
10004
10593
|
return;
|
|
10005
10594
|
const lastSegment = message.segment;
|
|
10006
10595
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -10012,7 +10601,8 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
10012
10601
|
const lastMentionedSegment = isMentionedInMessage
|
|
10013
10602
|
? message.segment
|
|
10014
10603
|
: channelUnread.lastMentionedSegment;
|
|
10015
|
-
const
|
|
10604
|
+
const readToSegment = (_c = channelUnread.readToSegment) !== null && _c !== void 0 ? _c : 0;
|
|
10605
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - readToSegment, 0), lastMentionedSegment, isMentioned: typeof lastMentionedSegment === 'number' && readToSegment < lastMentionedSegment });
|
|
10016
10606
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
10017
10607
|
fireEvent('local.channelUnread.updated', [updatedChannelUnread]);
|
|
10018
10608
|
});
|
|
@@ -10375,7 +10965,9 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
10375
10965
|
validateUrls,
|
|
10376
10966
|
validateTexts,
|
|
10377
10967
|
getFeedSettings,
|
|
10968
|
+
getCoreUserSettings,
|
|
10378
10969
|
getSocialSettings,
|
|
10970
|
+
getChatSettings,
|
|
10379
10971
|
getVisitorDeviceId: getDeviceId,
|
|
10380
10972
|
getMessagePreviewSetting,
|
|
10381
10973
|
use: () => setActiveClient(client),
|
|
@@ -10650,11 +11242,18 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10650
11242
|
return data;
|
|
10651
11243
|
};
|
|
10652
11244
|
|
|
11245
|
+
const CONTENT_TYPE_CONFIG = {
|
|
11246
|
+
[exports.AmitySharableContentType.POST]: { key: 'posts', placeholder: 'postId' },
|
|
11247
|
+
[exports.AmitySharableContentType.COMMUNITY]: { key: 'communities', placeholder: 'communityId' },
|
|
11248
|
+
[exports.AmitySharableContentType.USER]: { key: 'users', placeholder: 'userId' },
|
|
11249
|
+
[exports.AmitySharableContentType.LIVESTREAM]: { key: 'livestream', placeholder: 'livestream' },
|
|
11250
|
+
[exports.AmitySharableContentType.EVENT]: { key: 'events', placeholder: 'eventId' },
|
|
11251
|
+
};
|
|
10653
11252
|
/**
|
|
10654
11253
|
* ```js
|
|
10655
11254
|
* import Client from '@amityco/ts-sdk'
|
|
10656
|
-
* const
|
|
10657
|
-
* const
|
|
11255
|
+
* const config = await Client.getShareableLinkConfiguration()
|
|
11256
|
+
* const link = config.generateLink(AmitySharableContentType.EVENT, eventId)
|
|
10658
11257
|
* ```
|
|
10659
11258
|
*
|
|
10660
11259
|
* Fetches a {@link Amity.ShareableLinkConfiguration} object
|
|
@@ -10665,9 +11264,29 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10665
11264
|
* @async
|
|
10666
11265
|
*/
|
|
10667
11266
|
const getShareableLinkConfiguration = async () => {
|
|
11267
|
+
var _a, _b;
|
|
10668
11268
|
const client = getActiveClient();
|
|
10669
11269
|
const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
|
|
10670
|
-
|
|
11270
|
+
const domain = (_a = data.domain) !== null && _a !== void 0 ? _a : '';
|
|
11271
|
+
const patterns = (_b = data.patterns) !== null && _b !== void 0 ? _b : {};
|
|
11272
|
+
return {
|
|
11273
|
+
domain,
|
|
11274
|
+
patterns,
|
|
11275
|
+
isEnabled(contentType) {
|
|
11276
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11277
|
+
return !!domain && !!patterns[key];
|
|
11278
|
+
},
|
|
11279
|
+
getPattern(contentType) {
|
|
11280
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11281
|
+
return patterns[key] || null;
|
|
11282
|
+
},
|
|
11283
|
+
generateLink(contentType, referenceId) {
|
|
11284
|
+
const { key, placeholder } = CONTENT_TYPE_CONFIG[contentType];
|
|
11285
|
+
if (!domain || !patterns[key])
|
|
11286
|
+
return null;
|
|
11287
|
+
return domain + patterns[key].replace(`{${placeholder}}`, referenceId);
|
|
11288
|
+
},
|
|
11289
|
+
};
|
|
10671
11290
|
};
|
|
10672
11291
|
|
|
10673
11292
|
/**
|
|
@@ -10858,6 +11477,205 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
10858
11477
|
client.accessTokenHandler = accessTokenHandler;
|
|
10859
11478
|
};
|
|
10860
11479
|
|
|
11480
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
11481
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
11482
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
11483
|
+
}
|
|
11484
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
11485
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
11486
|
+
}
|
|
11487
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ALL };
|
|
11488
|
+
}
|
|
11489
|
+
function serializeRolesFilter(rolesFilter) {
|
|
11490
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === exports.NotificationRolesFilterTypeEnum.ONLY) {
|
|
11491
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
11492
|
+
}
|
|
11493
|
+
return { listenFromRoleIds: [] };
|
|
11494
|
+
}
|
|
11495
|
+
class ChannelNotifications {
|
|
11496
|
+
constructor(channelId) {
|
|
11497
|
+
this.channelId = channelId;
|
|
11498
|
+
}
|
|
11499
|
+
async enable() {
|
|
11500
|
+
const client = getActiveClient();
|
|
11501
|
+
const body = {
|
|
11502
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11503
|
+
channelId: this.channelId,
|
|
11504
|
+
isPushNotifiable: true,
|
|
11505
|
+
};
|
|
11506
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11507
|
+
}
|
|
11508
|
+
async disable() {
|
|
11509
|
+
const client = getActiveClient();
|
|
11510
|
+
const body = {
|
|
11511
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11512
|
+
channelId: this.channelId,
|
|
11513
|
+
isPushNotifiable: false,
|
|
11514
|
+
};
|
|
11515
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11516
|
+
}
|
|
11517
|
+
async getSettings() {
|
|
11518
|
+
const client = getActiveClient();
|
|
11519
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
11520
|
+
return { isEnabled: data.isPushNotifiable };
|
|
11521
|
+
}
|
|
11522
|
+
}
|
|
11523
|
+
class UserNotifications {
|
|
11524
|
+
async enable(modules) {
|
|
11525
|
+
var _a;
|
|
11526
|
+
const client = getActiveClient();
|
|
11527
|
+
const notifiableEvents = (_a = modules === null || modules === void 0 ? void 0 : modules.map(module => (Object.assign({ moduleName: module.moduleName, isPushNotifiable: module.isEnabled }, serializeRolesFilter(module.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
|
|
11528
|
+
const body = {
|
|
11529
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
11530
|
+
isPushNotifiable: true,
|
|
11531
|
+
notifiableEvents,
|
|
11532
|
+
};
|
|
11533
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11534
|
+
}
|
|
11535
|
+
async disableAllNotifications() {
|
|
11536
|
+
const client = getActiveClient();
|
|
11537
|
+
const body = {
|
|
11538
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
11539
|
+
isPushNotifiable: false,
|
|
11540
|
+
notifiableEvents: [],
|
|
11541
|
+
};
|
|
11542
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11543
|
+
}
|
|
11544
|
+
async getSettings() {
|
|
11545
|
+
var _a;
|
|
11546
|
+
const client = getActiveClient();
|
|
11547
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.USER}`);
|
|
11548
|
+
const validModuleNames = Object.values(exports.UserNotificationModuleNameEnum);
|
|
11549
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11550
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
11551
|
+
.map(e => ({
|
|
11552
|
+
moduleName: e.moduleName,
|
|
11553
|
+
isEnabled: e.isPushNotifiable,
|
|
11554
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11555
|
+
}));
|
|
11556
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
11557
|
+
}
|
|
11558
|
+
}
|
|
11559
|
+
class CommunityNotifications {
|
|
11560
|
+
constructor(communityId) {
|
|
11561
|
+
this.communityId = communityId;
|
|
11562
|
+
}
|
|
11563
|
+
async enable(events) {
|
|
11564
|
+
var _a;
|
|
11565
|
+
const client = getActiveClient();
|
|
11566
|
+
const notifiableEvents = (_a = events === null || events === void 0 ? void 0 : events.map(event => (Object.assign({ moduleName: exports.UserNotificationModuleNameEnum.SOCIAL, name: event.eventName, isPushNotifiable: event.isEnabled }, serializeRolesFilter(event.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
|
|
11567
|
+
const body = {
|
|
11568
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11569
|
+
communityId: this.communityId,
|
|
11570
|
+
isPushNotifiable: true,
|
|
11571
|
+
notifiableEvents,
|
|
11572
|
+
};
|
|
11573
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11574
|
+
}
|
|
11575
|
+
async disable() {
|
|
11576
|
+
const client = getActiveClient();
|
|
11577
|
+
const body = {
|
|
11578
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11579
|
+
communityId: this.communityId,
|
|
11580
|
+
isPushNotifiable: false,
|
|
11581
|
+
notifiableEvents: [],
|
|
11582
|
+
};
|
|
11583
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11584
|
+
}
|
|
11585
|
+
async getSettings() {
|
|
11586
|
+
var _a;
|
|
11587
|
+
const client = getActiveClient();
|
|
11588
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
11589
|
+
const validEventNames = Object.values(exports.CommunityNotificationEventNameEnum);
|
|
11590
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11591
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
11592
|
+
.map(e => ({
|
|
11593
|
+
eventName: e.name,
|
|
11594
|
+
isEnabled: e.isPushNotifiable,
|
|
11595
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
11596
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11597
|
+
}));
|
|
11598
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
11599
|
+
}
|
|
11600
|
+
}
|
|
11601
|
+
class Notifications {
|
|
11602
|
+
user() {
|
|
11603
|
+
return new UserNotifications();
|
|
11604
|
+
}
|
|
11605
|
+
community(communityId) {
|
|
11606
|
+
return new CommunityNotifications(communityId);
|
|
11607
|
+
}
|
|
11608
|
+
channel(channelId) {
|
|
11609
|
+
return new ChannelNotifications(channelId);
|
|
11610
|
+
}
|
|
11611
|
+
}
|
|
11612
|
+
const notifications = () => new Notifications();
|
|
11613
|
+
|
|
11614
|
+
/* begin_public_function
|
|
11615
|
+
id: client.enable_auto_subscriptions
|
|
11616
|
+
*/
|
|
11617
|
+
/**
|
|
11618
|
+
* ```js
|
|
11619
|
+
* import { Client, AmityAutoSubscription } from '@amityco/ts-sdk'
|
|
11620
|
+
* Client.enableAutoSubscriptions([AmityAutoSubscription.BLOCK])
|
|
11621
|
+
* ```
|
|
11622
|
+
*
|
|
11623
|
+
* Enables one or more managed auto-subscription handles. Managed handles are
|
|
11624
|
+
* re-applied on every (re)connect and ref-counted. All handles are on by
|
|
11625
|
+
* default; use this to re-enable handles previously turned off via
|
|
11626
|
+
* {@link disableAutoSubscriptions}. Synchronous fire-and-forget — the registry
|
|
11627
|
+
* updates immediately and the broker subscribe is retried on reconnect.
|
|
11628
|
+
*
|
|
11629
|
+
* @param features the {@link AmityAutoSubscription} handles to enable
|
|
11630
|
+
*
|
|
11631
|
+
* @category Client API
|
|
11632
|
+
*/
|
|
11633
|
+
const enableAutoSubscriptions = (features) => {
|
|
11634
|
+
const manager = getAutoSubscriptionManager();
|
|
11635
|
+
features.forEach(feature => manager.subscribe(feature));
|
|
11636
|
+
};
|
|
11637
|
+
/* end_public_function */
|
|
11638
|
+
/* begin_public_function
|
|
11639
|
+
id: client.disable_auto_subscriptions
|
|
11640
|
+
*/
|
|
11641
|
+
/**
|
|
11642
|
+
* ```js
|
|
11643
|
+
* import { Client, AmityAutoSubscription } from '@amityco/ts-sdk'
|
|
11644
|
+
* Client.disableAutoSubscriptions([AmityAutoSubscription.LIVESTREAM])
|
|
11645
|
+
* ```
|
|
11646
|
+
*
|
|
11647
|
+
* Disables one or more managed auto-subscription handles. The change persists
|
|
11648
|
+
* across reconnect (it is not silently re-enabled) until
|
|
11649
|
+
* {@link enableAutoSubscriptions} is called again. Synchronous fire-and-forget.
|
|
11650
|
+
*
|
|
11651
|
+
* @param features the {@link AmityAutoSubscription} handles to disable
|
|
11652
|
+
*
|
|
11653
|
+
* @category Client API
|
|
11654
|
+
*/
|
|
11655
|
+
const disableAutoSubscriptions = (features) => {
|
|
11656
|
+
const manager = getAutoSubscriptionManager();
|
|
11657
|
+
features.forEach(feature => manager.unsubscribe(feature));
|
|
11658
|
+
};
|
|
11659
|
+
/* end_public_function */
|
|
11660
|
+
/* begin_public_function
|
|
11661
|
+
id: client.auto_subscriptions
|
|
11662
|
+
*/
|
|
11663
|
+
/**
|
|
11664
|
+
* ```js
|
|
11665
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
11666
|
+
* Client.autoSubscriptions().forEach(s => console.log(s.feature, s.isActive, s.topicCount))
|
|
11667
|
+
* ```
|
|
11668
|
+
*
|
|
11669
|
+
* Inspects the managed auto-subscription registry — each handle's `isActive`,
|
|
11670
|
+
* `isSystem`, and `topicCount`.
|
|
11671
|
+
*
|
|
11672
|
+
* @returns a snapshot of the managed subscription registry
|
|
11673
|
+
*
|
|
11674
|
+
* @category Client API
|
|
11675
|
+
*/
|
|
11676
|
+
const autoSubscriptions = () => getAutoSubscriptionManager().subscriptions();
|
|
11677
|
+
/* end_public_function */
|
|
11678
|
+
|
|
10861
11679
|
/**
|
|
10862
11680
|
* ```js
|
|
10863
11681
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -11238,6 +12056,12 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11238
12056
|
getCurrentUserType: getCurrentUserType,
|
|
11239
12057
|
setCurrentUserType: setCurrentUserType,
|
|
11240
12058
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
12059
|
+
getChatSettings: getChatSettings,
|
|
12060
|
+
getCoreUserSettings: getCoreUserSettings,
|
|
12061
|
+
notifications: notifications,
|
|
12062
|
+
enableAutoSubscriptions: enableAutoSubscriptions,
|
|
12063
|
+
disableAutoSubscriptions: disableAutoSubscriptions,
|
|
12064
|
+
autoSubscriptions: autoSubscriptions,
|
|
11241
12065
|
onConnectionError: onConnectionError,
|
|
11242
12066
|
onClientDisconnected: onClientDisconnected,
|
|
11243
12067
|
onClientBanned: onClientBanned,
|
|
@@ -11255,19 +12079,6 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11255
12079
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
11256
12080
|
});
|
|
11257
12081
|
|
|
11258
|
-
function prepareFollowersPayload(response) {
|
|
11259
|
-
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
11260
|
-
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
11261
|
-
}
|
|
11262
|
-
function prepareFollowingsPayload(response) {
|
|
11263
|
-
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
11264
|
-
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
11265
|
-
}
|
|
11266
|
-
function prepareFollowStatusPayload(response) {
|
|
11267
|
-
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
11268
|
-
return Object.assign(Object.assign({}, rest), { follows });
|
|
11269
|
-
}
|
|
11270
|
-
|
|
11271
12082
|
/* begin_public_function
|
|
11272
12083
|
id: user.relationship.block
|
|
11273
12084
|
*/
|
|
@@ -12445,6 +13256,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
12445
13256
|
__proto__: null,
|
|
12446
13257
|
blockUser: blockUser,
|
|
12447
13258
|
unBlockUser: unBlockUser,
|
|
13259
|
+
onUserDidBlock: onUserDidBlock,
|
|
13260
|
+
onUserDidUnblock: onUserDidUnblock,
|
|
12448
13261
|
follow: follow,
|
|
12449
13262
|
unfollow: unfollow,
|
|
12450
13263
|
acceptMyFollower: acceptMyFollower,
|
|
@@ -13274,7 +14087,7 @@ const getWatchSessionStorage = () => {
|
|
|
13274
14087
|
return storageInstance;
|
|
13275
14088
|
};
|
|
13276
14089
|
|
|
13277
|
-
const privateKey = "
|
|
14090
|
+
const privateKey = "MIIEpQIBAAKCAQEAwAEc/oZgYIvKSUG/C3mONYLR4ZPgAjMEX4bJ+xqqakUDRtqlNO+eZs2blQ1Ko0DBkqPExyQezvjibH5W2UZBV5RaBTlTcNVKTToMBEGesAfaEcM3qUyQHxdbFYZv6P4sb14dcwxTQ8usmaV8ooiR1Fcaso5ZWYcZ8Hb46FbQ7OoVumsBtPWwfZ4f003o5VCl6AIM6lcLv9UDLlFVYhE+PeXpRHtfWlGqxMvqC9oinlwhL6nWv6VjQXW4nhcib72dPBzfHT7k/PMKto2SxALYdb68ENiAGuJLWi3AUHSyYCJK2w7wIlWfJUAI0v26ub10IpExr6D5QuW2577jjP93iwIDAQABAoIBAFWfqXhwIIatkFY+9Z1+ZcbDQimgsmMIsUiQaX6Lk7e0cxOj6czDlxYtVtaPiNtow2pLkjNkjkCqiP7tEHnwdK9DvylZOTa2R15NJpK3WLcTqVIGhsn/FL5owfvFah6zSsmXZParZm5zY9NZE03ALZhOB9/cz0e3kf/EbpfeL2mW7MApyiUt5i09ycchroOpcWp73ipIxvgigtZyUGFmsQicWhUs28F0D7w4Qfk76yG3nqXeb+BAMhCaIaa/k/aAxhiZG/ygEQWQrcC8gfe+jyicMAQPDEVS9YuUMGsLjIjKuVLZzp2xirQnhc2i2zVNEIvG6soprPOBEMQugzrtX5ECgYEA3b7KAbBIbDl1e4ZSCWhHdHkiWVZHaopsR/LhqDDNhXjWjq3AesgV6k0j9EdziMn/HmmOso0bz99GTV3JZf4A9ztTLumJlkHbdVtlgOqSjrFLj12rH9KXTheyIhWSpUmm8+WB1xasFbqpvJaGo7F3pd2Fqj1XR4mp5BO7c/t7LJ0CgYEA3aouEzXQ9THRKYocdfY69EI1Il1t/d/RSqqd9BxEjxBgxkM13ZiYIn/R4WW/nCUrlmhxG44Aa2Gob4Ahfsui2xKTg/g/3Zk/rAxAEGkfOLGoenaJMD41fH4wUq3FRYwkvnaMb9Hd6f/TlBHslIRa2NN58bSBGJCyBP2b59+2+EcCgYEAixDVRXvV37GlYUOa/XVdosk5Zoe6oDGRuQm0xbNdoUBoZvDHDvme7ONWEiQha/8qtVsD+CyQ7awcPfb8kK9c0bBt+bTS6d4BkTcxkEkMgtrkBVR8Nqfu5jXsLH4VCv4G61zbMhZw8+ut+az5YX2yCN7Frj9sFlxapMRPQmzMEe0CgYEAumsAzM8ZqNv4mAK65Mnr0rhLj1cbxcKRdUYACOgtEFQpzxN/HZnTeFAe5nx3pI3uFlRHq3DFEYnT6dHMWaJQmAULYpVIwMi9L6gtyJ9fzoI6uqMtxRDMUqKdaSsTGOY/kJ6KhQ/unXi1K3XXjR+yd1+C0q+HUm1+CYxvrZYLfskCgYEArsEy+IQOiqniJ0NE2vVUF+UK/IRZaic9YKcpov5Ot7Vvzm/MnnW4N1ljVskocETBWMmPUvNSExVjPebi+rxd8fa5kY8BJScPTzMFbunZn/wjtGdcM10qdlVQ9doG61A/9P3ezFKCfS4AvF/H/59LcSx2Bh28fp3/efiVIOpVd4Y=";
|
|
13278
14091
|
/*
|
|
13279
14092
|
* The crypto algorithm used for importing key and signing string
|
|
13280
14093
|
*/
|
|
@@ -14596,6 +15409,10 @@ const postLinkedObject = (post) => {
|
|
|
14596
15409
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
14597
15410
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
14598
15411
|
},
|
|
15412
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
15413
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
15414
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
15415
|
+
},
|
|
14599
15416
|
},
|
|
14600
15417
|
get productTags() {
|
|
14601
15418
|
var _a, _b;
|
|
@@ -14785,6 +15602,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
14785
15602
|
});
|
|
14786
15603
|
return true;
|
|
14787
15604
|
}
|
|
15605
|
+
if (referenceType === 'message') {
|
|
15606
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15607
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15608
|
+
return true;
|
|
15609
|
+
}
|
|
14788
15610
|
}
|
|
14789
15611
|
return true;
|
|
14790
15612
|
};
|
|
@@ -14863,7 +15685,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14863
15685
|
return true;
|
|
14864
15686
|
}
|
|
14865
15687
|
if (referenceType === 'story') {
|
|
14866
|
-
fireEvent('local.story.
|
|
15688
|
+
fireEvent('local.story.reactionRemoved', {
|
|
14867
15689
|
story: updatedModel,
|
|
14868
15690
|
reactor: {
|
|
14869
15691
|
userId: client.userId,
|
|
@@ -14873,6 +15695,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14873
15695
|
});
|
|
14874
15696
|
return true;
|
|
14875
15697
|
}
|
|
15698
|
+
if (referenceType === 'message') {
|
|
15699
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15700
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15701
|
+
return true;
|
|
15702
|
+
}
|
|
14876
15703
|
}
|
|
14877
15704
|
return true;
|
|
14878
15705
|
};
|
|
@@ -15145,7 +15972,7 @@ const createEventResponseSubscriber = (event, callback) => {
|
|
|
15145
15972
|
const eventResponse = pullFromCache([
|
|
15146
15973
|
'eventResponse',
|
|
15147
15974
|
'get',
|
|
15148
|
-
|
|
15975
|
+
unpackedPayload.eventResponses[0].userId,
|
|
15149
15976
|
]);
|
|
15150
15977
|
callback(eventResponse.data);
|
|
15151
15978
|
}
|
|
@@ -15809,7 +16636,38 @@ const getAllBlockedUsers = async () => {
|
|
|
15809
16636
|
const engine = BlockedUserSyncEngine$1.getInstance();
|
|
15810
16637
|
// Ensure data is fetched (no-op if cache is fresh)
|
|
15811
16638
|
await engine.ensureFetched();
|
|
15812
|
-
|
|
16639
|
+
return engine.getCachedUsers();
|
|
16640
|
+
};
|
|
16641
|
+
/* end_public_function */
|
|
16642
|
+
|
|
16643
|
+
/* begin_public_function
|
|
16644
|
+
id: user.get_all_blocking_users
|
|
16645
|
+
*/
|
|
16646
|
+
/**
|
|
16647
|
+
* ```js
|
|
16648
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16649
|
+
* const blockingUsers = await UserRepository.getAllBlockingUsers()
|
|
16650
|
+
* ```
|
|
16651
|
+
*
|
|
16652
|
+
* Returns all users who have blocked the current user
|
|
16653
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window). Within the
|
|
16654
|
+
* TTL window, subsequent calls resolve instantly from the local store without any
|
|
16655
|
+
* server call. After the TTL expires, the next call triggers a fresh server fetch.
|
|
16656
|
+
*
|
|
16657
|
+
* The directional inverse of {@link getAllBlockedUsers}.
|
|
16658
|
+
*
|
|
16659
|
+
* @returns A promise that resolves to an array of blocking {@link Amity.User} objects
|
|
16660
|
+
*
|
|
16661
|
+
* @category Block API
|
|
16662
|
+
* @async
|
|
16663
|
+
*/
|
|
16664
|
+
const getAllBlockingUsers = async () => {
|
|
16665
|
+
const client = getActiveClient();
|
|
16666
|
+
client.log('user/getAllBlockingUsers');
|
|
16667
|
+
const engine = BlockingUserSyncEngine$1.getInstance();
|
|
16668
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16669
|
+
await engine.ensureFetched();
|
|
16670
|
+
// Read from the engine's bounded ID list — O(blocking users) not O(cache size)
|
|
15813
16671
|
return engine.getCachedUsers();
|
|
15814
16672
|
};
|
|
15815
16673
|
/* end_public_function */
|
|
@@ -16124,75 +16982,271 @@ class UserLiveCollectionController extends LiveCollectionController {
|
|
|
16124
16982
|
}
|
|
16125
16983
|
applyFilter(data) {
|
|
16126
16984
|
let users = data;
|
|
16127
|
-
const sortFn = (() => {
|
|
16128
|
-
switch (this.query.sortBy) {
|
|
16129
|
-
case 'firstCreated':
|
|
16130
|
-
return sortByFirstCreated;
|
|
16131
|
-
case 'lastCreated':
|
|
16132
|
-
return sortByLastCreated;
|
|
16133
|
-
default:
|
|
16134
|
-
return sortByLastCreated;
|
|
16135
|
-
}
|
|
16136
|
-
})();
|
|
16137
|
-
users = users.sort(sortFn);
|
|
16138
|
-
if (this.query.filter === 'flagged') {
|
|
16139
|
-
users = users.filter(user => !!user.hashFlag);
|
|
16140
|
-
}
|
|
16985
|
+
const sortFn = (() => {
|
|
16986
|
+
switch (this.query.sortBy) {
|
|
16987
|
+
case 'firstCreated':
|
|
16988
|
+
return sortByFirstCreated;
|
|
16989
|
+
case 'lastCreated':
|
|
16990
|
+
return sortByLastCreated;
|
|
16991
|
+
default:
|
|
16992
|
+
return sortByLastCreated;
|
|
16993
|
+
}
|
|
16994
|
+
})();
|
|
16995
|
+
users = users.sort(sortFn);
|
|
16996
|
+
if (this.query.filter === 'flagged') {
|
|
16997
|
+
users = users.filter(user => !!user.hashFlag);
|
|
16998
|
+
}
|
|
16999
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
17000
|
+
return users;
|
|
17001
|
+
}
|
|
17002
|
+
}
|
|
17003
|
+
|
|
17004
|
+
/* begin_public_function
|
|
17005
|
+
id: user.query
|
|
17006
|
+
*/
|
|
17007
|
+
/**
|
|
17008
|
+
* ```js
|
|
17009
|
+
* import { liveUsers } from '@amityco/ts-sdk'
|
|
17010
|
+
*
|
|
17011
|
+
* let users = []
|
|
17012
|
+
* const unsub = liveUsers({}, response => merge(users, response.data))
|
|
17013
|
+
* ```
|
|
17014
|
+
*
|
|
17015
|
+
* Observe all mutations on a list of {@link Amity.User}s
|
|
17016
|
+
*
|
|
17017
|
+
* @param params for querying users
|
|
17018
|
+
* @param callback the function to call when new data are available
|
|
17019
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the users
|
|
17020
|
+
*
|
|
17021
|
+
* @category Category Live Collection
|
|
17022
|
+
*/
|
|
17023
|
+
const getUsers = (params, callback, config) => {
|
|
17024
|
+
const { log, cache } = getActiveClient();
|
|
17025
|
+
if (!cache) {
|
|
17026
|
+
// eslint-disable-next-line no-console
|
|
17027
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
17028
|
+
}
|
|
17029
|
+
const timestamp = Date.now();
|
|
17030
|
+
log(`liveUsers(tmpid: ${timestamp}) > listen`);
|
|
17031
|
+
const usersLiveCollection = new UserLiveCollectionController(params, callback);
|
|
17032
|
+
const disposers = usersLiveCollection.startSubscription();
|
|
17033
|
+
const cacheKey = usersLiveCollection.getCacheKey();
|
|
17034
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
17035
|
+
return () => {
|
|
17036
|
+
log(`liveUsers(tmpid: ${timestamp}) > dispose`);
|
|
17037
|
+
disposers.forEach(fn => fn());
|
|
17038
|
+
};
|
|
17039
|
+
};
|
|
17040
|
+
/* end_public_function */
|
|
17041
|
+
|
|
17042
|
+
class BlockedUserPaginationController extends PaginationController {
|
|
17043
|
+
async getRequest(queryParams, token) {
|
|
17044
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
17045
|
+
const options = token ? { token } : { limit };
|
|
17046
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
17047
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
17048
|
+
});
|
|
17049
|
+
return queryResponse;
|
|
17050
|
+
}
|
|
17051
|
+
}
|
|
17052
|
+
|
|
17053
|
+
var EnumBlockActions;
|
|
17054
|
+
(function (EnumBlockActions) {
|
|
17055
|
+
EnumBlockActions["OnBlocked"] = "onBlocked";
|
|
17056
|
+
EnumBlockActions["OnUnblocked"] = "onUnblocked";
|
|
17057
|
+
})(EnumBlockActions || (EnumBlockActions = {}));
|
|
17058
|
+
|
|
17059
|
+
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
17060
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
17061
|
+
super(query, cacheKey);
|
|
17062
|
+
this.notifyChange = notifyChange;
|
|
17063
|
+
this.preparePayload = preparePayload;
|
|
17064
|
+
}
|
|
17065
|
+
async saveToMainDB(response) {
|
|
17066
|
+
const processedPayload = await this.preparePayload(response);
|
|
17067
|
+
const client = getActiveClient();
|
|
17068
|
+
const cachedAt = client.cache && Date.now();
|
|
17069
|
+
if (client.cache) {
|
|
17070
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
17071
|
+
}
|
|
17072
|
+
}
|
|
17073
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
17074
|
+
var _a, _b;
|
|
17075
|
+
if (refresh) {
|
|
17076
|
+
pushToCache(this.cacheKey, {
|
|
17077
|
+
data: response.users.map(getResolver('user')),
|
|
17078
|
+
});
|
|
17079
|
+
}
|
|
17080
|
+
else {
|
|
17081
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17082
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17083
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
17084
|
+
}
|
|
17085
|
+
}
|
|
17086
|
+
reactor(action) {
|
|
17087
|
+
return (targetUser) => {
|
|
17088
|
+
var _a, _b;
|
|
17089
|
+
const isRemoval = action === EnumFollowActions.OnFollowed || action === EnumBlockActions.OnUnblocked;
|
|
17090
|
+
const isAddition = action === EnumBlockActions.OnBlocked;
|
|
17091
|
+
if (isRemoval || isAddition) {
|
|
17092
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17093
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17094
|
+
const data = isAddition
|
|
17095
|
+
? [...new Set([...ids, targetUser.userId])]
|
|
17096
|
+
: ids.filter(id => id !== targetUser.userId);
|
|
17097
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
17098
|
+
}
|
|
17099
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17100
|
+
};
|
|
17101
|
+
}
|
|
17102
|
+
subscribeRTE(createSubscriber) {
|
|
17103
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
17104
|
+
}
|
|
17105
|
+
}
|
|
17106
|
+
|
|
17107
|
+
const convertEventPayload = (eventHandler, sourceModelProp, destinationDomain) => (callback) => eventHandler(sourceModel => {
|
|
17108
|
+
var _a;
|
|
17109
|
+
if (!sourceModel) {
|
|
17110
|
+
return sourceModel;
|
|
17111
|
+
}
|
|
17112
|
+
const cacheKey = [destinationDomain, 'get', `${sourceModel[sourceModelProp]}`];
|
|
17113
|
+
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17114
|
+
if (!model)
|
|
17115
|
+
return;
|
|
17116
|
+
return callback(model);
|
|
17117
|
+
});
|
|
17118
|
+
|
|
17119
|
+
class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
17120
|
+
constructor(query, callback) {
|
|
17121
|
+
const queryStreamId = hash__default["default"](query);
|
|
17122
|
+
const cacheKey = ['blockedUsers', 'collection', queryStreamId];
|
|
17123
|
+
const paginationController = new BlockedUserPaginationController(query);
|
|
17124
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
17125
|
+
this.query = query;
|
|
17126
|
+
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
17127
|
+
this.callback = callback.bind(this);
|
|
17128
|
+
this.loadPage({ initial: true });
|
|
17129
|
+
}
|
|
17130
|
+
setup() {
|
|
17131
|
+
var _a;
|
|
17132
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17133
|
+
if (!collection) {
|
|
17134
|
+
pushToCache(this.cacheKey, {
|
|
17135
|
+
data: [],
|
|
17136
|
+
params: {},
|
|
17137
|
+
});
|
|
17138
|
+
}
|
|
17139
|
+
}
|
|
17140
|
+
async persistModel(queryPayload) {
|
|
17141
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
17142
|
+
}
|
|
17143
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
17144
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
17145
|
+
}
|
|
17146
|
+
startSubscription() {
|
|
17147
|
+
return this.queryStreamController.subscribeRTE([
|
|
17148
|
+
{
|
|
17149
|
+
fn: onUserDeleted$2,
|
|
17150
|
+
action: EnumUserActions.OnUserDeleted,
|
|
17151
|
+
},
|
|
17152
|
+
{
|
|
17153
|
+
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
17154
|
+
action: EnumFollowActions.OnFollowed,
|
|
17155
|
+
},
|
|
17156
|
+
{
|
|
17157
|
+
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
17158
|
+
action: EnumFollowActions.OnFollowed,
|
|
17159
|
+
},
|
|
17160
|
+
{
|
|
17161
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
17162
|
+
var _a;
|
|
17163
|
+
if (status.from !== getActiveClient().userId)
|
|
17164
|
+
return;
|
|
17165
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17166
|
+
if (blocked)
|
|
17167
|
+
reactor(blocked);
|
|
17168
|
+
}),
|
|
17169
|
+
action: EnumBlockActions.OnBlocked,
|
|
17170
|
+
},
|
|
17171
|
+
{
|
|
17172
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
17173
|
+
var _a;
|
|
17174
|
+
if (status.from !== getActiveClient().userId)
|
|
17175
|
+
return;
|
|
17176
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17177
|
+
if (blocked)
|
|
17178
|
+
reactor(blocked);
|
|
17179
|
+
}),
|
|
17180
|
+
action: EnumBlockActions.OnUnblocked,
|
|
17181
|
+
},
|
|
17182
|
+
]);
|
|
17183
|
+
}
|
|
17184
|
+
notifyChange({ origin, loading, error }) {
|
|
17185
|
+
var _a, _b;
|
|
17186
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17187
|
+
if (!collection)
|
|
17188
|
+
return;
|
|
17189
|
+
const data = this.applyFilter((_b = collection.data
|
|
17190
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
17191
|
+
.filter(isNonNullable)
|
|
17192
|
+
.map(({ data }) => data)
|
|
17193
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
17194
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
17195
|
+
return;
|
|
17196
|
+
this.callback({
|
|
17197
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
17198
|
+
data,
|
|
17199
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
17200
|
+
loading,
|
|
17201
|
+
error,
|
|
17202
|
+
});
|
|
17203
|
+
}
|
|
17204
|
+
// eslint-disable-next-line class-methods-use-this
|
|
17205
|
+
applyFilter(data) {
|
|
17206
|
+
let users = data;
|
|
16141
17207
|
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
16142
17208
|
return users;
|
|
16143
17209
|
}
|
|
16144
17210
|
}
|
|
16145
17211
|
|
|
16146
17212
|
/* begin_public_function
|
|
16147
|
-
id: user.
|
|
17213
|
+
id: user.get_blocked_users
|
|
16148
17214
|
*/
|
|
16149
17215
|
/**
|
|
16150
17216
|
* ```js
|
|
16151
|
-
* import {
|
|
16152
|
-
*
|
|
16153
|
-
* let users = []
|
|
16154
|
-
* const unsub = liveUsers({}, response => merge(users, response.data))
|
|
17217
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
17218
|
+
* const unblockedUser = await UserRepository.blockUser('userId')
|
|
16155
17219
|
* ```
|
|
16156
17220
|
*
|
|
16157
|
-
*
|
|
17221
|
+
* Blocks a {@link Amity.User}
|
|
16158
17222
|
*
|
|
16159
|
-
* @param params
|
|
16160
|
-
* @param callback
|
|
16161
|
-
* @returns
|
|
17223
|
+
* @param params The params to get blocked {@link Amity.User}s
|
|
17224
|
+
* @param callback to recieve updates on unblocked {@link Amity.User}s
|
|
17225
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
16162
17226
|
*
|
|
16163
|
-
* @category
|
|
17227
|
+
* @category Post API
|
|
17228
|
+
* @async
|
|
16164
17229
|
*/
|
|
16165
|
-
const
|
|
17230
|
+
const getBlockedUsers = (params, callback, config) => {
|
|
16166
17231
|
const { log, cache } = getActiveClient();
|
|
16167
17232
|
if (!cache) {
|
|
16168
|
-
// eslint-disable-next-line no-console
|
|
16169
17233
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
16170
17234
|
}
|
|
16171
17235
|
const timestamp = Date.now();
|
|
16172
|
-
log(`
|
|
16173
|
-
const
|
|
16174
|
-
const disposers =
|
|
16175
|
-
const cacheKey =
|
|
17236
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > listen`);
|
|
17237
|
+
const blockedUserLiveCollection = new BlockedUserLiveCollectionController(params, callback);
|
|
17238
|
+
const disposers = blockedUserLiveCollection.startSubscription();
|
|
17239
|
+
const cacheKey = blockedUserLiveCollection.getCacheKey();
|
|
16176
17240
|
disposers.push(() => dropFromCache(cacheKey));
|
|
16177
17241
|
return () => {
|
|
16178
|
-
log(`
|
|
17242
|
+
log(`getBlockedUsers(tmpid: ${timestamp}) > dispose`);
|
|
16179
17243
|
disposers.forEach(fn => fn());
|
|
17244
|
+
dropFromCache(cacheKey);
|
|
16180
17245
|
};
|
|
16181
17246
|
};
|
|
16182
17247
|
/* end_public_function */
|
|
16183
17248
|
|
|
16184
|
-
class
|
|
16185
|
-
async getRequest(queryParams, token) {
|
|
16186
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
16187
|
-
const options = token ? { token } : { limit };
|
|
16188
|
-
const { data: queryResponse } = await this.http.get('/api/v4/me/user-blocks', {
|
|
16189
|
-
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
16190
|
-
});
|
|
16191
|
-
return queryResponse;
|
|
16192
|
-
}
|
|
16193
|
-
}
|
|
16194
|
-
|
|
16195
|
-
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
17249
|
+
class BlockingUserQueryStreamController extends QueryStreamController {
|
|
16196
17250
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
16197
17251
|
super(query, cacheKey);
|
|
16198
17252
|
this.notifyChange = notifyChange;
|
|
@@ -16220,12 +17274,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
16220
17274
|
}
|
|
16221
17275
|
}
|
|
16222
17276
|
reactor(action) {
|
|
16223
|
-
return (
|
|
16224
|
-
var _a;
|
|
16225
|
-
if (
|
|
17277
|
+
return (user) => {
|
|
17278
|
+
var _a, _b;
|
|
17279
|
+
if (user &&
|
|
17280
|
+
(action === EnumBlockActions.OnBlocked || action === EnumBlockActions.OnUnblocked)) {
|
|
16226
17281
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16227
|
-
const
|
|
16228
|
-
|
|
17282
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17283
|
+
const data = action === EnumBlockActions.OnBlocked
|
|
17284
|
+
? [...new Set([...ids, user.userId])]
|
|
17285
|
+
: ids.filter(id => id !== user.userId);
|
|
17286
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
16229
17287
|
}
|
|
16230
17288
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16231
17289
|
};
|
|
@@ -16235,26 +17293,25 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
16235
17293
|
}
|
|
16236
17294
|
}
|
|
16237
17295
|
|
|
16238
|
-
|
|
16239
|
-
|
|
16240
|
-
|
|
16241
|
-
|
|
17296
|
+
class BlockingUserPaginationController extends PaginationController {
|
|
17297
|
+
async getRequest(queryParams, token) {
|
|
17298
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
17299
|
+
const options = token ? { token } : { limit };
|
|
17300
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/blockers', {
|
|
17301
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
17302
|
+
});
|
|
17303
|
+
return queryResponse;
|
|
16242
17304
|
}
|
|
16243
|
-
|
|
16244
|
-
const model = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16245
|
-
if (!model)
|
|
16246
|
-
return;
|
|
16247
|
-
return callback(model);
|
|
16248
|
-
});
|
|
17305
|
+
}
|
|
16249
17306
|
|
|
16250
|
-
class
|
|
16251
|
-
constructor(
|
|
16252
|
-
const queryStreamId =
|
|
16253
|
-
const
|
|
16254
|
-
const
|
|
17307
|
+
class BlockingUserLiveCollectionController extends LiveCollectionController {
|
|
17308
|
+
constructor(callback) {
|
|
17309
|
+
const queryStreamId = `blocking-users-${getActiveClient().userId}`;
|
|
17310
|
+
const query = {};
|
|
17311
|
+
const cacheKey = ['blockingUsers', 'collection', queryStreamId];
|
|
17312
|
+
const paginationController = new BlockingUserPaginationController(query);
|
|
16255
17313
|
super(paginationController, queryStreamId, cacheKey, callback);
|
|
16256
|
-
this.
|
|
16257
|
-
this.queryStreamController = new BlockedUserQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareBlockedUserPayload);
|
|
17314
|
+
this.queryStreamController = new BlockingUserQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), prepareBlockingUserPayload);
|
|
16258
17315
|
this.callback = callback.bind(this);
|
|
16259
17316
|
this.loadPage({ initial: true });
|
|
16260
17317
|
}
|
|
@@ -16280,14 +17337,27 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16280
17337
|
fn: onUserDeleted$2,
|
|
16281
17338
|
action: EnumUserActions.OnUserDeleted,
|
|
16282
17339
|
},
|
|
16283
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
16284
17340
|
{
|
|
16285
|
-
fn:
|
|
16286
|
-
|
|
17341
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
17342
|
+
var _a;
|
|
17343
|
+
if (status.to !== getActiveClient().userId)
|
|
17344
|
+
return;
|
|
17345
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17346
|
+
if (blocker)
|
|
17347
|
+
reactor(blocker);
|
|
17348
|
+
}),
|
|
17349
|
+
action: EnumBlockActions.OnBlocked,
|
|
16287
17350
|
},
|
|
16288
17351
|
{
|
|
16289
|
-
fn:
|
|
16290
|
-
|
|
17352
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
17353
|
+
var _a;
|
|
17354
|
+
if (status.to !== getActiveClient().userId)
|
|
17355
|
+
return;
|
|
17356
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17357
|
+
if (blocker)
|
|
17358
|
+
reactor(blocker);
|
|
17359
|
+
}),
|
|
17360
|
+
action: EnumBlockActions.OnUnblocked,
|
|
16291
17361
|
},
|
|
16292
17362
|
]);
|
|
16293
17363
|
}
|
|
@@ -16311,7 +17381,6 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16311
17381
|
error,
|
|
16312
17382
|
});
|
|
16313
17383
|
}
|
|
16314
|
-
// eslint-disable-next-line class-methods-use-this
|
|
16315
17384
|
applyFilter(data) {
|
|
16316
17385
|
let users = data;
|
|
16317
17386
|
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
@@ -16320,36 +17389,35 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16320
17389
|
}
|
|
16321
17390
|
|
|
16322
17391
|
/* begin_public_function
|
|
16323
|
-
id: user.
|
|
17392
|
+
id: user.get_blocking_users
|
|
16324
17393
|
*/
|
|
16325
17394
|
/**
|
|
16326
17395
|
* ```js
|
|
16327
17396
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16328
|
-
* const
|
|
17397
|
+
* const unsubscribe = UserRepository.getBlockingUsers(({ data: users }) => {
|
|
17398
|
+
* console.log(users)
|
|
17399
|
+
* })
|
|
16329
17400
|
* ```
|
|
16330
17401
|
*
|
|
16331
|
-
*
|
|
17402
|
+
* Observe the {@link Amity.User}s who have blocked the current user
|
|
16332
17403
|
*
|
|
16333
|
-
* @param
|
|
16334
|
-
* @param callback to recieve updates on unblocked {@link Amity.User}s
|
|
17404
|
+
* @param callback to receive updates on the blocking {@link Amity.User}s
|
|
16335
17405
|
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
16336
17406
|
*
|
|
16337
|
-
* @category
|
|
16338
|
-
* @async
|
|
17407
|
+
* @category User API
|
|
16339
17408
|
*/
|
|
16340
|
-
const
|
|
17409
|
+
const getBlockingUsers = (callback) => {
|
|
16341
17410
|
const { log, cache } = getActiveClient();
|
|
16342
|
-
if (!cache)
|
|
17411
|
+
if (!cache)
|
|
16343
17412
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
16344
|
-
}
|
|
16345
17413
|
const timestamp = Date.now();
|
|
16346
|
-
log(`
|
|
16347
|
-
const
|
|
16348
|
-
const disposers =
|
|
16349
|
-
const cacheKey =
|
|
17414
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > listen`);
|
|
17415
|
+
const blockingUserLiveCollection = new BlockingUserLiveCollectionController(callback);
|
|
17416
|
+
const disposers = blockingUserLiveCollection.startSubscription();
|
|
17417
|
+
const cacheKey = blockingUserLiveCollection.getCacheKey();
|
|
16350
17418
|
disposers.push(() => dropFromCache(cacheKey));
|
|
16351
17419
|
return () => {
|
|
16352
|
-
log(`
|
|
17420
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > dispose`);
|
|
16353
17421
|
disposers.forEach(fn => fn());
|
|
16354
17422
|
dropFromCache(cacheKey);
|
|
16355
17423
|
};
|
|
@@ -16622,6 +17690,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
16622
17690
|
unflagUser: unflagUser,
|
|
16623
17691
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
16624
17692
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
17693
|
+
getAllBlockingUsers: getAllBlockingUsers,
|
|
16625
17694
|
onUserUpdated: onUserUpdated,
|
|
16626
17695
|
onUserDeleted: onUserDeleted$2,
|
|
16627
17696
|
onUserFlagged: onUserFlagged,
|
|
@@ -16630,6 +17699,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
16630
17699
|
getUser: getUser,
|
|
16631
17700
|
getUsers: getUsers,
|
|
16632
17701
|
getBlockedUsers: getBlockedUsers,
|
|
17702
|
+
getBlockingUsers: getBlockingUsers,
|
|
16633
17703
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
16634
17704
|
getReachedUsers: getReachedUsers,
|
|
16635
17705
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
@@ -17796,7 +18866,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17796
18866
|
return true;
|
|
17797
18867
|
}
|
|
17798
18868
|
if (referenceType === 'story') {
|
|
17799
|
-
fireEvent('local.story.
|
|
18869
|
+
fireEvent('local.story.reactionRemoved', {
|
|
17800
18870
|
story: updatedModel,
|
|
17801
18871
|
reactor: {
|
|
17802
18872
|
userId: client.userId,
|
|
@@ -19380,6 +20450,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
19380
20450
|
};
|
|
19381
20451
|
/* end_public_function */
|
|
19382
20452
|
|
|
20453
|
+
/* begin_public_function
|
|
20454
|
+
id: channel.archive
|
|
20455
|
+
*/
|
|
20456
|
+
/**
|
|
20457
|
+
* ```js
|
|
20458
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20459
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
20460
|
+
* ```
|
|
20461
|
+
*
|
|
20462
|
+
* Archive a {@link Amity.Channel}.
|
|
20463
|
+
*
|
|
20464
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
20465
|
+
* @returns A success boolean
|
|
20466
|
+
*
|
|
20467
|
+
* @category Channel API
|
|
20468
|
+
* @async
|
|
20469
|
+
*/
|
|
20470
|
+
const archiveChannel = async (channelId) => {
|
|
20471
|
+
const client = getActiveClient();
|
|
20472
|
+
client.log('channel/archiveChannel', channelId);
|
|
20473
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20474
|
+
const archive = {
|
|
20475
|
+
channelId,
|
|
20476
|
+
archivedAt: new Date().toISOString(),
|
|
20477
|
+
};
|
|
20478
|
+
if (client.cache) {
|
|
20479
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
20480
|
+
}
|
|
20481
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
20482
|
+
};
|
|
20483
|
+
/* end_public_function */
|
|
20484
|
+
|
|
20485
|
+
/* begin_public_function
|
|
20486
|
+
id: channel.unarchive
|
|
20487
|
+
*/
|
|
20488
|
+
/**
|
|
20489
|
+
* ```js
|
|
20490
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20491
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
20492
|
+
* ```
|
|
20493
|
+
*
|
|
20494
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
20495
|
+
*
|
|
20496
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
20497
|
+
* @returns A success boolean
|
|
20498
|
+
*
|
|
20499
|
+
* @category Channel API
|
|
20500
|
+
* @async
|
|
20501
|
+
*/
|
|
20502
|
+
const unarchiveChannel = async (channelId) => {
|
|
20503
|
+
var _a;
|
|
20504
|
+
const client = getActiveClient();
|
|
20505
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
20506
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20507
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20508
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
20509
|
+
channelId,
|
|
20510
|
+
archivedAt: new Date().toISOString(),
|
|
20511
|
+
};
|
|
20512
|
+
if (client.cache) {
|
|
20513
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
20514
|
+
}
|
|
20515
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
20516
|
+
};
|
|
20517
|
+
/* end_public_function */
|
|
20518
|
+
|
|
20519
|
+
/* begin_public_function
|
|
20520
|
+
id: channel.archive.ids
|
|
20521
|
+
*/
|
|
20522
|
+
/**
|
|
20523
|
+
* ```js
|
|
20524
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20525
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
20526
|
+
* ```
|
|
20527
|
+
*
|
|
20528
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
20529
|
+
*
|
|
20530
|
+
* @category Channel API
|
|
20531
|
+
* @async
|
|
20532
|
+
*/
|
|
20533
|
+
const getArchivedChannelIds = async () => {
|
|
20534
|
+
var _a;
|
|
20535
|
+
const client = getActiveClient();
|
|
20536
|
+
client.log('channel/getArchivedChannelIds');
|
|
20537
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
20538
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
20539
|
+
if (client.cache) {
|
|
20540
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
20541
|
+
archives.forEach(archive => {
|
|
20542
|
+
if (!archive.channelId)
|
|
20543
|
+
return;
|
|
20544
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
20545
|
+
});
|
|
20546
|
+
}
|
|
20547
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
20548
|
+
};
|
|
20549
|
+
/* end_public_function */
|
|
20550
|
+
|
|
19383
20551
|
/**
|
|
19384
20552
|
* ```js
|
|
19385
20553
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -20758,6 +21926,160 @@ const getMessages = (params, callback, config) => {
|
|
|
20758
21926
|
};
|
|
20759
21927
|
/* end_public_function */
|
|
20760
21928
|
|
|
21929
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
21930
|
+
async getRequest(queryParams, token) {
|
|
21931
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
21932
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
21933
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
21934
|
+
params: {
|
|
21935
|
+
query,
|
|
21936
|
+
exactMatch,
|
|
21937
|
+
channelId,
|
|
21938
|
+
messageFeedId,
|
|
21939
|
+
userIds,
|
|
21940
|
+
tags,
|
|
21941
|
+
types,
|
|
21942
|
+
options,
|
|
21943
|
+
},
|
|
21944
|
+
});
|
|
21945
|
+
return queryResponse;
|
|
21946
|
+
}
|
|
21947
|
+
}
|
|
21948
|
+
|
|
21949
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
21950
|
+
constructor(query, cacheKey, notifyChange) {
|
|
21951
|
+
super(query, cacheKey);
|
|
21952
|
+
this.notifyChange = notifyChange;
|
|
21953
|
+
}
|
|
21954
|
+
async saveToMainDB(response) {
|
|
21955
|
+
var _a;
|
|
21956
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
21957
|
+
const client = getActiveClient();
|
|
21958
|
+
const cachedAt = client.cache && Date.now();
|
|
21959
|
+
if (client.cache) {
|
|
21960
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21961
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21962
|
+
response.channels.forEach(channel => {
|
|
21963
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
21964
|
+
});
|
|
21965
|
+
}
|
|
21966
|
+
}
|
|
21967
|
+
}
|
|
21968
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21969
|
+
var _a, _b;
|
|
21970
|
+
if (refresh) {
|
|
21971
|
+
pushToCache(this.cacheKey, {
|
|
21972
|
+
data: response.messages.map(getResolver('message')),
|
|
21973
|
+
});
|
|
21974
|
+
return;
|
|
21975
|
+
}
|
|
21976
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21977
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21978
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
21979
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
21980
|
+
? [...new Set([...incoming, ...existing])]
|
|
21981
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
21982
|
+
}
|
|
21983
|
+
}
|
|
21984
|
+
|
|
21985
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
21986
|
+
constructor(query, callback) {
|
|
21987
|
+
const queryStreamId = hash__default["default"](query);
|
|
21988
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
21989
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
21990
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21991
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
21992
|
+
this.callback = callback.bind(this);
|
|
21993
|
+
this.loadPage({ initial: true });
|
|
21994
|
+
}
|
|
21995
|
+
startSubscription() {
|
|
21996
|
+
return [];
|
|
21997
|
+
}
|
|
21998
|
+
notifyChange({ origin, loading, error }) {
|
|
21999
|
+
var _a, _b;
|
|
22000
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22001
|
+
if (!collection)
|
|
22002
|
+
return;
|
|
22003
|
+
const data = (_b = collection.data
|
|
22004
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
22005
|
+
.filter(isNonNullable)
|
|
22006
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
22007
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22008
|
+
return;
|
|
22009
|
+
this.callback({
|
|
22010
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22011
|
+
data,
|
|
22012
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22013
|
+
loading,
|
|
22014
|
+
error,
|
|
22015
|
+
});
|
|
22016
|
+
}
|
|
22017
|
+
setup() {
|
|
22018
|
+
var _a;
|
|
22019
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22020
|
+
if (!collection) {
|
|
22021
|
+
pushToCache(this.cacheKey, {
|
|
22022
|
+
data: [],
|
|
22023
|
+
params: {},
|
|
22024
|
+
});
|
|
22025
|
+
}
|
|
22026
|
+
}
|
|
22027
|
+
async persistModel(response) {
|
|
22028
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
22029
|
+
}
|
|
22030
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22031
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22032
|
+
}
|
|
22033
|
+
}
|
|
22034
|
+
|
|
22035
|
+
/* begin_public_function
|
|
22036
|
+
id: message.search
|
|
22037
|
+
*/
|
|
22038
|
+
/**
|
|
22039
|
+
* ```js
|
|
22040
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
22041
|
+
*
|
|
22042
|
+
* let messages = [];
|
|
22043
|
+
*
|
|
22044
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
22045
|
+
* { query: 'hello' },
|
|
22046
|
+
* response => merge(messages, response.data),
|
|
22047
|
+
* );
|
|
22048
|
+
* ```
|
|
22049
|
+
*
|
|
22050
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
22051
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
22052
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
22053
|
+
*
|
|
22054
|
+
* @param params Search parameters. `query` is required.
|
|
22055
|
+
* @param callback Called whenever new data are available.
|
|
22056
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
22057
|
+
*
|
|
22058
|
+
* @category Message Live Collection
|
|
22059
|
+
*/
|
|
22060
|
+
const searchMessage = (params, callback) => {
|
|
22061
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
22062
|
+
throw new Error('Query is required for message search');
|
|
22063
|
+
}
|
|
22064
|
+
const { log, cache } = getActiveClient();
|
|
22065
|
+
if (!cache) {
|
|
22066
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
22067
|
+
}
|
|
22068
|
+
const timestamp = Date.now();
|
|
22069
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
22070
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
22071
|
+
const disposers = controller.startSubscription();
|
|
22072
|
+
const cacheKey = controller.getCacheKey();
|
|
22073
|
+
disposers.push(() => {
|
|
22074
|
+
dropFromCache(cacheKey);
|
|
22075
|
+
});
|
|
22076
|
+
return () => {
|
|
22077
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
22078
|
+
disposers.forEach(fn => fn());
|
|
22079
|
+
};
|
|
22080
|
+
};
|
|
22081
|
+
/* end_public_function */
|
|
22082
|
+
|
|
20761
22083
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
20762
22084
|
__proto__: null,
|
|
20763
22085
|
createMessage: createMessage,
|
|
@@ -20783,6 +22105,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
20783
22105
|
onMessageFetched: onMessageFetched,
|
|
20784
22106
|
getMessage: getMessage,
|
|
20785
22107
|
getMessages: getMessages,
|
|
22108
|
+
searchMessage: searchMessage,
|
|
20786
22109
|
convertFromRaw: convertFromRaw$1,
|
|
20787
22110
|
prepareMessagePayload: prepareMessagePayload,
|
|
20788
22111
|
convertParams: convertParams,
|
|
@@ -21630,6 +22953,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21630
22953
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
21631
22954
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
21632
22955
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
22956
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
21633
22957
|
].includes(action)) {
|
|
21634
22958
|
if (Array.isArray(payload)) {
|
|
21635
22959
|
collection.data = [
|
|
@@ -21639,6 +22963,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21639
22963
|
else
|
|
21640
22964
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
21641
22965
|
}
|
|
22966
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
22967
|
+
const ids = Array.isArray(payload)
|
|
22968
|
+
? payload.map(getResolver('channel'))
|
|
22969
|
+
: [getResolver('channel')(payload)];
|
|
22970
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
22971
|
+
}
|
|
21642
22972
|
pushToCache(this.cacheKey, collection);
|
|
21643
22973
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21644
22974
|
};
|
|
@@ -21905,6 +23235,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21905
23235
|
},
|
|
21906
23236
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
21907
23237
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
23238
|
+
{
|
|
23239
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
23240
|
+
const channels = payload.archives
|
|
23241
|
+
.map(archive => {
|
|
23242
|
+
var _a;
|
|
23243
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23244
|
+
})
|
|
23245
|
+
.filter((c) => Boolean(c));
|
|
23246
|
+
if (channels.length > 0)
|
|
23247
|
+
reactor(channels);
|
|
23248
|
+
}),
|
|
23249
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23250
|
+
},
|
|
23251
|
+
{
|
|
23252
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
23253
|
+
const channels = payload.archives
|
|
23254
|
+
.map(archive => {
|
|
23255
|
+
var _a;
|
|
23256
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23257
|
+
})
|
|
23258
|
+
.filter((c) => Boolean(c));
|
|
23259
|
+
if (channels.length > 0)
|
|
23260
|
+
reactor(channels);
|
|
23261
|
+
}),
|
|
23262
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23263
|
+
},
|
|
21908
23264
|
{
|
|
21909
23265
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
21910
23266
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -22258,6 +23614,192 @@ const getTotalChannelsUnread = (callback) => {
|
|
|
22258
23614
|
};
|
|
22259
23615
|
};
|
|
22260
23616
|
|
|
23617
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
23618
|
+
async getRequest(queryParams, token) {
|
|
23619
|
+
var _a, _b;
|
|
23620
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
23621
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
23622
|
+
if (pageIndex === 0) {
|
|
23623
|
+
await getArchivedChannelIds();
|
|
23624
|
+
}
|
|
23625
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
23626
|
+
const archives = cached
|
|
23627
|
+
.map(entry => entry.data)
|
|
23628
|
+
.slice()
|
|
23629
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
23630
|
+
const start = pageIndex * limit;
|
|
23631
|
+
const end = start + limit;
|
|
23632
|
+
const slice = archives.slice(start, end);
|
|
23633
|
+
const hasMore = end < archives.length;
|
|
23634
|
+
if (slice.length > 0) {
|
|
23635
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
23636
|
+
}
|
|
23637
|
+
return {
|
|
23638
|
+
archives: slice,
|
|
23639
|
+
paging: {
|
|
23640
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
23641
|
+
previous: undefined,
|
|
23642
|
+
},
|
|
23643
|
+
};
|
|
23644
|
+
}
|
|
23645
|
+
}
|
|
23646
|
+
|
|
23647
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
23648
|
+
constructor(query, cacheKey, notifyChange) {
|
|
23649
|
+
super(query, cacheKey);
|
|
23650
|
+
this.notifyChange = notifyChange;
|
|
23651
|
+
}
|
|
23652
|
+
async saveToMainDB(_response) {
|
|
23653
|
+
//
|
|
23654
|
+
}
|
|
23655
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23656
|
+
var _a, _b;
|
|
23657
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
23658
|
+
if (refresh) {
|
|
23659
|
+
pushToCache(this.cacheKey, {
|
|
23660
|
+
data: channelIds,
|
|
23661
|
+
params: {},
|
|
23662
|
+
});
|
|
23663
|
+
return;
|
|
23664
|
+
}
|
|
23665
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23666
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23667
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
23668
|
+
? [...new Set([...channelIds, ...existing])]
|
|
23669
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
23670
|
+
}
|
|
23671
|
+
reactor(action) {
|
|
23672
|
+
return (channelIds) => {
|
|
23673
|
+
var _a;
|
|
23674
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23675
|
+
if (!collection)
|
|
23676
|
+
return;
|
|
23677
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
23678
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
23679
|
+
collection.data = [...channelIds, ...filtered];
|
|
23680
|
+
}
|
|
23681
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
23682
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
23683
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
23684
|
+
}
|
|
23685
|
+
pushToCache(this.cacheKey, collection);
|
|
23686
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23687
|
+
};
|
|
23688
|
+
}
|
|
23689
|
+
subscribeRTE(createSubscriber) {
|
|
23690
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23691
|
+
}
|
|
23692
|
+
}
|
|
23693
|
+
|
|
23694
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
23695
|
+
constructor(query, callback) {
|
|
23696
|
+
const queryStreamId = hash__default["default"](query);
|
|
23697
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
23698
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
23699
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23700
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
23701
|
+
this.callback = callback.bind(this);
|
|
23702
|
+
this.loadPage({ initial: true });
|
|
23703
|
+
}
|
|
23704
|
+
setup() {
|
|
23705
|
+
var _a;
|
|
23706
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23707
|
+
if (!collection) {
|
|
23708
|
+
pushToCache(this.cacheKey, {
|
|
23709
|
+
data: [],
|
|
23710
|
+
params: {},
|
|
23711
|
+
});
|
|
23712
|
+
}
|
|
23713
|
+
}
|
|
23714
|
+
async persistModel(response) {
|
|
23715
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
23716
|
+
}
|
|
23717
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23718
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23719
|
+
}
|
|
23720
|
+
startSubscription() {
|
|
23721
|
+
return this.queryStreamController.subscribeRTE([
|
|
23722
|
+
{
|
|
23723
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23724
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23725
|
+
},
|
|
23726
|
+
{
|
|
23727
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23728
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23729
|
+
},
|
|
23730
|
+
{
|
|
23731
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
23732
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
23733
|
+
},
|
|
23734
|
+
{
|
|
23735
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
23736
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
23737
|
+
},
|
|
23738
|
+
]);
|
|
23739
|
+
}
|
|
23740
|
+
notifyChange({ origin, loading, error }) {
|
|
23741
|
+
var _a, _b;
|
|
23742
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23743
|
+
if (!collection)
|
|
23744
|
+
return;
|
|
23745
|
+
const data = (_b = collection.data
|
|
23746
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
23747
|
+
.filter((entry) => Boolean(entry))
|
|
23748
|
+
.map(({ data: channel }) => channel)
|
|
23749
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
23750
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23751
|
+
return;
|
|
23752
|
+
this.callback({
|
|
23753
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23754
|
+
data,
|
|
23755
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23756
|
+
loading,
|
|
23757
|
+
error,
|
|
23758
|
+
});
|
|
23759
|
+
}
|
|
23760
|
+
}
|
|
23761
|
+
|
|
23762
|
+
/* begin_public_function
|
|
23763
|
+
id: channel.archive.collection
|
|
23764
|
+
*/
|
|
23765
|
+
/**
|
|
23766
|
+
* ```js
|
|
23767
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
23768
|
+
*
|
|
23769
|
+
* let channels = []
|
|
23770
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
23771
|
+
* ```
|
|
23772
|
+
*
|
|
23773
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
23774
|
+
*
|
|
23775
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
23776
|
+
* archive list takes no other filters).
|
|
23777
|
+
* @param callback the function to call when new data are available
|
|
23778
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
23779
|
+
* stop observing.
|
|
23780
|
+
*
|
|
23781
|
+
* @category Channel Live Collection
|
|
23782
|
+
*/
|
|
23783
|
+
const getArchivedChannels = (params, callback) => {
|
|
23784
|
+
const { log, cache } = getActiveClient();
|
|
23785
|
+
if (!cache) {
|
|
23786
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23787
|
+
}
|
|
23788
|
+
const timestamp = Date.now();
|
|
23789
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
23790
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
23791
|
+
const disposers = controller.startSubscription();
|
|
23792
|
+
const cacheKey = controller.getCacheKey();
|
|
23793
|
+
disposers.push(() => {
|
|
23794
|
+
dropFromCache(cacheKey);
|
|
23795
|
+
});
|
|
23796
|
+
return () => {
|
|
23797
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
23798
|
+
disposers.forEach(fn => fn());
|
|
23799
|
+
};
|
|
23800
|
+
};
|
|
23801
|
+
/* end_public_function */
|
|
23802
|
+
|
|
22261
23803
|
/* begin_public_function
|
|
22262
23804
|
id: channel.member.add
|
|
22263
23805
|
*/
|
|
@@ -22389,7 +23931,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
22389
23931
|
channelId: this.query.channelId,
|
|
22390
23932
|
userId: channelMember.userId,
|
|
22391
23933
|
});
|
|
22392
|
-
|
|
23934
|
+
const membershipFilter = this.query.memberships;
|
|
23935
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
23936
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
22393
23937
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
22394
23938
|
}
|
|
22395
23939
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -22725,6 +24269,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
22725
24269
|
const cachedAt = client.cache && Date.now();
|
|
22726
24270
|
if (client.cache)
|
|
22727
24271
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24272
|
+
fireEvent('channel.banned', payload);
|
|
22728
24273
|
return {
|
|
22729
24274
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
22730
24275
|
cachedAt,
|
|
@@ -22759,6 +24304,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
22759
24304
|
const cachedAt = client.cache && Date.now();
|
|
22760
24305
|
if (client.cache)
|
|
22761
24306
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24307
|
+
fireEvent('channel.unbanned', payload);
|
|
22762
24308
|
const { channelUsers } = preparedPayload;
|
|
22763
24309
|
return {
|
|
22764
24310
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -22787,6 +24333,7 @@ const MUTE_FOREVER = -1;
|
|
|
22787
24333
|
* @async
|
|
22788
24334
|
* */
|
|
22789
24335
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
24336
|
+
var _a;
|
|
22790
24337
|
const client = getActiveClient();
|
|
22791
24338
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
22792
24339
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -22794,6 +24341,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22794
24341
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
22795
24342
|
});
|
|
22796
24343
|
const { success } = data;
|
|
24344
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
24345
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
24346
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
24347
|
+
fireEvent('channel.setMutedUsers', {
|
|
24348
|
+
channelId,
|
|
24349
|
+
userIds,
|
|
24350
|
+
muteTimeout,
|
|
24351
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24352
|
+
});
|
|
22797
24353
|
return success;
|
|
22798
24354
|
};
|
|
22799
24355
|
/* end_public_function */
|
|
@@ -22816,6 +24372,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22816
24372
|
* @async
|
|
22817
24373
|
* */
|
|
22818
24374
|
const unmuteMembers = async (channelId, userIds) => {
|
|
24375
|
+
var _a;
|
|
22819
24376
|
const client = getActiveClient();
|
|
22820
24377
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
22821
24378
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -22823,6 +24380,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22823
24380
|
mutePeriod: 0,
|
|
22824
24381
|
});
|
|
22825
24382
|
const { success } = data;
|
|
24383
|
+
fireEvent('channel.setMutedUsers', {
|
|
24384
|
+
channelId,
|
|
24385
|
+
userIds,
|
|
24386
|
+
muteTimeout: new Date(0).toISOString(),
|
|
24387
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24388
|
+
});
|
|
22826
24389
|
return success;
|
|
22827
24390
|
};
|
|
22828
24391
|
/* end_public_function */
|
|
@@ -22849,6 +24412,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22849
24412
|
leaveChannel: leaveChannel,
|
|
22850
24413
|
muteChannel: muteChannel,
|
|
22851
24414
|
unmuteChannel: unmuteChannel,
|
|
24415
|
+
archiveChannel: archiveChannel,
|
|
24416
|
+
unarchiveChannel: unarchiveChannel,
|
|
24417
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
22852
24418
|
onChannelCreated: onChannelCreated,
|
|
22853
24419
|
onChannelUpdated: onChannelUpdated,
|
|
22854
24420
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -22861,9 +24427,12 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22861
24427
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
22862
24428
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
22863
24429
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
24430
|
+
onChannelArchived: onChannelArchived,
|
|
24431
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
22864
24432
|
getChannel: getChannel,
|
|
22865
24433
|
getChannels: getChannels,
|
|
22866
24434
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
24435
|
+
getArchivedChannels: getArchivedChannels,
|
|
22867
24436
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
22868
24437
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22869
24438
|
convertFromRaw: convertFromRaw,
|
|
@@ -26759,7 +28328,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26759
28328
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26760
28329
|
}
|
|
26761
28330
|
startSubscription() {
|
|
26762
|
-
|
|
28331
|
+
const disposers = this.queryStreamController.subscribeRTE([
|
|
26763
28332
|
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
26764
28333
|
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
26765
28334
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
@@ -26772,6 +28341,11 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26772
28341
|
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
26773
28342
|
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
26774
28343
|
]);
|
|
28344
|
+
if (this.query.excludeBlockUserComments) {
|
|
28345
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28346
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
28347
|
+
}
|
|
28348
|
+
return disposers;
|
|
26775
28349
|
}
|
|
26776
28350
|
notifyChange({ origin, loading, error }) {
|
|
26777
28351
|
var _a, _b;
|
|
@@ -26824,6 +28398,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26824
28398
|
comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
|
|
26825
28399
|
}
|
|
26826
28400
|
}
|
|
28401
|
+
if (this.query.excludeBlockUserComments) {
|
|
28402
|
+
comments = filterCommentsByBlockUsers(comments);
|
|
28403
|
+
}
|
|
26827
28404
|
switch (this.query.sortBy) {
|
|
26828
28405
|
case 'firstCreated':
|
|
26829
28406
|
comments = comments.sort(sortByFirstCreated);
|
|
@@ -27909,13 +29486,218 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
27909
29486
|
};
|
|
27910
29487
|
/* end_public_function */
|
|
27911
29488
|
|
|
29489
|
+
/**
|
|
29490
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
29491
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
29492
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
29493
|
+
*
|
|
29494
|
+
* @category Errors
|
|
29495
|
+
*/
|
|
29496
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
29497
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
29498
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29499
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
29500
|
+
}
|
|
29501
|
+
}
|
|
29502
|
+
|
|
29503
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
29504
|
+
constructor(query) {
|
|
29505
|
+
super(query);
|
|
29506
|
+
this.checkedDisk = false;
|
|
29507
|
+
this.cursor = CursorController.current();
|
|
29508
|
+
}
|
|
29509
|
+
async getRequest(_queryParams, token) {
|
|
29510
|
+
let effectiveToken = token;
|
|
29511
|
+
if (!effectiveToken && !this.checkedDisk && this.cursor) {
|
|
29512
|
+
this.checkedDisk = true;
|
|
29513
|
+
const stored = await this.cursor.get();
|
|
29514
|
+
if (stored && !CursorController.isExpired(stored.expiredAt)) {
|
|
29515
|
+
effectiveToken = stored.cursor;
|
|
29516
|
+
}
|
|
29517
|
+
else if (stored) {
|
|
29518
|
+
await this.cursor.clear();
|
|
29519
|
+
}
|
|
29520
|
+
}
|
|
29521
|
+
const options = {
|
|
29522
|
+
limit: COLLECTION_DEFAULT_PAGINATION_SIZE,
|
|
29523
|
+
};
|
|
29524
|
+
if (effectiveToken)
|
|
29525
|
+
options.token = effectiveToken;
|
|
29526
|
+
let queryResponse;
|
|
29527
|
+
try {
|
|
29528
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options } }));
|
|
29529
|
+
}
|
|
29530
|
+
catch (error) {
|
|
29531
|
+
if (error instanceof ASCApiError && error.code === 400300 /* Amity.ServerError.FORBIDDEN */) {
|
|
29532
|
+
throw new AmityForYouFeedDisabledError();
|
|
29533
|
+
}
|
|
29534
|
+
const recoverable = error instanceof ASCApiError && error.code === 400322 /* Amity.ServerError.FEED_SNAPSHOT_EXPIRED */;
|
|
29535
|
+
if (recoverable && effectiveToken !== undefined) {
|
|
29536
|
+
if (this.cursor)
|
|
29537
|
+
await this.cursor.clear();
|
|
29538
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } } }));
|
|
29539
|
+
}
|
|
29540
|
+
else {
|
|
29541
|
+
throw error;
|
|
29542
|
+
}
|
|
29543
|
+
}
|
|
29544
|
+
await this.persistCursor(queryResponse);
|
|
29545
|
+
return queryResponse;
|
|
29546
|
+
}
|
|
29547
|
+
async persistCursor(response) {
|
|
29548
|
+
var _a, _b;
|
|
29549
|
+
if (!this.cursor)
|
|
29550
|
+
return;
|
|
29551
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
29552
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
29553
|
+
if (!cursor || !expiredAtIso)
|
|
29554
|
+
return;
|
|
29555
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
29556
|
+
if (Number.isNaN(expiredAt))
|
|
29557
|
+
return;
|
|
29558
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
29559
|
+
}
|
|
29560
|
+
}
|
|
29561
|
+
|
|
29562
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
29563
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
29564
|
+
super(query, cacheKey);
|
|
29565
|
+
this.notifyChange = notifyChange;
|
|
29566
|
+
this.preparePayload = preparePayload;
|
|
29567
|
+
}
|
|
29568
|
+
async saveToMainDB(response) {
|
|
29569
|
+
const processedPayload = await this.preparePayload(response);
|
|
29570
|
+
const client = getActiveClient();
|
|
29571
|
+
const cachedAt = client.cache && Date.now();
|
|
29572
|
+
if (client.cache)
|
|
29573
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
29574
|
+
}
|
|
29575
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
29576
|
+
var _a, _b;
|
|
29577
|
+
if (refresh) {
|
|
29578
|
+
pushToCache(this.cacheKey, {
|
|
29579
|
+
data: response.posts.map(getResolver('post')),
|
|
29580
|
+
});
|
|
29581
|
+
}
|
|
29582
|
+
else {
|
|
29583
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29584
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
29585
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
29586
|
+
}
|
|
29587
|
+
}
|
|
29588
|
+
reactor(action) {
|
|
29589
|
+
return (post) => {
|
|
29590
|
+
var _a;
|
|
29591
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29592
|
+
if (!collection)
|
|
29593
|
+
return;
|
|
29594
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
29595
|
+
return;
|
|
29596
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
29597
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
29598
|
+
}
|
|
29599
|
+
pushToCache(this.cacheKey, collection);
|
|
29600
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
29601
|
+
};
|
|
29602
|
+
}
|
|
29603
|
+
subscribeRTE(createSubscriber) {
|
|
29604
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
29605
|
+
}
|
|
29606
|
+
}
|
|
29607
|
+
|
|
29608
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
29609
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
29610
|
+
constructor(callback) {
|
|
29611
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
29612
|
+
const query = {};
|
|
29613
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
29614
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
29615
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
29616
|
+
this.callback = callback.bind(this);
|
|
29617
|
+
this.loadPage({ initial: true });
|
|
29618
|
+
}
|
|
29619
|
+
setup() {
|
|
29620
|
+
var _a;
|
|
29621
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29622
|
+
if (!collection)
|
|
29623
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
29624
|
+
}
|
|
29625
|
+
async persistModel(payload) {
|
|
29626
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
29627
|
+
}
|
|
29628
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
29629
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
29630
|
+
}
|
|
29631
|
+
startSubscription() {
|
|
29632
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
29633
|
+
}
|
|
29634
|
+
notifyChange({ origin, loading, error }) {
|
|
29635
|
+
var _a, _b;
|
|
29636
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29637
|
+
if (!collection)
|
|
29638
|
+
return;
|
|
29639
|
+
const data = ((_b = collection.data
|
|
29640
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
29641
|
+
.filter(isNonNullable)
|
|
29642
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
29643
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
29644
|
+
return;
|
|
29645
|
+
this.callback({
|
|
29646
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
29647
|
+
data,
|
|
29648
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
29649
|
+
loading,
|
|
29650
|
+
error,
|
|
29651
|
+
});
|
|
29652
|
+
}
|
|
29653
|
+
}
|
|
29654
|
+
|
|
29655
|
+
/* begin_public_function
|
|
29656
|
+
id: feed.query.for_you_feed
|
|
29657
|
+
*/
|
|
29658
|
+
/**
|
|
29659
|
+
* ```js
|
|
29660
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
29661
|
+
*
|
|
29662
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
29663
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
29664
|
+
* })
|
|
29665
|
+
* ```
|
|
29666
|
+
*
|
|
29667
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
29668
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
29669
|
+
*
|
|
29670
|
+
* @param callback the function to call when new data is available
|
|
29671
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
29672
|
+
*
|
|
29673
|
+
* @category Posts Live Collection
|
|
29674
|
+
*/
|
|
29675
|
+
const getForYouFeed = (callback) => {
|
|
29676
|
+
const { log, cache } = getActiveClient();
|
|
29677
|
+
if (!cache)
|
|
29678
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
29679
|
+
const timestamp = Date.now();
|
|
29680
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
29681
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
29682
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
29683
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
29684
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
29685
|
+
return () => {
|
|
29686
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
29687
|
+
disposers.forEach(fn => fn());
|
|
29688
|
+
};
|
|
29689
|
+
};
|
|
29690
|
+
/* end_public_function */
|
|
29691
|
+
|
|
27912
29692
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
27913
29693
|
__proto__: null,
|
|
27914
29694
|
queryGlobalFeed: queryGlobalFeed,
|
|
27915
29695
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
27916
29696
|
getGlobalFeed: getGlobalFeed,
|
|
27917
29697
|
getUserFeed: getUserFeed,
|
|
27918
|
-
getCommunityFeed: getCommunityFeed
|
|
29698
|
+
getCommunityFeed: getCommunityFeed,
|
|
29699
|
+
getForYouFeed: getForYouFeed,
|
|
29700
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
27919
29701
|
});
|
|
27920
29702
|
|
|
27921
29703
|
/* begin_public_function
|
|
@@ -28928,7 +30710,12 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28928
30710
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28929
30711
|
}
|
|
28930
30712
|
startSubscription() {
|
|
28931
|
-
|
|
30713
|
+
const disposers = this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
30714
|
+
if (this.query.excludeBlockUserPosts) {
|
|
30715
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30716
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
30717
|
+
}
|
|
30718
|
+
return disposers;
|
|
28932
30719
|
}
|
|
28933
30720
|
notifyChange({ origin, loading, error }) {
|
|
28934
30721
|
var _a, _b;
|
|
@@ -28974,6 +30761,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28974
30761
|
const sortBy = this.query.sortBy || 'lastCreated';
|
|
28975
30762
|
posts = posts.filter(post => !exceedsUntilAtBoundary(post.createdAt, validatedUntilAt, sortBy));
|
|
28976
30763
|
}
|
|
30764
|
+
if (this.query.excludeBlockUserPosts) {
|
|
30765
|
+
posts = filterPostsByBlockUsers(posts);
|
|
30766
|
+
}
|
|
28977
30767
|
switch (this.query.sortBy) {
|
|
28978
30768
|
case 'firstCreated':
|
|
28979
30769
|
posts = posts.sort(sortByFirstCreated);
|
|
@@ -35696,6 +37486,9 @@ exports.filterByPropIntersection = filterByPropIntersection;
|
|
|
35696
37486
|
exports.filterBySearchTerm = filterBySearchTerm;
|
|
35697
37487
|
exports.filterByStringComparePartially = filterByStringComparePartially;
|
|
35698
37488
|
exports.filterByUntilAt = filterByUntilAt;
|
|
37489
|
+
exports.filterCommentsByBlockUsers = filterCommentsByBlockUsers;
|
|
37490
|
+
exports.filterPostsByBlockUsers = filterPostsByBlockUsers;
|
|
37491
|
+
exports.getBlockUsersId = getBlockUsersId;
|
|
35699
37492
|
exports.getChannelTopic = getChannelTopic;
|
|
35700
37493
|
exports.getCommentTopic = getCommentTopic;
|
|
35701
37494
|
exports.getCommunityStoriesTopic = getCommunityStoriesTopic;
|
|
@@ -35707,6 +37500,7 @@ exports.getMarkerUserFeedTopic = getMarkerUserFeedTopic;
|
|
|
35707
37500
|
exports.getMessageTopic = getMessageTopic;
|
|
35708
37501
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
35709
37502
|
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
37503
|
+
exports.getNetworkId = getNetworkId;
|
|
35710
37504
|
exports.getNetworkTopic = getNetworkTopic;
|
|
35711
37505
|
exports.getPostTopic = getPostTopic;
|
|
35712
37506
|
exports.getRole = getRole;
|