@amityco/ts-sdk 7.22.0 → 7.22.1-0aa9742a.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 +1817 -195
- package/dist/index.esm.js +1814 -196
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/updateChannelMessagePreviewCache.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +1 -0
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts +12 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts +10 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts +8 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts +2 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts +24 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts +2 -0
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts +2 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/setup.d.ts +6 -0
- package/dist/postRepository/tests/integration/setup.d.ts.map +1 -0
- package/dist/reactionRepository/internalApi/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/internalApi/removeReaction.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +1 -1
- package/dist/userRepository/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.esm.js
CHANGED
|
@@ -59,6 +59,13 @@ var FileAccessTypeEnum;
|
|
|
59
59
|
FileAccessTypeEnum["NETWORK"] = "network";
|
|
60
60
|
})(FileAccessTypeEnum || (FileAccessTypeEnum = {}));
|
|
61
61
|
|
|
62
|
+
var AmityChannelNotificationModeEnum;
|
|
63
|
+
(function (AmityChannelNotificationModeEnum) {
|
|
64
|
+
AmityChannelNotificationModeEnum["Default"] = "default";
|
|
65
|
+
AmityChannelNotificationModeEnum["Silent"] = "silent";
|
|
66
|
+
AmityChannelNotificationModeEnum["Subscribe"] = "subscribe";
|
|
67
|
+
})(AmityChannelNotificationModeEnum || (AmityChannelNotificationModeEnum = {}));
|
|
68
|
+
|
|
62
69
|
const CommunityPostSettings = Object.freeze({
|
|
63
70
|
ONLY_ADMIN_CAN_POST: 'ONLY_ADMIN_CAN_POST',
|
|
64
71
|
ADMIN_REVIEW_POST_REQUIRED: 'ADMIN_REVIEW_POST_REQUIRED',
|
|
@@ -234,12 +241,54 @@ var AmityEventOrderOption;
|
|
|
234
241
|
AmityEventOrderOption["Descending"] = "desc";
|
|
235
242
|
})(AmityEventOrderOption || (AmityEventOrderOption = {}));
|
|
236
243
|
|
|
244
|
+
var AmitySharableContentType;
|
|
245
|
+
(function (AmitySharableContentType) {
|
|
246
|
+
AmitySharableContentType["POST"] = "post";
|
|
247
|
+
AmitySharableContentType["COMMUNITY"] = "community";
|
|
248
|
+
AmitySharableContentType["USER"] = "user";
|
|
249
|
+
AmitySharableContentType["LIVESTREAM"] = "livestream";
|
|
250
|
+
AmitySharableContentType["EVENT"] = "event";
|
|
251
|
+
})(AmitySharableContentType || (AmitySharableContentType = {}));
|
|
252
|
+
|
|
237
253
|
var AnalyticsSourceTypeEnum;
|
|
238
254
|
(function (AnalyticsSourceTypeEnum) {
|
|
239
255
|
AnalyticsSourceTypeEnum["POST"] = "post";
|
|
240
256
|
AnalyticsSourceTypeEnum["ROOM"] = "room";
|
|
241
257
|
})(AnalyticsSourceTypeEnum || (AnalyticsSourceTypeEnum = {}));
|
|
242
258
|
|
|
259
|
+
var UserNotificationModuleNameEnum;
|
|
260
|
+
(function (UserNotificationModuleNameEnum) {
|
|
261
|
+
UserNotificationModuleNameEnum["CHAT"] = "chat";
|
|
262
|
+
UserNotificationModuleNameEnum["SOCIAL"] = "social";
|
|
263
|
+
UserNotificationModuleNameEnum["VIDEO_STREAMING"] = "video-streaming";
|
|
264
|
+
})(UserNotificationModuleNameEnum || (UserNotificationModuleNameEnum = {}));
|
|
265
|
+
var CommunityNotificationEventNameEnum;
|
|
266
|
+
(function (CommunityNotificationEventNameEnum) {
|
|
267
|
+
CommunityNotificationEventNameEnum["POST_CREATED"] = "post.created";
|
|
268
|
+
CommunityNotificationEventNameEnum["POST_REACTED"] = "post.reacted";
|
|
269
|
+
CommunityNotificationEventNameEnum["COMMENT_CREATED"] = "comment.created";
|
|
270
|
+
CommunityNotificationEventNameEnum["COMMENT_REPLIED"] = "comment.replied";
|
|
271
|
+
CommunityNotificationEventNameEnum["COMMENT_REACTED"] = "comment.reacted";
|
|
272
|
+
CommunityNotificationEventNameEnum["STORY_CREATED"] = "story.created";
|
|
273
|
+
CommunityNotificationEventNameEnum["STORY_REACTED"] = "story.reacted";
|
|
274
|
+
CommunityNotificationEventNameEnum["STORY_COMMENT_CREATED"] = "story-comment.created";
|
|
275
|
+
CommunityNotificationEventNameEnum["LIVESTREAM_START"] = "video-streaming.didStart";
|
|
276
|
+
})(CommunityNotificationEventNameEnum || (CommunityNotificationEventNameEnum = {}));
|
|
277
|
+
var NotificationSettingsLevelEnum;
|
|
278
|
+
(function (NotificationSettingsLevelEnum) {
|
|
279
|
+
NotificationSettingsLevelEnum["USER"] = "user";
|
|
280
|
+
NotificationSettingsLevelEnum["COMMUNITY"] = "community";
|
|
281
|
+
NotificationSettingsLevelEnum["CHANNEL"] = "channel";
|
|
282
|
+
})(NotificationSettingsLevelEnum || (NotificationSettingsLevelEnum = {}));
|
|
283
|
+
/**
|
|
284
|
+
* `NOT` variant is intentionally excluded from public API (internal server-side use only).
|
|
285
|
+
*/
|
|
286
|
+
var NotificationRolesFilterTypeEnum;
|
|
287
|
+
(function (NotificationRolesFilterTypeEnum) {
|
|
288
|
+
NotificationRolesFilterTypeEnum["ALL"] = "all";
|
|
289
|
+
NotificationRolesFilterTypeEnum["ONLY"] = "only";
|
|
290
|
+
})(NotificationRolesFilterTypeEnum || (NotificationRolesFilterTypeEnum = {}));
|
|
291
|
+
|
|
243
292
|
function getVersion() {
|
|
244
293
|
try {
|
|
245
294
|
// the string ''v7.22.0-esm'' should be replaced by actual value by @rollup/plugin-replace
|
|
@@ -252,6 +301,7 @@ function getVersion() {
|
|
|
252
301
|
const VERSION = getVersion();
|
|
253
302
|
|
|
254
303
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
304
|
+
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
255
305
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
256
306
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
257
307
|
const LIVE_OBJECT_ENABLE_CACHE_MESSAGE = 'For using Live Object feature you need to enable Cache!';
|
|
@@ -264,6 +314,9 @@ const DAY = 24 * HOUR;
|
|
|
264
314
|
const WEEK = 7 * DAY;
|
|
265
315
|
const YEAR = 365 * DAY;
|
|
266
316
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
317
|
+
const API_ENDPOINTS = {
|
|
318
|
+
forYouFeed: '/api/v1/feeds/for-you',
|
|
319
|
+
};
|
|
267
320
|
|
|
268
321
|
// cache constants
|
|
269
322
|
const CACHE_KEY_GET = 'get';
|
|
@@ -644,6 +697,95 @@ function createSnapshot(data, options) {
|
|
|
644
697
|
return Object.assign(Object.assign({}, options), { data });
|
|
645
698
|
}
|
|
646
699
|
|
|
700
|
+
/* eslint-disable max-classes-per-file */
|
|
701
|
+
/**
|
|
702
|
+
* Generic ASC error
|
|
703
|
+
* @category Errors
|
|
704
|
+
*/
|
|
705
|
+
class ASCError extends Error {
|
|
706
|
+
/**
|
|
707
|
+
* @param message A custom error message
|
|
708
|
+
* @param code A normalized error code
|
|
709
|
+
* @param level A normalized failure level descriptor
|
|
710
|
+
*/
|
|
711
|
+
constructor(message, code, level) {
|
|
712
|
+
super(`Amity SDK (${code}): ${message}`);
|
|
713
|
+
this.code = code;
|
|
714
|
+
this.level = level;
|
|
715
|
+
this.type = 'ASC';
|
|
716
|
+
this.timestamp = Date.now();
|
|
717
|
+
if (Error.captureStackTrace)
|
|
718
|
+
Error.captureStackTrace(this, ASCError);
|
|
719
|
+
}
|
|
720
|
+
}
|
|
721
|
+
/**
|
|
722
|
+
* API level error
|
|
723
|
+
* @category Errors
|
|
724
|
+
*/
|
|
725
|
+
class ASCApiError extends ASCError {
|
|
726
|
+
/**
|
|
727
|
+
* @param code A normalized error code
|
|
728
|
+
* @param level A normalized failure level descriptor
|
|
729
|
+
*/
|
|
730
|
+
// eslint-disable-next-line no-useless-constructor
|
|
731
|
+
constructor(message, code, level) {
|
|
732
|
+
super(message, code, level);
|
|
733
|
+
}
|
|
734
|
+
}
|
|
735
|
+
/**
|
|
736
|
+
* Unexpected error
|
|
737
|
+
* @category Errors
|
|
738
|
+
*/
|
|
739
|
+
class ASCUnknownError extends ASCError {
|
|
740
|
+
/**
|
|
741
|
+
* @param code A normalized error code
|
|
742
|
+
* @param level A normalized failure level descriptor
|
|
743
|
+
*/
|
|
744
|
+
constructor(code = 800000 /* Amity.ClientError.UNKNOWN_ERROR */, level = "fatal" /* Amity.ErrorLevel.FATAL */) {
|
|
745
|
+
super('Unexpected error', code, level);
|
|
746
|
+
}
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
749
|
+
* Network related error
|
|
750
|
+
* @category Errors
|
|
751
|
+
*/
|
|
752
|
+
class ASCConnectionError extends ASCError {
|
|
753
|
+
/**
|
|
754
|
+
* @param message A custom error message
|
|
755
|
+
*/
|
|
756
|
+
constructor(event, message = 'SDK client is having connection issues') {
|
|
757
|
+
super(`${message} (${event})`, event === 'disconnected'
|
|
758
|
+
? 800211 /* Amity.ClientError.DISCONNECTED */
|
|
759
|
+
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
760
|
+
this.event = event;
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
|
|
764
|
+
let activeClient = null;
|
|
765
|
+
/**
|
|
766
|
+
* Get the active client
|
|
767
|
+
*
|
|
768
|
+
* @returns the active client instance
|
|
769
|
+
*
|
|
770
|
+
* @hidden
|
|
771
|
+
*/
|
|
772
|
+
const getActiveClient = () => {
|
|
773
|
+
if (!activeClient) {
|
|
774
|
+
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
775
|
+
}
|
|
776
|
+
return activeClient;
|
|
777
|
+
};
|
|
778
|
+
/**
|
|
779
|
+
* Sets the active client
|
|
780
|
+
*
|
|
781
|
+
* @param client the client to assume as currently active client
|
|
782
|
+
*
|
|
783
|
+
* @hidden
|
|
784
|
+
*/
|
|
785
|
+
const setActiveClient = (client) => {
|
|
786
|
+
activeClient = client;
|
|
787
|
+
};
|
|
788
|
+
|
|
647
789
|
/** @hidden */
|
|
648
790
|
const idResolvers = {
|
|
649
791
|
user: ({ userId }) => userId,
|
|
@@ -652,6 +794,7 @@ const idResolvers = {
|
|
|
652
794
|
channel: ({ channelInternalId }) => channelInternalId,
|
|
653
795
|
subChannel: ({ subChannelId }) => subChannelId,
|
|
654
796
|
channelUsers: ({ channelId, userId }) => `${channelId}#${userId}`,
|
|
797
|
+
archivedChannel: ({ channelId }) => channelId,
|
|
655
798
|
message: ({ messageId, referenceId }) => referenceId !== null && referenceId !== void 0 ? referenceId : messageId,
|
|
656
799
|
messagePreviewChannel: ({ channelId }) => `${channelId}`,
|
|
657
800
|
messagePreviewSubChannel: ({ subChannelId }) => `${subChannelId}`,
|
|
@@ -693,6 +836,7 @@ const idResolvers = {
|
|
|
693
836
|
event: ({ eventId }) => eventId,
|
|
694
837
|
eventResponse: ({ userId }) => userId,
|
|
695
838
|
product: ({ productId }) => productId,
|
|
839
|
+
feedMetadata: ({ postId }) => postId,
|
|
696
840
|
};
|
|
697
841
|
/**
|
|
698
842
|
* Retrieve the id resolver matching a domain name
|
|
@@ -715,6 +859,7 @@ const PAYLOAD2MODEL = {
|
|
|
715
859
|
channels: 'channel',
|
|
716
860
|
messageFeeds: 'subChannel',
|
|
717
861
|
channelUsers: 'channelUsers',
|
|
862
|
+
archives: 'archivedChannel',
|
|
718
863
|
messages: 'message',
|
|
719
864
|
messagePreviewChannel: 'messagePreviewChannel',
|
|
720
865
|
messagePreviewSubChannel: 'messagePreviewSubChannel',
|
|
@@ -753,6 +898,7 @@ const PAYLOAD2MODEL = {
|
|
|
753
898
|
viewers: 'viewer',
|
|
754
899
|
eventResponses: 'eventResponse',
|
|
755
900
|
products: 'product',
|
|
901
|
+
feedMetadata: 'feedMetadata',
|
|
756
902
|
};
|
|
757
903
|
/** hidden */
|
|
758
904
|
const isOutdated = (prevData, nextData) => {
|
|
@@ -767,95 +913,6 @@ function getFutureDate(date = new Date().toISOString()) {
|
|
|
767
913
|
return new Date(new Date(date).getTime() + 1).toISOString();
|
|
768
914
|
}
|
|
769
915
|
|
|
770
|
-
/* eslint-disable max-classes-per-file */
|
|
771
|
-
/**
|
|
772
|
-
* Generic ASC error
|
|
773
|
-
* @category Errors
|
|
774
|
-
*/
|
|
775
|
-
class ASCError extends Error {
|
|
776
|
-
/**
|
|
777
|
-
* @param message A custom error message
|
|
778
|
-
* @param code A normalized error code
|
|
779
|
-
* @param level A normalized failure level descriptor
|
|
780
|
-
*/
|
|
781
|
-
constructor(message, code, level) {
|
|
782
|
-
super(`Amity SDK (${code}): ${message}`);
|
|
783
|
-
this.code = code;
|
|
784
|
-
this.level = level;
|
|
785
|
-
this.type = 'ASC';
|
|
786
|
-
this.timestamp = Date.now();
|
|
787
|
-
if (Error.captureStackTrace)
|
|
788
|
-
Error.captureStackTrace(this, ASCError);
|
|
789
|
-
}
|
|
790
|
-
}
|
|
791
|
-
/**
|
|
792
|
-
* API level error
|
|
793
|
-
* @category Errors
|
|
794
|
-
*/
|
|
795
|
-
class ASCApiError extends ASCError {
|
|
796
|
-
/**
|
|
797
|
-
* @param code A normalized error code
|
|
798
|
-
* @param level A normalized failure level descriptor
|
|
799
|
-
*/
|
|
800
|
-
// eslint-disable-next-line no-useless-constructor
|
|
801
|
-
constructor(message, code, level) {
|
|
802
|
-
super(message, code, level);
|
|
803
|
-
}
|
|
804
|
-
}
|
|
805
|
-
/**
|
|
806
|
-
* Unexpected error
|
|
807
|
-
* @category Errors
|
|
808
|
-
*/
|
|
809
|
-
class ASCUnknownError extends ASCError {
|
|
810
|
-
/**
|
|
811
|
-
* @param code A normalized error code
|
|
812
|
-
* @param level A normalized failure level descriptor
|
|
813
|
-
*/
|
|
814
|
-
constructor(code = 800000 /* Amity.ClientError.UNKNOWN_ERROR */, level = "fatal" /* Amity.ErrorLevel.FATAL */) {
|
|
815
|
-
super('Unexpected error', code, level);
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
/**
|
|
819
|
-
* Network related error
|
|
820
|
-
* @category Errors
|
|
821
|
-
*/
|
|
822
|
-
class ASCConnectionError extends ASCError {
|
|
823
|
-
/**
|
|
824
|
-
* @param message A custom error message
|
|
825
|
-
*/
|
|
826
|
-
constructor(event, message = 'SDK client is having connection issues') {
|
|
827
|
-
super(`${message} (${event})`, event === 'disconnected'
|
|
828
|
-
? 800211 /* Amity.ClientError.DISCONNECTED */
|
|
829
|
-
: 800210 /* Amity.ClientError.CONNECTION_ERROR */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
830
|
-
this.event = event;
|
|
831
|
-
}
|
|
832
|
-
}
|
|
833
|
-
|
|
834
|
-
let activeClient = null;
|
|
835
|
-
/**
|
|
836
|
-
* Get the active client
|
|
837
|
-
*
|
|
838
|
-
* @returns the active client instance
|
|
839
|
-
*
|
|
840
|
-
* @hidden
|
|
841
|
-
*/
|
|
842
|
-
const getActiveClient = () => {
|
|
843
|
-
if (!activeClient) {
|
|
844
|
-
throw new ASCError('There is no active client', 800000 /* Amity.ClientError.UNKNOWN_ERROR */, "fatal" /* Amity.ErrorLevel.FATAL */);
|
|
845
|
-
}
|
|
846
|
-
return activeClient;
|
|
847
|
-
};
|
|
848
|
-
/**
|
|
849
|
-
* Sets the active client
|
|
850
|
-
*
|
|
851
|
-
* @param client the client to assume as currently active client
|
|
852
|
-
*
|
|
853
|
-
* @hidden
|
|
854
|
-
*/
|
|
855
|
-
const setActiveClient = (client) => {
|
|
856
|
-
activeClient = client;
|
|
857
|
-
};
|
|
858
|
-
|
|
859
916
|
/**
|
|
860
917
|
* ```js
|
|
861
918
|
* import { enableCache } from '@amityco/ts-sdk'
|
|
@@ -1363,6 +1420,65 @@ const filterBySearchTerm = (collection, searchTerm) => {
|
|
|
1363
1420
|
return m.user && ((_a = m.user.displayName) === null || _a === void 0 ? void 0 : _a.match(containsMatcher));
|
|
1364
1421
|
});
|
|
1365
1422
|
};
|
|
1423
|
+
/**
|
|
1424
|
+
* The ids of users in a block relationship with the current user — in BOTH
|
|
1425
|
+
* directions — derived synchronously from the local follow cache. For every
|
|
1426
|
+
* `status === 'blocked'` row that involves the current user, the OTHER party
|
|
1427
|
+
* is collected: `from === me` (users I blocked, outgoing) contributes `to`;
|
|
1428
|
+
* `to === me` (users who blocked me, incoming) contributes `from`.
|
|
1429
|
+
*
|
|
1430
|
+
* @returns a set of block-related user ids (both directions)
|
|
1431
|
+
*
|
|
1432
|
+
* @hidden
|
|
1433
|
+
*/
|
|
1434
|
+
const getBlockUsersId = () => {
|
|
1435
|
+
var _a;
|
|
1436
|
+
const { userId } = getActiveClient();
|
|
1437
|
+
const ids = new Set();
|
|
1438
|
+
((_a = queryCache(['follow', 'get'])) !== null && _a !== void 0 ? _a : [])
|
|
1439
|
+
.map(entry => entry.data)
|
|
1440
|
+
.filter(follow => (follow === null || follow === void 0 ? void 0 : follow.status) === 'blocked' && (follow.from === userId || follow.to === userId))
|
|
1441
|
+
.forEach(follow => {
|
|
1442
|
+
ids.add(follow.from === userId ? follow.to : follow.from);
|
|
1443
|
+
});
|
|
1444
|
+
return ids;
|
|
1445
|
+
};
|
|
1446
|
+
/**
|
|
1447
|
+
* Filter out posts whose author or any mentionee is in a block relationship
|
|
1448
|
+
* with the current user, in either direction (see {@link getBlockUsersId}).
|
|
1449
|
+
*
|
|
1450
|
+
* @param collection the post collection to filter
|
|
1451
|
+
* @returns a filtered collection excluding posts involving block-related users
|
|
1452
|
+
*
|
|
1453
|
+
* @hidden
|
|
1454
|
+
*/
|
|
1455
|
+
const filterPostsByBlockUsers = (collection) => {
|
|
1456
|
+
const blockUsersId = getBlockUsersId();
|
|
1457
|
+
if (blockUsersId.size === 0)
|
|
1458
|
+
return collection;
|
|
1459
|
+
return collection.filter(post => {
|
|
1460
|
+
var _a, _b;
|
|
1461
|
+
if (blockUsersId.has(post.postedUserId))
|
|
1462
|
+
return false;
|
|
1463
|
+
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 : [];
|
|
1464
|
+
return !mentionedUserIds.some(id => blockUsersId.has(id));
|
|
1465
|
+
});
|
|
1466
|
+
};
|
|
1467
|
+
/**
|
|
1468
|
+
* Filter out comments whose creator is in a block relationship with the
|
|
1469
|
+
* current user, in either direction (see {@link getBlockUsersId}).
|
|
1470
|
+
*
|
|
1471
|
+
* @param collection the comment collection to filter
|
|
1472
|
+
* @returns a filtered collection excluding comments from block-related users
|
|
1473
|
+
*
|
|
1474
|
+
* @hidden
|
|
1475
|
+
*/
|
|
1476
|
+
const filterCommentsByBlockUsers = (collection) => {
|
|
1477
|
+
const blockUsersId = getBlockUsersId();
|
|
1478
|
+
if (blockUsersId.size === 0)
|
|
1479
|
+
return collection;
|
|
1480
|
+
return collection.filter(comment => !blockUsersId.has(comment.userId));
|
|
1481
|
+
};
|
|
1366
1482
|
|
|
1367
1483
|
// Note:
|
|
1368
1484
|
// this file should contain a suite of sorting utilities to help the
|
|
@@ -1833,13 +1949,13 @@ class NetworkActivitiesWatcher {
|
|
|
1833
1949
|
this._listener.clear();
|
|
1834
1950
|
}
|
|
1835
1951
|
}
|
|
1836
|
-
let instance$
|
|
1952
|
+
let instance$a;
|
|
1837
1953
|
var NetworkActivitiesWatcher$1 = {
|
|
1838
1954
|
getInstance: () => {
|
|
1839
|
-
if (!instance$
|
|
1840
|
-
instance$
|
|
1955
|
+
if (!instance$a) {
|
|
1956
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
1841
1957
|
}
|
|
1842
|
-
return instance$
|
|
1958
|
+
return instance$a;
|
|
1843
1959
|
},
|
|
1844
1960
|
};
|
|
1845
1961
|
|
|
@@ -20678,18 +20794,161 @@ var mqtt$1 = {exports: {}};
|
|
|
20678
20794
|
|
|
20679
20795
|
var mqtt = /*@__PURE__*/getDefaultExportFromCjs(mqtt$1.exports);
|
|
20680
20796
|
|
|
20797
|
+
class SessionWatcher {
|
|
20798
|
+
constructor() {
|
|
20799
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
20800
|
+
this._listener = new Map();
|
|
20801
|
+
}
|
|
20802
|
+
onSessionStateChange(callback) {
|
|
20803
|
+
this._listener.set(callback, callback);
|
|
20804
|
+
return () => {
|
|
20805
|
+
this._listener.delete(callback);
|
|
20806
|
+
};
|
|
20807
|
+
}
|
|
20808
|
+
setSessionState(state, reason) {
|
|
20809
|
+
if (this._sessionState === state)
|
|
20810
|
+
return;
|
|
20811
|
+
this._sessionState = state;
|
|
20812
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
20813
|
+
}
|
|
20814
|
+
destroy() {
|
|
20815
|
+
this._listener.clear();
|
|
20816
|
+
}
|
|
20817
|
+
}
|
|
20818
|
+
let instance$9;
|
|
20819
|
+
var SessionWatcher$1 = {
|
|
20820
|
+
getInstance: () => {
|
|
20821
|
+
if (!instance$9) {
|
|
20822
|
+
instance$9 = new SessionWatcher();
|
|
20823
|
+
}
|
|
20824
|
+
return instance$9;
|
|
20825
|
+
},
|
|
20826
|
+
};
|
|
20827
|
+
|
|
20828
|
+
/**
|
|
20829
|
+
* ```js
|
|
20830
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
20831
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
20832
|
+
* // ...
|
|
20833
|
+
* })
|
|
20834
|
+
* ```
|
|
20835
|
+
*
|
|
20836
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
20837
|
+
*
|
|
20838
|
+
* @param callback The function to call when the event was fired
|
|
20839
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20840
|
+
*
|
|
20841
|
+
* @category Client Events
|
|
20842
|
+
*/
|
|
20843
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
20844
|
+
|
|
20845
|
+
/** Feature-grouped real-time handles; all default-on, toggleable per handle. */
|
|
20846
|
+
var AutoSubscription;
|
|
20847
|
+
(function (AutoSubscription) {
|
|
20848
|
+
/** SMART_CHANNEL + SMART_MESSAGE + SMART_MESSAGE_FEED — chat "smart" real-time. */
|
|
20849
|
+
AutoSubscription["CHAT"] = "chat";
|
|
20850
|
+
/** Network-wide events (e.g. global ban). */
|
|
20851
|
+
AutoSubscription["NETWORK"] = "network";
|
|
20852
|
+
/** Livestream state events. */
|
|
20853
|
+
AutoSubscription["LIVESTREAM"] = "livestream";
|
|
20854
|
+
/** Both membership wildcards (followers + followings) — block real-time. */
|
|
20855
|
+
AutoSubscription["BLOCK"] = "block";
|
|
20856
|
+
})(AutoSubscription || (AutoSubscription = {}));
|
|
20857
|
+
const TOPICS = {
|
|
20858
|
+
[AutoSubscription.NETWORK]: [getNetworkTopic],
|
|
20859
|
+
[AutoSubscription.CHAT]: [
|
|
20860
|
+
getSmartFeedChannelTopic,
|
|
20861
|
+
getSmartFeedSubChannelTopic,
|
|
20862
|
+
getSmartFeedMessageTopic,
|
|
20863
|
+
],
|
|
20864
|
+
[AutoSubscription.LIVESTREAM]: [getLiveStreamTopic],
|
|
20865
|
+
[AutoSubscription.BLOCK]: [getMyFollowersTopic, getMyFollowingsTopic],
|
|
20866
|
+
};
|
|
20867
|
+
const DEFAULT_TOPICS = [
|
|
20868
|
+
AutoSubscription.CHAT,
|
|
20869
|
+
AutoSubscription.NETWORK,
|
|
20870
|
+
AutoSubscription.LIVESTREAM,
|
|
20871
|
+
AutoSubscription.BLOCK,
|
|
20872
|
+
];
|
|
20873
|
+
const ALL_FEATURES = Object.values(AutoSubscription);
|
|
20874
|
+
/** Ref-counted, reconnect-resilient registry of the managed auto-subscriptions. */
|
|
20875
|
+
class AutoSubscriptionManager {
|
|
20876
|
+
constructor() {
|
|
20877
|
+
this.refCountByFeature = new Map();
|
|
20878
|
+
this.disposers = new Map();
|
|
20879
|
+
this.seed();
|
|
20880
|
+
}
|
|
20881
|
+
seed() {
|
|
20882
|
+
this.refCountByFeature.clear();
|
|
20883
|
+
DEFAULT_TOPICS.forEach(feature => this.refCountByFeature.set(feature, 1));
|
|
20884
|
+
}
|
|
20885
|
+
isActive(feature) {
|
|
20886
|
+
var _a;
|
|
20887
|
+
return ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
20888
|
+
}
|
|
20889
|
+
subscribeTopics(feature) {
|
|
20890
|
+
this.unsubscribeTopics(feature);
|
|
20891
|
+
this.disposers.set(feature, TOPICS[feature].map(buildTopic => subscribeTopic(buildTopic())));
|
|
20892
|
+
}
|
|
20893
|
+
unsubscribeTopics(feature) {
|
|
20894
|
+
var _a;
|
|
20895
|
+
((_a = this.disposers.get(feature)) !== null && _a !== void 0 ? _a : []).forEach(dispose => dispose());
|
|
20896
|
+
this.disposers.delete(feature);
|
|
20897
|
+
}
|
|
20898
|
+
/** Subscribe every enabled handle's topics, converging the broker to the registry. Called on each (re)connect. */
|
|
20899
|
+
initialize() {
|
|
20900
|
+
ALL_FEATURES.forEach(feature => {
|
|
20901
|
+
if (this.isActive(feature))
|
|
20902
|
+
this.subscribeTopics(feature);
|
|
20903
|
+
});
|
|
20904
|
+
}
|
|
20905
|
+
subscribe(feature) {
|
|
20906
|
+
var _a;
|
|
20907
|
+
const next = ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
20908
|
+
this.refCountByFeature.set(feature, next);
|
|
20909
|
+
if (next === 1)
|
|
20910
|
+
this.subscribeTopics(feature);
|
|
20911
|
+
}
|
|
20912
|
+
unsubscribe(feature) {
|
|
20913
|
+
var _a;
|
|
20914
|
+
const next = Math.max(0, ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
20915
|
+
this.refCountByFeature.set(feature, next);
|
|
20916
|
+
if (next === 0)
|
|
20917
|
+
this.unsubscribeTopics(feature);
|
|
20918
|
+
}
|
|
20919
|
+
subscriptions() {
|
|
20920
|
+
return ALL_FEATURES.map(feature => ({
|
|
20921
|
+
feature,
|
|
20922
|
+
isActive: this.isActive(feature),
|
|
20923
|
+
isSystem: true,
|
|
20924
|
+
topicCount: TOPICS[feature].length,
|
|
20925
|
+
}));
|
|
20926
|
+
}
|
|
20927
|
+
reset() {
|
|
20928
|
+
ALL_FEATURES.forEach(feature => this.unsubscribeTopics(feature));
|
|
20929
|
+
this.disposers.clear();
|
|
20930
|
+
this.seed();
|
|
20931
|
+
}
|
|
20932
|
+
}
|
|
20933
|
+
let instance$8 = null;
|
|
20934
|
+
const getAutoSubscriptionManager = () => {
|
|
20935
|
+
if (!instance$8)
|
|
20936
|
+
instance$8 = new AutoSubscriptionManager();
|
|
20937
|
+
return instance$8;
|
|
20938
|
+
};
|
|
20939
|
+
/** Resets the registry to its default baseline when the session ends. */
|
|
20940
|
+
const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
|
|
20941
|
+
if (state !== "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
20942
|
+
getAutoSubscriptionManager().reset();
|
|
20943
|
+
});
|
|
20944
|
+
|
|
20945
|
+
/**
|
|
20946
|
+
* (Re)subscribes the managed auto-subscription registry on every (re)connect.
|
|
20947
|
+
* The hardcoded topic list was promoted to the toggleable, ref-counted registry
|
|
20948
|
+
* in {@link getAutoSubscriptionManager} — see `client.manageAutoSubscriptions`.
|
|
20949
|
+
*/
|
|
20681
20950
|
const subscribeGlobalTopic = () => {
|
|
20682
|
-
|
|
20683
|
-
subscribeTopic(getNetworkTopic()),
|
|
20684
|
-
subscribeTopic(getSmartFeedChannelTopic()),
|
|
20685
|
-
subscribeTopic(getSmartFeedSubChannelTopic()),
|
|
20686
|
-
subscribeTopic(getSmartFeedMessageTopic()),
|
|
20687
|
-
// subscribing to user topic is necessary to handle ban event
|
|
20688
|
-
subscribeTopic(getUserTopic(getActiveUser())),
|
|
20689
|
-
subscribeTopic(getMarkerUserFeedTopic()),
|
|
20690
|
-
subscribeTopic(getLiveStreamTopic()),
|
|
20691
|
-
];
|
|
20692
|
-
return () => disposers.forEach(fn => fn());
|
|
20951
|
+
getAutoSubscriptionManager().initialize();
|
|
20693
20952
|
};
|
|
20694
20953
|
|
|
20695
20954
|
class OnMemoryStorage {
|
|
@@ -21225,8 +21484,12 @@ const getChannelMessagePreviewWithUser = (channel) => {
|
|
|
21225
21484
|
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
21226
21485
|
};
|
|
21227
21486
|
|
|
21487
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
21488
|
+
return new Date(dateString).getTime();
|
|
21489
|
+
};
|
|
21490
|
+
|
|
21228
21491
|
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
21229
|
-
var _a
|
|
21492
|
+
var _a;
|
|
21230
21493
|
const withMessageFeedInfo = (messagePreview) => {
|
|
21231
21494
|
var _a;
|
|
21232
21495
|
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
@@ -21248,10 +21511,26 @@ const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
|
21248
21511
|
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21249
21512
|
};
|
|
21250
21513
|
};
|
|
21251
|
-
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21514
|
+
// Skip server previews older than what's cached — the cache may carry a newer
|
|
21515
|
+
// preview written by handleMessageCreated from an MQTT message that the server
|
|
21516
|
+
// payload hasn't surfaced yet. Mirrors isLastestMessageOnChannel.
|
|
21517
|
+
const newPreviews = ((_a = rawPayload.messagePreviews) !== null && _a !== void 0 ? _a : [])
|
|
21518
|
+
.map(withMessageFeedInfo)
|
|
21519
|
+
.filter(preview => {
|
|
21520
|
+
var _a;
|
|
21521
|
+
const cached = (_a = pullFromCache([
|
|
21522
|
+
'messagePreviewChannel',
|
|
21523
|
+
'get',
|
|
21524
|
+
preview.channelId,
|
|
21525
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21526
|
+
if (!cached)
|
|
21527
|
+
return true;
|
|
21528
|
+
return (convertDateStringToTimestamp(cached.createdAt) <=
|
|
21529
|
+
convertDateStringToTimestamp(preview.createdAt));
|
|
21530
|
+
});
|
|
21531
|
+
if (newPreviews.length === 0)
|
|
21532
|
+
return;
|
|
21533
|
+
ingestInCache({ messagePreviewChannel: newPreviews });
|
|
21255
21534
|
};
|
|
21256
21535
|
|
|
21257
21536
|
const getSubChannelMessagePreview = (subChannelId) => {
|
|
@@ -21879,10 +22158,6 @@ getSubChannel$1.locally = (subChannelId) => {
|
|
|
21879
22158
|
};
|
|
21880
22159
|
};
|
|
21881
22160
|
|
|
21882
|
-
const convertDateStringToTimestamp = (dateString) => {
|
|
21883
|
-
return new Date(dateString).getTime();
|
|
21884
|
-
};
|
|
21885
|
-
|
|
21886
22161
|
const getMessagePreviewSetting$1 = async () => {
|
|
21887
22162
|
const client = getActiveClient();
|
|
21888
22163
|
return client.getMessagePreviewSetting(false);
|
|
@@ -22090,24 +22365,41 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
22090
22365
|
});
|
|
22091
22366
|
};
|
|
22092
22367
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
22368
|
+
var _a, _b;
|
|
22093
22369
|
const channelsUnread = [];
|
|
22094
22370
|
for (let i = 0; i < channels.length; i += 1) {
|
|
22095
22371
|
if (isUnreadCountSupport(channels[i])) {
|
|
22096
22372
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
22097
22373
|
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
22098
|
-
|
|
22374
|
+
// readToSegment, lastMentionedSegment and lastSegment are monotonically non-decreasing;
|
|
22375
|
+
// prefer cached values when ahead of the server so a refetch returning stale data cannot
|
|
22376
|
+
const cached = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22377
|
+
const lastSegment = Math.max((_b = cached === null || cached === void 0 ? void 0 : cached.lastSegment) !== null && _b !== void 0 ? _b : 0, channels[i].messageCount);
|
|
22099
22378
|
let readToSegment = null;
|
|
22100
22379
|
let lastMentionedSegment = null;
|
|
22380
|
+
let unreadCount = 0;
|
|
22101
22381
|
let isMentioned = false;
|
|
22102
22382
|
if (channelUser) {
|
|
22103
|
-
|
|
22104
|
-
|
|
22105
|
-
|
|
22106
|
-
|
|
22383
|
+
const serverRead = channelUser.readToSegment;
|
|
22384
|
+
const serverMention = channelUser.lastMentionedSegment;
|
|
22385
|
+
readToSegment =
|
|
22386
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.readToSegment) === 'number' &&
|
|
22387
|
+
(typeof serverRead !== 'number' || cached.readToSegment > serverRead)
|
|
22388
|
+
? cached.readToSegment
|
|
22389
|
+
: serverRead !== null && serverRead !== void 0 ? serverRead : null;
|
|
22390
|
+
lastMentionedSegment =
|
|
22391
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.lastMentionedSegment) === 'number' &&
|
|
22392
|
+
(typeof serverMention !== 'number' || cached.lastMentionedSegment > serverMention)
|
|
22393
|
+
? cached.lastMentionedSegment
|
|
22394
|
+
: serverMention !== null && serverMention !== void 0 ? serverMention : null;
|
|
22395
|
+
const readForCalc = readToSegment !== null && readToSegment !== void 0 ? readToSegment : 0;
|
|
22396
|
+
unreadCount = Math.max(lastSegment - readForCalc, 0);
|
|
22397
|
+
isMentioned =
|
|
22398
|
+
typeof lastMentionedSegment === 'number' && readForCalc < lastMentionedSegment;
|
|
22107
22399
|
}
|
|
22108
22400
|
const cacheChannelUnread = {
|
|
22109
22401
|
channelId: channels[i].channelId,
|
|
22110
|
-
lastSegment
|
|
22402
|
+
lastSegment,
|
|
22111
22403
|
readToSegment,
|
|
22112
22404
|
lastMentionedSegment,
|
|
22113
22405
|
unreadCount,
|
|
@@ -22117,6 +22409,8 @@ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
|
22117
22409
|
pushToCache(cacheKey, cacheChannelUnread);
|
|
22118
22410
|
channelsUnread.push(cacheChannelUnread);
|
|
22119
22411
|
}
|
|
22412
|
+
}
|
|
22413
|
+
if (channelsUnread.length > 0) {
|
|
22120
22414
|
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
22121
22415
|
}
|
|
22122
22416
|
};
|
|
@@ -22816,7 +23110,7 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
22816
23110
|
const client = getActiveClient();
|
|
22817
23111
|
const filter = async (payload) => {
|
|
22818
23112
|
const { channels, channelUsers } = payload;
|
|
22819
|
-
|
|
23113
|
+
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
22820
23114
|
};
|
|
22821
23115
|
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
|
|
22822
23116
|
}
|
|
@@ -22824,6 +23118,39 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
22824
23118
|
return () => dispose$1(callback);
|
|
22825
23119
|
};
|
|
22826
23120
|
|
|
23121
|
+
/**
|
|
23122
|
+
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
23123
|
+
*
|
|
23124
|
+
* @param callback The function to call when the event was fired
|
|
23125
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23126
|
+
*
|
|
23127
|
+
* @category Channel Events
|
|
23128
|
+
*/
|
|
23129
|
+
const onChannelArchived = (callback) => {
|
|
23130
|
+
const client = getActiveClient();
|
|
23131
|
+
const filter = async (payload) => {
|
|
23132
|
+
callback(payload);
|
|
23133
|
+
};
|
|
23134
|
+
return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
|
|
23135
|
+
};
|
|
23136
|
+
|
|
23137
|
+
/**
|
|
23138
|
+
* Fired when a previously archived {@link Amity.Channel} has been unarchived
|
|
23139
|
+
* by the active user.
|
|
23140
|
+
*
|
|
23141
|
+
* @param callback The function to call when the event was fired
|
|
23142
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23143
|
+
*
|
|
23144
|
+
* @category Channel Events
|
|
23145
|
+
*/
|
|
23146
|
+
const onChannelUnarchived = (callback) => {
|
|
23147
|
+
const client = getActiveClient();
|
|
23148
|
+
const filter = async (payload) => {
|
|
23149
|
+
callback(payload);
|
|
23150
|
+
};
|
|
23151
|
+
return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
|
|
23152
|
+
};
|
|
23153
|
+
|
|
22827
23154
|
const callbacks = [];
|
|
22828
23155
|
let mainDisposer = null;
|
|
22829
23156
|
const dispose = (cb) => {
|
|
@@ -22937,6 +23264,17 @@ const channelLinkedObject = (channel) => {
|
|
|
22937
23264
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
22938
23265
|
previewMembers,
|
|
22939
23266
|
myMembership: (callback) => getMyMembership(channel.channelId, callback),
|
|
23267
|
+
get avatar() {
|
|
23268
|
+
var _a;
|
|
23269
|
+
if (!channel.avatarFileId)
|
|
23270
|
+
return undefined;
|
|
23271
|
+
const avatar = (_a = pullFromCache([
|
|
23272
|
+
'file',
|
|
23273
|
+
'get',
|
|
23274
|
+
`${channel.avatarFileId}`,
|
|
23275
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23276
|
+
return avatar;
|
|
23277
|
+
},
|
|
22940
23278
|
});
|
|
22941
23279
|
};
|
|
22942
23280
|
|
|
@@ -23035,54 +23373,6 @@ getChannelByIds$1.locally = (channelIds) => {
|
|
|
23035
23373
|
};
|
|
23036
23374
|
};
|
|
23037
23375
|
|
|
23038
|
-
class SessionWatcher {
|
|
23039
|
-
constructor() {
|
|
23040
|
-
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
23041
|
-
this._listener = new Map();
|
|
23042
|
-
}
|
|
23043
|
-
onSessionStateChange(callback) {
|
|
23044
|
-
this._listener.set(callback, callback);
|
|
23045
|
-
return () => {
|
|
23046
|
-
this._listener.delete(callback);
|
|
23047
|
-
};
|
|
23048
|
-
}
|
|
23049
|
-
setSessionState(state, reason) {
|
|
23050
|
-
if (this._sessionState === state)
|
|
23051
|
-
return;
|
|
23052
|
-
this._sessionState = state;
|
|
23053
|
-
this._listener.forEach(cb => cb(state, reason));
|
|
23054
|
-
}
|
|
23055
|
-
destroy() {
|
|
23056
|
-
this._listener.clear();
|
|
23057
|
-
}
|
|
23058
|
-
}
|
|
23059
|
-
let instance$8;
|
|
23060
|
-
var SessionWatcher$1 = {
|
|
23061
|
-
getInstance: () => {
|
|
23062
|
-
if (!instance$8) {
|
|
23063
|
-
instance$8 = new SessionWatcher();
|
|
23064
|
-
}
|
|
23065
|
-
return instance$8;
|
|
23066
|
-
},
|
|
23067
|
-
};
|
|
23068
|
-
|
|
23069
|
-
/**
|
|
23070
|
-
* ```js
|
|
23071
|
-
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
23072
|
-
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
23073
|
-
* // ...
|
|
23074
|
-
* })
|
|
23075
|
-
* ```
|
|
23076
|
-
*
|
|
23077
|
-
* Fired when any {@link Amity.Client} has a session state change
|
|
23078
|
-
*
|
|
23079
|
-
* @param callback The function to call when the event was fired
|
|
23080
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23081
|
-
*
|
|
23082
|
-
* @category Client Events
|
|
23083
|
-
*/
|
|
23084
|
-
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
23085
|
-
|
|
23086
23376
|
const setIntervalTask = (handler, timeout) => {
|
|
23087
23377
|
const timer = setInterval(handler, timeout);
|
|
23088
23378
|
return () => clearInterval(timer);
|
|
@@ -23876,7 +24166,7 @@ class AnalyticsEventSyncer {
|
|
|
23876
24166
|
|
|
23877
24167
|
class AnalyticsEventCapturer {
|
|
23878
24168
|
constructor() {
|
|
23879
|
-
this._expireTime = 5 *
|
|
24169
|
+
this._expireTime = 5 * SECOND$1;
|
|
23880
24170
|
this._poolLimit = 1000;
|
|
23881
24171
|
this._recentViewed = {};
|
|
23882
24172
|
this._recentHighPriorityViewed = {};
|
|
@@ -23930,12 +24220,36 @@ class AnalyticsEventCapturer {
|
|
|
23930
24220
|
}
|
|
23931
24221
|
markPostAsViewed(postId) {
|
|
23932
24222
|
this.markAs({
|
|
23933
|
-
uniqueId: postId
|
|
24223
|
+
uniqueId: `post.${postId}`,
|
|
23934
24224
|
contentId: postId,
|
|
23935
24225
|
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
23936
24226
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
23937
24227
|
});
|
|
23938
24228
|
}
|
|
24229
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
24230
|
+
var _a;
|
|
24231
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24232
|
+
const metadata = {};
|
|
24233
|
+
if (feedRenderPosition !== undefined)
|
|
24234
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
24235
|
+
if (cached) {
|
|
24236
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
24237
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
24238
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
24239
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
24240
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
24241
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
24242
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
24243
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
24244
|
+
}
|
|
24245
|
+
this.markAs({
|
|
24246
|
+
uniqueId: `post.${postId}.meaningfulView`,
|
|
24247
|
+
contentId: postId,
|
|
24248
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
24249
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
24250
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
24251
|
+
});
|
|
24252
|
+
}
|
|
23939
24253
|
markStory(story, activityType) {
|
|
23940
24254
|
if (!story.expiresAt)
|
|
23941
24255
|
return;
|
|
@@ -24075,6 +24389,12 @@ class AnalyticsEngine {
|
|
|
24075
24389
|
this._eventCapturer.markPostAsViewed(postId);
|
|
24076
24390
|
}
|
|
24077
24391
|
}
|
|
24392
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
24393
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
24394
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
24395
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
24396
|
+
}
|
|
24397
|
+
}
|
|
24078
24398
|
markStoryAsViewed(story) {
|
|
24079
24399
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
24080
24400
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -24299,9 +24619,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
24299
24619
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
24300
24620
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
24301
24621
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24302
|
-
if (
|
|
24303
|
-
channelUnread
|
|
24304
|
-
segment > channelUnread.readToSegment) {
|
|
24622
|
+
if (channelUnread &&
|
|
24623
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
24305
24624
|
channelUnread.readToSegment = segment;
|
|
24306
24625
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
24307
24626
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -25195,6 +25514,59 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
25195
25514
|
};
|
|
25196
25515
|
};
|
|
25197
25516
|
|
|
25517
|
+
class CursorController {
|
|
25518
|
+
constructor(networkId, userId) {
|
|
25519
|
+
this.networkId = networkId;
|
|
25520
|
+
this.userId = userId;
|
|
25521
|
+
}
|
|
25522
|
+
static current() {
|
|
25523
|
+
try {
|
|
25524
|
+
const user = getCurrentUser();
|
|
25525
|
+
if (!user)
|
|
25526
|
+
return null;
|
|
25527
|
+
const networkId = getNetworkId(user);
|
|
25528
|
+
const { userId } = user;
|
|
25529
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
25530
|
+
}
|
|
25531
|
+
catch (_a) {
|
|
25532
|
+
return null;
|
|
25533
|
+
}
|
|
25534
|
+
}
|
|
25535
|
+
static isExpired(expiredAt) {
|
|
25536
|
+
return Date.now() >= expiredAt;
|
|
25537
|
+
}
|
|
25538
|
+
static clearOnLogout() {
|
|
25539
|
+
return onSessionStateChange(state => {
|
|
25540
|
+
var _a;
|
|
25541
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
25542
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
25543
|
+
});
|
|
25544
|
+
}
|
|
25545
|
+
get key() {
|
|
25546
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
25547
|
+
}
|
|
25548
|
+
async get() {
|
|
25549
|
+
const raw = await getItem(this.key);
|
|
25550
|
+
if (!raw)
|
|
25551
|
+
return null;
|
|
25552
|
+
try {
|
|
25553
|
+
const parsed = JSON.parse(raw);
|
|
25554
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
25555
|
+
return null;
|
|
25556
|
+
return { cursor: parsed.cursor, expiredAt: parsed.expiredAt };
|
|
25557
|
+
}
|
|
25558
|
+
catch (_a) {
|
|
25559
|
+
return null;
|
|
25560
|
+
}
|
|
25561
|
+
}
|
|
25562
|
+
async set(value) {
|
|
25563
|
+
await setItem(this.key, JSON.stringify(value));
|
|
25564
|
+
}
|
|
25565
|
+
async clear() {
|
|
25566
|
+
await setItem(this.key, '');
|
|
25567
|
+
}
|
|
25568
|
+
}
|
|
25569
|
+
|
|
25198
25570
|
const EVENTS = [
|
|
25199
25571
|
'disconnected',
|
|
25200
25572
|
'error',
|
|
@@ -25384,7 +25756,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
25384
25756
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25385
25757
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25386
25758
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
25387
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler());
|
|
25759
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
25388
25760
|
if (client.useLegacyUnreadCount) {
|
|
25389
25761
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
25390
25762
|
}
|
|
@@ -26083,16 +26455,13 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
26083
26455
|
}
|
|
26084
26456
|
if (client.useLegacyUnreadCount) {
|
|
26085
26457
|
rawPayload.messages.forEach(message => {
|
|
26086
|
-
var _a, _b;
|
|
26458
|
+
var _a, _b, _c;
|
|
26087
26459
|
const channelUnread = (_a = pullFromCache([
|
|
26088
26460
|
'channelUnread',
|
|
26089
26461
|
'get',
|
|
26090
26462
|
message.channelId,
|
|
26091
26463
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
26092
|
-
if (!channelUnread ||
|
|
26093
|
-
channelUnread.lastSegment >= message.segment ||
|
|
26094
|
-
typeof channelUnread.readToSegment !== 'number' ||
|
|
26095
|
-
typeof channelUnread.lastMentionedSegment !== 'number')
|
|
26464
|
+
if (!channelUnread || channelUnread.lastSegment >= message.segment)
|
|
26096
26465
|
return;
|
|
26097
26466
|
const lastSegment = message.segment;
|
|
26098
26467
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -26104,7 +26473,8 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
26104
26473
|
const lastMentionedSegment = isMentionedInMessage
|
|
26105
26474
|
? message.segment
|
|
26106
26475
|
: channelUnread.lastMentionedSegment;
|
|
26107
|
-
const
|
|
26476
|
+
const readToSegment = (_c = channelUnread.readToSegment) !== null && _c !== void 0 ? _c : 0;
|
|
26477
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - readToSegment, 0), lastMentionedSegment, isMentioned: typeof lastMentionedSegment === 'number' && readToSegment < lastMentionedSegment });
|
|
26108
26478
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
26109
26479
|
fireEvent('local.channelUnread.updated', [updatedChannelUnread]);
|
|
26110
26480
|
});
|
|
@@ -26742,11 +27112,18 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
26742
27112
|
return data;
|
|
26743
27113
|
};
|
|
26744
27114
|
|
|
27115
|
+
const CONTENT_TYPE_CONFIG = {
|
|
27116
|
+
[AmitySharableContentType.POST]: { key: 'posts', placeholder: 'postId' },
|
|
27117
|
+
[AmitySharableContentType.COMMUNITY]: { key: 'communities', placeholder: 'communityId' },
|
|
27118
|
+
[AmitySharableContentType.USER]: { key: 'users', placeholder: 'userId' },
|
|
27119
|
+
[AmitySharableContentType.LIVESTREAM]: { key: 'livestream', placeholder: 'livestream' },
|
|
27120
|
+
[AmitySharableContentType.EVENT]: { key: 'events', placeholder: 'eventId' },
|
|
27121
|
+
};
|
|
26745
27122
|
/**
|
|
26746
27123
|
* ```js
|
|
26747
27124
|
* import Client from '@amityco/ts-sdk'
|
|
26748
|
-
* const
|
|
26749
|
-
* const
|
|
27125
|
+
* const config = await Client.getShareableLinkConfiguration()
|
|
27126
|
+
* const link = config.generateLink(AmitySharableContentType.EVENT, eventId)
|
|
26750
27127
|
* ```
|
|
26751
27128
|
*
|
|
26752
27129
|
* Fetches a {@link Amity.ShareableLinkConfiguration} object
|
|
@@ -26757,9 +27134,29 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
26757
27134
|
* @async
|
|
26758
27135
|
*/
|
|
26759
27136
|
const getShareableLinkConfiguration = async () => {
|
|
27137
|
+
var _a, _b;
|
|
26760
27138
|
const client = getActiveClient();
|
|
26761
27139
|
const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
|
|
26762
|
-
|
|
27140
|
+
const domain = (_a = data.domain) !== null && _a !== void 0 ? _a : '';
|
|
27141
|
+
const patterns = (_b = data.patterns) !== null && _b !== void 0 ? _b : {};
|
|
27142
|
+
return {
|
|
27143
|
+
domain,
|
|
27144
|
+
patterns,
|
|
27145
|
+
isEnabled(contentType) {
|
|
27146
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
27147
|
+
return !!domain && !!patterns[key];
|
|
27148
|
+
},
|
|
27149
|
+
getPattern(contentType) {
|
|
27150
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
27151
|
+
return patterns[key] || null;
|
|
27152
|
+
},
|
|
27153
|
+
generateLink(contentType, referenceId) {
|
|
27154
|
+
const { key, placeholder } = CONTENT_TYPE_CONFIG[contentType];
|
|
27155
|
+
if (!domain || !patterns[key])
|
|
27156
|
+
return null;
|
|
27157
|
+
return domain + patterns[key].replace(`{${placeholder}}`, referenceId);
|
|
27158
|
+
},
|
|
27159
|
+
};
|
|
26763
27160
|
};
|
|
26764
27161
|
|
|
26765
27162
|
/**
|
|
@@ -26950,6 +27347,205 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
26950
27347
|
client.accessTokenHandler = accessTokenHandler;
|
|
26951
27348
|
};
|
|
26952
27349
|
|
|
27350
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
27351
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
27352
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
27353
|
+
}
|
|
27354
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
27355
|
+
return { type: NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
27356
|
+
}
|
|
27357
|
+
return { type: NotificationRolesFilterTypeEnum.ALL };
|
|
27358
|
+
}
|
|
27359
|
+
function serializeRolesFilter(rolesFilter) {
|
|
27360
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === NotificationRolesFilterTypeEnum.ONLY) {
|
|
27361
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
27362
|
+
}
|
|
27363
|
+
return { listenFromRoleIds: [] };
|
|
27364
|
+
}
|
|
27365
|
+
class ChannelNotifications {
|
|
27366
|
+
constructor(channelId) {
|
|
27367
|
+
this.channelId = channelId;
|
|
27368
|
+
}
|
|
27369
|
+
async enable() {
|
|
27370
|
+
const client = getActiveClient();
|
|
27371
|
+
const body = {
|
|
27372
|
+
level: NotificationSettingsLevelEnum.CHANNEL,
|
|
27373
|
+
channelId: this.channelId,
|
|
27374
|
+
isPushNotifiable: true,
|
|
27375
|
+
};
|
|
27376
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27377
|
+
}
|
|
27378
|
+
async disable() {
|
|
27379
|
+
const client = getActiveClient();
|
|
27380
|
+
const body = {
|
|
27381
|
+
level: NotificationSettingsLevelEnum.CHANNEL,
|
|
27382
|
+
channelId: this.channelId,
|
|
27383
|
+
isPushNotifiable: false,
|
|
27384
|
+
};
|
|
27385
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27386
|
+
}
|
|
27387
|
+
async getSettings() {
|
|
27388
|
+
const client = getActiveClient();
|
|
27389
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
27390
|
+
return { isEnabled: data.isPushNotifiable };
|
|
27391
|
+
}
|
|
27392
|
+
}
|
|
27393
|
+
class UserNotifications {
|
|
27394
|
+
async enable(modules) {
|
|
27395
|
+
var _a;
|
|
27396
|
+
const client = getActiveClient();
|
|
27397
|
+
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 : [];
|
|
27398
|
+
const body = {
|
|
27399
|
+
level: NotificationSettingsLevelEnum.USER,
|
|
27400
|
+
isPushNotifiable: true,
|
|
27401
|
+
notifiableEvents,
|
|
27402
|
+
};
|
|
27403
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27404
|
+
}
|
|
27405
|
+
async disableAllNotifications() {
|
|
27406
|
+
const client = getActiveClient();
|
|
27407
|
+
const body = {
|
|
27408
|
+
level: NotificationSettingsLevelEnum.USER,
|
|
27409
|
+
isPushNotifiable: false,
|
|
27410
|
+
notifiableEvents: [],
|
|
27411
|
+
};
|
|
27412
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27413
|
+
}
|
|
27414
|
+
async getSettings() {
|
|
27415
|
+
var _a;
|
|
27416
|
+
const client = getActiveClient();
|
|
27417
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.USER}`);
|
|
27418
|
+
const validModuleNames = Object.values(UserNotificationModuleNameEnum);
|
|
27419
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
27420
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
27421
|
+
.map(e => ({
|
|
27422
|
+
moduleName: e.moduleName,
|
|
27423
|
+
isEnabled: e.isPushNotifiable,
|
|
27424
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
27425
|
+
}));
|
|
27426
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
27427
|
+
}
|
|
27428
|
+
}
|
|
27429
|
+
class CommunityNotifications {
|
|
27430
|
+
constructor(communityId) {
|
|
27431
|
+
this.communityId = communityId;
|
|
27432
|
+
}
|
|
27433
|
+
async enable(events) {
|
|
27434
|
+
var _a;
|
|
27435
|
+
const client = getActiveClient();
|
|
27436
|
+
const notifiableEvents = (_a = events === null || events === void 0 ? void 0 : events.map(event => (Object.assign({ moduleName: UserNotificationModuleNameEnum.SOCIAL, name: event.eventName, isPushNotifiable: event.isEnabled }, serializeRolesFilter(event.rolesFilter))))) !== null && _a !== void 0 ? _a : [];
|
|
27437
|
+
const body = {
|
|
27438
|
+
level: NotificationSettingsLevelEnum.COMMUNITY,
|
|
27439
|
+
communityId: this.communityId,
|
|
27440
|
+
isPushNotifiable: true,
|
|
27441
|
+
notifiableEvents,
|
|
27442
|
+
};
|
|
27443
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27444
|
+
}
|
|
27445
|
+
async disable() {
|
|
27446
|
+
const client = getActiveClient();
|
|
27447
|
+
const body = {
|
|
27448
|
+
level: NotificationSettingsLevelEnum.COMMUNITY,
|
|
27449
|
+
communityId: this.communityId,
|
|
27450
|
+
isPushNotifiable: false,
|
|
27451
|
+
notifiableEvents: [],
|
|
27452
|
+
};
|
|
27453
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27454
|
+
}
|
|
27455
|
+
async getSettings() {
|
|
27456
|
+
var _a;
|
|
27457
|
+
const client = getActiveClient();
|
|
27458
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
27459
|
+
const validEventNames = Object.values(CommunityNotificationEventNameEnum);
|
|
27460
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
27461
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
27462
|
+
.map(e => ({
|
|
27463
|
+
eventName: e.name,
|
|
27464
|
+
isEnabled: e.isPushNotifiable,
|
|
27465
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
27466
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
27467
|
+
}));
|
|
27468
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
27469
|
+
}
|
|
27470
|
+
}
|
|
27471
|
+
class Notifications {
|
|
27472
|
+
user() {
|
|
27473
|
+
return new UserNotifications();
|
|
27474
|
+
}
|
|
27475
|
+
community(communityId) {
|
|
27476
|
+
return new CommunityNotifications(communityId);
|
|
27477
|
+
}
|
|
27478
|
+
channel(channelId) {
|
|
27479
|
+
return new ChannelNotifications(channelId);
|
|
27480
|
+
}
|
|
27481
|
+
}
|
|
27482
|
+
const notifications = () => new Notifications();
|
|
27483
|
+
|
|
27484
|
+
/* begin_public_function
|
|
27485
|
+
id: client.enable_auto_subscriptions
|
|
27486
|
+
*/
|
|
27487
|
+
/**
|
|
27488
|
+
* ```js
|
|
27489
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27490
|
+
* Client.enableAutoSubscriptions([Client.AutoSubscription.BLOCK])
|
|
27491
|
+
* ```
|
|
27492
|
+
*
|
|
27493
|
+
* Enables one or more managed auto-subscription handles. Managed handles are
|
|
27494
|
+
* re-applied on every (re)connect and ref-counted. All handles are on by
|
|
27495
|
+
* default; use this to re-enable handles previously turned off via
|
|
27496
|
+
* {@link disableAutoSubscriptions}. Synchronous fire-and-forget — the registry
|
|
27497
|
+
* updates immediately and the broker subscribe is retried on reconnect.
|
|
27498
|
+
*
|
|
27499
|
+
* @param features the {@link AutoSubscription} handles to enable
|
|
27500
|
+
*
|
|
27501
|
+
* @category Client API
|
|
27502
|
+
*/
|
|
27503
|
+
const enableAutoSubscriptions = (features) => {
|
|
27504
|
+
const manager = getAutoSubscriptionManager();
|
|
27505
|
+
features.forEach(feature => manager.subscribe(feature));
|
|
27506
|
+
};
|
|
27507
|
+
/* end_public_function */
|
|
27508
|
+
/* begin_public_function
|
|
27509
|
+
id: client.disable_auto_subscriptions
|
|
27510
|
+
*/
|
|
27511
|
+
/**
|
|
27512
|
+
* ```js
|
|
27513
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27514
|
+
* Client.disableAutoSubscriptions([Client.AutoSubscription.LIVESTREAM])
|
|
27515
|
+
* ```
|
|
27516
|
+
*
|
|
27517
|
+
* Disables one or more managed auto-subscription handles. The change persists
|
|
27518
|
+
* across reconnect (it is not silently re-enabled) until
|
|
27519
|
+
* {@link enableAutoSubscriptions} is called again. Synchronous fire-and-forget.
|
|
27520
|
+
*
|
|
27521
|
+
* @param features the {@link AutoSubscription} handles to disable
|
|
27522
|
+
*
|
|
27523
|
+
* @category Client API
|
|
27524
|
+
*/
|
|
27525
|
+
const disableAutoSubscriptions = (features) => {
|
|
27526
|
+
const manager = getAutoSubscriptionManager();
|
|
27527
|
+
features.forEach(feature => manager.unsubscribe(feature));
|
|
27528
|
+
};
|
|
27529
|
+
/* end_public_function */
|
|
27530
|
+
/* begin_public_function
|
|
27531
|
+
id: client.auto_subscriptions
|
|
27532
|
+
*/
|
|
27533
|
+
/**
|
|
27534
|
+
* ```js
|
|
27535
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27536
|
+
* Client.autoSubscriptions().forEach(s => console.log(s.feature, s.isActive, s.topicCount))
|
|
27537
|
+
* ```
|
|
27538
|
+
*
|
|
27539
|
+
* Inspects the managed auto-subscription registry — each handle's `isActive`,
|
|
27540
|
+
* `isSystem`, and `topicCount`.
|
|
27541
|
+
*
|
|
27542
|
+
* @returns a snapshot of the managed subscription registry
|
|
27543
|
+
*
|
|
27544
|
+
* @category Client API
|
|
27545
|
+
*/
|
|
27546
|
+
const autoSubscriptions = () => getAutoSubscriptionManager().subscriptions();
|
|
27547
|
+
/* end_public_function */
|
|
27548
|
+
|
|
26953
27549
|
/**
|
|
26954
27550
|
* ```js
|
|
26955
27551
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -27330,6 +27926,12 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
27330
27926
|
getCurrentUserType: getCurrentUserType,
|
|
27331
27927
|
setCurrentUserType: setCurrentUserType,
|
|
27332
27928
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
27929
|
+
getChatSettings: getChatSettings,
|
|
27930
|
+
notifications: notifications,
|
|
27931
|
+
get AutoSubscription () { return AutoSubscription; },
|
|
27932
|
+
enableAutoSubscriptions: enableAutoSubscriptions,
|
|
27933
|
+
disableAutoSubscriptions: disableAutoSubscriptions,
|
|
27934
|
+
autoSubscriptions: autoSubscriptions,
|
|
27333
27935
|
onConnectionError: onConnectionError,
|
|
27334
27936
|
onClientDisconnected: onClientDisconnected,
|
|
27335
27937
|
onClientBanned: onClientBanned,
|
|
@@ -27435,6 +28037,67 @@ const unBlockUser = async (userId) => {
|
|
|
27435
28037
|
};
|
|
27436
28038
|
/* end_public_function */
|
|
27437
28039
|
|
|
28040
|
+
/**
|
|
28041
|
+
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
28042
|
+
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
28043
|
+
* the block-relationship rows (`['follow', 'get', from#to]`) and user rows are
|
|
28044
|
+
* kept current, then forwards the affected {@link Amity.FollowStatus} to the
|
|
28045
|
+
* caller.
|
|
28046
|
+
*
|
|
28047
|
+
* @hidden
|
|
28048
|
+
*/
|
|
28049
|
+
const createBlockEventSubscriber = (event, callback) => {
|
|
28050
|
+
const client = getActiveClient();
|
|
28051
|
+
const filter = (data) => {
|
|
28052
|
+
const payload = prepareFollowersPayload(data);
|
|
28053
|
+
if (client.cache) {
|
|
28054
|
+
ingestInCache(payload);
|
|
28055
|
+
}
|
|
28056
|
+
callback(payload.follows[0]);
|
|
28057
|
+
};
|
|
28058
|
+
return createEventSubscriber(client, event, event, filter);
|
|
28059
|
+
};
|
|
28060
|
+
|
|
28061
|
+
/**
|
|
28062
|
+
* ```js
|
|
28063
|
+
* import { onUserDidBlock } from '@amityco/ts-sdk'
|
|
28064
|
+
* const dispose = onUserDidBlock(status => {
|
|
28065
|
+
* // ...
|
|
28066
|
+
* })
|
|
28067
|
+
* ```
|
|
28068
|
+
*
|
|
28069
|
+
* Fired when a block relationship is created in real time — either a user
|
|
28070
|
+
* blocks the current user (incoming) or the current user blocks someone on
|
|
28071
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
28072
|
+
* before the callback runs.
|
|
28073
|
+
*
|
|
28074
|
+
* @param callback The function to call when the event was fired
|
|
28075
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28076
|
+
*
|
|
28077
|
+
* @category Block Events
|
|
28078
|
+
*/
|
|
28079
|
+
const onUserDidBlock = (callback) => createBlockEventSubscriber('user.didBlock', callback);
|
|
28080
|
+
|
|
28081
|
+
/**
|
|
28082
|
+
* ```js
|
|
28083
|
+
* import { onUserDidUnblock } from '@amityco/ts-sdk'
|
|
28084
|
+
* const dispose = onUserDidUnblock(status => {
|
|
28085
|
+
* // ...
|
|
28086
|
+
* })
|
|
28087
|
+
* ```
|
|
28088
|
+
*
|
|
28089
|
+
* Fired when a block relationship is removed in real time — either a user
|
|
28090
|
+
* unblocks the current user (incoming) or the current user unblocks someone on
|
|
28091
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
28092
|
+
* before the callback runs.
|
|
28093
|
+
*
|
|
28094
|
+
* @param callback The function to call when the event was fired
|
|
28095
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28096
|
+
*
|
|
28097
|
+
* @category Block Events
|
|
28098
|
+
*/
|
|
28099
|
+
const onUserDidUnblock = (callback) => createBlockEventSubscriber('user.didUnblock', callback);
|
|
28100
|
+
|
|
27438
28101
|
/* begin_public_function
|
|
27439
28102
|
id: user.relationship.follow
|
|
27440
28103
|
*/
|
|
@@ -28537,6 +29200,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
28537
29200
|
__proto__: null,
|
|
28538
29201
|
blockUser: blockUser,
|
|
28539
29202
|
unBlockUser: unBlockUser,
|
|
29203
|
+
onUserDidBlock: onUserDidBlock,
|
|
29204
|
+
onUserDidUnblock: onUserDidUnblock,
|
|
28540
29205
|
follow: follow,
|
|
28541
29206
|
unfollow: unfollow,
|
|
28542
29207
|
acceptMyFollower: acceptMyFollower,
|
|
@@ -29366,7 +30031,7 @@ const getWatchSessionStorage = () => {
|
|
|
29366
30031
|
return storageInstance;
|
|
29367
30032
|
};
|
|
29368
30033
|
|
|
29369
|
-
const privateKey = "
|
|
30034
|
+
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=";
|
|
29370
30035
|
/*
|
|
29371
30036
|
* The crypto algorithm used for importing key and signing string
|
|
29372
30037
|
*/
|
|
@@ -30688,6 +31353,10 @@ const postLinkedObject = (post) => {
|
|
|
30688
31353
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
30689
31354
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
30690
31355
|
},
|
|
31356
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
31357
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
31358
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
31359
|
+
},
|
|
30691
31360
|
},
|
|
30692
31361
|
get productTags() {
|
|
30693
31362
|
var _a, _b;
|
|
@@ -30877,6 +31546,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
30877
31546
|
});
|
|
30878
31547
|
return true;
|
|
30879
31548
|
}
|
|
31549
|
+
if (referenceType === 'message') {
|
|
31550
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
31551
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
31552
|
+
return true;
|
|
31553
|
+
}
|
|
30880
31554
|
}
|
|
30881
31555
|
return true;
|
|
30882
31556
|
};
|
|
@@ -30955,7 +31629,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
30955
31629
|
return true;
|
|
30956
31630
|
}
|
|
30957
31631
|
if (referenceType === 'story') {
|
|
30958
|
-
fireEvent('local.story.
|
|
31632
|
+
fireEvent('local.story.reactionRemoved', {
|
|
30959
31633
|
story: updatedModel,
|
|
30960
31634
|
reactor: {
|
|
30961
31635
|
userId: client.userId,
|
|
@@ -30965,6 +31639,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
30965
31639
|
});
|
|
30966
31640
|
return true;
|
|
30967
31641
|
}
|
|
31642
|
+
if (referenceType === 'message') {
|
|
31643
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
31644
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
31645
|
+
return true;
|
|
31646
|
+
}
|
|
30968
31647
|
}
|
|
30969
31648
|
return true;
|
|
30970
31649
|
};
|
|
@@ -32284,6 +32963,12 @@ class BlockedUserPaginationController extends PaginationController {
|
|
|
32284
32963
|
}
|
|
32285
32964
|
}
|
|
32286
32965
|
|
|
32966
|
+
var EnumBlockActions;
|
|
32967
|
+
(function (EnumBlockActions) {
|
|
32968
|
+
EnumBlockActions["OnBlocked"] = "onBlocked";
|
|
32969
|
+
EnumBlockActions["OnUnblocked"] = "onUnblocked";
|
|
32970
|
+
})(EnumBlockActions || (EnumBlockActions = {}));
|
|
32971
|
+
|
|
32287
32972
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
32288
32973
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
32289
32974
|
super(query, cacheKey);
|
|
@@ -32313,11 +32998,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
32313
32998
|
}
|
|
32314
32999
|
reactor(action) {
|
|
32315
33000
|
return (targetUser) => {
|
|
32316
|
-
var _a;
|
|
32317
|
-
|
|
33001
|
+
var _a, _b;
|
|
33002
|
+
const isRemoval = action === EnumFollowActions.OnFollowed || action === EnumBlockActions.OnUnblocked;
|
|
33003
|
+
const isAddition = action === EnumBlockActions.OnBlocked;
|
|
33004
|
+
if (isRemoval || isAddition) {
|
|
32318
33005
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32319
|
-
const
|
|
32320
|
-
|
|
33006
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33007
|
+
const data = isAddition
|
|
33008
|
+
? [...new Set([...ids, targetUser.userId])]
|
|
33009
|
+
: ids.filter(id => id !== targetUser.userId);
|
|
33010
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
32321
33011
|
}
|
|
32322
33012
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
32323
33013
|
};
|
|
@@ -32372,7 +33062,6 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
32372
33062
|
fn: onUserDeleted$2,
|
|
32373
33063
|
action: EnumUserActions.OnUserDeleted,
|
|
32374
33064
|
},
|
|
32375
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
32376
33065
|
{
|
|
32377
33066
|
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
32378
33067
|
action: EnumFollowActions.OnFollowed,
|
|
@@ -32381,6 +33070,28 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
32381
33070
|
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
32382
33071
|
action: EnumFollowActions.OnFollowed,
|
|
32383
33072
|
},
|
|
33073
|
+
{
|
|
33074
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
33075
|
+
var _a;
|
|
33076
|
+
if (status.from !== getActiveClient().userId)
|
|
33077
|
+
return;
|
|
33078
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33079
|
+
if (blocked)
|
|
33080
|
+
reactor(blocked);
|
|
33081
|
+
}),
|
|
33082
|
+
action: EnumBlockActions.OnBlocked,
|
|
33083
|
+
},
|
|
33084
|
+
{
|
|
33085
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
33086
|
+
var _a;
|
|
33087
|
+
if (status.from !== getActiveClient().userId)
|
|
33088
|
+
return;
|
|
33089
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33090
|
+
if (blocked)
|
|
33091
|
+
reactor(blocked);
|
|
33092
|
+
}),
|
|
33093
|
+
action: EnumBlockActions.OnUnblocked,
|
|
33094
|
+
},
|
|
32384
33095
|
]);
|
|
32385
33096
|
}
|
|
32386
33097
|
notifyChange({ origin, loading, error }) {
|
|
@@ -32448,6 +33159,192 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
32448
33159
|
};
|
|
32449
33160
|
/* end_public_function */
|
|
32450
33161
|
|
|
33162
|
+
function prepareBlockingUserPayload(response) {
|
|
33163
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
33164
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
33165
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
33166
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
33167
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
33168
|
+
}
|
|
33169
|
+
|
|
33170
|
+
class BlockingUserQueryStreamController extends QueryStreamController {
|
|
33171
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
33172
|
+
super(query, cacheKey);
|
|
33173
|
+
this.notifyChange = notifyChange;
|
|
33174
|
+
this.preparePayload = preparePayload;
|
|
33175
|
+
}
|
|
33176
|
+
async saveToMainDB(response) {
|
|
33177
|
+
const processedPayload = await this.preparePayload(response);
|
|
33178
|
+
const client = getActiveClient();
|
|
33179
|
+
const cachedAt = client.cache && Date.now();
|
|
33180
|
+
if (client.cache) {
|
|
33181
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
33182
|
+
}
|
|
33183
|
+
}
|
|
33184
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
33185
|
+
var _a, _b;
|
|
33186
|
+
if (refresh) {
|
|
33187
|
+
pushToCache(this.cacheKey, {
|
|
33188
|
+
data: response.users.map(getResolver('user')),
|
|
33189
|
+
});
|
|
33190
|
+
}
|
|
33191
|
+
else {
|
|
33192
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33193
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33194
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
33195
|
+
}
|
|
33196
|
+
}
|
|
33197
|
+
reactor(action) {
|
|
33198
|
+
return (user) => {
|
|
33199
|
+
var _a, _b;
|
|
33200
|
+
if (user &&
|
|
33201
|
+
(action === EnumBlockActions.OnBlocked || action === EnumBlockActions.OnUnblocked)) {
|
|
33202
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33203
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33204
|
+
const data = action === EnumBlockActions.OnBlocked
|
|
33205
|
+
? [...new Set([...ids, user.userId])]
|
|
33206
|
+
: ids.filter(id => id !== user.userId);
|
|
33207
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
33208
|
+
}
|
|
33209
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
33210
|
+
};
|
|
33211
|
+
}
|
|
33212
|
+
subscribeRTE(createSubscriber) {
|
|
33213
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
33214
|
+
}
|
|
33215
|
+
}
|
|
33216
|
+
|
|
33217
|
+
class BlockingUserPaginationController extends PaginationController {
|
|
33218
|
+
async getRequest(queryParams, token) {
|
|
33219
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
33220
|
+
const options = token ? { token } : { limit };
|
|
33221
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/blockers', {
|
|
33222
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
33223
|
+
});
|
|
33224
|
+
return queryResponse;
|
|
33225
|
+
}
|
|
33226
|
+
}
|
|
33227
|
+
|
|
33228
|
+
class BlockingUserLiveCollectionController extends LiveCollectionController {
|
|
33229
|
+
constructor(callback) {
|
|
33230
|
+
const queryStreamId = `blocking-users-${getActiveClient().userId}`;
|
|
33231
|
+
const query = {};
|
|
33232
|
+
const cacheKey = ['blockingUsers', 'collection', queryStreamId];
|
|
33233
|
+
const paginationController = new BlockingUserPaginationController(query);
|
|
33234
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
33235
|
+
this.queryStreamController = new BlockingUserQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), prepareBlockingUserPayload);
|
|
33236
|
+
this.callback = callback.bind(this);
|
|
33237
|
+
this.loadPage({ initial: true });
|
|
33238
|
+
}
|
|
33239
|
+
setup() {
|
|
33240
|
+
var _a;
|
|
33241
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33242
|
+
if (!collection) {
|
|
33243
|
+
pushToCache(this.cacheKey, {
|
|
33244
|
+
data: [],
|
|
33245
|
+
params: {},
|
|
33246
|
+
});
|
|
33247
|
+
}
|
|
33248
|
+
}
|
|
33249
|
+
async persistModel(queryPayload) {
|
|
33250
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
33251
|
+
}
|
|
33252
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
33253
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
33254
|
+
}
|
|
33255
|
+
startSubscription() {
|
|
33256
|
+
return this.queryStreamController.subscribeRTE([
|
|
33257
|
+
{
|
|
33258
|
+
fn: onUserDeleted$2,
|
|
33259
|
+
action: EnumUserActions.OnUserDeleted,
|
|
33260
|
+
},
|
|
33261
|
+
{
|
|
33262
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
33263
|
+
var _a;
|
|
33264
|
+
if (status.to !== getActiveClient().userId)
|
|
33265
|
+
return;
|
|
33266
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33267
|
+
if (blocker)
|
|
33268
|
+
reactor(blocker);
|
|
33269
|
+
}),
|
|
33270
|
+
action: EnumBlockActions.OnBlocked,
|
|
33271
|
+
},
|
|
33272
|
+
{
|
|
33273
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
33274
|
+
var _a;
|
|
33275
|
+
if (status.to !== getActiveClient().userId)
|
|
33276
|
+
return;
|
|
33277
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33278
|
+
if (blocker)
|
|
33279
|
+
reactor(blocker);
|
|
33280
|
+
}),
|
|
33281
|
+
action: EnumBlockActions.OnUnblocked,
|
|
33282
|
+
},
|
|
33283
|
+
]);
|
|
33284
|
+
}
|
|
33285
|
+
notifyChange({ origin, loading, error }) {
|
|
33286
|
+
var _a, _b;
|
|
33287
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33288
|
+
if (!collection)
|
|
33289
|
+
return;
|
|
33290
|
+
const data = this.applyFilter((_b = collection.data
|
|
33291
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
33292
|
+
.filter(isNonNullable)
|
|
33293
|
+
.map(({ data }) => data)
|
|
33294
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
33295
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
33296
|
+
return;
|
|
33297
|
+
this.callback({
|
|
33298
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
33299
|
+
data,
|
|
33300
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
33301
|
+
loading,
|
|
33302
|
+
error,
|
|
33303
|
+
});
|
|
33304
|
+
}
|
|
33305
|
+
applyFilter(data) {
|
|
33306
|
+
let users = data;
|
|
33307
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
33308
|
+
return users;
|
|
33309
|
+
}
|
|
33310
|
+
}
|
|
33311
|
+
|
|
33312
|
+
/* begin_public_function
|
|
33313
|
+
id: user.get_blocking_users
|
|
33314
|
+
*/
|
|
33315
|
+
/**
|
|
33316
|
+
* ```js
|
|
33317
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
33318
|
+
* const unsubscribe = UserRepository.getBlockingUsers(({ data: users }) => {
|
|
33319
|
+
* console.log(users)
|
|
33320
|
+
* })
|
|
33321
|
+
* ```
|
|
33322
|
+
*
|
|
33323
|
+
* Observe the {@link Amity.User}s who have blocked the current user
|
|
33324
|
+
*
|
|
33325
|
+
* @param callback to receive updates on the blocking {@link Amity.User}s
|
|
33326
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
33327
|
+
*
|
|
33328
|
+
* @category User API
|
|
33329
|
+
*/
|
|
33330
|
+
const getBlockingUsers = (callback) => {
|
|
33331
|
+
const { log, cache } = getActiveClient();
|
|
33332
|
+
if (!cache)
|
|
33333
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
33334
|
+
const timestamp = Date.now();
|
|
33335
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > listen`);
|
|
33336
|
+
const blockingUserLiveCollection = new BlockingUserLiveCollectionController(callback);
|
|
33337
|
+
const disposers = blockingUserLiveCollection.startSubscription();
|
|
33338
|
+
const cacheKey = blockingUserLiveCollection.getCacheKey();
|
|
33339
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
33340
|
+
return () => {
|
|
33341
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > dispose`);
|
|
33342
|
+
disposers.forEach(fn => fn());
|
|
33343
|
+
dropFromCache(cacheKey);
|
|
33344
|
+
};
|
|
33345
|
+
};
|
|
33346
|
+
/* end_public_function */
|
|
33347
|
+
|
|
32451
33348
|
class SearchUserPaginationController extends PaginationController {
|
|
32452
33349
|
async getRequest(queryParams, token) {
|
|
32453
33350
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
@@ -32722,6 +33619,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
32722
33619
|
getUser: getUser,
|
|
32723
33620
|
getUsers: getUsers,
|
|
32724
33621
|
getBlockedUsers: getBlockedUsers,
|
|
33622
|
+
getBlockingUsers: getBlockingUsers,
|
|
32725
33623
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
32726
33624
|
getReachedUsers: getReachedUsers,
|
|
32727
33625
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
@@ -33888,7 +34786,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
33888
34786
|
return true;
|
|
33889
34787
|
}
|
|
33890
34788
|
if (referenceType === 'story') {
|
|
33891
|
-
fireEvent('local.story.
|
|
34789
|
+
fireEvent('local.story.reactionRemoved', {
|
|
33892
34790
|
story: updatedModel,
|
|
33893
34791
|
reactor: {
|
|
33894
34792
|
userId: client.userId,
|
|
@@ -35472,6 +36370,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
35472
36370
|
};
|
|
35473
36371
|
/* end_public_function */
|
|
35474
36372
|
|
|
36373
|
+
/* begin_public_function
|
|
36374
|
+
id: channel.archive
|
|
36375
|
+
*/
|
|
36376
|
+
/**
|
|
36377
|
+
* ```js
|
|
36378
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36379
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
36380
|
+
* ```
|
|
36381
|
+
*
|
|
36382
|
+
* Archive a {@link Amity.Channel}.
|
|
36383
|
+
*
|
|
36384
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
36385
|
+
* @returns A success boolean
|
|
36386
|
+
*
|
|
36387
|
+
* @category Channel API
|
|
36388
|
+
* @async
|
|
36389
|
+
*/
|
|
36390
|
+
const archiveChannel = async (channelId) => {
|
|
36391
|
+
const client = getActiveClient();
|
|
36392
|
+
client.log('channel/archiveChannel', channelId);
|
|
36393
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
36394
|
+
const archive = {
|
|
36395
|
+
channelId,
|
|
36396
|
+
archivedAt: new Date().toISOString(),
|
|
36397
|
+
};
|
|
36398
|
+
if (client.cache) {
|
|
36399
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
36400
|
+
}
|
|
36401
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
36402
|
+
};
|
|
36403
|
+
/* end_public_function */
|
|
36404
|
+
|
|
36405
|
+
/* begin_public_function
|
|
36406
|
+
id: channel.unarchive
|
|
36407
|
+
*/
|
|
36408
|
+
/**
|
|
36409
|
+
* ```js
|
|
36410
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36411
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
36412
|
+
* ```
|
|
36413
|
+
*
|
|
36414
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
36415
|
+
*
|
|
36416
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
36417
|
+
* @returns A success boolean
|
|
36418
|
+
*
|
|
36419
|
+
* @category Channel API
|
|
36420
|
+
* @async
|
|
36421
|
+
*/
|
|
36422
|
+
const unarchiveChannel = async (channelId) => {
|
|
36423
|
+
var _a;
|
|
36424
|
+
const client = getActiveClient();
|
|
36425
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
36426
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
36427
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
36428
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
36429
|
+
channelId,
|
|
36430
|
+
archivedAt: new Date().toISOString(),
|
|
36431
|
+
};
|
|
36432
|
+
if (client.cache) {
|
|
36433
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
36434
|
+
}
|
|
36435
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
36436
|
+
};
|
|
36437
|
+
/* end_public_function */
|
|
36438
|
+
|
|
36439
|
+
/* begin_public_function
|
|
36440
|
+
id: channel.archive.ids
|
|
36441
|
+
*/
|
|
36442
|
+
/**
|
|
36443
|
+
* ```js
|
|
36444
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36445
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
36446
|
+
* ```
|
|
36447
|
+
*
|
|
36448
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
36449
|
+
*
|
|
36450
|
+
* @category Channel API
|
|
36451
|
+
* @async
|
|
36452
|
+
*/
|
|
36453
|
+
const getArchivedChannelIds = async () => {
|
|
36454
|
+
var _a;
|
|
36455
|
+
const client = getActiveClient();
|
|
36456
|
+
client.log('channel/getArchivedChannelIds');
|
|
36457
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
36458
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
36459
|
+
if (client.cache) {
|
|
36460
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
36461
|
+
archives.forEach(archive => {
|
|
36462
|
+
if (!archive.channelId)
|
|
36463
|
+
return;
|
|
36464
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
36465
|
+
});
|
|
36466
|
+
}
|
|
36467
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
36468
|
+
};
|
|
36469
|
+
/* end_public_function */
|
|
36470
|
+
|
|
35475
36471
|
/**
|
|
35476
36472
|
* ```js
|
|
35477
36473
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -36850,6 +37846,160 @@ const getMessages = (params, callback, config) => {
|
|
|
36850
37846
|
};
|
|
36851
37847
|
/* end_public_function */
|
|
36852
37848
|
|
|
37849
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
37850
|
+
async getRequest(queryParams, token) {
|
|
37851
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
37852
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
37853
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
37854
|
+
params: {
|
|
37855
|
+
query,
|
|
37856
|
+
exactMatch,
|
|
37857
|
+
channelId,
|
|
37858
|
+
messageFeedId,
|
|
37859
|
+
userIds,
|
|
37860
|
+
tags,
|
|
37861
|
+
types,
|
|
37862
|
+
options,
|
|
37863
|
+
},
|
|
37864
|
+
});
|
|
37865
|
+
return queryResponse;
|
|
37866
|
+
}
|
|
37867
|
+
}
|
|
37868
|
+
|
|
37869
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
37870
|
+
constructor(query, cacheKey, notifyChange) {
|
|
37871
|
+
super(query, cacheKey);
|
|
37872
|
+
this.notifyChange = notifyChange;
|
|
37873
|
+
}
|
|
37874
|
+
async saveToMainDB(response) {
|
|
37875
|
+
var _a;
|
|
37876
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
37877
|
+
const client = getActiveClient();
|
|
37878
|
+
const cachedAt = client.cache && Date.now();
|
|
37879
|
+
if (client.cache) {
|
|
37880
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37881
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
37882
|
+
response.channels.forEach(channel => {
|
|
37883
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
37884
|
+
});
|
|
37885
|
+
}
|
|
37886
|
+
}
|
|
37887
|
+
}
|
|
37888
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37889
|
+
var _a, _b;
|
|
37890
|
+
if (refresh) {
|
|
37891
|
+
pushToCache(this.cacheKey, {
|
|
37892
|
+
data: response.messages.map(getResolver('message')),
|
|
37893
|
+
});
|
|
37894
|
+
return;
|
|
37895
|
+
}
|
|
37896
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37897
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37898
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
37899
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
37900
|
+
? [...new Set([...incoming, ...existing])]
|
|
37901
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
37902
|
+
}
|
|
37903
|
+
}
|
|
37904
|
+
|
|
37905
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
37906
|
+
constructor(query, callback) {
|
|
37907
|
+
const queryStreamId = hash(query);
|
|
37908
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
37909
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
37910
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37911
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
37912
|
+
this.callback = callback.bind(this);
|
|
37913
|
+
this.loadPage({ initial: true });
|
|
37914
|
+
}
|
|
37915
|
+
startSubscription() {
|
|
37916
|
+
return [];
|
|
37917
|
+
}
|
|
37918
|
+
notifyChange({ origin, loading, error }) {
|
|
37919
|
+
var _a, _b;
|
|
37920
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37921
|
+
if (!collection)
|
|
37922
|
+
return;
|
|
37923
|
+
const data = (_b = collection.data
|
|
37924
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
37925
|
+
.filter(isNonNullable)
|
|
37926
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
37927
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37928
|
+
return;
|
|
37929
|
+
this.callback({
|
|
37930
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
37931
|
+
data,
|
|
37932
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
37933
|
+
loading,
|
|
37934
|
+
error,
|
|
37935
|
+
});
|
|
37936
|
+
}
|
|
37937
|
+
setup() {
|
|
37938
|
+
var _a;
|
|
37939
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37940
|
+
if (!collection) {
|
|
37941
|
+
pushToCache(this.cacheKey, {
|
|
37942
|
+
data: [],
|
|
37943
|
+
params: {},
|
|
37944
|
+
});
|
|
37945
|
+
}
|
|
37946
|
+
}
|
|
37947
|
+
async persistModel(response) {
|
|
37948
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
37949
|
+
}
|
|
37950
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37951
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37952
|
+
}
|
|
37953
|
+
}
|
|
37954
|
+
|
|
37955
|
+
/* begin_public_function
|
|
37956
|
+
id: message.search
|
|
37957
|
+
*/
|
|
37958
|
+
/**
|
|
37959
|
+
* ```js
|
|
37960
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
37961
|
+
*
|
|
37962
|
+
* let messages = [];
|
|
37963
|
+
*
|
|
37964
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
37965
|
+
* { query: 'hello' },
|
|
37966
|
+
* response => merge(messages, response.data),
|
|
37967
|
+
* );
|
|
37968
|
+
* ```
|
|
37969
|
+
*
|
|
37970
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
37971
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
37972
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
37973
|
+
*
|
|
37974
|
+
* @param params Search parameters. `query` is required.
|
|
37975
|
+
* @param callback Called whenever new data are available.
|
|
37976
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
37977
|
+
*
|
|
37978
|
+
* @category Message Live Collection
|
|
37979
|
+
*/
|
|
37980
|
+
const searchMessage = (params, callback) => {
|
|
37981
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
37982
|
+
throw new Error('Query is required for message search');
|
|
37983
|
+
}
|
|
37984
|
+
const { log, cache } = getActiveClient();
|
|
37985
|
+
if (!cache) {
|
|
37986
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37987
|
+
}
|
|
37988
|
+
const timestamp = Date.now();
|
|
37989
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
37990
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
37991
|
+
const disposers = controller.startSubscription();
|
|
37992
|
+
const cacheKey = controller.getCacheKey();
|
|
37993
|
+
disposers.push(() => {
|
|
37994
|
+
dropFromCache(cacheKey);
|
|
37995
|
+
});
|
|
37996
|
+
return () => {
|
|
37997
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
37998
|
+
disposers.forEach(fn => fn());
|
|
37999
|
+
};
|
|
38000
|
+
};
|
|
38001
|
+
/* end_public_function */
|
|
38002
|
+
|
|
36853
38003
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
36854
38004
|
__proto__: null,
|
|
36855
38005
|
createMessage: createMessage,
|
|
@@ -36875,6 +38025,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
36875
38025
|
onMessageFetched: onMessageFetched,
|
|
36876
38026
|
getMessage: getMessage,
|
|
36877
38027
|
getMessages: getMessages,
|
|
38028
|
+
searchMessage: searchMessage,
|
|
36878
38029
|
convertFromRaw: convertFromRaw$1,
|
|
36879
38030
|
prepareMessagePayload: prepareMessagePayload,
|
|
36880
38031
|
convertParams: convertParams,
|
|
@@ -37722,6 +38873,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
37722
38873
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
37723
38874
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
37724
38875
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
38876
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
37725
38877
|
].includes(action)) {
|
|
37726
38878
|
if (Array.isArray(payload)) {
|
|
37727
38879
|
collection.data = [
|
|
@@ -37731,6 +38883,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
37731
38883
|
else
|
|
37732
38884
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
37733
38885
|
}
|
|
38886
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
38887
|
+
const ids = Array.isArray(payload)
|
|
38888
|
+
? payload.map(getResolver('channel'))
|
|
38889
|
+
: [getResolver('channel')(payload)];
|
|
38890
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
38891
|
+
}
|
|
37734
38892
|
pushToCache(this.cacheKey, collection);
|
|
37735
38893
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37736
38894
|
};
|
|
@@ -37997,6 +39155,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
37997
39155
|
},
|
|
37998
39156
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
37999
39157
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
39158
|
+
{
|
|
39159
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
39160
|
+
const channels = payload.archives
|
|
39161
|
+
.map(archive => {
|
|
39162
|
+
var _a;
|
|
39163
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39164
|
+
})
|
|
39165
|
+
.filter((c) => Boolean(c));
|
|
39166
|
+
if (channels.length > 0)
|
|
39167
|
+
reactor(channels);
|
|
39168
|
+
}),
|
|
39169
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
39170
|
+
},
|
|
39171
|
+
{
|
|
39172
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
39173
|
+
const channels = payload.archives
|
|
39174
|
+
.map(archive => {
|
|
39175
|
+
var _a;
|
|
39176
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39177
|
+
})
|
|
39178
|
+
.filter((c) => Boolean(c));
|
|
39179
|
+
if (channels.length > 0)
|
|
39180
|
+
reactor(channels);
|
|
39181
|
+
}),
|
|
39182
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
39183
|
+
},
|
|
38000
39184
|
{
|
|
38001
39185
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
38002
39186
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -38350,6 +39534,192 @@ const getTotalChannelsUnread = (callback) => {
|
|
|
38350
39534
|
};
|
|
38351
39535
|
};
|
|
38352
39536
|
|
|
39537
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
39538
|
+
async getRequest(queryParams, token) {
|
|
39539
|
+
var _a, _b;
|
|
39540
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
39541
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
39542
|
+
if (pageIndex === 0) {
|
|
39543
|
+
await getArchivedChannelIds();
|
|
39544
|
+
}
|
|
39545
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
39546
|
+
const archives = cached
|
|
39547
|
+
.map(entry => entry.data)
|
|
39548
|
+
.slice()
|
|
39549
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
39550
|
+
const start = pageIndex * limit;
|
|
39551
|
+
const end = start + limit;
|
|
39552
|
+
const slice = archives.slice(start, end);
|
|
39553
|
+
const hasMore = end < archives.length;
|
|
39554
|
+
if (slice.length > 0) {
|
|
39555
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
39556
|
+
}
|
|
39557
|
+
return {
|
|
39558
|
+
archives: slice,
|
|
39559
|
+
paging: {
|
|
39560
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
39561
|
+
previous: undefined,
|
|
39562
|
+
},
|
|
39563
|
+
};
|
|
39564
|
+
}
|
|
39565
|
+
}
|
|
39566
|
+
|
|
39567
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
39568
|
+
constructor(query, cacheKey, notifyChange) {
|
|
39569
|
+
super(query, cacheKey);
|
|
39570
|
+
this.notifyChange = notifyChange;
|
|
39571
|
+
}
|
|
39572
|
+
async saveToMainDB(_response) {
|
|
39573
|
+
//
|
|
39574
|
+
}
|
|
39575
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39576
|
+
var _a, _b;
|
|
39577
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
39578
|
+
if (refresh) {
|
|
39579
|
+
pushToCache(this.cacheKey, {
|
|
39580
|
+
data: channelIds,
|
|
39581
|
+
params: {},
|
|
39582
|
+
});
|
|
39583
|
+
return;
|
|
39584
|
+
}
|
|
39585
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39586
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39587
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
39588
|
+
? [...new Set([...channelIds, ...existing])]
|
|
39589
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
39590
|
+
}
|
|
39591
|
+
reactor(action) {
|
|
39592
|
+
return (channelIds) => {
|
|
39593
|
+
var _a;
|
|
39594
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39595
|
+
if (!collection)
|
|
39596
|
+
return;
|
|
39597
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
39598
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
39599
|
+
collection.data = [...channelIds, ...filtered];
|
|
39600
|
+
}
|
|
39601
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
39602
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
39603
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
39604
|
+
}
|
|
39605
|
+
pushToCache(this.cacheKey, collection);
|
|
39606
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
39607
|
+
};
|
|
39608
|
+
}
|
|
39609
|
+
subscribeRTE(createSubscriber) {
|
|
39610
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
39611
|
+
}
|
|
39612
|
+
}
|
|
39613
|
+
|
|
39614
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
39615
|
+
constructor(query, callback) {
|
|
39616
|
+
const queryStreamId = hash(query);
|
|
39617
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
39618
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
39619
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39620
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
39621
|
+
this.callback = callback.bind(this);
|
|
39622
|
+
this.loadPage({ initial: true });
|
|
39623
|
+
}
|
|
39624
|
+
setup() {
|
|
39625
|
+
var _a;
|
|
39626
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39627
|
+
if (!collection) {
|
|
39628
|
+
pushToCache(this.cacheKey, {
|
|
39629
|
+
data: [],
|
|
39630
|
+
params: {},
|
|
39631
|
+
});
|
|
39632
|
+
}
|
|
39633
|
+
}
|
|
39634
|
+
async persistModel(response) {
|
|
39635
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
39636
|
+
}
|
|
39637
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
39638
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
39639
|
+
}
|
|
39640
|
+
startSubscription() {
|
|
39641
|
+
return this.queryStreamController.subscribeRTE([
|
|
39642
|
+
{
|
|
39643
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
39644
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
39645
|
+
},
|
|
39646
|
+
{
|
|
39647
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
39648
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
39649
|
+
},
|
|
39650
|
+
{
|
|
39651
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
39652
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
39653
|
+
},
|
|
39654
|
+
{
|
|
39655
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
39656
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
39657
|
+
},
|
|
39658
|
+
]);
|
|
39659
|
+
}
|
|
39660
|
+
notifyChange({ origin, loading, error }) {
|
|
39661
|
+
var _a, _b;
|
|
39662
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39663
|
+
if (!collection)
|
|
39664
|
+
return;
|
|
39665
|
+
const data = (_b = collection.data
|
|
39666
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
39667
|
+
.filter((entry) => Boolean(entry))
|
|
39668
|
+
.map(({ data: channel }) => channel)
|
|
39669
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
39670
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
39671
|
+
return;
|
|
39672
|
+
this.callback({
|
|
39673
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
39674
|
+
data,
|
|
39675
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
39676
|
+
loading,
|
|
39677
|
+
error,
|
|
39678
|
+
});
|
|
39679
|
+
}
|
|
39680
|
+
}
|
|
39681
|
+
|
|
39682
|
+
/* begin_public_function
|
|
39683
|
+
id: channel.archive.collection
|
|
39684
|
+
*/
|
|
39685
|
+
/**
|
|
39686
|
+
* ```js
|
|
39687
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
39688
|
+
*
|
|
39689
|
+
* let channels = []
|
|
39690
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
39691
|
+
* ```
|
|
39692
|
+
*
|
|
39693
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
39694
|
+
*
|
|
39695
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
39696
|
+
* archive list takes no other filters).
|
|
39697
|
+
* @param callback the function to call when new data are available
|
|
39698
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
39699
|
+
* stop observing.
|
|
39700
|
+
*
|
|
39701
|
+
* @category Channel Live Collection
|
|
39702
|
+
*/
|
|
39703
|
+
const getArchivedChannels = (params, callback) => {
|
|
39704
|
+
const { log, cache } = getActiveClient();
|
|
39705
|
+
if (!cache) {
|
|
39706
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
39707
|
+
}
|
|
39708
|
+
const timestamp = Date.now();
|
|
39709
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
39710
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
39711
|
+
const disposers = controller.startSubscription();
|
|
39712
|
+
const cacheKey = controller.getCacheKey();
|
|
39713
|
+
disposers.push(() => {
|
|
39714
|
+
dropFromCache(cacheKey);
|
|
39715
|
+
});
|
|
39716
|
+
return () => {
|
|
39717
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
39718
|
+
disposers.forEach(fn => fn());
|
|
39719
|
+
};
|
|
39720
|
+
};
|
|
39721
|
+
/* end_public_function */
|
|
39722
|
+
|
|
38353
39723
|
/* begin_public_function
|
|
38354
39724
|
id: channel.member.add
|
|
38355
39725
|
*/
|
|
@@ -38481,7 +39851,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
38481
39851
|
channelId: this.query.channelId,
|
|
38482
39852
|
userId: channelMember.userId,
|
|
38483
39853
|
});
|
|
38484
|
-
|
|
39854
|
+
const membershipFilter = this.query.memberships;
|
|
39855
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
39856
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
38485
39857
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
38486
39858
|
}
|
|
38487
39859
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -38817,6 +40189,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
38817
40189
|
const cachedAt = client.cache && Date.now();
|
|
38818
40190
|
if (client.cache)
|
|
38819
40191
|
ingestInCache(preparedPayload, { cachedAt });
|
|
40192
|
+
fireEvent('channel.banned', payload);
|
|
38820
40193
|
return {
|
|
38821
40194
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
38822
40195
|
cachedAt,
|
|
@@ -38851,6 +40224,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
38851
40224
|
const cachedAt = client.cache && Date.now();
|
|
38852
40225
|
if (client.cache)
|
|
38853
40226
|
ingestInCache(preparedPayload, { cachedAt });
|
|
40227
|
+
fireEvent('channel.unbanned', payload);
|
|
38854
40228
|
const { channelUsers } = preparedPayload;
|
|
38855
40229
|
return {
|
|
38856
40230
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -38879,6 +40253,7 @@ const MUTE_FOREVER = -1;
|
|
|
38879
40253
|
* @async
|
|
38880
40254
|
* */
|
|
38881
40255
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
40256
|
+
var _a;
|
|
38882
40257
|
const client = getActiveClient();
|
|
38883
40258
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
38884
40259
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -38886,6 +40261,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
38886
40261
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
38887
40262
|
});
|
|
38888
40263
|
const { success } = data;
|
|
40264
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
40265
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
40266
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
40267
|
+
fireEvent('channel.setMutedUsers', {
|
|
40268
|
+
channelId,
|
|
40269
|
+
userIds,
|
|
40270
|
+
muteTimeout,
|
|
40271
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
40272
|
+
});
|
|
38889
40273
|
return success;
|
|
38890
40274
|
};
|
|
38891
40275
|
/* end_public_function */
|
|
@@ -38908,6 +40292,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
38908
40292
|
* @async
|
|
38909
40293
|
* */
|
|
38910
40294
|
const unmuteMembers = async (channelId, userIds) => {
|
|
40295
|
+
var _a;
|
|
38911
40296
|
const client = getActiveClient();
|
|
38912
40297
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
38913
40298
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -38915,6 +40300,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
38915
40300
|
mutePeriod: 0,
|
|
38916
40301
|
});
|
|
38917
40302
|
const { success } = data;
|
|
40303
|
+
fireEvent('channel.setMutedUsers', {
|
|
40304
|
+
channelId,
|
|
40305
|
+
userIds,
|
|
40306
|
+
muteTimeout: new Date(0).toISOString(),
|
|
40307
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
40308
|
+
});
|
|
38918
40309
|
return success;
|
|
38919
40310
|
};
|
|
38920
40311
|
/* end_public_function */
|
|
@@ -38941,6 +40332,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38941
40332
|
leaveChannel: leaveChannel,
|
|
38942
40333
|
muteChannel: muteChannel,
|
|
38943
40334
|
unmuteChannel: unmuteChannel,
|
|
40335
|
+
archiveChannel: archiveChannel,
|
|
40336
|
+
unarchiveChannel: unarchiveChannel,
|
|
40337
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
38944
40338
|
onChannelCreated: onChannelCreated,
|
|
38945
40339
|
onChannelUpdated: onChannelUpdated,
|
|
38946
40340
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -38953,9 +40347,12 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38953
40347
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
38954
40348
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
38955
40349
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
40350
|
+
onChannelArchived: onChannelArchived,
|
|
40351
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
38956
40352
|
getChannel: getChannel,
|
|
38957
40353
|
getChannels: getChannels,
|
|
38958
40354
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
40355
|
+
getArchivedChannels: getArchivedChannels,
|
|
38959
40356
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
38960
40357
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
38961
40358
|
convertFromRaw: convertFromRaw,
|
|
@@ -42851,7 +44248,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42851
44248
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
42852
44249
|
}
|
|
42853
44250
|
startSubscription() {
|
|
42854
|
-
|
|
44251
|
+
const disposers = this.queryStreamController.subscribeRTE([
|
|
42855
44252
|
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
42856
44253
|
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
42857
44254
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
@@ -42864,6 +44261,11 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42864
44261
|
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
42865
44262
|
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
42866
44263
|
]);
|
|
44264
|
+
if (this.query.excludeBlockUserComments) {
|
|
44265
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44266
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
44267
|
+
}
|
|
44268
|
+
return disposers;
|
|
42867
44269
|
}
|
|
42868
44270
|
notifyChange({ origin, loading, error }) {
|
|
42869
44271
|
var _a, _b;
|
|
@@ -42916,6 +44318,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42916
44318
|
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); }); });
|
|
42917
44319
|
}
|
|
42918
44320
|
}
|
|
44321
|
+
if (this.query.excludeBlockUserComments) {
|
|
44322
|
+
comments = filterCommentsByBlockUsers(comments);
|
|
44323
|
+
}
|
|
42919
44324
|
switch (this.query.sortBy) {
|
|
42920
44325
|
case 'firstCreated':
|
|
42921
44326
|
comments = comments.sort(sortByFirstCreated);
|
|
@@ -44001,13 +45406,218 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
44001
45406
|
};
|
|
44002
45407
|
/* end_public_function */
|
|
44003
45408
|
|
|
45409
|
+
/**
|
|
45410
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
45411
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
45412
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
45413
|
+
*
|
|
45414
|
+
* @category Errors
|
|
45415
|
+
*/
|
|
45416
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
45417
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
45418
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
45419
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
45420
|
+
}
|
|
45421
|
+
}
|
|
45422
|
+
|
|
45423
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
45424
|
+
constructor(query) {
|
|
45425
|
+
super(query);
|
|
45426
|
+
this.checkedDisk = false;
|
|
45427
|
+
this.cursor = CursorController.current();
|
|
45428
|
+
}
|
|
45429
|
+
async getRequest(_queryParams, token) {
|
|
45430
|
+
let effectiveToken = token;
|
|
45431
|
+
if (!effectiveToken && !this.checkedDisk && this.cursor) {
|
|
45432
|
+
this.checkedDisk = true;
|
|
45433
|
+
const stored = await this.cursor.get();
|
|
45434
|
+
if (stored && !CursorController.isExpired(stored.expiredAt)) {
|
|
45435
|
+
effectiveToken = stored.cursor;
|
|
45436
|
+
}
|
|
45437
|
+
else if (stored) {
|
|
45438
|
+
await this.cursor.clear();
|
|
45439
|
+
}
|
|
45440
|
+
}
|
|
45441
|
+
const options = {
|
|
45442
|
+
limit: COLLECTION_DEFAULT_PAGINATION_SIZE,
|
|
45443
|
+
};
|
|
45444
|
+
if (effectiveToken)
|
|
45445
|
+
options.token = effectiveToken;
|
|
45446
|
+
let queryResponse;
|
|
45447
|
+
try {
|
|
45448
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options } }));
|
|
45449
|
+
}
|
|
45450
|
+
catch (error) {
|
|
45451
|
+
if (error instanceof ASCApiError && error.code === 400300 /* Amity.ServerError.FORBIDDEN */) {
|
|
45452
|
+
throw new AmityForYouFeedDisabledError();
|
|
45453
|
+
}
|
|
45454
|
+
const recoverable = error instanceof ASCApiError && error.code === 400322 /* Amity.ServerError.FEED_SNAPSHOT_EXPIRED */;
|
|
45455
|
+
if (recoverable && effectiveToken !== undefined) {
|
|
45456
|
+
if (this.cursor)
|
|
45457
|
+
await this.cursor.clear();
|
|
45458
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } } }));
|
|
45459
|
+
}
|
|
45460
|
+
else {
|
|
45461
|
+
throw error;
|
|
45462
|
+
}
|
|
45463
|
+
}
|
|
45464
|
+
await this.persistCursor(queryResponse);
|
|
45465
|
+
return queryResponse;
|
|
45466
|
+
}
|
|
45467
|
+
async persistCursor(response) {
|
|
45468
|
+
var _a, _b;
|
|
45469
|
+
if (!this.cursor)
|
|
45470
|
+
return;
|
|
45471
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
45472
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
45473
|
+
if (!cursor || !expiredAtIso)
|
|
45474
|
+
return;
|
|
45475
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
45476
|
+
if (Number.isNaN(expiredAt))
|
|
45477
|
+
return;
|
|
45478
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
45479
|
+
}
|
|
45480
|
+
}
|
|
45481
|
+
|
|
45482
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
45483
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
45484
|
+
super(query, cacheKey);
|
|
45485
|
+
this.notifyChange = notifyChange;
|
|
45486
|
+
this.preparePayload = preparePayload;
|
|
45487
|
+
}
|
|
45488
|
+
async saveToMainDB(response) {
|
|
45489
|
+
const processedPayload = await this.preparePayload(response);
|
|
45490
|
+
const client = getActiveClient();
|
|
45491
|
+
const cachedAt = client.cache && Date.now();
|
|
45492
|
+
if (client.cache)
|
|
45493
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
45494
|
+
}
|
|
45495
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
45496
|
+
var _a, _b;
|
|
45497
|
+
if (refresh) {
|
|
45498
|
+
pushToCache(this.cacheKey, {
|
|
45499
|
+
data: response.posts.map(getResolver('post')),
|
|
45500
|
+
});
|
|
45501
|
+
}
|
|
45502
|
+
else {
|
|
45503
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45504
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
45505
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
45506
|
+
}
|
|
45507
|
+
}
|
|
45508
|
+
reactor(action) {
|
|
45509
|
+
return (post) => {
|
|
45510
|
+
var _a;
|
|
45511
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45512
|
+
if (!collection)
|
|
45513
|
+
return;
|
|
45514
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
45515
|
+
return;
|
|
45516
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
45517
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
45518
|
+
}
|
|
45519
|
+
pushToCache(this.cacheKey, collection);
|
|
45520
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
45521
|
+
};
|
|
45522
|
+
}
|
|
45523
|
+
subscribeRTE(createSubscriber) {
|
|
45524
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
45525
|
+
}
|
|
45526
|
+
}
|
|
45527
|
+
|
|
45528
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
45529
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
45530
|
+
constructor(callback) {
|
|
45531
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
45532
|
+
const query = {};
|
|
45533
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
45534
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
45535
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
45536
|
+
this.callback = callback.bind(this);
|
|
45537
|
+
this.loadPage({ initial: true });
|
|
45538
|
+
}
|
|
45539
|
+
setup() {
|
|
45540
|
+
var _a;
|
|
45541
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45542
|
+
if (!collection)
|
|
45543
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
45544
|
+
}
|
|
45545
|
+
async persistModel(payload) {
|
|
45546
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
45547
|
+
}
|
|
45548
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
45549
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
45550
|
+
}
|
|
45551
|
+
startSubscription() {
|
|
45552
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
45553
|
+
}
|
|
45554
|
+
notifyChange({ origin, loading, error }) {
|
|
45555
|
+
var _a, _b;
|
|
45556
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45557
|
+
if (!collection)
|
|
45558
|
+
return;
|
|
45559
|
+
const data = ((_b = collection.data
|
|
45560
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
45561
|
+
.filter(isNonNullable)
|
|
45562
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
45563
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
45564
|
+
return;
|
|
45565
|
+
this.callback({
|
|
45566
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
45567
|
+
data,
|
|
45568
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
45569
|
+
loading,
|
|
45570
|
+
error,
|
|
45571
|
+
});
|
|
45572
|
+
}
|
|
45573
|
+
}
|
|
45574
|
+
|
|
45575
|
+
/* begin_public_function
|
|
45576
|
+
id: feed.query.for_you_feed
|
|
45577
|
+
*/
|
|
45578
|
+
/**
|
|
45579
|
+
* ```js
|
|
45580
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
45581
|
+
*
|
|
45582
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
45583
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
45584
|
+
* })
|
|
45585
|
+
* ```
|
|
45586
|
+
*
|
|
45587
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
45588
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
45589
|
+
*
|
|
45590
|
+
* @param callback the function to call when new data is available
|
|
45591
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
45592
|
+
*
|
|
45593
|
+
* @category Posts Live Collection
|
|
45594
|
+
*/
|
|
45595
|
+
const getForYouFeed = (callback) => {
|
|
45596
|
+
const { log, cache } = getActiveClient();
|
|
45597
|
+
if (!cache)
|
|
45598
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
45599
|
+
const timestamp = Date.now();
|
|
45600
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
45601
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
45602
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
45603
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
45604
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
45605
|
+
return () => {
|
|
45606
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
45607
|
+
disposers.forEach(fn => fn());
|
|
45608
|
+
};
|
|
45609
|
+
};
|
|
45610
|
+
/* end_public_function */
|
|
45611
|
+
|
|
44004
45612
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
44005
45613
|
__proto__: null,
|
|
44006
45614
|
queryGlobalFeed: queryGlobalFeed,
|
|
44007
45615
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
44008
45616
|
getGlobalFeed: getGlobalFeed,
|
|
44009
45617
|
getUserFeed: getUserFeed,
|
|
44010
|
-
getCommunityFeed: getCommunityFeed
|
|
45618
|
+
getCommunityFeed: getCommunityFeed,
|
|
45619
|
+
getForYouFeed: getForYouFeed,
|
|
45620
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
44011
45621
|
});
|
|
44012
45622
|
|
|
44013
45623
|
/* begin_public_function
|
|
@@ -45020,7 +46630,12 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
45020
46630
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
45021
46631
|
}
|
|
45022
46632
|
startSubscription() {
|
|
45023
|
-
|
|
46633
|
+
const disposers = this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
46634
|
+
if (this.query.excludeBlockUserPosts) {
|
|
46635
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46636
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
46637
|
+
}
|
|
46638
|
+
return disposers;
|
|
45024
46639
|
}
|
|
45025
46640
|
notifyChange({ origin, loading, error }) {
|
|
45026
46641
|
var _a, _b;
|
|
@@ -45066,6 +46681,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
45066
46681
|
const sortBy = this.query.sortBy || 'lastCreated';
|
|
45067
46682
|
posts = posts.filter(post => !exceedsUntilAtBoundary(post.createdAt, validatedUntilAt, sortBy));
|
|
45068
46683
|
}
|
|
46684
|
+
if (this.query.excludeBlockUserPosts) {
|
|
46685
|
+
posts = filterPostsByBlockUsers(posts);
|
|
46686
|
+
}
|
|
45069
46687
|
switch (this.query.sortBy) {
|
|
45070
46688
|
case 'firstCreated':
|
|
45071
46689
|
posts = posts.sort(sortByFirstCreated);
|
|
@@ -51731,4 +53349,4 @@ class AmityAttachmentProductTags {
|
|
|
51731
53349
|
}
|
|
51732
53350
|
}
|
|
51733
53351
|
|
|
51734
|
-
export { API_REGIONS, index$5 as AdRepository, AmityAttachmentProductTags, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AnalyticsSourceTypeEnum, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, SearchUsersByEnum, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|
|
53352
|
+
export { API_REGIONS, index$5 as AdRepository, AmityAttachmentProductTags, AmityChannelNotificationModeEnum, AmityCommunityType, AmityEventOrderOption, AmityEventOriginType, AmityEventResponseStatus, AmityEventSortOption, AmityEventStatus, AmityEventType, AmitySharableContentType, AnalyticsSourceTypeEnum, index$f as CategoryRepository, index$j as ChannelRepository, index$s as Client, index$e as CommentRepository, CommunityNotificationEventNameEnum, CommunityPostSettingMaps, CommunityPostSettings, index$g as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$1 as EventRepository, FeedDataTypeEnum, index$d as FeedRepository, FeedSortByEnum, FeedSourceEnum, FeedTypeEnum, FileAccessTypeEnum, index$p as FileRepository, FileType, GET_WATCHER_URLS, index$3 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTargetTypeEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index$2 as LiveReactionRepository, index$7 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$n as MessageRepository, NotificationRolesFilterTypeEnum, NotificationSettingsLevelEnum, index$8 as PollRepository, PostContentType, index$b as PostRepository, PostStructureType, index as ProductRepository, index$o as ReactionRepository, index$9 as RoomPresenceRepository, index$c as RoomRepository, SearchUsersByEnum, index$6 as StoryRepository, index$a as StreamRepository, index$m as SubChannelRepository, SubscriptionLevels, UserNotificationModuleNameEnum, index$q as UserRepository, UserTypeEnum, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, exceedsUntilAtBoundary, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, filterByUntilAt, filterCommentsByBlockUsers, filterPostsByBlockUsers, getBlockUsersId, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkId, getNetworkTopic, getPostTopic, getRole, getRoomStreamerTopic, getRoomWatcherTopic, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$4 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, validateUntilAt, wipeCache };
|