@amityco/ts-sdk 7.22.0 → 7.22.1-3c040f58.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@types/core/errors.d.ts +2 -1
- package/dist/@types/core/errors.d.ts.map +1 -1
- package/dist/@types/core/events.d.ts +7 -1
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/model.d.ts +4 -0
- package/dist/@types/core/model.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +16 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/transport.d.ts +1 -0
- package/dist/@types/core/transport.d.ts.map +1 -1
- package/dist/@types/domains/analytics.d.ts +3 -2
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/block.d.ts +5 -0
- package/dist/@types/domains/block.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +20 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +8 -2
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +1 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/feed.d.ts +14 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/message.d.ts +16 -0
- package/dist/@types/domains/message.d.ts.map +1 -1
- package/dist/@types/domains/notificationSettings.d.ts +101 -0
- package/dist/@types/domains/notificationSettings.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +2 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/sharableContentType.d.ts +9 -0
- package/dist/@types/domains/sharableContentType.d.ts.map +1 -0
- package/dist/@types/index.d.ts +3 -1
- package/dist/@types/index.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +2 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsService.d.ts +1 -0
- package/dist/analytic/service/analytic/AnalyticsService.d.ts.map +1 -1
- package/dist/channelRepository/api/archiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/archiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts +13 -0
- package/dist/channelRepository/api/getArchivedChannelIds.d.ts.map +1 -0
- package/dist/channelRepository/api/index.d.ts +3 -0
- package/dist/channelRepository/api/index.d.ts.map +1 -1
- package/dist/channelRepository/api/unarchiveChannel.d.ts +16 -0
- package/dist/channelRepository/api/unarchiveChannel.d.ts.map +1 -0
- package/dist/channelRepository/api/updateChannel.d.ts +1 -1
- package/dist/channelRepository/api/updateChannel.d.ts.map +1 -1
- package/dist/channelRepository/channelMembership/observers/getMembers/ChannelMemberQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/banMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/muteMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unbanMembers.d.ts.map +1 -1
- package/dist/channelRepository/channelModeration/api/unmuteMembers.d.ts.map +1 -1
- package/dist/channelRepository/events/index.d.ts +2 -0
- package/dist/channelRepository/events/index.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelArchived.d.ts +10 -0
- package/dist/channelRepository/events/onChannelArchived.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelUnarchived.d.ts +11 -0
- package/dist/channelRepository/events/onChannelUnarchived.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts +12 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelLiveCollectionController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts +11 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelPaginationController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts +13 -0
- package/dist/channelRepository/observers/getArchivedChannels/ArchivedChannelQueryStreamController.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts +20 -0
- package/dist/channelRepository/observers/getArchivedChannels/getArchivedChannels.d.ts.map +1 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts +2 -0
- package/dist/channelRepository/observers/getArchivedChannels/index.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelQueryStreamController.d.ts.map +1 -1
- package/dist/channelRepository/observers/index.d.ts +1 -0
- package/dist/channelRepository/observers/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/prepareChannelPayload.d.ts.map +1 -1
- package/dist/client/api/autoSubscription.d.ts +50 -0
- package/dist/client/api/autoSubscription.d.ts.map +1 -0
- package/dist/client/api/getShareableLinkConfiguration.d.ts +2 -2
- package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +3 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/notifications.d.ts +27 -0
- package/dist/client/api/notifications.d.ts.map +1 -0
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/client/api/tests/ShareableLinkConfiguration.test.d.ts +2 -0
- package/dist/client/api/tests/ShareableLinkConfiguration.test.d.ts.map +1 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts +2 -0
- package/dist/client/api/tests/notifications.integration.test.d.ts.map +1 -0
- package/dist/client/services/ReadReceiptSync/readReceiptSyncEngine.d.ts.map +1 -1
- package/dist/client/utils/autoSubscriptionManager.d.ts +41 -0
- package/dist/client/utils/autoSubscriptionManager.d.ts.map +1 -0
- package/dist/client/utils/subscribeGlobalTopic.d.ts +6 -1
- package/dist/client/utils/subscribeGlobalTopic.d.ts.map +1 -1
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts +2 -0
- package/dist/client/utils/tests/autoSubscriptionManager.test.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/integrations/getCommentsExcludeBlockUser.integration.test.d.ts.map +1 -0
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/model/idResolvers.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/core/query/filtering.d.ts +32 -0
- package/dist/core/query/filtering.d.ts.map +1 -1
- package/dist/core/query/paging.d.ts +1 -0
- package/dist/core/query/paging.d.ts.map +1 -1
- package/dist/core/subscription.d.ts +3 -0
- package/dist/core/subscription.d.ts.map +1 -1
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts +13 -0
- package/dist/feedRepository/errors/AmityForYouFeedDisabledError.d.ts.map +1 -0
- package/dist/feedRepository/index.d.ts +2 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts +17 -0
- package/dist/feedRepository/observers/getForYouFeed/CursorController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getForYouFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts +12 -0
- package/dist/feedRepository/observers/getForYouFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getForYouFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts +19 -0
- package/dist/feedRepository/observers/getForYouFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +1 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/integration/getForYouFeed.integration.test.d.ts.map +1 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts +2 -0
- package/dist/feedRepository/observers/tests/unit/CursorController.test.d.ts.map +1 -0
- package/dist/index.cjs.js +1841 -218
- package/dist/index.esm.js +1838 -219
- package/dist/index.umd.js +3 -3
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messagePreview/utils/updateChannelMessagePreviewCache.d.ts.map +1 -1
- package/dist/messageRepository/events/onMessageCreated.d.ts.map +1 -1
- package/dist/messageRepository/observers/index.d.ts +1 -0
- package/dist/messageRepository/observers/index.d.ts.map +1 -1
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts +12 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageLiveCollectionController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts +10 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessagePaginationController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts +8 -0
- package/dist/messageRepository/observers/searchMessage/SearchMessageQueryStreamController.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts +2 -0
- package/dist/messageRepository/observers/searchMessage/index.d.ts.map +1 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts +24 -0
- package/dist/messageRepository/observers/searchMessage/searchMessage.d.ts.map +1 -0
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts +2 -0
- package/dist/postRepository/observers/tests/getPostsExcludeBlockUser.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts +2 -0
- package/dist/postRepository/tests/integration/postAnalytics.integration.test.d.ts.map +1 -0
- package/dist/postRepository/tests/integration/setup.d.ts +6 -0
- package/dist/postRepository/tests/integration/setup.d.ts.map +1 -0
- package/dist/reactionRepository/internalApi/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/internalApi/removeReaction.d.ts.map +1 -1
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts +1 -0
- package/dist/streamRepository/observers/getStreams/GetStreamsPageController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserLiveCollectionController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts +4 -3
- package/dist/userRepository/observers/getBlockedUsers/BlockedUserQueryStreamController.d.ts.map +1 -1
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts +13 -0
- package/dist/userRepository/observers/getBlockingUsers/LiveCollectionController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers/PaginationController.d.ts +5 -0
- package/dist/userRepository/observers/getBlockingUsers/PaginationController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers/QueryStreamController.d.ts +16 -0
- package/dist/userRepository/observers/getBlockingUsers/QueryStreamController.d.ts.map +1 -0
- package/dist/userRepository/observers/getBlockingUsers.d.ts +17 -0
- package/dist/userRepository/observers/getBlockingUsers.d.ts.map +1 -0
- package/dist/userRepository/observers/index.d.ts +1 -0
- package/dist/userRepository/observers/index.d.ts.map +1 -1
- package/dist/userRepository/observers/tests/integrations/getBlockingUsers.integration.test.d.ts +2 -0
- package/dist/userRepository/observers/tests/integrations/getBlockingUsers.integration.test.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/enum/index.d.ts +5 -0
- package/dist/userRepository/relationship/block/enum/index.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/index.d.ts +3 -0
- package/dist/userRepository/relationship/block/events/index.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/onUserDidBlock.d.ts +20 -0
- package/dist/userRepository/relationship/block/events/onUserDidBlock.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/events/onUserDidUnblock.d.ts +20 -0
- package/dist/userRepository/relationship/block/events/onUserDidUnblock.d.ts.map +1 -0
- package/dist/userRepository/relationship/block/index.d.ts +1 -0
- package/dist/userRepository/relationship/block/index.d.ts.map +1 -1
- package/dist/userRepository/relationship/block/utils/createBlockEventSubscriber.d.ts +11 -0
- package/dist/userRepository/relationship/block/utils/createBlockEventSubscriber.d.ts.map +1 -0
- package/dist/userRepository/utils/prepareBlockingUserPayload.d.ts +2 -0
- package/dist/userRepository/utils/prepareBlockingUserPayload.d.ts.map +1 -0
- package/dist/utils/constants.d.ts +4 -0
- package/dist/utils/constants.d.ts.map +1 -1
- package/dist/utils/linkedObject/channelLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/tests/dummy/community.d.ts +2 -0
- package/dist/utils/tests/dummy/community.d.ts.map +1 -1
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.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
|
|
@@ -1558,6 +1674,7 @@ const createEventSubscriber = (client, namespace, event, fn) => {
|
|
|
1558
1674
|
log(`${namespace}(tmpid: ${timestamp}) > listen`);
|
|
1559
1675
|
const handler = (...payload) => {
|
|
1560
1676
|
log(`${namespace}(tmpid: ${timestamp}) > trigger`, payload);
|
|
1677
|
+
console.log(payload);
|
|
1561
1678
|
try {
|
|
1562
1679
|
fn(...payload);
|
|
1563
1680
|
}
|
|
@@ -1833,13 +1950,13 @@ class NetworkActivitiesWatcher {
|
|
|
1833
1950
|
this._listener.clear();
|
|
1834
1951
|
}
|
|
1835
1952
|
}
|
|
1836
|
-
let instance$
|
|
1953
|
+
let instance$a;
|
|
1837
1954
|
var NetworkActivitiesWatcher$1 = {
|
|
1838
1955
|
getInstance: () => {
|
|
1839
|
-
if (!instance$
|
|
1840
|
-
instance$
|
|
1956
|
+
if (!instance$a) {
|
|
1957
|
+
instance$a = new NetworkActivitiesWatcher();
|
|
1841
1958
|
}
|
|
1842
|
-
return instance$
|
|
1959
|
+
return instance$a;
|
|
1843
1960
|
},
|
|
1844
1961
|
};
|
|
1845
1962
|
|
|
@@ -20678,18 +20795,161 @@ var mqtt$1 = {exports: {}};
|
|
|
20678
20795
|
|
|
20679
20796
|
var mqtt = /*@__PURE__*/getDefaultExportFromCjs(mqtt$1.exports);
|
|
20680
20797
|
|
|
20798
|
+
class SessionWatcher {
|
|
20799
|
+
constructor() {
|
|
20800
|
+
this._sessionState = "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */;
|
|
20801
|
+
this._listener = new Map();
|
|
20802
|
+
}
|
|
20803
|
+
onSessionStateChange(callback) {
|
|
20804
|
+
this._listener.set(callback, callback);
|
|
20805
|
+
return () => {
|
|
20806
|
+
this._listener.delete(callback);
|
|
20807
|
+
};
|
|
20808
|
+
}
|
|
20809
|
+
setSessionState(state, reason) {
|
|
20810
|
+
if (this._sessionState === state)
|
|
20811
|
+
return;
|
|
20812
|
+
this._sessionState = state;
|
|
20813
|
+
this._listener.forEach(cb => cb(state, reason));
|
|
20814
|
+
}
|
|
20815
|
+
destroy() {
|
|
20816
|
+
this._listener.clear();
|
|
20817
|
+
}
|
|
20818
|
+
}
|
|
20819
|
+
let instance$9;
|
|
20820
|
+
var SessionWatcher$1 = {
|
|
20821
|
+
getInstance: () => {
|
|
20822
|
+
if (!instance$9) {
|
|
20823
|
+
instance$9 = new SessionWatcher();
|
|
20824
|
+
}
|
|
20825
|
+
return instance$9;
|
|
20826
|
+
},
|
|
20827
|
+
};
|
|
20828
|
+
|
|
20829
|
+
/**
|
|
20830
|
+
* ```js
|
|
20831
|
+
* import { onSessionStateChange } from '@amityco/ts-sdk'
|
|
20832
|
+
* const dispose = onSessionStateChange((state: Amity.SessionStates) => {
|
|
20833
|
+
* // ...
|
|
20834
|
+
* })
|
|
20835
|
+
* ```
|
|
20836
|
+
*
|
|
20837
|
+
* Fired when any {@link Amity.Client} has a session state change
|
|
20838
|
+
*
|
|
20839
|
+
* @param callback The function to call when the event was fired
|
|
20840
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
20841
|
+
*
|
|
20842
|
+
* @category Client Events
|
|
20843
|
+
*/
|
|
20844
|
+
const onSessionStateChange = (callback) => SessionWatcher$1.getInstance().onSessionStateChange(callback);
|
|
20845
|
+
|
|
20846
|
+
/** Feature-grouped real-time handles; all default-on, toggleable per handle. */
|
|
20847
|
+
var AutoSubscription;
|
|
20848
|
+
(function (AutoSubscription) {
|
|
20849
|
+
/** SMART_CHANNEL + SMART_MESSAGE + SMART_MESSAGE_FEED — chat "smart" real-time. */
|
|
20850
|
+
AutoSubscription["CHAT"] = "chat";
|
|
20851
|
+
/** Network-wide events (e.g. global ban). */
|
|
20852
|
+
AutoSubscription["NETWORK"] = "network";
|
|
20853
|
+
/** Livestream state events. */
|
|
20854
|
+
AutoSubscription["LIVESTREAM"] = "livestream";
|
|
20855
|
+
/** Both membership wildcards (followers + followings) — block real-time. */
|
|
20856
|
+
AutoSubscription["BLOCK"] = "block";
|
|
20857
|
+
})(AutoSubscription || (AutoSubscription = {}));
|
|
20858
|
+
const TOPICS = {
|
|
20859
|
+
[AutoSubscription.NETWORK]: [getNetworkTopic],
|
|
20860
|
+
[AutoSubscription.CHAT]: [
|
|
20861
|
+
getSmartFeedChannelTopic,
|
|
20862
|
+
getSmartFeedSubChannelTopic,
|
|
20863
|
+
getSmartFeedMessageTopic,
|
|
20864
|
+
],
|
|
20865
|
+
[AutoSubscription.LIVESTREAM]: [getLiveStreamTopic],
|
|
20866
|
+
[AutoSubscription.BLOCK]: [getMyFollowersTopic, getMyFollowingsTopic],
|
|
20867
|
+
};
|
|
20868
|
+
const DEFAULT_TOPICS = [
|
|
20869
|
+
AutoSubscription.CHAT,
|
|
20870
|
+
AutoSubscription.NETWORK,
|
|
20871
|
+
AutoSubscription.LIVESTREAM,
|
|
20872
|
+
AutoSubscription.BLOCK,
|
|
20873
|
+
];
|
|
20874
|
+
const ALL_FEATURES = Object.values(AutoSubscription);
|
|
20875
|
+
/** Ref-counted, reconnect-resilient registry of the managed auto-subscriptions. */
|
|
20876
|
+
class AutoSubscriptionManager {
|
|
20877
|
+
constructor() {
|
|
20878
|
+
this.refCountByFeature = new Map();
|
|
20879
|
+
this.disposers = new Map();
|
|
20880
|
+
this.seed();
|
|
20881
|
+
}
|
|
20882
|
+
seed() {
|
|
20883
|
+
this.refCountByFeature.clear();
|
|
20884
|
+
DEFAULT_TOPICS.forEach(feature => this.refCountByFeature.set(feature, 1));
|
|
20885
|
+
}
|
|
20886
|
+
isActive(feature) {
|
|
20887
|
+
var _a;
|
|
20888
|
+
return ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) > 0;
|
|
20889
|
+
}
|
|
20890
|
+
subscribeTopics(feature) {
|
|
20891
|
+
this.unsubscribeTopics(feature);
|
|
20892
|
+
this.disposers.set(feature, TOPICS[feature].map(buildTopic => subscribeTopic(buildTopic())));
|
|
20893
|
+
}
|
|
20894
|
+
unsubscribeTopics(feature) {
|
|
20895
|
+
var _a;
|
|
20896
|
+
((_a = this.disposers.get(feature)) !== null && _a !== void 0 ? _a : []).forEach(dispose => dispose());
|
|
20897
|
+
this.disposers.delete(feature);
|
|
20898
|
+
}
|
|
20899
|
+
/** Subscribe every enabled handle's topics, converging the broker to the registry. Called on each (re)connect. */
|
|
20900
|
+
initialize() {
|
|
20901
|
+
ALL_FEATURES.forEach(feature => {
|
|
20902
|
+
if (this.isActive(feature))
|
|
20903
|
+
this.subscribeTopics(feature);
|
|
20904
|
+
});
|
|
20905
|
+
}
|
|
20906
|
+
subscribe(feature) {
|
|
20907
|
+
var _a;
|
|
20908
|
+
const next = ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) + 1;
|
|
20909
|
+
this.refCountByFeature.set(feature, next);
|
|
20910
|
+
if (next === 1)
|
|
20911
|
+
this.subscribeTopics(feature);
|
|
20912
|
+
}
|
|
20913
|
+
unsubscribe(feature) {
|
|
20914
|
+
var _a;
|
|
20915
|
+
const next = Math.max(0, ((_a = this.refCountByFeature.get(feature)) !== null && _a !== void 0 ? _a : 0) - 1);
|
|
20916
|
+
this.refCountByFeature.set(feature, next);
|
|
20917
|
+
if (next === 0)
|
|
20918
|
+
this.unsubscribeTopics(feature);
|
|
20919
|
+
}
|
|
20920
|
+
subscriptions() {
|
|
20921
|
+
return ALL_FEATURES.map(feature => ({
|
|
20922
|
+
feature,
|
|
20923
|
+
isActive: this.isActive(feature),
|
|
20924
|
+
isSystem: true,
|
|
20925
|
+
topicCount: TOPICS[feature].length,
|
|
20926
|
+
}));
|
|
20927
|
+
}
|
|
20928
|
+
reset() {
|
|
20929
|
+
ALL_FEATURES.forEach(feature => this.unsubscribeTopics(feature));
|
|
20930
|
+
this.disposers.clear();
|
|
20931
|
+
this.seed();
|
|
20932
|
+
}
|
|
20933
|
+
}
|
|
20934
|
+
let instance$8 = null;
|
|
20935
|
+
const getAutoSubscriptionManager = () => {
|
|
20936
|
+
if (!instance$8)
|
|
20937
|
+
instance$8 = new AutoSubscriptionManager();
|
|
20938
|
+
return instance$8;
|
|
20939
|
+
};
|
|
20940
|
+
/** Resets the registry to its default baseline when the session ends. */
|
|
20941
|
+
const resetAutoSubscriptionsOnLogout = () => onSessionStateChange(state => {
|
|
20942
|
+
if (state !== "established" /* Amity.SessionStates.ESTABLISHED */)
|
|
20943
|
+
getAutoSubscriptionManager().reset();
|
|
20944
|
+
});
|
|
20945
|
+
|
|
20946
|
+
/**
|
|
20947
|
+
* (Re)subscribes the managed auto-subscription registry on every (re)connect.
|
|
20948
|
+
* The hardcoded topic list was promoted to the toggleable, ref-counted registry
|
|
20949
|
+
* in {@link getAutoSubscriptionManager} — see `client.manageAutoSubscriptions`.
|
|
20950
|
+
*/
|
|
20681
20951
|
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());
|
|
20952
|
+
getAutoSubscriptionManager().initialize();
|
|
20693
20953
|
};
|
|
20694
20954
|
|
|
20695
20955
|
class OnMemoryStorage {
|
|
@@ -21225,8 +21485,12 @@ const getChannelMessagePreviewWithUser = (channel) => {
|
|
|
21225
21485
|
return Object.assign(Object.assign({}, channel), { messagePreview: messagePreviewWithUser });
|
|
21226
21486
|
};
|
|
21227
21487
|
|
|
21488
|
+
const convertDateStringToTimestamp = (dateString) => {
|
|
21489
|
+
return new Date(dateString).getTime();
|
|
21490
|
+
};
|
|
21491
|
+
|
|
21228
21492
|
const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
21229
|
-
var _a
|
|
21493
|
+
var _a;
|
|
21230
21494
|
const withMessageFeedInfo = (messagePreview) => {
|
|
21231
21495
|
var _a;
|
|
21232
21496
|
const messageFeedInfo = (_a = rawPayload.messageFeedsInfo) === null || _a === void 0 ? void 0 : _a.find(messageFeed => {
|
|
@@ -21248,10 +21512,26 @@ const updateChannelMessagePreviewCache = (rawPayload) => {
|
|
|
21248
21512
|
subChannelUpdatedAt: messageFeedInfo === null || messageFeedInfo === void 0 ? void 0 : messageFeedInfo.updatedAt,
|
|
21249
21513
|
};
|
|
21250
21514
|
};
|
|
21251
|
-
|
|
21252
|
-
|
|
21253
|
-
|
|
21254
|
-
|
|
21515
|
+
// Skip server previews older than what's cached — the cache may carry a newer
|
|
21516
|
+
// preview written by handleMessageCreated from an MQTT message that the server
|
|
21517
|
+
// payload hasn't surfaced yet. Mirrors isLastestMessageOnChannel.
|
|
21518
|
+
const newPreviews = ((_a = rawPayload.messagePreviews) !== null && _a !== void 0 ? _a : [])
|
|
21519
|
+
.map(withMessageFeedInfo)
|
|
21520
|
+
.filter(preview => {
|
|
21521
|
+
var _a;
|
|
21522
|
+
const cached = (_a = pullFromCache([
|
|
21523
|
+
'messagePreviewChannel',
|
|
21524
|
+
'get',
|
|
21525
|
+
preview.channelId,
|
|
21526
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
21527
|
+
if (!cached)
|
|
21528
|
+
return true;
|
|
21529
|
+
return (convertDateStringToTimestamp(cached.createdAt) <=
|
|
21530
|
+
convertDateStringToTimestamp(preview.createdAt));
|
|
21531
|
+
});
|
|
21532
|
+
if (newPreviews.length === 0)
|
|
21533
|
+
return;
|
|
21534
|
+
ingestInCache({ messagePreviewChannel: newPreviews });
|
|
21255
21535
|
};
|
|
21256
21536
|
|
|
21257
21537
|
const getSubChannelMessagePreview = (subChannelId) => {
|
|
@@ -21879,10 +22159,6 @@ getSubChannel$1.locally = (subChannelId) => {
|
|
|
21879
22159
|
};
|
|
21880
22160
|
};
|
|
21881
22161
|
|
|
21882
|
-
const convertDateStringToTimestamp = (dateString) => {
|
|
21883
|
-
return new Date(dateString).getTime();
|
|
21884
|
-
};
|
|
21885
|
-
|
|
21886
22162
|
const getMessagePreviewSetting$1 = async () => {
|
|
21887
22163
|
const client = getActiveClient();
|
|
21888
22164
|
return client.getMessagePreviewSetting(false);
|
|
@@ -22090,24 +22366,41 @@ const preUpdateChannelCache = (rawPayload, options = { isMessagePreviewUpdated:
|
|
|
22090
22366
|
});
|
|
22091
22367
|
};
|
|
22092
22368
|
const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
22369
|
+
var _a, _b;
|
|
22093
22370
|
const channelsUnread = [];
|
|
22094
22371
|
for (let i = 0; i < channels.length; i += 1) {
|
|
22095
22372
|
if (isUnreadCountSupport(channels[i])) {
|
|
22096
22373
|
const cacheKey = ['channelUnread', 'get', channels[i].channelId];
|
|
22097
22374
|
const channelUser = channelUsers.find(channelUser => channelUser.channelId === channels[i].channelId && channelUser.userId === currentUserId);
|
|
22098
|
-
|
|
22375
|
+
// readToSegment, lastMentionedSegment and lastSegment are monotonically non-decreasing;
|
|
22376
|
+
// prefer cached values when ahead of the server so a refetch returning stale data cannot
|
|
22377
|
+
const cached = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
22378
|
+
const lastSegment = Math.max((_b = cached === null || cached === void 0 ? void 0 : cached.lastSegment) !== null && _b !== void 0 ? _b : 0, channels[i].messageCount);
|
|
22099
22379
|
let readToSegment = null;
|
|
22100
22380
|
let lastMentionedSegment = null;
|
|
22381
|
+
let unreadCount = 0;
|
|
22101
22382
|
let isMentioned = false;
|
|
22102
22383
|
if (channelUser) {
|
|
22103
|
-
|
|
22104
|
-
|
|
22105
|
-
|
|
22106
|
-
|
|
22384
|
+
const serverRead = channelUser.readToSegment;
|
|
22385
|
+
const serverMention = channelUser.lastMentionedSegment;
|
|
22386
|
+
readToSegment =
|
|
22387
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.readToSegment) === 'number' &&
|
|
22388
|
+
(typeof serverRead !== 'number' || cached.readToSegment > serverRead)
|
|
22389
|
+
? cached.readToSegment
|
|
22390
|
+
: serverRead !== null && serverRead !== void 0 ? serverRead : null;
|
|
22391
|
+
lastMentionedSegment =
|
|
22392
|
+
typeof (cached === null || cached === void 0 ? void 0 : cached.lastMentionedSegment) === 'number' &&
|
|
22393
|
+
(typeof serverMention !== 'number' || cached.lastMentionedSegment > serverMention)
|
|
22394
|
+
? cached.lastMentionedSegment
|
|
22395
|
+
: serverMention !== null && serverMention !== void 0 ? serverMention : null;
|
|
22396
|
+
const readForCalc = readToSegment !== null && readToSegment !== void 0 ? readToSegment : 0;
|
|
22397
|
+
unreadCount = Math.max(lastSegment - readForCalc, 0);
|
|
22398
|
+
isMentioned =
|
|
22399
|
+
typeof lastMentionedSegment === 'number' && readForCalc < lastMentionedSegment;
|
|
22107
22400
|
}
|
|
22108
22401
|
const cacheChannelUnread = {
|
|
22109
22402
|
channelId: channels[i].channelId,
|
|
22110
|
-
lastSegment
|
|
22403
|
+
lastSegment,
|
|
22111
22404
|
readToSegment,
|
|
22112
22405
|
lastMentionedSegment,
|
|
22113
22406
|
unreadCount,
|
|
@@ -22117,6 +22410,8 @@ const updateChannelUnread = ({ currentUserId, channels, channelUsers, }) => {
|
|
|
22117
22410
|
pushToCache(cacheKey, cacheChannelUnread);
|
|
22118
22411
|
channelsUnread.push(cacheChannelUnread);
|
|
22119
22412
|
}
|
|
22413
|
+
}
|
|
22414
|
+
if (channelsUnread.length > 0) {
|
|
22120
22415
|
fireEvent('local.channelUnread.updated', channelsUnread);
|
|
22121
22416
|
}
|
|
22122
22417
|
};
|
|
@@ -22816,7 +23111,7 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
22816
23111
|
const client = getActiveClient();
|
|
22817
23112
|
const filter = async (payload) => {
|
|
22818
23113
|
const { channels, channelUsers } = payload;
|
|
22819
|
-
|
|
23114
|
+
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
22820
23115
|
};
|
|
22821
23116
|
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', filter);
|
|
22822
23117
|
}
|
|
@@ -22824,6 +23119,39 @@ const onChannelMemberRoleRemoved = (callback) => {
|
|
|
22824
23119
|
return () => dispose$1(callback);
|
|
22825
23120
|
};
|
|
22826
23121
|
|
|
23122
|
+
/**
|
|
23123
|
+
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
23124
|
+
*
|
|
23125
|
+
* @param callback The function to call when the event was fired
|
|
23126
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23127
|
+
*
|
|
23128
|
+
* @category Channel Events
|
|
23129
|
+
*/
|
|
23130
|
+
const onChannelArchived = (callback) => {
|
|
23131
|
+
const client = getActiveClient();
|
|
23132
|
+
const filter = async (payload) => {
|
|
23133
|
+
callback(payload);
|
|
23134
|
+
};
|
|
23135
|
+
return createEventSubscriber(client, 'onChannelArchived', 'local.channel.archived', filter);
|
|
23136
|
+
};
|
|
23137
|
+
|
|
23138
|
+
/**
|
|
23139
|
+
* Fired when a previously archived {@link Amity.Channel} has been unarchived
|
|
23140
|
+
* by the active user.
|
|
23141
|
+
*
|
|
23142
|
+
* @param callback The function to call when the event was fired
|
|
23143
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23144
|
+
*
|
|
23145
|
+
* @category Channel Events
|
|
23146
|
+
*/
|
|
23147
|
+
const onChannelUnarchived = (callback) => {
|
|
23148
|
+
const client = getActiveClient();
|
|
23149
|
+
const filter = async (payload) => {
|
|
23150
|
+
callback(payload);
|
|
23151
|
+
};
|
|
23152
|
+
return createEventSubscriber(client, 'onChannelUnarchived', 'local.channel.unarchived', filter);
|
|
23153
|
+
};
|
|
23154
|
+
|
|
22827
23155
|
const callbacks = [];
|
|
22828
23156
|
let mainDisposer = null;
|
|
22829
23157
|
const dispose = (cb) => {
|
|
@@ -22937,6 +23265,17 @@ const channelLinkedObject = (channel) => {
|
|
|
22937
23265
|
markAsRead: () => markAsRead(channel.channelInternalId),
|
|
22938
23266
|
previewMembers,
|
|
22939
23267
|
myMembership: (callback) => getMyMembership(channel.channelId, callback),
|
|
23268
|
+
get avatar() {
|
|
23269
|
+
var _a;
|
|
23270
|
+
if (!channel.avatarFileId)
|
|
23271
|
+
return undefined;
|
|
23272
|
+
const avatar = (_a = pullFromCache([
|
|
23273
|
+
'file',
|
|
23274
|
+
'get',
|
|
23275
|
+
`${channel.avatarFileId}`,
|
|
23276
|
+
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23277
|
+
return avatar;
|
|
23278
|
+
},
|
|
22940
23279
|
});
|
|
22941
23280
|
};
|
|
22942
23281
|
|
|
@@ -23035,54 +23374,6 @@ getChannelByIds$1.locally = (channelIds) => {
|
|
|
23035
23374
|
};
|
|
23036
23375
|
};
|
|
23037
23376
|
|
|
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
23377
|
const setIntervalTask = (handler, timeout) => {
|
|
23087
23378
|
const timer = setInterval(handler, timeout);
|
|
23088
23379
|
return () => clearInterval(timer);
|
|
@@ -23876,7 +24167,7 @@ class AnalyticsEventSyncer {
|
|
|
23876
24167
|
|
|
23877
24168
|
class AnalyticsEventCapturer {
|
|
23878
24169
|
constructor() {
|
|
23879
|
-
this._expireTime = 5 *
|
|
24170
|
+
this._expireTime = 5 * SECOND$1;
|
|
23880
24171
|
this._poolLimit = 1000;
|
|
23881
24172
|
this._recentViewed = {};
|
|
23882
24173
|
this._recentHighPriorityViewed = {};
|
|
@@ -23930,12 +24221,36 @@ class AnalyticsEventCapturer {
|
|
|
23930
24221
|
}
|
|
23931
24222
|
markPostAsViewed(postId) {
|
|
23932
24223
|
this.markAs({
|
|
23933
|
-
uniqueId: postId
|
|
24224
|
+
uniqueId: `post.${postId}`,
|
|
23934
24225
|
contentId: postId,
|
|
23935
24226
|
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
23936
24227
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
23937
24228
|
});
|
|
23938
24229
|
}
|
|
24230
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
24231
|
+
var _a;
|
|
24232
|
+
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
24233
|
+
const metadata = {};
|
|
24234
|
+
if (feedRenderPosition !== undefined)
|
|
24235
|
+
metadata.feedRenderPosition = feedRenderPosition;
|
|
24236
|
+
if (cached) {
|
|
24237
|
+
metadata.feedSnapshotPosition = cached.feedSnapshotPosition;
|
|
24238
|
+
metadata.feedInjectionType = cached.feedInjectionType;
|
|
24239
|
+
metadata.feedRelevanceScore = cached.feedRelevanceScore;
|
|
24240
|
+
metadata.feedPopularityScore = cached.feedPopularityScore;
|
|
24241
|
+
metadata.feedFreshnessScore = cached.feedFreshnessScore;
|
|
24242
|
+
metadata.feedAffinityScore = cached.feedAffinityScore;
|
|
24243
|
+
metadata.feedFinalScore = cached.feedFinalScore;
|
|
24244
|
+
metadata.feedMmrPenalty = cached.feedMmrPenalty;
|
|
24245
|
+
}
|
|
24246
|
+
this.markAs({
|
|
24247
|
+
uniqueId: `post.${postId}.meaningfulView`,
|
|
24248
|
+
contentId: postId,
|
|
24249
|
+
contentType: "post" /* Amity.AnalyticEventContentType.Post */,
|
|
24250
|
+
activityType: "meaningfulView" /* Amity.AnalyticEventActivityType.MeaningfulView */,
|
|
24251
|
+
metadata: Object.keys(metadata).length > 0 ? metadata : undefined,
|
|
24252
|
+
});
|
|
24253
|
+
}
|
|
23939
24254
|
markStory(story, activityType) {
|
|
23940
24255
|
if (!story.expiresAt)
|
|
23941
24256
|
return;
|
|
@@ -24075,6 +24390,12 @@ class AnalyticsEngine {
|
|
|
24075
24390
|
this._eventCapturer.markPostAsViewed(postId);
|
|
24076
24391
|
}
|
|
24077
24392
|
}
|
|
24393
|
+
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
24394
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
24395
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
24396
|
+
this._eventCapturer.markPostAsMeaningfullyViewed(postId, feedRenderPosition);
|
|
24397
|
+
}
|
|
24398
|
+
}
|
|
24078
24399
|
markStoryAsViewed(story) {
|
|
24079
24400
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
24080
24401
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */ // For case token_expired, we assume token is expired and gonna re-connect soon
|
|
@@ -24299,9 +24620,8 @@ class MessageReadReceiptSyncEngine {
|
|
|
24299
24620
|
// Step 1: Optimistic update of channelUnread.readToSegment to message.segment and update unreadCount value
|
|
24300
24621
|
const cacheKey = ['channelUnread', 'get', channelId];
|
|
24301
24622
|
const channelUnread = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24302
|
-
if (
|
|
24303
|
-
channelUnread
|
|
24304
|
-
segment > channelUnread.readToSegment) {
|
|
24623
|
+
if (channelUnread &&
|
|
24624
|
+
(typeof channelUnread.readToSegment !== 'number' || segment > channelUnread.readToSegment)) {
|
|
24305
24625
|
channelUnread.readToSegment = segment;
|
|
24306
24626
|
channelUnread.unreadCount = Math.max(channelUnread.lastSegment - segment, 0);
|
|
24307
24627
|
pushToCache(cacheKey, channelUnread);
|
|
@@ -25195,6 +25515,59 @@ var blockedUserSyncEngineOnLoginHandler = () => {
|
|
|
25195
25515
|
};
|
|
25196
25516
|
};
|
|
25197
25517
|
|
|
25518
|
+
class CursorController {
|
|
25519
|
+
constructor(networkId, userId) {
|
|
25520
|
+
this.networkId = networkId;
|
|
25521
|
+
this.userId = userId;
|
|
25522
|
+
}
|
|
25523
|
+
static current() {
|
|
25524
|
+
try {
|
|
25525
|
+
const user = getCurrentUser();
|
|
25526
|
+
if (!user)
|
|
25527
|
+
return null;
|
|
25528
|
+
const networkId = getNetworkId(user);
|
|
25529
|
+
const { userId } = user;
|
|
25530
|
+
return networkId && userId ? new CursorController(networkId, userId) : null;
|
|
25531
|
+
}
|
|
25532
|
+
catch (_a) {
|
|
25533
|
+
return null;
|
|
25534
|
+
}
|
|
25535
|
+
}
|
|
25536
|
+
static isExpired(expiredAt) {
|
|
25537
|
+
return Date.now() >= expiredAt;
|
|
25538
|
+
}
|
|
25539
|
+
static clearOnLogout() {
|
|
25540
|
+
return onSessionStateChange(state => {
|
|
25541
|
+
var _a;
|
|
25542
|
+
if (state === "terminated" /* Amity.SessionStates.TERMINATED */)
|
|
25543
|
+
(_a = CursorController.current()) === null || _a === void 0 ? void 0 : _a.clear();
|
|
25544
|
+
});
|
|
25545
|
+
}
|
|
25546
|
+
get key() {
|
|
25547
|
+
return `amity:forYouFeed:cursor:${this.networkId}:${this.userId}`;
|
|
25548
|
+
}
|
|
25549
|
+
async get() {
|
|
25550
|
+
const raw = await getItem(this.key);
|
|
25551
|
+
if (!raw)
|
|
25552
|
+
return null;
|
|
25553
|
+
try {
|
|
25554
|
+
const parsed = JSON.parse(raw);
|
|
25555
|
+
if (typeof (parsed === null || parsed === void 0 ? void 0 : parsed.cursor) !== 'string' || typeof (parsed === null || parsed === void 0 ? void 0 : parsed.expiredAt) !== 'number')
|
|
25556
|
+
return null;
|
|
25557
|
+
return { cursor: parsed.cursor, expiredAt: parsed.expiredAt };
|
|
25558
|
+
}
|
|
25559
|
+
catch (_a) {
|
|
25560
|
+
return null;
|
|
25561
|
+
}
|
|
25562
|
+
}
|
|
25563
|
+
async set(value) {
|
|
25564
|
+
await setItem(this.key, JSON.stringify(value));
|
|
25565
|
+
}
|
|
25566
|
+
async clear() {
|
|
25567
|
+
await setItem(this.key, '');
|
|
25568
|
+
}
|
|
25569
|
+
}
|
|
25570
|
+
|
|
25198
25571
|
const EVENTS = [
|
|
25199
25572
|
'disconnected',
|
|
25200
25573
|
'error',
|
|
@@ -25384,7 +25757,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
25384
25757
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
25385
25758
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
25386
25759
|
// 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());
|
|
25760
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
25388
25761
|
if (client.useLegacyUnreadCount) {
|
|
25389
25762
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
25390
25763
|
}
|
|
@@ -26083,16 +26456,13 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
26083
26456
|
}
|
|
26084
26457
|
if (client.useLegacyUnreadCount) {
|
|
26085
26458
|
rawPayload.messages.forEach(message => {
|
|
26086
|
-
var _a, _b;
|
|
26459
|
+
var _a, _b, _c;
|
|
26087
26460
|
const channelUnread = (_a = pullFromCache([
|
|
26088
26461
|
'channelUnread',
|
|
26089
26462
|
'get',
|
|
26090
26463
|
message.channelId,
|
|
26091
26464
|
])) === 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')
|
|
26465
|
+
if (!channelUnread || channelUnread.lastSegment >= message.segment)
|
|
26096
26466
|
return;
|
|
26097
26467
|
const lastSegment = message.segment;
|
|
26098
26468
|
const isMentionedInMessage = (_b = message.mentionedUsers) === null || _b === void 0 ? void 0 : _b.some(mention => {
|
|
@@ -26104,7 +26474,8 @@ const onMessageCreatedMqtt = (callback) => {
|
|
|
26104
26474
|
const lastMentionedSegment = isMentionedInMessage
|
|
26105
26475
|
? message.segment
|
|
26106
26476
|
: channelUnread.lastMentionedSegment;
|
|
26107
|
-
const
|
|
26477
|
+
const readToSegment = (_c = channelUnread.readToSegment) !== null && _c !== void 0 ? _c : 0;
|
|
26478
|
+
const updatedChannelUnread = Object.assign(Object.assign({}, channelUnread), { lastSegment, unreadCount: Math.max(lastSegment - readToSegment, 0), lastMentionedSegment, isMentioned: typeof lastMentionedSegment === 'number' && readToSegment < lastMentionedSegment });
|
|
26108
26479
|
pushToCache(['channelUnread', 'get', message.channelId], updatedChannelUnread);
|
|
26109
26480
|
fireEvent('local.channelUnread.updated', [updatedChannelUnread]);
|
|
26110
26481
|
});
|
|
@@ -26742,11 +27113,18 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
26742
27113
|
return data;
|
|
26743
27114
|
};
|
|
26744
27115
|
|
|
27116
|
+
const CONTENT_TYPE_CONFIG = {
|
|
27117
|
+
[AmitySharableContentType.POST]: { key: 'posts', placeholder: 'postId' },
|
|
27118
|
+
[AmitySharableContentType.COMMUNITY]: { key: 'communities', placeholder: 'communityId' },
|
|
27119
|
+
[AmitySharableContentType.USER]: { key: 'users', placeholder: 'userId' },
|
|
27120
|
+
[AmitySharableContentType.LIVESTREAM]: { key: 'livestream', placeholder: 'livestream' },
|
|
27121
|
+
[AmitySharableContentType.EVENT]: { key: 'events', placeholder: 'eventId' },
|
|
27122
|
+
};
|
|
26745
27123
|
/**
|
|
26746
27124
|
* ```js
|
|
26747
27125
|
* import Client from '@amityco/ts-sdk'
|
|
26748
|
-
* const
|
|
26749
|
-
* const
|
|
27126
|
+
* const config = await Client.getShareableLinkConfiguration()
|
|
27127
|
+
* const link = config.generateLink(AmitySharableContentType.EVENT, eventId)
|
|
26750
27128
|
* ```
|
|
26751
27129
|
*
|
|
26752
27130
|
* Fetches a {@link Amity.ShareableLinkConfiguration} object
|
|
@@ -26757,9 +27135,29 @@ const getLinkPreviewMetadata = async (url) => {
|
|
|
26757
27135
|
* @async
|
|
26758
27136
|
*/
|
|
26759
27137
|
const getShareableLinkConfiguration = async () => {
|
|
27138
|
+
var _a, _b;
|
|
26760
27139
|
const client = getActiveClient();
|
|
26761
27140
|
const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
|
|
26762
|
-
|
|
27141
|
+
const domain = (_a = data.domain) !== null && _a !== void 0 ? _a : '';
|
|
27142
|
+
const patterns = (_b = data.patterns) !== null && _b !== void 0 ? _b : {};
|
|
27143
|
+
return {
|
|
27144
|
+
domain,
|
|
27145
|
+
patterns,
|
|
27146
|
+
isEnabled(contentType) {
|
|
27147
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
27148
|
+
return !!domain && !!patterns[key];
|
|
27149
|
+
},
|
|
27150
|
+
getPattern(contentType) {
|
|
27151
|
+
const { key } = CONTENT_TYPE_CONFIG[contentType];
|
|
27152
|
+
return patterns[key] || null;
|
|
27153
|
+
},
|
|
27154
|
+
generateLink(contentType, referenceId) {
|
|
27155
|
+
const { key, placeholder } = CONTENT_TYPE_CONFIG[contentType];
|
|
27156
|
+
if (!domain || !patterns[key])
|
|
27157
|
+
return null;
|
|
27158
|
+
return domain + patterns[key].replace(`{${placeholder}}`, referenceId);
|
|
27159
|
+
},
|
|
27160
|
+
};
|
|
26763
27161
|
};
|
|
26764
27162
|
|
|
26765
27163
|
/**
|
|
@@ -26950,6 +27348,205 @@ const setAccessTokenHandler = (accessTokenHandler) => {
|
|
|
26950
27348
|
client.accessTokenHandler = accessTokenHandler;
|
|
26951
27349
|
};
|
|
26952
27350
|
|
|
27351
|
+
function parseRolesFilter(listenFromRoleIds, ignoreFromRoleIds) {
|
|
27352
|
+
if (ignoreFromRoleIds && ignoreFromRoleIds.length > 0) {
|
|
27353
|
+
return { type: 'not', roleIds: ignoreFromRoleIds };
|
|
27354
|
+
}
|
|
27355
|
+
if (listenFromRoleIds && listenFromRoleIds.length > 0) {
|
|
27356
|
+
return { type: NotificationRolesFilterTypeEnum.ONLY, roleIds: listenFromRoleIds };
|
|
27357
|
+
}
|
|
27358
|
+
return { type: NotificationRolesFilterTypeEnum.ALL };
|
|
27359
|
+
}
|
|
27360
|
+
function serializeRolesFilter(rolesFilter) {
|
|
27361
|
+
if ((rolesFilter === null || rolesFilter === void 0 ? void 0 : rolesFilter.type) === NotificationRolesFilterTypeEnum.ONLY) {
|
|
27362
|
+
return { listenFromRoleIds: rolesFilter.roleIds };
|
|
27363
|
+
}
|
|
27364
|
+
return { listenFromRoleIds: [] };
|
|
27365
|
+
}
|
|
27366
|
+
class ChannelNotifications {
|
|
27367
|
+
constructor(channelId) {
|
|
27368
|
+
this.channelId = channelId;
|
|
27369
|
+
}
|
|
27370
|
+
async enable() {
|
|
27371
|
+
const client = getActiveClient();
|
|
27372
|
+
const body = {
|
|
27373
|
+
level: NotificationSettingsLevelEnum.CHANNEL,
|
|
27374
|
+
channelId: this.channelId,
|
|
27375
|
+
isPushNotifiable: true,
|
|
27376
|
+
};
|
|
27377
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27378
|
+
}
|
|
27379
|
+
async disable() {
|
|
27380
|
+
const client = getActiveClient();
|
|
27381
|
+
const body = {
|
|
27382
|
+
level: NotificationSettingsLevelEnum.CHANNEL,
|
|
27383
|
+
channelId: this.channelId,
|
|
27384
|
+
isPushNotifiable: false,
|
|
27385
|
+
};
|
|
27386
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27387
|
+
}
|
|
27388
|
+
async getSettings() {
|
|
27389
|
+
const client = getActiveClient();
|
|
27390
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.CHANNEL}&channelId=${encodeURIComponent(this.channelId)}`);
|
|
27391
|
+
return { isEnabled: data.isPushNotifiable };
|
|
27392
|
+
}
|
|
27393
|
+
}
|
|
27394
|
+
class UserNotifications {
|
|
27395
|
+
async enable(modules) {
|
|
27396
|
+
var _a;
|
|
27397
|
+
const client = getActiveClient();
|
|
27398
|
+
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 : [];
|
|
27399
|
+
const body = {
|
|
27400
|
+
level: NotificationSettingsLevelEnum.USER,
|
|
27401
|
+
isPushNotifiable: true,
|
|
27402
|
+
notifiableEvents,
|
|
27403
|
+
};
|
|
27404
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27405
|
+
}
|
|
27406
|
+
async disableAllNotifications() {
|
|
27407
|
+
const client = getActiveClient();
|
|
27408
|
+
const body = {
|
|
27409
|
+
level: NotificationSettingsLevelEnum.USER,
|
|
27410
|
+
isPushNotifiable: false,
|
|
27411
|
+
notifiableEvents: [],
|
|
27412
|
+
};
|
|
27413
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27414
|
+
}
|
|
27415
|
+
async getSettings() {
|
|
27416
|
+
var _a;
|
|
27417
|
+
const client = getActiveClient();
|
|
27418
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.USER}`);
|
|
27419
|
+
const validModuleNames = Object.values(UserNotificationModuleNameEnum);
|
|
27420
|
+
const modules = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
27421
|
+
.filter(e => e.moduleName != null && validModuleNames.includes(e.moduleName))
|
|
27422
|
+
.map(e => ({
|
|
27423
|
+
moduleName: e.moduleName,
|
|
27424
|
+
isEnabled: e.isPushNotifiable,
|
|
27425
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
27426
|
+
}));
|
|
27427
|
+
return { isEnabled: data.isPushNotifiable, modules };
|
|
27428
|
+
}
|
|
27429
|
+
}
|
|
27430
|
+
class CommunityNotifications {
|
|
27431
|
+
constructor(communityId) {
|
|
27432
|
+
this.communityId = communityId;
|
|
27433
|
+
}
|
|
27434
|
+
async enable(events) {
|
|
27435
|
+
var _a;
|
|
27436
|
+
const client = getActiveClient();
|
|
27437
|
+
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 : [];
|
|
27438
|
+
const body = {
|
|
27439
|
+
level: NotificationSettingsLevelEnum.COMMUNITY,
|
|
27440
|
+
communityId: this.communityId,
|
|
27441
|
+
isPushNotifiable: true,
|
|
27442
|
+
notifiableEvents,
|
|
27443
|
+
};
|
|
27444
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27445
|
+
}
|
|
27446
|
+
async disable() {
|
|
27447
|
+
const client = getActiveClient();
|
|
27448
|
+
const body = {
|
|
27449
|
+
level: NotificationSettingsLevelEnum.COMMUNITY,
|
|
27450
|
+
communityId: this.communityId,
|
|
27451
|
+
isPushNotifiable: false,
|
|
27452
|
+
notifiableEvents: [],
|
|
27453
|
+
};
|
|
27454
|
+
await client.http.post('/api/v3/notification/setting', body);
|
|
27455
|
+
}
|
|
27456
|
+
async getSettings() {
|
|
27457
|
+
var _a;
|
|
27458
|
+
const client = getActiveClient();
|
|
27459
|
+
const { data } = await client.http.get(`/api/v3/notification/setting?level=${NotificationSettingsLevelEnum.COMMUNITY}&communityId=${encodeURIComponent(this.communityId)}`);
|
|
27460
|
+
const validEventNames = Object.values(CommunityNotificationEventNameEnum);
|
|
27461
|
+
const events = ((_a = data.notifiableEvents) !== null && _a !== void 0 ? _a : [])
|
|
27462
|
+
.filter(e => e.name != null && validEventNames.includes(e.name))
|
|
27463
|
+
.map(e => ({
|
|
27464
|
+
eventName: e.name,
|
|
27465
|
+
isEnabled: e.isPushNotifiable,
|
|
27466
|
+
isNetworkEnabled: e.isNetworkEnabled,
|
|
27467
|
+
rolesFilter: parseRolesFilter(e.listenFromRoleIds, e.ignoreFromRoleIds),
|
|
27468
|
+
}));
|
|
27469
|
+
return { isEnabled: data.isPushNotifiable, events };
|
|
27470
|
+
}
|
|
27471
|
+
}
|
|
27472
|
+
class Notifications {
|
|
27473
|
+
user() {
|
|
27474
|
+
return new UserNotifications();
|
|
27475
|
+
}
|
|
27476
|
+
community(communityId) {
|
|
27477
|
+
return new CommunityNotifications(communityId);
|
|
27478
|
+
}
|
|
27479
|
+
channel(channelId) {
|
|
27480
|
+
return new ChannelNotifications(channelId);
|
|
27481
|
+
}
|
|
27482
|
+
}
|
|
27483
|
+
const notifications = () => new Notifications();
|
|
27484
|
+
|
|
27485
|
+
/* begin_public_function
|
|
27486
|
+
id: client.enable_auto_subscriptions
|
|
27487
|
+
*/
|
|
27488
|
+
/**
|
|
27489
|
+
* ```js
|
|
27490
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27491
|
+
* Client.enableAutoSubscriptions([Client.AutoSubscription.BLOCK])
|
|
27492
|
+
* ```
|
|
27493
|
+
*
|
|
27494
|
+
* Enables one or more managed auto-subscription handles. Managed handles are
|
|
27495
|
+
* re-applied on every (re)connect and ref-counted. All handles are on by
|
|
27496
|
+
* default; use this to re-enable handles previously turned off via
|
|
27497
|
+
* {@link disableAutoSubscriptions}. Synchronous fire-and-forget — the registry
|
|
27498
|
+
* updates immediately and the broker subscribe is retried on reconnect.
|
|
27499
|
+
*
|
|
27500
|
+
* @param features the {@link AutoSubscription} handles to enable
|
|
27501
|
+
*
|
|
27502
|
+
* @category Client API
|
|
27503
|
+
*/
|
|
27504
|
+
const enableAutoSubscriptions = (features) => {
|
|
27505
|
+
const manager = getAutoSubscriptionManager();
|
|
27506
|
+
features.forEach(feature => manager.subscribe(feature));
|
|
27507
|
+
};
|
|
27508
|
+
/* end_public_function */
|
|
27509
|
+
/* begin_public_function
|
|
27510
|
+
id: client.disable_auto_subscriptions
|
|
27511
|
+
*/
|
|
27512
|
+
/**
|
|
27513
|
+
* ```js
|
|
27514
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27515
|
+
* Client.disableAutoSubscriptions([Client.AutoSubscription.LIVESTREAM])
|
|
27516
|
+
* ```
|
|
27517
|
+
*
|
|
27518
|
+
* Disables one or more managed auto-subscription handles. The change persists
|
|
27519
|
+
* across reconnect (it is not silently re-enabled) until
|
|
27520
|
+
* {@link enableAutoSubscriptions} is called again. Synchronous fire-and-forget.
|
|
27521
|
+
*
|
|
27522
|
+
* @param features the {@link AutoSubscription} handles to disable
|
|
27523
|
+
*
|
|
27524
|
+
* @category Client API
|
|
27525
|
+
*/
|
|
27526
|
+
const disableAutoSubscriptions = (features) => {
|
|
27527
|
+
const manager = getAutoSubscriptionManager();
|
|
27528
|
+
features.forEach(feature => manager.unsubscribe(feature));
|
|
27529
|
+
};
|
|
27530
|
+
/* end_public_function */
|
|
27531
|
+
/* begin_public_function
|
|
27532
|
+
id: client.auto_subscriptions
|
|
27533
|
+
*/
|
|
27534
|
+
/**
|
|
27535
|
+
* ```js
|
|
27536
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
27537
|
+
* Client.autoSubscriptions().forEach(s => console.log(s.feature, s.isActive, s.topicCount))
|
|
27538
|
+
* ```
|
|
27539
|
+
*
|
|
27540
|
+
* Inspects the managed auto-subscription registry — each handle's `isActive`,
|
|
27541
|
+
* `isSystem`, and `topicCount`.
|
|
27542
|
+
*
|
|
27543
|
+
* @returns a snapshot of the managed subscription registry
|
|
27544
|
+
*
|
|
27545
|
+
* @category Client API
|
|
27546
|
+
*/
|
|
27547
|
+
const autoSubscriptions = () => getAutoSubscriptionManager().subscriptions();
|
|
27548
|
+
/* end_public_function */
|
|
27549
|
+
|
|
26953
27550
|
/**
|
|
26954
27551
|
* ```js
|
|
26955
27552
|
* import { onChannelMarkerFetched } from '@amityco/ts-sdk'
|
|
@@ -27330,6 +27927,12 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
27330
27927
|
getCurrentUserType: getCurrentUserType,
|
|
27331
27928
|
setCurrentUserType: setCurrentUserType,
|
|
27332
27929
|
setAccessTokenHandler: setAccessTokenHandler,
|
|
27930
|
+
getChatSettings: getChatSettings,
|
|
27931
|
+
notifications: notifications,
|
|
27932
|
+
get AutoSubscription () { return AutoSubscription; },
|
|
27933
|
+
enableAutoSubscriptions: enableAutoSubscriptions,
|
|
27934
|
+
disableAutoSubscriptions: disableAutoSubscriptions,
|
|
27935
|
+
autoSubscriptions: autoSubscriptions,
|
|
27333
27936
|
onConnectionError: onConnectionError,
|
|
27334
27937
|
onClientDisconnected: onClientDisconnected,
|
|
27335
27938
|
onClientBanned: onClientBanned,
|
|
@@ -27435,6 +28038,67 @@ const unBlockUser = async (userId) => {
|
|
|
27435
28038
|
};
|
|
27436
28039
|
/* end_public_function */
|
|
27437
28040
|
|
|
28041
|
+
/**
|
|
28042
|
+
* Subscribes to a block MQTT event (`user.didBlock` / `user.didUnblock`),
|
|
28043
|
+
* ingests the carried `FollowersPayload` (follows + users) into the cache so
|
|
28044
|
+
* the block-relationship rows (`['follow', 'get', from#to]`) and user rows are
|
|
28045
|
+
* kept current, then forwards the affected {@link Amity.FollowStatus} to the
|
|
28046
|
+
* caller.
|
|
28047
|
+
*
|
|
28048
|
+
* @hidden
|
|
28049
|
+
*/
|
|
28050
|
+
const createBlockEventSubscriber = (event, callback) => {
|
|
28051
|
+
const client = getActiveClient();
|
|
28052
|
+
const filter = (data) => {
|
|
28053
|
+
const payload = prepareFollowersPayload(data);
|
|
28054
|
+
if (client.cache) {
|
|
28055
|
+
ingestInCache(payload);
|
|
28056
|
+
}
|
|
28057
|
+
callback(payload.follows[0]);
|
|
28058
|
+
};
|
|
28059
|
+
return createEventSubscriber(client, event, event, filter);
|
|
28060
|
+
};
|
|
28061
|
+
|
|
28062
|
+
/**
|
|
28063
|
+
* ```js
|
|
28064
|
+
* import { onUserDidBlock } from '@amityco/ts-sdk'
|
|
28065
|
+
* const dispose = onUserDidBlock(status => {
|
|
28066
|
+
* // ...
|
|
28067
|
+
* })
|
|
28068
|
+
* ```
|
|
28069
|
+
*
|
|
28070
|
+
* Fired when a block relationship is created in real time — either a user
|
|
28071
|
+
* blocks the current user (incoming) or the current user blocks someone on
|
|
28072
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
28073
|
+
* before the callback runs.
|
|
28074
|
+
*
|
|
28075
|
+
* @param callback The function to call when the event was fired
|
|
28076
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28077
|
+
*
|
|
28078
|
+
* @category Block Events
|
|
28079
|
+
*/
|
|
28080
|
+
const onUserDidBlock = (callback) => createBlockEventSubscriber('user.didBlock', callback);
|
|
28081
|
+
|
|
28082
|
+
/**
|
|
28083
|
+
* ```js
|
|
28084
|
+
* import { onUserDidUnblock } from '@amityco/ts-sdk'
|
|
28085
|
+
* const dispose = onUserDidUnblock(status => {
|
|
28086
|
+
* // ...
|
|
28087
|
+
* })
|
|
28088
|
+
* ```
|
|
28089
|
+
*
|
|
28090
|
+
* Fired when a block relationship is removed in real time — either a user
|
|
28091
|
+
* unblocks the current user (incoming) or the current user unblocks someone on
|
|
28092
|
+
* another device (outgoing). The local block-relationship store is updated
|
|
28093
|
+
* before the callback runs.
|
|
28094
|
+
*
|
|
28095
|
+
* @param callback The function to call when the event was fired
|
|
28096
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
28097
|
+
*
|
|
28098
|
+
* @category Block Events
|
|
28099
|
+
*/
|
|
28100
|
+
const onUserDidUnblock = (callback) => createBlockEventSubscriber('user.didUnblock', callback);
|
|
28101
|
+
|
|
27438
28102
|
/* begin_public_function
|
|
27439
28103
|
id: user.relationship.follow
|
|
27440
28104
|
*/
|
|
@@ -28537,6 +29201,8 @@ var index$r = /*#__PURE__*/Object.freeze({
|
|
|
28537
29201
|
__proto__: null,
|
|
28538
29202
|
blockUser: blockUser,
|
|
28539
29203
|
unBlockUser: unBlockUser,
|
|
29204
|
+
onUserDidBlock: onUserDidBlock,
|
|
29205
|
+
onUserDidUnblock: onUserDidUnblock,
|
|
28540
29206
|
follow: follow,
|
|
28541
29207
|
unfollow: unfollow,
|
|
28542
29208
|
acceptMyFollower: acceptMyFollower,
|
|
@@ -29366,7 +30032,7 @@ const getWatchSessionStorage = () => {
|
|
|
29366
30032
|
return storageInstance;
|
|
29367
30033
|
};
|
|
29368
30034
|
|
|
29369
|
-
const privateKey = "
|
|
30035
|
+
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
30036
|
/*
|
|
29371
30037
|
* The crypto algorithm used for importing key and signing string
|
|
29372
30038
|
*/
|
|
@@ -30688,6 +31354,10 @@ const postLinkedObject = (post) => {
|
|
|
30688
31354
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
30689
31355
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
30690
31356
|
},
|
|
31357
|
+
markAsMeaningfullyViewed: (feedRenderPosition) => {
|
|
31358
|
+
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
31359
|
+
analyticsEngineInstance.markPostAsMeaningfullyViewed(post.postId, feedRenderPosition);
|
|
31360
|
+
},
|
|
30691
31361
|
},
|
|
30692
31362
|
get productTags() {
|
|
30693
31363
|
var _a, _b;
|
|
@@ -30877,6 +31547,11 @@ const addReaction$1 = async (referenceType, referenceId, reactionName, reference
|
|
|
30877
31547
|
});
|
|
30878
31548
|
return true;
|
|
30879
31549
|
}
|
|
31550
|
+
if (referenceType === 'message') {
|
|
31551
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
31552
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
31553
|
+
return true;
|
|
31554
|
+
}
|
|
30880
31555
|
}
|
|
30881
31556
|
return true;
|
|
30882
31557
|
};
|
|
@@ -30955,7 +31630,7 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
30955
31630
|
return true;
|
|
30956
31631
|
}
|
|
30957
31632
|
if (referenceType === 'story') {
|
|
30958
|
-
fireEvent('local.story.
|
|
31633
|
+
fireEvent('local.story.reactionRemoved', {
|
|
30959
31634
|
story: updatedModel,
|
|
30960
31635
|
reactor: {
|
|
30961
31636
|
userId: client.userId,
|
|
@@ -30965,6 +31640,11 @@ const removeReaction$1 = async (referenceType, referenceId, reactionName, refere
|
|
|
30965
31640
|
});
|
|
30966
31641
|
return true;
|
|
30967
31642
|
}
|
|
31643
|
+
if (referenceType === 'message') {
|
|
31644
|
+
upsertInCache(['message', 'get', referenceId], updatedModel);
|
|
31645
|
+
fireEvent('local.message.updated', { messages: [updatedModel] });
|
|
31646
|
+
return true;
|
|
31647
|
+
}
|
|
30968
31648
|
}
|
|
30969
31649
|
return true;
|
|
30970
31650
|
};
|
|
@@ -32284,6 +32964,12 @@ class BlockedUserPaginationController extends PaginationController {
|
|
|
32284
32964
|
}
|
|
32285
32965
|
}
|
|
32286
32966
|
|
|
32967
|
+
var EnumBlockActions;
|
|
32968
|
+
(function (EnumBlockActions) {
|
|
32969
|
+
EnumBlockActions["OnBlocked"] = "onBlocked";
|
|
32970
|
+
EnumBlockActions["OnUnblocked"] = "onUnblocked";
|
|
32971
|
+
})(EnumBlockActions || (EnumBlockActions = {}));
|
|
32972
|
+
|
|
32287
32973
|
class BlockedUserQueryStreamController extends QueryStreamController {
|
|
32288
32974
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
32289
32975
|
super(query, cacheKey);
|
|
@@ -32313,11 +32999,16 @@ class BlockedUserQueryStreamController extends QueryStreamController {
|
|
|
32313
32999
|
}
|
|
32314
33000
|
reactor(action) {
|
|
32315
33001
|
return (targetUser) => {
|
|
32316
|
-
var _a;
|
|
32317
|
-
|
|
33002
|
+
var _a, _b;
|
|
33003
|
+
const isRemoval = action === EnumFollowActions.OnFollowed || action === EnumBlockActions.OnUnblocked;
|
|
33004
|
+
const isAddition = action === EnumBlockActions.OnBlocked;
|
|
33005
|
+
if (isRemoval || isAddition) {
|
|
32318
33006
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
32319
|
-
const
|
|
32320
|
-
|
|
33007
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33008
|
+
const data = isAddition
|
|
33009
|
+
? [...new Set([...ids, targetUser.userId])]
|
|
33010
|
+
: ids.filter(id => id !== targetUser.userId);
|
|
33011
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
32321
33012
|
}
|
|
32322
33013
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
32323
33014
|
};
|
|
@@ -32372,7 +33063,6 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
32372
33063
|
fn: onUserDeleted$2,
|
|
32373
33064
|
action: EnumUserActions.OnUserDeleted,
|
|
32374
33065
|
},
|
|
32375
|
-
// In the case of unblocking a user, we need to subscribe to the follow events
|
|
32376
33066
|
{
|
|
32377
33067
|
fn: convertEventPayload(onLocalUserFollowed, 'to', 'user'),
|
|
32378
33068
|
action: EnumFollowActions.OnFollowed,
|
|
@@ -32381,6 +33071,28 @@ class BlockedUserLiveCollectionController extends LiveCollectionController {
|
|
|
32381
33071
|
fn: convertEventPayload(onUserFollowed, 'to', 'user'),
|
|
32382
33072
|
action: EnumFollowActions.OnFollowed,
|
|
32383
33073
|
},
|
|
33074
|
+
{
|
|
33075
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
33076
|
+
var _a;
|
|
33077
|
+
if (status.from !== getActiveClient().userId)
|
|
33078
|
+
return;
|
|
33079
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33080
|
+
if (blocked)
|
|
33081
|
+
reactor(blocked);
|
|
33082
|
+
}),
|
|
33083
|
+
action: EnumBlockActions.OnBlocked,
|
|
33084
|
+
},
|
|
33085
|
+
{
|
|
33086
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
33087
|
+
var _a;
|
|
33088
|
+
if (status.from !== getActiveClient().userId)
|
|
33089
|
+
return;
|
|
33090
|
+
const blocked = (_a = pullFromCache(['user', 'get', status.to])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33091
|
+
if (blocked)
|
|
33092
|
+
reactor(blocked);
|
|
33093
|
+
}),
|
|
33094
|
+
action: EnumBlockActions.OnUnblocked,
|
|
33095
|
+
},
|
|
32384
33096
|
]);
|
|
32385
33097
|
}
|
|
32386
33098
|
notifyChange({ origin, loading, error }) {
|
|
@@ -32448,6 +33160,192 @@ const getBlockedUsers = (params, callback, config) => {
|
|
|
32448
33160
|
};
|
|
32449
33161
|
/* end_public_function */
|
|
32450
33162
|
|
|
33163
|
+
function prepareBlockingUserPayload(response) {
|
|
33164
|
+
const { users, follows } = response, rest = __rest(response, ["users", "follows"]);
|
|
33165
|
+
return Object.assign(Object.assign({}, rest), { follows: follows.map(follow => {
|
|
33166
|
+
const followUser = users.find(user => user.userId === follow.from);
|
|
33167
|
+
return Object.assign(Object.assign({}, follow), { user: convertRawUserToInternalUser(followUser) });
|
|
33168
|
+
}), users: users.map(convertRawUserToInternalUser) });
|
|
33169
|
+
}
|
|
33170
|
+
|
|
33171
|
+
class BlockingUserQueryStreamController extends QueryStreamController {
|
|
33172
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
33173
|
+
super(query, cacheKey);
|
|
33174
|
+
this.notifyChange = notifyChange;
|
|
33175
|
+
this.preparePayload = preparePayload;
|
|
33176
|
+
}
|
|
33177
|
+
async saveToMainDB(response) {
|
|
33178
|
+
const processedPayload = await this.preparePayload(response);
|
|
33179
|
+
const client = getActiveClient();
|
|
33180
|
+
const cachedAt = client.cache && Date.now();
|
|
33181
|
+
if (client.cache) {
|
|
33182
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
33183
|
+
}
|
|
33184
|
+
}
|
|
33185
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
33186
|
+
var _a, _b;
|
|
33187
|
+
if (refresh) {
|
|
33188
|
+
pushToCache(this.cacheKey, {
|
|
33189
|
+
data: response.users.map(getResolver('user')),
|
|
33190
|
+
});
|
|
33191
|
+
}
|
|
33192
|
+
else {
|
|
33193
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33194
|
+
const users = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33195
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...users, ...response.users.map(getResolver('user'))])] }));
|
|
33196
|
+
}
|
|
33197
|
+
}
|
|
33198
|
+
reactor(action) {
|
|
33199
|
+
return (user) => {
|
|
33200
|
+
var _a, _b;
|
|
33201
|
+
if (user &&
|
|
33202
|
+
(action === EnumBlockActions.OnBlocked || action === EnumBlockActions.OnUnblocked)) {
|
|
33203
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33204
|
+
const ids = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
33205
|
+
const data = action === EnumBlockActions.OnBlocked
|
|
33206
|
+
? [...new Set([...ids, user.userId])]
|
|
33207
|
+
: ids.filter(id => id !== user.userId);
|
|
33208
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data }));
|
|
33209
|
+
}
|
|
33210
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
33211
|
+
};
|
|
33212
|
+
}
|
|
33213
|
+
subscribeRTE(createSubscriber) {
|
|
33214
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
33215
|
+
}
|
|
33216
|
+
}
|
|
33217
|
+
|
|
33218
|
+
class BlockingUserPaginationController extends PaginationController {
|
|
33219
|
+
async getRequest(queryParams, token) {
|
|
33220
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_SIZE } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
33221
|
+
const options = token ? { token } : { limit };
|
|
33222
|
+
const { data: queryResponse } = await this.http.get('/api/v4/me/blockers', {
|
|
33223
|
+
params: Object.assign(Object.assign({}, params), { options, isDeleted: false }),
|
|
33224
|
+
});
|
|
33225
|
+
return queryResponse;
|
|
33226
|
+
}
|
|
33227
|
+
}
|
|
33228
|
+
|
|
33229
|
+
class BlockingUserLiveCollectionController extends LiveCollectionController {
|
|
33230
|
+
constructor(callback) {
|
|
33231
|
+
const queryStreamId = `blocking-users-${getActiveClient().userId}`;
|
|
33232
|
+
const query = {};
|
|
33233
|
+
const cacheKey = ['blockingUsers', 'collection', queryStreamId];
|
|
33234
|
+
const paginationController = new BlockingUserPaginationController(query);
|
|
33235
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
33236
|
+
this.queryStreamController = new BlockingUserQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), prepareBlockingUserPayload);
|
|
33237
|
+
this.callback = callback.bind(this);
|
|
33238
|
+
this.loadPage({ initial: true });
|
|
33239
|
+
}
|
|
33240
|
+
setup() {
|
|
33241
|
+
var _a;
|
|
33242
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33243
|
+
if (!collection) {
|
|
33244
|
+
pushToCache(this.cacheKey, {
|
|
33245
|
+
data: [],
|
|
33246
|
+
params: {},
|
|
33247
|
+
});
|
|
33248
|
+
}
|
|
33249
|
+
}
|
|
33250
|
+
async persistModel(queryPayload) {
|
|
33251
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
33252
|
+
}
|
|
33253
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
33254
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
33255
|
+
}
|
|
33256
|
+
startSubscription() {
|
|
33257
|
+
return this.queryStreamController.subscribeRTE([
|
|
33258
|
+
{
|
|
33259
|
+
fn: onUserDeleted$2,
|
|
33260
|
+
action: EnumUserActions.OnUserDeleted,
|
|
33261
|
+
},
|
|
33262
|
+
{
|
|
33263
|
+
fn: (reactor) => onUserDidBlock(status => {
|
|
33264
|
+
var _a;
|
|
33265
|
+
if (status.to !== getActiveClient().userId)
|
|
33266
|
+
return;
|
|
33267
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33268
|
+
if (blocker)
|
|
33269
|
+
reactor(blocker);
|
|
33270
|
+
}),
|
|
33271
|
+
action: EnumBlockActions.OnBlocked,
|
|
33272
|
+
},
|
|
33273
|
+
{
|
|
33274
|
+
fn: (reactor) => onUserDidUnblock(status => {
|
|
33275
|
+
var _a;
|
|
33276
|
+
if (status.to !== getActiveClient().userId)
|
|
33277
|
+
return;
|
|
33278
|
+
const blocker = (_a = pullFromCache(['user', 'get', status.from])) === null || _a === void 0 ? void 0 : _a.data;
|
|
33279
|
+
if (blocker)
|
|
33280
|
+
reactor(blocker);
|
|
33281
|
+
}),
|
|
33282
|
+
action: EnumBlockActions.OnUnblocked,
|
|
33283
|
+
},
|
|
33284
|
+
]);
|
|
33285
|
+
}
|
|
33286
|
+
notifyChange({ origin, loading, error }) {
|
|
33287
|
+
var _a, _b;
|
|
33288
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
33289
|
+
if (!collection)
|
|
33290
|
+
return;
|
|
33291
|
+
const data = this.applyFilter((_b = collection.data
|
|
33292
|
+
.map(id => pullFromCache(['user', 'get', id]))
|
|
33293
|
+
.filter(isNonNullable)
|
|
33294
|
+
.map(({ data }) => data)
|
|
33295
|
+
.map(LinkedObject.user)) !== null && _b !== void 0 ? _b : []);
|
|
33296
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
33297
|
+
return;
|
|
33298
|
+
this.callback({
|
|
33299
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
33300
|
+
data,
|
|
33301
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
33302
|
+
loading,
|
|
33303
|
+
error,
|
|
33304
|
+
});
|
|
33305
|
+
}
|
|
33306
|
+
applyFilter(data) {
|
|
33307
|
+
let users = data;
|
|
33308
|
+
users = users.filter(user => user.isDeleted == null || user.isDeleted === false);
|
|
33309
|
+
return users;
|
|
33310
|
+
}
|
|
33311
|
+
}
|
|
33312
|
+
|
|
33313
|
+
/* begin_public_function
|
|
33314
|
+
id: user.get_blocking_users
|
|
33315
|
+
*/
|
|
33316
|
+
/**
|
|
33317
|
+
* ```js
|
|
33318
|
+
* import { UserRepository } from '@amityco/ts-sdk'
|
|
33319
|
+
* const unsubscribe = UserRepository.getBlockingUsers(({ data: users }) => {
|
|
33320
|
+
* console.log(users)
|
|
33321
|
+
* })
|
|
33322
|
+
* ```
|
|
33323
|
+
*
|
|
33324
|
+
* Observe the {@link Amity.User}s who have blocked the current user
|
|
33325
|
+
*
|
|
33326
|
+
* @param callback to receive updates on the blocking {@link Amity.User}s
|
|
33327
|
+
* @returns {@link Amity.Unsubscriber} to unsubscribe from collection
|
|
33328
|
+
*
|
|
33329
|
+
* @category User API
|
|
33330
|
+
*/
|
|
33331
|
+
const getBlockingUsers = (callback) => {
|
|
33332
|
+
const { log, cache } = getActiveClient();
|
|
33333
|
+
if (!cache)
|
|
33334
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
33335
|
+
const timestamp = Date.now();
|
|
33336
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > listen`);
|
|
33337
|
+
const blockingUserLiveCollection = new BlockingUserLiveCollectionController(callback);
|
|
33338
|
+
const disposers = blockingUserLiveCollection.startSubscription();
|
|
33339
|
+
const cacheKey = blockingUserLiveCollection.getCacheKey();
|
|
33340
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
33341
|
+
return () => {
|
|
33342
|
+
log(`getBlockingUsers(tmpid: ${timestamp}) > dispose`);
|
|
33343
|
+
disposers.forEach(fn => fn());
|
|
33344
|
+
dropFromCache(cacheKey);
|
|
33345
|
+
};
|
|
33346
|
+
};
|
|
33347
|
+
/* end_public_function */
|
|
33348
|
+
|
|
32451
33349
|
class SearchUserPaginationController extends PaginationController {
|
|
32452
33350
|
async getRequest(queryParams, token) {
|
|
32453
33351
|
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, displayName } = queryParams, params = __rest(queryParams, ["limit", "displayName"]);
|
|
@@ -32722,6 +33620,7 @@ var index$q = /*#__PURE__*/Object.freeze({
|
|
|
32722
33620
|
getUser: getUser,
|
|
32723
33621
|
getUsers: getUsers,
|
|
32724
33622
|
getBlockedUsers: getBlockedUsers,
|
|
33623
|
+
getBlockingUsers: getBlockingUsers,
|
|
32725
33624
|
searchUserByDisplayName: searchUserByDisplayName,
|
|
32726
33625
|
getReachedUsers: getReachedUsers,
|
|
32727
33626
|
get AmityUserSearchMatchType () { return AmityUserSearchMatchType; }
|
|
@@ -33888,7 +34787,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
33888
34787
|
return true;
|
|
33889
34788
|
}
|
|
33890
34789
|
if (referenceType === 'story') {
|
|
33891
|
-
fireEvent('local.story.
|
|
34790
|
+
fireEvent('local.story.reactionRemoved', {
|
|
33892
34791
|
story: updatedModel,
|
|
33893
34792
|
reactor: {
|
|
33894
34793
|
userId: client.userId,
|
|
@@ -35472,6 +36371,104 @@ const unmuteChannel = async (channelId) => {
|
|
|
35472
36371
|
};
|
|
35473
36372
|
/* end_public_function */
|
|
35474
36373
|
|
|
36374
|
+
/* begin_public_function
|
|
36375
|
+
id: channel.archive
|
|
36376
|
+
*/
|
|
36377
|
+
/**
|
|
36378
|
+
* ```js
|
|
36379
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36380
|
+
* const success = await ChannelRepository.archiveChannel('foobar')
|
|
36381
|
+
* ```
|
|
36382
|
+
*
|
|
36383
|
+
* Archive a {@link Amity.Channel}.
|
|
36384
|
+
*
|
|
36385
|
+
* @param channelId The id of the {@link Amity.Channel} to archive
|
|
36386
|
+
* @returns A success boolean
|
|
36387
|
+
*
|
|
36388
|
+
* @category Channel API
|
|
36389
|
+
* @async
|
|
36390
|
+
*/
|
|
36391
|
+
const archiveChannel = async (channelId) => {
|
|
36392
|
+
const client = getActiveClient();
|
|
36393
|
+
client.log('channel/archiveChannel', channelId);
|
|
36394
|
+
await client.http.post(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
36395
|
+
const archive = {
|
|
36396
|
+
channelId,
|
|
36397
|
+
archivedAt: new Date().toISOString(),
|
|
36398
|
+
};
|
|
36399
|
+
if (client.cache) {
|
|
36400
|
+
pushToCache(['archivedChannel', 'get', getResolver('archivedChannel')(archive)], archive);
|
|
36401
|
+
}
|
|
36402
|
+
fireEvent('local.channel.archived', { archives: [archive] });
|
|
36403
|
+
};
|
|
36404
|
+
/* end_public_function */
|
|
36405
|
+
|
|
36406
|
+
/* begin_public_function
|
|
36407
|
+
id: channel.unarchive
|
|
36408
|
+
*/
|
|
36409
|
+
/**
|
|
36410
|
+
* ```js
|
|
36411
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36412
|
+
* const success = await ChannelRepository.unarchiveChannel('foobar')
|
|
36413
|
+
* ```
|
|
36414
|
+
*
|
|
36415
|
+
* Unarchive a previously archived {@link Amity.Channel}.
|
|
36416
|
+
*
|
|
36417
|
+
* @param channelId The id of the {@link Amity.Channel} to unarchive
|
|
36418
|
+
* @returns A success boolean
|
|
36419
|
+
*
|
|
36420
|
+
* @category Channel API
|
|
36421
|
+
* @async
|
|
36422
|
+
*/
|
|
36423
|
+
const unarchiveChannel = async (channelId) => {
|
|
36424
|
+
var _a;
|
|
36425
|
+
const client = getActiveClient();
|
|
36426
|
+
client.log('channel/unarchiveChannel', channelId);
|
|
36427
|
+
await client.http.delete(`/api/v1/archives/channels/${encodeURIComponent(channelId)}`);
|
|
36428
|
+
const cached = (_a = pullFromCache(['archivedChannel', 'get', channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
36429
|
+
const archive = cached !== null && cached !== void 0 ? cached : {
|
|
36430
|
+
channelId,
|
|
36431
|
+
archivedAt: new Date().toISOString(),
|
|
36432
|
+
};
|
|
36433
|
+
if (client.cache) {
|
|
36434
|
+
dropFromCache(['archivedChannel', 'get', channelId], true);
|
|
36435
|
+
}
|
|
36436
|
+
fireEvent('local.channel.unarchived', { archives: [archive] });
|
|
36437
|
+
};
|
|
36438
|
+
/* end_public_function */
|
|
36439
|
+
|
|
36440
|
+
/* begin_public_function
|
|
36441
|
+
id: channel.archive.ids
|
|
36442
|
+
*/
|
|
36443
|
+
/**
|
|
36444
|
+
* ```js
|
|
36445
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
36446
|
+
* const ids = await ChannelRepository.getArchivedChannelIds()
|
|
36447
|
+
* ```
|
|
36448
|
+
*
|
|
36449
|
+
* @returns A list of archived channel ids sorted by `archivedAt` descending.
|
|
36450
|
+
*
|
|
36451
|
+
* @category Channel API
|
|
36452
|
+
* @async
|
|
36453
|
+
*/
|
|
36454
|
+
const getArchivedChannelIds = async () => {
|
|
36455
|
+
var _a;
|
|
36456
|
+
const client = getActiveClient();
|
|
36457
|
+
client.log('channel/getArchivedChannelIds');
|
|
36458
|
+
const { data: payload } = await client.http.get(`/api/v1/archives/channels`);
|
|
36459
|
+
const archives = (_a = payload.archives) !== null && _a !== void 0 ? _a : [];
|
|
36460
|
+
if (client.cache) {
|
|
36461
|
+
dropFromCache(['archivedChannel', 'get']);
|
|
36462
|
+
archives.forEach(archive => {
|
|
36463
|
+
if (!archive.channelId)
|
|
36464
|
+
return;
|
|
36465
|
+
pushToCache(['archivedChannel', 'get', archive.channelId], archive);
|
|
36466
|
+
});
|
|
36467
|
+
}
|
|
36468
|
+
return archives.map(entry => entry.channelId).filter(channelId => !!channelId);
|
|
36469
|
+
};
|
|
36470
|
+
/* end_public_function */
|
|
36471
|
+
|
|
35475
36472
|
/**
|
|
35476
36473
|
* ```js
|
|
35477
36474
|
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
@@ -36850,6 +37847,160 @@ const getMessages = (params, callback, config) => {
|
|
|
36850
37847
|
};
|
|
36851
37848
|
/* end_public_function */
|
|
36852
37849
|
|
|
37850
|
+
class SearchMessagePaginationController extends PaginationController {
|
|
37851
|
+
async getRequest(queryParams, token) {
|
|
37852
|
+
const { query, exactMatch, channelId, messageFeedId, userIds, tags, types, sortBy, orderBy, limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, } = queryParams;
|
|
37853
|
+
const options = token ? { token } : { limit, sortBy, orderBy };
|
|
37854
|
+
const { data: queryResponse } = await this.http.get(`/api/v2/search/messages`, {
|
|
37855
|
+
params: {
|
|
37856
|
+
query,
|
|
37857
|
+
exactMatch,
|
|
37858
|
+
channelId,
|
|
37859
|
+
messageFeedId,
|
|
37860
|
+
userIds,
|
|
37861
|
+
tags,
|
|
37862
|
+
types,
|
|
37863
|
+
options,
|
|
37864
|
+
},
|
|
37865
|
+
});
|
|
37866
|
+
return queryResponse;
|
|
37867
|
+
}
|
|
37868
|
+
}
|
|
37869
|
+
|
|
37870
|
+
class SearchMessageQueryStreamController extends QueryStreamController {
|
|
37871
|
+
constructor(query, cacheKey, notifyChange) {
|
|
37872
|
+
super(query, cacheKey);
|
|
37873
|
+
this.notifyChange = notifyChange;
|
|
37874
|
+
}
|
|
37875
|
+
async saveToMainDB(response) {
|
|
37876
|
+
var _a;
|
|
37877
|
+
const processedPayload = await prepareMessagePayload(response);
|
|
37878
|
+
const client = getActiveClient();
|
|
37879
|
+
const cachedAt = client.cache && Date.now();
|
|
37880
|
+
if (client.cache) {
|
|
37881
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37882
|
+
if ((_a = response.channels) === null || _a === void 0 ? void 0 : _a.length) {
|
|
37883
|
+
response.channels.forEach(channel => {
|
|
37884
|
+
pushToCache(['channel', 'get', channel.channelId], channel, { cachedAt });
|
|
37885
|
+
});
|
|
37886
|
+
}
|
|
37887
|
+
}
|
|
37888
|
+
}
|
|
37889
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
37890
|
+
var _a, _b;
|
|
37891
|
+
if (refresh) {
|
|
37892
|
+
pushToCache(this.cacheKey, {
|
|
37893
|
+
data: response.messages.map(getResolver('message')),
|
|
37894
|
+
});
|
|
37895
|
+
return;
|
|
37896
|
+
}
|
|
37897
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37898
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
37899
|
+
const incoming = response.messages.map(getResolver('message'));
|
|
37900
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
37901
|
+
? [...new Set([...incoming, ...existing])]
|
|
37902
|
+
: [...new Set([...existing, ...incoming])] }));
|
|
37903
|
+
}
|
|
37904
|
+
}
|
|
37905
|
+
|
|
37906
|
+
class SearchMessageLiveCollectionController extends LiveCollectionController {
|
|
37907
|
+
constructor(query, callback) {
|
|
37908
|
+
const queryStreamId = hash(query);
|
|
37909
|
+
const cacheKey = ['message', 'search', queryStreamId];
|
|
37910
|
+
const paginationController = new SearchMessagePaginationController(query);
|
|
37911
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
37912
|
+
this.queryStreamController = new SearchMessageQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
37913
|
+
this.callback = callback.bind(this);
|
|
37914
|
+
this.loadPage({ initial: true });
|
|
37915
|
+
}
|
|
37916
|
+
startSubscription() {
|
|
37917
|
+
return [];
|
|
37918
|
+
}
|
|
37919
|
+
notifyChange({ origin, loading, error }) {
|
|
37920
|
+
var _a, _b;
|
|
37921
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37922
|
+
if (!collection)
|
|
37923
|
+
return;
|
|
37924
|
+
const data = (_b = collection.data
|
|
37925
|
+
.map(messageId => getMessageFromMainDB(messageId))
|
|
37926
|
+
.filter(isNonNullable)
|
|
37927
|
+
.map(message => LinkedObject.message(message))) !== null && _b !== void 0 ? _b : [];
|
|
37928
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
37929
|
+
return;
|
|
37930
|
+
this.callback({
|
|
37931
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
37932
|
+
data,
|
|
37933
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
37934
|
+
loading,
|
|
37935
|
+
error,
|
|
37936
|
+
});
|
|
37937
|
+
}
|
|
37938
|
+
setup() {
|
|
37939
|
+
var _a;
|
|
37940
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
37941
|
+
if (!collection) {
|
|
37942
|
+
pushToCache(this.cacheKey, {
|
|
37943
|
+
data: [],
|
|
37944
|
+
params: {},
|
|
37945
|
+
});
|
|
37946
|
+
}
|
|
37947
|
+
}
|
|
37948
|
+
async persistModel(response) {
|
|
37949
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
37950
|
+
}
|
|
37951
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
37952
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
37953
|
+
}
|
|
37954
|
+
}
|
|
37955
|
+
|
|
37956
|
+
/* begin_public_function
|
|
37957
|
+
id: message.search
|
|
37958
|
+
*/
|
|
37959
|
+
/**
|
|
37960
|
+
* ```js
|
|
37961
|
+
* import { MessageRepository } from '@amityco/ts-sdk';
|
|
37962
|
+
*
|
|
37963
|
+
* let messages = [];
|
|
37964
|
+
*
|
|
37965
|
+
* const unsubscribe = MessageRepository.searchMessage(
|
|
37966
|
+
* { query: 'hello' },
|
|
37967
|
+
* response => merge(messages, response.data),
|
|
37968
|
+
* );
|
|
37969
|
+
* ```
|
|
37970
|
+
*
|
|
37971
|
+
* Live collection of {@link Amity.Message}s matching the search query. Backed
|
|
37972
|
+
* by `GET /api/v2/search/messages`. The first emission delivers the first
|
|
37973
|
+
* page; pagination is driven by `response.onNextPage()`.
|
|
37974
|
+
*
|
|
37975
|
+
* @param params Search parameters. `query` is required.
|
|
37976
|
+
* @param callback Called whenever new data are available.
|
|
37977
|
+
* @returns An {@link Amity.Unsubscriber} function to stop observing.
|
|
37978
|
+
*
|
|
37979
|
+
* @category Message Live Collection
|
|
37980
|
+
*/
|
|
37981
|
+
const searchMessage = (params, callback) => {
|
|
37982
|
+
if (!params.query || params.query.trim().length === 0) {
|
|
37983
|
+
throw new Error('Query is required for message search');
|
|
37984
|
+
}
|
|
37985
|
+
const { log, cache } = getActiveClient();
|
|
37986
|
+
if (!cache) {
|
|
37987
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
37988
|
+
}
|
|
37989
|
+
const timestamp = Date.now();
|
|
37990
|
+
log(`searchMessage(tmpid: ${timestamp}) > listen`);
|
|
37991
|
+
const controller = new SearchMessageLiveCollectionController(params, callback);
|
|
37992
|
+
const disposers = controller.startSubscription();
|
|
37993
|
+
const cacheKey = controller.getCacheKey();
|
|
37994
|
+
disposers.push(() => {
|
|
37995
|
+
dropFromCache(cacheKey);
|
|
37996
|
+
});
|
|
37997
|
+
return () => {
|
|
37998
|
+
log(`searchMessage(tmpid: ${timestamp}) > dispose`);
|
|
37999
|
+
disposers.forEach(fn => fn());
|
|
38000
|
+
};
|
|
38001
|
+
};
|
|
38002
|
+
/* end_public_function */
|
|
38003
|
+
|
|
36853
38004
|
var index$n = /*#__PURE__*/Object.freeze({
|
|
36854
38005
|
__proto__: null,
|
|
36855
38006
|
createMessage: createMessage,
|
|
@@ -36875,6 +38026,7 @@ var index$n = /*#__PURE__*/Object.freeze({
|
|
|
36875
38026
|
onMessageFetched: onMessageFetched,
|
|
36876
38027
|
getMessage: getMessage,
|
|
36877
38028
|
getMessages: getMessages,
|
|
38029
|
+
searchMessage: searchMessage,
|
|
36878
38030
|
convertFromRaw: convertFromRaw$1,
|
|
36879
38031
|
prepareMessagePayload: prepareMessagePayload,
|
|
36880
38032
|
convertParams: convertParams,
|
|
@@ -37722,6 +38874,7 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
37722
38874
|
"onCreate" /* Amity.ChannelActionType.OnCreate */,
|
|
37723
38875
|
"onJoin" /* Amity.ChannelActionType.OnJoin */,
|
|
37724
38876
|
"onResolveChannel" /* Amity.ChannelActionType.OnResolveChannel */,
|
|
38877
|
+
"onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
37725
38878
|
].includes(action)) {
|
|
37726
38879
|
if (Array.isArray(payload)) {
|
|
37727
38880
|
collection.data = [
|
|
@@ -37731,6 +38884,12 @@ class ChannelQueryStreamController extends QueryStreamController {
|
|
|
37731
38884
|
else
|
|
37732
38885
|
collection.data = [...new Set([payload.channelInternalId, ...collection.data])];
|
|
37733
38886
|
}
|
|
38887
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
38888
|
+
const ids = Array.isArray(payload)
|
|
38889
|
+
? payload.map(getResolver('channel'))
|
|
38890
|
+
: [getResolver('channel')(payload)];
|
|
38891
|
+
collection.data = collection.data.filter(channelInternalId => !ids.includes(channelInternalId));
|
|
38892
|
+
}
|
|
37734
38893
|
pushToCache(this.cacheKey, collection);
|
|
37735
38894
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
37736
38895
|
};
|
|
@@ -37997,6 +39156,32 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
37997
39156
|
},
|
|
37998
39157
|
{ fn: onChannelMemberAdded, action: "onMemberAdded" /* Amity.ChannelActionType.OnMemberAdded */ },
|
|
37999
39158
|
{ fn: onChannelMemberRemoved, action: "onMemberRemoved" /* Amity.ChannelActionType.OnMemberRemoved */ },
|
|
39159
|
+
{
|
|
39160
|
+
fn: (reactor) => onChannelArchived(payload => {
|
|
39161
|
+
const channels = payload.archives
|
|
39162
|
+
.map(archive => {
|
|
39163
|
+
var _a;
|
|
39164
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39165
|
+
})
|
|
39166
|
+
.filter((c) => Boolean(c));
|
|
39167
|
+
if (channels.length > 0)
|
|
39168
|
+
reactor(channels);
|
|
39169
|
+
}),
|
|
39170
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
39171
|
+
},
|
|
39172
|
+
{
|
|
39173
|
+
fn: (reactor) => onChannelUnarchived(payload => {
|
|
39174
|
+
const channels = payload.archives
|
|
39175
|
+
.map(archive => {
|
|
39176
|
+
var _a;
|
|
39177
|
+
return (_a = pullFromCache(['channel', 'get', archive.channelId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39178
|
+
})
|
|
39179
|
+
.filter((c) => Boolean(c));
|
|
39180
|
+
if (channels.length > 0)
|
|
39181
|
+
reactor(channels);
|
|
39182
|
+
}),
|
|
39183
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
39184
|
+
},
|
|
38000
39185
|
{
|
|
38001
39186
|
fn: convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
38002
39187
|
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
@@ -38350,6 +39535,192 @@ const getTotalChannelsUnread = (callback) => {
|
|
|
38350
39535
|
};
|
|
38351
39536
|
};
|
|
38352
39537
|
|
|
39538
|
+
class ArchivedChannelPaginationController extends PaginationController {
|
|
39539
|
+
async getRequest(queryParams, token) {
|
|
39540
|
+
var _a, _b;
|
|
39541
|
+
const limit = (_a = queryParams.limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
39542
|
+
const pageIndex = token ? Number.parseInt(token, 10) : 0;
|
|
39543
|
+
if (pageIndex === 0) {
|
|
39544
|
+
await getArchivedChannelIds();
|
|
39545
|
+
}
|
|
39546
|
+
const cached = (_b = queryCache(['archivedChannel', 'get'])) !== null && _b !== void 0 ? _b : [];
|
|
39547
|
+
const archives = cached
|
|
39548
|
+
.map(entry => entry.data)
|
|
39549
|
+
.slice()
|
|
39550
|
+
.sort((a, b) => Number(new Date(b.archivedAt)) - Number(new Date(a.archivedAt)));
|
|
39551
|
+
const start = pageIndex * limit;
|
|
39552
|
+
const end = start + limit;
|
|
39553
|
+
const slice = archives.slice(start, end);
|
|
39554
|
+
const hasMore = end < archives.length;
|
|
39555
|
+
if (slice.length > 0) {
|
|
39556
|
+
await getChannelByIds$1(slice.map(archive => archive.channelId));
|
|
39557
|
+
}
|
|
39558
|
+
return {
|
|
39559
|
+
archives: slice,
|
|
39560
|
+
paging: {
|
|
39561
|
+
next: hasMore ? String(pageIndex + 1) : undefined,
|
|
39562
|
+
previous: undefined,
|
|
39563
|
+
},
|
|
39564
|
+
};
|
|
39565
|
+
}
|
|
39566
|
+
}
|
|
39567
|
+
|
|
39568
|
+
class ArchivedChannelQueryStreamController extends QueryStreamController {
|
|
39569
|
+
constructor(query, cacheKey, notifyChange) {
|
|
39570
|
+
super(query, cacheKey);
|
|
39571
|
+
this.notifyChange = notifyChange;
|
|
39572
|
+
}
|
|
39573
|
+
async saveToMainDB(_response) {
|
|
39574
|
+
//
|
|
39575
|
+
}
|
|
39576
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39577
|
+
var _a, _b;
|
|
39578
|
+
const channelIds = response.archives.map(archive => archive.channelId);
|
|
39579
|
+
if (refresh) {
|
|
39580
|
+
pushToCache(this.cacheKey, {
|
|
39581
|
+
data: channelIds,
|
|
39582
|
+
params: {},
|
|
39583
|
+
});
|
|
39584
|
+
return;
|
|
39585
|
+
}
|
|
39586
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39587
|
+
const existing = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39588
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: direction === "prev" /* Amity.LiveCollectionPageDirection.PREV */
|
|
39589
|
+
? [...new Set([...channelIds, ...existing])]
|
|
39590
|
+
: [...new Set([...existing, ...channelIds])] }));
|
|
39591
|
+
}
|
|
39592
|
+
reactor(action) {
|
|
39593
|
+
return (channelIds) => {
|
|
39594
|
+
var _a;
|
|
39595
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39596
|
+
if (!collection)
|
|
39597
|
+
return;
|
|
39598
|
+
if (action === "onArchived" /* Amity.ChannelActionType.OnArchived */) {
|
|
39599
|
+
const filtered = collection.data.filter(id => !channelIds.includes(id));
|
|
39600
|
+
collection.data = [...channelIds, ...filtered];
|
|
39601
|
+
}
|
|
39602
|
+
if (action === "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */ ||
|
|
39603
|
+
action === "onDelete" /* Amity.ChannelActionType.OnDelete */) {
|
|
39604
|
+
collection.data = collection.data.filter(id => !channelIds.includes(id));
|
|
39605
|
+
}
|
|
39606
|
+
pushToCache(this.cacheKey, collection);
|
|
39607
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
39608
|
+
};
|
|
39609
|
+
}
|
|
39610
|
+
subscribeRTE(createSubscriber) {
|
|
39611
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
39612
|
+
}
|
|
39613
|
+
}
|
|
39614
|
+
|
|
39615
|
+
class ArchivedChannelLiveCollectionController extends LiveCollectionController {
|
|
39616
|
+
constructor(query, callback) {
|
|
39617
|
+
const queryStreamId = hash(query);
|
|
39618
|
+
const cacheKey = ['archivedChannel', 'collection', queryStreamId];
|
|
39619
|
+
const paginationController = new ArchivedChannelPaginationController(query);
|
|
39620
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
39621
|
+
this.queryStreamController = new ArchivedChannelQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this));
|
|
39622
|
+
this.callback = callback.bind(this);
|
|
39623
|
+
this.loadPage({ initial: true });
|
|
39624
|
+
}
|
|
39625
|
+
setup() {
|
|
39626
|
+
var _a;
|
|
39627
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39628
|
+
if (!collection) {
|
|
39629
|
+
pushToCache(this.cacheKey, {
|
|
39630
|
+
data: [],
|
|
39631
|
+
params: {},
|
|
39632
|
+
});
|
|
39633
|
+
}
|
|
39634
|
+
}
|
|
39635
|
+
async persistModel(response) {
|
|
39636
|
+
await this.queryStreamController.saveToMainDB(response);
|
|
39637
|
+
}
|
|
39638
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
39639
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
39640
|
+
}
|
|
39641
|
+
startSubscription() {
|
|
39642
|
+
return this.queryStreamController.subscribeRTE([
|
|
39643
|
+
{
|
|
39644
|
+
fn: reactor => onChannelArchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
39645
|
+
action: "onArchived" /* Amity.ChannelActionType.OnArchived */,
|
|
39646
|
+
},
|
|
39647
|
+
{
|
|
39648
|
+
fn: reactor => onChannelUnarchived(payload => reactor(payload.archives.map(archive => archive.channelId))),
|
|
39649
|
+
action: "onUnarchived" /* Amity.ChannelActionType.OnUnarchived */,
|
|
39650
|
+
},
|
|
39651
|
+
{
|
|
39652
|
+
fn: reactor => onChannelUpdated(channel => reactor([channel.channelId])),
|
|
39653
|
+
action: "onUpdate" /* Amity.ChannelActionType.OnUpdate */,
|
|
39654
|
+
},
|
|
39655
|
+
{
|
|
39656
|
+
fn: reactor => onChannelDeleted(channel => reactor([channel.channelId])),
|
|
39657
|
+
action: "onDelete" /* Amity.ChannelActionType.OnDelete */,
|
|
39658
|
+
},
|
|
39659
|
+
]);
|
|
39660
|
+
}
|
|
39661
|
+
notifyChange({ origin, loading, error }) {
|
|
39662
|
+
var _a, _b;
|
|
39663
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39664
|
+
if (!collection)
|
|
39665
|
+
return;
|
|
39666
|
+
const data = (_b = collection.data
|
|
39667
|
+
.map(channelId => pullFromCache(['channel', 'get', channelId]))
|
|
39668
|
+
.filter((entry) => Boolean(entry))
|
|
39669
|
+
.map(({ data: channel }) => channel)
|
|
39670
|
+
.map(constructChannelObject)) !== null && _b !== void 0 ? _b : [];
|
|
39671
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
39672
|
+
return;
|
|
39673
|
+
this.callback({
|
|
39674
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
39675
|
+
data,
|
|
39676
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
39677
|
+
loading,
|
|
39678
|
+
error,
|
|
39679
|
+
});
|
|
39680
|
+
}
|
|
39681
|
+
}
|
|
39682
|
+
|
|
39683
|
+
/* begin_public_function
|
|
39684
|
+
id: channel.archive.collection
|
|
39685
|
+
*/
|
|
39686
|
+
/**
|
|
39687
|
+
* ```js
|
|
39688
|
+
* import { ChannelRepository } from '@amityco/ts-sdk'
|
|
39689
|
+
*
|
|
39690
|
+
* let channels = []
|
|
39691
|
+
* const unsub = ChannelRepository.getArchivedChannels(params, response => merge(channels, response.data))
|
|
39692
|
+
* ```
|
|
39693
|
+
*
|
|
39694
|
+
* Live collection of {@link Amity.Channel}s archived by the active user.
|
|
39695
|
+
*
|
|
39696
|
+
* @param params Live collection parameters (only `limit` is honored; the
|
|
39697
|
+
* archive list takes no other filters).
|
|
39698
|
+
* @param callback the function to call when new data are available
|
|
39699
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to
|
|
39700
|
+
* stop observing.
|
|
39701
|
+
*
|
|
39702
|
+
* @category Channel Live Collection
|
|
39703
|
+
*/
|
|
39704
|
+
const getArchivedChannels = (params, callback) => {
|
|
39705
|
+
const { log, cache } = getActiveClient();
|
|
39706
|
+
if (!cache) {
|
|
39707
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
39708
|
+
}
|
|
39709
|
+
const timestamp = Date.now();
|
|
39710
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > listen`);
|
|
39711
|
+
const controller = new ArchivedChannelLiveCollectionController(params, callback);
|
|
39712
|
+
const disposers = controller.startSubscription();
|
|
39713
|
+
const cacheKey = controller.getCacheKey();
|
|
39714
|
+
disposers.push(() => {
|
|
39715
|
+
dropFromCache(cacheKey);
|
|
39716
|
+
});
|
|
39717
|
+
return () => {
|
|
39718
|
+
log(`getArchivedChannels(tmpid: ${timestamp}) > dispose`);
|
|
39719
|
+
disposers.forEach(fn => fn());
|
|
39720
|
+
};
|
|
39721
|
+
};
|
|
39722
|
+
/* end_public_function */
|
|
39723
|
+
|
|
38353
39724
|
/* begin_public_function
|
|
38354
39725
|
id: channel.member.add
|
|
38355
39726
|
*/
|
|
@@ -38481,7 +39852,9 @@ class ChannelMemberQueryStreamController extends QueryStreamController {
|
|
|
38481
39852
|
channelId: this.query.channelId,
|
|
38482
39853
|
userId: channelMember.userId,
|
|
38483
39854
|
});
|
|
38484
|
-
|
|
39855
|
+
const membershipFilter = this.query.memberships;
|
|
39856
|
+
const isInFilter = !membershipFilter || membershipFilter.includes(channelMember.membership);
|
|
39857
|
+
if (channelMember.membership === 'none' || !isInFilter) {
|
|
38485
39858
|
collection.data = collection.data.filter(m => m !== channelMemberCacheId);
|
|
38486
39859
|
}
|
|
38487
39860
|
else if (!collection.data.includes(channelMemberCacheId)) {
|
|
@@ -38817,6 +40190,7 @@ const banMembers$1 = async (channelId, userIds) => {
|
|
|
38817
40190
|
const cachedAt = client.cache && Date.now();
|
|
38818
40191
|
if (client.cache)
|
|
38819
40192
|
ingestInCache(preparedPayload, { cachedAt });
|
|
40193
|
+
fireEvent('channel.banned', payload);
|
|
38820
40194
|
return {
|
|
38821
40195
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'banned'),
|
|
38822
40196
|
cachedAt,
|
|
@@ -38851,6 +40225,7 @@ const unbanMembers$1 = async (channelId, userIds) => {
|
|
|
38851
40225
|
const cachedAt = client.cache && Date.now();
|
|
38852
40226
|
if (client.cache)
|
|
38853
40227
|
ingestInCache(preparedPayload, { cachedAt });
|
|
40228
|
+
fireEvent('channel.unbanned', payload);
|
|
38854
40229
|
const { channelUsers } = preparedPayload;
|
|
38855
40230
|
return {
|
|
38856
40231
|
data: channelUsers === null || channelUsers === void 0 ? void 0 : channelUsers.filter(user => user.membership === 'member'),
|
|
@@ -38879,6 +40254,7 @@ const MUTE_FOREVER = -1;
|
|
|
38879
40254
|
* @async
|
|
38880
40255
|
* */
|
|
38881
40256
|
const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
40257
|
+
var _a;
|
|
38882
40258
|
const client = getActiveClient();
|
|
38883
40259
|
client.log('channel/muteMembers', { userIds, channelId, mutePeriod });
|
|
38884
40260
|
const { data } = await client.http.put(`/api/v2/channel/${channelId}/users/mute`, {
|
|
@@ -38886,6 +40262,15 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
38886
40262
|
mutePeriod: mutePeriod === MUTE_FOREVER ? mutePeriod : mutePeriod * 1000,
|
|
38887
40263
|
});
|
|
38888
40264
|
const { success } = data;
|
|
40265
|
+
const muteTimeout = mutePeriod === MUTE_FOREVER
|
|
40266
|
+
? new Date('9999-12-31T23:59:59.999Z').toISOString()
|
|
40267
|
+
: new Date(Date.now() + mutePeriod * 1000).toISOString();
|
|
40268
|
+
fireEvent('channel.setMutedUsers', {
|
|
40269
|
+
channelId,
|
|
40270
|
+
userIds,
|
|
40271
|
+
muteTimeout,
|
|
40272
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
40273
|
+
});
|
|
38889
40274
|
return success;
|
|
38890
40275
|
};
|
|
38891
40276
|
/* end_public_function */
|
|
@@ -38908,6 +40293,7 @@ const muteMembers = async (channelId, userIds, mutePeriod = MUTE_FOREVER) => {
|
|
|
38908
40293
|
* @async
|
|
38909
40294
|
* */
|
|
38910
40295
|
const unmuteMembers = async (channelId, userIds) => {
|
|
40296
|
+
var _a;
|
|
38911
40297
|
const client = getActiveClient();
|
|
38912
40298
|
client.log('channel/unmuteMembers', { userIds, channelId });
|
|
38913
40299
|
const { data } = await client.http.put(`/api/v2/channel/${encodeURIComponent(channelId)}/users/mute`, {
|
|
@@ -38915,6 +40301,12 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
38915
40301
|
mutePeriod: 0,
|
|
38916
40302
|
});
|
|
38917
40303
|
const { success } = data;
|
|
40304
|
+
fireEvent('channel.setMutedUsers', {
|
|
40305
|
+
channelId,
|
|
40306
|
+
userIds,
|
|
40307
|
+
muteTimeout: new Date(0).toISOString(),
|
|
40308
|
+
actor: (_a = client.userId) !== null && _a !== void 0 ? _a : '',
|
|
40309
|
+
});
|
|
38918
40310
|
return success;
|
|
38919
40311
|
};
|
|
38920
40312
|
/* end_public_function */
|
|
@@ -38941,6 +40333,9 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38941
40333
|
leaveChannel: leaveChannel,
|
|
38942
40334
|
muteChannel: muteChannel,
|
|
38943
40335
|
unmuteChannel: unmuteChannel,
|
|
40336
|
+
archiveChannel: archiveChannel,
|
|
40337
|
+
unarchiveChannel: unarchiveChannel,
|
|
40338
|
+
getArchivedChannelIds: getArchivedChannelIds,
|
|
38944
40339
|
onChannelCreated: onChannelCreated,
|
|
38945
40340
|
onChannelUpdated: onChannelUpdated,
|
|
38946
40341
|
onChannelDeleted: onChannelDeleted,
|
|
@@ -38953,9 +40348,12 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
38953
40348
|
onChannelMemberUnbanned: onChannelMemberUnbanned,
|
|
38954
40349
|
onChannelMemberRoleAdded: onChannelMemberRoleAdded,
|
|
38955
40350
|
onChannelMemberRoleRemoved: onChannelMemberRoleRemoved,
|
|
40351
|
+
onChannelArchived: onChannelArchived,
|
|
40352
|
+
onChannelUnarchived: onChannelUnarchived,
|
|
38956
40353
|
getChannel: getChannel,
|
|
38957
40354
|
getChannels: getChannels,
|
|
38958
40355
|
getTotalChannelsUnread: getTotalChannelsUnread,
|
|
40356
|
+
getArchivedChannels: getArchivedChannels,
|
|
38959
40357
|
MARKER_INCLUDED_CHANNEL_TYPE: MARKER_INCLUDED_CHANNEL_TYPE,
|
|
38960
40358
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
38961
40359
|
convertFromRaw: convertFromRaw,
|
|
@@ -42851,7 +44249,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42851
44249
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
42852
44250
|
}
|
|
42853
44251
|
startSubscription() {
|
|
42854
|
-
|
|
44252
|
+
const disposers = this.queryStreamController.subscribeRTE([
|
|
42855
44253
|
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
42856
44254
|
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
42857
44255
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
@@ -42864,6 +44262,11 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42864
44262
|
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
42865
44263
|
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
42866
44264
|
]);
|
|
44265
|
+
if (this.query.excludeBlockUserComments) {
|
|
44266
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
44267
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
44268
|
+
}
|
|
44269
|
+
return disposers;
|
|
42867
44270
|
}
|
|
42868
44271
|
notifyChange({ origin, loading, error }) {
|
|
42869
44272
|
var _a, _b;
|
|
@@ -42916,6 +44319,9 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
42916
44319
|
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
44320
|
}
|
|
42918
44321
|
}
|
|
44322
|
+
if (this.query.excludeBlockUserComments) {
|
|
44323
|
+
comments = filterCommentsByBlockUsers(comments);
|
|
44324
|
+
}
|
|
42919
44325
|
switch (this.query.sortBy) {
|
|
42920
44326
|
case 'firstCreated':
|
|
42921
44327
|
comments = comments.sort(sortByFirstCreated);
|
|
@@ -44001,13 +45407,218 @@ const getCommunityFeed = (params, callback, config) => {
|
|
|
44001
45407
|
};
|
|
44002
45408
|
/* end_public_function */
|
|
44003
45409
|
|
|
45410
|
+
/**
|
|
45411
|
+
* Thrown by `getForYouFeed` when the network has the For You feature
|
|
45412
|
+
* disabled. Mapped from HTTP 404 NOT_FOUND. Distinct from a generic
|
|
45413
|
+
* not-found so consumers can hide the For You tab without retrying.
|
|
45414
|
+
*
|
|
45415
|
+
* @category Errors
|
|
45416
|
+
*/
|
|
45417
|
+
class AmityForYouFeedDisabledError extends ASCApiError {
|
|
45418
|
+
constructor(message = 'For You feed is not enabled for this network') {
|
|
45419
|
+
super(message, 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
45420
|
+
this.type = 'AmityForYouFeedDisabledError';
|
|
45421
|
+
}
|
|
45422
|
+
}
|
|
45423
|
+
|
|
45424
|
+
class ForYouFeedPaginationController extends PaginationController {
|
|
45425
|
+
constructor(query) {
|
|
45426
|
+
super(query);
|
|
45427
|
+
this.checkedDisk = false;
|
|
45428
|
+
this.cursor = CursorController.current();
|
|
45429
|
+
}
|
|
45430
|
+
async getRequest(_queryParams, token) {
|
|
45431
|
+
let effectiveToken = token;
|
|
45432
|
+
if (!effectiveToken && !this.checkedDisk && this.cursor) {
|
|
45433
|
+
this.checkedDisk = true;
|
|
45434
|
+
const stored = await this.cursor.get();
|
|
45435
|
+
if (stored && !CursorController.isExpired(stored.expiredAt)) {
|
|
45436
|
+
effectiveToken = stored.cursor;
|
|
45437
|
+
}
|
|
45438
|
+
else if (stored) {
|
|
45439
|
+
await this.cursor.clear();
|
|
45440
|
+
}
|
|
45441
|
+
}
|
|
45442
|
+
const options = {
|
|
45443
|
+
limit: COLLECTION_DEFAULT_PAGINATION_SIZE,
|
|
45444
|
+
};
|
|
45445
|
+
if (effectiveToken)
|
|
45446
|
+
options.token = effectiveToken;
|
|
45447
|
+
let queryResponse;
|
|
45448
|
+
try {
|
|
45449
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options } }));
|
|
45450
|
+
}
|
|
45451
|
+
catch (error) {
|
|
45452
|
+
if (error instanceof ASCApiError && error.code === 400300 /* Amity.ServerError.FORBIDDEN */) {
|
|
45453
|
+
throw new AmityForYouFeedDisabledError();
|
|
45454
|
+
}
|
|
45455
|
+
const recoverable = error instanceof ASCApiError && error.code === 400322 /* Amity.ServerError.FEED_SNAPSHOT_EXPIRED */;
|
|
45456
|
+
if (recoverable && effectiveToken !== undefined) {
|
|
45457
|
+
if (this.cursor)
|
|
45458
|
+
await this.cursor.clear();
|
|
45459
|
+
({ data: queryResponse } = await this.http.get(API_ENDPOINTS.forYouFeed, { params: { options: { limit: COLLECTION_DEFAULT_PAGINATION_SIZE } } }));
|
|
45460
|
+
}
|
|
45461
|
+
else {
|
|
45462
|
+
throw error;
|
|
45463
|
+
}
|
|
45464
|
+
}
|
|
45465
|
+
await this.persistCursor(queryResponse);
|
|
45466
|
+
return queryResponse;
|
|
45467
|
+
}
|
|
45468
|
+
async persistCursor(response) {
|
|
45469
|
+
var _a, _b;
|
|
45470
|
+
if (!this.cursor)
|
|
45471
|
+
return;
|
|
45472
|
+
const cursor = (_a = response.paging) === null || _a === void 0 ? void 0 : _a.next;
|
|
45473
|
+
const expiredAtIso = (_b = response.paging) === null || _b === void 0 ? void 0 : _b.expiredAt;
|
|
45474
|
+
if (!cursor || !expiredAtIso)
|
|
45475
|
+
return;
|
|
45476
|
+
const expiredAt = Date.parse(expiredAtIso);
|
|
45477
|
+
if (Number.isNaN(expiredAt))
|
|
45478
|
+
return;
|
|
45479
|
+
await this.cursor.set({ cursor, expiredAt });
|
|
45480
|
+
}
|
|
45481
|
+
}
|
|
45482
|
+
|
|
45483
|
+
class ForYouFeedQueryStreamController extends QueryStreamController {
|
|
45484
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
45485
|
+
super(query, cacheKey);
|
|
45486
|
+
this.notifyChange = notifyChange;
|
|
45487
|
+
this.preparePayload = preparePayload;
|
|
45488
|
+
}
|
|
45489
|
+
async saveToMainDB(response) {
|
|
45490
|
+
const processedPayload = await this.preparePayload(response);
|
|
45491
|
+
const client = getActiveClient();
|
|
45492
|
+
const cachedAt = client.cache && Date.now();
|
|
45493
|
+
if (client.cache)
|
|
45494
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
45495
|
+
}
|
|
45496
|
+
appendToQueryStream(response, _direction, refresh = false) {
|
|
45497
|
+
var _a, _b;
|
|
45498
|
+
if (refresh) {
|
|
45499
|
+
pushToCache(this.cacheKey, {
|
|
45500
|
+
data: response.posts.map(getResolver('post')),
|
|
45501
|
+
});
|
|
45502
|
+
}
|
|
45503
|
+
else {
|
|
45504
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45505
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
45506
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
45507
|
+
}
|
|
45508
|
+
}
|
|
45509
|
+
reactor(action) {
|
|
45510
|
+
return (post) => {
|
|
45511
|
+
var _a;
|
|
45512
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45513
|
+
if (!collection)
|
|
45514
|
+
return;
|
|
45515
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
45516
|
+
return;
|
|
45517
|
+
if (action === EnumPostActions.OnPostDeleted || action === EnumPostActions.OnPostDeclined) {
|
|
45518
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
45519
|
+
}
|
|
45520
|
+
pushToCache(this.cacheKey, collection);
|
|
45521
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
45522
|
+
};
|
|
45523
|
+
}
|
|
45524
|
+
subscribeRTE(createSubscriber) {
|
|
45525
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
45526
|
+
}
|
|
45527
|
+
}
|
|
45528
|
+
|
|
45529
|
+
const FOR_YOU_FEED_CACHE_KEY = ['forYouFeed', 'collection'];
|
|
45530
|
+
class ForYouFeedLiveCollectionController extends LiveCollectionController {
|
|
45531
|
+
constructor(callback) {
|
|
45532
|
+
const queryStreamId = `for-you-feed-${getActiveClient().userId}`;
|
|
45533
|
+
const query = {};
|
|
45534
|
+
const paginationController = new ForYouFeedPaginationController(query);
|
|
45535
|
+
super(paginationController, queryStreamId, FOR_YOU_FEED_CACHE_KEY, callback);
|
|
45536
|
+
this.queryStreamController = new ForYouFeedQueryStreamController(query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
45537
|
+
this.callback = callback.bind(this);
|
|
45538
|
+
this.loadPage({ initial: true });
|
|
45539
|
+
}
|
|
45540
|
+
setup() {
|
|
45541
|
+
var _a;
|
|
45542
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45543
|
+
if (!collection)
|
|
45544
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
45545
|
+
}
|
|
45546
|
+
async persistModel(payload) {
|
|
45547
|
+
await this.queryStreamController.saveToMainDB(payload);
|
|
45548
|
+
}
|
|
45549
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
45550
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
45551
|
+
}
|
|
45552
|
+
startSubscription() {
|
|
45553
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
45554
|
+
}
|
|
45555
|
+
notifyChange({ origin, loading, error }) {
|
|
45556
|
+
var _a, _b;
|
|
45557
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
45558
|
+
if (!collection)
|
|
45559
|
+
return;
|
|
45560
|
+
const data = ((_b = collection.data
|
|
45561
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
45562
|
+
.filter(isNonNullable)
|
|
45563
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
45564
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
45565
|
+
return;
|
|
45566
|
+
this.callback({
|
|
45567
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
45568
|
+
data,
|
|
45569
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
45570
|
+
loading,
|
|
45571
|
+
error,
|
|
45572
|
+
});
|
|
45573
|
+
}
|
|
45574
|
+
}
|
|
45575
|
+
|
|
45576
|
+
/* begin_public_function
|
|
45577
|
+
id: feed.query.for_you_feed
|
|
45578
|
+
*/
|
|
45579
|
+
/**
|
|
45580
|
+
* ```js
|
|
45581
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
45582
|
+
*
|
|
45583
|
+
* const unsub = FeedRepository.getForYouFeed(({ data, loading, error, hasNextPage, onNextPage }) => {
|
|
45584
|
+
* // render posts; call onNextPage() to load the next page (20 posts)
|
|
45585
|
+
* })
|
|
45586
|
+
* ```
|
|
45587
|
+
*
|
|
45588
|
+
* Observe the For You feed — a personalized, server-ranked
|
|
45589
|
+
* {@link Amity.LiveCollection} of {@link Amity.Post}.
|
|
45590
|
+
*
|
|
45591
|
+
* @param callback the function to call when new data is available
|
|
45592
|
+
* @returns an {@link Amity.Unsubscriber} function to stop observing
|
|
45593
|
+
*
|
|
45594
|
+
* @category Posts Live Collection
|
|
45595
|
+
*/
|
|
45596
|
+
const getForYouFeed = (callback) => {
|
|
45597
|
+
const { log, cache } = getActiveClient();
|
|
45598
|
+
if (!cache)
|
|
45599
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
45600
|
+
const timestamp = Date.now();
|
|
45601
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > listen`);
|
|
45602
|
+
const forYouFeedLiveCollection = new ForYouFeedLiveCollectionController(callback);
|
|
45603
|
+
const disposers = forYouFeedLiveCollection.startSubscription();
|
|
45604
|
+
const cacheKey = forYouFeedLiveCollection.getCacheKey();
|
|
45605
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
45606
|
+
return () => {
|
|
45607
|
+
log(`getForYouFeed(tmpid: ${timestamp}) > dispose`);
|
|
45608
|
+
disposers.forEach(fn => fn());
|
|
45609
|
+
};
|
|
45610
|
+
};
|
|
45611
|
+
/* end_public_function */
|
|
45612
|
+
|
|
44004
45613
|
var index$d = /*#__PURE__*/Object.freeze({
|
|
44005
45614
|
__proto__: null,
|
|
44006
45615
|
queryGlobalFeed: queryGlobalFeed,
|
|
44007
45616
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
44008
45617
|
getGlobalFeed: getGlobalFeed,
|
|
44009
45618
|
getUserFeed: getUserFeed,
|
|
44010
|
-
getCommunityFeed: getCommunityFeed
|
|
45619
|
+
getCommunityFeed: getCommunityFeed,
|
|
45620
|
+
getForYouFeed: getForYouFeed,
|
|
45621
|
+
AmityForYouFeedDisabledError: AmityForYouFeedDisabledError
|
|
44011
45622
|
});
|
|
44012
45623
|
|
|
44013
45624
|
/* begin_public_function
|
|
@@ -44874,29 +46485,6 @@ const getPost = (postId, callback) => {
|
|
|
44874
46485
|
};
|
|
44875
46486
|
/* end_public_function */
|
|
44876
46487
|
|
|
44877
|
-
class PostPaginationController extends PaginationController {
|
|
44878
|
-
async getRequest(queryParams, token) {
|
|
44879
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost, untilAt } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost", "untilAt"]);
|
|
44880
|
-
const { dataTypes } = params;
|
|
44881
|
-
const baseOptions = {
|
|
44882
|
-
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
44883
|
-
};
|
|
44884
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
44885
|
-
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
44886
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
44887
|
-
/*
|
|
44888
|
-
* when creating post like image, file, video BE will create 2 posts
|
|
44889
|
-
* 1. parent post to store text with dataType=text
|
|
44890
|
-
* 2. child post to store dataTypes post data
|
|
44891
|
-
*
|
|
44892
|
-
* By default, BE queries only parent post
|
|
44893
|
-
*/
|
|
44894
|
-
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
44895
|
-
});
|
|
44896
|
-
return queryResponse;
|
|
44897
|
-
}
|
|
44898
|
-
}
|
|
44899
|
-
|
|
44900
46488
|
class PostQueryStreamController extends QueryStreamController {
|
|
44901
46489
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
44902
46490
|
super(query, cacheKey);
|
|
@@ -44992,6 +46580,29 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
44992
46580
|
}
|
|
44993
46581
|
}
|
|
44994
46582
|
|
|
46583
|
+
class PostPaginationController extends PaginationController {
|
|
46584
|
+
async getRequest(queryParams, token) {
|
|
46585
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted, matchingOnlyParentPost, untilAt } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted", "matchingOnlyParentPost", "untilAt"]);
|
|
46586
|
+
const { dataTypes } = params;
|
|
46587
|
+
const baseOptions = {
|
|
46588
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
46589
|
+
};
|
|
46590
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
46591
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/posts`, {
|
|
46592
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted),
|
|
46593
|
+
/*
|
|
46594
|
+
* when creating post like image, file, video BE will create 2 posts
|
|
46595
|
+
* 1. parent post to store text with dataType=text
|
|
46596
|
+
* 2. child post to store dataTypes post data
|
|
46597
|
+
*
|
|
46598
|
+
* By default, BE queries only parent post
|
|
46599
|
+
*/
|
|
46600
|
+
matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
|
|
46601
|
+
});
|
|
46602
|
+
return queryResponse;
|
|
46603
|
+
}
|
|
46604
|
+
}
|
|
46605
|
+
|
|
44995
46606
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
44996
46607
|
constructor(query, callback) {
|
|
44997
46608
|
const queryStreamId = hash(query);
|
|
@@ -45020,7 +46631,12 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
45020
46631
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
45021
46632
|
}
|
|
45022
46633
|
startSubscription() {
|
|
45023
|
-
|
|
46634
|
+
const disposers = this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
46635
|
+
if (this.query.excludeBlockUserPosts) {
|
|
46636
|
+
const refresh = () => this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
46637
|
+
disposers.push(onUserDidBlock(refresh), onUserDidUnblock(refresh));
|
|
46638
|
+
}
|
|
46639
|
+
return disposers;
|
|
45024
46640
|
}
|
|
45025
46641
|
notifyChange({ origin, loading, error }) {
|
|
45026
46642
|
var _a, _b;
|
|
@@ -45066,6 +46682,9 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
45066
46682
|
const sortBy = this.query.sortBy || 'lastCreated';
|
|
45067
46683
|
posts = posts.filter(post => !exceedsUntilAtBoundary(post.createdAt, validatedUntilAt, sortBy));
|
|
45068
46684
|
}
|
|
46685
|
+
if (this.query.excludeBlockUserPosts) {
|
|
46686
|
+
posts = filterPostsByBlockUsers(posts);
|
|
46687
|
+
}
|
|
45069
46688
|
switch (this.query.sortBy) {
|
|
45070
46689
|
case 'firstCreated':
|
|
45071
46690
|
posts = posts.sort(sortByFirstCreated);
|
|
@@ -51731,4 +53350,4 @@ class AmityAttachmentProductTags {
|
|
|
51731
53350
|
}
|
|
51732
53351
|
}
|
|
51733
53352
|
|
|
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 };
|
|
53353
|
+
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 };
|