@amityco/ts-sdk 7.22.0 → 7.22.1-3c040f58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/errors.d.ts +2 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +7 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +3 -2
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/block.d.ts +5 -0
- package/dist/@types/domains/block.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +20 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +8 -2
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +14 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +16 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/notificationSettings.d.ts +101 -0
- package/dist/@types/domains/notificationSettings.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/sharableContentType.d.ts +9 -0
- package/dist/@types/domains/sharableContentType.d.ts.map +1 -0
- package/dist/@types/index.d.ts +3 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +2 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsService.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsService.d.ts.map +1 -1
- package/dist/channelRepository/api/archiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/archiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts +13 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts.map +1 -0
- package/dist/channelRepository/api/index.d.ts +3 -0
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/api/unarchiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/unarchiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/updateChannel.d.ts +1 -1
- package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/banMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/muteMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unmuteMembers.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +2 -0
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelArchived.d.ts +10 -0
- package/dist/channelRepository/events/onChannelArchived.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelUnarchived.d.ts +11 -0
- package/dist/channelRepository/events/onChannelUnarchived.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts +12 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts +11 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts +13 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts +20 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts +2 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/autoSubscription.d.ts +50 -0
- package/dist/client/api/autoSubscription.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 +3 -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 +41 -0
- package/dist/client/utils/autoSubscriptionManager.d.ts.map +1 -0
- package/dist/client/utils/subscribeGlobalTopic.d.ts +6 -1
- package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts +2 -0
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +32 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +1 -0
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +3 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts +13 -0
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts.map +1 -0
- package/dist/feedRepository/index.d.ts +2 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts +17 -0
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts +12 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts +19 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +1 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts.map +1 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts.map +1 -0
- package/dist/index.cjs.js +1841 -218
- package/dist/index.esm.js +1838 -219
- 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 +1 -1
- 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/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/createBlockEventSubscriber.d.ts +11 -0
- package/dist/userRepository/relationship/block/utils/createBlockEventSubscriber.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/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
|
@@ -74,6 +74,13 @@ exports.FileAccessTypeEnum = void 0;
|
|
|
74
74
|
FileAccessTypeEnum["NETWORK"] = "network";
|
|
75
75
|
})(exports.FileAccessTypeEnum || (exports.FileAccessTypeEnum = {}));
|
|
76
76
|
|
|
77
|
+
exports.AmityChannelNotificationModeEnum = void 0;
|
|
78
|
+
(function (AmityChannelNotificationModeEnum) {
|
|
79
|
+
AmityChannelNotificationModeEnum["Default"] = "default";
|
|
80
|
+
AmityChannelNotificationModeEnum["Silent"] = "silent";
|
|
81
|
+
AmityChannelNotificationModeEnum["Subscribe"] = "subscribe";
|
|
82
|
+
})(exports.AmityChannelNotificationModeEnum || (exports.AmityChannelNotificationModeEnum = {}));
|
|
83
|
+
|
|
77
84
|
const CommunityPostSettings = Object.freeze({
|
|
78
85
|
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
79
86
|
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
@@ -249,12 +256,54 @@ exports.AmityEventOrderOption = void 0;
|
|
|
249
256
|
AmityEventOrderOption["Descending"] = "desc";
|
|
250
257
|
})(exports.AmityEventOrderOption || (exports.AmityEventOrderOption = {}));
|
|
251
258
|
|
|
259
|
+
exports.AmitySharableContentType = void 0;
|
|
260
|
+
(function (AmitySharableContentType) {
|
|
261
|
+
AmitySharableContentType["POST"] = "post";
|
|
262
|
+
AmitySharableContentType["COMMUNITY"] = "community";
|
|
263
|
+
AmitySharableContentType["USER"] = "user";
|
|
264
|
+
AmitySharableContentType["LIVESTREAM"] = "livestream";
|
|
265
|
+
AmitySharableContentType["EVENT"] = "event";
|
|
266
|
+
})(exports.AmitySharableContentType || (exports.AmitySharableContentType = {}));
|
|
267
|
+
|
|
252
268
|
exports.AnalyticsSourceTypeEnum = void 0;
|
|
253
269
|
(function (AnalyticsSourceTypeEnum) {
|
|
254
270
|
AnalyticsSourceTypeEnum["POST"] = "post";
|
|
255
271
|
AnalyticsSourceTypeEnum["ROOM"] = "room";
|
|
256
272
|
})(exports.AnalyticsSourceTypeEnum || (exports.AnalyticsSourceTypeEnum = {}));
|
|
257
273
|
|
|
274
|
+
exports.UserNotificationModuleNameEnum = void 0;
|
|
275
|
+
(function (UserNotificationModuleNameEnum) {
|
|
276
|
+
UserNotificationModuleNameEnum["CHAT"] = "chat";
|
|
277
|
+
UserNotificationModuleNameEnum["SOCIAL"] = "social";
|
|
278
|
+
UserNotificationModuleNameEnum["VIDEO_STREAMING"] = "video-streaming";
|
|
279
|
+
})(exports.UserNotificationModuleNameEnum || (exports.UserNotificationModuleNameEnum = {}));
|
|
280
|
+
exports.CommunityNotificationEventNameEnum = void 0;
|
|
281
|
+
(function (CommunityNotificationEventNameEnum) {
|
|
282
|
+
CommunityNotificationEventNameEnum["POST_CREATED"] = "post.created";
|
|
283
|
+
CommunityNotificationEventNameEnum["POST_REACTED"] = "post.reacted";
|
|
284
|
+
CommunityNotificationEventNameEnum["COMMENT_CREATED"] = "comment.created";
|
|
285
|
+
CommunityNotificationEventNameEnum["COMMENT_REPLIED"] = "comment.replied";
|
|
286
|
+
CommunityNotificationEventNameEnum["COMMENT_REACTED"] = "comment.reacted";
|
|
287
|
+
CommunityNotificationEventNameEnum["STORY_CREATED"] = "story.created";
|
|
288
|
+
CommunityNotificationEventNameEnum["STORY_REACTED"] = "story.reacted";
|
|
289
|
+
CommunityNotificationEventNameEnum["STORY_COMMENT_CREATED"] = "story-comment.created";
|
|
290
|
+
CommunityNotificationEventNameEnum["LIVESTREAM_START"] = "video-streaming.didStart";
|
|
291
|
+
})(exports.CommunityNotificationEventNameEnum || (exports.CommunityNotificationEventNameEnum = {}));
|
|
292
|
+
exports.NotificationSettingsLevelEnum = void 0;
|
|
293
|
+
(function (NotificationSettingsLevelEnum) {
|
|
294
|
+
NotificationSettingsLevelEnum["USER"] = "user";
|
|
295
|
+
NotificationSettingsLevelEnum["COMMUNITY"] = "community";
|
|
296
|
+
NotificationSettingsLevelEnum["CHANNEL"] = "channel";
|
|
297
|
+
})(exports.NotificationSettingsLevelEnum || (exports.NotificationSettingsLevelEnum = {}));
|
|
298
|
+
/**
|
|
299
|
+
* `NOT` variant is intentionally excluded from public API (internal server-side use only).
|
|
300
|
+
*/
|
|
301
|
+
exports.NotificationRolesFilterTypeEnum = void 0;
|
|
302
|
+
(function (NotificationRolesFilterTypeEnum) {
|
|
303
|
+
NotificationRolesFilterTypeEnum["ALL"] = "all";
|
|
304
|
+
NotificationRolesFilterTypeEnum["ONLY"] = "only";
|
|
305
|
+
})(exports.NotificationRolesFilterTypeEnum || (exports.NotificationRolesFilterTypeEnum = {}));
|
|
306
|
+
|
|
258
307
|
function getVersion() {
|
|
259
308
|
try {
|
|
260
309
|
// the string ''v7.22.0-cjs'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -267,6 +316,7 @@ function getVersion() {
|
|
|
267
316
|
const VERSION = getVersion();
|
|
268
317
|
|
|
269
318
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
319
|
+
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
270
320
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
271
321
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
272
322
|
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
@@ -279,6 +329,9 @@ const DAY = 24 * HOUR;
|
|
|
279
329
|
const WEEK = 7 * DAY;
|
|
280
330
|
const YEAR = 365 * DAY;
|
|
281
331
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
332
|
+
const API_ENDPOINTS = {
|
|
333
|
+
forYouFeed: '/api/v1/feeds/for-you',
|
|
334
|
+
};
|
|
282
335
|
|
|
283
336
|
// cache constants
|
|
284
337
|
const CACHE_KEY_GET = 'get';
|
|
@@ -659,6 +712,95 @@ function createSnapshot(data, options) {
|
|
|
659
712
|
return Object.assign(Object.assign({}, options), { data });
|
|
660
713
|
}
|
|
661
714
|
|
|
715
|
+
/* eslint-disable max-classes-per-file */
|
|
716
|
+
/**
|
|
717
|
+
* Generic ASC error
|
|
718
|
+
* @category Errors
|
|
719
|
+
*/
|
|
720
|
+
class ASCError extends Error {
|
|
721
|
+
/**
|
|
722
|
+
* @param message A custom error message
|
|
723
|
+
* @param code A normalized error code
|
|
724
|
+
* @param level A normalized failure level descriptor
|
|
725
|
+
*/
|
|
726
|
+
constructor(message, code, level) {
|
|
727
|
+
super(`Amity SDK (${code}): ${message}`);
|
|
728
|
+
this.code = code;
|
|
729
|
+
this.level = level;
|
|
730
|
+
this.type = 'ASC';
|
|
731
|
+
this.timestamp = Date.now();
|
|
732
|
+
if (Error.captureStackTrace)
|
|
733
|
+
Error.captureStackTrace(this, ASCError);
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
/**
|
|
737
|
+
* API level error
|
|
738
|
+
* @category Errors
|
|
739
|
+
*/
|
|
740
|
+
class ASCApiError extends ASCError {
|
|
741
|
+
/**
|
|
742
|
+
* @param code A normalized error code
|
|
743
|
+
* @param level A normalized failure level descriptor
|
|
744
|
+
*/
|
|
745
|
+
// eslint-disable-next-line no-useless-constructor
|
|
746
|
+
constructor(message, code, level) {
|
|
747
|
+
super(message, code, level);
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
/**
|
|
751
|
+
* Unexpected error
|
|
752
|
+
* @category Errors
|
|
753
|
+
*/
|
|
754
|
+
class ASCUnknownError extends ASCError {
|
|
755
|
+
/**
|
|
756
|
+
* @param code A normalized error code
|
|
757
|
+
* @param level A normalized failure level descriptor
|
|
758
|
+
*/
|
|
759
|
+
constructor(code = 800000 /* Amity.ClientError.UNKNOWN_ERROR */, level = "fatal" /* Amity.ErrorLevel.FATAL */) {
|
|
760
|
+
super('Unexpected error', code, level);
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
/**
|
|
764
|
+
* Network related error
|
|
765
|
+
* @category Errors
|
|
766
|
+
*/
|
|
767
|
+
class ASCConnectionError extends ASCError {
|
|
768
|
+
/**
|
|
769
|
+
* @param message A custom error message
|
|
770
|
+
*/
|
|
771
|
+
constructor(event, message = 'SDK client is having connection issues') {
|
|
772
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
773
|
+
? 800211 /* Amity.ClientError.DISCONNECTED */
|
|
774
|
+
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
775
|
+
this.event = event;
|
|
776
|
+
}
|
|
777
|
+
}
|
|
778
|
+
|
|
779
|
+
let activeClient = null;
|
|
780
|
+
/**
|
|
781
|
+
* Get the active client
|
|
782
|
+
*
|
|
783
|
+
* @returns the active client instance
|
|
784
|
+
*
|
|
785
|
+
* @hidden
|
|
786
|
+
*/
|
|
787
|
+
const getActiveClient = () => {
|
|
788
|
+
if (!activeClient) {
|
|
789
|
+
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
790
|
+
}
|
|
791
|
+
return activeClient;
|
|
792
|
+
};
|
|
793
|
+
/**
|
|
794
|
+
* Sets the active client
|
|
795
|
+
*
|
|
796
|
+
* @param client the client to assume as currently active client
|
|
797
|
+
*
|
|
798
|
+
* @hidden
|
|
799
|
+
*/
|
|
800
|
+
const setActiveClient = (client) => {
|
|
801
|
+
activeClient = client;
|
|
802
|
+
};
|
|
803
|
+
|
|
662
804
|
/** @hidden */
|
|
663
805
|
const idResolvers = {
|
|
664
806
|
user: ({ userId }) => userId,
|
|
@@ -667,6 +809,7 @@ const idResolvers = {
|
|
|
667
809
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
668
810
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
669
811
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
812
|
+
archivedChannel: ({ channelId }) => channelId,
|
|
670
813
|
message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
|
|
671
814
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
672
815
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
@@ -708,6 +851,7 @@ const idResolvers = {
|
|
|
708
851
|
event: ({ eventId }) => eventId,
|
|
709
852
|
eventResponse: ({ userId }) => userId,
|
|
710
853
|
product: ({ productId }) => productId,
|
|
854
|
+
feedMetadata: ({ postId }) => postId,
|
|
711
855
|
};
|
|
712
856
|
/**
|
|
713
857
|
* Retrieve the id resolver matching a domain name
|
|
@@ -730,6 +874,7 @@ const PAYLOAD2MODEL = {
|
|
|
730
874
|
channels: 'channel',
|
|
731
875
|
messageFeeds: 'subChannel',
|
|
732
876
|
channelUsers: 'channelUsers',
|
|
877
|
+
archives: 'archivedChannel',
|
|
733
878
|
messages: 'message',
|
|
734
879
|
messagePreviewChannel: 'messagePreviewChannel',
|
|
735
880
|
messagePreviewSubChannel: 'messagePreviewSubChannel',
|
|
@@ -768,6 +913,7 @@ const PAYLOAD2MODEL = {
|
|
|
768
913
|
viewers: 'viewer',
|
|
769
914
|
eventResponses: 'eventResponse',
|
|
770
915
|
products: 'product',
|
|
916
|
+
feedMetadata: 'feedMetadata',
|
|
771
917
|
};
|
|
772
918
|
/** hidden */
|
|
773
919
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -782,95 +928,6 @@ function getFutureDate(date = new Date().toISOString()) {
|
|
|
782
928
|
return new Date(new Date(date).getTime() + 1).toISOString();
|
|
783
929
|
}
|
|
784
930
|
|
|
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
931
|
/**
|
|
875
932
|
* ```js
|
|
876
933
|
* import { enableCache } from '@amityco/ts-sdk'
|
|
@@ -1378,6 +1435,65 @@ const filterBySearchTerm = (collection, searchTerm) => {
|
|
|
1378
1435
|
return m.user && ((_a = m.user.displayName) === null || _a === void 0 ? void 0 : _a.match(containsMatcher));
|
|
1379
1436
|
});
|
|
1380
1437
|
};
|
|
1438
|
+
/**
|
|
1439
|
+
* The ids of users in a block relationship with the current user — in BOTH
|
|
1440
|
+
* directions — derived synchronously from the local follow cache. For every
|
|
1441
|
+
* `status === 'blocked'` row that involves the current user, the OTHER party
|
|
1442
|
+
* is collected: `from === me` (users I blocked, outgoing) contributes `to`;
|
|
1443
|
+
* `to === me` (users who blocked me, incoming) contributes `from`.
|
|
1444
|
+
*
|
|
1445
|
+
* @returns a set of block-related user ids (both directions)
|
|
1446
|
+
*
|
|
1447
|
+
* @hidden
|
|
1448
|
+
*/
|
|
1449
|
+
const getBlockUsersId = () => {
|
|
1450
|
+
var _a;
|
|
1451
|
+
const { userId } = getActiveClient();
|
|
1452
|
+
const ids = new Set();
|
|
1453
|
+
((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
1454
|
+
.map(entry => entry.data)
|
|
1455
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && (follow.from === userId || follow.to === userId))
|
|
1456
|
+
.forEach(follow => {
|
|
1457
|
+
ids.add(follow.from === userId ? follow.to : follow.from);
|
|
1458
|
+
});
|
|
1459
|
+
return ids;
|
|
1460
|
+
};
|
|
1461
|
+
/**
|
|
1462
|
+
* Filter out posts whose author or any mentionee is in a block relationship
|
|
1463
|
+
* with the current user, in either direction (see {@link getBlockUsersId}).
|
|
1464
|
+
*
|
|
1465
|
+
* @param collection the post collection to filter
|
|
1466
|
+
* @returns a filtered collection excluding posts involving block-related users
|
|
1467
|
+
*
|
|
1468
|
+
* @hidden
|
|
1469
|
+
*/
|
|
1470
|
+
const filterPostsByBlockUsers = (collection) => {
|
|
1471
|
+
const blockUsersId = getBlockUsersId();
|
|
1472
|
+
if (blockUsersId.size === 0)
|
|
1473
|
+
return collection;
|
|
1474
|
+
return collection.filter(post => {
|
|
1475
|
+
var _a, _b;
|
|
1476
|
+
if (blockUsersId.has(post.postedUserId))
|
|
1477
|
+
return false;
|
|
1478
|
+
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 : [];
|
|
1479
|
+
return !mentionedUserIds.some(id => blockUsersId.has(id));
|
|
1480
|
+
});
|
|
1481
|
+
};
|
|
1482
|
+
/**
|
|
1483
|
+
* Filter out comments whose creator is in a block relationship with the
|
|
1484
|
+
* current user, in either direction (see {@link getBlockUsersId}).
|
|
1485
|
+
*
|
|
1486
|
+
* @param collection the comment collection to filter
|
|
1487
|
+
* @returns a filtered collection excluding comments from block-related users
|
|
1488
|
+
*
|
|
1489
|
+
* @hidden
|
|
1490
|
+
*/
|
|
1491
|
+
const filterCommentsByBlockUsers = (collection) => {
|
|
1492
|
+
const blockUsersId = getBlockUsersId();
|
|
1493
|
+
if (blockUsersId.size === 0)
|
|
1494
|
+
return collection;
|
|
1495
|
+
return collection.filter(comment => !blockUsersId.has(comment.userId));
|
|
1496
|
+
};
|
|
1381
1497
|
|
|
1382
1498
|
// Note:
|
|
1383
1499
|
// this file should contain a suite of sorting utilities to help the
|
|
@@ -1573,6 +1689,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
1573
1689
|
log(`${namespace}(tmpid: ${timestamp}) > listen`);
|
|
1574
1690
|
const handler = (...payload) => {
|
|
1575
1691
|
log(`${namespace}(tmpid: ${timestamp}) > trigger`, payload);
|
|
1692
|
+
console.log(payload);
|
|
1576
1693
|
try {
|
|
1577
1694
|
fn(...payload);
|
|
1578
1695
|
}
|
|
@@ -1848,13 +1965,13 @@ class NetworkActivitiesWatcher {
|
|
|
1848
1965
|
this._listener.clear();
|
|
1849
1966
|
}
|
|
1850
1967
|
}
|
|
1851
|
-
let instance$
|
|
1968
|
+
let instance$a;
|
|
1852
1969
|
var NetworkActivitiesWatcher$1 = {
|
|
1853
1970
|
getInstance: () => {
|
|
1854
|
-
if (!instance$
|
|
1855
|
-
instance$
|
|
1971
|
+
if (!instance$a) {
|
|
1972
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
1856
1973
|
}
|
|
1857
|
-
return instance$
|
|
1974
|
+
return instance$a;
|
|
1858
1975
|
},
|
|
1859
1976
|
};
|
|
1860
1977
|
|
|
@@ -4602,18 +4719,161 @@ walker=walker.next;}if(i===n&&walker!==null){return walker.value;}};Yallist.prot
|
|
|
4602
4719
|
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
4720
|
require('./iterator.js')(Yallist);}catch(er){}},{"./iterator.js":82}]},{},[12])(12);});})(mqtt$1);var mqtt = /*@__PURE__*/getDefaultExportFromCjs(mqtt$1.exports);
|
|
4604
4721
|
|
|
4722
|
+
class SessionWatcher {
|
|
4723
|
+
constructor() {
|
|
4724
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
4725
|
+
this._listener = new Map();
|
|
4726
|
+
}
|
|
4727
|
+
onSessionStateChange(callback) {
|
|
4728
|
+
this._listener.set(callback, callback);
|
|
4729
|
+
return () => {
|
|
4730
|
+
this._listener.delete(callback);
|
|
4731
|
+
};
|
|
4732
|
+
}
|
|
4733
|
+
setSessionState(state, reason) {
|
|
4734
|
+
if (this._sessionState === state)
|
|
4735
|
+
return;
|
|
4736
|
+
this._sessionState = state;
|
|
4737
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
4738
|
+
}
|
|
4739
|
+
destroy() {
|
|
4740
|
+
this._listener.clear();
|
|
4741
|
+
}
|
|
4742
|
+
}
|
|
4743
|
+
let instance$9;
|
|
4744
|
+
var SessionWatcher$1 = {
|
|
4745
|
+
getInstance: () => {
|
|
4746
|
+
if (!instance$9) {
|
|
4747
|
+
instance$9 = new SessionWatcher();
|
|
4748
|
+
}
|
|
4749
|
+
return instance$9;
|
|
4750
|
+
},
|
|
4751
|
+
};
|
|
4752
|
+
|
|
4753
|
+
/**
|
|
4754
|
+
* ```js
|
|
4755
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
4756
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
4757
|
+
* // ...
|
|
4758
|
+
* })
|
|
4759
|
+
* ```
|
|
4760
|
+
*
|
|
4761
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
4762
|
+
*
|
|
4763
|
+
* @param callback The function to call when the event was fired
|
|
4764
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
4765
|
+
*
|
|
4766
|
+
* @category Client Events
|
|
4767
|
+
*/
|
|
4768
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
4769
|
+
|
|
4770
|
+
/** Feature-grouped real-time handles; all default-on, toggleable per handle. */
|
|
4771
|
+
var AutoSubscription;
|
|
4772
|
+
(function (AutoSubscription) {
|
|
4773
|
+
/** SMART_CHANNEL + SMART_MESSAGE + SMART_MESSAGE_FEED — chat "smart" real-time. */
|
|
4774
|
+
AutoSubscription["CHAT"] = "chat";
|
|
4775
|
+
/** Network-wide events (e.g. global ban). */
|
|
4776
|
+
AutoSubscription["NETWORK"] = "network";
|
|
4777
|
+
/** Livestream state events. */
|
|
4778
|
+
AutoSubscription["LIVESTREAM"] = "livestream";
|
|
4779
|
+
/** Both membership wildcards (followers + followings) — block real-time. */
|
|
4780
|
+
AutoSubscription["BLOCK"] = "block";
|
|
4781
|
+
})(AutoSubscription || (AutoSubscription = {}));
|
|
4782
|
+
const TOPICS = {
|
|
4783
|
+
[AutoSubscription.NETWORK]: [getNetworkTopic],
|
|
4784
|
+
[AutoSubscription.CHAT]: [
|
|
4785
|
+
getSmartFeedChannelTopic,
|
|
4786
|
+
getSmartFeedSubChannelTopic,
|
|
4787
|
+
getSmartFeedMessageTopic,
|
|
4788
|
+
],
|
|
4789
|
+
[AutoSubscription.LIVESTREAM]: [getLiveStreamTopic],
|
|
4790
|
+
[AutoSubscription.BLOCK]: [getMyFollowersTopic, getMyFollowingsTopic],
|
|
4791
|
+
};
|
|
4792
|
+
const DEFAULT_TOPICS = [
|
|
4793
|
+
AutoSubscription.CHAT,
|
|
4794
|
+
AutoSubscription.NETWORK,
|
|
4795
|
+
AutoSubscription.LIVESTREAM,
|
|
4796
|
+
AutoSubscription.BLOCK,
|
|
4797
|
+
];
|
|
4798
|
+
const ALL_FEATURES = Object.values(AutoSubscription);
|
|
4799
|
+
/** Ref-counted, reconnect-resilient registry of the managed auto-subscriptions. */
|
|
4800
|
+
class AutoSubscriptionManager {
|
|
4801
|
+
constructor() {
|
|
4802
|
+
this.refCountByFeature = new Map();
|
|
4803
|
+
this.disposers = new Map();
|
|
4804
|
+
this.seed();
|
|
4805
|
+
}
|
|
4806
|
+
seed() {
|
|
4807
|
+
this.refCountByFeature.clear();
|
|
4808
|
+
DEFAULT_TOPICS.forEach(feature => this.refCountByFeature.set(feature, 1));
|
|
4809
|
+
}
|
|
4810
|
+
isActive(feature) {
|
|
4811
|
+
var _a;
|
|
4812
|
+
return ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
4813
|
+
}
|
|
4814
|
+
subscribeTopics(feature) {
|
|
4815
|
+
this.unsubscribeTopics(feature);
|
|
4816
|
+
this.disposers.set(feature, TOPICS[feature].map(buildTopic => subscribeTopic(buildTopic())));
|
|
4817
|
+
}
|
|
4818
|
+
unsubscribeTopics(feature) {
|
|
4819
|
+
var _a;
|
|
4820
|
+
((_a = this.disposers.get(feature)) !== null && _a !== void 0 ? _a : []).forEach(dispose => dispose());
|
|
4821
|
+
this.disposers.delete(feature);
|
|
4822
|
+
}
|
|
4823
|
+
/** Subscribe every enabled handle's topics, converging the broker to the registry. Called on each (re)connect. */
|
|
4824
|
+
initialize() {
|
|
4825
|
+
ALL_FEATURES.forEach(feature => {
|
|
4826
|
+
if (this.isActive(feature))
|
|
4827
|
+
this.subscribeTopics(feature);
|
|
4828
|
+
});
|
|
4829
|
+
}
|
|
4830
|
+
subscribe(feature) {
|
|
4831
|
+
var _a;
|
|
4832
|
+
const next = ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
4833
|
+
this.refCountByFeature.set(feature, next);
|
|
4834
|
+
if (next === 1)
|
|
4835
|
+
this.subscribeTopics(feature);
|
|
4836
|
+
}
|
|
4837
|
+
unsubscribe(feature) {
|
|
4838
|
+
var _a;
|
|
4839
|
+
const next = Math.max(0, ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
4840
|
+
this.refCountByFeature.set(feature, next);
|
|
4841
|
+
if (next === 0)
|
|
4842
|
+
this.unsubscribeTopics(feature);
|
|
4843
|
+
}
|
|
4844
|
+
subscriptions() {
|
|
4845
|
+
return ALL_FEATURES.map(feature => ({
|
|
4846
|
+
feature,
|
|
4847
|
+
isActive: this.isActive(feature),
|
|
4848
|
+
isSystem: true,
|
|
4849
|
+
topicCount: TOPICS[feature].length,
|
|
4850
|
+
}));
|
|
4851
|
+
}
|
|
4852
|
+
reset() {
|
|
4853
|
+
ALL_FEATURES.forEach(feature => this.unsubscribeTopics(feature));
|
|
4854
|
+
this.disposers.clear();
|
|
4855
|
+
this.seed();
|
|
4856
|
+
}
|
|
4857
|
+
}
|
|
4858
|
+
let instance$8 = null;
|
|
4859
|
+
const getAutoSubscriptionManager = () => {
|
|
4860
|
+
if (!instance$8)
|
|
4861
|
+
instance$8 = new AutoSubscriptionManager();
|
|
4862
|
+
return instance$8;
|
|
4863
|
+
};
|
|
4864
|
+
/** Resets the registry to its default baseline when the session ends. */
|
|
4865
|
+
const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
|
|
4866
|
+
if (state !== "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
4867
|
+
getAutoSubscriptionManager().reset();
|
|
4868
|
+
});
|
|
4869
|
+
|
|
4870
|
+
/**
|
|
4871
|
+
* (Re)subscribes the managed auto-subscription registry on every (re)connect.
|
|
4872
|
+
* The hardcoded topic list was promoted to the toggleable, ref-counted registry
|
|
4873
|
+
* in {@link getAutoSubscriptionManager} — see `client.manageAutoSubscriptions`.
|
|
4874
|
+
*/
|
|
4605
4875
|
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());
|
|
4876
|
+
getAutoSubscriptionManager().initialize();
|
|
4617
4877
|
};
|
|
4618
4878
|
|
|
4619
4879
|
class OnMemoryStorage {
|
|
@@ -5133,8 +5393,12 @@ const getChannelMessagePreviewWithUser = (channel) => {
|
|
|
5133
5393
|
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
5134
5394
|
};
|
|
5135
5395
|
|
|
5396
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
5397
|
+
return new Date(dateString).getTime();
|
|
5398
|
+
};
|
|
5399
|
+
|
|
5136
5400
|
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
5137
|
-
var _a
|
|
5401
|
+
var _a;
|
|
5138
5402
|
const withMessageFeedInfo = (messagePreview) => {
|
|
5139
5403
|
var _a;
|
|
5140
5404
|
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
@@ -5156,10 +5420,26 @@ const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
|
5156
5420
|
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
5157
5421
|
};
|
|
5158
5422
|
};
|
|
5159
|
-
|
|
5160
|
-
|
|
5161
|
-
|
|
5162
|
-
|
|
5423
|
+
// Skip server previews older than what's cached — the cache may carry a newer
|
|
5424
|
+
// preview written by handleMessageCreated from an MQTT message that the server
|
|
5425
|
+
// payload hasn't surfaced yet. Mirrors isLastestMessageOnChannel.
|
|
5426
|
+
const newPreviews = ((_a = rawPayload.messagePreviews) !== null && _a !== void 0 ? _a : [])
|
|
5427
|
+
.map(withMessageFeedInfo)
|
|
5428
|
+
.filter(preview => {
|
|
5429
|
+
var _a;
|
|
5430
|
+
const cached = (_a = pullFromCache([
|
|
5431
|
+
'messagePreviewChannel',
|
|
5432
|
+
'get',
|
|
5433
|
+
preview.channelId,
|
|
5434
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
5435
|
+
if (!cached)
|
|
5436
|
+
return true;
|
|
5437
|
+
return (convertDateStringToTimestamp(cached.createdAt) <=
|
|
5438
|
+
convertDateStringToTimestamp(preview.createdAt));
|
|
5439
|
+
});
|
|
5440
|
+
if (newPreviews.length === 0)
|
|
5441
|
+
return;
|
|
5442
|
+
ingestInCache({ messagePreviewChannel: newPreviews });
|
|
5163
5443
|
};
|
|
5164
5444
|
|
|
5165
5445
|
const getSubChannelMessagePreview = (subChannelId) => {
|
|
@@ -5787,10 +6067,6 @@ getSubChannel$1.locally = (subChannelId) => {
|
|
|
5787
6067
|
};
|
|
5788
6068
|
};
|
|
5789
6069
|
|
|
5790
|
-
const convertDateStringToTimestamp = (dateString) => {
|
|
5791
|
-
return new Date(dateString).getTime();
|
|
5792
|
-
};
|
|
5793
|
-
|
|
5794
6070
|
const getMessagePreviewSetting$1 = async () => {
|
|
5795
6071
|
const client = getActiveClient();
|
|
5796
6072
|
return client.getMessagePreviewSetting(false);
|
|
@@ -5998,24 +6274,41 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
5998
6274
|
});
|
|
5999
6275
|
};
|
|
6000
6276
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
6277
|
+
var _a, _b;
|
|
6001
6278
|
const channelsUnread = [];
|
|
6002
6279
|
for (let i = 0; i < channels.length; i += 1) {
|
|
6003
6280
|
if (isUnreadCountSupport(channels[i])) {
|
|
6004
6281
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
6005
6282
|
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
6006
|
-
|
|
6283
|
+
// readToSegment, lastMentionedSegment and lastSegment are monotonically non-decreasing;
|
|
6284
|
+
// prefer cached values when ahead of the server so a refetch returning stale data cannot
|
|
6285
|
+
const cached = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
6286
|
+
const lastSegment = Math.max((_b = cached === null || cached === void 0 ? void 0 : cached.lastSegment) !== null && _b !== void 0 ? _b : 0, channels[i].messageCount);
|
|
6007
6287
|
let readToSegment = null;
|
|
6008
6288
|
let lastMentionedSegment = null;
|
|
6289
|
+
let unreadCount = 0;
|
|
6009
6290
|
let isMentioned = false;
|
|
6010
6291
|
if (channelUser) {
|
|
6011
|
-
|
|
6012
|
-
|
|
6013
|
-
|
|
6014
|
-
|
|
6292
|
+
const serverRead = channelUser.readToSegment;
|
|
6293
|
+
const serverMention = channelUser.lastMentionedSegment;
|
|
6294
|
+
readToSegment =
|
|
6295
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.readToSegment) === 'number' &&
|
|
6296
|
+
(typeof serverRead !== 'number' || cached.readToSegment > serverRead)
|
|
6297
|
+
? cached.readToSegment
|
|
6298
|
+
: serverRead !== null && serverRead !== void 0 ? serverRead : null;
|
|
6299
|
+
lastMentionedSegment =
|
|
6300
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.lastMentionedSegment) === 'number' &&
|
|
6301
|
+
(typeof serverMention !== 'number' || cached.lastMentionedSegment > serverMention)
|
|
6302
|
+
? cached.lastMentionedSegment
|
|
6303
|
+
: serverMention !== null && serverMention !== void 0 ? serverMention : null;
|
|
6304
|
+
const readForCalc = readToSegment !== null && readToSegment !== void 0 ? readToSegment : 0;
|
|
6305
|
+
unreadCount = Math.max(lastSegment - readForCalc, 0);
|
|
6306
|
+
isMentioned =
|
|
6307
|
+
typeof lastMentionedSegment === 'number' && readForCalc < lastMentionedSegment;
|
|
6015
6308
|
}
|
|
6016
6309
|
const cacheChannelUnread = {
|
|
6017
6310
|
channelId: channels[i].channelId,
|
|
6018
|
-
lastSegment
|
|
6311
|
+
lastSegment,
|
|
6019
6312
|
readToSegment,
|
|
6020
6313
|
lastMentionedSegment,
|
|
6021
6314
|
unreadCount,
|
|
@@ -6025,6 +6318,8 @@ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
|
6025
6318
|
pushToCache(cacheKey, cacheChannelUnread);
|
|
6026
6319
|
channelsUnread.push(cacheChannelUnread);
|
|
6027
6320
|
}
|
|
6321
|
+
}
|
|
6322
|
+
if (channelsUnread.length > 0) {
|
|
6028
6323
|
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
6029
6324
|
}
|
|
6030
6325
|
};
|
|
@@ -6724,7 +7019,7 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6724
7019
|
const client = getActiveClient();
|
|
6725
7020
|
const filter = async (payload) => {
|
|
6726
7021
|
const { channels, channelUsers } = payload;
|
|
6727
|
-
|
|
7022
|
+
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
6728
7023
|
};
|
|
6729
7024
|
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
|
|
6730
7025
|
}
|
|
@@ -6732,6 +7027,39 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
6732
7027
|
return () => dispose$1(callback);
|
|
6733
7028
|
};
|
|
6734
7029
|
|
|
7030
|
+
/**
|
|
7031
|
+
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
7032
|
+
*
|
|
7033
|
+
* @param callback The function to call when the event was fired
|
|
7034
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7035
|
+
*
|
|
7036
|
+
* @category Channel Events
|
|
7037
|
+
*/
|
|
7038
|
+
const onChannelArchived = (callback) => {
|
|
7039
|
+
const client = getActiveClient();
|
|
7040
|
+
const filter = async (payload) => {
|
|
7041
|
+
callback(payload);
|
|
7042
|
+
};
|
|
7043
|
+
return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
|
|
7044
|
+
};
|
|
7045
|
+
|
|
7046
|
+
/**
|
|
7047
|
+
* Fired when a previously archived {@link Amity.Channel} has been unarchived
|
|
7048
|
+
* by the active user.
|
|
7049
|
+
*
|
|
7050
|
+
* @param callback The function to call when the event was fired
|
|
7051
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
7052
|
+
*
|
|
7053
|
+
* @category Channel Events
|
|
7054
|
+
*/
|
|
7055
|
+
const onChannelUnarchived = (callback) => {
|
|
7056
|
+
const client = getActiveClient();
|
|
7057
|
+
const filter = async (payload) => {
|
|
7058
|
+
callback(payload);
|
|
7059
|
+
};
|
|
7060
|
+
return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
|
|
7061
|
+
};
|
|
7062
|
+
|
|
6735
7063
|
const callbacks = [];
|
|
6736
7064
|
let mainDisposer = null;
|
|
6737
7065
|
const dispose = (cb) => {
|
|
@@ -6845,6 +7173,17 @@ const channelLinkedObject = (channel) => {
|
|
|
6845
7173
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
6846
7174
|
previewMembers,
|
|
6847
7175
|
myMembership: (callback) => getMyMembership(channel.channelId, callback),
|
|
7176
|
+
get avatar() {
|
|
7177
|
+
var _a;
|
|
7178
|
+
if (!channel.avatarFileId)
|
|
7179
|
+
return undefined;
|
|
7180
|
+
const avatar = (_a = pullFromCache([
|
|
7181
|
+
'file',
|
|
7182
|
+
'get',
|
|
7183
|
+
`${channel.avatarFileId}`,
|
|
7184
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
7185
|
+
return avatar;
|
|
7186
|
+
},
|
|
6848
7187
|
});
|
|
6849
7188
|
};
|
|
6850
7189
|
|
|
@@ -6943,54 +7282,6 @@ getChannelByIds$1.locally = (channelIds) => {
|
|
|
6943
7282
|
};
|
|
6944
7283
|
};
|
|
6945
7284
|
|
|
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
7285
|
const setIntervalTask = (handler, timeout) => {
|
|
6995
7286
|
const timer = setInterval(handler, timeout);
|
|
6996
7287
|
return () => clearInterval(timer);
|
|
@@ -7784,7 +8075,7 @@ class AnalyticsEventSyncer {
|
|
|
7784
8075
|
|
|
7785
8076
|
class AnalyticsEventCapturer {
|
|
7786
8077
|
constructor() {
|
|
7787
|
-
this._expireTime = 5 *
|
|
8078
|
+
this._expireTime = 5 * SECOND$1;
|
|
7788
8079
|
this._poolLimit = 1000;
|
|
7789
8080
|
this._recentViewed = {};
|
|
7790
8081
|
this._recentHighPriorityViewed = {};
|
|
@@ -7838,12 +8129,36 @@ class AnalyticsEventCapturer {
|
|
|
7838
8129
|
}
|
|
7839
8130
|
markPostAsViewed(postId) {
|
|
7840
8131
|
this.markAs({
|
|
7841
|
-
uniqueId: postId
|
|
8132
|
+
uniqueId: `post.${postId}`,
|
|
7842
8133
|
contentId: postId,
|
|
7843
8134
|
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
7844
8135
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
7845
8136
|
});
|
|
7846
8137
|
}
|
|
8138
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8139
|
+
var _a;
|
|
8140
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
8141
|
+
const metadata = {};
|
|
8142
|
+
if (feedRenderPosition !== undefined)
|
|
8143
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
8144
|
+
if (cached) {
|
|
8145
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
8146
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
8147
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
8148
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
8149
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
8150
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
8151
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
8152
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
8153
|
+
}
|
|
8154
|
+
this.markAs({
|
|
8155
|
+
uniqueId: `post.${postId}.meaningfulView`,
|
|
8156
|
+
contentId: postId,
|
|
8157
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
8158
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
8159
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
8160
|
+
});
|
|
8161
|
+
}
|
|
7847
8162
|
markStory(story, activityType) {
|
|
7848
8163
|
if (!story.expiresAt)
|
|
7849
8164
|
return;
|
|
@@ -7983,6 +8298,12 @@ class AnalyticsEngine {
|
|
|
7983
8298
|
this._eventCapturer.markPostAsViewed(postId);
|
|
7984
8299
|
}
|
|
7985
8300
|
}
|
|
8301
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
8302
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
8303
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
8304
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
8305
|
+
}
|
|
8306
|
+
}
|
|
7986
8307
|
markStoryAsViewed(story) {
|
|
7987
8308
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
7988
8309
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -8207,9 +8528,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
8207
8528
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
8208
8529
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
8209
8530
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8210
|
-
if (
|
|
8211
|
-
channelUnread
|
|
8212
|
-
segment > channelUnread.readToSegment) {
|
|
8531
|
+
if (channelUnread &&
|
|
8532
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
8213
8533
|
channelUnread.readToSegment = segment;
|
|
8214
8534
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
8215
8535
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -9103,6 +9423,59 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
9103
9423
|
};
|
|
9104
9424
|
};
|
|
9105
9425
|
|
|
9426
|
+
class CursorController {
|
|
9427
|
+
constructor(networkId, userId) {
|
|
9428
|
+
this.networkId = networkId;
|
|
9429
|
+
this.userId = userId;
|
|
9430
|
+
}
|
|
9431
|
+
static current() {
|
|
9432
|
+
try {
|
|
9433
|
+
const user = getCurrentUser();
|
|
9434
|
+
if (!user)
|
|
9435
|
+
return null;
|
|
9436
|
+
const networkId = getNetworkId(user);
|
|
9437
|
+
const { userId } = user;
|
|
9438
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
9439
|
+
}
|
|
9440
|
+
catch (_a) {
|
|
9441
|
+
return null;
|
|
9442
|
+
}
|
|
9443
|
+
}
|
|
9444
|
+
static isExpired(expiredAt) {
|
|
9445
|
+
return Date.now() >= expiredAt;
|
|
9446
|
+
}
|
|
9447
|
+
static clearOnLogout() {
|
|
9448
|
+
return onSessionStateChange(state => {
|
|
9449
|
+
var _a;
|
|
9450
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
9451
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
9452
|
+
});
|
|
9453
|
+
}
|
|
9454
|
+
get key() {
|
|
9455
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
9456
|
+
}
|
|
9457
|
+
async get() {
|
|
9458
|
+
const raw = await getItem(this.key);
|
|
9459
|
+
if (!raw)
|
|
9460
|
+
return null;
|
|
9461
|
+
try {
|
|
9462
|
+
const parsed = JSON.parse(raw);
|
|
9463
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
9464
|
+
return null;
|
|
9465
|
+
return { cursor: parsed.cursor, expiredAt: parsed.expiredAt };
|
|
9466
|
+
}
|
|
9467
|
+
catch (_a) {
|
|
9468
|
+
return null;
|
|
9469
|
+
}
|
|
9470
|
+
}
|
|
9471
|
+
async set(value) {
|
|
9472
|
+
await setItem(this.key, JSON.stringify(value));
|
|
9473
|
+
}
|
|
9474
|
+
async clear() {
|
|
9475
|
+
await setItem(this.key, '');
|
|
9476
|
+
}
|
|
9477
|
+
}
|
|
9478
|
+
|
|
9106
9479
|
const EVENTS = [
|
|
9107
9480
|
'disconnected',
|
|
9108
9481
|
'error',
|
|
@@ -9292,7 +9665,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
9292
9665
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
9293
9666
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
9294
9667
|
// 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());
|
|
9668
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
9296
9669
|
if (client.useLegacyUnreadCount) {
|
|
9297
9670
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
9298
9671
|
}
|
|
@@ -9991,16 +10364,13 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
9991
10364
|
}
|
|
9992
10365
|
if (client.useLegacyUnreadCount) {
|
|
9993
10366
|
rawPayload.messages.forEach(message => {
|
|
9994
|
-
var _a, _b;
|
|
10367
|
+
var _a, _b, _c;
|
|
9995
10368
|
const channelUnread = (_a = pullFromCache([
|
|
9996
10369
|
'channelUnread',
|
|
9997
10370
|
'get',
|
|
9998
10371
|
message.channelId,
|
|
9999
10372
|
])) === 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')
|
|
10373
|
+
if (!channelUnread || channelUnread.lastSegment >= message.segment)
|
|
10004
10374
|
return;
|
|
10005
10375
|
const lastSegment = message.segment;
|
|
10006
10376
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -10012,7 +10382,8 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
10012
10382
|
const lastMentionedSegment = isMentionedInMessage
|
|
10013
10383
|
? message.segment
|
|
10014
10384
|
: channelUnread.lastMentionedSegment;
|
|
10015
|
-
const
|
|
10385
|
+
const readToSegment = (_c = channelUnread.readToSegment) !== null && _c !== void 0 ? _c : 0;
|
|
10386
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - readToSegment, 0), lastMentionedSegment, isMentioned: typeof lastMentionedSegment === 'number' && readToSegment < lastMentionedSegment });
|
|
10016
10387
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
10017
10388
|
fireEvent('local.channelUnread.updated', [updatedChannelUnread]);
|
|
10018
10389
|
});
|
|
@@ -10650,11 +11021,18 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10650
11021
|
return data;
|
|
10651
11022
|
};
|
|
10652
11023
|
|
|
11024
|
+
const CONTENT_TYPE_CONFIG = {
|
|
11025
|
+
[exports.AmitySharableContentType.POST]: { key: 'posts', placeholder: 'postId' },
|
|
11026
|
+
[exports.AmitySharableContentType.COMMUNITY]: { key: 'communities', placeholder: 'communityId' },
|
|
11027
|
+
[exports.AmitySharableContentType.USER]: { key: 'users', placeholder: 'userId' },
|
|
11028
|
+
[exports.AmitySharableContentType.LIVESTREAM]: { key: 'livestream', placeholder: 'livestream' },
|
|
11029
|
+
[exports.AmitySharableContentType.EVENT]: { key: 'events', placeholder: 'eventId' },
|
|
11030
|
+
};
|
|
10653
11031
|
/**
|
|
10654
11032
|
* ```js
|
|
10655
11033
|
* import Client from '@amityco/ts-sdk'
|
|
10656
|
-
* const
|
|
10657
|
-
* const
|
|
11034
|
+
* const config = await Client.getShareableLinkConfiguration()
|
|
11035
|
+
* const link = config.generateLink(AmitySharableContentType.EVENT, eventId)
|
|
10658
11036
|
* ```
|
|
10659
11037
|
*
|
|
10660
11038
|
* Fetches a {@link Amity.ShareableLinkConfiguration} object
|
|
@@ -10665,9 +11043,29 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
10665
11043
|
* @async
|
|
10666
11044
|
*/
|
|
10667
11045
|
const getShareableLinkConfiguration = async () => {
|
|
11046
|
+
var _a, _b;
|
|
10668
11047
|
const client = getActiveClient();
|
|
10669
11048
|
const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
|
|
10670
|
-
|
|
11049
|
+
const domain = (_a = data.domain) !== null && _a !== void 0 ? _a : '';
|
|
11050
|
+
const patterns = (_b = data.patterns) !== null && _b !== void 0 ? _b : {};
|
|
11051
|
+
return {
|
|
11052
|
+
domain,
|
|
11053
|
+
patterns,
|
|
11054
|
+
isEnabled(contentType) {
|
|
11055
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11056
|
+
return !!domain && !!patterns[key];
|
|
11057
|
+
},
|
|
11058
|
+
getPattern(contentType) {
|
|
11059
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
11060
|
+
return patterns[key] || null;
|
|
11061
|
+
},
|
|
11062
|
+
generateLink(contentType, referenceId) {
|
|
11063
|
+
const { key, placeholder } = CONTENT_TYPE_CONFIG[contentType];
|
|
11064
|
+
if (!domain || !patterns[key])
|
|
11065
|
+
return null;
|
|
11066
|
+
return domain + patterns[key].replace(`{${placeholder}}`, referenceId);
|
|
11067
|
+
},
|
|
11068
|
+
};
|
|
10671
11069
|
};
|
|
10672
11070
|
|
|
10673
11071
|
/**
|
|
@@ -10858,6 +11256,205 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
10858
11256
|
client.accessTokenHandler = accessTokenHandler;
|
|
10859
11257
|
};
|
|
10860
11258
|
|
|
11259
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
11260
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
11261
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
11262
|
+
}
|
|
11263
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
11264
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
11265
|
+
}
|
|
11266
|
+
return { type: exports.NotificationRolesFilterTypeEnum.ALL };
|
|
11267
|
+
}
|
|
11268
|
+
function serializeRolesFilter(rolesFilter) {
|
|
11269
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === exports.NotificationRolesFilterTypeEnum.ONLY) {
|
|
11270
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
11271
|
+
}
|
|
11272
|
+
return { listenFromRoleIds: [] };
|
|
11273
|
+
}
|
|
11274
|
+
class ChannelNotifications {
|
|
11275
|
+
constructor(channelId) {
|
|
11276
|
+
this.channelId = channelId;
|
|
11277
|
+
}
|
|
11278
|
+
async enable() {
|
|
11279
|
+
const client = getActiveClient();
|
|
11280
|
+
const body = {
|
|
11281
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11282
|
+
channelId: this.channelId,
|
|
11283
|
+
isPushNotifiable: true,
|
|
11284
|
+
};
|
|
11285
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11286
|
+
}
|
|
11287
|
+
async disable() {
|
|
11288
|
+
const client = getActiveClient();
|
|
11289
|
+
const body = {
|
|
11290
|
+
level: exports.NotificationSettingsLevelEnum.CHANNEL,
|
|
11291
|
+
channelId: this.channelId,
|
|
11292
|
+
isPushNotifiable: false,
|
|
11293
|
+
};
|
|
11294
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11295
|
+
}
|
|
11296
|
+
async getSettings() {
|
|
11297
|
+
const client = getActiveClient();
|
|
11298
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
11299
|
+
return { isEnabled: data.isPushNotifiable };
|
|
11300
|
+
}
|
|
11301
|
+
}
|
|
11302
|
+
class UserNotifications {
|
|
11303
|
+
async enable(modules) {
|
|
11304
|
+
var _a;
|
|
11305
|
+
const client = getActiveClient();
|
|
11306
|
+
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 : [];
|
|
11307
|
+
const body = {
|
|
11308
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
11309
|
+
isPushNotifiable: true,
|
|
11310
|
+
notifiableEvents,
|
|
11311
|
+
};
|
|
11312
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11313
|
+
}
|
|
11314
|
+
async disableAllNotifications() {
|
|
11315
|
+
const client = getActiveClient();
|
|
11316
|
+
const body = {
|
|
11317
|
+
level: exports.NotificationSettingsLevelEnum.USER,
|
|
11318
|
+
isPushNotifiable: false,
|
|
11319
|
+
notifiableEvents: [],
|
|
11320
|
+
};
|
|
11321
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11322
|
+
}
|
|
11323
|
+
async getSettings() {
|
|
11324
|
+
var _a;
|
|
11325
|
+
const client = getActiveClient();
|
|
11326
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.USER}`);
|
|
11327
|
+
const validModuleNames = Object.values(exports.UserNotificationModuleNameEnum);
|
|
11328
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11329
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
11330
|
+
.map(e => ({
|
|
11331
|
+
moduleName: e.moduleName,
|
|
11332
|
+
isEnabled: e.isPushNotifiable,
|
|
11333
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11334
|
+
}));
|
|
11335
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
11336
|
+
}
|
|
11337
|
+
}
|
|
11338
|
+
class CommunityNotifications {
|
|
11339
|
+
constructor(communityId) {
|
|
11340
|
+
this.communityId = communityId;
|
|
11341
|
+
}
|
|
11342
|
+
async enable(events) {
|
|
11343
|
+
var _a;
|
|
11344
|
+
const client = getActiveClient();
|
|
11345
|
+
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 : [];
|
|
11346
|
+
const body = {
|
|
11347
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11348
|
+
communityId: this.communityId,
|
|
11349
|
+
isPushNotifiable: true,
|
|
11350
|
+
notifiableEvents,
|
|
11351
|
+
};
|
|
11352
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11353
|
+
}
|
|
11354
|
+
async disable() {
|
|
11355
|
+
const client = getActiveClient();
|
|
11356
|
+
const body = {
|
|
11357
|
+
level: exports.NotificationSettingsLevelEnum.COMMUNITY,
|
|
11358
|
+
communityId: this.communityId,
|
|
11359
|
+
isPushNotifiable: false,
|
|
11360
|
+
notifiableEvents: [],
|
|
11361
|
+
};
|
|
11362
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
11363
|
+
}
|
|
11364
|
+
async getSettings() {
|
|
11365
|
+
var _a;
|
|
11366
|
+
const client = getActiveClient();
|
|
11367
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${exports.NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
11368
|
+
const validEventNames = Object.values(exports.CommunityNotificationEventNameEnum);
|
|
11369
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
11370
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
11371
|
+
.map(e => ({
|
|
11372
|
+
eventName: e.name,
|
|
11373
|
+
isEnabled: e.isPushNotifiable,
|
|
11374
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
11375
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
11376
|
+
}));
|
|
11377
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
11378
|
+
}
|
|
11379
|
+
}
|
|
11380
|
+
class Notifications {
|
|
11381
|
+
user() {
|
|
11382
|
+
return new UserNotifications();
|
|
11383
|
+
}
|
|
11384
|
+
community(communityId) {
|
|
11385
|
+
return new CommunityNotifications(communityId);
|
|
11386
|
+
}
|
|
11387
|
+
channel(channelId) {
|
|
11388
|
+
return new ChannelNotifications(channelId);
|
|
11389
|
+
}
|
|
11390
|
+
}
|
|
11391
|
+
const notifications = () => new Notifications();
|
|
11392
|
+
|
|
11393
|
+
/* begin_public_function
|
|
11394
|
+
id: client.enable_auto_subscriptions
|
|
11395
|
+
*/
|
|
11396
|
+
/**
|
|
11397
|
+
* ```js
|
|
11398
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
11399
|
+
* Client.enableAutoSubscriptions([Client.AutoSubscription.BLOCK])
|
|
11400
|
+
* ```
|
|
11401
|
+
*
|
|
11402
|
+
* Enables one or more managed auto-subscription handles. Managed handles are
|
|
11403
|
+
* re-applied on every (re)connect and ref-counted. All handles are on by
|
|
11404
|
+
* default; use this to re-enable handles previously turned off via
|
|
11405
|
+
* {@link disableAutoSubscriptions}. Synchronous fire-and-forget — the registry
|
|
11406
|
+
* updates immediately and the broker subscribe is retried on reconnect.
|
|
11407
|
+
*
|
|
11408
|
+
* @param features the {@link AutoSubscription} handles to enable
|
|
11409
|
+
*
|
|
11410
|
+
* @category Client API
|
|
11411
|
+
*/
|
|
11412
|
+
const enableAutoSubscriptions = (features) => {
|
|
11413
|
+
const manager = getAutoSubscriptionManager();
|
|
11414
|
+
features.forEach(feature => manager.subscribe(feature));
|
|
11415
|
+
};
|
|
11416
|
+
/* end_public_function */
|
|
11417
|
+
/* begin_public_function
|
|
11418
|
+
id: client.disable_auto_subscriptions
|
|
11419
|
+
*/
|
|
11420
|
+
/**
|
|
11421
|
+
* ```js
|
|
11422
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
11423
|
+
* Client.disableAutoSubscriptions([Client.AutoSubscription.LIVESTREAM])
|
|
11424
|
+
* ```
|
|
11425
|
+
*
|
|
11426
|
+
* Disables one or more managed auto-subscription handles. The change persists
|
|
11427
|
+
* across reconnect (it is not silently re-enabled) until
|
|
11428
|
+
* {@link enableAutoSubscriptions} is called again. Synchronous fire-and-forget.
|
|
11429
|
+
*
|
|
11430
|
+
* @param features the {@link AutoSubscription} handles to disable
|
|
11431
|
+
*
|
|
11432
|
+
* @category Client API
|
|
11433
|
+
*/
|
|
11434
|
+
const disableAutoSubscriptions = (features) => {
|
|
11435
|
+
const manager = getAutoSubscriptionManager();
|
|
11436
|
+
features.forEach(feature => manager.unsubscribe(feature));
|
|
11437
|
+
};
|
|
11438
|
+
/* end_public_function */
|
|
11439
|
+
/* begin_public_function
|
|
11440
|
+
id: client.auto_subscriptions
|
|
11441
|
+
*/
|
|
11442
|
+
/**
|
|
11443
|
+
* ```js
|
|
11444
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
11445
|
+
* Client.autoSubscriptions().forEach(s => console.log(s.feature, s.isActive, s.topicCount))
|
|
11446
|
+
* ```
|
|
11447
|
+
*
|
|
11448
|
+
* Inspects the managed auto-subscription registry — each handle's `isActive`,
|
|
11449
|
+
* `isSystem`, and `topicCount`.
|
|
11450
|
+
*
|
|
11451
|
+
* @returns a snapshot of the managed subscription registry
|
|
11452
|
+
*
|
|
11453
|
+
* @category Client API
|
|
11454
|
+
*/
|
|
11455
|
+
const autoSubscriptions = () => getAutoSubscriptionManager().subscriptions();
|
|
11456
|
+
/* end_public_function */
|
|
11457
|
+
|
|
10861
11458
|
/**
|
|
10862
11459
|
* ```js
|
|
10863
11460
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -11238,6 +11835,12 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
11238
11835
|
getCurrentUserType: getCurrentUserType,
|
|
11239
11836
|
setCurrentUserType: setCurrentUserType,
|
|
11240
11837
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
11838
|
+
getChatSettings: getChatSettings,
|
|
11839
|
+
notifications: notifications,
|
|
11840
|
+
get AutoSubscription () { return AutoSubscription; },
|
|
11841
|
+
enableAutoSubscriptions: enableAutoSubscriptions,
|
|
11842
|
+
disableAutoSubscriptions: disableAutoSubscriptions,
|
|
11843
|
+
autoSubscriptions: autoSubscriptions,
|
|
11241
11844
|
onConnectionError: onConnectionError,
|
|
11242
11845
|
onClientDisconnected: onClientDisconnected,
|
|
11243
11846
|
onClientBanned: onClientBanned,
|
|
@@ -11343,6 +11946,67 @@ const unBlockUser = async (userId) => {
|
|
|
11343
11946
|
};
|
|
11344
11947
|
/* end_public_function */
|
|
11345
11948
|
|
|
11949
|
+
/**
|
|
11950
|
+
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
11951
|
+
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
11952
|
+
* the block-relationship rows (`['follow', 'get', from#to]`) and user rows are
|
|
11953
|
+
* kept current, then forwards the affected {@link Amity.FollowStatus} to the
|
|
11954
|
+
* caller.
|
|
11955
|
+
*
|
|
11956
|
+
* @hidden
|
|
11957
|
+
*/
|
|
11958
|
+
const createBlockEventSubscriber = (event, callback) => {
|
|
11959
|
+
const client = getActiveClient();
|
|
11960
|
+
const filter = (data) => {
|
|
11961
|
+
const payload = prepareFollowersPayload(data);
|
|
11962
|
+
if (client.cache) {
|
|
11963
|
+
ingestInCache(payload);
|
|
11964
|
+
}
|
|
11965
|
+
callback(payload.follows[0]);
|
|
11966
|
+
};
|
|
11967
|
+
return createEventSubscriber(client, event, event, filter);
|
|
11968
|
+
};
|
|
11969
|
+
|
|
11970
|
+
/**
|
|
11971
|
+
* ```js
|
|
11972
|
+
* import { onUserDidBlock } from '@amityco/ts-sdk'
|
|
11973
|
+
* const dispose = onUserDidBlock(status => {
|
|
11974
|
+
* // ...
|
|
11975
|
+
* })
|
|
11976
|
+
* ```
|
|
11977
|
+
*
|
|
11978
|
+
* Fired when a block relationship is created in real time — either a user
|
|
11979
|
+
* blocks the current user (incoming) or the current user blocks someone on
|
|
11980
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
11981
|
+
* before the callback runs.
|
|
11982
|
+
*
|
|
11983
|
+
* @param callback The function to call when the event was fired
|
|
11984
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
11985
|
+
*
|
|
11986
|
+
* @category Block Events
|
|
11987
|
+
*/
|
|
11988
|
+
const onUserDidBlock = (callback) => createBlockEventSubscriber('user.didBlock', callback);
|
|
11989
|
+
|
|
11990
|
+
/**
|
|
11991
|
+
* ```js
|
|
11992
|
+
* import { onUserDidUnblock } from '@amityco/ts-sdk'
|
|
11993
|
+
* const dispose = onUserDidUnblock(status => {
|
|
11994
|
+
* // ...
|
|
11995
|
+
* })
|
|
11996
|
+
* ```
|
|
11997
|
+
*
|
|
11998
|
+
* Fired when a block relationship is removed in real time — either a user
|
|
11999
|
+
* unblocks the current user (incoming) or the current user unblocks someone on
|
|
12000
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
12001
|
+
* before the callback runs.
|
|
12002
|
+
*
|
|
12003
|
+
* @param callback The function to call when the event was fired
|
|
12004
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
12005
|
+
*
|
|
12006
|
+
* @category Block Events
|
|
12007
|
+
*/
|
|
12008
|
+
const onUserDidUnblock = (callback) => createBlockEventSubscriber('user.didUnblock', callback);
|
|
12009
|
+
|
|
11346
12010
|
/* begin_public_function
|
|
11347
12011
|
id: user.relationship.follow
|
|
11348
12012
|
*/
|
|
@@ -12445,6 +13109,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
12445
13109
|
__proto__: null,
|
|
12446
13110
|
blockUser: blockUser,
|
|
12447
13111
|
unBlockUser: unBlockUser,
|
|
13112
|
+
onUserDidBlock: onUserDidBlock,
|
|
13113
|
+
onUserDidUnblock: onUserDidUnblock,
|
|
12448
13114
|
follow: follow,
|
|
12449
13115
|
unfollow: unfollow,
|
|
12450
13116
|
acceptMyFollower: acceptMyFollower,
|
|
@@ -13274,7 +13940,7 @@ const getWatchSessionStorage = () => {
|
|
|
13274
13940
|
return storageInstance;
|
|
13275
13941
|
};
|
|
13276
13942
|
|
|
13277
|
-
const privateKey = "
|
|
13943
|
+
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
13944
|
/*
|
|
13279
13945
|
* The crypto algorithm used for importing key and signing string
|
|
13280
13946
|
*/
|
|
@@ -14596,6 +15262,10 @@ const postLinkedObject = (post) => {
|
|
|
14596
15262
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
14597
15263
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
14598
15264
|
},
|
|
15265
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
15266
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
15267
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
15268
|
+
},
|
|
14599
15269
|
},
|
|
14600
15270
|
get productTags() {
|
|
14601
15271
|
var _a, _b;
|
|
@@ -14785,6 +15455,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
14785
15455
|
});
|
|
14786
15456
|
return true;
|
|
14787
15457
|
}
|
|
15458
|
+
if (referenceType === 'message') {
|
|
15459
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15460
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15461
|
+
return true;
|
|
15462
|
+
}
|
|
14788
15463
|
}
|
|
14789
15464
|
return true;
|
|
14790
15465
|
};
|
|
@@ -14863,7 +15538,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14863
15538
|
return true;
|
|
14864
15539
|
}
|
|
14865
15540
|
if (referenceType === 'story') {
|
|
14866
|
-
fireEvent('local.story.
|
|
15541
|
+
fireEvent('local.story.reactionRemoved', {
|
|
14867
15542
|
story: updatedModel,
|
|
14868
15543
|
reactor: {
|
|
14869
15544
|
userId: client.userId,
|
|
@@ -14873,6 +15548,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
14873
15548
|
});
|
|
14874
15549
|
return true;
|
|
14875
15550
|
}
|
|
15551
|
+
if (referenceType === 'message') {
|
|
15552
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
15553
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
15554
|
+
return true;
|
|
15555
|
+
}
|
|
14876
15556
|
}
|
|
14877
15557
|
return true;
|
|
14878
15558
|
};
|
|
@@ -16192,6 +16872,12 @@ class BlockedUserPaginationController extends PaginationController {
|
|
|
16192
16872
|
}
|
|
16193
16873
|
}
|
|
16194
16874
|
|
|
16875
|
+
var EnumBlockActions;
|
|
16876
|
+
(function (EnumBlockActions) {
|
|
16877
|
+
EnumBlockActions["OnBlocked"] = "onBlocked";
|
|
16878
|
+
EnumBlockActions["OnUnblocked"] = "onUnblocked";
|
|
16879
|
+
})(EnumBlockActions || (EnumBlockActions = {}));
|
|
16880
|
+
|
|
16195
16881
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
16196
16882
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
16197
16883
|
super(query, cacheKey);
|
|
@@ -16221,11 +16907,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
16221
16907
|
}
|
|
16222
16908
|
reactor(action) {
|
|
16223
16909
|
return (targetUser) => {
|
|
16224
|
-
var _a;
|
|
16225
|
-
|
|
16910
|
+
var _a, _b;
|
|
16911
|
+
const isRemoval = action === EnumFollowActions.OnFollowed || action === EnumBlockActions.OnUnblocked;
|
|
16912
|
+
const isAddition = action === EnumBlockActions.OnBlocked;
|
|
16913
|
+
if (isRemoval || isAddition) {
|
|
16226
16914
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16227
|
-
const
|
|
16228
|
-
|
|
16915
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
16916
|
+
const data = isAddition
|
|
16917
|
+
? [...new Set([...ids, targetUser.userId])]
|
|
16918
|
+
: ids.filter(id => id !== targetUser.userId);
|
|
16919
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
16229
16920
|
}
|
|
16230
16921
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
16231
16922
|
};
|
|
@@ -16280,7 +16971,6 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16280
16971
|
fn: onUserDeleted$2,
|
|
16281
16972
|
action: EnumUserActions.OnUserDeleted,
|
|
16282
16973
|
},
|
|
16283
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
16284
16974
|
{
|
|
16285
16975
|
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
16286
16976
|
action: EnumFollowActions.OnFollowed,
|
|
@@ -16289,6 +16979,28 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
16289
16979
|
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
16290
16980
|
action: EnumFollowActions.OnFollowed,
|
|
16291
16981
|
},
|
|
16982
|
+
{
|
|
16983
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
16984
|
+
var _a;
|
|
16985
|
+
if (status.from !== getActiveClient().userId)
|
|
16986
|
+
return;
|
|
16987
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
16988
|
+
if (blocked)
|
|
16989
|
+
reactor(blocked);
|
|
16990
|
+
}),
|
|
16991
|
+
action: EnumBlockActions.OnBlocked,
|
|
16992
|
+
},
|
|
16993
|
+
{
|
|
16994
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
16995
|
+
var _a;
|
|
16996
|
+
if (status.from !== getActiveClient().userId)
|
|
16997
|
+
return;
|
|
16998
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
16999
|
+
if (blocked)
|
|
17000
|
+
reactor(blocked);
|
|
17001
|
+
}),
|
|
17002
|
+
action: EnumBlockActions.OnUnblocked,
|
|
17003
|
+
},
|
|
16292
17004
|
]);
|
|
16293
17005
|
}
|
|
16294
17006
|
notifyChange({ origin, loading, error }) {
|
|
@@ -16356,6 +17068,192 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
16356
17068
|
};
|
|
16357
17069
|
/* end_public_function */
|
|
16358
17070
|
|
|
17071
|
+
function prepareBlockingUserPayload(response) {
|
|
17072
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
17073
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
17074
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
17075
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
17076
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
17077
|
+
}
|
|
17078
|
+
|
|
17079
|
+
class BlockingUserQueryStreamController extends QueryStreamController {
|
|
17080
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
17081
|
+
super(query, cacheKey);
|
|
17082
|
+
this.notifyChange = notifyChange;
|
|
17083
|
+
this.preparePayload = preparePayload;
|
|
17084
|
+
}
|
|
17085
|
+
async saveToMainDB(response) {
|
|
17086
|
+
const processedPayload = await this.preparePayload(response);
|
|
17087
|
+
const client = getActiveClient();
|
|
17088
|
+
const cachedAt = client.cache && Date.now();
|
|
17089
|
+
if (client.cache) {
|
|
17090
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
17091
|
+
}
|
|
17092
|
+
}
|
|
17093
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
17094
|
+
var _a, _b;
|
|
17095
|
+
if (refresh) {
|
|
17096
|
+
pushToCache(this.cacheKey, {
|
|
17097
|
+
data: response.users.map(getResolver('user')),
|
|
17098
|
+
});
|
|
17099
|
+
}
|
|
17100
|
+
else {
|
|
17101
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17102
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17103
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
17104
|
+
}
|
|
17105
|
+
}
|
|
17106
|
+
reactor(action) {
|
|
17107
|
+
return (user) => {
|
|
17108
|
+
var _a, _b;
|
|
17109
|
+
if (user &&
|
|
17110
|
+
(action === EnumBlockActions.OnBlocked || action === EnumBlockActions.OnUnblocked)) {
|
|
17111
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17112
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
17113
|
+
const data = action === EnumBlockActions.OnBlocked
|
|
17114
|
+
? [...new Set([...ids, user.userId])]
|
|
17115
|
+
: ids.filter(id => id !== user.userId);
|
|
17116
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
17117
|
+
}
|
|
17118
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
17119
|
+
};
|
|
17120
|
+
}
|
|
17121
|
+
subscribeRTE(createSubscriber) {
|
|
17122
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
17123
|
+
}
|
|
17124
|
+
}
|
|
17125
|
+
|
|
17126
|
+
class BlockingUserPaginationController extends PaginationController {
|
|
17127
|
+
async getRequest(queryParams, token) {
|
|
17128
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
17129
|
+
const options = token ? { token } : { limit };
|
|
17130
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/blockers', {
|
|
17131
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
17132
|
+
});
|
|
17133
|
+
return queryResponse;
|
|
17134
|
+
}
|
|
17135
|
+
}
|
|
17136
|
+
|
|
17137
|
+
class BlockingUserLiveCollectionController extends LiveCollectionController {
|
|
17138
|
+
constructor(callback) {
|
|
17139
|
+
const queryStreamId = `blocking-users-${getActiveClient().userId}`;
|
|
17140
|
+
const query = {};
|
|
17141
|
+
const cacheKey = ['blockingUsers', 'collection', queryStreamId];
|
|
17142
|
+
const paginationController = new BlockingUserPaginationController(query);
|
|
17143
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
17144
|
+
this.queryStreamController = new BlockingUserQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), prepareBlockingUserPayload);
|
|
17145
|
+
this.callback = callback.bind(this);
|
|
17146
|
+
this.loadPage({ initial: true });
|
|
17147
|
+
}
|
|
17148
|
+
setup() {
|
|
17149
|
+
var _a;
|
|
17150
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17151
|
+
if (!collection) {
|
|
17152
|
+
pushToCache(this.cacheKey, {
|
|
17153
|
+
data: [],
|
|
17154
|
+
params: {},
|
|
17155
|
+
});
|
|
17156
|
+
}
|
|
17157
|
+
}
|
|
17158
|
+
async persistModel(queryPayload) {
|
|
17159
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
17160
|
+
}
|
|
17161
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
17162
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
17163
|
+
}
|
|
17164
|
+
startSubscription() {
|
|
17165
|
+
return this.queryStreamController.subscribeRTE([
|
|
17166
|
+
{
|
|
17167
|
+
fn: onUserDeleted$2,
|
|
17168
|
+
action: EnumUserActions.OnUserDeleted,
|
|
17169
|
+
},
|
|
17170
|
+
{
|
|
17171
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
17172
|
+
var _a;
|
|
17173
|
+
if (status.to !== getActiveClient().userId)
|
|
17174
|
+
return;
|
|
17175
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17176
|
+
if (blocker)
|
|
17177
|
+
reactor(blocker);
|
|
17178
|
+
}),
|
|
17179
|
+
action: EnumBlockActions.OnBlocked,
|
|
17180
|
+
},
|
|
17181
|
+
{
|
|
17182
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
17183
|
+
var _a;
|
|
17184
|
+
if (status.to !== getActiveClient().userId)
|
|
17185
|
+
return;
|
|
17186
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
17187
|
+
if (blocker)
|
|
17188
|
+
reactor(blocker);
|
|
17189
|
+
}),
|
|
17190
|
+
action: EnumBlockActions.OnUnblocked,
|
|
17191
|
+
},
|
|
17192
|
+
]);
|
|
17193
|
+
}
|
|
17194
|
+
notifyChange({ origin, loading, error }) {
|
|
17195
|
+
var _a, _b;
|
|
17196
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17197
|
+
if (!collection)
|
|
17198
|
+
return;
|
|
17199
|
+
const data = this.applyFilter((_b = collection.data
|
|
17200
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
17201
|
+
.filter(isNonNullable)
|
|
17202
|
+
.map(({ data }) => data)
|
|
17203
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
17204
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
17205
|
+
return;
|
|
17206
|
+
this.callback({
|
|
17207
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
17208
|
+
data,
|
|
17209
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
17210
|
+
loading,
|
|
17211
|
+
error,
|
|
17212
|
+
});
|
|
17213
|
+
}
|
|
17214
|
+
applyFilter(data) {
|
|
17215
|
+
let users = data;
|
|
17216
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
17217
|
+
return users;
|
|
17218
|
+
}
|
|
17219
|
+
}
|
|
17220
|
+
|
|
17221
|
+
/* begin_public_function
|
|
17222
|
+
id: user.get_blocking_users
|
|
17223
|
+
*/
|
|
17224
|
+
/**
|
|
17225
|
+
* ```js
|
|
17226
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
17227
|
+
* const unsubscribe = UserRepository.getBlockingUsers(({ data: users }) => {
|
|
17228
|
+
* console.log(users)
|
|
17229
|
+
* })
|
|
17230
|
+
* ```
|
|
17231
|
+
*
|
|
17232
|
+
* Observe the {@link Amity.User}s who have blocked the current user
|
|
17233
|
+
*
|
|
17234
|
+
* @param callback to receive updates on the blocking {@link Amity.User}s
|
|
17235
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
17236
|
+
*
|
|
17237
|
+
* @category User API
|
|
17238
|
+
*/
|
|
17239
|
+
const getBlockingUsers = (callback) => {
|
|
17240
|
+
const { log, cache } = getActiveClient();
|
|
17241
|
+
if (!cache)
|
|
17242
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
17243
|
+
const timestamp = Date.now();
|
|
17244
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > listen`);
|
|
17245
|
+
const blockingUserLiveCollection = new BlockingUserLiveCollectionController(callback);
|
|
17246
|
+
const disposers = blockingUserLiveCollection.startSubscription();
|
|
17247
|
+
const cacheKey = blockingUserLiveCollection.getCacheKey();
|
|
17248
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
17249
|
+
return () => {
|
|
17250
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > dispose`);
|
|
17251
|
+
disposers.forEach(fn => fn());
|
|
17252
|
+
dropFromCache(cacheKey);
|
|
17253
|
+
};
|
|
17254
|
+
};
|
|
17255
|
+
/* end_public_function */
|
|
17256
|
+
|
|
16359
17257
|
class SearchUserPaginationController extends PaginationController {
|
|
16360
17258
|
async getRequest(queryParams, token) {
|
|
16361
17259
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
@@ -16630,6 +17528,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
16630
17528
|
getUser: getUser,
|
|
16631
17529
|
getUsers: getUsers,
|
|
16632
17530
|
getBlockedUsers: getBlockedUsers,
|
|
17531
|
+
getBlockingUsers: getBlockingUsers,
|
|
16633
17532
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
16634
17533
|
getReachedUsers: getReachedUsers,
|
|
16635
17534
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
@@ -17796,7 +18695,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
17796
18695
|
return true;
|
|
17797
18696
|
}
|
|
17798
18697
|
if (referenceType === 'story') {
|
|
17799
|
-
fireEvent('local.story.
|
|
18698
|
+
fireEvent('local.story.reactionRemoved', {
|
|
17800
18699
|
story: updatedModel,
|
|
17801
18700
|
reactor: {
|
|
17802
18701
|
userId: client.userId,
|
|
@@ -19380,6 +20279,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
19380
20279
|
};
|
|
19381
20280
|
/* end_public_function */
|
|
19382
20281
|
|
|
20282
|
+
/* begin_public_function
|
|
20283
|
+
id: channel.archive
|
|
20284
|
+
*/
|
|
20285
|
+
/**
|
|
20286
|
+
* ```js
|
|
20287
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20288
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
20289
|
+
* ```
|
|
20290
|
+
*
|
|
20291
|
+
* Archive a {@link Amity.Channel}.
|
|
20292
|
+
*
|
|
20293
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
20294
|
+
* @returns A success boolean
|
|
20295
|
+
*
|
|
20296
|
+
* @category Channel API
|
|
20297
|
+
* @async
|
|
20298
|
+
*/
|
|
20299
|
+
const archiveChannel = async (channelId) => {
|
|
20300
|
+
const client = getActiveClient();
|
|
20301
|
+
client.log('channel/archiveChannel', channelId);
|
|
20302
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20303
|
+
const archive = {
|
|
20304
|
+
channelId,
|
|
20305
|
+
archivedAt: new Date().toISOString(),
|
|
20306
|
+
};
|
|
20307
|
+
if (client.cache) {
|
|
20308
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
20309
|
+
}
|
|
20310
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
20311
|
+
};
|
|
20312
|
+
/* end_public_function */
|
|
20313
|
+
|
|
20314
|
+
/* begin_public_function
|
|
20315
|
+
id: channel.unarchive
|
|
20316
|
+
*/
|
|
20317
|
+
/**
|
|
20318
|
+
* ```js
|
|
20319
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20320
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
20321
|
+
* ```
|
|
20322
|
+
*
|
|
20323
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
20324
|
+
*
|
|
20325
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
20326
|
+
* @returns A success boolean
|
|
20327
|
+
*
|
|
20328
|
+
* @category Channel API
|
|
20329
|
+
* @async
|
|
20330
|
+
*/
|
|
20331
|
+
const unarchiveChannel = async (channelId) => {
|
|
20332
|
+
var _a;
|
|
20333
|
+
const client = getActiveClient();
|
|
20334
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
20335
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
20336
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
20337
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
20338
|
+
channelId,
|
|
20339
|
+
archivedAt: new Date().toISOString(),
|
|
20340
|
+
};
|
|
20341
|
+
if (client.cache) {
|
|
20342
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
20343
|
+
}
|
|
20344
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
20345
|
+
};
|
|
20346
|
+
/* end_public_function */
|
|
20347
|
+
|
|
20348
|
+
/* begin_public_function
|
|
20349
|
+
id: channel.archive.ids
|
|
20350
|
+
*/
|
|
20351
|
+
/**
|
|
20352
|
+
* ```js
|
|
20353
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
20354
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
20355
|
+
* ```
|
|
20356
|
+
*
|
|
20357
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
20358
|
+
*
|
|
20359
|
+
* @category Channel API
|
|
20360
|
+
* @async
|
|
20361
|
+
*/
|
|
20362
|
+
const getArchivedChannelIds = async () => {
|
|
20363
|
+
var _a;
|
|
20364
|
+
const client = getActiveClient();
|
|
20365
|
+
client.log('channel/getArchivedChannelIds');
|
|
20366
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
20367
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
20368
|
+
if (client.cache) {
|
|
20369
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
20370
|
+
archives.forEach(archive => {
|
|
20371
|
+
if (!archive.channelId)
|
|
20372
|
+
return;
|
|
20373
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
20374
|
+
});
|
|
20375
|
+
}
|
|
20376
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
20377
|
+
};
|
|
20378
|
+
/* end_public_function */
|
|
20379
|
+
|
|
19383
20380
|
/**
|
|
19384
20381
|
* ```js
|
|
19385
20382
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -20758,6 +21755,160 @@ const getMessages = (params, callback, config) => {
|
|
|
20758
21755
|
};
|
|
20759
21756
|
/* end_public_function */
|
|
20760
21757
|
|
|
21758
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
21759
|
+
async getRequest(queryParams, token) {
|
|
21760
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
21761
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
21762
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
21763
|
+
params: {
|
|
21764
|
+
query,
|
|
21765
|
+
exactMatch,
|
|
21766
|
+
channelId,
|
|
21767
|
+
messageFeedId,
|
|
21768
|
+
userIds,
|
|
21769
|
+
tags,
|
|
21770
|
+
types,
|
|
21771
|
+
options,
|
|
21772
|
+
},
|
|
21773
|
+
});
|
|
21774
|
+
return queryResponse;
|
|
21775
|
+
}
|
|
21776
|
+
}
|
|
21777
|
+
|
|
21778
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
21779
|
+
constructor(query, cacheKey, notifyChange) {
|
|
21780
|
+
super(query, cacheKey);
|
|
21781
|
+
this.notifyChange = notifyChange;
|
|
21782
|
+
}
|
|
21783
|
+
async saveToMainDB(response) {
|
|
21784
|
+
var _a;
|
|
21785
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
21786
|
+
const client = getActiveClient();
|
|
21787
|
+
const cachedAt = client.cache && Date.now();
|
|
21788
|
+
if (client.cache) {
|
|
21789
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
21790
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
21791
|
+
response.channels.forEach(channel => {
|
|
21792
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
21793
|
+
});
|
|
21794
|
+
}
|
|
21795
|
+
}
|
|
21796
|
+
}
|
|
21797
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
21798
|
+
var _a, _b;
|
|
21799
|
+
if (refresh) {
|
|
21800
|
+
pushToCache(this.cacheKey, {
|
|
21801
|
+
data: response.messages.map(getResolver('message')),
|
|
21802
|
+
});
|
|
21803
|
+
return;
|
|
21804
|
+
}
|
|
21805
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21806
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
21807
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
21808
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
21809
|
+
? [...new Set([...incoming, ...existing])]
|
|
21810
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
21811
|
+
}
|
|
21812
|
+
}
|
|
21813
|
+
|
|
21814
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
21815
|
+
constructor(query, callback) {
|
|
21816
|
+
const queryStreamId = hash__default["default"](query);
|
|
21817
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
21818
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
21819
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
21820
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
21821
|
+
this.callback = callback.bind(this);
|
|
21822
|
+
this.loadPage({ initial: true });
|
|
21823
|
+
}
|
|
21824
|
+
startSubscription() {
|
|
21825
|
+
return [];
|
|
21826
|
+
}
|
|
21827
|
+
notifyChange({ origin, loading, error }) {
|
|
21828
|
+
var _a, _b;
|
|
21829
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21830
|
+
if (!collection)
|
|
21831
|
+
return;
|
|
21832
|
+
const data = (_b = collection.data
|
|
21833
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
21834
|
+
.filter(isNonNullable)
|
|
21835
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
21836
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
21837
|
+
return;
|
|
21838
|
+
this.callback({
|
|
21839
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
21840
|
+
data,
|
|
21841
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
21842
|
+
loading,
|
|
21843
|
+
error,
|
|
21844
|
+
});
|
|
21845
|
+
}
|
|
21846
|
+
setup() {
|
|
21847
|
+
var _a;
|
|
21848
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
21849
|
+
if (!collection) {
|
|
21850
|
+
pushToCache(this.cacheKey, {
|
|
21851
|
+
data: [],
|
|
21852
|
+
params: {},
|
|
21853
|
+
});
|
|
21854
|
+
}
|
|
21855
|
+
}
|
|
21856
|
+
async persistModel(response) {
|
|
21857
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
21858
|
+
}
|
|
21859
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
21860
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
21861
|
+
}
|
|
21862
|
+
}
|
|
21863
|
+
|
|
21864
|
+
/* begin_public_function
|
|
21865
|
+
id: message.search
|
|
21866
|
+
*/
|
|
21867
|
+
/**
|
|
21868
|
+
* ```js
|
|
21869
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
21870
|
+
*
|
|
21871
|
+
* let messages = [];
|
|
21872
|
+
*
|
|
21873
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
21874
|
+
* { query: 'hello' },
|
|
21875
|
+
* response => merge(messages, response.data),
|
|
21876
|
+
* );
|
|
21877
|
+
* ```
|
|
21878
|
+
*
|
|
21879
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
21880
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
21881
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
21882
|
+
*
|
|
21883
|
+
* @param params Search parameters. `query` is required.
|
|
21884
|
+
* @param callback Called whenever new data are available.
|
|
21885
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
21886
|
+
*
|
|
21887
|
+
* @category Message Live Collection
|
|
21888
|
+
*/
|
|
21889
|
+
const searchMessage = (params, callback) => {
|
|
21890
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
21891
|
+
throw new Error('Query is required for message search');
|
|
21892
|
+
}
|
|
21893
|
+
const { log, cache } = getActiveClient();
|
|
21894
|
+
if (!cache) {
|
|
21895
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
21896
|
+
}
|
|
21897
|
+
const timestamp = Date.now();
|
|
21898
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
21899
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
21900
|
+
const disposers = controller.startSubscription();
|
|
21901
|
+
const cacheKey = controller.getCacheKey();
|
|
21902
|
+
disposers.push(() => {
|
|
21903
|
+
dropFromCache(cacheKey);
|
|
21904
|
+
});
|
|
21905
|
+
return () => {
|
|
21906
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
21907
|
+
disposers.forEach(fn => fn());
|
|
21908
|
+
};
|
|
21909
|
+
};
|
|
21910
|
+
/* end_public_function */
|
|
21911
|
+
|
|
20761
21912
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
20762
21913
|
__proto__: null,
|
|
20763
21914
|
createMessage: createMessage,
|
|
@@ -20783,6 +21934,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
20783
21934
|
onMessageFetched: onMessageFetched,
|
|
20784
21935
|
getMessage: getMessage,
|
|
20785
21936
|
getMessages: getMessages,
|
|
21937
|
+
searchMessage: searchMessage,
|
|
20786
21938
|
convertFromRaw: convertFromRaw$1,
|
|
20787
21939
|
prepareMessagePayload: prepareMessagePayload,
|
|
20788
21940
|
convertParams: convertParams,
|
|
@@ -21630,6 +22782,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21630
22782
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
21631
22783
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
21632
22784
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
22785
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
21633
22786
|
].includes(action)) {
|
|
21634
22787
|
if (Array.isArray(payload)) {
|
|
21635
22788
|
collection.data = [
|
|
@@ -21639,6 +22792,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
21639
22792
|
else
|
|
21640
22793
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
21641
22794
|
}
|
|
22795
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
22796
|
+
const ids = Array.isArray(payload)
|
|
22797
|
+
? payload.map(getResolver('channel'))
|
|
22798
|
+
: [getResolver('channel')(payload)];
|
|
22799
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
22800
|
+
}
|
|
21642
22801
|
pushToCache(this.cacheKey, collection);
|
|
21643
22802
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
21644
22803
|
};
|
|
@@ -21905,6 +23064,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21905
23064
|
},
|
|
21906
23065
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
21907
23066
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
23067
|
+
{
|
|
23068
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
23069
|
+
const channels = payload.archives
|
|
23070
|
+
.map(archive => {
|
|
23071
|
+
var _a;
|
|
23072
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23073
|
+
})
|
|
23074
|
+
.filter((c) => Boolean(c));
|
|
23075
|
+
if (channels.length > 0)
|
|
23076
|
+
reactor(channels);
|
|
23077
|
+
}),
|
|
23078
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23079
|
+
},
|
|
23080
|
+
{
|
|
23081
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
23082
|
+
const channels = payload.archives
|
|
23083
|
+
.map(archive => {
|
|
23084
|
+
var _a;
|
|
23085
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23086
|
+
})
|
|
23087
|
+
.filter((c) => Boolean(c));
|
|
23088
|
+
if (channels.length > 0)
|
|
23089
|
+
reactor(channels);
|
|
23090
|
+
}),
|
|
23091
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23092
|
+
},
|
|
21908
23093
|
{
|
|
21909
23094
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
21910
23095
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -22258,6 +23443,192 @@ const getTotalChannelsUnread = (callback) => {
|
|
|
22258
23443
|
};
|
|
22259
23444
|
};
|
|
22260
23445
|
|
|
23446
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
23447
|
+
async getRequest(queryParams, token) {
|
|
23448
|
+
var _a, _b;
|
|
23449
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
23450
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
23451
|
+
if (pageIndex === 0) {
|
|
23452
|
+
await getArchivedChannelIds();
|
|
23453
|
+
}
|
|
23454
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
23455
|
+
const archives = cached
|
|
23456
|
+
.map(entry => entry.data)
|
|
23457
|
+
.slice()
|
|
23458
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
23459
|
+
const start = pageIndex * limit;
|
|
23460
|
+
const end = start + limit;
|
|
23461
|
+
const slice = archives.slice(start, end);
|
|
23462
|
+
const hasMore = end < archives.length;
|
|
23463
|
+
if (slice.length > 0) {
|
|
23464
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
23465
|
+
}
|
|
23466
|
+
return {
|
|
23467
|
+
archives: slice,
|
|
23468
|
+
paging: {
|
|
23469
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
23470
|
+
previous: undefined,
|
|
23471
|
+
},
|
|
23472
|
+
};
|
|
23473
|
+
}
|
|
23474
|
+
}
|
|
23475
|
+
|
|
23476
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
23477
|
+
constructor(query, cacheKey, notifyChange) {
|
|
23478
|
+
super(query, cacheKey);
|
|
23479
|
+
this.notifyChange = notifyChange;
|
|
23480
|
+
}
|
|
23481
|
+
async saveToMainDB(_response) {
|
|
23482
|
+
//
|
|
23483
|
+
}
|
|
23484
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23485
|
+
var _a, _b;
|
|
23486
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
23487
|
+
if (refresh) {
|
|
23488
|
+
pushToCache(this.cacheKey, {
|
|
23489
|
+
data: channelIds,
|
|
23490
|
+
params: {},
|
|
23491
|
+
});
|
|
23492
|
+
return;
|
|
23493
|
+
}
|
|
23494
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23495
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23496
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
23497
|
+
? [...new Set([...channelIds, ...existing])]
|
|
23498
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
23499
|
+
}
|
|
23500
|
+
reactor(action) {
|
|
23501
|
+
return (channelIds) => {
|
|
23502
|
+
var _a;
|
|
23503
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23504
|
+
if (!collection)
|
|
23505
|
+
return;
|
|
23506
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
23507
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
23508
|
+
collection.data = [...channelIds, ...filtered];
|
|
23509
|
+
}
|
|
23510
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
23511
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
23512
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
23513
|
+
}
|
|
23514
|
+
pushToCache(this.cacheKey, collection);
|
|
23515
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23516
|
+
};
|
|
23517
|
+
}
|
|
23518
|
+
subscribeRTE(createSubscriber) {
|
|
23519
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23520
|
+
}
|
|
23521
|
+
}
|
|
23522
|
+
|
|
23523
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
23524
|
+
constructor(query, callback) {
|
|
23525
|
+
const queryStreamId = hash__default["default"](query);
|
|
23526
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
23527
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
23528
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23529
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
23530
|
+
this.callback = callback.bind(this);
|
|
23531
|
+
this.loadPage({ initial: true });
|
|
23532
|
+
}
|
|
23533
|
+
setup() {
|
|
23534
|
+
var _a;
|
|
23535
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23536
|
+
if (!collection) {
|
|
23537
|
+
pushToCache(this.cacheKey, {
|
|
23538
|
+
data: [],
|
|
23539
|
+
params: {},
|
|
23540
|
+
});
|
|
23541
|
+
}
|
|
23542
|
+
}
|
|
23543
|
+
async persistModel(response) {
|
|
23544
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
23545
|
+
}
|
|
23546
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23547
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23548
|
+
}
|
|
23549
|
+
startSubscription() {
|
|
23550
|
+
return this.queryStreamController.subscribeRTE([
|
|
23551
|
+
{
|
|
23552
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23553
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
23554
|
+
},
|
|
23555
|
+
{
|
|
23556
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
23557
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
23558
|
+
},
|
|
23559
|
+
{
|
|
23560
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
23561
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
23562
|
+
},
|
|
23563
|
+
{
|
|
23564
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
23565
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
23566
|
+
},
|
|
23567
|
+
]);
|
|
23568
|
+
}
|
|
23569
|
+
notifyChange({ origin, loading, error }) {
|
|
23570
|
+
var _a, _b;
|
|
23571
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23572
|
+
if (!collection)
|
|
23573
|
+
return;
|
|
23574
|
+
const data = (_b = collection.data
|
|
23575
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
23576
|
+
.filter((entry) => Boolean(entry))
|
|
23577
|
+
.map(({ data: channel }) => channel)
|
|
23578
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
23579
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
23580
|
+
return;
|
|
23581
|
+
this.callback({
|
|
23582
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
23583
|
+
data,
|
|
23584
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
23585
|
+
loading,
|
|
23586
|
+
error,
|
|
23587
|
+
});
|
|
23588
|
+
}
|
|
23589
|
+
}
|
|
23590
|
+
|
|
23591
|
+
/* begin_public_function
|
|
23592
|
+
id: channel.archive.collection
|
|
23593
|
+
*/
|
|
23594
|
+
/**
|
|
23595
|
+
* ```js
|
|
23596
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
23597
|
+
*
|
|
23598
|
+
* let channels = []
|
|
23599
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
23600
|
+
* ```
|
|
23601
|
+
*
|
|
23602
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
23603
|
+
*
|
|
23604
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
23605
|
+
* archive list takes no other filters).
|
|
23606
|
+
* @param callback the function to call when new data are available
|
|
23607
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
23608
|
+
* stop observing.
|
|
23609
|
+
*
|
|
23610
|
+
* @category Channel Live Collection
|
|
23611
|
+
*/
|
|
23612
|
+
const getArchivedChannels = (params, callback) => {
|
|
23613
|
+
const { log, cache } = getActiveClient();
|
|
23614
|
+
if (!cache) {
|
|
23615
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
23616
|
+
}
|
|
23617
|
+
const timestamp = Date.now();
|
|
23618
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
23619
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
23620
|
+
const disposers = controller.startSubscription();
|
|
23621
|
+
const cacheKey = controller.getCacheKey();
|
|
23622
|
+
disposers.push(() => {
|
|
23623
|
+
dropFromCache(cacheKey);
|
|
23624
|
+
});
|
|
23625
|
+
return () => {
|
|
23626
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
23627
|
+
disposers.forEach(fn => fn());
|
|
23628
|
+
};
|
|
23629
|
+
};
|
|
23630
|
+
/* end_public_function */
|
|
23631
|
+
|
|
22261
23632
|
/* begin_public_function
|
|
22262
23633
|
id: channel.member.add
|
|
22263
23634
|
*/
|
|
@@ -22389,7 +23760,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
22389
23760
|
channelId: this.query.channelId,
|
|
22390
23761
|
userId: channelMember.userId,
|
|
22391
23762
|
});
|
|
22392
|
-
|
|
23763
|
+
const membershipFilter = this.query.memberships;
|
|
23764
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
23765
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
22393
23766
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
22394
23767
|
}
|
|
22395
23768
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -22725,6 +24098,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
22725
24098
|
const cachedAt = client.cache && Date.now();
|
|
22726
24099
|
if (client.cache)
|
|
22727
24100
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24101
|
+
fireEvent('channel.banned', payload);
|
|
22728
24102
|
return {
|
|
22729
24103
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
22730
24104
|
cachedAt,
|
|
@@ -22759,6 +24133,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
22759
24133
|
const cachedAt = client.cache && Date.now();
|
|
22760
24134
|
if (client.cache)
|
|
22761
24135
|
ingestInCache(preparedPayload, { cachedAt });
|
|
24136
|
+
fireEvent('channel.unbanned', payload);
|
|
22762
24137
|
const { channelUsers } = preparedPayload;
|
|
22763
24138
|
return {
|
|
22764
24139
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -22787,6 +24162,7 @@ const MUTE_FOREVER = -1;
|
|
|
22787
24162
|
* @async
|
|
22788
24163
|
* */
|
|
22789
24164
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
24165
|
+
var _a;
|
|
22790
24166
|
const client = getActiveClient();
|
|
22791
24167
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
22792
24168
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -22794,6 +24170,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22794
24170
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
22795
24171
|
});
|
|
22796
24172
|
const { success } = data;
|
|
24173
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
24174
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
24175
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
24176
|
+
fireEvent('channel.setMutedUsers', {
|
|
24177
|
+
channelId,
|
|
24178
|
+
userIds,
|
|
24179
|
+
muteTimeout,
|
|
24180
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24181
|
+
});
|
|
22797
24182
|
return success;
|
|
22798
24183
|
};
|
|
22799
24184
|
/* end_public_function */
|
|
@@ -22816,6 +24201,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
22816
24201
|
* @async
|
|
22817
24202
|
* */
|
|
22818
24203
|
const unmuteMembers = async (channelId, userIds) => {
|
|
24204
|
+
var _a;
|
|
22819
24205
|
const client = getActiveClient();
|
|
22820
24206
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
22821
24207
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -22823,6 +24209,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22823
24209
|
mutePeriod: 0,
|
|
22824
24210
|
});
|
|
22825
24211
|
const { success } = data;
|
|
24212
|
+
fireEvent('channel.setMutedUsers', {
|
|
24213
|
+
channelId,
|
|
24214
|
+
userIds,
|
|
24215
|
+
muteTimeout: new Date(0).toISOString(),
|
|
24216
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
24217
|
+
});
|
|
22826
24218
|
return success;
|
|
22827
24219
|
};
|
|
22828
24220
|
/* end_public_function */
|
|
@@ -22849,6 +24241,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22849
24241
|
leaveChannel: leaveChannel,
|
|
22850
24242
|
muteChannel: muteChannel,
|
|
22851
24243
|
unmuteChannel: unmuteChannel,
|
|
24244
|
+
archiveChannel: archiveChannel,
|
|
24245
|
+
unarchiveChannel: unarchiveChannel,
|
|
24246
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
22852
24247
|
onChannelCreated: onChannelCreated,
|
|
22853
24248
|
onChannelUpdated: onChannelUpdated,
|
|
22854
24249
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -22861,9 +24256,12 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22861
24256
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
22862
24257
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
22863
24258
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
24259
|
+
onChannelArchived: onChannelArchived,
|
|
24260
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
22864
24261
|
getChannel: getChannel,
|
|
22865
24262
|
getChannels: getChannels,
|
|
22866
24263
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
24264
|
+
getArchivedChannels: getArchivedChannels,
|
|
22867
24265
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
22868
24266
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22869
24267
|
convertFromRaw: convertFromRaw,
|
|
@@ -26759,7 +28157,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26759
28157
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
26760
28158
|
}
|
|
26761
28159
|
startSubscription() {
|
|
26762
|
-
|
|
28160
|
+
const disposers = this.queryStreamController.subscribeRTE([
|
|
26763
28161
|
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
26764
28162
|
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
26765
28163
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
@@ -26772,6 +28170,11 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26772
28170
|
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
26773
28171
|
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
26774
28172
|
]);
|
|
28173
|
+
if (this.query.excludeBlockUserComments) {
|
|
28174
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28175
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
28176
|
+
}
|
|
28177
|
+
return disposers;
|
|
26775
28178
|
}
|
|
26776
28179
|
notifyChange({ origin, loading, error }) {
|
|
26777
28180
|
var _a, _b;
|
|
@@ -26824,6 +28227,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26824
28227
|
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
28228
|
}
|
|
26826
28229
|
}
|
|
28230
|
+
if (this.query.excludeBlockUserComments) {
|
|
28231
|
+
comments = filterCommentsByBlockUsers(comments);
|
|
28232
|
+
}
|
|
26827
28233
|
switch (this.query.sortBy) {
|
|
26828
28234
|
case 'firstCreated':
|
|
26829
28235
|
comments = comments.sort(sortByFirstCreated);
|
|
@@ -27909,13 +29315,218 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
27909
29315
|
};
|
|
27910
29316
|
/* end_public_function */
|
|
27911
29317
|
|
|
29318
|
+
/**
|
|
29319
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
29320
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
29321
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
29322
|
+
*
|
|
29323
|
+
* @category Errors
|
|
29324
|
+
*/
|
|
29325
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
29326
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
29327
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
29328
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
29329
|
+
}
|
|
29330
|
+
}
|
|
29331
|
+
|
|
29332
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
29333
|
+
constructor(query) {
|
|
29334
|
+
super(query);
|
|
29335
|
+
this.checkedDisk = false;
|
|
29336
|
+
this.cursor = CursorController.current();
|
|
29337
|
+
}
|
|
29338
|
+
async getRequest(_queryParams, token) {
|
|
29339
|
+
let effectiveToken = token;
|
|
29340
|
+
if (!effectiveToken && !this.checkedDisk && this.cursor) {
|
|
29341
|
+
this.checkedDisk = true;
|
|
29342
|
+
const stored = await this.cursor.get();
|
|
29343
|
+
if (stored && !CursorController.isExpired(stored.expiredAt)) {
|
|
29344
|
+
effectiveToken = stored.cursor;
|
|
29345
|
+
}
|
|
29346
|
+
else if (stored) {
|
|
29347
|
+
await this.cursor.clear();
|
|
29348
|
+
}
|
|
29349
|
+
}
|
|
29350
|
+
const options = {
|
|
29351
|
+
limit: COLLECTION_DEFAULT_PAGINATION_SIZE,
|
|
29352
|
+
};
|
|
29353
|
+
if (effectiveToken)
|
|
29354
|
+
options.token = effectiveToken;
|
|
29355
|
+
let queryResponse;
|
|
29356
|
+
try {
|
|
29357
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options } }));
|
|
29358
|
+
}
|
|
29359
|
+
catch (error) {
|
|
29360
|
+
if (error instanceof ASCApiError && error.code === 400300 /* Amity.ServerError.FORBIDDEN */) {
|
|
29361
|
+
throw new AmityForYouFeedDisabledError();
|
|
29362
|
+
}
|
|
29363
|
+
const recoverable = error instanceof ASCApiError && error.code === 400322 /* Amity.ServerError.FEED_SNAPSHOT_EXPIRED */;
|
|
29364
|
+
if (recoverable && effectiveToken !== undefined) {
|
|
29365
|
+
if (this.cursor)
|
|
29366
|
+
await this.cursor.clear();
|
|
29367
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } } }));
|
|
29368
|
+
}
|
|
29369
|
+
else {
|
|
29370
|
+
throw error;
|
|
29371
|
+
}
|
|
29372
|
+
}
|
|
29373
|
+
await this.persistCursor(queryResponse);
|
|
29374
|
+
return queryResponse;
|
|
29375
|
+
}
|
|
29376
|
+
async persistCursor(response) {
|
|
29377
|
+
var _a, _b;
|
|
29378
|
+
if (!this.cursor)
|
|
29379
|
+
return;
|
|
29380
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
29381
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
29382
|
+
if (!cursor || !expiredAtIso)
|
|
29383
|
+
return;
|
|
29384
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
29385
|
+
if (Number.isNaN(expiredAt))
|
|
29386
|
+
return;
|
|
29387
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
29388
|
+
}
|
|
29389
|
+
}
|
|
29390
|
+
|
|
29391
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
29392
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
29393
|
+
super(query, cacheKey);
|
|
29394
|
+
this.notifyChange = notifyChange;
|
|
29395
|
+
this.preparePayload = preparePayload;
|
|
29396
|
+
}
|
|
29397
|
+
async saveToMainDB(response) {
|
|
29398
|
+
const processedPayload = await this.preparePayload(response);
|
|
29399
|
+
const client = getActiveClient();
|
|
29400
|
+
const cachedAt = client.cache && Date.now();
|
|
29401
|
+
if (client.cache)
|
|
29402
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
29403
|
+
}
|
|
29404
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
29405
|
+
var _a, _b;
|
|
29406
|
+
if (refresh) {
|
|
29407
|
+
pushToCache(this.cacheKey, {
|
|
29408
|
+
data: response.posts.map(getResolver('post')),
|
|
29409
|
+
});
|
|
29410
|
+
}
|
|
29411
|
+
else {
|
|
29412
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29413
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
29414
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
29415
|
+
}
|
|
29416
|
+
}
|
|
29417
|
+
reactor(action) {
|
|
29418
|
+
return (post) => {
|
|
29419
|
+
var _a;
|
|
29420
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29421
|
+
if (!collection)
|
|
29422
|
+
return;
|
|
29423
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
29424
|
+
return;
|
|
29425
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
29426
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
29427
|
+
}
|
|
29428
|
+
pushToCache(this.cacheKey, collection);
|
|
29429
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
29430
|
+
};
|
|
29431
|
+
}
|
|
29432
|
+
subscribeRTE(createSubscriber) {
|
|
29433
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
29434
|
+
}
|
|
29435
|
+
}
|
|
29436
|
+
|
|
29437
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
29438
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
29439
|
+
constructor(callback) {
|
|
29440
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
29441
|
+
const query = {};
|
|
29442
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
29443
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
29444
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
29445
|
+
this.callback = callback.bind(this);
|
|
29446
|
+
this.loadPage({ initial: true });
|
|
29447
|
+
}
|
|
29448
|
+
setup() {
|
|
29449
|
+
var _a;
|
|
29450
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29451
|
+
if (!collection)
|
|
29452
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
29453
|
+
}
|
|
29454
|
+
async persistModel(payload) {
|
|
29455
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
29456
|
+
}
|
|
29457
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
29458
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
29459
|
+
}
|
|
29460
|
+
startSubscription() {
|
|
29461
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
29462
|
+
}
|
|
29463
|
+
notifyChange({ origin, loading, error }) {
|
|
29464
|
+
var _a, _b;
|
|
29465
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
29466
|
+
if (!collection)
|
|
29467
|
+
return;
|
|
29468
|
+
const data = ((_b = collection.data
|
|
29469
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
29470
|
+
.filter(isNonNullable)
|
|
29471
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
29472
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
29473
|
+
return;
|
|
29474
|
+
this.callback({
|
|
29475
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
29476
|
+
data,
|
|
29477
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
29478
|
+
loading,
|
|
29479
|
+
error,
|
|
29480
|
+
});
|
|
29481
|
+
}
|
|
29482
|
+
}
|
|
29483
|
+
|
|
29484
|
+
/* begin_public_function
|
|
29485
|
+
id: feed.query.for_you_feed
|
|
29486
|
+
*/
|
|
29487
|
+
/**
|
|
29488
|
+
* ```js
|
|
29489
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
29490
|
+
*
|
|
29491
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
29492
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
29493
|
+
* })
|
|
29494
|
+
* ```
|
|
29495
|
+
*
|
|
29496
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
29497
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
29498
|
+
*
|
|
29499
|
+
* @param callback the function to call when new data is available
|
|
29500
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
29501
|
+
*
|
|
29502
|
+
* @category Posts Live Collection
|
|
29503
|
+
*/
|
|
29504
|
+
const getForYouFeed = (callback) => {
|
|
29505
|
+
const { log, cache } = getActiveClient();
|
|
29506
|
+
if (!cache)
|
|
29507
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
29508
|
+
const timestamp = Date.now();
|
|
29509
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
29510
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
29511
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
29512
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
29513
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
29514
|
+
return () => {
|
|
29515
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
29516
|
+
disposers.forEach(fn => fn());
|
|
29517
|
+
};
|
|
29518
|
+
};
|
|
29519
|
+
/* end_public_function */
|
|
29520
|
+
|
|
27912
29521
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
27913
29522
|
__proto__: null,
|
|
27914
29523
|
queryGlobalFeed: queryGlobalFeed,
|
|
27915
29524
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
27916
29525
|
getGlobalFeed: getGlobalFeed,
|
|
27917
29526
|
getUserFeed: getUserFeed,
|
|
27918
|
-
getCommunityFeed: getCommunityFeed
|
|
29527
|
+
getCommunityFeed: getCommunityFeed,
|
|
29528
|
+
getForYouFeed: getForYouFeed,
|
|
29529
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
27919
29530
|
});
|
|
27920
29531
|
|
|
27921
29532
|
/* begin_public_function
|
|
@@ -28782,29 +30393,6 @@ const getPost = (postId, callback) => {
|
|
|
28782
30393
|
};
|
|
28783
30394
|
/* end_public_function */
|
|
28784
30395
|
|
|
28785
|
-
class PostPaginationController extends PaginationController {
|
|
28786
|
-
async getRequest(queryParams, token) {
|
|
28787
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost, untilAt } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost", "untilAt"]);
|
|
28788
|
-
const { dataTypes } = params;
|
|
28789
|
-
const baseOptions = {
|
|
28790
|
-
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
28791
|
-
};
|
|
28792
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
28793
|
-
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
28794
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
28795
|
-
/*
|
|
28796
|
-
* when creating post like image, file, video BE will create 2 posts
|
|
28797
|
-
* 1. parent post to store text with dataType=text
|
|
28798
|
-
* 2. child post to store dataTypes post data
|
|
28799
|
-
*
|
|
28800
|
-
* By default, BE queries only parent post
|
|
28801
|
-
*/
|
|
28802
|
-
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
28803
|
-
});
|
|
28804
|
-
return queryResponse;
|
|
28805
|
-
}
|
|
28806
|
-
}
|
|
28807
|
-
|
|
28808
30396
|
class PostQueryStreamController extends QueryStreamController {
|
|
28809
30397
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
28810
30398
|
super(query, cacheKey);
|
|
@@ -28900,6 +30488,29 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
28900
30488
|
}
|
|
28901
30489
|
}
|
|
28902
30490
|
|
|
30491
|
+
class PostPaginationController extends PaginationController {
|
|
30492
|
+
async getRequest(queryParams, token) {
|
|
30493
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost, untilAt } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost", "untilAt"]);
|
|
30494
|
+
const { dataTypes } = params;
|
|
30495
|
+
const baseOptions = {
|
|
30496
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
30497
|
+
};
|
|
30498
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
30499
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
30500
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
30501
|
+
/*
|
|
30502
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
30503
|
+
* 1. parent post to store text with dataType=text
|
|
30504
|
+
* 2. child post to store dataTypes post data
|
|
30505
|
+
*
|
|
30506
|
+
* By default, BE queries only parent post
|
|
30507
|
+
*/
|
|
30508
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
30509
|
+
});
|
|
30510
|
+
return queryResponse;
|
|
30511
|
+
}
|
|
30512
|
+
}
|
|
30513
|
+
|
|
28903
30514
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
28904
30515
|
constructor(query, callback) {
|
|
28905
30516
|
const queryStreamId = hash__default["default"](query);
|
|
@@ -28928,7 +30539,12 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28928
30539
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28929
30540
|
}
|
|
28930
30541
|
startSubscription() {
|
|
28931
|
-
|
|
30542
|
+
const disposers = this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
30543
|
+
if (this.query.excludeBlockUserPosts) {
|
|
30544
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
30545
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
30546
|
+
}
|
|
30547
|
+
return disposers;
|
|
28932
30548
|
}
|
|
28933
30549
|
notifyChange({ origin, loading, error }) {
|
|
28934
30550
|
var _a, _b;
|
|
@@ -28974,6 +30590,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
28974
30590
|
const sortBy = this.query.sortBy || 'lastCreated';
|
|
28975
30591
|
posts = posts.filter(post => !exceedsUntilAtBoundary(post.createdAt, validatedUntilAt, sortBy));
|
|
28976
30592
|
}
|
|
30593
|
+
if (this.query.excludeBlockUserPosts) {
|
|
30594
|
+
posts = filterPostsByBlockUsers(posts);
|
|
30595
|
+
}
|
|
28977
30596
|
switch (this.query.sortBy) {
|
|
28978
30597
|
case 'firstCreated':
|
|
28979
30598
|
posts = posts.sort(sortByFirstCreated);
|
|
@@ -35696,6 +37315,9 @@ exports.filterByPropIntersection = filterByPropIntersection;
|
|
|
35696
37315
|
exports.filterBySearchTerm = filterBySearchTerm;
|
|
35697
37316
|
exports.filterByStringComparePartially = filterByStringComparePartially;
|
|
35698
37317
|
exports.filterByUntilAt = filterByUntilAt;
|
|
37318
|
+
exports.filterCommentsByBlockUsers = filterCommentsByBlockUsers;
|
|
37319
|
+
exports.filterPostsByBlockUsers = filterPostsByBlockUsers;
|
|
37320
|
+
exports.getBlockUsersId = getBlockUsersId;
|
|
35699
37321
|
exports.getChannelTopic = getChannelTopic;
|
|
35700
37322
|
exports.getCommentTopic = getCommentTopic;
|
|
35701
37323
|
exports.getCommunityStoriesTopic = getCommunityStoriesTopic;
|
|
@@ -35707,6 +37329,7 @@ exports.getMarkerUserFeedTopic = getMarkerUserFeedTopic;
|
|
|
35707
37329
|
exports.getMessageTopic = getMessageTopic;
|
|
35708
37330
|
exports.getMyFollowersTopic = getMyFollowersTopic;
|
|
35709
37331
|
exports.getMyFollowingsTopic = getMyFollowingsTopic;
|
|
37332
|
+
exports.getNetworkId = getNetworkId;
|
|
35710
37333
|
exports.getNetworkTopic = getNetworkTopic;
|
|
35711
37334
|
exports.getPostTopic = getPostTopic;
|
|
35712
37335
|
exports.getRole = getRole;
|