@amityco/ts-sdk 7.22.0 → 7.22.1-0aa28d6.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 +3 -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 +15 -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 +31 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +31 -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 +2 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts +14 -0
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/searchChannels/SearchChannelPaginationController.d.ts +10 -0
- package/dist/channelRepository/observers/searchChannels/SearchChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/searchChannels/SearchChannelQueryStreamController.d.ts +13 -0
- package/dist/channelRepository/observers/searchChannels/SearchChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/searchChannels.d.ts +21 -0
- package/dist/channelRepository/observers/searchChannels.d.ts.map +1 -0
- package/dist/channelRepository/observers/tests/integrations/searchChannels.integration.test.d.ts +2 -0
- package/dist/channelRepository/observers/tests/integrations/searchChannels.integration.test.d.ts.map +1 -0
- 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/getForYouFeedSetting.d.ts +17 -0
- package/dist/client/api/getForYouFeedSetting.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 +5 -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 +19 -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 +13 -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 +2700 -429
- package/dist/index.esm.js +2697 -430
- 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,11 +6061,7 @@ getSubChannel$1.locally = (subChannelId) => {
|
|
|
5787
6061
|
};
|
|
5788
6062
|
};
|
|
5789
6063
|
|
|
5790
|
-
const
|
|
5791
|
-
return new Date(dateString).getTime();
|
|
5792
|
-
};
|
|
5793
|
-
|
|
5794
|
-
const getMessagePreviewSetting$1 = async () => {
|
|
6064
|
+
const getMessagePreviewSetting$2 = async () => {
|
|
5795
6065
|
const client = getActiveClient();
|
|
5796
6066
|
return client.getMessagePreviewSetting(false);
|
|
5797
6067
|
};
|
|
@@ -5826,7 +6096,7 @@ const isLastestMessageOnChannel = (message) => {
|
|
|
5826
6096
|
convertDateStringToTimestamp(cache.createdAt) <= convertDateStringToTimestamp(message.createdAt));
|
|
5827
6097
|
};
|
|
5828
6098
|
const handleMessageCreatedOnSubChannel = async (message) => {
|
|
5829
|
-
const messagePreviewSetting = await getMessagePreviewSetting$
|
|
6099
|
+
const messagePreviewSetting = await getMessagePreviewSetting$2();
|
|
5830
6100
|
const { channelId, messageId: messagePreviewId, creatorId, createdAt, updatedAt, data, dataType, subChannelId, channelSegment: segment, isDeleted, } = message;
|
|
5831
6101
|
// 1. get subChannel from cache, if not exist fetch from server
|
|
5832
6102
|
const subChannelCache = await getSubChannelCache(subChannelId);
|
|
@@ -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);
|
|
@@ -7162,7 +7447,7 @@ const convertMessagePreviewSetting = (chatSetting) => {
|
|
|
7162
7447
|
* @category private
|
|
7163
7448
|
* @async
|
|
7164
7449
|
*/
|
|
7165
|
-
const getMessagePreviewSetting = async (refresh = true) => {
|
|
7450
|
+
const getMessagePreviewSetting$1 = async (refresh = true) => {
|
|
7166
7451
|
var _a;
|
|
7167
7452
|
const messagePreviewSetting = (_a = pullFromCache([
|
|
7168
7453
|
'MessagePreviewSetting',
|
|
@@ -7183,7 +7468,7 @@ const getMessagePreviewSetting = async (refresh = true) => {
|
|
|
7183
7468
|
*/
|
|
7184
7469
|
const initializeMessagePreviewSetting = async () => {
|
|
7185
7470
|
var _a;
|
|
7186
|
-
const newMessagePreviewSetting = await getMessagePreviewSetting();
|
|
7471
|
+
const newMessagePreviewSetting = await getMessagePreviewSetting$1();
|
|
7187
7472
|
const messagePreviewSetting = (_a = pullFromCache([
|
|
7188
7473
|
'MessagePreviewSetting',
|
|
7189
7474
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -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
|
*/
|
|
@@ -7277,6 +7582,33 @@ const getProductCatalogueSetting = async () => {
|
|
|
7277
7582
|
};
|
|
7278
7583
|
/* end_public_function */
|
|
7279
7584
|
|
|
7585
|
+
/* begin_public_function
|
|
7586
|
+
id: client.getForYouFeedSetting
|
|
7587
|
+
*/
|
|
7588
|
+
/**
|
|
7589
|
+
* ```js
|
|
7590
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
7591
|
+
* const forYouFeedSetting = await Client.getForYouFeedSetting()
|
|
7592
|
+
* ```
|
|
7593
|
+
*
|
|
7594
|
+
* Fetches the network-level {@link Amity.ForYouFeedSetting} — whether the For You
|
|
7595
|
+
* feed feature is enabled for the current network. Use `forYouFeed.enabled` as a
|
|
7596
|
+
* feature gate before querying {@link getForYouFeed}.
|
|
7597
|
+
*
|
|
7598
|
+
* @returns A Promise of {@link Amity.ForYouFeedSetting} object
|
|
7599
|
+
*
|
|
7600
|
+
* @category Client API
|
|
7601
|
+
* @async
|
|
7602
|
+
*/
|
|
7603
|
+
const getForYouFeedSetting = async () => {
|
|
7604
|
+
var _a, _b;
|
|
7605
|
+
const client = getActiveClient();
|
|
7606
|
+
const { data } = await client.http.get(`/api/v3/network-settings/for-you-feed`);
|
|
7607
|
+
// Surface only `enabled`; ignore server-side ranking config (scoringConfig, etc.)
|
|
7608
|
+
return { forYouFeed: { enabled: (_b = (_a = data.forYouFeed) === null || _a === void 0 ? void 0 : _a.enabled) !== null && _b !== void 0 ? _b : false } };
|
|
7609
|
+
};
|
|
7610
|
+
/* end_public_function */
|
|
7611
|
+
|
|
7280
7612
|
const checkUserPermission = (userId, permission) => {
|
|
7281
7613
|
var _a;
|
|
7282
7614
|
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -7784,7 +8116,7 @@ class AnalyticsEventSyncer {
|
|
|
7784
8116
|
|
|
7785
8117
|
class AnalyticsEventCapturer {
|
|
7786
8118
|
constructor() {
|
|
7787
|
-
this._expireTime = 5 *
|
|
8119
|
+
this._expireTime = 5 * SECOND$1;
|
|
7788
8120
|
this._poolLimit = 1000;
|
|
7789
8121
|
this._recentViewed = {};
|
|
7790
8122
|
this._recentHighPriorityViewed = {};
|
|
@@ -7838,12 +8170,36 @@ class AnalyticsEventCapturer {
|
|
|
7838
8170
|
}
|
|
7839
8171
|
markPostAsViewed(postId) {
|
|
7840
8172
|
this.markAs({
|
|
7841
|
-
uniqueId: postId
|
|
8173
|
+
uniqueId: `post.${postId}`,
|
|
7842
8174
|
contentId: postId,
|
|
7843
8175
|
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
7844
8176
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
7845
8177
|
});
|
|
7846
8178
|
}
|
|
8179
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8180
|
+
var _a;
|
|
8181
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8182
|
+
const metadata = {};
|
|
8183
|
+
if (feedRenderPosition !== undefined)
|
|
8184
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
8185
|
+
if (cached) {
|
|
8186
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
8187
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
8188
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
8189
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
8190
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
8191
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
8192
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
8193
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
8194
|
+
}
|
|
8195
|
+
this.markAs({
|
|
8196
|
+
uniqueId: `post.${postId}.meaningfulView`,
|
|
8197
|
+
contentId: postId,
|
|
8198
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
8199
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
8200
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
8201
|
+
});
|
|
8202
|
+
}
|
|
7847
8203
|
markStory(story, activityType) {
|
|
7848
8204
|
if (!story.expiresAt)
|
|
7849
8205
|
return;
|
|
@@ -7983,6 +8339,12 @@ class AnalyticsEngine {
|
|
|
7983
8339
|
this._eventCapturer.markPostAsViewed(postId);
|
|
7984
8340
|
}
|
|
7985
8341
|
}
|
|
8342
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8343
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
8344
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8345
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
8346
|
+
}
|
|
8347
|
+
}
|
|
7986
8348
|
markStoryAsViewed(story) {
|
|
7987
8349
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
7988
8350
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -8034,13 +8396,13 @@ class AnalyticsEngine {
|
|
|
8034
8396
|
this._eventCapturer.resetAllBuckets();
|
|
8035
8397
|
}
|
|
8036
8398
|
}
|
|
8037
|
-
let instance$
|
|
8399
|
+
let instance$8;
|
|
8038
8400
|
var AnalyticsEngine$1 = {
|
|
8039
8401
|
getInstance: () => {
|
|
8040
|
-
if (!instance$
|
|
8041
|
-
instance$
|
|
8402
|
+
if (!instance$8) {
|
|
8403
|
+
instance$8 = new AnalyticsEngine();
|
|
8042
8404
|
}
|
|
8043
|
-
return instance$
|
|
8405
|
+
return instance$8;
|
|
8044
8406
|
},
|
|
8045
8407
|
};
|
|
8046
8408
|
|
|
@@ -8207,9 +8569,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
8207
8569
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
8208
8570
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
8209
8571
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8210
|
-
if (
|
|
8211
|
-
channelUnread
|
|
8212
|
-
segment > channelUnread.readToSegment) {
|
|
8572
|
+
if (channelUnread &&
|
|
8573
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
8213
8574
|
channelUnread.readToSegment = segment;
|
|
8214
8575
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
8215
8576
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -8268,12 +8629,12 @@ class MessageReadReceiptSyncEngine {
|
|
|
8268
8629
|
}
|
|
8269
8630
|
}
|
|
8270
8631
|
}
|
|
8271
|
-
let instance$
|
|
8632
|
+
let instance$7 = null;
|
|
8272
8633
|
var ReadReceiptSyncEngine = {
|
|
8273
8634
|
getInstance: () => {
|
|
8274
|
-
if (!instance$
|
|
8275
|
-
instance$
|
|
8276
|
-
return instance$
|
|
8635
|
+
if (!instance$7)
|
|
8636
|
+
instance$7 = new MessageReadReceiptSyncEngine();
|
|
8637
|
+
return instance$7;
|
|
8277
8638
|
},
|
|
8278
8639
|
};
|
|
8279
8640
|
|
|
@@ -8527,12 +8888,12 @@ class LegacyMessageReadReceiptSyncEngine {
|
|
|
8527
8888
|
}
|
|
8528
8889
|
}
|
|
8529
8890
|
}
|
|
8530
|
-
let instance$
|
|
8891
|
+
let instance$6 = null;
|
|
8531
8892
|
var LegacyReadReceiptSyncEngine = {
|
|
8532
8893
|
getInstance: () => {
|
|
8533
|
-
if (!instance$
|
|
8534
|
-
instance$
|
|
8535
|
-
return instance$
|
|
8894
|
+
if (!instance$6)
|
|
8895
|
+
instance$6 = new LegacyMessageReadReceiptSyncEngine();
|
|
8896
|
+
return instance$6;
|
|
8536
8897
|
},
|
|
8537
8898
|
};
|
|
8538
8899
|
|
|
@@ -8778,12 +9139,12 @@ class ObjectResolverEngine {
|
|
|
8778
9139
|
this.stopResolver();
|
|
8779
9140
|
}
|
|
8780
9141
|
}
|
|
8781
|
-
let instance$
|
|
9142
|
+
let instance$5 = null;
|
|
8782
9143
|
var ObjectResolverEngine$1 = {
|
|
8783
9144
|
getInstance: () => {
|
|
8784
|
-
if (!instance$
|
|
8785
|
-
instance$
|
|
8786
|
-
return instance$
|
|
9145
|
+
if (!instance$5)
|
|
9146
|
+
instance$5 = new ObjectResolverEngine();
|
|
9147
|
+
return instance$5;
|
|
8787
9148
|
},
|
|
8788
9149
|
};
|
|
8789
9150
|
|
|
@@ -8933,13 +9294,13 @@ class LiveReactionSyncEngine {
|
|
|
8933
9294
|
this.stopReactionsSync();
|
|
8934
9295
|
}
|
|
8935
9296
|
}
|
|
8936
|
-
let instance$
|
|
9297
|
+
let instance$4;
|
|
8937
9298
|
var ReactionSyncEngine = {
|
|
8938
9299
|
getInstance: () => {
|
|
8939
|
-
if (!instance$
|
|
8940
|
-
instance$
|
|
9300
|
+
if (!instance$4) {
|
|
9301
|
+
instance$4 = new LiveReactionSyncEngine();
|
|
8941
9302
|
}
|
|
8942
|
-
return instance$
|
|
9303
|
+
return instance$4;
|
|
8943
9304
|
},
|
|
8944
9305
|
};
|
|
8945
9306
|
|
|
@@ -8969,19 +9330,20 @@ function prepareBlockedUserPayload(response) {
|
|
|
8969
9330
|
}), users: users.map(convertRawUserToInternalUser) });
|
|
8970
9331
|
}
|
|
8971
9332
|
|
|
8972
|
-
const BLOCK_LIST_LIMIT = 100;
|
|
8973
|
-
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
9333
|
+
const BLOCK_LIST_LIMIT$1 = 100;
|
|
9334
|
+
const TTL_MS$1 = 5 * 60 * 1000; // 5 minutes
|
|
8974
9335
|
/**
|
|
8975
9336
|
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
8976
9337
|
* of blocked users. Provides a lazy `ensureFetched()` gate for the
|
|
8977
9338
|
* `getAllBlockedUsers()` API.
|
|
8978
9339
|
*
|
|
8979
9340
|
* Key behaviours:
|
|
8980
|
-
* - `
|
|
8981
|
-
* - `
|
|
9341
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
9342
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
8982
9343
|
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
8983
9344
|
* - `lastFetchedAt` is only updated on successful fetch
|
|
8984
|
-
* -
|
|
9345
|
+
* - reads query the follow cache live, so block/unblock changes are reflected
|
|
9346
|
+
* even within the TTL window
|
|
8985
9347
|
*
|
|
8986
9348
|
* @internal
|
|
8987
9349
|
*/
|
|
@@ -8989,12 +9351,7 @@ class BlockedUserSyncEngine {
|
|
|
8989
9351
|
constructor() {
|
|
8990
9352
|
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
8991
9353
|
this.lastFetchedAt = null;
|
|
8992
|
-
/** Ordered list of userId strings from the most recent successful fetch. */
|
|
8993
|
-
this.blockedUserIds = [];
|
|
8994
9354
|
}
|
|
8995
|
-
// ---------------------------------------------------------------------------
|
|
8996
|
-
// SessionComponent lifecycle
|
|
8997
|
-
// ---------------------------------------------------------------------------
|
|
8998
9355
|
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockedUsers(). */
|
|
8999
9356
|
// eslint-disable-next-line class-methods-use-this
|
|
9000
9357
|
onSessionEstablished() {
|
|
@@ -9003,24 +9360,17 @@ class BlockedUserSyncEngine {
|
|
|
9003
9360
|
/** Resets state so the next session starts with a cold cache. */
|
|
9004
9361
|
onSessionDestroyed() {
|
|
9005
9362
|
this.lastFetchedAt = null;
|
|
9006
|
-
this.blockedUserIds = [];
|
|
9007
9363
|
}
|
|
9008
9364
|
/** No-op for this engine. */
|
|
9009
9365
|
// eslint-disable-next-line class-methods-use-this
|
|
9010
9366
|
onTokenExpired() {
|
|
9011
9367
|
// intentionally empty
|
|
9012
9368
|
}
|
|
9013
|
-
// ---------------------------------------------------------------------------
|
|
9014
|
-
// Cache helpers
|
|
9015
|
-
// ---------------------------------------------------------------------------
|
|
9016
9369
|
isCacheExpired() {
|
|
9017
9370
|
if (this.lastFetchedAt === null)
|
|
9018
9371
|
return true;
|
|
9019
|
-
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
9372
|
+
return Date.now() - this.lastFetchedAt > TTL_MS$1;
|
|
9020
9373
|
}
|
|
9021
|
-
// ---------------------------------------------------------------------------
|
|
9022
|
-
// Core fetch gate
|
|
9023
|
-
// ---------------------------------------------------------------------------
|
|
9024
9374
|
/**
|
|
9025
9375
|
* Ensures the local store is populated with fresh blocked-user data.
|
|
9026
9376
|
*
|
|
@@ -9036,52 +9386,50 @@ class BlockedUserSyncEngine {
|
|
|
9036
9386
|
if (!this.isCacheExpired())
|
|
9037
9387
|
return;
|
|
9038
9388
|
const client = getActiveClient();
|
|
9039
|
-
const { data } = await client.http.get('/api/v4/me/user-blocks', { params: { options: { limit: BLOCK_LIST_LIMIT }, isDeleted: false } });
|
|
9389
|
+
const { data } = await client.http.get('/api/v4/me/user-blocks', { params: { options: { limit: BLOCK_LIST_LIMIT$1 }, isDeleted: false } });
|
|
9040
9390
|
const cachedAt = client.cache && Date.now();
|
|
9041
9391
|
const payload = prepareBlockedUserPayload(data);
|
|
9042
9392
|
if (client.cache) {
|
|
9043
9393
|
ingestInCache(payload, { cachedAt });
|
|
9044
9394
|
}
|
|
9045
|
-
// Keep the ordered list of blocked user IDs for getCachedUsers()
|
|
9046
|
-
this.blockedUserIds = payload.users.map(u => u.userId);
|
|
9047
9395
|
// Only update timestamp on success — failure leaves it unchanged so the
|
|
9048
9396
|
// next call retries.
|
|
9049
9397
|
this.lastFetchedAt = Date.now();
|
|
9050
9398
|
}
|
|
9051
|
-
// ---------------------------------------------------------------------------
|
|
9052
|
-
// Local store read
|
|
9053
|
-
// ---------------------------------------------------------------------------
|
|
9054
9399
|
/**
|
|
9055
|
-
* Returns blocked
|
|
9400
|
+
* Returns the blocked users by querying the follow cache live — the outgoing
|
|
9401
|
+
* direction (`from === me`, `status === 'blocked'`). Reading the cache (not a
|
|
9402
|
+
* fetched snapshot) means `blockUser()` / `unblockUser()` changes are reflected
|
|
9403
|
+
* even within the TTL window.
|
|
9056
9404
|
*
|
|
9057
|
-
* Applies the spec-mandated
|
|
9058
|
-
* -
|
|
9059
|
-
* -
|
|
9060
|
-
*
|
|
9061
|
-
* This always reads the latest local state, so changes made by `blockUser()`
|
|
9062
|
-
* and `unblockUser()` are reflected even within the TTL window.
|
|
9405
|
+
* Applies the spec-mandated query:
|
|
9406
|
+
* - filter `from === currentUserId`, `status === 'blocked'`, blocked user not deleted
|
|
9407
|
+
* - sort by `updatedAt` DESC
|
|
9408
|
+
* - hard limit of 100 results
|
|
9063
9409
|
*/
|
|
9410
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9064
9411
|
getCachedUsers() {
|
|
9412
|
+
var _a;
|
|
9065
9413
|
const client = getActiveClient();
|
|
9066
|
-
if (!client.cache)
|
|
9067
|
-
// No cache available — fall back to the in-memory list from the last fetch
|
|
9414
|
+
if (!client.cache)
|
|
9068
9415
|
return [];
|
|
9069
|
-
}
|
|
9070
|
-
return
|
|
9071
|
-
.map(
|
|
9416
|
+
const { userId } = client;
|
|
9417
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
9418
|
+
.map(entry => entry.data)
|
|
9419
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && follow.from === userId)
|
|
9420
|
+
.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); })
|
|
9421
|
+
.map(follow => { var _a; return (_a = pullFromCache(['user', 'get', follow.to])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
9072
9422
|
.filter((user) => user != null && user.isDeleted !== true)
|
|
9073
|
-
.slice(0, BLOCK_LIST_LIMIT)
|
|
9423
|
+
.slice(0, BLOCK_LIST_LIMIT$1)
|
|
9424
|
+
.map(userLinkedObject);
|
|
9074
9425
|
}
|
|
9075
9426
|
}
|
|
9076
|
-
|
|
9077
|
-
// Module-level singleton
|
|
9078
|
-
// ---------------------------------------------------------------------------
|
|
9079
|
-
let instance$2 = null;
|
|
9427
|
+
let instance$3 = null;
|
|
9080
9428
|
var BlockedUserSyncEngine$1 = {
|
|
9081
9429
|
getInstance: () => {
|
|
9082
|
-
if (!instance$
|
|
9083
|
-
instance$
|
|
9084
|
-
return instance$
|
|
9430
|
+
if (!instance$3)
|
|
9431
|
+
instance$3 = new BlockedUserSyncEngine();
|
|
9432
|
+
return instance$3;
|
|
9085
9433
|
},
|
|
9086
9434
|
};
|
|
9087
9435
|
|
|
@@ -9103,6 +9451,290 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
9103
9451
|
};
|
|
9104
9452
|
};
|
|
9105
9453
|
|
|
9454
|
+
function prepareBlockingUserPayload(response) {
|
|
9455
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9456
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
9457
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
9458
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
9459
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
9460
|
+
}
|
|
9461
|
+
|
|
9462
|
+
const BLOCK_LIST_LIMIT = 100;
|
|
9463
|
+
const TTL_MS = 5 * 60 * 1000; // 5 minutes
|
|
9464
|
+
/**
|
|
9465
|
+
* Session-scoped singleton engine that manages TTL-based fetching and caching
|
|
9466
|
+
* of blocking users (the "blocked-by" list — users who blocked the current
|
|
9467
|
+
* user). Provides a lazy `ensureFetched()` gate for the `getAllBlockingUsers()`
|
|
9468
|
+
* API. Directional inverse of {@link BlockedUserSyncEngine}.
|
|
9469
|
+
*
|
|
9470
|
+
* Key behaviours:
|
|
9471
|
+
* - `onSessionEstablished()` is a no-op — fetch is lazy, triggered only by consumer call
|
|
9472
|
+
* - `onSessionDestroyed()` resets `lastFetchedAt` to null (ensures fresh fetch on next session)
|
|
9473
|
+
* - `ensureFetched()` fetches from server only when cache is expired or never fetched
|
|
9474
|
+
* - `lastFetchedAt` is only updated on successful fetch
|
|
9475
|
+
* - reads query the follow cache live, so block/unblock changes are reflected
|
|
9476
|
+
* even within the TTL window
|
|
9477
|
+
*
|
|
9478
|
+
* @internal
|
|
9479
|
+
*/
|
|
9480
|
+
class BlockingUserSyncEngine {
|
|
9481
|
+
constructor() {
|
|
9482
|
+
/** Epoch ms of last successful fetch. null = never fetched in this session. */
|
|
9483
|
+
this.lastFetchedAt = null;
|
|
9484
|
+
}
|
|
9485
|
+
/** No-op — fetch is lazy, triggered by consumer calling getAllBlockingUsers(). */
|
|
9486
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9487
|
+
onSessionEstablished() {
|
|
9488
|
+
// intentionally empty
|
|
9489
|
+
}
|
|
9490
|
+
/** Resets state so the next session starts with a cold cache. */
|
|
9491
|
+
onSessionDestroyed() {
|
|
9492
|
+
this.lastFetchedAt = null;
|
|
9493
|
+
}
|
|
9494
|
+
/** No-op for this engine. */
|
|
9495
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9496
|
+
onTokenExpired() {
|
|
9497
|
+
// intentionally empty
|
|
9498
|
+
}
|
|
9499
|
+
isCacheExpired() {
|
|
9500
|
+
if (this.lastFetchedAt === null)
|
|
9501
|
+
return true;
|
|
9502
|
+
return Date.now() - this.lastFetchedAt > TTL_MS;
|
|
9503
|
+
}
|
|
9504
|
+
/**
|
|
9505
|
+
* Ensures the local store is populated with fresh blocking-user data.
|
|
9506
|
+
*
|
|
9507
|
+
* - If the cache is still within the 5-minute TTL window: resolves immediately
|
|
9508
|
+
* (no server call).
|
|
9509
|
+
* - If the cache is expired (or never fetched): fetches from the server,
|
|
9510
|
+
* persists the payload to the cache, and updates `lastFetchedAt`.
|
|
9511
|
+
*
|
|
9512
|
+
* On failure the error propagates to the caller and `lastFetchedAt` is NOT
|
|
9513
|
+
* updated, so the next call will retry.
|
|
9514
|
+
*/
|
|
9515
|
+
async ensureFetched() {
|
|
9516
|
+
if (!this.isCacheExpired())
|
|
9517
|
+
return;
|
|
9518
|
+
const client = getActiveClient();
|
|
9519
|
+
const { data } = await client.http.get('/api/v4/me/blockers', { params: { options: { limit: BLOCK_LIST_LIMIT }, isDeleted: false } });
|
|
9520
|
+
const cachedAt = client.cache && Date.now();
|
|
9521
|
+
const payload = prepareBlockingUserPayload(data);
|
|
9522
|
+
if (client.cache) {
|
|
9523
|
+
ingestInCache(payload, { cachedAt });
|
|
9524
|
+
}
|
|
9525
|
+
// Only update timestamp on success — failure leaves it unchanged so the
|
|
9526
|
+
// next call retries.
|
|
9527
|
+
this.lastFetchedAt = Date.now();
|
|
9528
|
+
}
|
|
9529
|
+
/**
|
|
9530
|
+
* Returns the "blocked-by" users by querying the follow cache live — the
|
|
9531
|
+
* incoming direction (`to === me`, `status === 'blocked'`). Reading the cache
|
|
9532
|
+
* (not a fetched snapshot) means RTE `user.didBlock` / `user.didUnblock`
|
|
9533
|
+
* changes are reflected even within the TTL window.
|
|
9534
|
+
*
|
|
9535
|
+
* Applies the spec-mandated query (REQ-012/013/014):
|
|
9536
|
+
* - filter `to === currentUserId`, `status === 'blocked'`, blocker not deleted
|
|
9537
|
+
* - sort by `updatedAt` DESC
|
|
9538
|
+
* - hard limit of 100 results
|
|
9539
|
+
*/
|
|
9540
|
+
// eslint-disable-next-line class-methods-use-this
|
|
9541
|
+
getCachedUsers() {
|
|
9542
|
+
var _a;
|
|
9543
|
+
const client = getActiveClient();
|
|
9544
|
+
if (!client.cache)
|
|
9545
|
+
return [];
|
|
9546
|
+
const { userId } = client;
|
|
9547
|
+
return ((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
9548
|
+
.map(entry => entry.data)
|
|
9549
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && follow.to === userId)
|
|
9550
|
+
.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); })
|
|
9551
|
+
.map(follow => { var _a; return (_a = pullFromCache(['user', 'get', follow.from])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
9552
|
+
.filter((user) => user != null && user.isDeleted !== true)
|
|
9553
|
+
.slice(0, BLOCK_LIST_LIMIT)
|
|
9554
|
+
.map(userLinkedObject);
|
|
9555
|
+
}
|
|
9556
|
+
}
|
|
9557
|
+
let instance$2 = null;
|
|
9558
|
+
var BlockingUserSyncEngine$1 = {
|
|
9559
|
+
getInstance: () => {
|
|
9560
|
+
if (!instance$2)
|
|
9561
|
+
instance$2 = new BlockingUserSyncEngine();
|
|
9562
|
+
return instance$2;
|
|
9563
|
+
},
|
|
9564
|
+
};
|
|
9565
|
+
|
|
9566
|
+
var blockingUserSyncEngineOnLoginHandler = () => {
|
|
9567
|
+
const blockingUserSyncEngine = BlockingUserSyncEngine$1.getInstance();
|
|
9568
|
+
onSessionStateChange(state => {
|
|
9569
|
+
if (state === "established" /* Amity.SessionStates.ESTABLISHED */) {
|
|
9570
|
+
blockingUserSyncEngine.onSessionEstablished();
|
|
9571
|
+
}
|
|
9572
|
+
else if (state === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
9573
|
+
blockingUserSyncEngine.onTokenExpired();
|
|
9574
|
+
}
|
|
9575
|
+
else {
|
|
9576
|
+
blockingUserSyncEngine.onSessionDestroyed();
|
|
9577
|
+
}
|
|
9578
|
+
});
|
|
9579
|
+
return () => {
|
|
9580
|
+
blockingUserSyncEngine.onSessionDestroyed();
|
|
9581
|
+
};
|
|
9582
|
+
};
|
|
9583
|
+
|
|
9584
|
+
function prepareFollowersPayload(response) {
|
|
9585
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9586
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9587
|
+
}
|
|
9588
|
+
function prepareFollowingsPayload(response) {
|
|
9589
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
9590
|
+
return Object.assign(Object.assign({}, rest), { follows, users: users.map(convertRawUserToInternalUser) });
|
|
9591
|
+
}
|
|
9592
|
+
function prepareFollowStatusPayload(response) {
|
|
9593
|
+
const { follows } = response, rest = __rest(response, ["follows"]);
|
|
9594
|
+
return Object.assign(Object.assign({}, rest), { follows });
|
|
9595
|
+
}
|
|
9596
|
+
|
|
9597
|
+
/**
|
|
9598
|
+
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
9599
|
+
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
9600
|
+
* the block-relationship rows (`['follow', 'get', from#to]`) and user rows are
|
|
9601
|
+
* kept current, then forwards the affected {@link Amity.FollowStatus} to the
|
|
9602
|
+
* caller.
|
|
9603
|
+
*
|
|
9604
|
+
* @hidden
|
|
9605
|
+
*/
|
|
9606
|
+
const createBlockEventSubscriber = (event, callback) => {
|
|
9607
|
+
const client = getActiveClient();
|
|
9608
|
+
const filter = (data) => {
|
|
9609
|
+
const payload = prepareFollowersPayload(data);
|
|
9610
|
+
if (client.cache) {
|
|
9611
|
+
ingestInCache(payload);
|
|
9612
|
+
}
|
|
9613
|
+
callback(payload.follows[0]);
|
|
9614
|
+
};
|
|
9615
|
+
return createEventSubscriber(client, event, event, filter);
|
|
9616
|
+
};
|
|
9617
|
+
|
|
9618
|
+
/**
|
|
9619
|
+
* ```js
|
|
9620
|
+
* import { onUserDidBlock } from '@amityco/ts-sdk'
|
|
9621
|
+
* const dispose = onUserDidBlock(status => {
|
|
9622
|
+
* // ...
|
|
9623
|
+
* })
|
|
9624
|
+
* ```
|
|
9625
|
+
*
|
|
9626
|
+
* Fired when a block relationship is created in real time — either a user
|
|
9627
|
+
* blocks the current user (incoming) or the current user blocks someone on
|
|
9628
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
9629
|
+
* before the callback runs.
|
|
9630
|
+
*
|
|
9631
|
+
* @param callback The function to call when the event was fired
|
|
9632
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9633
|
+
*
|
|
9634
|
+
* @category Block Events
|
|
9635
|
+
*/
|
|
9636
|
+
const onUserDidBlock = (callback) => createBlockEventSubscriber('user.didBlock', callback);
|
|
9637
|
+
|
|
9638
|
+
/**
|
|
9639
|
+
* ```js
|
|
9640
|
+
* import { onUserDidUnblock } from '@amityco/ts-sdk'
|
|
9641
|
+
* const dispose = onUserDidUnblock(status => {
|
|
9642
|
+
* // ...
|
|
9643
|
+
* })
|
|
9644
|
+
* ```
|
|
9645
|
+
*
|
|
9646
|
+
* Fired when a block relationship is removed in real time — either a user
|
|
9647
|
+
* unblocks the current user (incoming) or the current user unblocks someone on
|
|
9648
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
9649
|
+
* before the callback runs.
|
|
9650
|
+
*
|
|
9651
|
+
* @param callback The function to call when the event was fired
|
|
9652
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
9653
|
+
*
|
|
9654
|
+
* @category Block Events
|
|
9655
|
+
*/
|
|
9656
|
+
const onUserDidUnblock = (callback) => createBlockEventSubscriber('user.didUnblock', callback);
|
|
9657
|
+
|
|
9658
|
+
/**
|
|
9659
|
+
* Keeps the follow cache current for incoming/outgoing block changes for the
|
|
9660
|
+
* whole session — the ingest happens as a side effect inside
|
|
9661
|
+
* createBlockEventSubscriber, so the one-shot `getAllBlockedUsers()` /
|
|
9662
|
+
* `getAllBlockingUsers()` reflect RTE block/unblock within the TTL window.
|
|
9663
|
+
*
|
|
9664
|
+
* Registered via `setupLoginSubscriptions`; the returned unsubscriber is torn
|
|
9665
|
+
* down on logout.
|
|
9666
|
+
*/
|
|
9667
|
+
var blockRealtimeOnLoginHandler = () => {
|
|
9668
|
+
const disposers = [onUserDidBlock(() => { }), onUserDidUnblock(() => { })];
|
|
9669
|
+
return () => disposers.forEach(dispose => dispose());
|
|
9670
|
+
};
|
|
9671
|
+
|
|
9672
|
+
class CursorController {
|
|
9673
|
+
constructor(networkId, userId) {
|
|
9674
|
+
this.networkId = networkId;
|
|
9675
|
+
this.userId = userId;
|
|
9676
|
+
}
|
|
9677
|
+
static current() {
|
|
9678
|
+
try {
|
|
9679
|
+
const user = getCurrentUser();
|
|
9680
|
+
if (!user)
|
|
9681
|
+
return null;
|
|
9682
|
+
const networkId = getNetworkId(user);
|
|
9683
|
+
const { userId } = user;
|
|
9684
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
9685
|
+
}
|
|
9686
|
+
catch (_a) {
|
|
9687
|
+
return null;
|
|
9688
|
+
}
|
|
9689
|
+
}
|
|
9690
|
+
static isExpired(expiredAt) {
|
|
9691
|
+
return Date.now() >= expiredAt;
|
|
9692
|
+
}
|
|
9693
|
+
static clearOnLogout() {
|
|
9694
|
+
return onSessionStateChange(state => {
|
|
9695
|
+
var _a;
|
|
9696
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
9697
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
9698
|
+
});
|
|
9699
|
+
}
|
|
9700
|
+
get key() {
|
|
9701
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
9702
|
+
}
|
|
9703
|
+
async get() {
|
|
9704
|
+
const raw = await getItem(this.key);
|
|
9705
|
+
if (!raw)
|
|
9706
|
+
return null;
|
|
9707
|
+
try {
|
|
9708
|
+
const parsed = JSON.parse(raw);
|
|
9709
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
9710
|
+
return null;
|
|
9711
|
+
return {
|
|
9712
|
+
cursor: parsed.cursor,
|
|
9713
|
+
expiredAt: parsed.expiredAt,
|
|
9714
|
+
reachedEndOfFeed: parsed.reachedEndOfFeed === true,
|
|
9715
|
+
};
|
|
9716
|
+
}
|
|
9717
|
+
catch (_a) {
|
|
9718
|
+
return null;
|
|
9719
|
+
}
|
|
9720
|
+
}
|
|
9721
|
+
async set(value) {
|
|
9722
|
+
await setItem(this.key, JSON.stringify(value));
|
|
9723
|
+
}
|
|
9724
|
+
async markReachedEndOfFeed(expiredAt) {
|
|
9725
|
+
var _a;
|
|
9726
|
+
const stored = await this.get();
|
|
9727
|
+
await this.set({
|
|
9728
|
+
cursor: (_a = stored === null || stored === void 0 ? void 0 : stored.cursor) !== null && _a !== void 0 ? _a : '',
|
|
9729
|
+
expiredAt,
|
|
9730
|
+
reachedEndOfFeed: true,
|
|
9731
|
+
});
|
|
9732
|
+
}
|
|
9733
|
+
async clear() {
|
|
9734
|
+
await setItem(this.key, '');
|
|
9735
|
+
}
|
|
9736
|
+
}
|
|
9737
|
+
|
|
9106
9738
|
const EVENTS = [
|
|
9107
9739
|
'disconnected',
|
|
9108
9740
|
'error',
|
|
@@ -9292,7 +9924,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
9292
9924
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9293
9925
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9294
9926
|
// 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());
|
|
9927
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
9296
9928
|
if (client.useLegacyUnreadCount) {
|
|
9297
9929
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9298
9930
|
}
|
|
@@ -9991,16 +10623,13 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
9991
10623
|
}
|
|
9992
10624
|
if (client.useLegacyUnreadCount) {
|
|
9993
10625
|
rawPayload.messages.forEach(message => {
|
|
9994
|
-
var _a, _b;
|
|
10626
|
+
var _a, _b, _c;
|
|
9995
10627
|
const channelUnread = (_a = pullFromCache([
|
|
9996
10628
|
'channelUnread',
|
|
9997
10629
|
'get',
|
|
9998
10630
|
message.channelId,
|
|
9999
10631
|
])) === 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')
|
|
10632
|
+
if (!channelUnread || channelUnread.lastSegment >= message.segment)
|
|
10004
10633
|
return;
|
|
10005
10634
|
const lastSegment = message.segment;
|
|
10006
10635
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -10012,7 +10641,8 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
10012
10641
|
const lastMentionedSegment = isMentionedInMessage
|
|
10013
10642
|
? message.segment
|
|
10014
10643
|
: channelUnread.lastMentionedSegment;
|
|
10015
|
-
const
|
|
10644
|
+
const readToSegment = (_c = channelUnread.readToSegment) !== null && _c !== void 0 ? _c : 0;
|
|
10645
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - readToSegment, 0), lastMentionedSegment, isMentioned: typeof lastMentionedSegment === 'number' && readToSegment < lastMentionedSegment });
|
|
10016
10646
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
10017
10647
|
fireEvent('local.channelUnread.updated', [updatedChannelUnread]);
|
|
10018
10648
|
});
|
|
@@ -10375,14 +11005,17 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
10375
11005
|
validateUrls,
|
|
10376
11006
|
validateTexts,
|
|
10377
11007
|
getFeedSettings,
|
|
11008
|
+
getCoreUserSettings,
|
|
10378
11009
|
getSocialSettings,
|
|
11010
|
+
getChatSettings,
|
|
10379
11011
|
getVisitorDeviceId: getDeviceId,
|
|
10380
|
-
getMessagePreviewSetting,
|
|
11012
|
+
getMessagePreviewSetting: getMessagePreviewSetting$1,
|
|
10381
11013
|
use: () => setActiveClient(client),
|
|
10382
11014
|
isUnreadCountEnabled,
|
|
10383
11015
|
useLegacyUnreadCount,
|
|
10384
11016
|
getMarkerSyncConsistentMode,
|
|
10385
11017
|
getProductCatalogueSetting,
|
|
11018
|
+
getForYouFeedSetting,
|
|
10386
11019
|
/**
|
|
10387
11020
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
10388
11021
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
@@ -10650,11 +11283,18 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10650
11283
|
return data;
|
|
10651
11284
|
};
|
|
10652
11285
|
|
|
11286
|
+
const CONTENT_TYPE_CONFIG = {
|
|
11287
|
+
[exports.AmitySharableContentType.POST]: { key: 'posts', placeholder: 'postId' },
|
|
11288
|
+
[exports.AmitySharableContentType.COMMUNITY]: { key: 'communities', placeholder: 'communityId' },
|
|
11289
|
+
[exports.AmitySharableContentType.USER]: { key: 'users', placeholder: 'userId' },
|
|
11290
|
+
[exports.AmitySharableContentType.LIVESTREAM]: { key: 'livestream', placeholder: 'livestream' },
|
|
11291
|
+
[exports.AmitySharableContentType.EVENT]: { key: 'events', placeholder: 'eventId' },
|
|
11292
|
+
};
|
|
10653
11293
|
/**
|
|
10654
11294
|
* ```js
|
|
10655
11295
|
* import Client from '@amityco/ts-sdk'
|
|
10656
|
-
* const
|
|
10657
|
-
* const
|
|
11296
|
+
* const config = await Client.getShareableLinkConfiguration()
|
|
11297
|
+
* const link = config.generateLink(AmitySharableContentType.EVENT, eventId)
|
|
10658
11298
|
* ```
|
|
10659
11299
|
*
|
|
10660
11300
|
* Fetches a {@link Amity.ShareableLinkConfiguration} object
|
|
@@ -10665,9 +11305,29 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10665
11305
|
* @async
|
|
10666
11306
|
*/
|
|
10667
11307
|
const getShareableLinkConfiguration = async () => {
|
|
11308
|
+
var _a, _b;
|
|
10668
11309
|
const client = getActiveClient();
|
|
10669
11310
|
const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
|
|
10670
|
-
|
|
11311
|
+
const domain = (_a = data.domain) !== null && _a !== void 0 ? _a : '';
|
|
11312
|
+
const patterns = (_b = data.patterns) !== null && _b !== void 0 ? _b : {};
|
|
11313
|
+
return {
|
|
11314
|
+
domain,
|
|
11315
|
+
patterns,
|
|
11316
|
+
isEnabled(contentType) {
|
|
11317
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11318
|
+
return !!domain && !!patterns[key];
|
|
11319
|
+
},
|
|
11320
|
+
getPattern(contentType) {
|
|
11321
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11322
|
+
return patterns[key] || null;
|
|
11323
|
+
},
|
|
11324
|
+
generateLink(contentType, referenceId) {
|
|
11325
|
+
const { key, placeholder } = CONTENT_TYPE_CONFIG[contentType];
|
|
11326
|
+
if (!domain || !patterns[key])
|
|
11327
|
+
return null;
|
|
11328
|
+
return domain + patterns[key].replace(`{${placeholder}}`, referenceId);
|
|
11329
|
+
},
|
|
11330
|
+
};
|
|
10671
11331
|
};
|
|
10672
11332
|
|
|
10673
11333
|
/**
|
|
@@ -10858,6 +11518,205 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
10858
11518
|
client.accessTokenHandler = accessTokenHandler;
|
|
10859
11519
|
};
|
|
10860
11520
|
|
|
11521
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
11522
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
11523
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
11524
|
+
}
|
|
11525
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
11526
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
11527
|
+
}
|
|
11528
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ALL };
|
|
11529
|
+
}
|
|
11530
|
+
function serializeRolesFilter(rolesFilter) {
|
|
11531
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === exports.NotificationRolesFilterTypeEnum.ONLY) {
|
|
11532
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
11533
|
+
}
|
|
11534
|
+
return { listenFromRoleIds: [] };
|
|
11535
|
+
}
|
|
11536
|
+
class ChannelNotifications {
|
|
11537
|
+
constructor(channelId) {
|
|
11538
|
+
this.channelId = channelId;
|
|
11539
|
+
}
|
|
11540
|
+
async enable() {
|
|
11541
|
+
const client = getActiveClient();
|
|
11542
|
+
const body = {
|
|
11543
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11544
|
+
channelId: this.channelId,
|
|
11545
|
+
isPushNotifiable: true,
|
|
11546
|
+
};
|
|
11547
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11548
|
+
}
|
|
11549
|
+
async disable() {
|
|
11550
|
+
const client = getActiveClient();
|
|
11551
|
+
const body = {
|
|
11552
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11553
|
+
channelId: this.channelId,
|
|
11554
|
+
isPushNotifiable: false,
|
|
11555
|
+
};
|
|
11556
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11557
|
+
}
|
|
11558
|
+
async getSettings() {
|
|
11559
|
+
const client = getActiveClient();
|
|
11560
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
11561
|
+
return { isEnabled: data.isPushNotifiable };
|
|
11562
|
+
}
|
|
11563
|
+
}
|
|
11564
|
+
class UserNotifications {
|
|
11565
|
+
async enable(modules) {
|
|
11566
|
+
var _a;
|
|
11567
|
+
const client = getActiveClient();
|
|
11568
|
+
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 : [];
|
|
11569
|
+
const body = {
|
|
11570
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
11571
|
+
isPushNotifiable: true,
|
|
11572
|
+
notifiableEvents,
|
|
11573
|
+
};
|
|
11574
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11575
|
+
}
|
|
11576
|
+
async disableAllNotifications() {
|
|
11577
|
+
const client = getActiveClient();
|
|
11578
|
+
const body = {
|
|
11579
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
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.USER}`);
|
|
11589
|
+
const validModuleNames = Object.values(exports.UserNotificationModuleNameEnum);
|
|
11590
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11591
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
11592
|
+
.map(e => ({
|
|
11593
|
+
moduleName: e.moduleName,
|
|
11594
|
+
isEnabled: e.isPushNotifiable,
|
|
11595
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11596
|
+
}));
|
|
11597
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
11598
|
+
}
|
|
11599
|
+
}
|
|
11600
|
+
class CommunityNotifications {
|
|
11601
|
+
constructor(communityId) {
|
|
11602
|
+
this.communityId = communityId;
|
|
11603
|
+
}
|
|
11604
|
+
async enable(events) {
|
|
11605
|
+
var _a;
|
|
11606
|
+
const client = getActiveClient();
|
|
11607
|
+
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 : [];
|
|
11608
|
+
const body = {
|
|
11609
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11610
|
+
communityId: this.communityId,
|
|
11611
|
+
isPushNotifiable: true,
|
|
11612
|
+
notifiableEvents,
|
|
11613
|
+
};
|
|
11614
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11615
|
+
}
|
|
11616
|
+
async disable() {
|
|
11617
|
+
const client = getActiveClient();
|
|
11618
|
+
const body = {
|
|
11619
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11620
|
+
communityId: this.communityId,
|
|
11621
|
+
isPushNotifiable: false,
|
|
11622
|
+
notifiableEvents: [],
|
|
11623
|
+
};
|
|
11624
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11625
|
+
}
|
|
11626
|
+
async getSettings() {
|
|
11627
|
+
var _a;
|
|
11628
|
+
const client = getActiveClient();
|
|
11629
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
11630
|
+
const validEventNames = Object.values(exports.CommunityNotificationEventNameEnum);
|
|
11631
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11632
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
11633
|
+
.map(e => ({
|
|
11634
|
+
eventName: e.name,
|
|
11635
|
+
isEnabled: e.isPushNotifiable,
|
|
11636
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
11637
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11638
|
+
}));
|
|
11639
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
11640
|
+
}
|
|
11641
|
+
}
|
|
11642
|
+
class Notifications {
|
|
11643
|
+
user() {
|
|
11644
|
+
return new UserNotifications();
|
|
11645
|
+
}
|
|
11646
|
+
community(communityId) {
|
|
11647
|
+
return new CommunityNotifications(communityId);
|
|
11648
|
+
}
|
|
11649
|
+
channel(channelId) {
|
|
11650
|
+
return new ChannelNotifications(channelId);
|
|
11651
|
+
}
|
|
11652
|
+
}
|
|
11653
|
+
const notifications = () => new Notifications();
|
|
11654
|
+
|
|
11655
|
+
/* begin_public_function
|
|
11656
|
+
id: client.enable_auto_subscriptions
|
|
11657
|
+
*/
|
|
11658
|
+
/**
|
|
11659
|
+
* ```js
|
|
11660
|
+
* import { Client, AmityAutoSubscription } from '@amityco/ts-sdk'
|
|
11661
|
+
* Client.enableAutoSubscriptions([AmityAutoSubscription.BLOCK])
|
|
11662
|
+
* ```
|
|
11663
|
+
*
|
|
11664
|
+
* Enables one or more managed auto-subscription handles. Managed handles are
|
|
11665
|
+
* re-applied on every (re)connect and ref-counted. All handles are on by
|
|
11666
|
+
* default; use this to re-enable handles previously turned off via
|
|
11667
|
+
* {@link disableAutoSubscriptions}. Synchronous fire-and-forget — the registry
|
|
11668
|
+
* updates immediately and the broker subscribe is retried on reconnect.
|
|
11669
|
+
*
|
|
11670
|
+
* @param features the {@link AmityAutoSubscription} handles to enable
|
|
11671
|
+
*
|
|
11672
|
+
* @category Client API
|
|
11673
|
+
*/
|
|
11674
|
+
const enableAutoSubscriptions = (features) => {
|
|
11675
|
+
const manager = getAutoSubscriptionManager();
|
|
11676
|
+
features.forEach(feature => manager.subscribe(feature));
|
|
11677
|
+
};
|
|
11678
|
+
/* end_public_function */
|
|
11679
|
+
/* begin_public_function
|
|
11680
|
+
id: client.disable_auto_subscriptions
|
|
11681
|
+
*/
|
|
11682
|
+
/**
|
|
11683
|
+
* ```js
|
|
11684
|
+
* import { Client, AmityAutoSubscription } from '@amityco/ts-sdk'
|
|
11685
|
+
* Client.disableAutoSubscriptions([AmityAutoSubscription.LIVESTREAM])
|
|
11686
|
+
* ```
|
|
11687
|
+
*
|
|
11688
|
+
* Disables one or more managed auto-subscription handles. The change persists
|
|
11689
|
+
* across reconnect (it is not silently re-enabled) until
|
|
11690
|
+
* {@link enableAutoSubscriptions} is called again. Synchronous fire-and-forget.
|
|
11691
|
+
*
|
|
11692
|
+
* @param features the {@link AmityAutoSubscription} handles to disable
|
|
11693
|
+
*
|
|
11694
|
+
* @category Client API
|
|
11695
|
+
*/
|
|
11696
|
+
const disableAutoSubscriptions = (features) => {
|
|
11697
|
+
const manager = getAutoSubscriptionManager();
|
|
11698
|
+
features.forEach(feature => manager.unsubscribe(feature));
|
|
11699
|
+
};
|
|
11700
|
+
/* end_public_function */
|
|
11701
|
+
/* begin_public_function
|
|
11702
|
+
id: client.auto_subscriptions
|
|
11703
|
+
*/
|
|
11704
|
+
/**
|
|
11705
|
+
* ```js
|
|
11706
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
11707
|
+
* Client.autoSubscriptions().forEach(s => console.log(s.feature, s.isActive, s.topicCount))
|
|
11708
|
+
* ```
|
|
11709
|
+
*
|
|
11710
|
+
* Inspects the managed auto-subscription registry — each handle's `isActive`,
|
|
11711
|
+
* `isSystem`, and `topicCount`.
|
|
11712
|
+
*
|
|
11713
|
+
* @returns a snapshot of the managed subscription registry
|
|
11714
|
+
*
|
|
11715
|
+
* @category Client API
|
|
11716
|
+
*/
|
|
11717
|
+
const autoSubscriptions = () => getAutoSubscriptionManager().subscriptions();
|
|
11718
|
+
/* end_public_function */
|
|
11719
|
+
|
|
10861
11720
|
/**
|
|
10862
11721
|
* ```js
|
|
10863
11722
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -11232,12 +12091,19 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11232
12091
|
getSocialSettings: getSocialSettings,
|
|
11233
12092
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
11234
12093
|
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
12094
|
+
getForYouFeedSetting: getForYouFeedSetting,
|
|
11235
12095
|
loginAsVisitor: loginAsVisitor,
|
|
11236
12096
|
loginAsBot: loginAsBot,
|
|
11237
12097
|
getCurrentUser: getCurrentUser,
|
|
11238
12098
|
getCurrentUserType: getCurrentUserType,
|
|
11239
12099
|
setCurrentUserType: setCurrentUserType,
|
|
11240
12100
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
12101
|
+
getChatSettings: getChatSettings,
|
|
12102
|
+
getCoreUserSettings: getCoreUserSettings,
|
|
12103
|
+
notifications: notifications,
|
|
12104
|
+
enableAutoSubscriptions: enableAutoSubscriptions,
|
|
12105
|
+
disableAutoSubscriptions: disableAutoSubscriptions,
|
|
12106
|
+
autoSubscriptions: autoSubscriptions,
|
|
11241
12107
|
onConnectionError: onConnectionError,
|
|
11242
12108
|
onClientDisconnected: onClientDisconnected,
|
|
11243
12109
|
onClientBanned: onClientBanned,
|
|
@@ -11255,19 +12121,6 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11255
12121
|
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
11256
12122
|
});
|
|
11257
12123
|
|
|
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
12124
|
/* begin_public_function
|
|
11272
12125
|
id: user.relationship.block
|
|
11273
12126
|
*/
|
|
@@ -12445,6 +13298,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
12445
13298
|
__proto__: null,
|
|
12446
13299
|
blockUser: blockUser,
|
|
12447
13300
|
unBlockUser: unBlockUser,
|
|
13301
|
+
onUserDidBlock: onUserDidBlock,
|
|
13302
|
+
onUserDidUnblock: onUserDidUnblock,
|
|
12448
13303
|
follow: follow,
|
|
12449
13304
|
unfollow: unfollow,
|
|
12450
13305
|
acceptMyFollower: acceptMyFollower,
|
|
@@ -13274,7 +14129,7 @@ const getWatchSessionStorage = () => {
|
|
|
13274
14129
|
return storageInstance;
|
|
13275
14130
|
};
|
|
13276
14131
|
|
|
13277
|
-
const privateKey = "
|
|
14132
|
+
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
14133
|
/*
|
|
13279
14134
|
* The crypto algorithm used for importing key and signing string
|
|
13280
14135
|
*/
|
|
@@ -14596,6 +15451,10 @@ const postLinkedObject = (post) => {
|
|
|
14596
15451
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
14597
15452
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
14598
15453
|
},
|
|
15454
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
15455
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
15456
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
15457
|
+
},
|
|
14599
15458
|
},
|
|
14600
15459
|
get productTags() {
|
|
14601
15460
|
var _a, _b;
|
|
@@ -14785,6 +15644,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
14785
15644
|
});
|
|
14786
15645
|
return true;
|
|
14787
15646
|
}
|
|
15647
|
+
if (referenceType === 'message') {
|
|
15648
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15649
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15650
|
+
return true;
|
|
15651
|
+
}
|
|
14788
15652
|
}
|
|
14789
15653
|
return true;
|
|
14790
15654
|
};
|
|
@@ -14863,7 +15727,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14863
15727
|
return true;
|
|
14864
15728
|
}
|
|
14865
15729
|
if (referenceType === 'story') {
|
|
14866
|
-
fireEvent('local.story.
|
|
15730
|
+
fireEvent('local.story.reactionRemoved', {
|
|
14867
15731
|
story: updatedModel,
|
|
14868
15732
|
reactor: {
|
|
14869
15733
|
userId: client.userId,
|
|
@@ -14873,6 +15737,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14873
15737
|
});
|
|
14874
15738
|
return true;
|
|
14875
15739
|
}
|
|
15740
|
+
if (referenceType === 'message') {
|
|
15741
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15742
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15743
|
+
return true;
|
|
15744
|
+
}
|
|
14876
15745
|
}
|
|
14877
15746
|
return true;
|
|
14878
15747
|
};
|
|
@@ -15145,7 +16014,7 @@ const createEventResponseSubscriber = (event, callback) => {
|
|
|
15145
16014
|
const eventResponse = pullFromCache([
|
|
15146
16015
|
'eventResponse',
|
|
15147
16016
|
'get',
|
|
15148
|
-
|
|
16017
|
+
unpackedPayload.eventResponses[0].userId,
|
|
15149
16018
|
]);
|
|
15150
16019
|
callback(eventResponse.data);
|
|
15151
16020
|
}
|
|
@@ -15809,7 +16678,38 @@ const getAllBlockedUsers = async () => {
|
|
|
15809
16678
|
const engine = BlockedUserSyncEngine$1.getInstance();
|
|
15810
16679
|
// Ensure data is fetched (no-op if cache is fresh)
|
|
15811
16680
|
await engine.ensureFetched();
|
|
15812
|
-
|
|
16681
|
+
return engine.getCachedUsers();
|
|
16682
|
+
};
|
|
16683
|
+
/* end_public_function */
|
|
16684
|
+
|
|
16685
|
+
/* begin_public_function
|
|
16686
|
+
id: user.get_all_blocking_users
|
|
16687
|
+
*/
|
|
16688
|
+
/**
|
|
16689
|
+
* ```js
|
|
16690
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
16691
|
+
* const blockingUsers = await UserRepository.getAllBlockingUsers()
|
|
16692
|
+
* ```
|
|
16693
|
+
*
|
|
16694
|
+
* Returns all users who have blocked the current user
|
|
16695
|
+
* non-paginated list (limit 100) with TTL-based caching (5-minute window). Within the
|
|
16696
|
+
* TTL window, subsequent calls resolve instantly from the local store without any
|
|
16697
|
+
* server call. After the TTL expires, the next call triggers a fresh server fetch.
|
|
16698
|
+
*
|
|
16699
|
+
* The directional inverse of {@link getAllBlockedUsers}.
|
|
16700
|
+
*
|
|
16701
|
+
* @returns A promise that resolves to an array of blocking {@link Amity.User} objects
|
|
16702
|
+
*
|
|
16703
|
+
* @category Block API
|
|
16704
|
+
* @async
|
|
16705
|
+
*/
|
|
16706
|
+
const getAllBlockingUsers = async () => {
|
|
16707
|
+
const client = getActiveClient();
|
|
16708
|
+
client.log('user/getAllBlockingUsers');
|
|
16709
|
+
const engine = BlockingUserSyncEngine$1.getInstance();
|
|
16710
|
+
// Ensure data is fetched (no-op if cache is fresh)
|
|
16711
|
+
await engine.ensureFetched();
|
|
16712
|
+
// Read from the engine's bounded ID list — O(blocking users) not O(cache size)
|
|
15813
16713
|
return engine.getCachedUsers();
|
|
15814
16714
|
};
|
|
15815
16715
|
/* end_public_function */
|
|
@@ -16192,6 +17092,12 @@ class BlockedUserPaginationController extends PaginationController {
|
|
|
16192
17092
|
}
|
|
16193
17093
|
}
|
|
16194
17094
|
|
|
17095
|
+
var EnumBlockActions;
|
|
17096
|
+
(function (EnumBlockActions) {
|
|
17097
|
+
EnumBlockActions["OnBlocked"] = "onBlocked";
|
|
17098
|
+
EnumBlockActions["OnUnblocked"] = "onUnblocked";
|
|
17099
|
+
})(EnumBlockActions || (EnumBlockActions = {}));
|
|
17100
|
+
|
|
16195
17101
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
16196
17102
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
16197
17103
|
super(query, cacheKey);
|
|
@@ -16221,11 +17127,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
16221
17127
|
}
|
|
16222
17128
|
reactor(action) {
|
|
16223
17129
|
return (targetUser) => {
|
|
16224
|
-
var _a;
|
|
16225
|
-
|
|
17130
|
+
var _a, _b;
|
|
17131
|
+
const isRemoval = action === EnumFollowActions.OnFollowed || action === EnumBlockActions.OnUnblocked;
|
|
17132
|
+
const isAddition = action === EnumBlockActions.OnBlocked;
|
|
17133
|
+
if (isRemoval || isAddition) {
|
|
16226
17134
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16227
|
-
const
|
|
16228
|
-
|
|
17135
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17136
|
+
const data = isAddition
|
|
17137
|
+
? [...new Set([...ids, targetUser.userId])]
|
|
17138
|
+
: ids.filter(id => id !== targetUser.userId);
|
|
17139
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
16229
17140
|
}
|
|
16230
17141
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16231
17142
|
};
|
|
@@ -16280,7 +17191,6 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16280
17191
|
fn: onUserDeleted$2,
|
|
16281
17192
|
action: EnumUserActions.OnUserDeleted,
|
|
16282
17193
|
},
|
|
16283
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
16284
17194
|
{
|
|
16285
17195
|
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
16286
17196
|
action: EnumFollowActions.OnFollowed,
|
|
@@ -16289,6 +17199,28 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16289
17199
|
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
16290
17200
|
action: EnumFollowActions.OnFollowed,
|
|
16291
17201
|
},
|
|
17202
|
+
{
|
|
17203
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
17204
|
+
var _a;
|
|
17205
|
+
if (status.from !== getActiveClient().userId)
|
|
17206
|
+
return;
|
|
17207
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17208
|
+
if (blocked)
|
|
17209
|
+
reactor(blocked);
|
|
17210
|
+
}),
|
|
17211
|
+
action: EnumBlockActions.OnBlocked,
|
|
17212
|
+
},
|
|
17213
|
+
{
|
|
17214
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
17215
|
+
var _a;
|
|
17216
|
+
if (status.from !== getActiveClient().userId)
|
|
17217
|
+
return;
|
|
17218
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17219
|
+
if (blocked)
|
|
17220
|
+
reactor(blocked);
|
|
17221
|
+
}),
|
|
17222
|
+
action: EnumBlockActions.OnUnblocked,
|
|
17223
|
+
},
|
|
16292
17224
|
]);
|
|
16293
17225
|
}
|
|
16294
17226
|
notifyChange({ origin, loading, error }) {
|
|
@@ -16356,6 +17288,184 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
16356
17288
|
};
|
|
16357
17289
|
/* end_public_function */
|
|
16358
17290
|
|
|
17291
|
+
class BlockingUserQueryStreamController extends QueryStreamController {
|
|
17292
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
17293
|
+
super(query, cacheKey);
|
|
17294
|
+
this.notifyChange = notifyChange;
|
|
17295
|
+
this.preparePayload = preparePayload;
|
|
17296
|
+
}
|
|
17297
|
+
async saveToMainDB(response) {
|
|
17298
|
+
const processedPayload = await this.preparePayload(response);
|
|
17299
|
+
const client = getActiveClient();
|
|
17300
|
+
const cachedAt = client.cache && Date.now();
|
|
17301
|
+
if (client.cache) {
|
|
17302
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
17303
|
+
}
|
|
17304
|
+
}
|
|
17305
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
17306
|
+
var _a, _b;
|
|
17307
|
+
if (refresh) {
|
|
17308
|
+
pushToCache(this.cacheKey, {
|
|
17309
|
+
data: response.users.map(getResolver('user')),
|
|
17310
|
+
});
|
|
17311
|
+
}
|
|
17312
|
+
else {
|
|
17313
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17314
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17315
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
17316
|
+
}
|
|
17317
|
+
}
|
|
17318
|
+
reactor(action) {
|
|
17319
|
+
return (user) => {
|
|
17320
|
+
var _a, _b;
|
|
17321
|
+
if (user &&
|
|
17322
|
+
(action === EnumBlockActions.OnBlocked || action === EnumBlockActions.OnUnblocked)) {
|
|
17323
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17324
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17325
|
+
const data = action === EnumBlockActions.OnBlocked
|
|
17326
|
+
? [...new Set([...ids, user.userId])]
|
|
17327
|
+
: ids.filter(id => id !== user.userId);
|
|
17328
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
17329
|
+
}
|
|
17330
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17331
|
+
};
|
|
17332
|
+
}
|
|
17333
|
+
subscribeRTE(createSubscriber) {
|
|
17334
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
17335
|
+
}
|
|
17336
|
+
}
|
|
17337
|
+
|
|
17338
|
+
class BlockingUserPaginationController extends PaginationController {
|
|
17339
|
+
async getRequest(queryParams, token) {
|
|
17340
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
17341
|
+
const options = token ? { token } : { limit };
|
|
17342
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/blockers', {
|
|
17343
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
17344
|
+
});
|
|
17345
|
+
return queryResponse;
|
|
17346
|
+
}
|
|
17347
|
+
}
|
|
17348
|
+
|
|
17349
|
+
class BlockingUserLiveCollectionController extends LiveCollectionController {
|
|
17350
|
+
constructor(callback) {
|
|
17351
|
+
const queryStreamId = `blocking-users-${getActiveClient().userId}`;
|
|
17352
|
+
const query = {};
|
|
17353
|
+
const cacheKey = ['blockingUsers', 'collection', queryStreamId];
|
|
17354
|
+
const paginationController = new BlockingUserPaginationController(query);
|
|
17355
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
17356
|
+
this.queryStreamController = new BlockingUserQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), prepareBlockingUserPayload);
|
|
17357
|
+
this.callback = callback.bind(this);
|
|
17358
|
+
this.loadPage({ initial: true });
|
|
17359
|
+
}
|
|
17360
|
+
setup() {
|
|
17361
|
+
var _a;
|
|
17362
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17363
|
+
if (!collection) {
|
|
17364
|
+
pushToCache(this.cacheKey, {
|
|
17365
|
+
data: [],
|
|
17366
|
+
params: {},
|
|
17367
|
+
});
|
|
17368
|
+
}
|
|
17369
|
+
}
|
|
17370
|
+
async persistModel(queryPayload) {
|
|
17371
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
17372
|
+
}
|
|
17373
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
17374
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
17375
|
+
}
|
|
17376
|
+
startSubscription() {
|
|
17377
|
+
return this.queryStreamController.subscribeRTE([
|
|
17378
|
+
{
|
|
17379
|
+
fn: onUserDeleted$2,
|
|
17380
|
+
action: EnumUserActions.OnUserDeleted,
|
|
17381
|
+
},
|
|
17382
|
+
{
|
|
17383
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
17384
|
+
var _a;
|
|
17385
|
+
if (status.to !== getActiveClient().userId)
|
|
17386
|
+
return;
|
|
17387
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17388
|
+
if (blocker)
|
|
17389
|
+
reactor(blocker);
|
|
17390
|
+
}),
|
|
17391
|
+
action: EnumBlockActions.OnBlocked,
|
|
17392
|
+
},
|
|
17393
|
+
{
|
|
17394
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
17395
|
+
var _a;
|
|
17396
|
+
if (status.to !== getActiveClient().userId)
|
|
17397
|
+
return;
|
|
17398
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17399
|
+
if (blocker)
|
|
17400
|
+
reactor(blocker);
|
|
17401
|
+
}),
|
|
17402
|
+
action: EnumBlockActions.OnUnblocked,
|
|
17403
|
+
},
|
|
17404
|
+
]);
|
|
17405
|
+
}
|
|
17406
|
+
notifyChange({ origin, loading, error }) {
|
|
17407
|
+
var _a, _b;
|
|
17408
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17409
|
+
if (!collection)
|
|
17410
|
+
return;
|
|
17411
|
+
const data = this.applyFilter((_b = collection.data
|
|
17412
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
17413
|
+
.filter(isNonNullable)
|
|
17414
|
+
.map(({ data }) => data)
|
|
17415
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
17416
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
17417
|
+
return;
|
|
17418
|
+
this.callback({
|
|
17419
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
17420
|
+
data,
|
|
17421
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
17422
|
+
loading,
|
|
17423
|
+
error,
|
|
17424
|
+
});
|
|
17425
|
+
}
|
|
17426
|
+
applyFilter(data) {
|
|
17427
|
+
let users = data;
|
|
17428
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
17429
|
+
return users;
|
|
17430
|
+
}
|
|
17431
|
+
}
|
|
17432
|
+
|
|
17433
|
+
/* begin_public_function
|
|
17434
|
+
id: user.get_blocking_users
|
|
17435
|
+
*/
|
|
17436
|
+
/**
|
|
17437
|
+
* ```js
|
|
17438
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
17439
|
+
* const unsubscribe = UserRepository.getBlockingUsers(({ data: users }) => {
|
|
17440
|
+
* console.log(users)
|
|
17441
|
+
* })
|
|
17442
|
+
* ```
|
|
17443
|
+
*
|
|
17444
|
+
* Observe the {@link Amity.User}s who have blocked the current user
|
|
17445
|
+
*
|
|
17446
|
+
* @param callback to receive updates on the blocking {@link Amity.User}s
|
|
17447
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
17448
|
+
*
|
|
17449
|
+
* @category User API
|
|
17450
|
+
*/
|
|
17451
|
+
const getBlockingUsers = (callback) => {
|
|
17452
|
+
const { log, cache } = getActiveClient();
|
|
17453
|
+
if (!cache)
|
|
17454
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
17455
|
+
const timestamp = Date.now();
|
|
17456
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > listen`);
|
|
17457
|
+
const blockingUserLiveCollection = new BlockingUserLiveCollectionController(callback);
|
|
17458
|
+
const disposers = blockingUserLiveCollection.startSubscription();
|
|
17459
|
+
const cacheKey = blockingUserLiveCollection.getCacheKey();
|
|
17460
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
17461
|
+
return () => {
|
|
17462
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > dispose`);
|
|
17463
|
+
disposers.forEach(fn => fn());
|
|
17464
|
+
dropFromCache(cacheKey);
|
|
17465
|
+
};
|
|
17466
|
+
};
|
|
17467
|
+
/* end_public_function */
|
|
17468
|
+
|
|
16359
17469
|
class SearchUserPaginationController extends PaginationController {
|
|
16360
17470
|
async getRequest(queryParams, token) {
|
|
16361
17471
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
@@ -16622,6 +17732,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
16622
17732
|
unflagUser: unflagUser,
|
|
16623
17733
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
16624
17734
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
17735
|
+
getAllBlockingUsers: getAllBlockingUsers,
|
|
16625
17736
|
onUserUpdated: onUserUpdated,
|
|
16626
17737
|
onUserDeleted: onUserDeleted$2,
|
|
16627
17738
|
onUserFlagged: onUserFlagged,
|
|
@@ -16630,6 +17741,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
16630
17741
|
getUser: getUser,
|
|
16631
17742
|
getUsers: getUsers,
|
|
16632
17743
|
getBlockedUsers: getBlockedUsers,
|
|
17744
|
+
getBlockingUsers: getBlockingUsers,
|
|
16633
17745
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
16634
17746
|
getReachedUsers: getReachedUsers,
|
|
16635
17747
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
@@ -17796,7 +18908,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17796
18908
|
return true;
|
|
17797
18909
|
}
|
|
17798
18910
|
if (referenceType === 'story') {
|
|
17799
|
-
fireEvent('local.story.
|
|
18911
|
+
fireEvent('local.story.reactionRemoved', {
|
|
17800
18912
|
story: updatedModel,
|
|
17801
18913
|
reactor: {
|
|
17802
18914
|
userId: client.userId,
|
|
@@ -19380,6 +20492,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
19380
20492
|
};
|
|
19381
20493
|
/* end_public_function */
|
|
19382
20494
|
|
|
20495
|
+
/* begin_public_function
|
|
20496
|
+
id: channel.archive
|
|
20497
|
+
*/
|
|
20498
|
+
/**
|
|
20499
|
+
* ```js
|
|
20500
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20501
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
20502
|
+
* ```
|
|
20503
|
+
*
|
|
20504
|
+
* Archive a {@link Amity.Channel}.
|
|
20505
|
+
*
|
|
20506
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
20507
|
+
* @returns A success boolean
|
|
20508
|
+
*
|
|
20509
|
+
* @category Channel API
|
|
20510
|
+
* @async
|
|
20511
|
+
*/
|
|
20512
|
+
const archiveChannel = async (channelId) => {
|
|
20513
|
+
const client = getActiveClient();
|
|
20514
|
+
client.log('channel/archiveChannel', channelId);
|
|
20515
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20516
|
+
const archive = {
|
|
20517
|
+
channelId,
|
|
20518
|
+
archivedAt: new Date().toISOString(),
|
|
20519
|
+
};
|
|
20520
|
+
if (client.cache) {
|
|
20521
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
20522
|
+
}
|
|
20523
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
20524
|
+
};
|
|
20525
|
+
/* end_public_function */
|
|
20526
|
+
|
|
20527
|
+
/* begin_public_function
|
|
20528
|
+
id: channel.unarchive
|
|
20529
|
+
*/
|
|
20530
|
+
/**
|
|
20531
|
+
* ```js
|
|
20532
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20533
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
20534
|
+
* ```
|
|
20535
|
+
*
|
|
20536
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
20537
|
+
*
|
|
20538
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
20539
|
+
* @returns A success boolean
|
|
20540
|
+
*
|
|
20541
|
+
* @category Channel API
|
|
20542
|
+
* @async
|
|
20543
|
+
*/
|
|
20544
|
+
const unarchiveChannel = async (channelId) => {
|
|
20545
|
+
var _a;
|
|
20546
|
+
const client = getActiveClient();
|
|
20547
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
20548
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20549
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20550
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
20551
|
+
channelId,
|
|
20552
|
+
archivedAt: new Date().toISOString(),
|
|
20553
|
+
};
|
|
20554
|
+
if (client.cache) {
|
|
20555
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
20556
|
+
}
|
|
20557
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
20558
|
+
};
|
|
20559
|
+
/* end_public_function */
|
|
20560
|
+
|
|
20561
|
+
/* begin_public_function
|
|
20562
|
+
id: channel.archive.ids
|
|
20563
|
+
*/
|
|
20564
|
+
/**
|
|
20565
|
+
* ```js
|
|
20566
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20567
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
20568
|
+
* ```
|
|
20569
|
+
*
|
|
20570
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
20571
|
+
*
|
|
20572
|
+
* @category Channel API
|
|
20573
|
+
* @async
|
|
20574
|
+
*/
|
|
20575
|
+
const getArchivedChannelIds = async () => {
|
|
20576
|
+
var _a;
|
|
20577
|
+
const client = getActiveClient();
|
|
20578
|
+
client.log('channel/getArchivedChannelIds');
|
|
20579
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
20580
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
20581
|
+
if (client.cache) {
|
|
20582
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
20583
|
+
archives.forEach(archive => {
|
|
20584
|
+
if (!archive.channelId)
|
|
20585
|
+
return;
|
|
20586
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
20587
|
+
});
|
|
20588
|
+
}
|
|
20589
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
20590
|
+
};
|
|
20591
|
+
/* end_public_function */
|
|
20592
|
+
|
|
19383
20593
|
/**
|
|
19384
20594
|
* ```js
|
|
19385
20595
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -20758,6 +21968,160 @@ const getMessages = (params, callback, config) => {
|
|
|
20758
21968
|
};
|
|
20759
21969
|
/* end_public_function */
|
|
20760
21970
|
|
|
21971
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
21972
|
+
async getRequest(queryParams, token) {
|
|
21973
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
21974
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
21975
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
21976
|
+
params: {
|
|
21977
|
+
query,
|
|
21978
|
+
exactMatch,
|
|
21979
|
+
channelId,
|
|
21980
|
+
messageFeedId,
|
|
21981
|
+
userIds,
|
|
21982
|
+
tags,
|
|
21983
|
+
types,
|
|
21984
|
+
options,
|
|
21985
|
+
},
|
|
21986
|
+
});
|
|
21987
|
+
return queryResponse;
|
|
21988
|
+
}
|
|
21989
|
+
}
|
|
21990
|
+
|
|
21991
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
21992
|
+
constructor(query, cacheKey, notifyChange) {
|
|
21993
|
+
super(query, cacheKey);
|
|
21994
|
+
this.notifyChange = notifyChange;
|
|
21995
|
+
}
|
|
21996
|
+
async saveToMainDB(response) {
|
|
21997
|
+
var _a;
|
|
21998
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
21999
|
+
const client = getActiveClient();
|
|
22000
|
+
const cachedAt = client.cache && Date.now();
|
|
22001
|
+
if (client.cache) {
|
|
22002
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
22003
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
22004
|
+
response.channels.forEach(channel => {
|
|
22005
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
22006
|
+
});
|
|
22007
|
+
}
|
|
22008
|
+
}
|
|
22009
|
+
}
|
|
22010
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
22011
|
+
var _a, _b;
|
|
22012
|
+
if (refresh) {
|
|
22013
|
+
pushToCache(this.cacheKey, {
|
|
22014
|
+
data: response.messages.map(getResolver('message')),
|
|
22015
|
+
});
|
|
22016
|
+
return;
|
|
22017
|
+
}
|
|
22018
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22019
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
22020
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
22021
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
22022
|
+
? [...new Set([...incoming, ...existing])]
|
|
22023
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
22024
|
+
}
|
|
22025
|
+
}
|
|
22026
|
+
|
|
22027
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
22028
|
+
constructor(query, callback) {
|
|
22029
|
+
const queryStreamId = hash__default["default"](query);
|
|
22030
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
22031
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
22032
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
22033
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
22034
|
+
this.callback = callback.bind(this);
|
|
22035
|
+
this.loadPage({ initial: true });
|
|
22036
|
+
}
|
|
22037
|
+
startSubscription() {
|
|
22038
|
+
return [];
|
|
22039
|
+
}
|
|
22040
|
+
notifyChange({ origin, loading, error }) {
|
|
22041
|
+
var _a, _b;
|
|
22042
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22043
|
+
if (!collection)
|
|
22044
|
+
return;
|
|
22045
|
+
const data = (_b = collection.data
|
|
22046
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
22047
|
+
.filter(isNonNullable)
|
|
22048
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
22049
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
22050
|
+
return;
|
|
22051
|
+
this.callback({
|
|
22052
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
22053
|
+
data,
|
|
22054
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
22055
|
+
loading,
|
|
22056
|
+
error,
|
|
22057
|
+
});
|
|
22058
|
+
}
|
|
22059
|
+
setup() {
|
|
22060
|
+
var _a;
|
|
22061
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22062
|
+
if (!collection) {
|
|
22063
|
+
pushToCache(this.cacheKey, {
|
|
22064
|
+
data: [],
|
|
22065
|
+
params: {},
|
|
22066
|
+
});
|
|
22067
|
+
}
|
|
22068
|
+
}
|
|
22069
|
+
async persistModel(response) {
|
|
22070
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
22071
|
+
}
|
|
22072
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
22073
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
22074
|
+
}
|
|
22075
|
+
}
|
|
22076
|
+
|
|
22077
|
+
/* begin_public_function
|
|
22078
|
+
id: message.search
|
|
22079
|
+
*/
|
|
22080
|
+
/**
|
|
22081
|
+
* ```js
|
|
22082
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
22083
|
+
*
|
|
22084
|
+
* let messages = [];
|
|
22085
|
+
*
|
|
22086
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
22087
|
+
* { query: 'hello' },
|
|
22088
|
+
* response => merge(messages, response.data),
|
|
22089
|
+
* );
|
|
22090
|
+
* ```
|
|
22091
|
+
*
|
|
22092
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
22093
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
22094
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
22095
|
+
*
|
|
22096
|
+
* @param params Search parameters. `query` is required.
|
|
22097
|
+
* @param callback Called whenever new data are available.
|
|
22098
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
22099
|
+
*
|
|
22100
|
+
* @category Message Live Collection
|
|
22101
|
+
*/
|
|
22102
|
+
const searchMessage = (params, callback) => {
|
|
22103
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
22104
|
+
throw new Error('Query is required for message search');
|
|
22105
|
+
}
|
|
22106
|
+
const { log, cache } = getActiveClient();
|
|
22107
|
+
if (!cache) {
|
|
22108
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
22109
|
+
}
|
|
22110
|
+
const timestamp = Date.now();
|
|
22111
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
22112
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
22113
|
+
const disposers = controller.startSubscription();
|
|
22114
|
+
const cacheKey = controller.getCacheKey();
|
|
22115
|
+
disposers.push(() => {
|
|
22116
|
+
dropFromCache(cacheKey);
|
|
22117
|
+
});
|
|
22118
|
+
return () => {
|
|
22119
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
22120
|
+
disposers.forEach(fn => fn());
|
|
22121
|
+
};
|
|
22122
|
+
};
|
|
22123
|
+
/* end_public_function */
|
|
22124
|
+
|
|
20761
22125
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
20762
22126
|
__proto__: null,
|
|
20763
22127
|
createMessage: createMessage,
|
|
@@ -20783,6 +22147,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
20783
22147
|
onMessageFetched: onMessageFetched,
|
|
20784
22148
|
getMessage: getMessage,
|
|
20785
22149
|
getMessages: getMessages,
|
|
22150
|
+
searchMessage: searchMessage,
|
|
20786
22151
|
convertFromRaw: convertFromRaw$1,
|
|
20787
22152
|
prepareMessagePayload: prepareMessagePayload,
|
|
20788
22153
|
convertParams: convertParams,
|
|
@@ -21630,6 +22995,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21630
22995
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
21631
22996
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
21632
22997
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
22998
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
21633
22999
|
].includes(action)) {
|
|
21634
23000
|
if (Array.isArray(payload)) {
|
|
21635
23001
|
collection.data = [
|
|
@@ -21639,6 +23005,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21639
23005
|
else
|
|
21640
23006
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
21641
23007
|
}
|
|
23008
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
23009
|
+
const ids = Array.isArray(payload)
|
|
23010
|
+
? payload.map(getResolver('channel'))
|
|
23011
|
+
: [getResolver('channel')(payload)];
|
|
23012
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
23013
|
+
}
|
|
21642
23014
|
pushToCache(this.cacheKey, collection);
|
|
21643
23015
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21644
23016
|
};
|
|
@@ -21905,6 +23277,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21905
23277
|
},
|
|
21906
23278
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
21907
23279
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
23280
|
+
{
|
|
23281
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
23282
|
+
const channels = payload.archives
|
|
23283
|
+
.map(archive => {
|
|
23284
|
+
var _a;
|
|
23285
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23286
|
+
})
|
|
23287
|
+
.filter((c) => Boolean(c));
|
|
23288
|
+
if (channels.length > 0)
|
|
23289
|
+
reactor(channels);
|
|
23290
|
+
}),
|
|
23291
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23292
|
+
},
|
|
23293
|
+
{
|
|
23294
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
23295
|
+
const channels = payload.archives
|
|
23296
|
+
.map(archive => {
|
|
23297
|
+
var _a;
|
|
23298
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23299
|
+
})
|
|
23300
|
+
.filter((c) => Boolean(c));
|
|
23301
|
+
if (channels.length > 0)
|
|
23302
|
+
reactor(channels);
|
|
23303
|
+
}),
|
|
23304
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23305
|
+
},
|
|
21908
23306
|
{
|
|
21909
23307
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
21910
23308
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -22083,181 +23481,766 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
22083
23481
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
22084
23482
|
},
|
|
22085
23483
|
];
|
|
22086
|
-
if (this.paginationController instanceof PaginationController) {
|
|
22087
|
-
return [
|
|
22088
|
-
...subscriptions,
|
|
22089
|
-
{
|
|
22090
|
-
fn: (callback) => {
|
|
22091
|
-
return onChannelCreated(channel => {
|
|
22092
|
-
resolveUnreadInfoOnChannelEvent(channel);
|
|
22093
|
-
callback(channel);
|
|
22094
|
-
});
|
|
22095
|
-
},
|
|
22096
|
-
action: "onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
22097
|
-
},
|
|
22098
|
-
];
|
|
22099
|
-
}
|
|
22100
|
-
return subscriptions;
|
|
23484
|
+
if (this.paginationController instanceof PaginationController) {
|
|
23485
|
+
return [
|
|
23486
|
+
...subscriptions,
|
|
23487
|
+
{
|
|
23488
|
+
fn: (callback) => {
|
|
23489
|
+
return onChannelCreated(channel => {
|
|
23490
|
+
resolveUnreadInfoOnChannelEvent(channel);
|
|
23491
|
+
callback(channel);
|
|
23492
|
+
});
|
|
23493
|
+
},
|
|
23494
|
+
action: "onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
23495
|
+
},
|
|
23496
|
+
];
|
|
23497
|
+
}
|
|
23498
|
+
return subscriptions;
|
|
23499
|
+
}
|
|
23500
|
+
}
|
|
23501
|
+
|
|
23502
|
+
/* eslint-disable no-use-before-define */
|
|
23503
|
+
/* begin_public_function
|
|
23504
|
+
id: channel.query
|
|
23505
|
+
*/
|
|
23506
|
+
/**
|
|
23507
|
+
* ```js
|
|
23508
|
+
* import { getChannels } from '@amityco/ts-sdk'
|
|
23509
|
+
*
|
|
23510
|
+
* let channels = []
|
|
23511
|
+
* const unsub = getChannels({
|
|
23512
|
+
* displayName: Amity.Channel['displayName'],
|
|
23513
|
+
* }, response => merge(channels, response.data))
|
|
23514
|
+
* ```
|
|
23515
|
+
*
|
|
23516
|
+
* Observe all mutations on a list of {@link Amity.Channel}s
|
|
23517
|
+
*
|
|
23518
|
+
* @param params for querying channels
|
|
23519
|
+
* @param callback the function to call when new data are available
|
|
23520
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the channels
|
|
23521
|
+
*
|
|
23522
|
+
* @category Channel Live Collection
|
|
23523
|
+
*/
|
|
23524
|
+
const getChannels = (params, callback, config) => {
|
|
23525
|
+
const { log, cache, userId } = getActiveClient();
|
|
23526
|
+
if (!cache) {
|
|
23527
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23528
|
+
}
|
|
23529
|
+
const timestamp = Date.now();
|
|
23530
|
+
log(`getChannels(tmpid: ${timestamp}) > listen`);
|
|
23531
|
+
const channelLiveCollection = new ChannelLiveCollectionController(params, callback);
|
|
23532
|
+
const disposers = channelLiveCollection.startSubscription();
|
|
23533
|
+
const cacheKey = channelLiveCollection.getCacheKey();
|
|
23534
|
+
disposers.push(() => {
|
|
23535
|
+
dropFromCache(cacheKey);
|
|
23536
|
+
});
|
|
23537
|
+
return () => {
|
|
23538
|
+
log(`getChannels(tmpid: ${timestamp}) > dispose`);
|
|
23539
|
+
disposers.forEach(fn => fn());
|
|
23540
|
+
};
|
|
23541
|
+
};
|
|
23542
|
+
/* end_public_function */
|
|
23543
|
+
|
|
23544
|
+
/**
|
|
23545
|
+
*
|
|
23546
|
+
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
23547
|
+
*
|
|
23548
|
+
* @returns the {@link Amity.UserUnread} objects
|
|
23549
|
+
*
|
|
23550
|
+
* @category Channel API
|
|
23551
|
+
* @async
|
|
23552
|
+
*/
|
|
23553
|
+
const getTotalChannelsUnread$1 = () => {
|
|
23554
|
+
var _a;
|
|
23555
|
+
const client = getActiveClient();
|
|
23556
|
+
client.log('channel/getTotalChannelsUnread.locally');
|
|
23557
|
+
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
23558
|
+
return !data.isDeleted;
|
|
23559
|
+
})) || [];
|
|
23560
|
+
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
23561
|
+
acc.unreadCount += data.unreadCount;
|
|
23562
|
+
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
23563
|
+
return acc;
|
|
23564
|
+
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
23565
|
+
const cachedAt = client.cache && Date.now();
|
|
23566
|
+
return {
|
|
23567
|
+
data: totalChannelsUnread,
|
|
23568
|
+
cachedAt,
|
|
23569
|
+
};
|
|
23570
|
+
};
|
|
23571
|
+
|
|
23572
|
+
/* begin_public_function
|
|
23573
|
+
id: totalChannelsUnread.get
|
|
23574
|
+
*/
|
|
23575
|
+
/**
|
|
23576
|
+
* ```js
|
|
23577
|
+
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
23578
|
+
*
|
|
23579
|
+
* let totalChannelsUnread;
|
|
23580
|
+
*
|
|
23581
|
+
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
23582
|
+
* unread = response.data;
|
|
23583
|
+
* });
|
|
23584
|
+
* ```
|
|
23585
|
+
*
|
|
23586
|
+
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
23587
|
+
*
|
|
23588
|
+
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
23589
|
+
*
|
|
23590
|
+
* @category User Unread Live Object
|
|
23591
|
+
*
|
|
23592
|
+
*/
|
|
23593
|
+
const getTotalChannelsUnread = (callback) => {
|
|
23594
|
+
const { _id: userId } = getActiveUser();
|
|
23595
|
+
if (!userId)
|
|
23596
|
+
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
23597
|
+
const { log, cache } = getActiveClient();
|
|
23598
|
+
if (!cache) {
|
|
23599
|
+
console.log('For using Live Object feature you need to enable Cache!');
|
|
23600
|
+
}
|
|
23601
|
+
const timestamp = Date.now();
|
|
23602
|
+
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
23603
|
+
const disposers = [];
|
|
23604
|
+
let isUnsyncedModel = false; // for messages
|
|
23605
|
+
let model;
|
|
23606
|
+
const dispatcher = (data) => {
|
|
23607
|
+
const { data: userUnread } = data;
|
|
23608
|
+
const callbackModel = userUnread
|
|
23609
|
+
? {
|
|
23610
|
+
unreadCount: userUnread.unreadCount,
|
|
23611
|
+
isMentioned: userUnread.isMentioned,
|
|
23612
|
+
}
|
|
23613
|
+
: undefined;
|
|
23614
|
+
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
23615
|
+
callback({
|
|
23616
|
+
data: callbackModel
|
|
23617
|
+
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
23618
|
+
loading: data.loading,
|
|
23619
|
+
error: data.error,
|
|
23620
|
+
});
|
|
23621
|
+
};
|
|
23622
|
+
const realtimeRouter = (_) => {
|
|
23623
|
+
const { data: userUnread } = getTotalChannelsUnread$1();
|
|
23624
|
+
if (isEqual(model, userUnread))
|
|
23625
|
+
return;
|
|
23626
|
+
dispatcher({
|
|
23627
|
+
loading: false,
|
|
23628
|
+
data: userUnread,
|
|
23629
|
+
});
|
|
23630
|
+
};
|
|
23631
|
+
const onFetch = () => {
|
|
23632
|
+
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
23633
|
+
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
23634
|
+
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
23635
|
+
dispatcher({
|
|
23636
|
+
data,
|
|
23637
|
+
origin,
|
|
23638
|
+
loading: false,
|
|
23639
|
+
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
23640
|
+
});
|
|
23641
|
+
isUnsyncedModel = true;
|
|
23642
|
+
disposers.forEach(fn => fn());
|
|
23643
|
+
}
|
|
23644
|
+
else if (!isUnsyncedModel) {
|
|
23645
|
+
dispatcher({ loading, data, origin, error });
|
|
23646
|
+
}
|
|
23647
|
+
if (error) {
|
|
23648
|
+
disposers.forEach(fn => fn());
|
|
23649
|
+
}
|
|
23650
|
+
});
|
|
23651
|
+
};
|
|
23652
|
+
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
23653
|
+
onFetch();
|
|
23654
|
+
return () => {
|
|
23655
|
+
disposers.forEach(fn => fn());
|
|
23656
|
+
};
|
|
23657
|
+
};
|
|
23658
|
+
|
|
23659
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
23660
|
+
async getRequest(queryParams, token) {
|
|
23661
|
+
var _a, _b;
|
|
23662
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
23663
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
23664
|
+
if (pageIndex === 0) {
|
|
23665
|
+
await getArchivedChannelIds();
|
|
23666
|
+
}
|
|
23667
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
23668
|
+
const archives = cached
|
|
23669
|
+
.map(entry => entry.data)
|
|
23670
|
+
.slice()
|
|
23671
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
23672
|
+
const start = pageIndex * limit;
|
|
23673
|
+
const end = start + limit;
|
|
23674
|
+
const slice = archives.slice(start, end);
|
|
23675
|
+
const hasMore = end < archives.length;
|
|
23676
|
+
if (slice.length > 0) {
|
|
23677
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
23678
|
+
}
|
|
23679
|
+
return {
|
|
23680
|
+
archives: slice,
|
|
23681
|
+
paging: {
|
|
23682
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
23683
|
+
previous: undefined,
|
|
23684
|
+
},
|
|
23685
|
+
};
|
|
23686
|
+
}
|
|
23687
|
+
}
|
|
23688
|
+
|
|
23689
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
23690
|
+
constructor(query, cacheKey, notifyChange) {
|
|
23691
|
+
super(query, cacheKey);
|
|
23692
|
+
this.notifyChange = notifyChange;
|
|
23693
|
+
}
|
|
23694
|
+
async saveToMainDB(_response) {
|
|
23695
|
+
//
|
|
23696
|
+
}
|
|
23697
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23698
|
+
var _a, _b;
|
|
23699
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
23700
|
+
if (refresh) {
|
|
23701
|
+
pushToCache(this.cacheKey, {
|
|
23702
|
+
data: channelIds,
|
|
23703
|
+
params: {},
|
|
23704
|
+
});
|
|
23705
|
+
return;
|
|
23706
|
+
}
|
|
23707
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23708
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23709
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
23710
|
+
? [...new Set([...channelIds, ...existing])]
|
|
23711
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
23712
|
+
}
|
|
23713
|
+
reactor(action) {
|
|
23714
|
+
return (channelIds) => {
|
|
23715
|
+
var _a;
|
|
23716
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23717
|
+
if (!collection)
|
|
23718
|
+
return;
|
|
23719
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
23720
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
23721
|
+
collection.data = [...channelIds, ...filtered];
|
|
23722
|
+
}
|
|
23723
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
23724
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
23725
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
23726
|
+
}
|
|
23727
|
+
pushToCache(this.cacheKey, collection);
|
|
23728
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23729
|
+
};
|
|
23730
|
+
}
|
|
23731
|
+
subscribeRTE(createSubscriber) {
|
|
23732
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23733
|
+
}
|
|
23734
|
+
}
|
|
23735
|
+
|
|
23736
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
23737
|
+
constructor(query, callback) {
|
|
23738
|
+
const queryStreamId = hash__default["default"](query);
|
|
23739
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
23740
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
23741
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23742
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
23743
|
+
this.callback = callback.bind(this);
|
|
23744
|
+
this.loadPage({ initial: true });
|
|
23745
|
+
}
|
|
23746
|
+
setup() {
|
|
23747
|
+
var _a;
|
|
23748
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23749
|
+
if (!collection) {
|
|
23750
|
+
pushToCache(this.cacheKey, {
|
|
23751
|
+
data: [],
|
|
23752
|
+
params: {},
|
|
23753
|
+
});
|
|
23754
|
+
}
|
|
23755
|
+
}
|
|
23756
|
+
async persistModel(response) {
|
|
23757
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
23758
|
+
}
|
|
23759
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23760
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23761
|
+
}
|
|
23762
|
+
startSubscription() {
|
|
23763
|
+
return this.queryStreamController.subscribeRTE([
|
|
23764
|
+
{
|
|
23765
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23766
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23767
|
+
},
|
|
23768
|
+
{
|
|
23769
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23770
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23771
|
+
},
|
|
23772
|
+
{
|
|
23773
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
23774
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
23775
|
+
},
|
|
23776
|
+
{
|
|
23777
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
23778
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
23779
|
+
},
|
|
23780
|
+
]);
|
|
23781
|
+
}
|
|
23782
|
+
notifyChange({ origin, loading, error }) {
|
|
23783
|
+
var _a, _b;
|
|
23784
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23785
|
+
if (!collection)
|
|
23786
|
+
return;
|
|
23787
|
+
const data = (_b = collection.data
|
|
23788
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
23789
|
+
.filter((entry) => Boolean(entry))
|
|
23790
|
+
.map(({ data: channel }) => channel)
|
|
23791
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
23792
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23793
|
+
return;
|
|
23794
|
+
this.callback({
|
|
23795
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23796
|
+
data,
|
|
23797
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23798
|
+
loading,
|
|
23799
|
+
error,
|
|
23800
|
+
});
|
|
23801
|
+
}
|
|
23802
|
+
}
|
|
23803
|
+
|
|
23804
|
+
/* begin_public_function
|
|
23805
|
+
id: channel.archive.collection
|
|
23806
|
+
*/
|
|
23807
|
+
/**
|
|
23808
|
+
* ```js
|
|
23809
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
23810
|
+
*
|
|
23811
|
+
* let channels = []
|
|
23812
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
23813
|
+
* ```
|
|
23814
|
+
*
|
|
23815
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
23816
|
+
*
|
|
23817
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
23818
|
+
* archive list takes no other filters).
|
|
23819
|
+
* @param callback the function to call when new data are available
|
|
23820
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
23821
|
+
* stop observing.
|
|
23822
|
+
*
|
|
23823
|
+
* @category Channel Live Collection
|
|
23824
|
+
*/
|
|
23825
|
+
const getArchivedChannels = (params, callback) => {
|
|
23826
|
+
const { log, cache } = getActiveClient();
|
|
23827
|
+
if (!cache) {
|
|
23828
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23829
|
+
}
|
|
23830
|
+
const timestamp = Date.now();
|
|
23831
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
23832
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
23833
|
+
const disposers = controller.startSubscription();
|
|
23834
|
+
const cacheKey = controller.getCacheKey();
|
|
23835
|
+
disposers.push(() => {
|
|
23836
|
+
dropFromCache(cacheKey);
|
|
23837
|
+
});
|
|
23838
|
+
return () => {
|
|
23839
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
23840
|
+
disposers.forEach(fn => fn());
|
|
23841
|
+
};
|
|
23842
|
+
};
|
|
23843
|
+
/* end_public_function */
|
|
23844
|
+
|
|
23845
|
+
class SearchChannelPaginationController extends PaginationController {
|
|
23846
|
+
async getRequest(queryParams, token) {
|
|
23847
|
+
const { query, exactMatch, isMemberOnly, types, tags, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_SIZE, } = queryParams;
|
|
23848
|
+
const options = token ? { token } : { limit: Math.min(100, Math.max(1, limit)) };
|
|
23849
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/channels`, {
|
|
23850
|
+
params: {
|
|
23851
|
+
query,
|
|
23852
|
+
exactMatch,
|
|
23853
|
+
isMemberOnly,
|
|
23854
|
+
types,
|
|
23855
|
+
tags,
|
|
23856
|
+
sortBy,
|
|
23857
|
+
orderBy,
|
|
23858
|
+
options,
|
|
23859
|
+
},
|
|
23860
|
+
});
|
|
23861
|
+
return queryResponse;
|
|
23862
|
+
}
|
|
23863
|
+
}
|
|
23864
|
+
|
|
23865
|
+
class SearchChannelQueryStreamController extends QueryStreamController {
|
|
23866
|
+
constructor(query, cacheKey, notifyChange) {
|
|
23867
|
+
super(query, cacheKey);
|
|
23868
|
+
this.notifyChange = notifyChange;
|
|
23869
|
+
}
|
|
23870
|
+
async saveToMainDB(response) {
|
|
23871
|
+
const processedPayload = await prepareChannelPayload(response);
|
|
23872
|
+
const client = getActiveClient();
|
|
23873
|
+
const cachedAt = client.cache && Date.now();
|
|
23874
|
+
if (client.cache) {
|
|
23875
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23876
|
+
}
|
|
23877
|
+
}
|
|
23878
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23879
|
+
var _a, _b;
|
|
23880
|
+
if (refresh) {
|
|
23881
|
+
pushToCache(this.cacheKey, {
|
|
23882
|
+
data: response.channels.map(getResolver('channel')),
|
|
23883
|
+
});
|
|
23884
|
+
return;
|
|
23885
|
+
}
|
|
23886
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23887
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23888
|
+
const incoming = response.channels.map(getResolver('channel'));
|
|
23889
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
23890
|
+
? [...new Set([...incoming, ...existing])]
|
|
23891
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
23892
|
+
}
|
|
23893
|
+
reactor() {
|
|
23894
|
+
return () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23895
|
+
}
|
|
23896
|
+
subscribeRTE(createSubscriber) {
|
|
23897
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor()));
|
|
23898
|
+
}
|
|
23899
|
+
}
|
|
23900
|
+
|
|
23901
|
+
/* eslint-disable no-use-before-define */
|
|
23902
|
+
const getMessagePreviewSetting = () => {
|
|
23903
|
+
const client = getActiveClient();
|
|
23904
|
+
return client.getMessagePreviewSetting(false);
|
|
23905
|
+
};
|
|
23906
|
+
class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
23907
|
+
constructor(query, callback) {
|
|
23908
|
+
const queryStreamId = hash__default["default"](query);
|
|
23909
|
+
const cacheKey = ['channel', 'search', queryStreamId];
|
|
23910
|
+
const paginationController = new SearchChannelPaginationController(query);
|
|
23911
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23912
|
+
this.queryStreamController = new SearchChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
23913
|
+
this.callback = callback.bind(this);
|
|
23914
|
+
this.loadPage({ initial: true });
|
|
23915
|
+
}
|
|
23916
|
+
startSubscription() {
|
|
23917
|
+
return this.queryStreamController.subscribeRTE(this.getSubscriptions());
|
|
23918
|
+
}
|
|
23919
|
+
notifyChange({ origin, loading, error }) {
|
|
23920
|
+
var _a, _b;
|
|
23921
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23922
|
+
if (!collection)
|
|
23923
|
+
return;
|
|
23924
|
+
const data = (_b = collection.data
|
|
23925
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
23926
|
+
.filter(Boolean)
|
|
23927
|
+
.map(cached => constructChannelObject(cached.data))) !== null && _b !== void 0 ? _b : [];
|
|
23928
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23929
|
+
return;
|
|
23930
|
+
this.callback({
|
|
23931
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23932
|
+
data,
|
|
23933
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23934
|
+
loading,
|
|
23935
|
+
error,
|
|
23936
|
+
});
|
|
23937
|
+
}
|
|
23938
|
+
setup() {
|
|
23939
|
+
var _a;
|
|
23940
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23941
|
+
if (!collection) {
|
|
23942
|
+
pushToCache(this.cacheKey, {
|
|
23943
|
+
data: [],
|
|
23944
|
+
params: {},
|
|
23945
|
+
});
|
|
23946
|
+
}
|
|
23947
|
+
}
|
|
23948
|
+
async persistModel(response) {
|
|
23949
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
23950
|
+
}
|
|
23951
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23952
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23953
|
+
}
|
|
23954
|
+
shouldAbort(targetChannelId) {
|
|
23955
|
+
var _a;
|
|
23956
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23957
|
+
if (!collection)
|
|
23958
|
+
return true;
|
|
23959
|
+
return !collection.data.find(channelId => channelId === targetChannelId);
|
|
23960
|
+
}
|
|
23961
|
+
getSubscriptions() {
|
|
23962
|
+
return [
|
|
23963
|
+
{
|
|
23964
|
+
fn: convertEventPayload((callback) => {
|
|
23965
|
+
return onMessageCreatedMqtt(message => {
|
|
23966
|
+
var _a;
|
|
23967
|
+
const cacheData = (_a = pullFromCache([
|
|
23968
|
+
'channel',
|
|
23969
|
+
'get',
|
|
23970
|
+
message.channelId,
|
|
23971
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23972
|
+
if (!cacheData)
|
|
23973
|
+
return;
|
|
23974
|
+
updateChannelCache(cacheData, {
|
|
23975
|
+
lastActivity: message.createdAt,
|
|
23976
|
+
});
|
|
23977
|
+
callback(message);
|
|
23978
|
+
});
|
|
23979
|
+
}, 'channelId', 'channel'),
|
|
23980
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
23981
|
+
},
|
|
23982
|
+
{
|
|
23983
|
+
fn: convertEventPayload((callback) => {
|
|
23984
|
+
return onMessageCreatedLocal(message => {
|
|
23985
|
+
var _a;
|
|
23986
|
+
const cacheData = (_a = pullFromCache([
|
|
23987
|
+
'channel',
|
|
23988
|
+
'get',
|
|
23989
|
+
message.channelId,
|
|
23990
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23991
|
+
if (!cacheData)
|
|
23992
|
+
return;
|
|
23993
|
+
updateChannelCache(cacheData, {
|
|
23994
|
+
lastActivity: message.createdAt,
|
|
23995
|
+
});
|
|
23996
|
+
callback(message);
|
|
23997
|
+
});
|
|
23998
|
+
}, 'channelId', 'channel'),
|
|
23999
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24000
|
+
},
|
|
24001
|
+
{ fn: onChannelDeleted, action: "onDelete" /* Amity.ChannelActionType.OnDelete */ },
|
|
24002
|
+
{ fn: onChannelUpdated, action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */ },
|
|
24003
|
+
{ fn: onChannelSetMuted, action: "onMute" /* Amity.ChannelActionType.OnMute */ },
|
|
24004
|
+
{
|
|
24005
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
24006
|
+
const channels = payload.archives
|
|
24007
|
+
.map(archive => {
|
|
24008
|
+
var _a;
|
|
24009
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24010
|
+
})
|
|
24011
|
+
.filter((c) => Boolean(c));
|
|
24012
|
+
if (channels.length > 0)
|
|
24013
|
+
reactor(channels);
|
|
24014
|
+
}),
|
|
24015
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
24016
|
+
},
|
|
24017
|
+
{
|
|
24018
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
24019
|
+
const channels = payload.archives
|
|
24020
|
+
.map(archive => {
|
|
24021
|
+
var _a;
|
|
24022
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24023
|
+
})
|
|
24024
|
+
.filter((c) => Boolean(c));
|
|
24025
|
+
if (channels.length > 0)
|
|
24026
|
+
reactor(channels);
|
|
24027
|
+
}),
|
|
24028
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
24029
|
+
},
|
|
24030
|
+
{
|
|
24031
|
+
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
24032
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24033
|
+
},
|
|
24034
|
+
{
|
|
24035
|
+
fn: convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
|
|
24036
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24037
|
+
},
|
|
24038
|
+
{
|
|
24039
|
+
fn: convertEventPayload((callback) => {
|
|
24040
|
+
const updateMessagePreview = async (message) => {
|
|
24041
|
+
var _a;
|
|
24042
|
+
const messagePreviewSetting = await getMessagePreviewSetting();
|
|
24043
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
24044
|
+
return;
|
|
24045
|
+
handleMessageCreated(message);
|
|
24046
|
+
if (this.shouldAbort(message.channelId))
|
|
24047
|
+
return;
|
|
24048
|
+
const channel = (_a = pullFromCache([
|
|
24049
|
+
'channel',
|
|
24050
|
+
'get',
|
|
24051
|
+
message.channelId,
|
|
24052
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24053
|
+
if (!channel)
|
|
24054
|
+
return;
|
|
24055
|
+
updateChannelCache(channel, {
|
|
24056
|
+
messagePreviewId: message.messageId,
|
|
24057
|
+
});
|
|
24058
|
+
callback(message);
|
|
24059
|
+
};
|
|
24060
|
+
return onMessageCreatedMqtt(updateMessagePreview);
|
|
24061
|
+
}, 'channelId', 'channel'),
|
|
24062
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24063
|
+
},
|
|
24064
|
+
{
|
|
24065
|
+
fn: convertEventPayload((callback) => {
|
|
24066
|
+
const updateMessagePreview = async (message) => {
|
|
24067
|
+
var _a;
|
|
24068
|
+
const messagePreviewSetting = await getMessagePreviewSetting();
|
|
24069
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
24070
|
+
return;
|
|
24071
|
+
handleMessageCreated(message);
|
|
24072
|
+
if (this.shouldAbort(message.channelId))
|
|
24073
|
+
return;
|
|
24074
|
+
const channel = (_a = pullFromCache([
|
|
24075
|
+
'channel',
|
|
24076
|
+
'get',
|
|
24077
|
+
message.channelId,
|
|
24078
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24079
|
+
if (!channel)
|
|
24080
|
+
return;
|
|
24081
|
+
updateChannelCache(channel, {
|
|
24082
|
+
messagePreviewId: message.messageId,
|
|
24083
|
+
});
|
|
24084
|
+
callback(message);
|
|
24085
|
+
};
|
|
24086
|
+
return onMessageCreatedLocal(updateMessagePreview);
|
|
24087
|
+
}, 'channelId', 'channel'),
|
|
24088
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24089
|
+
},
|
|
24090
|
+
{
|
|
24091
|
+
fn: convertEventPayload((callback) => {
|
|
24092
|
+
const updateMessagePreview = async (message) => {
|
|
24093
|
+
const messagePreviewSetting = await getMessagePreviewSetting();
|
|
24094
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
24095
|
+
return;
|
|
24096
|
+
handleMessageUpdated(message);
|
|
24097
|
+
if (this.shouldAbort(message.channelId))
|
|
24098
|
+
return;
|
|
24099
|
+
callback(message);
|
|
24100
|
+
};
|
|
24101
|
+
return onMessageUpdated(updateMessagePreview);
|
|
24102
|
+
}, 'channelId', 'channel'),
|
|
24103
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24104
|
+
},
|
|
24105
|
+
{
|
|
24106
|
+
fn: convertEventPayload((callback) => {
|
|
24107
|
+
const updateMessagePreview = async (message) => {
|
|
24108
|
+
const messagePreviewSetting = await getMessagePreviewSetting();
|
|
24109
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
24110
|
+
return;
|
|
24111
|
+
if (messagePreviewSetting ===
|
|
24112
|
+
"message-preview-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_INCLUDE_DELETED */)
|
|
24113
|
+
await handleMessageUpdated(message);
|
|
24114
|
+
if (this.shouldAbort(message.channelId))
|
|
24115
|
+
return;
|
|
24116
|
+
if (messagePreviewSetting ===
|
|
24117
|
+
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
24118
|
+
await getChannel$1(message.channelId);
|
|
24119
|
+
}
|
|
24120
|
+
callback(message);
|
|
24121
|
+
};
|
|
24122
|
+
return onMessageDeleted(updateMessagePreview);
|
|
24123
|
+
}, 'channelId', 'channel'),
|
|
24124
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24125
|
+
},
|
|
24126
|
+
{
|
|
24127
|
+
fn: convertEventPayload((callback) => {
|
|
24128
|
+
const updateMessagePreview = async (subChannel) => {
|
|
24129
|
+
var _a;
|
|
24130
|
+
const collections = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24131
|
+
if (!collections)
|
|
24132
|
+
return;
|
|
24133
|
+
const channelId = collections.data.find(channel => {
|
|
24134
|
+
const messagePreviewCache = getChannelMessagePreview(channel);
|
|
24135
|
+
return (messagePreviewCache === null || messagePreviewCache === void 0 ? void 0 : messagePreviewCache.subChannelId) === subChannel.subChannelId;
|
|
24136
|
+
});
|
|
24137
|
+
if (!channelId)
|
|
24138
|
+
return;
|
|
24139
|
+
await getChannel$1(subChannel.channelId);
|
|
24140
|
+
callback(subChannel);
|
|
24141
|
+
};
|
|
24142
|
+
return onSubChannelDeleted(updateMessagePreview);
|
|
24143
|
+
}, 'channelId', 'channel'),
|
|
24144
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24145
|
+
},
|
|
24146
|
+
{
|
|
24147
|
+
fn: convertEventPayload((callback) => {
|
|
24148
|
+
const updateMessagePreview = async (subChannel) => {
|
|
24149
|
+
var _a;
|
|
24150
|
+
const messagePreviewSetting = await getMessagePreviewSetting();
|
|
24151
|
+
if (messagePreviewSetting === "no-message-preview" /* Amity.MessagePreviewSetting.NO_MESSAGE_PREVIEW */)
|
|
24152
|
+
return;
|
|
24153
|
+
const collections = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24154
|
+
if (!collections)
|
|
24155
|
+
return;
|
|
24156
|
+
await handleSubChannelUpdated(subChannel);
|
|
24157
|
+
if (this.shouldAbort(subChannel.channelId))
|
|
24158
|
+
return;
|
|
24159
|
+
callback(subChannel);
|
|
24160
|
+
};
|
|
24161
|
+
return onSubChannelUpdated(updateMessagePreview);
|
|
24162
|
+
}, 'channelId', 'channel'),
|
|
24163
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24164
|
+
},
|
|
24165
|
+
{
|
|
24166
|
+
fn: (callback) => {
|
|
24167
|
+
const handleUserFeedMarkerResolved = async (marker) => {
|
|
24168
|
+
if (marker.feedMarkers) {
|
|
24169
|
+
const channels = marker.feedMarkers
|
|
24170
|
+
.map(feedMarker => {
|
|
24171
|
+
var _a;
|
|
24172
|
+
return (_a = pullFromCache([
|
|
24173
|
+
'channel',
|
|
24174
|
+
'get',
|
|
24175
|
+
feedMarker.entityId,
|
|
24176
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24177
|
+
})
|
|
24178
|
+
.filter(Boolean);
|
|
24179
|
+
callback(channels);
|
|
24180
|
+
}
|
|
24181
|
+
};
|
|
24182
|
+
return onUserMessageFeedMarkerResolved(handleUserFeedMarkerResolved);
|
|
24183
|
+
},
|
|
24184
|
+
action: "OnResolveUnread" /* Amity.ChannelActionType.OnResolveUnread */,
|
|
24185
|
+
},
|
|
24186
|
+
{
|
|
24187
|
+
fn: convertEventPayload(onChannelUnreadInfoUpdatedLocal, 'channelId', 'channel'),
|
|
24188
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24189
|
+
},
|
|
24190
|
+
{
|
|
24191
|
+
fn: convertEventPayload((callback) => {
|
|
24192
|
+
const processPayload = (payloads) => {
|
|
24193
|
+
payloads.forEach(callback);
|
|
24194
|
+
};
|
|
24195
|
+
return onChannelUnreadUpdatedLocal(processPayload);
|
|
24196
|
+
}, 'channelId', 'channel'),
|
|
24197
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
24198
|
+
},
|
|
24199
|
+
];
|
|
22101
24200
|
}
|
|
22102
24201
|
}
|
|
22103
24202
|
|
|
22104
|
-
/* eslint-disable no-use-before-define */
|
|
22105
24203
|
/* begin_public_function
|
|
22106
|
-
id: channel.
|
|
24204
|
+
id: channel.search
|
|
22107
24205
|
*/
|
|
22108
24206
|
/**
|
|
22109
24207
|
* ```js
|
|
22110
|
-
* import {
|
|
24208
|
+
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
22111
24209
|
*
|
|
22112
|
-
*
|
|
22113
|
-
*
|
|
22114
|
-
*
|
|
22115
|
-
*
|
|
24210
|
+
* const unsubscribe = ChannelRepository.searchChannels(
|
|
24211
|
+
* { query: 'hello' },
|
|
24212
|
+
* response => response.data,
|
|
24213
|
+
* );
|
|
22116
24214
|
* ```
|
|
22117
24215
|
*
|
|
22118
|
-
*
|
|
24216
|
+
* Live collection of {@link Amity.Channel}s matching the search query. Backed by
|
|
24217
|
+
* `GET /api/v2/search/channels`.
|
|
22119
24218
|
*
|
|
22120
|
-
* @param params
|
|
22121
|
-
* @param callback
|
|
22122
|
-
* @returns An {@link Amity.Unsubscriber} function to
|
|
24219
|
+
* @param params Search parameters.
|
|
24220
|
+
* @param callback Called whenever new data are available.
|
|
24221
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
22123
24222
|
*
|
|
22124
24223
|
* @category Channel Live Collection
|
|
22125
24224
|
*/
|
|
22126
|
-
const
|
|
22127
|
-
const { log, cache
|
|
22128
|
-
if (!cache)
|
|
24225
|
+
const searchChannels = (params, callback) => {
|
|
24226
|
+
const { log, cache } = getActiveClient();
|
|
24227
|
+
if (!cache)
|
|
22129
24228
|
console.log(ENABLE_CACHE_MESSAGE);
|
|
22130
|
-
}
|
|
22131
24229
|
const timestamp = Date.now();
|
|
22132
|
-
log(`
|
|
22133
|
-
const
|
|
22134
|
-
const disposers =
|
|
22135
|
-
const cacheKey =
|
|
24230
|
+
log(`searchChannels(tmpid: ${timestamp}) > listen`);
|
|
24231
|
+
const searchChannelLiveCollection = new SearchChannelLiveCollectionController(params, callback);
|
|
24232
|
+
const disposers = searchChannelLiveCollection.startSubscription();
|
|
24233
|
+
const cacheKey = searchChannelLiveCollection.getCacheKey();
|
|
22136
24234
|
disposers.push(() => {
|
|
22137
24235
|
dropFromCache(cacheKey);
|
|
22138
24236
|
});
|
|
22139
24237
|
return () => {
|
|
22140
|
-
log(`
|
|
24238
|
+
log(`searchChannels(tmpid: ${timestamp}) > dispose`);
|
|
22141
24239
|
disposers.forEach(fn => fn());
|
|
22142
24240
|
};
|
|
22143
24241
|
};
|
|
22144
24242
|
/* end_public_function */
|
|
22145
24243
|
|
|
22146
|
-
/**
|
|
22147
|
-
*
|
|
22148
|
-
* Calculate user unread from {@link Amity.ChannelUnread} objects
|
|
22149
|
-
*
|
|
22150
|
-
* @returns the {@link Amity.UserUnread} objects
|
|
22151
|
-
*
|
|
22152
|
-
* @category Channel API
|
|
22153
|
-
* @async
|
|
22154
|
-
*/
|
|
22155
|
-
const getTotalChannelsUnread$1 = () => {
|
|
22156
|
-
var _a;
|
|
22157
|
-
const client = getActiveClient();
|
|
22158
|
-
client.log('channel/getTotalChannelsUnread.locally');
|
|
22159
|
-
const cachedChannelsUnread = ((_a = queryCache(['channelUnread', 'get'])) === null || _a === void 0 ? void 0 : _a.filter(({ data }) => {
|
|
22160
|
-
return !data.isDeleted;
|
|
22161
|
-
})) || [];
|
|
22162
|
-
const totalChannelsUnread = (cachedChannelsUnread === null || cachedChannelsUnread === void 0 ? void 0 : cachedChannelsUnread.reduce((acc, { data }) => {
|
|
22163
|
-
acc.unreadCount += data.unreadCount;
|
|
22164
|
-
acc.isMentioned = acc.isMentioned || data.isMentioned;
|
|
22165
|
-
return acc;
|
|
22166
|
-
}, { unreadCount: 0, isMentioned: false })) || { unreadCount: 0, isMentioned: false };
|
|
22167
|
-
const cachedAt = client.cache && Date.now();
|
|
22168
|
-
return {
|
|
22169
|
-
data: totalChannelsUnread,
|
|
22170
|
-
cachedAt,
|
|
22171
|
-
};
|
|
22172
|
-
};
|
|
22173
|
-
|
|
22174
|
-
/* begin_public_function
|
|
22175
|
-
id: totalChannelsUnread.get
|
|
22176
|
-
*/
|
|
22177
|
-
/**
|
|
22178
|
-
* ```js
|
|
22179
|
-
* import { ChannelRepository } from '@amityco/ts-sdk';
|
|
22180
|
-
*
|
|
22181
|
-
* let totalChannelsUnread;
|
|
22182
|
-
*
|
|
22183
|
-
* const unsubscribe = ChannelRepository.getTotalChannelsUnread(response => {
|
|
22184
|
-
* unread = response.data;
|
|
22185
|
-
* });
|
|
22186
|
-
* ```
|
|
22187
|
-
*
|
|
22188
|
-
* Observe all mutation on a given {@link Amity.UserUnread}
|
|
22189
|
-
*
|
|
22190
|
-
* @returns An {@link Amity.UserUnread} function to run when willing to stop observing the message
|
|
22191
|
-
*
|
|
22192
|
-
* @category User Unread Live Object
|
|
22193
|
-
*
|
|
22194
|
-
*/
|
|
22195
|
-
const getTotalChannelsUnread = (callback) => {
|
|
22196
|
-
const { _id: userId } = getActiveUser();
|
|
22197
|
-
if (!userId)
|
|
22198
|
-
throw new ASCError('The _id has not been defined in ActiveUser', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
22199
|
-
const { log, cache } = getActiveClient();
|
|
22200
|
-
if (!cache) {
|
|
22201
|
-
console.log('For using Live Object feature you need to enable Cache!');
|
|
22202
|
-
}
|
|
22203
|
-
const timestamp = Date.now();
|
|
22204
|
-
log(`liveTotalChannelsUnread(tmpid: ${timestamp}) > listen`);
|
|
22205
|
-
const disposers = [];
|
|
22206
|
-
let isUnsyncedModel = false; // for messages
|
|
22207
|
-
let model;
|
|
22208
|
-
const dispatcher = (data) => {
|
|
22209
|
-
const { data: userUnread } = data;
|
|
22210
|
-
const callbackModel = userUnread
|
|
22211
|
-
? {
|
|
22212
|
-
unreadCount: userUnread.unreadCount,
|
|
22213
|
-
isMentioned: userUnread.isMentioned,
|
|
22214
|
-
}
|
|
22215
|
-
: undefined;
|
|
22216
|
-
model = callbackModel ? convertGetterPropsToStatic(callbackModel) : callbackModel;
|
|
22217
|
-
callback({
|
|
22218
|
-
data: callbackModel
|
|
22219
|
-
? Object.assign(Object.assign({}, callbackModel), { isMentioned: callbackModel.isMentioned }) : callbackModel,
|
|
22220
|
-
loading: data.loading,
|
|
22221
|
-
error: data.error,
|
|
22222
|
-
});
|
|
22223
|
-
};
|
|
22224
|
-
const realtimeRouter = (_) => {
|
|
22225
|
-
const { data: userUnread } = getTotalChannelsUnread$1();
|
|
22226
|
-
if (isEqual(model, userUnread))
|
|
22227
|
-
return;
|
|
22228
|
-
dispatcher({
|
|
22229
|
-
loading: false,
|
|
22230
|
-
data: userUnread,
|
|
22231
|
-
});
|
|
22232
|
-
};
|
|
22233
|
-
const onFetch = () => {
|
|
22234
|
-
const query = createQuery(async () => getTotalChannelsUnread$1());
|
|
22235
|
-
runQuery(query, ({ error, data, loading, origin, cachedAt }) => {
|
|
22236
|
-
if (cachedAt === UNSYNCED_OBJECT_CACHED_AT_VALUE) {
|
|
22237
|
-
dispatcher({
|
|
22238
|
-
data,
|
|
22239
|
-
origin,
|
|
22240
|
-
loading: false,
|
|
22241
|
-
error: new ASCApiError(UNSYNCED_OBJECT_CACHED_AT_MESSAGE, 800800 /* Amity.ClientError.DISALOOW_UNSYNCED_OBJECT */, "error" /* Amity.ErrorLevel.ERROR */),
|
|
22242
|
-
});
|
|
22243
|
-
isUnsyncedModel = true;
|
|
22244
|
-
disposers.forEach(fn => fn());
|
|
22245
|
-
}
|
|
22246
|
-
else if (!isUnsyncedModel) {
|
|
22247
|
-
dispatcher({ loading, data, origin, error });
|
|
22248
|
-
}
|
|
22249
|
-
if (error) {
|
|
22250
|
-
disposers.forEach(fn => fn());
|
|
22251
|
-
}
|
|
22252
|
-
});
|
|
22253
|
-
};
|
|
22254
|
-
disposers.push(onChannelUnreadUpdatedLocal(realtimeRouter));
|
|
22255
|
-
onFetch();
|
|
22256
|
-
return () => {
|
|
22257
|
-
disposers.forEach(fn => fn());
|
|
22258
|
-
};
|
|
22259
|
-
};
|
|
22260
|
-
|
|
22261
24244
|
/* begin_public_function
|
|
22262
24245
|
id: channel.member.add
|
|
22263
24246
|
*/
|
|
@@ -22389,7 +24372,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
22389
24372
|
channelId: this.query.channelId,
|
|
22390
24373
|
userId: channelMember.userId,
|
|
22391
24374
|
});
|
|
22392
|
-
|
|
24375
|
+
const membershipFilter = this.query.memberships;
|
|
24376
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
24377
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
22393
24378
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
22394
24379
|
}
|
|
22395
24380
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -22725,6 +24710,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
22725
24710
|
const cachedAt = client.cache && Date.now();
|
|
22726
24711
|
if (client.cache)
|
|
22727
24712
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24713
|
+
fireEvent('channel.banned', payload);
|
|
22728
24714
|
return {
|
|
22729
24715
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
22730
24716
|
cachedAt,
|
|
@@ -22759,6 +24745,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
22759
24745
|
const cachedAt = client.cache && Date.now();
|
|
22760
24746
|
if (client.cache)
|
|
22761
24747
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24748
|
+
fireEvent('channel.unbanned', payload);
|
|
22762
24749
|
const { channelUsers } = preparedPayload;
|
|
22763
24750
|
return {
|
|
22764
24751
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -22787,6 +24774,7 @@ const MUTE_FOREVER = -1;
|
|
|
22787
24774
|
* @async
|
|
22788
24775
|
* */
|
|
22789
24776
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
24777
|
+
var _a;
|
|
22790
24778
|
const client = getActiveClient();
|
|
22791
24779
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
22792
24780
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -22794,6 +24782,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22794
24782
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
22795
24783
|
});
|
|
22796
24784
|
const { success } = data;
|
|
24785
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
24786
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
24787
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
24788
|
+
fireEvent('channel.setMutedUsers', {
|
|
24789
|
+
channelId,
|
|
24790
|
+
userIds,
|
|
24791
|
+
muteTimeout,
|
|
24792
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24793
|
+
});
|
|
22797
24794
|
return success;
|
|
22798
24795
|
};
|
|
22799
24796
|
/* end_public_function */
|
|
@@ -22816,6 +24813,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22816
24813
|
* @async
|
|
22817
24814
|
* */
|
|
22818
24815
|
const unmuteMembers = async (channelId, userIds) => {
|
|
24816
|
+
var _a;
|
|
22819
24817
|
const client = getActiveClient();
|
|
22820
24818
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
22821
24819
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -22823,6 +24821,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22823
24821
|
mutePeriod: 0,
|
|
22824
24822
|
});
|
|
22825
24823
|
const { success } = data;
|
|
24824
|
+
fireEvent('channel.setMutedUsers', {
|
|
24825
|
+
channelId,
|
|
24826
|
+
userIds,
|
|
24827
|
+
muteTimeout: new Date(0).toISOString(),
|
|
24828
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24829
|
+
});
|
|
22826
24830
|
return success;
|
|
22827
24831
|
};
|
|
22828
24832
|
/* end_public_function */
|
|
@@ -22849,6 +24853,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22849
24853
|
leaveChannel: leaveChannel,
|
|
22850
24854
|
muteChannel: muteChannel,
|
|
22851
24855
|
unmuteChannel: unmuteChannel,
|
|
24856
|
+
archiveChannel: archiveChannel,
|
|
24857
|
+
unarchiveChannel: unarchiveChannel,
|
|
24858
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
22852
24859
|
onChannelCreated: onChannelCreated,
|
|
22853
24860
|
onChannelUpdated: onChannelUpdated,
|
|
22854
24861
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -22861,9 +24868,13 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22861
24868
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
22862
24869
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
22863
24870
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
24871
|
+
onChannelArchived: onChannelArchived,
|
|
24872
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
22864
24873
|
getChannel: getChannel,
|
|
22865
24874
|
getChannels: getChannels,
|
|
22866
24875
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
24876
|
+
getArchivedChannels: getArchivedChannels,
|
|
24877
|
+
searchChannels: searchChannels,
|
|
22867
24878
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
22868
24879
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22869
24880
|
convertFromRaw: convertFromRaw,
|
|
@@ -26759,7 +28770,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26759
28770
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26760
28771
|
}
|
|
26761
28772
|
startSubscription() {
|
|
26762
|
-
|
|
28773
|
+
const disposers = this.queryStreamController.subscribeRTE([
|
|
26763
28774
|
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
26764
28775
|
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
26765
28776
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
@@ -26772,6 +28783,11 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26772
28783
|
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
26773
28784
|
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
26774
28785
|
]);
|
|
28786
|
+
if (this.query.excludeBlockUserComments) {
|
|
28787
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28788
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
28789
|
+
}
|
|
28790
|
+
return disposers;
|
|
26775
28791
|
}
|
|
26776
28792
|
notifyChange({ origin, loading, error }) {
|
|
26777
28793
|
var _a, _b;
|
|
@@ -26824,6 +28840,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26824
28840
|
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
28841
|
}
|
|
26826
28842
|
}
|
|
28843
|
+
if (this.query.excludeBlockUserComments) {
|
|
28844
|
+
comments = filterCommentsByBlockUsers(comments);
|
|
28845
|
+
}
|
|
26827
28846
|
switch (this.query.sortBy) {
|
|
26828
28847
|
case 'firstCreated':
|
|
26829
28848
|
comments = comments.sort(sortByFirstCreated);
|
|
@@ -27909,13 +29928,253 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
27909
29928
|
};
|
|
27910
29929
|
/* end_public_function */
|
|
27911
29930
|
|
|
29931
|
+
/**
|
|
29932
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
29933
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
29934
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
29935
|
+
*
|
|
29936
|
+
* @category Errors
|
|
29937
|
+
*/
|
|
29938
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
29939
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
29940
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29941
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
29942
|
+
}
|
|
29943
|
+
}
|
|
29944
|
+
|
|
29945
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
29946
|
+
constructor(query) {
|
|
29947
|
+
super(query);
|
|
29948
|
+
this.checkedDisk = false;
|
|
29949
|
+
this.hasDeliveredPost = false;
|
|
29950
|
+
this.cursor = CursorController.current();
|
|
29951
|
+
}
|
|
29952
|
+
async getRequest(_queryParams, token) {
|
|
29953
|
+
var _a, _b, _c, _d, _e;
|
|
29954
|
+
const isFirstPage = token === undefined;
|
|
29955
|
+
let stored = null;
|
|
29956
|
+
// On the first page of a fresh collection, load the saved cursor from disk once.
|
|
29957
|
+
// Drop it if the snapshot has already expired so we start fresh.
|
|
29958
|
+
if (isFirstPage && !this.checkedDisk && this.cursor) {
|
|
29959
|
+
this.checkedDisk = true;
|
|
29960
|
+
stored = await this.cursor.get();
|
|
29961
|
+
if (stored && CursorController.isExpired(stored.expiredAt)) {
|
|
29962
|
+
await this.cursor.clear();
|
|
29963
|
+
stored = null;
|
|
29964
|
+
}
|
|
29965
|
+
}
|
|
29966
|
+
// Already paged to the end before. Ask the BE fresh (no cursor) and check if it's
|
|
29967
|
+
// still the same snapshot the user finished.
|
|
29968
|
+
if (isFirstPage && (stored === null || stored === void 0 ? void 0 : stored.reachedEndOfFeed)) {
|
|
29969
|
+
const fresh = await this.fetch();
|
|
29970
|
+
const freshExpiredAt = Date.parse((_b = (_a = fresh.paging) === null || _a === void 0 ? void 0 : _a.expiredAt) !== null && _b !== void 0 ? _b : '');
|
|
29971
|
+
const rolledOver = !Number.isNaN(freshExpiredAt) && freshExpiredAt !== stored.expiredAt;
|
|
29972
|
+
// New snapshot → serve it. Same snapshot → user has seen it all, show empty.
|
|
29973
|
+
if (rolledOver) {
|
|
29974
|
+
await this.persistCursor(fresh);
|
|
29975
|
+
if (fresh.posts.length > 0)
|
|
29976
|
+
this.hasDeliveredPost = true;
|
|
29977
|
+
return fresh;
|
|
29978
|
+
}
|
|
29979
|
+
return Object.assign(Object.assign({}, fresh), { posts: [], paging: {} });
|
|
29980
|
+
}
|
|
29981
|
+
// Resume from the saved cursor on re-entry; otherwise use the live-collection token.
|
|
29982
|
+
const effectiveToken = isFirstPage && stored ? stored.cursor : token;
|
|
29983
|
+
const response = await this.fetch(effectiveToken);
|
|
29984
|
+
if (response.posts.length > 0)
|
|
29985
|
+
this.hasDeliveredPost = true;
|
|
29986
|
+
if ((_c = response.paging) === null || _c === void 0 ? void 0 : _c.next) {
|
|
29987
|
+
// More pages left → advance the saved cursor.
|
|
29988
|
+
await this.persistCursor(response);
|
|
29989
|
+
}
|
|
29990
|
+
else if (this.hasDeliveredPost && this.cursor) {
|
|
29991
|
+
// Reached the end and mark end of feed
|
|
29992
|
+
const expiredAt = Date.parse((_e = (_d = response.paging) === null || _d === void 0 ? void 0 : _d.expiredAt) !== null && _e !== void 0 ? _e : '');
|
|
29993
|
+
if (!Number.isNaN(expiredAt))
|
|
29994
|
+
await this.cursor.markReachedEndOfFeed(expiredAt);
|
|
29995
|
+
}
|
|
29996
|
+
return response;
|
|
29997
|
+
}
|
|
29998
|
+
async fetch(token) {
|
|
29999
|
+
const options = { limit: COLLECTION_DEFAULT_PAGINATION_SIZE };
|
|
30000
|
+
if (token)
|
|
30001
|
+
options.token = token;
|
|
30002
|
+
try {
|
|
30003
|
+
const { data } = await this.http.get(API_ENDPOINTS.forYouFeed, {
|
|
30004
|
+
params: { options },
|
|
30005
|
+
});
|
|
30006
|
+
return data;
|
|
30007
|
+
}
|
|
30008
|
+
catch (error) {
|
|
30009
|
+
if (error instanceof ASCApiError && error.code === 400300 /* Amity.ServerError.FORBIDDEN */) {
|
|
30010
|
+
throw new AmityForYouFeedDisabledError();
|
|
30011
|
+
}
|
|
30012
|
+
const recoverable = error instanceof ASCApiError && error.code === 400322 /* Amity.ServerError.FEED_SNAPSHOT_EXPIRED */;
|
|
30013
|
+
if (recoverable && token !== undefined) {
|
|
30014
|
+
if (this.cursor)
|
|
30015
|
+
await this.cursor.clear();
|
|
30016
|
+
const { data } = await this.http.get(API_ENDPOINTS.forYouFeed, {
|
|
30017
|
+
params: { options: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } },
|
|
30018
|
+
});
|
|
30019
|
+
return data;
|
|
30020
|
+
}
|
|
30021
|
+
throw error;
|
|
30022
|
+
}
|
|
30023
|
+
}
|
|
30024
|
+
async persistCursor(response) {
|
|
30025
|
+
var _a, _b;
|
|
30026
|
+
if (!this.cursor)
|
|
30027
|
+
return;
|
|
30028
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
30029
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
30030
|
+
if (!cursor || !expiredAtIso)
|
|
30031
|
+
return;
|
|
30032
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
30033
|
+
if (Number.isNaN(expiredAt))
|
|
30034
|
+
return;
|
|
30035
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
30036
|
+
}
|
|
30037
|
+
}
|
|
30038
|
+
|
|
30039
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
30040
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
30041
|
+
super(query, cacheKey);
|
|
30042
|
+
this.notifyChange = notifyChange;
|
|
30043
|
+
this.preparePayload = preparePayload;
|
|
30044
|
+
}
|
|
30045
|
+
async saveToMainDB(response) {
|
|
30046
|
+
const processedPayload = await this.preparePayload(response);
|
|
30047
|
+
const client = getActiveClient();
|
|
30048
|
+
const cachedAt = client.cache && Date.now();
|
|
30049
|
+
if (client.cache)
|
|
30050
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
30051
|
+
}
|
|
30052
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
30053
|
+
var _a, _b;
|
|
30054
|
+
if (refresh) {
|
|
30055
|
+
pushToCache(this.cacheKey, {
|
|
30056
|
+
data: response.posts.map(getResolver('post')),
|
|
30057
|
+
});
|
|
30058
|
+
}
|
|
30059
|
+
else {
|
|
30060
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30061
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
30062
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
30063
|
+
}
|
|
30064
|
+
}
|
|
30065
|
+
reactor(action) {
|
|
30066
|
+
return (post) => {
|
|
30067
|
+
var _a;
|
|
30068
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30069
|
+
if (!collection)
|
|
30070
|
+
return;
|
|
30071
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
30072
|
+
return;
|
|
30073
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
30074
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
30075
|
+
}
|
|
30076
|
+
pushToCache(this.cacheKey, collection);
|
|
30077
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30078
|
+
};
|
|
30079
|
+
}
|
|
30080
|
+
subscribeRTE(createSubscriber) {
|
|
30081
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
30082
|
+
}
|
|
30083
|
+
}
|
|
30084
|
+
|
|
30085
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
30086
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
30087
|
+
constructor(callback) {
|
|
30088
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
30089
|
+
const query = {};
|
|
30090
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
30091
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
30092
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
30093
|
+
this.callback = callback.bind(this);
|
|
30094
|
+
this.loadPage({ initial: true });
|
|
30095
|
+
}
|
|
30096
|
+
setup() {
|
|
30097
|
+
var _a;
|
|
30098
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30099
|
+
if (!collection)
|
|
30100
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
30101
|
+
}
|
|
30102
|
+
async persistModel(payload) {
|
|
30103
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
30104
|
+
}
|
|
30105
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
30106
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
30107
|
+
}
|
|
30108
|
+
startSubscription() {
|
|
30109
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
30110
|
+
}
|
|
30111
|
+
notifyChange({ origin, loading, error }) {
|
|
30112
|
+
var _a, _b;
|
|
30113
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
30114
|
+
if (!collection)
|
|
30115
|
+
return;
|
|
30116
|
+
const data = ((_b = collection.data
|
|
30117
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
30118
|
+
.filter(isNonNullable)
|
|
30119
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
30120
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
30121
|
+
return;
|
|
30122
|
+
this.callback({
|
|
30123
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
30124
|
+
data,
|
|
30125
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
30126
|
+
loading,
|
|
30127
|
+
error,
|
|
30128
|
+
});
|
|
30129
|
+
}
|
|
30130
|
+
}
|
|
30131
|
+
|
|
30132
|
+
/* begin_public_function
|
|
30133
|
+
id: feed.query.for_you_feed
|
|
30134
|
+
*/
|
|
30135
|
+
/**
|
|
30136
|
+
* ```js
|
|
30137
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
30138
|
+
*
|
|
30139
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
30140
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
30141
|
+
* })
|
|
30142
|
+
* ```
|
|
30143
|
+
*
|
|
30144
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
30145
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
30146
|
+
*
|
|
30147
|
+
* @param callback the function to call when new data is available
|
|
30148
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
30149
|
+
*
|
|
30150
|
+
* @category Posts Live Collection
|
|
30151
|
+
*/
|
|
30152
|
+
const getForYouFeed = (callback) => {
|
|
30153
|
+
const { log, cache } = getActiveClient();
|
|
30154
|
+
if (!cache)
|
|
30155
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
30156
|
+
const timestamp = Date.now();
|
|
30157
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
30158
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
30159
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
30160
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
30161
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
30162
|
+
return () => {
|
|
30163
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
30164
|
+
disposers.forEach(fn => fn());
|
|
30165
|
+
};
|
|
30166
|
+
};
|
|
30167
|
+
/* end_public_function */
|
|
30168
|
+
|
|
27912
30169
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
27913
30170
|
__proto__: null,
|
|
27914
30171
|
queryGlobalFeed: queryGlobalFeed,
|
|
27915
30172
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
27916
30173
|
getGlobalFeed: getGlobalFeed,
|
|
27917
30174
|
getUserFeed: getUserFeed,
|
|
27918
|
-
getCommunityFeed: getCommunityFeed
|
|
30175
|
+
getCommunityFeed: getCommunityFeed,
|
|
30176
|
+
getForYouFeed: getForYouFeed,
|
|
30177
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
27919
30178
|
});
|
|
27920
30179
|
|
|
27921
30180
|
/* begin_public_function
|
|
@@ -28928,7 +31187,12 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28928
31187
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28929
31188
|
}
|
|
28930
31189
|
startSubscription() {
|
|
28931
|
-
|
|
31190
|
+
const disposers = this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
31191
|
+
if (this.query.excludeBlockUserPosts) {
|
|
31192
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
31193
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
31194
|
+
}
|
|
31195
|
+
return disposers;
|
|
28932
31196
|
}
|
|
28933
31197
|
notifyChange({ origin, loading, error }) {
|
|
28934
31198
|
var _a, _b;
|
|
@@ -28974,6 +31238,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28974
31238
|
const sortBy = this.query.sortBy || 'lastCreated';
|
|
28975
31239
|
posts = posts.filter(post => !exceedsUntilAtBoundary(post.createdAt, validatedUntilAt, sortBy));
|
|
28976
31240
|
}
|
|
31241
|
+
if (this.query.excludeBlockUserPosts) {
|
|
31242
|
+
posts = filterPostsByBlockUsers(posts);
|
|
31243
|
+
}
|
|
28977
31244
|
switch (this.query.sortBy) {
|
|
28978
31245
|
case 'firstCreated':
|
|
28979
31246
|
posts = posts.sort(sortByFirstCreated);
|
|
@@ -35696,6 +37963,9 @@ exports.filterByPropIntersection = filterByPropIntersection;
|
|
|
35696
37963
|
exports.filterBySearchTerm = filterBySearchTerm;
|
|
35697
37964
|
exports.filterByStringComparePartially = filterByStringComparePartially;
|
|
35698
37965
|
exports.filterByUntilAt = filterByUntilAt;
|
|
37966
|
+
exports.filterCommentsByBlockUsers = filterCommentsByBlockUsers;
|
|
37967
|
+
exports.filterPostsByBlockUsers = filterPostsByBlockUsers;
|
|
37968
|
+
exports.getBlockUsersId = getBlockUsersId;
|
|
35699
37969
|
exports.getChannelTopic = getChannelTopic;
|
|
35700
37970
|
exports.getCommentTopic = getCommentTopic;
|
|
35701
37971
|
exports.getCommunityStoriesTopic = getCommunityStoriesTopic;
|
|
@@ -35707,6 +37977,7 @@ exports.getMarkerUserFeedTopic = getMarkerUserFeedTopic;
|
|
|
35707
37977
|
exports.getMessageTopic = getMessageTopic;
|
|
35708
37978
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
35709
37979
|
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
37980
|
+
exports.getNetworkId = getNetworkId;
|
|
35710
37981
|
exports.getNetworkTopic = getNetworkTopic;
|
|
35711
37982
|
exports.getPostTopic = getPostTopic;
|
|
35712
37983
|
exports.getRole = getRole;
|