@amityco/ts-sdk 7.27.1 → 7.27.2-1852fdfa.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 +5 -0
- package/dist/@types/core/events.d.ts.map +1 -1
- package/dist/@types/core/payload.d.ts +26 -0
- package/dist/@types/core/payload.d.ts.map +1 -1
- package/dist/@types/core/permissions.d.ts +10 -4
- package/dist/@types/core/permissions.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 -1
- package/dist/@types/domains/analytics.d.ts.map +1 -1
- package/dist/@types/domains/channel.d.ts +5 -0
- package/dist/@types/domains/channel.d.ts.map +1 -1
- package/dist/@types/domains/client.d.ts +104 -0
- package/dist/@types/domains/client.d.ts.map +1 -1
- package/dist/@types/domains/comment.d.ts +27 -0
- package/dist/@types/domains/comment.d.ts.map +1 -1
- package/dist/@types/domains/community.d.ts +1 -0
- package/dist/@types/domains/community.d.ts.map +1 -1
- package/dist/@types/domains/content.d.ts +11 -0
- package/dist/@types/domains/content.d.ts.map +1 -1
- package/dist/@types/domains/curatedContent.d.ts +25 -0
- package/dist/@types/domains/curatedContent.d.ts.map +1 -0
- package/dist/@types/domains/pinnedMessage.d.ts +43 -0
- package/dist/@types/domains/pinnedMessage.d.ts.map +1 -0
- package/dist/@types/domains/post.d.ts +11 -0
- package/dist/@types/domains/post.d.ts.map +1 -1
- package/dist/@types/domains/user.d.ts +31 -0
- package/dist/@types/domains/user.d.ts.map +1 -1
- 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 +3 -0
- package/dist/analytic/service/analytic/AnalyticsEngine.d.ts.map +1 -1
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts +3 -0
- package/dist/analytic/service/analytic/AnalyticsEventCapturer.d.ts.map +1 -1
- package/dist/channelRepository/api/createChannel.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/onChannelMemberRoleAdded.d.ts +22 -0
- package/dist/channelRepository/events/onChannelMemberRoleAdded.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts +22 -0
- package/dist/channelRepository/events/onChannelMemberRoleRemoved.d.ts.map +1 -1
- package/dist/channelRepository/events/onChannelMessagePinned.d.ts +24 -0
- package/dist/channelRepository/events/onChannelMessagePinned.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts +21 -0
- package/dist/channelRepository/events/onChannelMessageUnpinned.d.ts.map +1 -0
- package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts +12 -0
- package/dist/channelRepository/events/onChannelPinnedMessageDeleted.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleAdded.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleAdded.test.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleRemoved.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMemberRoleRemoved.test.d.ts.map +1 -0
- package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts +2 -0
- package/dist/channelRepository/events/tests/onChannelMessagePinned.test.d.ts.map +1 -0
- package/dist/channelRepository/observers/getChannel.d.ts.map +1 -1
- package/dist/channelRepository/observers/getChannels/ChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/observers/getMyMembership.d.ts.map +1 -1
- package/dist/channelRepository/observers/searchChannels/SearchChannelLiveCollectionController.d.ts.map +1 -1
- package/dist/channelRepository/utils/applyChannelRolePayload.d.ts +21 -0
- package/dist/channelRepository/utils/applyChannelRolePayload.d.ts.map +1 -0
- package/dist/channelRepository/utils/index.d.ts +2 -0
- package/dist/channelRepository/utils/index.d.ts.map +1 -1
- package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts +2 -0
- package/dist/channelRepository/utils/tests/pinnedMessage.test.d.ts.map +1 -0
- package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts +24 -0
- package/dist/channelRepository/utils/updatePinnedMessageCache.d.ts.map +1 -0
- package/dist/client/api/createClient.d.ts +5 -1
- package/dist/client/api/createClient.d.ts.map +1 -1
- package/dist/client/api/getModuleSettings.d.ts +25 -0
- package/dist/client/api/getModuleSettings.d.ts.map +1 -0
- package/dist/client/api/getSocialSettings.d.ts.map +1 -1
- package/dist/client/api/index.d.ts +1 -0
- package/dist/client/api/index.d.ts.map +1 -1
- package/dist/client/api/setupLoginSubscriptions.d.ts.map +1 -1
- package/dist/client/api/tests/getSocialSettings.test.d.ts +2 -0
- package/dist/client/api/tests/getSocialSettings.test.d.ts.map +1 -0
- package/dist/client/api/tests/integration/moduleSettings.integration.test.d.ts +2 -0
- package/dist/client/api/tests/integration/moduleSettings.integration.test.d.ts.map +1 -0
- package/dist/client/index.d.ts +1 -0
- package/dist/client/index.d.ts.map +1 -1
- package/dist/client/utils/parseModuleSettings.d.ts +9 -0
- package/dist/client/utils/parseModuleSettings.d.ts.map +1 -0
- package/dist/client/utils/resolveModuleAvailability.d.ts +39 -0
- package/dist/client/utils/resolveModuleAvailability.d.ts.map +1 -0
- package/dist/client/utils/tests/resolveModuleAvailability.test.d.ts +2 -0
- package/dist/client/utils/tests/resolveModuleAvailability.test.d.ts.map +1 -0
- package/dist/commentRepository/api/approveComment.d.ts +17 -0
- package/dist/commentRepository/api/approveComment.d.ts.map +1 -0
- package/dist/commentRepository/api/createComment.d.ts +12 -1
- package/dist/commentRepository/api/createComment.d.ts.map +1 -1
- package/dist/commentRepository/api/declineComment.d.ts +18 -0
- package/dist/commentRepository/api/declineComment.d.ts.map +1 -0
- package/dist/commentRepository/api/deleteComment.d.ts.map +1 -1
- package/dist/commentRepository/api/flagComment.d.ts +72 -5
- package/dist/commentRepository/api/flagComment.d.ts.map +1 -1
- package/dist/commentRepository/api/flagCommentWithOptions.d.ts +13 -0
- package/dist/commentRepository/api/flagCommentWithOptions.d.ts.map +1 -0
- package/dist/commentRepository/api/flagCommentWithReasonString.d.ts +16 -0
- package/dist/commentRepository/api/flagCommentWithReasonString.d.ts.map +1 -0
- package/dist/commentRepository/api/index.d.ts +2 -0
- package/dist/commentRepository/api/index.d.ts.map +1 -1
- package/dist/commentRepository/api/tests/approveComment.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/approveComment.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/createComment.optimistic.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/createComment.optimistic.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/declineComment.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/declineComment.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/integration/flagCommentWithOptions.integration.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/integration/flagCommentWithOptions.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/api/tests/integration/flagCommentWithReasonString.integration.test.d.ts +2 -0
- package/dist/commentRepository/api/tests/integration/flagCommentWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/api/updateComment.d.ts.map +1 -1
- package/dist/commentRepository/events/index.d.ts +1 -0
- package/dist/commentRepository/events/index.d.ts.map +1 -1
- package/dist/commentRepository/events/onCommentApproved.d.ts +17 -0
- package/dist/commentRepository/events/onCommentApproved.d.ts.map +1 -0
- package/dist/commentRepository/events/tests/onCommentApproved.test.d.ts +2 -0
- package/dist/commentRepository/events/tests/onCommentApproved.test.d.ts.map +1 -0
- package/dist/commentRepository/events/tests/onCommentCreated.count.test.d.ts +2 -0
- package/dist/commentRepository/events/tests/onCommentCreated.count.test.d.ts.map +1 -0
- package/dist/commentRepository/events/utils.d.ts.map +1 -1
- package/dist/commentRepository/internalApi/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComment.d.ts.map +1 -1
- package/dist/commentRepository/observers/getCommentReviewQueue/LiveCollectionController.d.ts +13 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/LiveCollectionController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/PaginationController.d.ts +5 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/PaginationController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/QueryStreamController.d.ts +15 -0
- package/dist/commentRepository/observers/getCommentReviewQueue/QueryStreamController.d.ts.map +1 -0
- package/dist/commentRepository/observers/getCommentReviewQueue.d.ts +22 -0
- package/dist/commentRepository/observers/getCommentReviewQueue.d.ts.map +1 -0
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts +1 -1
- package/dist/commentRepository/observers/getComments/CommentLiveCollectionController.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/CommentQueryStreamController.d.ts.map +1 -1
- package/dist/commentRepository/observers/getComments/enums.d.ts +1 -0
- package/dist/commentRepository/observers/getComments/enums.d.ts.map +1 -1
- package/dist/commentRepository/observers/index.d.ts +1 -0
- package/dist/commentRepository/observers/index.d.ts.map +1 -1
- package/dist/commentRepository/observers/tests/integrations/getCommentReviewQueue.integration.test.d.ts +2 -0
- package/dist/commentRepository/observers/tests/integrations/getCommentReviewQueue.integration.test.d.ts.map +1 -0
- package/dist/commentRepository/utils/approval.d.ts +49 -0
- package/dist/commentRepository/utils/approval.d.ts.map +1 -0
- package/dist/commentRepository/utils/payload.d.ts +6 -0
- package/dist/commentRepository/utils/payload.d.ts.map +1 -1
- package/dist/commentRepository/utils/tests/approval.test.d.ts +2 -0
- package/dist/commentRepository/utils/tests/approval.test.d.ts.map +1 -0
- package/dist/commentRepository/utils/tests/payload.test.d.ts +2 -0
- package/dist/commentRepository/utils/tests/payload.test.d.ts.map +1 -0
- package/dist/communityRepository/api/createCommunity.d.ts +1 -1
- package/dist/communityRepository/api/createCommunity.d.ts.map +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts +1 -1
- package/dist/communityRepository/api/updateCommunity.d.ts.map +1 -1
- package/dist/core/device.d.ts +1 -1
- package/dist/core/device.d.ts.map +1 -1
- package/dist/core/errors.d.ts +20 -0
- package/dist/core/errors.d.ts.map +1 -1
- package/dist/core/events.d.ts +3 -3
- package/dist/core/events.d.ts.map +1 -1
- package/dist/core/tests/device.test.d.ts +2 -0
- package/dist/core/tests/device.test.d.ts.map +1 -0
- package/dist/core/transports/http.d.ts.map +1 -1
- package/dist/core/transports/tests/moduleNotEntitled.test.d.ts +2 -0
- package/dist/core/transports/tests/moduleNotEntitled.test.d.ts.map +1 -0
- package/dist/core/transports/utils.d.ts +8 -0
- package/dist/core/transports/utils.d.ts.map +1 -1
- package/dist/curatedContentRepository/api/getPool.d.ts +2 -0
- package/dist/curatedContentRepository/api/getPool.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/index.d.ts +2 -0
- package/dist/curatedContentRepository/api/index.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/tests/getPool.test.d.ts +2 -0
- package/dist/curatedContentRepository/api/tests/getPool.test.d.ts.map +1 -0
- package/dist/curatedContentRepository/api/tests/integration/getPool.integration.test.d.ts +2 -0
- package/dist/curatedContentRepository/api/tests/integration/getPool.integration.test.d.ts.map +1 -0
- package/dist/curatedContentRepository/index.d.ts +2 -0
- package/dist/curatedContentRepository/index.d.ts.map +1 -0
- package/dist/index.cjs.js +2398 -521
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.esm.js +2371 -497
- package/dist/index.umd.js +2 -2
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts +1 -0
- package/dist/messagePreview/utils/getChannelMessagePreviewWithUser.d.ts.map +1 -1
- package/dist/messageRepository/api/flagMessage.d.ts +73 -6
- package/dist/messageRepository/api/flagMessage.d.ts.map +1 -1
- package/dist/messageRepository/api/flagMessageWithOptions.d.ts +13 -0
- package/dist/messageRepository/api/flagMessageWithOptions.d.ts.map +1 -0
- package/dist/messageRepository/api/flagMessageWithReasonString.d.ts +17 -0
- package/dist/messageRepository/api/flagMessageWithReasonString.d.ts.map +1 -0
- package/dist/messageRepository/api/index.d.ts +2 -0
- package/dist/messageRepository/api/index.d.ts.map +1 -1
- package/dist/messageRepository/api/pinMessage.d.ts +29 -0
- package/dist/messageRepository/api/pinMessage.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/integration/flagMessage.overloads.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/integration/flagMessageWithOptions.integration.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/integration/flagMessageWithOptions.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/integration/flagMessageWithReasonString.integration.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/integration/flagMessageWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/pinMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/pinMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/tests/unpinMessage.test.d.ts +2 -0
- package/dist/messageRepository/api/tests/unpinMessage.test.d.ts.map +1 -0
- package/dist/messageRepository/api/unpinMessage.d.ts +28 -0
- package/dist/messageRepository/api/unpinMessage.d.ts.map +1 -0
- package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts +13 -0
- package/dist/messageRepository/utils/refreshChannelPermissionsForMessage.d.ts.map +1 -0
- package/dist/postRepository/api/flagPost.d.ts +73 -6
- package/dist/postRepository/api/flagPost.d.ts.map +1 -1
- package/dist/postRepository/api/flagPostWithOptions.d.ts +13 -0
- package/dist/postRepository/api/flagPostWithOptions.d.ts.map +1 -0
- package/dist/postRepository/api/flagPostWithReasonString.d.ts +16 -0
- package/dist/postRepository/api/flagPostWithReasonString.d.ts.map +1 -0
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts +2 -0
- package/dist/postRepository/api/tests/integration/flagPost.overloads.integration.test.d.ts.map +1 -0
- package/dist/postRepository/api/tests/integration/flagPostWithOptions.integration.test.d.ts +2 -0
- package/dist/postRepository/api/tests/integration/flagPostWithOptions.integration.test.d.ts.map +1 -0
- package/dist/postRepository/api/tests/integration/flagPostWithReasonString.integration.test.d.ts +2 -0
- package/dist/postRepository/api/tests/integration/flagPostWithReasonString.integration.test.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ApproveTask.d.ts +16 -0
- package/dist/postRepository/utils/PostCommentCountEngine/ApproveTask.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts +25 -1
- package/dist/postRepository/utils/PostCommentCountEngine/PostCommentCountEngine.d.ts.map +1 -1
- package/dist/postRepository/utils/PostCommentCountEngine/postCommentCountEngineOnLoginHandler.d.ts +9 -0
- package/dist/postRepository/utils/PostCommentCountEngine/postCommentCountEngineOnLoginHandler.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/getLocalCommentCount.test.d.ts +2 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/getLocalCommentCount.test.d.ts.map +1 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/pendingAuthoredComments.test.d.ts +2 -0
- package/dist/postRepository/utils/PostCommentCountEngine/tests/pendingAuthoredComments.test.d.ts.map +1 -0
- package/dist/postRepository/utils/latestComments.d.ts +10 -0
- package/dist/postRepository/utils/latestComments.d.ts.map +1 -0
- package/dist/postRepository/utils/payload.d.ts.map +1 -1
- package/dist/postRepository/utils/tests/latestComments.test.d.ts +2 -0
- package/dist/postRepository/utils/tests/latestComments.test.d.ts.map +1 -0
- package/dist/postRepository/utils/tests/payload.test.d.ts +2 -0
- package/dist/postRepository/utils/tests/payload.test.d.ts.map +1 -0
- package/dist/userRepository/api/flagUser.d.ts +50 -9
- package/dist/userRepository/api/flagUser.d.ts.map +1 -1
- package/dist/userRepository/api/flagUserBehavior.d.ts +29 -0
- package/dist/userRepository/api/flagUserBehavior.d.ts.map +1 -0
- package/dist/userRepository/api/flagUserProfile.d.ts +29 -0
- package/dist/userRepository/api/flagUserProfile.d.ts.map +1 -0
- package/dist/userRepository/api/index.d.ts +2 -0
- package/dist/userRepository/api/index.d.ts.map +1 -1
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUser.overloads.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserBehavior.integration.test.d.ts.map +1 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts +2 -0
- package/dist/userRepository/api/tests/integration/flagUserProfile.integration.test.d.ts.map +1 -0
- package/dist/userRepository/utils/submitUserReport.d.ts +10 -0
- package/dist/userRepository/utils/submitUserReport.d.ts.map +1 -0
- package/dist/userRepository/utils/userReport.d.ts +35 -0
- package/dist/userRepository/utils/userReport.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/contentFlag.d.ts +28 -0
- package/dist/utils/contentFlag.d.ts.map +1 -0
- package/dist/utils/linkedObject/commentLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/curatedContentTopicLinkedObject.d.ts +2 -0
- package/dist/utils/linkedObject/curatedContentTopicLinkedObject.d.ts.map +1 -0
- package/dist/utils/linkedObject/index.d.ts +1 -0
- package/dist/utils/linkedObject/index.d.ts.map +1 -1
- package/dist/utils/linkedObject/messageLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/dist/utils/linkedObject/tests/postLinkedObject.test.d.ts +2 -0
- package/dist/utils/linkedObject/tests/postLinkedObject.test.d.ts.map +1 -0
- package/dist/utils/tests/dummy/comment.d.ts +1 -0
- package/dist/utils/tests/dummy/comment.d.ts.map +1 -1
- package/dist/utils/tests/dummy/index.d.ts +1 -0
- package/dist/utils/tests/dummy/index.d.ts.map +1 -1
- package/dist/utils/tests/dummy/pinnedMessage.d.ts +2 -0
- package/dist/utils/tests/dummy/pinnedMessage.d.ts.map +1 -0
- package/dist/utils/tests/dummy/post.d.ts.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs.js
CHANGED
|
@@ -7,8 +7,9 @@ var mitt = require('mitt');
|
|
|
7
7
|
var debug = require('debug');
|
|
8
8
|
var axios = require('axios');
|
|
9
9
|
var HttpAgent = require('agentkeepalive');
|
|
10
|
-
var mqtt = require('mqtt');
|
|
11
10
|
var uuid$1 = require('react-native-uuid');
|
|
11
|
+
var mqtt = require('mqtt');
|
|
12
|
+
var uaParserJs = require('ua-parser-js');
|
|
12
13
|
var jwtDecode = require('jwt-decode');
|
|
13
14
|
var hash = require('object-hash');
|
|
14
15
|
var Hls = require('hls.js');
|
|
@@ -19,8 +20,8 @@ var mitt__default = /*#__PURE__*/_interopDefaultLegacy(mitt);
|
|
|
19
20
|
var debug__default = /*#__PURE__*/_interopDefaultLegacy(debug);
|
|
20
21
|
var axios__default = /*#__PURE__*/_interopDefaultLegacy(axios);
|
|
21
22
|
var HttpAgent__default = /*#__PURE__*/_interopDefaultLegacy(HttpAgent);
|
|
22
|
-
var mqtt__default = /*#__PURE__*/_interopDefaultLegacy(mqtt);
|
|
23
23
|
var uuid__default = /*#__PURE__*/_interopDefaultLegacy(uuid$1);
|
|
24
|
+
var mqtt__default = /*#__PURE__*/_interopDefaultLegacy(mqtt);
|
|
24
25
|
var jwtDecode__default = /*#__PURE__*/_interopDefaultLegacy(jwtDecode);
|
|
25
26
|
var hash__default = /*#__PURE__*/_interopDefaultLegacy(hash);
|
|
26
27
|
var Hls__default = /*#__PURE__*/_interopDefaultLegacy(Hls);
|
|
@@ -57,6 +58,18 @@ exports.UserReportTypeEnum = void 0;
|
|
|
57
58
|
UserReportTypeEnum["AVATAR"] = "avatarFileId";
|
|
58
59
|
UserReportTypeEnum["BEHAVIOR"] = "behavior";
|
|
59
60
|
})(exports.UserReportTypeEnum || (exports.UserReportTypeEnum = {}));
|
|
61
|
+
/**
|
|
62
|
+
* The profile field a user is reported for in `UserRepository.flagUserProfile`.
|
|
63
|
+
* Each member is the backend `reportType` wire value. There is deliberately no
|
|
64
|
+
* behavior member: behavior reports need a reason and go through
|
|
65
|
+
* `UserRepository.flagUserBehavior`.
|
|
66
|
+
*/
|
|
67
|
+
exports.UserProfileFieldEnum = void 0;
|
|
68
|
+
(function (UserProfileFieldEnum) {
|
|
69
|
+
UserProfileFieldEnum["DISPLAY_NAME"] = "displayName";
|
|
70
|
+
UserProfileFieldEnum["DESCRIPTION"] = "description";
|
|
71
|
+
UserProfileFieldEnum["AVATAR"] = "avatarFileId";
|
|
72
|
+
})(exports.UserProfileFieldEnum || (exports.UserProfileFieldEnum = {}));
|
|
60
73
|
|
|
61
74
|
const FileType = Object.freeze({
|
|
62
75
|
FILE: 'file',
|
|
@@ -341,6 +354,7 @@ function getVersion() {
|
|
|
341
354
|
const VERSION = getVersion();
|
|
342
355
|
|
|
343
356
|
const COLLECTION_DEFAULT_PAGINATION_LIMIT = 5;
|
|
357
|
+
const LATEST_COMMENTS_LIMIT = 5;
|
|
344
358
|
const COLLECTION_DEFAULT_PAGINATION_SIZE = 20;
|
|
345
359
|
const COLLECTION_DEFAULT_CACHING_POLICY = 'cache_then_server';
|
|
346
360
|
const ENABLE_CACHE_MESSAGE = 'For using Live Collection feature you need to enable Cache!';
|
|
@@ -356,7 +370,11 @@ const YEAR = 365 * DAY;
|
|
|
356
370
|
const ACCESS_TOKEN_WATCHER_INTERVAL = 10 * MINUTE;
|
|
357
371
|
const API_ENDPOINTS = {
|
|
358
372
|
forYouFeed: '/api/v1/feeds/for-you',
|
|
373
|
+
commentReviewQueue: (communityId) => `/api/v3/communities/${encodeURIComponent(communityId)}/comments/review-queue`,
|
|
359
374
|
};
|
|
375
|
+
// The review-queue route defaults to 10, not the SDK-wide page size, and caps at 100
|
|
376
|
+
const COMMENT_REVIEW_QUEUE_DEFAULT_PAGINATION_SIZE = 10;
|
|
377
|
+
const COMMENT_REVIEW_QUEUE_MAX_PAGINATION_SIZE = 100;
|
|
360
378
|
|
|
361
379
|
// cache constants
|
|
362
380
|
const CACHE_KEY_GET = 'get';
|
|
@@ -806,6 +824,40 @@ class ASCConnectionError extends ASCError {
|
|
|
806
824
|
this.event = event;
|
|
807
825
|
}
|
|
808
826
|
}
|
|
827
|
+
/**
|
|
828
|
+
* Thrown when the network does not own a module the call needs. Raised from
|
|
829
|
+
* any module endpoint under `enforce` enforcement, mapped from app code
|
|
830
|
+
* `400325` — never from HTTP 403 alone, which already covers a role problem
|
|
831
|
+
* (`400300` / `400301`), a visitor (`403999`) and a bot (`403998`).
|
|
832
|
+
*
|
|
833
|
+
* `modules` carries **every** key the refusal named, as raw strings, so a
|
|
834
|
+
* caller can say which entitlement is absent without a second request.
|
|
835
|
+
*
|
|
836
|
+
* @category Errors
|
|
837
|
+
*/
|
|
838
|
+
class AmityModuleNotEntitledError extends ASCApiError {
|
|
839
|
+
/**
|
|
840
|
+
* @param message The server's message, e.g. `Module not entitled: chat, live`
|
|
841
|
+
* @param modules Every module key from the rejection's `data.modules`
|
|
842
|
+
*/
|
|
843
|
+
constructor(message, modules = []) {
|
|
844
|
+
super(message, 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
845
|
+
this.modules = modules;
|
|
846
|
+
this.type = 'AmityModuleNotEntitledError';
|
|
847
|
+
}
|
|
848
|
+
}
|
|
849
|
+
/**
|
|
850
|
+
* Input sanitization related error
|
|
851
|
+
* @category Errors
|
|
852
|
+
*/
|
|
853
|
+
class ASCInvalidParameterError extends ASCError {
|
|
854
|
+
/**
|
|
855
|
+
* @param message A custom error message
|
|
856
|
+
*/
|
|
857
|
+
constructor(message) {
|
|
858
|
+
super(message, 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
859
|
+
}
|
|
860
|
+
}
|
|
809
861
|
|
|
810
862
|
let activeClient = null;
|
|
811
863
|
/**
|
|
@@ -1953,6 +2005,24 @@ function computeUrl(type, region) {
|
|
|
1953
2005
|
return URLS[type].replace('{region}', region);
|
|
1954
2006
|
}
|
|
1955
2007
|
|
|
2008
|
+
const uuid = () => uuid__default["default"].v4().toString();
|
|
2009
|
+
|
|
2010
|
+
/**
|
|
2011
|
+
* Reads the module keys a `MODULE_NOT_ENTITLED` rejection named.
|
|
2012
|
+
*
|
|
2013
|
+
* Every entry is kept, as a raw string: one call can need more than one
|
|
2014
|
+
* module, and a key this build predates is still the only part of the
|
|
2015
|
+
* payload a customer can act on.
|
|
2016
|
+
*
|
|
2017
|
+
* @category Transport
|
|
2018
|
+
* @hidden
|
|
2019
|
+
*/
|
|
2020
|
+
const extractNotEntitledModules = (data) => {
|
|
2021
|
+
const { modules } = data !== null && data !== void 0 ? data : {};
|
|
2022
|
+
if (!Array.isArray(modules))
|
|
2023
|
+
return [];
|
|
2024
|
+
return modules.filter((module) => typeof module === 'string');
|
|
2025
|
+
};
|
|
1956
2026
|
/**
|
|
1957
2027
|
* Unwraps v3 server payload (for error handling and type extraction)
|
|
1958
2028
|
*
|
|
@@ -1972,11 +2042,38 @@ const unwrapPayload = (response) => {
|
|
|
1972
2042
|
throw new ASCUnknownError(response.code);
|
|
1973
2043
|
}
|
|
1974
2044
|
else if (response.status === 'error') {
|
|
2045
|
+
/*
|
|
2046
|
+
* An entitlement refusal must not arrive as a generic failure: a customer
|
|
2047
|
+
* cannot then tell a module they have not bought from an outage. Keyed on
|
|
2048
|
+
* the app code, never on the HTTP status, so a role or membership problem
|
|
2049
|
+
* still maps to the generic error.
|
|
2050
|
+
*/
|
|
2051
|
+
if (response.code === 400325 /* Amity.ServerError.MODULE_NOT_ENTITLED */) {
|
|
2052
|
+
throw new AmityModuleNotEntitledError(response.message, extractNotEntitledModules(response.data));
|
|
2053
|
+
}
|
|
1975
2054
|
throw new ASCApiError(response.message, response.code, "error" /* Amity.ErrorLevel.ERROR */);
|
|
1976
2055
|
}
|
|
1977
2056
|
// unjust, but helps force uncast "T | undefined" to allow deconstruction without warnings
|
|
1978
2057
|
return undefined;
|
|
1979
2058
|
};
|
|
2059
|
+
/**
|
|
2060
|
+
* Builds a hex string of `bytes` length from the SDK's uuid helper (a v4 UUID is
|
|
2061
|
+
* 16 bytes / 32 hex chars once hyphens are removed) — avoids a new crypto dependency.
|
|
2062
|
+
*/
|
|
2063
|
+
const randomHex = (bytes) => {
|
|
2064
|
+
let hex = '';
|
|
2065
|
+
while (hex.length < bytes * 2)
|
|
2066
|
+
hex += uuid().replace(/-/g, '');
|
|
2067
|
+
return hex.slice(0, bytes * 2);
|
|
2068
|
+
};
|
|
2069
|
+
/**
|
|
2070
|
+
* W3C Trace Context `traceparent`: `version-<16-byte trace-id>-<8-byte span-id>-<flags>`.
|
|
2071
|
+
* The SDK is the trace originator, so it mints a fresh trace + span id per request; flags `01` = sampled.
|
|
2072
|
+
*
|
|
2073
|
+
* @category Transport
|
|
2074
|
+
* @hidden
|
|
2075
|
+
*/
|
|
2076
|
+
const generateTraceparent = () => `00-${randomHex(16)}-${randomHex(8)}-01`;
|
|
1980
2077
|
|
|
1981
2078
|
class NetworkActivitiesWatcher {
|
|
1982
2079
|
constructor() {
|
|
@@ -2101,6 +2198,10 @@ const createHttpTransport = (endpoint) => {
|
|
|
2101
2198
|
});
|
|
2102
2199
|
instance.defaults.withCredentials = false;
|
|
2103
2200
|
instance.interceptors.request.use(config => {
|
|
2201
|
+
// Request tracing — set on every outbound request (login included), never persisted.
|
|
2202
|
+
// Must run before the session-url early-return below so /api/v5/sessions carries them too.
|
|
2203
|
+
config.headers.set('x-request-id', uuid());
|
|
2204
|
+
config.headers.set('traceparent', generateTraceparent());
|
|
2104
2205
|
// do not check expiration for token creation url
|
|
2105
2206
|
if (config.url === '/api/v5/sessions') {
|
|
2106
2207
|
return config;
|
|
@@ -2144,20 +2245,28 @@ const createHttpTransport = (endpoint) => {
|
|
|
2144
2245
|
});
|
|
2145
2246
|
return response;
|
|
2146
2247
|
}, error => {
|
|
2147
|
-
var _a, _b, _c;
|
|
2248
|
+
var _a, _b, _c, _d;
|
|
2148
2249
|
const { response } = error;
|
|
2149
2250
|
// handle unauthorized request
|
|
2150
2251
|
if ((response === null || response === void 0 ? void 0 : response.data.code) === 400100 /* Amity.ServerError.UNAUTHORIZED */) {
|
|
2151
2252
|
fireEvent('tokenTerminated', "terminated" /* Amity.SessionStates.TERMINATED */);
|
|
2152
2253
|
}
|
|
2254
|
+
// handle globally banned user. The realtime `user.didGlobalBan` event can be missed
|
|
2255
|
+
// (e.g. MQTT dropped before delivery), so mirror the 400100 handling above and fire
|
|
2256
|
+
// the same virtual event the login subscriptions already listen to. That terminates
|
|
2257
|
+
// the session with `TokenTerminationReason.GLOBAL_BAN` and notifies `onClientBanned`
|
|
2258
|
+
// consumers, instead of leaving the session `established` with a revoked token.
|
|
2259
|
+
if (((_a = response === null || response === void 0 ? void 0 : response.data) === null || _a === void 0 ? void 0 : _a.code) === 400312 /* Amity.ServerError.GLOBAL_BAN */) {
|
|
2260
|
+
fireEvent('user.didGlobalBan', { users: [], files: [] });
|
|
2261
|
+
}
|
|
2153
2262
|
// handle visitor daily usage limit exceeded
|
|
2154
|
-
if (((
|
|
2263
|
+
if (((_b = response === null || response === void 0 ? void 0 : response.data) === null || _b === void 0 ? void 0 : _b.code) === 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */) {
|
|
2155
2264
|
throttledFireVisitorUsageLimit();
|
|
2156
2265
|
throw new ASCError('Visitor usage limit exceeded', 400323 /* Amity.ServerError.VISITOR_USAGE_LIMIT_EXCEEDED */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
2157
2266
|
}
|
|
2158
2267
|
// if it's an error with status in the response payload,
|
|
2159
2268
|
// then it's an expected error.
|
|
2160
|
-
if ((
|
|
2269
|
+
if ((_c = response === null || response === void 0 ? void 0 : response.data) === null || _c === void 0 ? void 0 : _c.status) {
|
|
2161
2270
|
unwrapPayload(response === null || response === void 0 ? void 0 : response.data);
|
|
2162
2271
|
}
|
|
2163
2272
|
// as on request cancellation error is returned
|
|
@@ -2165,7 +2274,7 @@ const createHttpTransport = (endpoint) => {
|
|
|
2165
2274
|
throw error;
|
|
2166
2275
|
}
|
|
2167
2276
|
// unexpected error.
|
|
2168
|
-
throw new Error((
|
|
2277
|
+
throw new Error((_d = response === null || response === void 0 ? void 0 : response.data) !== null && _d !== void 0 ? _d : error);
|
|
2169
2278
|
});
|
|
2170
2279
|
instance.defaults.paramsSerializer = {
|
|
2171
2280
|
encode: params => encodeURIComponent(params),
|
|
@@ -2363,8 +2472,6 @@ const getItem = async (key) => {
|
|
|
2363
2472
|
});
|
|
2364
2473
|
};
|
|
2365
2474
|
|
|
2366
|
-
const uuid = () => uuid__default["default"].v4().toString();
|
|
2367
|
-
|
|
2368
2475
|
// TODO: find a way to uniquely identify the device
|
|
2369
2476
|
let tabIndex = 0;
|
|
2370
2477
|
// This logic is running on browser only
|
|
@@ -2424,22 +2531,60 @@ const getMQTTClientId = async (userId) => {
|
|
|
2424
2531
|
};
|
|
2425
2532
|
/** @hidden */
|
|
2426
2533
|
const getDeviceModel = () => {
|
|
2427
|
-
var _a
|
|
2534
|
+
var _a;
|
|
2428
2535
|
if ((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node)
|
|
2429
2536
|
return safeProcess.versions.node;
|
|
2430
|
-
|
|
2431
|
-
|
|
2432
|
-
|
|
2537
|
+
return undefined;
|
|
2538
|
+
};
|
|
2539
|
+
const hasNavigator = () => typeof navigator !== 'undefined' && !!navigator;
|
|
2540
|
+
const getLocale = () => (hasNavigator() ? navigator.language : undefined);
|
|
2541
|
+
const getTimezone = () => {
|
|
2542
|
+
try {
|
|
2543
|
+
return Intl.DateTimeFormat().resolvedOptions().timeZone;
|
|
2544
|
+
}
|
|
2545
|
+
catch (_a) {
|
|
2546
|
+
return undefined;
|
|
2547
|
+
}
|
|
2548
|
+
};
|
|
2549
|
+
const getNetworkType = () => {
|
|
2550
|
+
var _a;
|
|
2551
|
+
if (!hasNavigator())
|
|
2552
|
+
return undefined;
|
|
2553
|
+
return (_a = navigator.connection) === null || _a === void 0 ? void 0 : _a.effectiveType;
|
|
2554
|
+
};
|
|
2555
|
+
const isNode = () => { var _a; return !!((_a = safeProcess.versions) === null || _a === void 0 ? void 0 : _a.node); };
|
|
2556
|
+
const parseUserAgent = () => {
|
|
2557
|
+
if (!hasNavigator() || !navigator.userAgent)
|
|
2558
|
+
return {};
|
|
2559
|
+
const { os, browser, device } = new uaParserJs.UAParser(navigator.userAgent).getResult();
|
|
2560
|
+
const result = {};
|
|
2561
|
+
if (os.name)
|
|
2562
|
+
result.osName = os.name;
|
|
2563
|
+
if (os.version)
|
|
2564
|
+
result.osVersion = os.version;
|
|
2565
|
+
if (browser.name)
|
|
2566
|
+
result.browserName = browser.name;
|
|
2567
|
+
if (browser.version)
|
|
2568
|
+
result.browserVersion = browser.version;
|
|
2569
|
+
if (device.type === 'tablet')
|
|
2570
|
+
result.deviceType = 'tablet';
|
|
2571
|
+
else if (device.type === 'mobile')
|
|
2572
|
+
result.deviceType = 'mobile';
|
|
2573
|
+
else
|
|
2574
|
+
result.deviceType = 'desktop';
|
|
2575
|
+
return result;
|
|
2433
2576
|
};
|
|
2434
2577
|
/** @hidden */
|
|
2435
2578
|
const getDeviceInfo = () => {
|
|
2436
|
-
|
|
2437
|
-
|
|
2438
|
-
|
|
2439
|
-
|
|
2440
|
-
|
|
2441
|
-
|
|
2442
|
-
|
|
2579
|
+
var _a;
|
|
2580
|
+
let client;
|
|
2581
|
+
try {
|
|
2582
|
+
client = getActiveClient();
|
|
2583
|
+
}
|
|
2584
|
+
catch (_b) {
|
|
2585
|
+
client = undefined;
|
|
2586
|
+
}
|
|
2587
|
+
return Object.assign({ kind: isNode() ? 'node' : 'web', model: getDeviceModel(), sdkVersion: VERSION, product: (_a = client === null || client === void 0 ? void 0 : client.product) !== null && _a !== void 0 ? _a : 'sdk', uikitVersion: client === null || client === void 0 ? void 0 : client.uikitVersion, appId: client === null || client === void 0 ? void 0 : client.appId, appVersion: client === null || client === void 0 ? void 0 : client.appVersion, locale: getLocale(), timezone: getTimezone(), networkType: getNetworkType() }, parseUserAgent());
|
|
2443
2588
|
};
|
|
2444
2589
|
|
|
2445
2590
|
/* eslint-disable no-console */
|
|
@@ -3851,6 +3996,95 @@ const prepareChannelPayload = async (rawPayload, options = { isMessagePreviewUpd
|
|
|
3851
3996
|
channelUsers });
|
|
3852
3997
|
};
|
|
3853
3998
|
|
|
3999
|
+
const channelCacheKey = (channel) => [
|
|
4000
|
+
'channel',
|
|
4001
|
+
'get',
|
|
4002
|
+
getResolver('channel')(channel),
|
|
4003
|
+
];
|
|
4004
|
+
/**
|
|
4005
|
+
* Find a cached channel by any of its ids (internal, public, or `channelId`).
|
|
4006
|
+
*
|
|
4007
|
+
* The channel cache is keyed by the channel internal id (see `idResolvers.channel`), but
|
|
4008
|
+
* realtime payloads reference channels by different ids: pin events carry the **public**
|
|
4009
|
+
* id, messages carry `channelId`. Try the cheap direct lookup first, then scan.
|
|
4010
|
+
*/
|
|
4011
|
+
const findCachedChannelByAnyId = (id) => {
|
|
4012
|
+
var _a, _b, _c;
|
|
4013
|
+
if (!id)
|
|
4014
|
+
return undefined;
|
|
4015
|
+
const direct = (_a = pullFromCache(['channel', 'get', id])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4016
|
+
if (direct)
|
|
4017
|
+
return direct;
|
|
4018
|
+
return (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => data.channelInternalId === id || data.channelPublicId === id || data.channelId === id)) === null || _c === void 0 ? void 0 : _c.data;
|
|
4019
|
+
};
|
|
4020
|
+
/**
|
|
4021
|
+
* Resolve the cached channel a `channel.messagePinned` / `channel.messageUnpinned` event
|
|
4022
|
+
* refers to. `data.channelId` is the channel public id; a pinned message body (present on
|
|
4023
|
+
* `messagePinned` only) also carries the internal id, which is the direct cache key.
|
|
4024
|
+
*/
|
|
4025
|
+
const findCachedChannelForPin = (payload) => {
|
|
4026
|
+
var _a, _b;
|
|
4027
|
+
return (_b = findCachedChannelByAnyId((_a = payload.pinnedMessage) === null || _a === void 0 ? void 0 : _a.channelId)) !== null && _b !== void 0 ? _b : findCachedChannelByAnyId(payload.channelId);
|
|
4028
|
+
};
|
|
4029
|
+
/**
|
|
4030
|
+
* Write a new pin snapshot (or `null` to clear) on a cached channel and ingest any
|
|
4031
|
+
* users delivered with it (the pin author and the message author), so the banner can
|
|
4032
|
+
* render a byline without a second fetch.
|
|
4033
|
+
*
|
|
4034
|
+
* Every `messagePinned` payload is a full snapshot — "this is the pin now" — so the last
|
|
4035
|
+
* one received always wins; there is no merging with the previous pin.
|
|
4036
|
+
*/
|
|
4037
|
+
const updatePinnedMessageCache = (channel, pinnedMessage, users) => {
|
|
4038
|
+
if (users && users.length > 0) {
|
|
4039
|
+
ingestInCache({ users: users.map(convertRawUserToInternalUser) });
|
|
4040
|
+
}
|
|
4041
|
+
const updated = Object.assign(Object.assign({}, channel), { pinnedMessage });
|
|
4042
|
+
pushToCache(channelCacheKey(channel), updated);
|
|
4043
|
+
return updated;
|
|
4044
|
+
};
|
|
4045
|
+
|
|
4046
|
+
/**
|
|
4047
|
+
* Applies a `channel.roleAdded` / `channel.roleRemoved` realtime payload to the cache.
|
|
4048
|
+
*
|
|
4049
|
+
* The event names every member the role request affected together with the
|
|
4050
|
+
* roles and channel-scoped permissions each of them is left holding. That is a
|
|
4051
|
+
* full state, not a delta, so it is written straight over the cached membership.
|
|
4052
|
+
*
|
|
4053
|
+
* Members the SDK has not fetched yet are skipped: the payload does not carry
|
|
4054
|
+
* enough to build a full {@link Amity.Membership} and the live collections only
|
|
4055
|
+
* emit rows that already exist in cache.
|
|
4056
|
+
*
|
|
4057
|
+
* @param payload the `data` of the realtime event
|
|
4058
|
+
* @returns the refreshed channel (when resolvable) and the updated cached memberships
|
|
4059
|
+
*
|
|
4060
|
+
* @hidden
|
|
4061
|
+
*/
|
|
4062
|
+
const applyChannelRolePayload = (payload) => {
|
|
4063
|
+
var _a, _b, _c;
|
|
4064
|
+
const { channelId, users = [], channels = [] } = payload;
|
|
4065
|
+
const rawChannel = (_a = channels.find(channel => channel.channelId === channelId)) !== null && _a !== void 0 ? _a : channels[0];
|
|
4066
|
+
let channel;
|
|
4067
|
+
if (rawChannel) {
|
|
4068
|
+
const channelKey = ['channel', 'get', getResolver('channel')(rawChannel)];
|
|
4069
|
+
// the role event does not touch message previews, keep whatever preview is cached
|
|
4070
|
+
const converted = convertFromRaw(rawChannel, { isMessagePreviewUpdated: false });
|
|
4071
|
+
upsertInCache(channelKey, converted);
|
|
4072
|
+
channel = (_c = (_b = pullFromCache(channelKey)) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : converted;
|
|
4073
|
+
}
|
|
4074
|
+
const members = [];
|
|
4075
|
+
users.forEach(({ userId, roles, permissions }) => {
|
|
4076
|
+
var _a, _b, _c;
|
|
4077
|
+
const memberKey = ['channelUsers', 'get', getResolver('channelUsers')({ channelId, userId })];
|
|
4078
|
+
const cached = (_a = pullFromCache(memberKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
4079
|
+
if (!cached)
|
|
4080
|
+
return;
|
|
4081
|
+
const updated = Object.assign(Object.assign({}, cached), { roles, permissions });
|
|
4082
|
+
pushToCache(memberKey, updated);
|
|
4083
|
+
members.push((_c = (_b = pullFromCache(memberKey)) === null || _b === void 0 ? void 0 : _b.data) !== null && _c !== void 0 ? _c : updated);
|
|
4084
|
+
});
|
|
4085
|
+
return { channel, members };
|
|
4086
|
+
};
|
|
4087
|
+
|
|
3854
4088
|
/**
|
|
3855
4089
|
* ```js
|
|
3856
4090
|
* import { getSubChannelMarkers } from '@amityco/ts-sdk'
|
|
@@ -4036,32 +4270,6 @@ const channelMemberLinkedObject = (channelMember) => {
|
|
|
4036
4270
|
} });
|
|
4037
4271
|
};
|
|
4038
4272
|
|
|
4039
|
-
/**
|
|
4040
|
-
*
|
|
4041
|
-
* get current user's membership data
|
|
4042
|
-
*
|
|
4043
|
-
* @returns the {@link Amity.Membership<'channel'>} objects
|
|
4044
|
-
*
|
|
4045
|
-
* @category Channel API
|
|
4046
|
-
* @async
|
|
4047
|
-
*/
|
|
4048
|
-
const getMyMembership$1 = (channelId) => {
|
|
4049
|
-
const client = getActiveClient();
|
|
4050
|
-
client.log('channel/getMyMembership.locally');
|
|
4051
|
-
const cacheChannelUser = pullFromCache([
|
|
4052
|
-
'channelUsers',
|
|
4053
|
-
'get',
|
|
4054
|
-
`${channelId}#${client.userId}`,
|
|
4055
|
-
]);
|
|
4056
|
-
if (!cacheChannelUser) {
|
|
4057
|
-
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
4058
|
-
}
|
|
4059
|
-
return {
|
|
4060
|
-
data: cacheChannelUser.data,
|
|
4061
|
-
cachedAt: cacheChannelUser.cachedAt,
|
|
4062
|
-
};
|
|
4063
|
-
};
|
|
4064
|
-
|
|
4065
4273
|
/**
|
|
4066
4274
|
* ```js
|
|
4067
4275
|
* import { isEqual } from '~/utils/isEqual'
|
|
@@ -4132,55 +4340,81 @@ function isEqual(x, y) {
|
|
|
4132
4340
|
}));
|
|
4133
4341
|
}
|
|
4134
4342
|
|
|
4135
|
-
|
|
4343
|
+
/**
|
|
4344
|
+
*
|
|
4345
|
+
* get current user's membership data
|
|
4346
|
+
*
|
|
4347
|
+
* @returns the {@link Amity.Membership<'channel'>} objects
|
|
4348
|
+
*
|
|
4349
|
+
* @category Channel API
|
|
4350
|
+
* @async
|
|
4351
|
+
*/
|
|
4352
|
+
const getMyMembership$1 = (channelId) => {
|
|
4353
|
+
const client = getActiveClient();
|
|
4354
|
+
client.log('channel/getMyMembership.locally');
|
|
4355
|
+
const cacheChannelUser = pullFromCache([
|
|
4356
|
+
'channelUsers',
|
|
4357
|
+
'get',
|
|
4358
|
+
`${channelId}#${client.userId}`,
|
|
4359
|
+
]);
|
|
4360
|
+
if (!cacheChannelUser) {
|
|
4361
|
+
throw new ASCApiError('Item not found!', 400400 /* Amity.ServerError.ITEM_NOT_FOUND */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
4362
|
+
}
|
|
4363
|
+
return {
|
|
4364
|
+
data: cacheChannelUser.data,
|
|
4365
|
+
cachedAt: cacheChannelUser.cachedAt,
|
|
4366
|
+
};
|
|
4367
|
+
};
|
|
4368
|
+
|
|
4369
|
+
const callbacks$e = [];
|
|
4136
4370
|
let mainDisposer$b = null;
|
|
4137
|
-
const dispose$
|
|
4138
|
-
const index = callbacks$
|
|
4371
|
+
const dispose$e = (cb) => {
|
|
4372
|
+
const index = callbacks$e.indexOf(cb);
|
|
4139
4373
|
if (index > -1) {
|
|
4140
|
-
callbacks$
|
|
4374
|
+
callbacks$e.splice(index, 1);
|
|
4141
4375
|
}
|
|
4142
|
-
if (callbacks$
|
|
4376
|
+
if (callbacks$e.length === 0) {
|
|
4143
4377
|
mainDisposer$b === null || mainDisposer$b === void 0 ? void 0 : mainDisposer$b();
|
|
4144
4378
|
}
|
|
4145
4379
|
};
|
|
4146
4380
|
const onChannelCreated = (callback) => {
|
|
4147
|
-
if (callbacks$
|
|
4381
|
+
if (callbacks$e.length === 0) {
|
|
4148
4382
|
const client = getActiveClient();
|
|
4149
4383
|
const filter = async (payload) => {
|
|
4150
4384
|
const data = await prepareChannelPayload(payload);
|
|
4151
4385
|
ingestInCache(data);
|
|
4152
|
-
callbacks$
|
|
4386
|
+
callbacks$e.forEach(cb => cb(data.channels[0]));
|
|
4153
4387
|
};
|
|
4154
4388
|
mainDisposer$b = createEventSubscriber(client, 'onChannelCreated', 'channel.created', filter);
|
|
4155
4389
|
}
|
|
4156
|
-
callbacks$
|
|
4157
|
-
return () => dispose$
|
|
4390
|
+
callbacks$e.push(callback);
|
|
4391
|
+
return () => dispose$e(callback);
|
|
4158
4392
|
};
|
|
4159
4393
|
|
|
4160
|
-
const callbacks$
|
|
4161
|
-
const mainDisposers = [];
|
|
4162
|
-
const dispose$
|
|
4163
|
-
const index = callbacks$
|
|
4394
|
+
const callbacks$d = [];
|
|
4395
|
+
const mainDisposers$2 = [];
|
|
4396
|
+
const dispose$d = (cb) => {
|
|
4397
|
+
const index = callbacks$d.indexOf(cb);
|
|
4164
4398
|
if (index > -1) {
|
|
4165
|
-
callbacks$
|
|
4399
|
+
callbacks$d.splice(index, 1);
|
|
4166
4400
|
}
|
|
4167
|
-
if (callbacks$
|
|
4168
|
-
mainDisposers.forEach(fn => fn());
|
|
4401
|
+
if (callbacks$d.length === 0) {
|
|
4402
|
+
mainDisposers$2.forEach(fn => fn());
|
|
4169
4403
|
}
|
|
4170
4404
|
};
|
|
4171
4405
|
const onChannelUpdated = (callback) => {
|
|
4172
4406
|
const client = getActiveClient();
|
|
4173
|
-
if (callbacks$
|
|
4407
|
+
if (callbacks$d.length === 0) {
|
|
4174
4408
|
const filter = async (payload) => {
|
|
4175
4409
|
const data = await prepareChannelPayload(payload);
|
|
4176
4410
|
ingestInCache(data);
|
|
4177
|
-
callbacks$
|
|
4411
|
+
callbacks$d.forEach(cb => cb(data.channels[0]));
|
|
4178
4412
|
};
|
|
4179
|
-
mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter));
|
|
4180
|
-
mainDisposers.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$
|
|
4413
|
+
mainDisposers$2.push(createEventSubscriber(client, 'onChannelUpdated', 'channel.updated', filter));
|
|
4414
|
+
mainDisposers$2.push(createEventSubscriber(client, 'onChannelUpdated', 'local.channel.updated', payload => callbacks$d.forEach(cb => cb(payload.channels[0]))));
|
|
4181
4415
|
}
|
|
4182
|
-
callbacks$
|
|
4183
|
-
return () => dispose$
|
|
4416
|
+
callbacks$d.push(callback);
|
|
4417
|
+
return () => dispose$d(callback);
|
|
4184
4418
|
};
|
|
4185
4419
|
|
|
4186
4420
|
const addFlagIsDeletedSubChannelUnreadByChannelId = (channelId) => {
|
|
@@ -4203,19 +4437,19 @@ const deleteChannelUnreadByChannelId = (channelId) => {
|
|
|
4203
4437
|
}
|
|
4204
4438
|
};
|
|
4205
4439
|
|
|
4206
|
-
const callbacks$
|
|
4440
|
+
const callbacks$c = [];
|
|
4207
4441
|
let mainDisposer$a = null;
|
|
4208
|
-
const dispose$
|
|
4209
|
-
const index = callbacks$
|
|
4442
|
+
const dispose$c = (cb) => {
|
|
4443
|
+
const index = callbacks$c.indexOf(cb);
|
|
4210
4444
|
if (index > -1) {
|
|
4211
|
-
callbacks$
|
|
4445
|
+
callbacks$c.splice(index, 1);
|
|
4212
4446
|
}
|
|
4213
|
-
if (callbacks$
|
|
4447
|
+
if (callbacks$c.length === 0) {
|
|
4214
4448
|
mainDisposer$a === null || mainDisposer$a === void 0 ? void 0 : mainDisposer$a();
|
|
4215
4449
|
}
|
|
4216
4450
|
};
|
|
4217
4451
|
const onChannelDeleted = (callback) => {
|
|
4218
|
-
if (callbacks$
|
|
4452
|
+
if (callbacks$c.length === 0) {
|
|
4219
4453
|
const client = getActiveClient();
|
|
4220
4454
|
const filter = async (payload) => {
|
|
4221
4455
|
const data = await prepareChannelPayload(payload);
|
|
@@ -4235,53 +4469,53 @@ const onChannelDeleted = (callback) => {
|
|
|
4235
4469
|
}
|
|
4236
4470
|
});
|
|
4237
4471
|
ingestInCache(data);
|
|
4238
|
-
callbacks$
|
|
4472
|
+
callbacks$c.forEach(cb => cb(data.channels[0]));
|
|
4239
4473
|
};
|
|
4240
4474
|
mainDisposer$a = createEventSubscriber(client, 'onChannelDeleted', 'channel.deleted', filter);
|
|
4241
4475
|
}
|
|
4242
|
-
callbacks$
|
|
4243
|
-
return () => dispose$
|
|
4476
|
+
callbacks$c.push(callback);
|
|
4477
|
+
return () => dispose$c(callback);
|
|
4244
4478
|
};
|
|
4245
4479
|
|
|
4246
|
-
const callbacks$
|
|
4480
|
+
const callbacks$b = [];
|
|
4247
4481
|
let mainDisposer$9 = null;
|
|
4248
|
-
const dispose$
|
|
4249
|
-
const index = callbacks$
|
|
4482
|
+
const dispose$b = (cb) => {
|
|
4483
|
+
const index = callbacks$b.indexOf(cb);
|
|
4250
4484
|
if (index > -1) {
|
|
4251
|
-
callbacks$
|
|
4485
|
+
callbacks$b.splice(index, 1);
|
|
4252
4486
|
}
|
|
4253
|
-
if (callbacks$
|
|
4487
|
+
if (callbacks$b.length === 0) {
|
|
4254
4488
|
mainDisposer$9 === null || mainDisposer$9 === void 0 ? void 0 : mainDisposer$9();
|
|
4255
4489
|
}
|
|
4256
4490
|
};
|
|
4257
4491
|
const onChannelJoined = (callback) => {
|
|
4258
|
-
if (callbacks$
|
|
4492
|
+
if (callbacks$b.length === 0) {
|
|
4259
4493
|
const client = getActiveClient();
|
|
4260
4494
|
const filter = async (payload) => {
|
|
4261
4495
|
const preparedPayload = await prepareChannelPayload(payload);
|
|
4262
4496
|
const { channels, channelUsers } = preparedPayload;
|
|
4263
4497
|
ingestInCache(preparedPayload);
|
|
4264
|
-
callbacks$
|
|
4498
|
+
callbacks$b.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4265
4499
|
};
|
|
4266
4500
|
mainDisposer$9 = createEventSubscriber(client, 'onChannelJoined', 'channel.joined', filter);
|
|
4267
4501
|
}
|
|
4268
|
-
callbacks$
|
|
4269
|
-
return () => dispose$
|
|
4502
|
+
callbacks$b.push(callback);
|
|
4503
|
+
return () => dispose$b(callback);
|
|
4270
4504
|
};
|
|
4271
4505
|
|
|
4272
|
-
const callbacks$
|
|
4506
|
+
const callbacks$a = [];
|
|
4273
4507
|
let mainDisposer$8 = null;
|
|
4274
|
-
const dispose$
|
|
4275
|
-
const index = callbacks$
|
|
4508
|
+
const dispose$a = (cb) => {
|
|
4509
|
+
const index = callbacks$a.indexOf(cb);
|
|
4276
4510
|
if (index > -1) {
|
|
4277
|
-
callbacks$
|
|
4511
|
+
callbacks$a.splice(index, 1);
|
|
4278
4512
|
}
|
|
4279
|
-
if (callbacks$
|
|
4513
|
+
if (callbacks$a.length === 0) {
|
|
4280
4514
|
mainDisposer$8 === null || mainDisposer$8 === void 0 ? void 0 : mainDisposer$8();
|
|
4281
4515
|
}
|
|
4282
4516
|
};
|
|
4283
4517
|
const onChannelLeft = (callback) => {
|
|
4284
|
-
if (callbacks$
|
|
4518
|
+
if (callbacks$a.length === 0) {
|
|
4285
4519
|
const client = getActiveClient();
|
|
4286
4520
|
const filter = async (payload) => {
|
|
4287
4521
|
const { userId } = getActiveClient();
|
|
@@ -4305,27 +4539,27 @@ const onChannelLeft = (callback) => {
|
|
|
4305
4539
|
}
|
|
4306
4540
|
const { channels, channelUsers } = preparedPayload;
|
|
4307
4541
|
ingestInCache(preparedPayload);
|
|
4308
|
-
callbacks$
|
|
4542
|
+
callbacks$a.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4309
4543
|
};
|
|
4310
4544
|
mainDisposer$8 = createEventSubscriber(client, 'onChannelLeft', 'channel.left', filter);
|
|
4311
4545
|
}
|
|
4312
|
-
callbacks$
|
|
4313
|
-
return () => dispose$
|
|
4546
|
+
callbacks$a.push(callback);
|
|
4547
|
+
return () => dispose$a(callback);
|
|
4314
4548
|
};
|
|
4315
4549
|
|
|
4316
|
-
const callbacks$
|
|
4550
|
+
const callbacks$9 = [];
|
|
4317
4551
|
let mainDisposer$7 = null;
|
|
4318
|
-
const dispose$
|
|
4319
|
-
const index = callbacks$
|
|
4552
|
+
const dispose$9 = (cb) => {
|
|
4553
|
+
const index = callbacks$9.indexOf(cb);
|
|
4320
4554
|
if (index > -1) {
|
|
4321
|
-
callbacks$
|
|
4555
|
+
callbacks$9.splice(index, 1);
|
|
4322
4556
|
}
|
|
4323
|
-
if (callbacks$
|
|
4557
|
+
if (callbacks$9.length === 0) {
|
|
4324
4558
|
mainDisposer$7 === null || mainDisposer$7 === void 0 ? void 0 : mainDisposer$7();
|
|
4325
4559
|
}
|
|
4326
4560
|
};
|
|
4327
4561
|
const onChannelSetMuted = (callback) => {
|
|
4328
|
-
if (callbacks$
|
|
4562
|
+
if (callbacks$9.length === 0) {
|
|
4329
4563
|
const client = getActiveClient();
|
|
4330
4564
|
const filter = async (payload) => {
|
|
4331
4565
|
var _a;
|
|
@@ -4340,24 +4574,124 @@ const onChannelSetMuted = (callback) => {
|
|
|
4340
4574
|
payload.channelId,
|
|
4341
4575
|
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
4342
4576
|
if (channel) {
|
|
4343
|
-
callbacks$
|
|
4577
|
+
callbacks$9.forEach(cb => cb(channel));
|
|
4344
4578
|
}
|
|
4345
4579
|
};
|
|
4346
4580
|
mainDisposer$7 = createEventSubscriber(client, 'onChannelMute', 'channel.setMuted', filter);
|
|
4347
4581
|
}
|
|
4582
|
+
callbacks$9.push(callback);
|
|
4583
|
+
return () => dispose$9(callback);
|
|
4584
|
+
};
|
|
4585
|
+
|
|
4586
|
+
const callbacks$8 = [];
|
|
4587
|
+
let mainDisposer$6 = null;
|
|
4588
|
+
const dispose$8 = (cb) => {
|
|
4589
|
+
const index = callbacks$8.indexOf(cb);
|
|
4590
|
+
if (index > -1) {
|
|
4591
|
+
callbacks$8.splice(index, 1);
|
|
4592
|
+
}
|
|
4593
|
+
if (callbacks$8.length === 0) {
|
|
4594
|
+
mainDisposer$6 === null || mainDisposer$6 === void 0 ? void 0 : mainDisposer$6();
|
|
4595
|
+
}
|
|
4596
|
+
};
|
|
4597
|
+
/* begin_public_function
|
|
4598
|
+
id: channel.event.message_pinned
|
|
4599
|
+
*/
|
|
4600
|
+
/**
|
|
4601
|
+
* ```js
|
|
4602
|
+
* import { onChannelMessagePinned } from '@amityco/ts-sdk'
|
|
4603
|
+
* const dispose = onChannelMessagePinned(channel => {
|
|
4604
|
+
* // channel.pinnedMessage is the new pin
|
|
4605
|
+
* })
|
|
4606
|
+
* ```
|
|
4607
|
+
*
|
|
4608
|
+
* Fired when a message is pinned in a channel (the `channel.messagePinned` realtime
|
|
4609
|
+
* event). Pinning a different message while one is already pinned emits a single
|
|
4610
|
+
* `messagePinned` carrying the replacement — treat every payload as a full snapshot.
|
|
4611
|
+
*
|
|
4612
|
+
* The updated channel is written to cache before the callback runs, so
|
|
4613
|
+
* `ChannelRepository.getChannel` observers see `channel.pinnedMessage` change.
|
|
4614
|
+
*
|
|
4615
|
+
* @param callback The function to call when the event was fired
|
|
4616
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4617
|
+
*
|
|
4618
|
+
* @category Channel Events
|
|
4619
|
+
*/
|
|
4620
|
+
const onChannelMessagePinned = (callback) => {
|
|
4621
|
+
if (callbacks$8.length === 0) {
|
|
4622
|
+
const client = getActiveClient();
|
|
4623
|
+
const filter = (payload) => {
|
|
4624
|
+
var _a;
|
|
4625
|
+
const channel = findCachedChannelForPin(payload);
|
|
4626
|
+
if (!channel)
|
|
4627
|
+
return;
|
|
4628
|
+
const updated = updatePinnedMessageCache(channel, (_a = payload.pinnedMessage) !== null && _a !== void 0 ? _a : null, payload.users);
|
|
4629
|
+
callbacks$8.forEach(cb => cb(updated));
|
|
4630
|
+
};
|
|
4631
|
+
mainDisposer$6 = createEventSubscriber(client, 'onChannelMessagePinned', 'channel.messagePinned', filter);
|
|
4632
|
+
}
|
|
4633
|
+
callbacks$8.push(callback);
|
|
4634
|
+
return () => dispose$8(callback);
|
|
4635
|
+
};
|
|
4636
|
+
/* end_public_function */
|
|
4637
|
+
|
|
4638
|
+
const callbacks$7 = [];
|
|
4639
|
+
let mainDisposer$5 = null;
|
|
4640
|
+
const dispose$7 = (cb) => {
|
|
4641
|
+
const index = callbacks$7.indexOf(cb);
|
|
4642
|
+
if (index > -1) {
|
|
4643
|
+
callbacks$7.splice(index, 1);
|
|
4644
|
+
}
|
|
4645
|
+
if (callbacks$7.length === 0) {
|
|
4646
|
+
mainDisposer$5 === null || mainDisposer$5 === void 0 ? void 0 : mainDisposer$5();
|
|
4647
|
+
}
|
|
4648
|
+
};
|
|
4649
|
+
/* begin_public_function
|
|
4650
|
+
id: channel.event.message_unpinned
|
|
4651
|
+
*/
|
|
4652
|
+
/**
|
|
4653
|
+
* ```js
|
|
4654
|
+
* import { onChannelMessageUnpinned } from '@amityco/ts-sdk'
|
|
4655
|
+
* const dispose = onChannelMessageUnpinned(channel => {
|
|
4656
|
+
* // channel.pinnedMessage is now null
|
|
4657
|
+
* })
|
|
4658
|
+
* ```
|
|
4659
|
+
*
|
|
4660
|
+
* Fired when a channel's pinned message is removed (the `channel.messageUnpinned`
|
|
4661
|
+
* realtime event) — either by an explicit unpin or automatically by the server when the
|
|
4662
|
+
* pinned message is deleted or its author is banned from the channel / globally.
|
|
4663
|
+
*
|
|
4664
|
+
* @param callback The function to call when the event was fired
|
|
4665
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4666
|
+
*
|
|
4667
|
+
* @category Channel Events
|
|
4668
|
+
*/
|
|
4669
|
+
const onChannelMessageUnpinned = (callback) => {
|
|
4670
|
+
if (callbacks$7.length === 0) {
|
|
4671
|
+
const client = getActiveClient();
|
|
4672
|
+
const filter = (payload) => {
|
|
4673
|
+
const channel = findCachedChannelForPin(payload);
|
|
4674
|
+
if (!channel)
|
|
4675
|
+
return;
|
|
4676
|
+
const updated = updatePinnedMessageCache(channel, null);
|
|
4677
|
+
callbacks$7.forEach(cb => cb(updated));
|
|
4678
|
+
};
|
|
4679
|
+
mainDisposer$5 = createEventSubscriber(client, 'onChannelMessageUnpinned', 'channel.messageUnpinned', filter);
|
|
4680
|
+
}
|
|
4348
4681
|
callbacks$7.push(callback);
|
|
4349
4682
|
return () => dispose$7(callback);
|
|
4350
4683
|
};
|
|
4684
|
+
/* end_public_function */
|
|
4351
4685
|
|
|
4352
4686
|
const callbacks$6 = [];
|
|
4353
|
-
let mainDisposer$
|
|
4687
|
+
let mainDisposer$4 = null;
|
|
4354
4688
|
const dispose$6 = (cb) => {
|
|
4355
4689
|
const index = callbacks$6.indexOf(cb);
|
|
4356
4690
|
if (index > -1) {
|
|
4357
4691
|
callbacks$6.splice(index, 1);
|
|
4358
4692
|
}
|
|
4359
4693
|
if (callbacks$6.length === 0) {
|
|
4360
|
-
mainDisposer$
|
|
4694
|
+
mainDisposer$4 === null || mainDisposer$4 === void 0 ? void 0 : mainDisposer$4();
|
|
4361
4695
|
}
|
|
4362
4696
|
};
|
|
4363
4697
|
const onChannelMemberAdded = (callback) => {
|
|
@@ -4369,21 +4703,21 @@ const onChannelMemberAdded = (callback) => {
|
|
|
4369
4703
|
ingestInCache(preparedPayload);
|
|
4370
4704
|
callbacks$6.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'member')));
|
|
4371
4705
|
};
|
|
4372
|
-
mainDisposer$
|
|
4706
|
+
mainDisposer$4 = createEventSubscriber(client, 'onChannelMemberAdded', 'channel.membersAdded', filter);
|
|
4373
4707
|
}
|
|
4374
4708
|
callbacks$6.push(callback);
|
|
4375
4709
|
return () => dispose$6(callback);
|
|
4376
4710
|
};
|
|
4377
4711
|
|
|
4378
4712
|
const callbacks$5 = [];
|
|
4379
|
-
let mainDisposer$
|
|
4713
|
+
let mainDisposer$3 = null;
|
|
4380
4714
|
const dispose$5 = (cb) => {
|
|
4381
4715
|
const index = callbacks$5.indexOf(cb);
|
|
4382
4716
|
if (index > -1) {
|
|
4383
4717
|
callbacks$5.splice(index, 1);
|
|
4384
4718
|
}
|
|
4385
4719
|
if (callbacks$5.length === 0) {
|
|
4386
|
-
mainDisposer$
|
|
4720
|
+
mainDisposer$3 === null || mainDisposer$3 === void 0 ? void 0 : mainDisposer$3();
|
|
4387
4721
|
}
|
|
4388
4722
|
};
|
|
4389
4723
|
const onChannelMemberRemoved = (callback) => {
|
|
@@ -4395,21 +4729,21 @@ const onChannelMemberRemoved = (callback) => {
|
|
|
4395
4729
|
ingestInCache(preparedPayload);
|
|
4396
4730
|
callbacks$5.forEach(cb => cb(channels[0], channelUsers[0]));
|
|
4397
4731
|
};
|
|
4398
|
-
mainDisposer$
|
|
4732
|
+
mainDisposer$3 = createEventSubscriber(client, 'onChannelMemberRemoved', 'channel.membersRemoved', filter);
|
|
4399
4733
|
}
|
|
4400
4734
|
callbacks$5.push(callback);
|
|
4401
4735
|
return () => dispose$5(callback);
|
|
4402
4736
|
};
|
|
4403
4737
|
|
|
4404
4738
|
const callbacks$4 = [];
|
|
4405
|
-
let mainDisposer$
|
|
4739
|
+
let mainDisposer$2 = null;
|
|
4406
4740
|
const dispose$4 = (cb) => {
|
|
4407
4741
|
const index = callbacks$4.indexOf(cb);
|
|
4408
4742
|
if (index > -1) {
|
|
4409
4743
|
callbacks$4.splice(index, 1);
|
|
4410
4744
|
}
|
|
4411
4745
|
if (callbacks$4.length === 0) {
|
|
4412
|
-
mainDisposer$
|
|
4746
|
+
mainDisposer$2 === null || mainDisposer$2 === void 0 ? void 0 : mainDisposer$2();
|
|
4413
4747
|
}
|
|
4414
4748
|
};
|
|
4415
4749
|
const onChannelMemberBanned = (callback) => {
|
|
@@ -4429,20 +4763,20 @@ const onChannelMemberBanned = (callback) => {
|
|
|
4429
4763
|
ingestInCache(preparedPayload);
|
|
4430
4764
|
callbacks$4.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'banned')));
|
|
4431
4765
|
};
|
|
4432
|
-
mainDisposer$
|
|
4766
|
+
mainDisposer$2 = createEventSubscriber(client, 'onChannelMemberBanned', 'channel.banned', filter);
|
|
4433
4767
|
callbacks$4.push(callback);
|
|
4434
4768
|
return () => dispose$4(callback);
|
|
4435
4769
|
};
|
|
4436
4770
|
|
|
4437
4771
|
const callbacks$3 = [];
|
|
4438
|
-
let mainDisposer$
|
|
4772
|
+
let mainDisposer$1 = null;
|
|
4439
4773
|
const dispose$3 = (cb) => {
|
|
4440
4774
|
const index = callbacks$3.indexOf(cb);
|
|
4441
4775
|
if (index > -1) {
|
|
4442
4776
|
callbacks$3.splice(index, 1);
|
|
4443
4777
|
}
|
|
4444
4778
|
if (callbacks$3.length === 0) {
|
|
4445
|
-
mainDisposer$
|
|
4779
|
+
mainDisposer$1 === null || mainDisposer$1 === void 0 ? void 0 : mainDisposer$1();
|
|
4446
4780
|
}
|
|
4447
4781
|
};
|
|
4448
4782
|
const onChannelMemberUnbanned = (callback) => {
|
|
@@ -4454,59 +4788,127 @@ const onChannelMemberUnbanned = (callback) => {
|
|
|
4454
4788
|
ingestInCache(preparedPayload);
|
|
4455
4789
|
callbacks$3.forEach(cb => cb(channels[0], channelUsers.find(cu => cu.membership === 'none')));
|
|
4456
4790
|
};
|
|
4457
|
-
mainDisposer$
|
|
4791
|
+
mainDisposer$1 = createEventSubscriber(client, 'onChannelMemberUnbanned', 'channel.unbanned', filter);
|
|
4458
4792
|
}
|
|
4459
4793
|
callbacks$3.push(callback);
|
|
4460
4794
|
return () => dispose$3(callback);
|
|
4461
4795
|
};
|
|
4462
4796
|
|
|
4463
4797
|
const callbacks$2 = [];
|
|
4464
|
-
|
|
4798
|
+
const mainDisposers$1 = [];
|
|
4465
4799
|
const dispose$2 = (cb) => {
|
|
4466
4800
|
const index = callbacks$2.indexOf(cb);
|
|
4467
4801
|
if (index > -1) {
|
|
4468
4802
|
callbacks$2.splice(index, 1);
|
|
4469
4803
|
}
|
|
4470
4804
|
if (callbacks$2.length === 0) {
|
|
4471
|
-
|
|
4805
|
+
mainDisposers$1.forEach(fn => fn());
|
|
4806
|
+
mainDisposers$1.length = 0;
|
|
4472
4807
|
}
|
|
4473
4808
|
};
|
|
4809
|
+
/* begin_public_function
|
|
4810
|
+
id: channel.event.member_role_added
|
|
4811
|
+
*/
|
|
4812
|
+
/**
|
|
4813
|
+
* ```js
|
|
4814
|
+
* import { onChannelMemberRoleAdded } from '@amityco/ts-sdk'
|
|
4815
|
+
* const dispose = onChannelMemberRoleAdded((channel, member) => {
|
|
4816
|
+
* // member.roles and member.permissions are the member's resulting state
|
|
4817
|
+
* })
|
|
4818
|
+
* ```
|
|
4819
|
+
*
|
|
4820
|
+
* Fired when a role is added to a member of a {@link Amity.Channel}, either by the
|
|
4821
|
+
* local `ChannelRepository.Moderation.addRole` call or by the `channel.roleAdded` realtime
|
|
4822
|
+
* event coming from any client or the admin console.
|
|
4823
|
+
*
|
|
4824
|
+
* The realtime event reaches every subscriber of the channel topic (see `getChannelTopic`),
|
|
4825
|
+
* not only the actor or the affected members. It carries the affected members' resulting
|
|
4826
|
+
* channel roles and channel-scoped permissions, which are written to cache before the
|
|
4827
|
+
* callback runs. The callback is invoked once per affected member already held in cache.
|
|
4828
|
+
*
|
|
4829
|
+
* @param callback The function to call when the event was fired
|
|
4830
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4831
|
+
*
|
|
4832
|
+
* @category Channel Events
|
|
4833
|
+
*/
|
|
4474
4834
|
const onChannelMemberRoleAdded = (callback) => {
|
|
4475
4835
|
if (callbacks$2.length === 0) {
|
|
4476
4836
|
const client = getActiveClient();
|
|
4477
|
-
const
|
|
4837
|
+
const onLocal = async (payload) => {
|
|
4478
4838
|
const { channels, channelUsers } = payload;
|
|
4479
4839
|
callbacks$2.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
4480
4840
|
};
|
|
4481
|
-
|
|
4841
|
+
const onRealtime = (payload) => {
|
|
4842
|
+
const { channel, members } = applyChannelRolePayload(payload);
|
|
4843
|
+
if (!channel)
|
|
4844
|
+
return;
|
|
4845
|
+
members.forEach(member => callbacks$2.forEach(cb => cb(channel, member)));
|
|
4846
|
+
};
|
|
4847
|
+
mainDisposers$1.push(createEventSubscriber(client, 'onChannelMemberRoleAdded', 'local.channel-moderator.role-added', onLocal));
|
|
4848
|
+
mainDisposers$1.push(createEventSubscriber(client, 'onChannelMemberRoleAdded', 'channel.roleAdded', onRealtime));
|
|
4482
4849
|
}
|
|
4483
4850
|
callbacks$2.push(callback);
|
|
4484
4851
|
return () => dispose$2(callback);
|
|
4485
4852
|
};
|
|
4853
|
+
/* end_public_function */
|
|
4486
4854
|
|
|
4487
4855
|
const callbacks$1 = [];
|
|
4488
|
-
|
|
4856
|
+
const mainDisposers = [];
|
|
4489
4857
|
const dispose$1 = (cb) => {
|
|
4490
4858
|
const index = callbacks$1.indexOf(cb);
|
|
4491
4859
|
if (index > -1) {
|
|
4492
4860
|
callbacks$1.splice(index, 1);
|
|
4493
4861
|
}
|
|
4494
4862
|
if (callbacks$1.length === 0) {
|
|
4495
|
-
|
|
4863
|
+
mainDisposers.forEach(fn => fn());
|
|
4864
|
+
mainDisposers.length = 0;
|
|
4496
4865
|
}
|
|
4497
4866
|
};
|
|
4867
|
+
/* begin_public_function
|
|
4868
|
+
id: channel.event.member_role_removed
|
|
4869
|
+
*/
|
|
4870
|
+
/**
|
|
4871
|
+
* ```js
|
|
4872
|
+
* import { onChannelMemberRoleRemoved } from '@amityco/ts-sdk'
|
|
4873
|
+
* const dispose = onChannelMemberRoleRemoved((channel, member) => {
|
|
4874
|
+
* // member.roles and member.permissions are the member's resulting state
|
|
4875
|
+
* })
|
|
4876
|
+
* ```
|
|
4877
|
+
*
|
|
4878
|
+
* Fired when a role is removed from a member of a {@link Amity.Channel}, either by the
|
|
4879
|
+
* local `ChannelRepository.Moderation.removeRole` call or by the `channel.roleRemoved` realtime
|
|
4880
|
+
* event coming from any client or the admin console.
|
|
4881
|
+
*
|
|
4882
|
+
* The realtime event reaches every subscriber of the channel topic (see `getChannelTopic`),
|
|
4883
|
+
* not only the actor or the affected members. It carries the affected members' resulting
|
|
4884
|
+
* channel roles and channel-scoped permissions, which are written to cache before the
|
|
4885
|
+
* callback runs. The callback is invoked once per affected member already held in cache.
|
|
4886
|
+
*
|
|
4887
|
+
* @param callback The function to call when the event was fired
|
|
4888
|
+
* @returns an {@link Amity.Unsubscriber} function to run when willing to stop listening
|
|
4889
|
+
*
|
|
4890
|
+
* @category Channel Events
|
|
4891
|
+
*/
|
|
4498
4892
|
const onChannelMemberRoleRemoved = (callback) => {
|
|
4499
4893
|
if (callbacks$1.length === 0) {
|
|
4500
4894
|
const client = getActiveClient();
|
|
4501
|
-
const
|
|
4895
|
+
const onLocal = async (payload) => {
|
|
4502
4896
|
const { channels, channelUsers } = payload;
|
|
4503
4897
|
callbacks$1.forEach(cb => cb(channels[0], channelUsers.find(channelUser => channelUser.membership === 'member')));
|
|
4504
4898
|
};
|
|
4505
|
-
|
|
4899
|
+
const onRealtime = (payload) => {
|
|
4900
|
+
const { channel, members } = applyChannelRolePayload(payload);
|
|
4901
|
+
if (!channel)
|
|
4902
|
+
return;
|
|
4903
|
+
members.forEach(member => callbacks$1.forEach(cb => cb(channel, member)));
|
|
4904
|
+
};
|
|
4905
|
+
mainDisposers.push(createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'local.channel-moderator.role-removed', onLocal));
|
|
4906
|
+
mainDisposers.push(createEventSubscriber(client, 'onChannelMemberRoleRemoved', 'channel.roleRemoved', onRealtime));
|
|
4506
4907
|
}
|
|
4507
4908
|
callbacks$1.push(callback);
|
|
4508
4909
|
return () => dispose$1(callback);
|
|
4509
4910
|
};
|
|
4911
|
+
/* end_public_function */
|
|
4510
4912
|
|
|
4511
4913
|
/**
|
|
4512
4914
|
* Fired when a {@link Amity.Channel} has been archived by the active user.
|
|
@@ -4630,6 +5032,8 @@ const getMyMembership = (channelId, callback) => {
|
|
|
4630
5032
|
disposers.push(onChannelMemberBanned(realtimeRouter));
|
|
4631
5033
|
disposers.push(onChannelMemberUnbanned(realtimeRouter));
|
|
4632
5034
|
disposers.push(onChannelSetUserMuted(realtimeRouter));
|
|
5035
|
+
disposers.push(onChannelMemberRoleAdded(realtimeRouter));
|
|
5036
|
+
disposers.push(onChannelMemberRoleRemoved(realtimeRouter));
|
|
4633
5037
|
onFetch();
|
|
4634
5038
|
return () => {
|
|
4635
5039
|
disposers.forEach(fn => fn());
|
|
@@ -5023,7 +5427,9 @@ const initializeMessagePreviewSetting = async () => {
|
|
|
5023
5427
|
const getSocialSettings = async () => {
|
|
5024
5428
|
const client = getActiveClient();
|
|
5025
5429
|
const { data } = await client.http.get(`/api/v3/network-settings/social`);
|
|
5026
|
-
return data.socialNetworkSetting
|
|
5430
|
+
return Object.assign(Object.assign({}, data.socialNetworkSetting), {
|
|
5431
|
+
// Networks that never set the comment edit switch allow the edit
|
|
5432
|
+
isAllowEditCommentWhenReviewingEnabled: data.socialNetworkSetting.isAllowEditCommentWhenReviewingEnabled });
|
|
5027
5433
|
};
|
|
5028
5434
|
|
|
5029
5435
|
/**
|
|
@@ -5141,6 +5547,95 @@ const getForYouFeedSetting = async () => {
|
|
|
5141
5547
|
};
|
|
5142
5548
|
/* end_public_function */
|
|
5143
5549
|
|
|
5550
|
+
const ENFORCEMENT_MODES = ['off', 'shadow', 'enforce'];
|
|
5551
|
+
/**
|
|
5552
|
+
* An unrecognised mode decodes to `off`, and so does an absent one. A mode
|
|
5553
|
+
* this build does not know must not withhold anything — defaulting to
|
|
5554
|
+
* `enforce` would let a server-side rename black out a customer's app.
|
|
5555
|
+
*
|
|
5556
|
+
* @category private
|
|
5557
|
+
*/
|
|
5558
|
+
const parseEnforcement = (mode) => {
|
|
5559
|
+
const match = ENFORCEMENT_MODES.find(value => value === mode);
|
|
5560
|
+
return match !== null && match !== void 0 ? match : 'off';
|
|
5561
|
+
};
|
|
5562
|
+
const parseGrants = (modules) => {
|
|
5563
|
+
const grants = {};
|
|
5564
|
+
Object.entries(modules !== null && modules !== void 0 ? modules : {}).forEach(([key, granted]) => {
|
|
5565
|
+
grants[key] = granted === true;
|
|
5566
|
+
});
|
|
5567
|
+
return grants;
|
|
5568
|
+
};
|
|
5569
|
+
/**
|
|
5570
|
+
* Every catalog entry survives, including one whose key this build has never
|
|
5571
|
+
* heard of, so a module added server-side is still listable.
|
|
5572
|
+
*
|
|
5573
|
+
* @category private
|
|
5574
|
+
*/
|
|
5575
|
+
const parseCatalog = (catalog) => {
|
|
5576
|
+
const parsed = {};
|
|
5577
|
+
Object.entries(catalog !== null && catalog !== void 0 ? catalog : {}).forEach(([key, definition]) => {
|
|
5578
|
+
const rawRequires = definition === null || definition === void 0 ? void 0 : definition.requires;
|
|
5579
|
+
const requires = Array.isArray(rawRequires)
|
|
5580
|
+
? rawRequires.filter((entry) => typeof entry === 'string')
|
|
5581
|
+
: [];
|
|
5582
|
+
parsed[key] = {
|
|
5583
|
+
label: typeof (definition === null || definition === void 0 ? void 0 : definition.label) === 'string' ? definition.label : key,
|
|
5584
|
+
kind: (definition === null || definition === void 0 ? void 0 : definition.kind) === 'setting' ? 'setting' : 'api',
|
|
5585
|
+
requires,
|
|
5586
|
+
};
|
|
5587
|
+
});
|
|
5588
|
+
return parsed;
|
|
5589
|
+
};
|
|
5590
|
+
/**
|
|
5591
|
+
* Decodes `GET /api/v3/network-settings/modules`. Nothing is trimmed: the
|
|
5592
|
+
* catalog is the dependency table callers resolve against, and a client that
|
|
5593
|
+
* cannot see it has to hardcode one.
|
|
5594
|
+
*
|
|
5595
|
+
* @category private
|
|
5596
|
+
*/
|
|
5597
|
+
const parseModuleSettings = (raw) => {
|
|
5598
|
+
var _a;
|
|
5599
|
+
return ({
|
|
5600
|
+
enforcement: parseEnforcement((_a = raw === null || raw === void 0 ? void 0 : raw.enforcement) !== null && _a !== void 0 ? _a : raw === null || raw === void 0 ? void 0 : raw.mode),
|
|
5601
|
+
modules: parseGrants(raw === null || raw === void 0 ? void 0 : raw.modules),
|
|
5602
|
+
catalog: parseCatalog(raw === null || raw === void 0 ? void 0 : raw.catalog),
|
|
5603
|
+
});
|
|
5604
|
+
};
|
|
5605
|
+
|
|
5606
|
+
/* begin_public_function
|
|
5607
|
+
id: client.getModuleSettings
|
|
5608
|
+
*/
|
|
5609
|
+
/**
|
|
5610
|
+
* ```js
|
|
5611
|
+
* import { Client } from '@amityco/ts-sdk'
|
|
5612
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
5613
|
+
* ```
|
|
5614
|
+
*
|
|
5615
|
+
* Fetches the network's module entitlements: which modules the network was
|
|
5616
|
+
* granted, whether core is enforcing those grants, and the catalog of all
|
|
5617
|
+
* modules with their dependency chains.
|
|
5618
|
+
*
|
|
5619
|
+
* The payload is returned whole — `catalog` is the dependency table
|
|
5620
|
+
* {@link resolveModuleAvailability} reads, and a client that cannot see it has
|
|
5621
|
+
* to hardcode one.
|
|
5622
|
+
*
|
|
5623
|
+
* The read is **advisory**. It tells a host what to offer; under `enforce` the
|
|
5624
|
+
* backend refuses a call to an unowned module regardless of what was resolved
|
|
5625
|
+
* here, and that refusal arrives as `AmityModuleNotEntitledError`.
|
|
5626
|
+
*
|
|
5627
|
+
* @returns A Promise of {@link Amity.ModuleSettings} object
|
|
5628
|
+
*
|
|
5629
|
+
* @category Client API
|
|
5630
|
+
* @async
|
|
5631
|
+
*/
|
|
5632
|
+
const getModuleSettings = async () => {
|
|
5633
|
+
const client = getActiveClient();
|
|
5634
|
+
const { data } = await client.http.get(`/api/v3/network-settings/modules`);
|
|
5635
|
+
return parseModuleSettings(data);
|
|
5636
|
+
};
|
|
5637
|
+
/* end_public_function */
|
|
5638
|
+
|
|
5144
5639
|
const checkUserPermission = (userId, permission) => {
|
|
5145
5640
|
var _a;
|
|
5146
5641
|
const user = (_a = pullFromCache(['user', 'get', userId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -5709,6 +6204,32 @@ class AnalyticsEventCapturer {
|
|
|
5709
6204
|
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
5710
6205
|
});
|
|
5711
6206
|
}
|
|
6207
|
+
markCuratedContentWidgetAsViewed(topicId) {
|
|
6208
|
+
this.markAs({
|
|
6209
|
+
uniqueId: `curatedContentWidget.${topicId}`,
|
|
6210
|
+
contentId: topicId,
|
|
6211
|
+
contentType: "curated_content_widget" /* Amity.AnalyticEventContentType.CuratedContentWidget */,
|
|
6212
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
6213
|
+
});
|
|
6214
|
+
}
|
|
6215
|
+
markCuratedContentPostAsViewed(postId, topicId) {
|
|
6216
|
+
this.markAs({
|
|
6217
|
+
uniqueId: `curatedContentPost.${postId}.view`,
|
|
6218
|
+
contentId: postId,
|
|
6219
|
+
contentType: "curated_content_post" /* Amity.AnalyticEventContentType.CuratedContentPost */,
|
|
6220
|
+
activityType: "view" /* Amity.AnalyticEventActivityType.View */,
|
|
6221
|
+
metadata: { topicId },
|
|
6222
|
+
});
|
|
6223
|
+
}
|
|
6224
|
+
markCuratedContentPostAsClicked(postId, topicId) {
|
|
6225
|
+
this.markAs({
|
|
6226
|
+
uniqueId: `curatedContentPost.${postId}.click`,
|
|
6227
|
+
contentId: postId,
|
|
6228
|
+
contentType: "curated_content_post" /* Amity.AnalyticEventContentType.CuratedContentPost */,
|
|
6229
|
+
activityType: "linkClicked" /* Amity.AnalyticEventActivityType.Click */,
|
|
6230
|
+
metadata: { topicId },
|
|
6231
|
+
});
|
|
6232
|
+
}
|
|
5712
6233
|
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
5713
6234
|
var _a;
|
|
5714
6235
|
const cached = (_a = pullFromCache(['feedMetadata', 'get', postId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
@@ -5872,6 +6393,24 @@ class AnalyticsEngine {
|
|
|
5872
6393
|
this._eventCapturer.markPostAsViewed(postId);
|
|
5873
6394
|
}
|
|
5874
6395
|
}
|
|
6396
|
+
markCuratedContentWidgetAsViewed(topicId) {
|
|
6397
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6398
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6399
|
+
this._eventCapturer.markCuratedContentWidgetAsViewed(topicId);
|
|
6400
|
+
}
|
|
6401
|
+
}
|
|
6402
|
+
markCuratedContentPostAsViewed(postId, topicId) {
|
|
6403
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6404
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6405
|
+
this._eventCapturer.markCuratedContentPostAsViewed(postId, topicId);
|
|
6406
|
+
}
|
|
6407
|
+
}
|
|
6408
|
+
markCuratedContentPostAsClicked(postId, topicId) {
|
|
6409
|
+
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
6410
|
+
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
6411
|
+
this._eventCapturer.markCuratedContentPostAsClicked(postId, topicId);
|
|
6412
|
+
}
|
|
6413
|
+
}
|
|
5875
6414
|
markPostAsMeaningfullyViewed(postId, feedRenderPosition) {
|
|
5876
6415
|
if (this._client.sessionState === "established" /* Amity.SessionStates.ESTABLISHED */ ||
|
|
5877
6416
|
this._client.sessionState === "tokenExpired" /* Amity.SessionStates.TOKEN_EXPIRED */) {
|
|
@@ -7268,6 +7807,265 @@ class CursorController {
|
|
|
7268
7807
|
}
|
|
7269
7808
|
}
|
|
7270
7809
|
|
|
7810
|
+
class ResetTask {
|
|
7811
|
+
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
7812
|
+
this.postId = postId;
|
|
7813
|
+
this.latestCreatedAt = latestCreatedAt;
|
|
7814
|
+
this.serverCommentCount = serverCommentCount;
|
|
7815
|
+
}
|
|
7816
|
+
}
|
|
7817
|
+
|
|
7818
|
+
// Task to track comment creation
|
|
7819
|
+
class CreateTask {
|
|
7820
|
+
constructor(postId, commentId, createdAt) {
|
|
7821
|
+
this.postId = postId;
|
|
7822
|
+
this.commentId = commentId;
|
|
7823
|
+
this.createdAt = createdAt;
|
|
7824
|
+
}
|
|
7825
|
+
}
|
|
7826
|
+
|
|
7827
|
+
/**
|
|
7828
|
+
* A pending comment was approved and now counts publicly. Unlike `CreateTask` it carries no
|
|
7829
|
+
* `createdAt` and bypasses the age guard on purpose: the comment was written before the last post
|
|
7830
|
+
* payload (so its `createdAt` is old) but entered the server count only now. Same rule as iOS.
|
|
7831
|
+
*
|
|
7832
|
+
* Accepted trade-off (plan 40 §9): if a `ResetTask` that already includes this comment lands
|
|
7833
|
+
* between the approve response and the late `comment.approved` event, the count reads +1 until
|
|
7834
|
+
* the next server sync — the same self-correcting drift accepted for stale deletes.
|
|
7835
|
+
*/
|
|
7836
|
+
class ApproveTask {
|
|
7837
|
+
constructor(postId, commentId) {
|
|
7838
|
+
this.postId = postId;
|
|
7839
|
+
this.commentId = commentId;
|
|
7840
|
+
}
|
|
7841
|
+
}
|
|
7842
|
+
|
|
7843
|
+
// Task to track comment deletion
|
|
7844
|
+
class DeleteTask {
|
|
7845
|
+
constructor(postId, commentId) {
|
|
7846
|
+
this.postId = postId;
|
|
7847
|
+
this.commentId = commentId;
|
|
7848
|
+
}
|
|
7849
|
+
}
|
|
7850
|
+
|
|
7851
|
+
class CommentChange {
|
|
7852
|
+
constructor(latestCreatedAt, serverCommentCount) {
|
|
7853
|
+
this.latestCommentCreatedAt = latestCreatedAt;
|
|
7854
|
+
this.serverCommentCount = serverCommentCount;
|
|
7855
|
+
this.createdCommentIds = new Set();
|
|
7856
|
+
this.deletedCommentIds = new Set();
|
|
7857
|
+
}
|
|
7858
|
+
}
|
|
7859
|
+
|
|
7860
|
+
class PostCommentCountEngine {
|
|
7861
|
+
constructor() {
|
|
7862
|
+
this.isProcessing = false;
|
|
7863
|
+
this.tasks = [];
|
|
7864
|
+
this.commentChangeTracker = new Map();
|
|
7865
|
+
// Ids of the LOGGED-IN USER's own pending comments, per post. Survives ResetTask, so the
|
|
7866
|
+
// author's +1 does not vanish on the next post refresh; emptied only when the comment leaves
|
|
7867
|
+
// the pending state (approval hands it to createdCommentIds, decline/delete drops it).
|
|
7868
|
+
this.pendingAuthoredCommentIds = new Map();
|
|
7869
|
+
}
|
|
7870
|
+
queueCommentChangeTask(task) {
|
|
7871
|
+
this.tasks.push(task);
|
|
7872
|
+
if (!this.isProcessing) {
|
|
7873
|
+
this.processCommentChangeTask();
|
|
7874
|
+
}
|
|
7875
|
+
}
|
|
7876
|
+
addPendingAuthoredComment(postId, commentId, { publish = true } = {}) {
|
|
7877
|
+
var _a;
|
|
7878
|
+
const ids = (_a = this.pendingAuthoredCommentIds.get(postId)) !== null && _a !== void 0 ? _a : new Set();
|
|
7879
|
+
if (ids.has(commentId))
|
|
7880
|
+
return;
|
|
7881
|
+
ids.add(commentId);
|
|
7882
|
+
this.pendingAuthoredCommentIds.set(postId, ids);
|
|
7883
|
+
if (publish)
|
|
7884
|
+
this.publishIfTracked(postId);
|
|
7885
|
+
}
|
|
7886
|
+
removePendingAuthoredComment(postId, commentId, { publish = true } = {}) {
|
|
7887
|
+
const ids = this.pendingAuthoredCommentIds.get(postId);
|
|
7888
|
+
if (!(ids === null || ids === void 0 ? void 0 : ids.delete(commentId)))
|
|
7889
|
+
return false;
|
|
7890
|
+
if (ids.size === 0)
|
|
7891
|
+
this.pendingAuthoredCommentIds.delete(postId);
|
|
7892
|
+
if (publish)
|
|
7893
|
+
this.publishIfTracked(postId);
|
|
7894
|
+
return true;
|
|
7895
|
+
}
|
|
7896
|
+
/** Whether a post payload has seeded this post; without one every count is `0`. */
|
|
7897
|
+
hasTracker(postId) {
|
|
7898
|
+
return this.commentChangeTracker.has(postId);
|
|
7899
|
+
}
|
|
7900
|
+
isPendingAuthoredComment(postId, commentId) {
|
|
7901
|
+
var _a, _b;
|
|
7902
|
+
return (_b = (_a = this.pendingAuthoredCommentIds.get(postId)) === null || _a === void 0 ? void 0 : _a.has(commentId)) !== null && _b !== void 0 ? _b : false;
|
|
7903
|
+
}
|
|
7904
|
+
// Drops every per-post state. Called on logout / user switch.
|
|
7905
|
+
reset() {
|
|
7906
|
+
this.tasks = [];
|
|
7907
|
+
this.commentChangeTracker.clear();
|
|
7908
|
+
this.pendingAuthoredCommentIds.clear();
|
|
7909
|
+
}
|
|
7910
|
+
publishIfTracked(postId) {
|
|
7911
|
+
// Without a tracker there is no server figure to add to; the next ResetTask picks it up.
|
|
7912
|
+
if (!this.commentChangeTracker.has(postId))
|
|
7913
|
+
return;
|
|
7914
|
+
PostCommentCountEngine.publishUpdate(postId, this.getLocalCommentCount(postId, true));
|
|
7915
|
+
}
|
|
7916
|
+
processCommentChangeTask() {
|
|
7917
|
+
if (this.isProcessing) {
|
|
7918
|
+
return;
|
|
7919
|
+
}
|
|
7920
|
+
this.isProcessing = true;
|
|
7921
|
+
if (this.tasks.length === 0) {
|
|
7922
|
+
this.isProcessing = false;
|
|
7923
|
+
return;
|
|
7924
|
+
}
|
|
7925
|
+
// Process in capped batches, coalescing updates
|
|
7926
|
+
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
7927
|
+
const modifiedPostIds = new Set();
|
|
7928
|
+
batch.forEach(task => {
|
|
7929
|
+
let modified = false;
|
|
7930
|
+
if (task instanceof ResetTask) {
|
|
7931
|
+
modified = this.processResetTaskInternal(task);
|
|
7932
|
+
}
|
|
7933
|
+
else if (task instanceof CreateTask) {
|
|
7934
|
+
modified = this.processCreateTaskInternal(task);
|
|
7935
|
+
}
|
|
7936
|
+
else if (task instanceof ApproveTask) {
|
|
7937
|
+
modified = this.processApproveTaskInternal(task);
|
|
7938
|
+
}
|
|
7939
|
+
else if (task instanceof DeleteTask) {
|
|
7940
|
+
modified = this.processDeleteTaskInternal(task);
|
|
7941
|
+
}
|
|
7942
|
+
if (modified) {
|
|
7943
|
+
modifiedPostIds.add(task.postId);
|
|
7944
|
+
}
|
|
7945
|
+
});
|
|
7946
|
+
// Publish one update per modified post
|
|
7947
|
+
modifiedPostIds.forEach(postId => {
|
|
7948
|
+
PostCommentCountEngine.publishUpdate(postId, this.getLocalCommentCount(postId, true));
|
|
7949
|
+
});
|
|
7950
|
+
this.isProcessing = false;
|
|
7951
|
+
// Recurse if more tasks remain
|
|
7952
|
+
if (this.tasks.length > 0) {
|
|
7953
|
+
this.processCommentChangeTask();
|
|
7954
|
+
}
|
|
7955
|
+
}
|
|
7956
|
+
processResetTaskInternal(task) {
|
|
7957
|
+
// Always creates/overwrites tracker
|
|
7958
|
+
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
7959
|
+
return true;
|
|
7960
|
+
}
|
|
7961
|
+
processCreateTaskInternal(task) {
|
|
7962
|
+
// The comment is public now: the author-local +1 hands over to the normal path, so the
|
|
7963
|
+
// count stays put instead of moving twice.
|
|
7964
|
+
const wasPendingAuthored = this.removePendingAuthoredComment(task.postId, task.commentId, {
|
|
7965
|
+
publish: false,
|
|
7966
|
+
});
|
|
7967
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7968
|
+
if (!tracker)
|
|
7969
|
+
return false; // No tracker, skip
|
|
7970
|
+
if (tracker.deletedCommentIds.delete(task.commentId))
|
|
7971
|
+
return true; // Re-approval cancels the earlier removal
|
|
7972
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
7973
|
+
return wasPendingAuthored; // Deduplication
|
|
7974
|
+
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
7975
|
+
return wasPendingAuthored; // Timestamp filtering
|
|
7976
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
7977
|
+
return true;
|
|
7978
|
+
}
|
|
7979
|
+
processApproveTaskInternal(task) {
|
|
7980
|
+
// The comment is public now: the author-local +1 hands over to the normal path, so the
|
|
7981
|
+
// count stays put instead of moving twice.
|
|
7982
|
+
const wasPendingAuthored = this.removePendingAuthoredComment(task.postId, task.commentId, {
|
|
7983
|
+
publish: false,
|
|
7984
|
+
});
|
|
7985
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7986
|
+
if (!tracker)
|
|
7987
|
+
return false; // No tracker, skip
|
|
7988
|
+
if (tracker.deletedCommentIds.delete(task.commentId))
|
|
7989
|
+
return true; // Re-approval cancels the earlier re-review removal
|
|
7990
|
+
if (tracker.createdCommentIds.has(task.commentId))
|
|
7991
|
+
return wasPendingAuthored; // Approve response and comment.approved event dedupe by id
|
|
7992
|
+
// No timestamp filtering: approval is the moment the comment enters the count, not createdAt
|
|
7993
|
+
tracker.createdCommentIds.add(task.commentId);
|
|
7994
|
+
return true;
|
|
7995
|
+
}
|
|
7996
|
+
processDeleteTaskInternal(task) {
|
|
7997
|
+
const tracker = this.commentChangeTracker.get(task.postId);
|
|
7998
|
+
if (!tracker)
|
|
7999
|
+
return false; // No tracker, skip
|
|
8000
|
+
if (tracker.deletedCommentIds.has(task.commentId))
|
|
8001
|
+
return false; // Deduplication
|
|
8002
|
+
tracker.deletedCommentIds.add(task.commentId);
|
|
8003
|
+
return true;
|
|
8004
|
+
}
|
|
8005
|
+
/**
|
|
8006
|
+
* The count as this session sees it: the last server figure plus the local delta.
|
|
8007
|
+
*
|
|
8008
|
+
* `includePending` adds the logged-in user's own pending comments — the author's view. A
|
|
8009
|
+
* pending id is added only while the public delta does not already count it, so a comment
|
|
8010
|
+
* present in both sets counts once: a `comment.created` that arrives pending after the
|
|
8011
|
+
* `comment.approved` hand-over adds nothing, while an approved comment sent back to review
|
|
8012
|
+
* (created, deleted and pending all hold its id) keeps the author's +1.
|
|
8013
|
+
*
|
|
8014
|
+
* `0` for a post no payload has seeded yet; callers fall back to the post's own figure.
|
|
8015
|
+
*/
|
|
8016
|
+
getLocalCommentCount(postId, includePending = false) {
|
|
8017
|
+
var _a;
|
|
8018
|
+
const tracker = this.commentChangeTracker.get(postId);
|
|
8019
|
+
if (!tracker)
|
|
8020
|
+
return 0;
|
|
8021
|
+
const publicDelta = tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
8022
|
+
if (!includePending)
|
|
8023
|
+
return Math.max(0, tracker.serverCommentCount + publicDelta);
|
|
8024
|
+
let pendingExtra = 0;
|
|
8025
|
+
(_a = this.pendingAuthoredCommentIds.get(postId)) === null || _a === void 0 ? void 0 : _a.forEach(commentId => {
|
|
8026
|
+
const countedPublicly = tracker.createdCommentIds.has(commentId) && !tracker.deletedCommentIds.has(commentId);
|
|
8027
|
+
if (!countedPublicly)
|
|
8028
|
+
pendingExtra += 1;
|
|
8029
|
+
});
|
|
8030
|
+
return Math.max(0, tracker.serverCommentCount + publicDelta + pendingExtra);
|
|
8031
|
+
}
|
|
8032
|
+
static publishUpdate(postId, newCount) {
|
|
8033
|
+
var _a;
|
|
8034
|
+
const queryKey = ['post', 'get', postId];
|
|
8035
|
+
mergeInCache(queryKey, {
|
|
8036
|
+
localCommentCount: newCount,
|
|
8037
|
+
});
|
|
8038
|
+
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
8039
|
+
if (!postPayload)
|
|
8040
|
+
return;
|
|
8041
|
+
fireEvent('local.post.updated', {
|
|
8042
|
+
posts: [postPayload],
|
|
8043
|
+
});
|
|
8044
|
+
}
|
|
8045
|
+
}
|
|
8046
|
+
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
8047
|
+
let instance$1;
|
|
8048
|
+
var PostCommentCountEngine$1 = {
|
|
8049
|
+
getInstance: () => {
|
|
8050
|
+
if (!instance$1) {
|
|
8051
|
+
instance$1 = new PostCommentCountEngine();
|
|
8052
|
+
}
|
|
8053
|
+
return instance$1;
|
|
8054
|
+
},
|
|
8055
|
+
};
|
|
8056
|
+
|
|
8057
|
+
/**
|
|
8058
|
+
* Comment-count state is per user — in particular the ids of the logged-in user's own pending
|
|
8059
|
+
* comments — so it must not survive a logout or a user switch.
|
|
8060
|
+
*
|
|
8061
|
+
* @category private
|
|
8062
|
+
*/
|
|
8063
|
+
const postCommentCountEngineOnLoginHandler = () => onSessionStateChange(state => {
|
|
8064
|
+
if (state === "notLoggedIn" /* Amity.SessionStates.NOT_LOGGED_IN */ || state === "terminated" /* Amity.SessionStates.TERMINATED */) {
|
|
8065
|
+
PostCommentCountEngine$1.getInstance().reset();
|
|
8066
|
+
}
|
|
8067
|
+
});
|
|
8068
|
+
|
|
7271
8069
|
const EVENTS = [
|
|
7272
8070
|
'disconnected',
|
|
7273
8071
|
'error',
|
|
@@ -7457,7 +8255,7 @@ const setupLoginSubscriptions = (unsubWatcher) => {
|
|
|
7457
8255
|
// NOTE: This is a temporary solution to handle the channel marker when the user is forced to leave
|
|
7458
8256
|
// the channel because currently backend can't handle this, so every time a user is banned from
|
|
7459
8257
|
// a channel or the channel is deleted the channel's unread count will not be reset to zero
|
|
7460
|
-
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout());
|
|
8258
|
+
onChannelDeleted(removeChannelMarkerCache), onChannelMemberBanned(removeChannelMarkerCache), markReadEngineOnLoginHandler(), analyticsEngineOnLoginHandler(), objectResolverEngineOnLoginHandler(), reactionSyncEngineOnLoginHandler(), blockedUserSyncEngineOnLoginHandler(), blockingUserSyncEngineOnLoginHandler(), blockRealtimeOnLoginHandler(), resetAutoSubscriptionsOnLogout(), CursorController.clearOnLogout(), postCommentCountEngineOnLoginHandler());
|
|
7461
8259
|
if (client.useLegacyUnreadCount) {
|
|
7462
8260
|
subscriptions.push(readReceiptSyncEngineOnLoginHandler());
|
|
7463
8261
|
}
|
|
@@ -8493,7 +9291,7 @@ const DEFAULT_DEBUG_SESSION = 'amity';
|
|
|
8493
9291
|
*
|
|
8494
9292
|
* @category Client API
|
|
8495
9293
|
* */
|
|
8496
|
-
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, } = {}) => {
|
|
9294
|
+
const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAULT_DEBUG_SESSION, apiEndpoint, prefixDeviceIdKey, rteEnabled = true, product, uikitVersion, appId, appVersion, } = {}) => {
|
|
8497
9295
|
var _a, _b, _c;
|
|
8498
9296
|
const log = createLogger(debugSession);
|
|
8499
9297
|
log('client/api/createClient', {
|
|
@@ -8522,6 +9320,10 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
8522
9320
|
const useLegacyUnreadCount = true;
|
|
8523
9321
|
const client = {
|
|
8524
9322
|
version: `${VERSION}`,
|
|
9323
|
+
product,
|
|
9324
|
+
uikitVersion,
|
|
9325
|
+
appId,
|
|
9326
|
+
appVersion,
|
|
8525
9327
|
apiKey,
|
|
8526
9328
|
/*
|
|
8527
9329
|
* SDK Components
|
|
@@ -8558,6 +9360,7 @@ const createClient = (apiKey, apiRegion = API_REGIONS.SG, { debugSession = DEFAU
|
|
|
8558
9360
|
getMarkerSyncConsistentMode,
|
|
8559
9361
|
getProductCatalogueSetting,
|
|
8560
9362
|
getForYouFeedSetting,
|
|
9363
|
+
getModuleSettings,
|
|
8561
9364
|
/**
|
|
8562
9365
|
* Prefix for the deviceId key in the local storage or async storage.
|
|
8563
9366
|
* This is allow user to have multiple SDK client and Mqtt client within the same app.
|
|
@@ -8760,13 +9563,13 @@ class GlobalFileAccessType {
|
|
|
8760
9563
|
}
|
|
8761
9564
|
}
|
|
8762
9565
|
_GlobalFileAccessType_fileAccessType = new WeakMap();
|
|
8763
|
-
let instance
|
|
9566
|
+
let instance;
|
|
8764
9567
|
var GlobalFileAccessType$1 = {
|
|
8765
9568
|
getInstance: () => {
|
|
8766
|
-
if (!instance
|
|
8767
|
-
instance
|
|
9569
|
+
if (!instance) {
|
|
9570
|
+
instance = new GlobalFileAccessType();
|
|
8768
9571
|
}
|
|
8769
|
-
return instance
|
|
9572
|
+
return instance;
|
|
8770
9573
|
},
|
|
8771
9574
|
};
|
|
8772
9575
|
|
|
@@ -9603,7 +10406,93 @@ const getUserUnread = (callback) => {
|
|
|
9603
10406
|
};
|
|
9604
10407
|
};
|
|
9605
10408
|
|
|
9606
|
-
|
|
10409
|
+
/**
|
|
10410
|
+
* ```js
|
|
10411
|
+
* import { Client, resolveModuleAvailability } from '@amityco/ts-sdk'
|
|
10412
|
+
*
|
|
10413
|
+
* const moduleSettings = await Client.getModuleSettings()
|
|
10414
|
+
*
|
|
10415
|
+
* if (resolveModuleAvailability(moduleSettings, 'live').isAvailable) {
|
|
10416
|
+
* // offer the Live entry point
|
|
10417
|
+
* }
|
|
10418
|
+
* ```
|
|
10419
|
+
*
|
|
10420
|
+
* Resolves whether one module is usable on this network.
|
|
10421
|
+
*
|
|
10422
|
+
* Availability is a function of all three fields of
|
|
10423
|
+
* {@link Amity.ModuleSettings} — the enforcement mode, the module's own grant,
|
|
10424
|
+
* and its prerequisite chain — combined in that order. Reading `modules`
|
|
10425
|
+
* directly contradicts the mode: staging answers `mode: 'off'` with
|
|
10426
|
+
* `modules: {}`, and every module still works.
|
|
10427
|
+
*
|
|
10428
|
+
* The dependency table comes from the payload's `catalog`, never from a
|
|
10429
|
+
* hardcoded copy, so a chain the backend changes takes effect without an SDK
|
|
10430
|
+
* release.
|
|
10431
|
+
*
|
|
10432
|
+
* The SDK does not hold the settings — the caller keeps what it fetched and
|
|
10433
|
+
* resolves against it. With no settings at all (a fetch that never succeeded)
|
|
10434
|
+
* the caller reads that as every module available: under `enforce` the backend
|
|
10435
|
+
* refuses the calls anyway, so the exposure is a screen that offers too much,
|
|
10436
|
+
* not one that withholds what a customer paid for.
|
|
10437
|
+
*
|
|
10438
|
+
* @param moduleSettings The network's module settings
|
|
10439
|
+
* @param moduleKey The module to resolve — an {@link Amity.ModuleKey}, so the
|
|
10440
|
+
* 15 keys this build knows complete and type-check while a catalog entry it
|
|
10441
|
+
* does not know still resolves.
|
|
10442
|
+
* @returns An {@link Amity.ModuleAvailability} answer
|
|
10443
|
+
*
|
|
10444
|
+
* @category Client API
|
|
10445
|
+
*/
|
|
10446
|
+
const resolveModuleAvailability = (moduleSettings, moduleKey, seen = new Set()) => {
|
|
10447
|
+
var _a, _b, _c, _d, _e;
|
|
10448
|
+
const isGranted = (_a = moduleSettings.modules[moduleKey]) !== null && _a !== void 0 ? _a : false;
|
|
10449
|
+
/*
|
|
10450
|
+
* Not enforcing: nothing is withheld, and no graph walk is needed. This has
|
|
10451
|
+
* to come first — `off` and `shadow` resolve available whatever the grant
|
|
10452
|
+
* says, and a cycle would otherwise return unavailable under `off` too.
|
|
10453
|
+
*/
|
|
10454
|
+
if (moduleSettings.enforcement !== 'enforce') {
|
|
10455
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10456
|
+
}
|
|
10457
|
+
// A cycle in `requires` resolves unavailable rather than recursing.
|
|
10458
|
+
if (seen.has(moduleKey)) {
|
|
10459
|
+
return {
|
|
10460
|
+
moduleKey,
|
|
10461
|
+
isAvailable: false,
|
|
10462
|
+
isGranted,
|
|
10463
|
+
reason: 'prerequisiteUnavailable',
|
|
10464
|
+
unsatisfied: (_c = (_b = moduleSettings.catalog[moduleKey]) === null || _b === void 0 ? void 0 : _b.requires) !== null && _c !== void 0 ? _c : [],
|
|
10465
|
+
};
|
|
10466
|
+
}
|
|
10467
|
+
// The module's own grant is evaluated before its prerequisites, so
|
|
10468
|
+
// `notGranted` is reported in preference when both hold.
|
|
10469
|
+
if (!isGranted) {
|
|
10470
|
+
return { moduleKey, isAvailable: false, isGranted, reason: 'notGranted' };
|
|
10471
|
+
}
|
|
10472
|
+
const requires = (_e = (_d = moduleSettings.catalog[moduleKey]) === null || _d === void 0 ? void 0 : _d.requires) !== null && _e !== void 0 ? _e : [];
|
|
10473
|
+
if (requires.length === 0)
|
|
10474
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10475
|
+
// `requires` is satisfied by any one entry, transitively.
|
|
10476
|
+
const isSatisfied = requires.some(dependency => resolveModuleAvailability(moduleSettings, dependency, new Set([...seen, moduleKey]))
|
|
10477
|
+
.isAvailable);
|
|
10478
|
+
if (isSatisfied)
|
|
10479
|
+
return { moduleKey, isAvailable: true, isGranted };
|
|
10480
|
+
/*
|
|
10481
|
+
* `unsatisfied` carries the whole `requires` list rather than one entry. Any
|
|
10482
|
+
* one of them would have satisfied the requirement, so naming a single
|
|
10483
|
+
* module misdirects: telling a Community-only customer "Comment needs post"
|
|
10484
|
+
* hides that Story would also have done.
|
|
10485
|
+
*/
|
|
10486
|
+
return {
|
|
10487
|
+
moduleKey,
|
|
10488
|
+
isAvailable: false,
|
|
10489
|
+
isGranted,
|
|
10490
|
+
reason: 'prerequisiteUnavailable',
|
|
10491
|
+
unsatisfied: requires,
|
|
10492
|
+
};
|
|
10493
|
+
};
|
|
10494
|
+
|
|
10495
|
+
var index$t = /*#__PURE__*/Object.freeze({
|
|
9607
10496
|
__proto__: null,
|
|
9608
10497
|
getActiveClient: getActiveClient,
|
|
9609
10498
|
getActiveUser: getActiveUser,
|
|
@@ -9626,6 +10515,7 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
9626
10515
|
getShareableLinkConfiguration: getShareableLinkConfiguration,
|
|
9627
10516
|
getProductCatalogueSetting: getProductCatalogueSetting,
|
|
9628
10517
|
getForYouFeedSetting: getForYouFeedSetting,
|
|
10518
|
+
getModuleSettings: getModuleSettings,
|
|
9629
10519
|
loginAsVisitor: loginAsVisitor,
|
|
9630
10520
|
loginAsBot: loginAsBot,
|
|
9631
10521
|
getCurrentUser: getCurrentUser,
|
|
@@ -9653,7 +10543,8 @@ var index$s = /*#__PURE__*/Object.freeze({
|
|
|
9653
10543
|
startMarkerSync: startMarkerSync,
|
|
9654
10544
|
startUnreadSync: startUnreadSync,
|
|
9655
10545
|
stopUnreadSync: stopUnreadSync,
|
|
9656
|
-
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode
|
|
10546
|
+
getMarkerSyncConsistentMode: getMarkerSyncConsistentMode,
|
|
10547
|
+
resolveModuleAvailability: resolveModuleAvailability
|
|
9657
10548
|
});
|
|
9658
10549
|
|
|
9659
10550
|
/* begin_public_function
|
|
@@ -10829,7 +11720,7 @@ const getMyFollowInfo = (callback) => {
|
|
|
10829
11720
|
};
|
|
10830
11721
|
/* end_public_function */
|
|
10831
11722
|
|
|
10832
|
-
var index$
|
|
11723
|
+
var index$s = /*#__PURE__*/Object.freeze({
|
|
10833
11724
|
__proto__: null,
|
|
10834
11725
|
blockUser: blockUser,
|
|
10835
11726
|
unBlockUser: unBlockUser,
|
|
@@ -12170,6 +13061,16 @@ const createChannel = async (bundle) => {
|
|
|
12170
13061
|
/* c8 ignore next */
|
|
12171
13062
|
isPublic: (bundle === null || bundle === void 0 ? void 0 : bundle.type) === 'community' ? isPublic : undefined }));
|
|
12172
13063
|
}
|
|
13064
|
+
// Fire the event locally, the same way createCommunity and createPost do.
|
|
13065
|
+
// Without it a running getChannels collection never inserts the new channel:
|
|
13066
|
+
// its query stream controller inserts an id only on OnCreate / OnJoin /
|
|
13067
|
+
// OnResolveChannel / OnUnarchived, and the first sent message arrives as an
|
|
13068
|
+
// OnUpdate, which only re-notifies. Reusing the MQTT event name means the
|
|
13069
|
+
// already-wired onChannelCreated -> OnCreate path does the insert, so the
|
|
13070
|
+
// list updates without a re-query. onChannelCreated re-runs
|
|
13071
|
+
// prepareChannelPayload + ingestInCache itself, so this is idempotent with
|
|
13072
|
+
// the ingest below.
|
|
13073
|
+
fireEvent('channel.created', payload.data);
|
|
12173
13074
|
const data = await prepareChannelPayload(payload.data);
|
|
12174
13075
|
const cachedAt = client.cache && Date.now();
|
|
12175
13076
|
if (client.cache)
|
|
@@ -12341,8 +13242,32 @@ const streamLinkedObject = (stream) => {
|
|
|
12341
13242
|
} });
|
|
12342
13243
|
};
|
|
12343
13244
|
|
|
13245
|
+
const KNOWN_APPROVAL_STATUSES = [
|
|
13246
|
+
"pending" /* Amity.CommentApprovalStatusEnum.Pending */,
|
|
13247
|
+
"approved" /* Amity.CommentApprovalStatusEnum.Approved */,
|
|
13248
|
+
"rejected" /* Amity.CommentApprovalStatusEnum.Rejected */,
|
|
13249
|
+
];
|
|
13250
|
+
/**
|
|
13251
|
+
* The server sends `approvalStatus` only while a comment is held for review or after it was
|
|
13252
|
+
* rejected. Absent, `null`, or an unrecognised value all resolve to `approved` — never to
|
|
13253
|
+
* `pending`, which would mark every comment written before the feature as unpublished.
|
|
13254
|
+
*/
|
|
13255
|
+
const resolveCommentApprovalStatus = (approvalStatus) => {
|
|
13256
|
+
if (approvalStatus && KNOWN_APPROVAL_STATUSES.includes(approvalStatus)) {
|
|
13257
|
+
return approvalStatus;
|
|
13258
|
+
}
|
|
13259
|
+
return "approved" /* Amity.CommentApprovalStatusEnum.Approved */;
|
|
13260
|
+
};
|
|
13261
|
+
const prepareComment = (comment) => (Object.assign(Object.assign(Object.assign({}, (comment.hasOwnProperty('myReactions') ? {} : { myReactions: [] })), comment), { approvalStatus: resolveCommentApprovalStatus(comment.approvalStatus) }));
|
|
13262
|
+
function prepareCommentPayload(commentPayload) {
|
|
13263
|
+
const { comments, commentChildren } = commentPayload;
|
|
13264
|
+
return Object.assign(Object.assign(Object.assign({}, commentPayload), { comments: comments.map(prepareComment) }), (commentChildren ? { commentChildren: commentChildren.map(prepareComment) } : {}));
|
|
13265
|
+
}
|
|
13266
|
+
|
|
12344
13267
|
const commentLinkedObject = (comment) => {
|
|
12345
|
-
return Object.assign(Object.assign({}, comment), {
|
|
13268
|
+
return Object.assign(Object.assign({}, comment), {
|
|
13269
|
+
// Non-optional on the public model: absent on the wire means approved
|
|
13270
|
+
approvalStatus: resolveCommentApprovalStatus(comment.approvalStatus), get target() {
|
|
12346
13271
|
const commentTypes = {
|
|
12347
13272
|
type: comment.targetType,
|
|
12348
13273
|
};
|
|
@@ -12550,7 +13475,7 @@ const getWatchSessionStorage = () => {
|
|
|
12550
13475
|
return storageInstance;
|
|
12551
13476
|
};
|
|
12552
13477
|
|
|
12553
|
-
const privateKey = "
|
|
13478
|
+
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=";
|
|
12554
13479
|
/*
|
|
12555
13480
|
* The crypto algorithm used for importing key and signing string
|
|
12556
13481
|
*/
|
|
@@ -12993,6 +13918,122 @@ const fileLinkedObject = (file) => {
|
|
|
12993
13918
|
return file;
|
|
12994
13919
|
};
|
|
12995
13920
|
|
|
13921
|
+
const isCommentPending = (comment) => resolveCommentApprovalStatus(comment.approvalStatus) === "pending" /* Amity.CommentApprovalStatusEnum.Pending */;
|
|
13922
|
+
const isCommentApproved = (comment) => resolveCommentApprovalStatus(comment.approvalStatus) === "approved" /* Amity.CommentApprovalStatusEnum.Approved */;
|
|
13923
|
+
// Only post and content references feed PostCommentCountEngine; story counts live on the story.
|
|
13924
|
+
const isCountedReference = (comment) => ['post', 'content'].includes(comment.referenceType);
|
|
13925
|
+
const isAuthoredByCurrentUser = (comment) => comment.userId === getActiveClient().userId;
|
|
13926
|
+
/**
|
|
13927
|
+
* Whether a comment on this reference would be held for review, read from the cached post's
|
|
13928
|
+
* community. `true` when that cannot be known — the post or its community is not cached yet.
|
|
13929
|
+
* A pending guess that turns out approved is corrected by the response and the comment then
|
|
13930
|
+
* enters the list; an approved guess that turns out pending has already been shown in a public
|
|
13931
|
+
* list with nothing to take it back out. Only shapes the optimistic object — the server
|
|
13932
|
+
* response is the authority on the actual status.
|
|
13933
|
+
*/
|
|
13934
|
+
const isCommentApprovalRequired = (bundle) => {
|
|
13935
|
+
var _a, _b;
|
|
13936
|
+
// Only comments on community posts are gated; every other reference is known-off
|
|
13937
|
+
if (bundle.referenceType !== 'post')
|
|
13938
|
+
return false;
|
|
13939
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
13940
|
+
if (!post)
|
|
13941
|
+
return true;
|
|
13942
|
+
// A user-feed post is known-off
|
|
13943
|
+
if (post.targetType !== 'community')
|
|
13944
|
+
return false;
|
|
13945
|
+
const community = (_b = pullFromCache([
|
|
13946
|
+
'community',
|
|
13947
|
+
'get',
|
|
13948
|
+
post.targetId,
|
|
13949
|
+
])) === null || _b === void 0 ? void 0 : _b.data;
|
|
13950
|
+
if (!community)
|
|
13951
|
+
return true;
|
|
13952
|
+
return community.needApprovalOnCommentCreation === true;
|
|
13953
|
+
};
|
|
13954
|
+
/**
|
|
13955
|
+
* An approved comment arrived over realtime: one `CreateTask` carrying its own `createdAt`, so
|
|
13956
|
+
* the timestamp filter skips anything the last post payload already counted. The author's own
|
|
13957
|
+
* comment reaches here as an echo too; the engine de-duplicates it by id against the task the
|
|
13958
|
+
* create response queued.
|
|
13959
|
+
*/
|
|
13960
|
+
const applyCommentCreatedCount = (comment) => {
|
|
13961
|
+
if (!isCountedReference(comment))
|
|
13962
|
+
return;
|
|
13963
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(comment.referenceId, comment.commentId, comment.createdAt));
|
|
13964
|
+
};
|
|
13965
|
+
/**
|
|
13966
|
+
* The author's own pending comment counts in their view only. Recorded as separate engine state
|
|
13967
|
+
* so it survives a post refresh (`ResetTask`).
|
|
13968
|
+
*/
|
|
13969
|
+
const recordPendingAuthoredComment = (comment, options) => {
|
|
13970
|
+
if (!isCountedReference(comment) || !isAuthoredByCurrentUser(comment))
|
|
13971
|
+
return;
|
|
13972
|
+
PostCommentCountEngine$1.getInstance().addPendingAuthoredComment(comment.referenceId, comment.commentId, options);
|
|
13973
|
+
};
|
|
13974
|
+
/**
|
|
13975
|
+
* A pending comment was declined or deleted: it was never in the server count, so no
|
|
13976
|
+
* `DeleteTask` — only the author-local +1 goes away.
|
|
13977
|
+
*/
|
|
13978
|
+
const releasePendingAuthoredComment = (comment) => {
|
|
13979
|
+
if (!isCountedReference(comment))
|
|
13980
|
+
return;
|
|
13981
|
+
PostCommentCountEngine$1.getInstance().removePendingAuthoredComment(comment.referenceId, comment.commentId);
|
|
13982
|
+
};
|
|
13983
|
+
/**
|
|
13984
|
+
* Reveal: exactly one `ApproveTask`. The engine de-duplicates by comment id, so the approve
|
|
13985
|
+
* response and the `comment.approved` event may both call this. `ApproveTask` bypasses the age
|
|
13986
|
+
* guard on purpose — the comment was written before the last server sync but enters the public
|
|
13987
|
+
* count now — matching the iOS `ApproveTask` (plan 40 §9, guard off for approve).
|
|
13988
|
+
*/
|
|
13989
|
+
const applyCommentApprovedCount = (comment) => {
|
|
13990
|
+
if (!isCountedReference(comment))
|
|
13991
|
+
return;
|
|
13992
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ApproveTask(comment.referenceId, comment.commentId));
|
|
13993
|
+
};
|
|
13994
|
+
/**
|
|
13995
|
+
* Re-review: an approved comment edited back to pending leaves the public count once. The
|
|
13996
|
+
* author keeps their own +1 through the pending set, so their count does not move.
|
|
13997
|
+
*/
|
|
13998
|
+
const applyCommentReReviewCount = (comment) => {
|
|
13999
|
+
if (!isCountedReference(comment))
|
|
14000
|
+
return;
|
|
14001
|
+
recordPendingAuthoredComment(comment, { publish: false });
|
|
14002
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new DeleteTask(comment.referenceId, comment.commentId));
|
|
14003
|
+
};
|
|
14004
|
+
/** Adds a reply to its cached parent's `children` (and count) once. */
|
|
14005
|
+
const linkCommentToParent = (comment) => {
|
|
14006
|
+
var _a;
|
|
14007
|
+
if (!comment.parentId)
|
|
14008
|
+
return;
|
|
14009
|
+
const parentKey = ['comment', 'get', comment.parentId];
|
|
14010
|
+
const parent = (_a = pullFromCache(parentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14011
|
+
if (!parent || parent.children.includes(comment.commentId))
|
|
14012
|
+
return;
|
|
14013
|
+
pushToCache(parentKey, Object.assign(Object.assign({}, parent), { childrenNumber: parent.childrenNumber + 1, children: [...new Set([...parent.children, comment.commentId])] }));
|
|
14014
|
+
};
|
|
14015
|
+
/** Removes a reply from its cached parent's `children` (and count) once. */
|
|
14016
|
+
const unlinkCommentFromParent = (comment) => {
|
|
14017
|
+
var _a;
|
|
14018
|
+
if (!comment.parentId)
|
|
14019
|
+
return;
|
|
14020
|
+
const parentKey = ['comment', 'get', comment.parentId];
|
|
14021
|
+
const parent = (_a = pullFromCache(parentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
14022
|
+
if (!parent || !parent.children.includes(comment.commentId))
|
|
14023
|
+
return;
|
|
14024
|
+
pushToCache(parentKey, Object.assign(Object.assign({}, parent), { childrenNumber: parent.childrenNumber - 1, children: parent.children.filter(id => id !== comment.commentId) }));
|
|
14025
|
+
};
|
|
14026
|
+
|
|
14027
|
+
/**
|
|
14028
|
+
* The server's list is oldest → newest, so the newest ids are the last ones. Kept unique so the
|
|
14029
|
+
* create response, the local event and the realtime echo cannot each add the same comment.
|
|
14030
|
+
*/
|
|
14031
|
+
const capLatestCommentIds = (commentIds) => [...new Set(commentIds)].slice(-LATEST_COMMENTS_LIMIT);
|
|
14032
|
+
/** A comment belongs in the post preview only while it is cached, not deleted and public. */
|
|
14033
|
+
const isPreviewableComment = (comment) => comment !== undefined && !comment.isDeleted && isCommentApproved(comment);
|
|
14034
|
+
/** The post's preview list after one of the user's own top-level comments is created. */
|
|
14035
|
+
const appendLatestCommentId = (post, commentId) => { var _a; return capLatestCommentIds([...((_a = post.comments) !== null && _a !== void 0 ? _a : []), commentId]); };
|
|
14036
|
+
|
|
12996
14037
|
const postLinkedObject = (post) => {
|
|
12997
14038
|
return shallowClone(post, {
|
|
12998
14039
|
childrenPosts: post.children
|
|
@@ -13016,19 +14057,13 @@ const postLinkedObject = (post) => {
|
|
|
13016
14057
|
get latestComments() {
|
|
13017
14058
|
if (!post.comments)
|
|
13018
14059
|
return [];
|
|
13019
|
-
|
|
13020
|
-
|
|
13021
|
-
|
|
13022
|
-
|
|
13023
|
-
|
|
13024
|
-
|
|
13025
|
-
|
|
13026
|
-
])) === null || _a === void 0 ? void 0 : _a.data;
|
|
13027
|
-
if (!commentCached)
|
|
13028
|
-
return null;
|
|
13029
|
-
return commentLinkedObject(commentCached);
|
|
13030
|
-
})
|
|
13031
|
-
.filter(Boolean) || []);
|
|
14060
|
+
// Same rule as the server's own list and as iOS: deleted and non-public comments are
|
|
14061
|
+
// dropped first, then the newest LATEST_COMMENTS_LIMIT remain
|
|
14062
|
+
return post.comments
|
|
14063
|
+
.map(commentId => { var _a; return (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
14064
|
+
.filter(isPreviewableComment)
|
|
14065
|
+
.slice(-LATEST_COMMENTS_LIMIT)
|
|
14066
|
+
.map(commentLinkedObject);
|
|
13032
14067
|
},
|
|
13033
14068
|
get creator() {
|
|
13034
14069
|
// The id is checked for a value, not just for presence: a payload can
|
|
@@ -13041,6 +14076,15 @@ const postLinkedObject = (post) => {
|
|
|
13041
14076
|
return undefined;
|
|
13042
14077
|
return userLinkedObject(cacheData.data);
|
|
13043
14078
|
},
|
|
14079
|
+
getLocalCommentCount(includePending = false) {
|
|
14080
|
+
var _a;
|
|
14081
|
+
const engine = PostCommentCountEngine$1.getInstance();
|
|
14082
|
+
// Before any payload has seeded the engine for this post there is no tracker; the
|
|
14083
|
+
// post's own figure is the best answer then.
|
|
14084
|
+
return engine.hasTracker(post.postId)
|
|
14085
|
+
? engine.getLocalCommentCount(post.postId, includePending)
|
|
14086
|
+
: (_a = post.localCommentCount) !== null && _a !== void 0 ? _a : post.commentsCount;
|
|
14087
|
+
},
|
|
13044
14088
|
get targetCommunity() {
|
|
13045
14089
|
var _a;
|
|
13046
14090
|
if (!post.targetId)
|
|
@@ -13405,7 +14449,8 @@ const messageLinkedObject = (message) => {
|
|
|
13405
14449
|
},
|
|
13406
14450
|
get creator() {
|
|
13407
14451
|
var _a;
|
|
13408
|
-
|
|
14452
|
+
const creator = (_a = pullFromCache(['user', 'get', message.creatorId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
14453
|
+
return creator ? userLinkedObject(creator) : undefined;
|
|
13409
14454
|
}, markRead: () => markReadMessage(message), addReaction: (reactionName) => addReactionToMessage(reactionName, message), removeReaction: (reactionName) => removeReactionToMessage(reactionName, message) });
|
|
13410
14455
|
};
|
|
13411
14456
|
|
|
@@ -14066,6 +15111,22 @@ const eventLinkedObject = (event) => {
|
|
|
14066
15111
|
} });
|
|
14067
15112
|
};
|
|
14068
15113
|
|
|
15114
|
+
const curatedContentTopicLinkedObject = (topic) => {
|
|
15115
|
+
return shallowClone(topic, {
|
|
15116
|
+
analytics: {
|
|
15117
|
+
markAsViewed: () => {
|
|
15118
|
+
AnalyticsEngine$1.getInstance().markCuratedContentWidgetAsViewed(topic.topicId);
|
|
15119
|
+
},
|
|
15120
|
+
markPostAsViewed: (postId) => {
|
|
15121
|
+
AnalyticsEngine$1.getInstance().markCuratedContentPostAsViewed(postId, topic.topicId);
|
|
15122
|
+
},
|
|
15123
|
+
markPostClick: (postId) => {
|
|
15124
|
+
AnalyticsEngine$1.getInstance().markCuratedContentPostAsClicked(postId, topic.topicId);
|
|
15125
|
+
},
|
|
15126
|
+
},
|
|
15127
|
+
});
|
|
15128
|
+
};
|
|
15129
|
+
|
|
14069
15130
|
const LinkedObject = {
|
|
14070
15131
|
file: fileLinkedObject,
|
|
14071
15132
|
ad: adLinkedObject,
|
|
@@ -14090,6 +15151,7 @@ const LinkedObject = {
|
|
|
14090
15151
|
eventResponse: eventResponseLinkedObject,
|
|
14091
15152
|
product: productLinkedObject,
|
|
14092
15153
|
poll: pollLinkedObject,
|
|
15154
|
+
curatedContentTopic: curatedContentTopicLinkedObject,
|
|
14093
15155
|
};
|
|
14094
15156
|
|
|
14095
15157
|
/* begin_public_function
|
|
@@ -14212,18 +15274,18 @@ const buildFlagUserBody = (options) => {
|
|
|
14212
15274
|
/**
|
|
14213
15275
|
* ```js
|
|
14214
15276
|
* import { UserRepository } from '@amityco/ts-sdk'
|
|
15277
|
+
*
|
|
15278
|
+
* // Typeless report (supported).
|
|
14215
15279
|
* const flagged = await UserRepository.flagUser('userId')
|
|
14216
|
-
* const flaggedBehavior = await UserRepository.flagUser('userId', {
|
|
14217
|
-
* reportType: 'behavior',
|
|
14218
|
-
* reason: 'Harassment or bullying',
|
|
14219
|
-
* comment: 'optional free-text',
|
|
14220
|
-
* })
|
|
14221
15280
|
* ```
|
|
14222
15281
|
*
|
|
15282
|
+
* Flags a user. Two call shapes are accepted (see the overloads): id-only, which
|
|
15283
|
+
* sends no body and stays supported, and the deprecated structured options object,
|
|
15284
|
+
* whose request mapping is unchanged. New code reporting a profile field or behavior
|
|
15285
|
+
* should use `flagUserProfile` or `flagUserBehavior`.
|
|
15286
|
+
*
|
|
14223
15287
|
* @param userId The ID of the user to be flagged
|
|
14224
|
-
* @param options
|
|
14225
|
-
* body: `reportType`, `reason`, `comment`. Only non-null fields are included.
|
|
14226
|
-
* All validation is server-side; a bodyless call produces a typeless report.
|
|
15288
|
+
* @param options Deprecated report metadata; omit for a typeless report
|
|
14227
15289
|
* @returns the flagged {@link Amity.User}
|
|
14228
15290
|
*
|
|
14229
15291
|
* @category User API
|
|
@@ -14244,6 +15306,156 @@ const flagUser = async (userId, options) => {
|
|
|
14244
15306
|
};
|
|
14245
15307
|
/* end_public_function */
|
|
14246
15308
|
|
|
15309
|
+
/**
|
|
15310
|
+
* Sends a validated split user report (`flagUserProfile` / `flagUserBehavior`) to the
|
|
15311
|
+
* same endpoint as `flagUser`, then persists the returned user and fires `user.flagged`
|
|
15312
|
+
* exactly as `flagUser` does, so all three calls share return, cache and event behaviour.
|
|
15313
|
+
*
|
|
15314
|
+
* Not exported from the public API.
|
|
15315
|
+
*/
|
|
15316
|
+
const submitUserReport = async (apiName, userId, body) => {
|
|
15317
|
+
var _a;
|
|
15318
|
+
const client = getActiveClient();
|
|
15319
|
+
client.log(`user/${apiName}`, { userId, body });
|
|
15320
|
+
const { data } = await client.http.post(`/api/v4/me/flags/${encodeURIComponent(userId)}`, body);
|
|
15321
|
+
const payload = prepareUserPayload(data);
|
|
15322
|
+
if (client.cache) {
|
|
15323
|
+
ingestInCache(payload);
|
|
15324
|
+
}
|
|
15325
|
+
fireEvent('user.flagged', data);
|
|
15326
|
+
return (_a = payload.users.find(user => user.userId === userId)) !== null && _a !== void 0 ? _a : payload.users[0];
|
|
15327
|
+
};
|
|
15328
|
+
|
|
15329
|
+
/** Maximum `comment` length, in string length units, after trimming. */
|
|
15330
|
+
const USER_REPORT_COMMENT_MAX_LENGTH = 300;
|
|
15331
|
+
const PROFILE_FIELDS = Object.values(exports.UserProfileFieldEnum);
|
|
15332
|
+
const BEHAVIOR_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
15333
|
+
const assertOptionsObject = (apiName, options, shape) => {
|
|
15334
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
15335
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`${shape}\``);
|
|
15336
|
+
}
|
|
15337
|
+
return options;
|
|
15338
|
+
};
|
|
15339
|
+
/**
|
|
15340
|
+
* Normalizes an optional reporter `comment`: it must be a string when supplied (`null`
|
|
15341
|
+
* is not a valid supplied comment); it is trimmed; a blank result is omitted (the
|
|
15342
|
+
* backend rejects `""`); a result longer than 300 characters is rejected before any
|
|
15343
|
+
* request. Otherwise the trimmed text is returned unchanged.
|
|
15344
|
+
*
|
|
15345
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` for a non-string or over-length comment
|
|
15346
|
+
*/
|
|
15347
|
+
const normalizeUserReportComment = (apiName, comment) => {
|
|
15348
|
+
if (comment === undefined)
|
|
15349
|
+
return undefined;
|
|
15350
|
+
if (typeof comment !== 'string') {
|
|
15351
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be a string when supplied`);
|
|
15352
|
+
}
|
|
15353
|
+
const trimmed = comment.trim();
|
|
15354
|
+
if (trimmed.length === 0)
|
|
15355
|
+
return undefined;
|
|
15356
|
+
if (trimmed.length > USER_REPORT_COMMENT_MAX_LENGTH) {
|
|
15357
|
+
throw new ASCInvalidParameterError(`${apiName}: \`comment\` must be at most ${USER_REPORT_COMMENT_MAX_LENGTH} characters after trimming`);
|
|
15358
|
+
}
|
|
15359
|
+
return trimmed;
|
|
15360
|
+
};
|
|
15361
|
+
const withComment = (body, comment) => comment === undefined ? body : Object.assign(Object.assign({}, body), { comment });
|
|
15362
|
+
/**
|
|
15363
|
+
* Validates `flagUserProfile` options and builds its request body. Untyped callers can
|
|
15364
|
+
* pass anything at runtime, so nothing is trusted from the declared type. Any `reason`
|
|
15365
|
+
* key is ignored and never sent.
|
|
15366
|
+
*
|
|
15367
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
15368
|
+
*/
|
|
15369
|
+
const toUserProfileReportBody = (options) => {
|
|
15370
|
+
const apiName = 'flagUserProfile';
|
|
15371
|
+
const { field, comment } = assertOptionsObject(apiName, options, '{ field, comment? }');
|
|
15372
|
+
if (typeof field !== 'string' || !PROFILE_FIELDS.includes(field)) {
|
|
15373
|
+
throw new ASCInvalidParameterError(`${apiName}: \`field\` must be a \`UserProfileFieldEnum\` value`);
|
|
15374
|
+
}
|
|
15375
|
+
return withComment({ reportType: field }, normalizeUserReportComment(apiName, comment));
|
|
15376
|
+
};
|
|
15377
|
+
/**
|
|
15378
|
+
* Validates `flagUserBehavior` options and builds its request body. `reason` must be one
|
|
15379
|
+
* of the nine `ContentFlagReasonEnum` values and is sent as that canonical label;
|
|
15380
|
+
* `reportType` is always `behavior`.
|
|
15381
|
+
*
|
|
15382
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
15383
|
+
*/
|
|
15384
|
+
const toUserBehaviorReportBody = (options) => {
|
|
15385
|
+
const apiName = 'flagUserBehavior';
|
|
15386
|
+
const { reason, comment } = assertOptionsObject(apiName, options, '{ reason, comment? }');
|
|
15387
|
+
if (typeof reason !== 'string' || !BEHAVIOR_REASONS.includes(reason)) {
|
|
15388
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
15389
|
+
}
|
|
15390
|
+
return withComment({ reportType: 'behavior', reason }, normalizeUserReportComment(apiName, comment));
|
|
15391
|
+
};
|
|
15392
|
+
|
|
15393
|
+
/* begin_public_function
|
|
15394
|
+
id: user.flag_profile
|
|
15395
|
+
*/
|
|
15396
|
+
/**
|
|
15397
|
+
* ```js
|
|
15398
|
+
* import { UserRepository, UserProfileFieldEnum } from '@amityco/ts-sdk'
|
|
15399
|
+
* const flagged = await UserRepository.flagUserProfile('userId', {
|
|
15400
|
+
* field: UserProfileFieldEnum.AVATAR,
|
|
15401
|
+
* comment: 'Nudity in profile photo',
|
|
15402
|
+
* })
|
|
15403
|
+
* ```
|
|
15404
|
+
*
|
|
15405
|
+
* Reports one of a user's profile fields (display name, description or avatar). The
|
|
15406
|
+
* call has no reason: profile reports never carry one, so the backend's reason rules
|
|
15407
|
+
* cannot be violated from here. A `reason` key passed at runtime is ignored and never sent.
|
|
15408
|
+
*
|
|
15409
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
15410
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
15411
|
+
* trimmed text is sent unchanged.
|
|
15412
|
+
*
|
|
15413
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: <field>, comment? }`.
|
|
15414
|
+
*
|
|
15415
|
+
* @param userId The ID of the user to be reported
|
|
15416
|
+
* @param options `field` is a `UserProfileFieldEnum` value; `comment` is optional free text
|
|
15417
|
+
* @returns the flagged {@link Amity.User}
|
|
15418
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, or `comment` is over 300 characters, before any request is made
|
|
15419
|
+
*
|
|
15420
|
+
* @category User API
|
|
15421
|
+
* @async
|
|
15422
|
+
* */
|
|
15423
|
+
const flagUserProfile = async (userId, options) => submitUserReport('flagUserProfile', userId, toUserProfileReportBody(options));
|
|
15424
|
+
/* end_public_function */
|
|
15425
|
+
|
|
15426
|
+
/* begin_public_function
|
|
15427
|
+
id: user.flag_behavior
|
|
15428
|
+
*/
|
|
15429
|
+
/**
|
|
15430
|
+
* ```js
|
|
15431
|
+
* import { UserRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
15432
|
+
* const flagged = await UserRepository.flagUserBehavior('userId', {
|
|
15433
|
+
* reason: ContentFlagReasonEnum.Others,
|
|
15434
|
+
* comment: 'Impersonating our brand',
|
|
15435
|
+
* })
|
|
15436
|
+
* ```
|
|
15437
|
+
*
|
|
15438
|
+
* Reports a user's behavior. `reason` is required and is one of the nine
|
|
15439
|
+
* `ContentFlagReasonEnum` values, sent as its canonical label. Reporter text, including
|
|
15440
|
+
* the explanation for `Others`, always travels in `comment`; the reason never carries text.
|
|
15441
|
+
*
|
|
15442
|
+
* `comment` is trimmed; a blank comment is omitted from the request; a comment longer
|
|
15443
|
+
* than 300 characters after trimming is rejected before any request. Otherwise the
|
|
15444
|
+
* trimmed text is sent unchanged.
|
|
15445
|
+
*
|
|
15446
|
+
* Sends `POST /api/v4/me/flags/:userId` with `{ reportType: 'behavior', reason, comment? }`.
|
|
15447
|
+
*
|
|
15448
|
+
* @param userId The ID of the user to be reported
|
|
15449
|
+
* @param options `reason` is a `ContentFlagReasonEnum` value; `comment` is optional free text
|
|
15450
|
+
* @returns the flagged {@link Amity.User}
|
|
15451
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is missing or malformed, `reason` is missing or unknown, or `comment` is over 300 characters, before any request is made
|
|
15452
|
+
*
|
|
15453
|
+
* @category User API
|
|
15454
|
+
* @async
|
|
15455
|
+
* */
|
|
15456
|
+
const flagUserBehavior = async (userId, options) => submitUserReport('flagUserBehavior', userId, toUserBehaviorReportBody(options));
|
|
15457
|
+
/* end_public_function */
|
|
15458
|
+
|
|
14247
15459
|
/* begin_public_function
|
|
14248
15460
|
id: user.unflag
|
|
14249
15461
|
*/
|
|
@@ -15412,12 +16624,14 @@ var AmityUserSearchMatchType;
|
|
|
15412
16624
|
AmityUserSearchMatchType["PARTIAL"] = "partial";
|
|
15413
16625
|
})(AmityUserSearchMatchType || (AmityUserSearchMatchType = {}));
|
|
15414
16626
|
|
|
15415
|
-
var index$
|
|
16627
|
+
var index$r = /*#__PURE__*/Object.freeze({
|
|
15416
16628
|
__proto__: null,
|
|
15417
|
-
Relationship: index$
|
|
16629
|
+
Relationship: index$s,
|
|
15418
16630
|
getUserByIds: getUserByIds,
|
|
15419
16631
|
updateUser: updateUser,
|
|
15420
16632
|
flagUser: flagUser,
|
|
16633
|
+
flagUserProfile: flagUserProfile,
|
|
16634
|
+
flagUserBehavior: flagUserBehavior,
|
|
15421
16635
|
unflagUser: unflagUser,
|
|
15422
16636
|
isUserFlaggedByMe: isUserFlaggedByMe,
|
|
15423
16637
|
getAllBlockedUsers: getAllBlockedUsers,
|
|
@@ -15822,7 +17036,7 @@ const uploadAudio = async (formData, onProgress) => {
|
|
|
15822
17036
|
};
|
|
15823
17037
|
/* end_public_function */
|
|
15824
17038
|
|
|
15825
|
-
var index$
|
|
17039
|
+
var index$q = /*#__PURE__*/Object.freeze({
|
|
15826
17040
|
__proto__: null,
|
|
15827
17041
|
getFile: getFile,
|
|
15828
17042
|
uploadFile: uploadFile,
|
|
@@ -16015,147 +17229,6 @@ getMessage$1.locally = (messageId) => {
|
|
|
16015
17229
|
};
|
|
16016
17230
|
};
|
|
16017
17231
|
|
|
16018
|
-
class ResetTask {
|
|
16019
|
-
constructor(postId, latestCreatedAt, serverCommentCount) {
|
|
16020
|
-
this.postId = postId;
|
|
16021
|
-
this.latestCreatedAt = latestCreatedAt;
|
|
16022
|
-
this.serverCommentCount = serverCommentCount;
|
|
16023
|
-
}
|
|
16024
|
-
}
|
|
16025
|
-
|
|
16026
|
-
// Task to track comment creation
|
|
16027
|
-
class CreateTask {
|
|
16028
|
-
constructor(postId, commentId, createdAt) {
|
|
16029
|
-
this.postId = postId;
|
|
16030
|
-
this.commentId = commentId;
|
|
16031
|
-
this.createdAt = createdAt;
|
|
16032
|
-
}
|
|
16033
|
-
}
|
|
16034
|
-
|
|
16035
|
-
// Task to track comment deletion
|
|
16036
|
-
class DeleteTask {
|
|
16037
|
-
constructor(postId, commentId) {
|
|
16038
|
-
this.postId = postId;
|
|
16039
|
-
this.commentId = commentId;
|
|
16040
|
-
}
|
|
16041
|
-
}
|
|
16042
|
-
|
|
16043
|
-
class CommentChange {
|
|
16044
|
-
constructor(latestCreatedAt, serverCommentCount) {
|
|
16045
|
-
this.latestCommentCreatedAt = latestCreatedAt;
|
|
16046
|
-
this.serverCommentCount = serverCommentCount;
|
|
16047
|
-
this.createdCommentIds = new Set();
|
|
16048
|
-
this.deletedCommentIds = new Set();
|
|
16049
|
-
}
|
|
16050
|
-
}
|
|
16051
|
-
|
|
16052
|
-
class PostCommentCountEngine {
|
|
16053
|
-
constructor() {
|
|
16054
|
-
this.isProcessing = false;
|
|
16055
|
-
this.tasks = [];
|
|
16056
|
-
this.commentChangeTracker = new Map();
|
|
16057
|
-
}
|
|
16058
|
-
queueCommentChangeTask(task) {
|
|
16059
|
-
this.tasks.push(task);
|
|
16060
|
-
if (!this.isProcessing) {
|
|
16061
|
-
this.processCommentChangeTask();
|
|
16062
|
-
}
|
|
16063
|
-
}
|
|
16064
|
-
processCommentChangeTask() {
|
|
16065
|
-
if (this.isProcessing) {
|
|
16066
|
-
return;
|
|
16067
|
-
}
|
|
16068
|
-
this.isProcessing = true;
|
|
16069
|
-
if (this.tasks.length === 0) {
|
|
16070
|
-
this.isProcessing = false;
|
|
16071
|
-
return;
|
|
16072
|
-
}
|
|
16073
|
-
// Process in capped batches, coalescing updates
|
|
16074
|
-
const batch = this.tasks.splice(0, PostCommentCountEngine.BATCH_SIZE);
|
|
16075
|
-
const modifiedPostIds = new Set();
|
|
16076
|
-
batch.forEach(task => {
|
|
16077
|
-
let modified = false;
|
|
16078
|
-
if (task instanceof ResetTask) {
|
|
16079
|
-
modified = this.processResetTaskInternal(task);
|
|
16080
|
-
}
|
|
16081
|
-
else if (task instanceof CreateTask) {
|
|
16082
|
-
modified = this.processCreateTaskInternal(task);
|
|
16083
|
-
}
|
|
16084
|
-
else if (task instanceof DeleteTask) {
|
|
16085
|
-
modified = this.processDeleteTaskInternal(task);
|
|
16086
|
-
}
|
|
16087
|
-
if (modified) {
|
|
16088
|
-
modifiedPostIds.add(task.postId);
|
|
16089
|
-
}
|
|
16090
|
-
});
|
|
16091
|
-
// Publish one update per modified post
|
|
16092
|
-
modifiedPostIds.forEach(postId => {
|
|
16093
|
-
const count = this.computeCommentCount(postId);
|
|
16094
|
-
PostCommentCountEngine.publishUpdate(postId, count);
|
|
16095
|
-
});
|
|
16096
|
-
this.isProcessing = false;
|
|
16097
|
-
// Recurse if more tasks remain
|
|
16098
|
-
if (this.tasks.length > 0) {
|
|
16099
|
-
this.processCommentChangeTask();
|
|
16100
|
-
}
|
|
16101
|
-
}
|
|
16102
|
-
processResetTaskInternal(task) {
|
|
16103
|
-
// Always creates/overwrites tracker
|
|
16104
|
-
this.commentChangeTracker.set(task.postId, new CommentChange(task.latestCreatedAt, task.serverCommentCount));
|
|
16105
|
-
return true;
|
|
16106
|
-
}
|
|
16107
|
-
processCreateTaskInternal(task) {
|
|
16108
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
16109
|
-
if (!tracker)
|
|
16110
|
-
return false; // No tracker, skip
|
|
16111
|
-
if (tracker.createdCommentIds.has(task.commentId))
|
|
16112
|
-
return false; // Deduplication
|
|
16113
|
-
if (task.createdAt <= tracker.latestCommentCreatedAt)
|
|
16114
|
-
return false; // Timestamp filtering
|
|
16115
|
-
tracker.createdCommentIds.add(task.commentId);
|
|
16116
|
-
return true;
|
|
16117
|
-
}
|
|
16118
|
-
processDeleteTaskInternal(task) {
|
|
16119
|
-
const tracker = this.commentChangeTracker.get(task.postId);
|
|
16120
|
-
if (!tracker)
|
|
16121
|
-
return false; // No tracker, skip
|
|
16122
|
-
if (tracker.deletedCommentIds.has(task.commentId))
|
|
16123
|
-
return false; // Deduplication
|
|
16124
|
-
tracker.deletedCommentIds.add(task.commentId);
|
|
16125
|
-
return true;
|
|
16126
|
-
}
|
|
16127
|
-
computeCommentCount(postId) {
|
|
16128
|
-
const tracker = this.commentChangeTracker.get(postId);
|
|
16129
|
-
if (!tracker)
|
|
16130
|
-
return 0;
|
|
16131
|
-
const count = tracker.serverCommentCount + tracker.createdCommentIds.size - tracker.deletedCommentIds.size;
|
|
16132
|
-
return Math.max(0, count);
|
|
16133
|
-
}
|
|
16134
|
-
static publishUpdate(postId, newCount) {
|
|
16135
|
-
var _a;
|
|
16136
|
-
const queryKey = ['post', 'get', postId];
|
|
16137
|
-
mergeInCache(queryKey, {
|
|
16138
|
-
localCommentCount: newCount,
|
|
16139
|
-
});
|
|
16140
|
-
const postPayload = (_a = pullFromCache(queryKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
16141
|
-
if (!postPayload)
|
|
16142
|
-
return;
|
|
16143
|
-
fireEvent('local.post.updated', {
|
|
16144
|
-
posts: [postPayload],
|
|
16145
|
-
});
|
|
16146
|
-
}
|
|
16147
|
-
}
|
|
16148
|
-
PostCommentCountEngine.BATCH_SIZE = 50;
|
|
16149
|
-
let instance;
|
|
16150
|
-
var PostCommentCountEngine$1 = {
|
|
16151
|
-
getInstance: () => {
|
|
16152
|
-
if (!instance) {
|
|
16153
|
-
instance = new PostCommentCountEngine();
|
|
16154
|
-
}
|
|
16155
|
-
return instance;
|
|
16156
|
-
},
|
|
16157
|
-
};
|
|
16158
|
-
|
|
16159
17232
|
const updateStreamReferences = (streams, streamId, postId) => {
|
|
16160
17233
|
if (!streamId)
|
|
16161
17234
|
return streams;
|
|
@@ -16175,7 +17248,7 @@ const preparePostPayload = (payload) => {
|
|
|
16175
17248
|
let mappedNewStream = [];
|
|
16176
17249
|
// feed type
|
|
16177
17250
|
const posts = postsData.map(post => {
|
|
16178
|
-
var _a, _b, _c
|
|
17251
|
+
var _a, _b, _c;
|
|
16179
17252
|
const feedType = (_a = postPayload.feeds.find(feed => feed.feedId === post.feedId)) === null || _a === void 0 ? void 0 : _a.feedType;
|
|
16180
17253
|
const childPosts = payload.postChildren.filter(children => children.parentPostId === post.postId);
|
|
16181
17254
|
if (childPosts.length > 0 && isAmityLivestreamPost(childPosts[0])) {
|
|
@@ -16194,7 +17267,11 @@ const preparePostPayload = (payload) => {
|
|
|
16194
17267
|
// Queue ResetTask for this post
|
|
16195
17268
|
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new ResetTask(post.postId, latestCreatedAt, (_c = post.commentsCount) !== null && _c !== void 0 ? _c : 0));
|
|
16196
17269
|
return Object.assign(Object.assign({}, post), { childPosts,
|
|
16197
|
-
feedType,
|
|
17270
|
+
feedType,
|
|
17271
|
+
// The ResetTask above has just seeded the engine, so this is the server figure plus the
|
|
17272
|
+
// author's own pending comments. Reading `post.commentsCount` here instead would overwrite
|
|
17273
|
+
// that +1 in the cache on every refresh, since the ingest that follows merges this object.
|
|
17274
|
+
localCommentCount: PostCommentCountEngine$1.getInstance().getLocalCommentCount(post.postId, true), pinnedProductId: post === null || post === void 0 ? void 0 : post.pinnedProductId });
|
|
16198
17275
|
});
|
|
16199
17276
|
return Object.assign(Object.assign({}, postPayload), { postChildren, videoStreamings: mappedNewStream, posts, communities: communityWithMembershipStatus, communityUsers: mappedCommunityUsers });
|
|
16200
17277
|
};
|
|
@@ -16947,62 +18024,67 @@ const onPostReactionRemoved = (callback) => {
|
|
|
16947
18024
|
return createEventSubscriber(client, 'post.removeReaction', 'post.removeReaction', filter);
|
|
16948
18025
|
};
|
|
16949
18026
|
|
|
18027
|
+
/**
|
|
18028
|
+
* `comment.created` fires while a comment is still pending, so delivery is not visibility. The
|
|
18029
|
+
* two side effects that make a comment public — the parent link that feeds the reply list and
|
|
18030
|
+
* the comment-count task — are gated here; `comment.approved` is the only reveal signal, and a
|
|
18031
|
+
* decline arrives as `comment.deleted`.
|
|
18032
|
+
*/
|
|
18033
|
+
const applyApprovalSideEffects = (event, comment, previous) => {
|
|
18034
|
+
switch (event) {
|
|
18035
|
+
case 'comment.created':
|
|
18036
|
+
if (isCommentPending(comment)) {
|
|
18037
|
+
recordPendingAuthoredComment(comment);
|
|
18038
|
+
}
|
|
18039
|
+
else {
|
|
18040
|
+
linkCommentToParent(comment);
|
|
18041
|
+
applyCommentCreatedCount(comment);
|
|
18042
|
+
}
|
|
18043
|
+
break;
|
|
18044
|
+
case 'comment.approved':
|
|
18045
|
+
linkCommentToParent(comment);
|
|
18046
|
+
applyCommentApprovedCount(comment);
|
|
18047
|
+
break;
|
|
18048
|
+
case 'comment.updated':
|
|
18049
|
+
// An effective edit in a gated community sends an approved comment back for review
|
|
18050
|
+
if (isCommentPending(comment) && previous && isCommentApproved(previous)) {
|
|
18051
|
+
unlinkCommentFromParent(comment);
|
|
18052
|
+
applyCommentReReviewCount(comment);
|
|
18053
|
+
}
|
|
18054
|
+
break;
|
|
18055
|
+
case 'comment.deleted':
|
|
18056
|
+
unlinkCommentFromParent(comment);
|
|
18057
|
+
// A pending comment was never counted, so its deletion (or decline) moves no count
|
|
18058
|
+
if (previous && isCommentPending(previous))
|
|
18059
|
+
releasePendingAuthoredComment(comment);
|
|
18060
|
+
break;
|
|
18061
|
+
}
|
|
18062
|
+
};
|
|
16950
18063
|
const createCommentEventSubscriber = (event, callback) => {
|
|
16951
18064
|
const client = getActiveClient();
|
|
16952
18065
|
const filter = (payload) => {
|
|
16953
|
-
var _a;
|
|
18066
|
+
var _a, _b;
|
|
16954
18067
|
if (!client.cache) {
|
|
16955
18068
|
// TODO: here we are missing specific properties here!
|
|
16956
18069
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
16957
18070
|
}
|
|
16958
18071
|
else {
|
|
16959
|
-
const
|
|
18072
|
+
const flagged = ['comment.flagged', 'comment.unflagged'].includes(event)
|
|
16960
18073
|
? prepareCommentFromFlaggedEvent(payload)
|
|
16961
18074
|
: payload;
|
|
16962
|
-
//
|
|
16963
|
-
|
|
18075
|
+
// Resolve `approvalStatus` before the merge: an absent value means approved and has to
|
|
18076
|
+
// overwrite a cached `pending`, which a plain merge would leave in place.
|
|
18077
|
+
const processed = prepareCommentPayload(flagged);
|
|
16964
18078
|
const { comments } = processed;
|
|
16965
18079
|
if (comments.length > 0) {
|
|
16966
|
-
const
|
|
16967
|
-
|
|
16968
|
-
|
|
16969
|
-
|
|
16970
|
-
|
|
16971
|
-
|
|
16972
|
-
if (comments[0].parentId) {
|
|
16973
|
-
const parentComment = pullFromCache([
|
|
16974
|
-
'comment',
|
|
16975
|
-
'get',
|
|
16976
|
-
comments[0].parentId,
|
|
16977
|
-
]);
|
|
16978
|
-
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
16979
|
-
// Skip to update parent childComment if current comment already exists
|
|
16980
|
-
if (!parentComment.data.children.includes(comments[0].commentId)) {
|
|
16981
|
-
pushToCache(['comment', 'get', comments[0].parentId], Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber + 1, children: [...new Set([...parentComment.data.children, comments[0].commentId])] }));
|
|
16982
|
-
}
|
|
16983
|
-
}
|
|
16984
|
-
}
|
|
16985
|
-
}
|
|
18080
|
+
const commentKey = ['comment', 'get', comments[0].commentId];
|
|
18081
|
+
const previous = (_a = pullFromCache(commentKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
18082
|
+
// NOTE: The event data should be merge with existing cache rather than replace it
|
|
18083
|
+
ingestInCache(processed, undefined, false);
|
|
18084
|
+
const comment = pullFromCache(commentKey);
|
|
18085
|
+
applyApprovalSideEffects(event, comment.data, previous);
|
|
16986
18086
|
if (['comment.deleted'].includes(event)) {
|
|
16987
|
-
|
|
16988
|
-
const parentComment = pullFromCache([
|
|
16989
|
-
'comment',
|
|
16990
|
-
'get',
|
|
16991
|
-
comments[0].parentId,
|
|
16992
|
-
]);
|
|
16993
|
-
if (parentComment === null || parentComment === void 0 ? void 0 : parentComment.data) {
|
|
16994
|
-
// Remove deleted comment in parent childComment if still exists
|
|
16995
|
-
if (parentComment.data.children.includes(comments[0].commentId)) {
|
|
16996
|
-
const newParentComment = Object.assign(Object.assign({}, parentComment.data), { childrenNumber: parentComment.data.childrenNumber - 1, children: [
|
|
16997
|
-
...new Set([
|
|
16998
|
-
...parentComment.data.children.filter(id => id !== comments[0].commentId),
|
|
16999
|
-
]),
|
|
17000
|
-
] });
|
|
17001
|
-
pushToCache(['comment', 'get', comments[0].parentId], newParentComment);
|
|
17002
|
-
}
|
|
17003
|
-
}
|
|
17004
|
-
}
|
|
17005
|
-
const queries = (_a = queryCache(['comment', 'query'])) === null || _a === void 0 ? void 0 : _a.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
18087
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17006
18088
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17007
18089
|
}
|
|
17008
18090
|
callback(LinkedObject.comment(comment.data));
|
|
@@ -17014,13 +18096,13 @@ const createCommentEventSubscriber = (event, callback) => {
|
|
|
17014
18096
|
const createLocalCommentEventSubscriber = (event, callback) => {
|
|
17015
18097
|
const client = getActiveClient();
|
|
17016
18098
|
const filter = (payload) => {
|
|
17017
|
-
var _a, _b, _c, _d
|
|
18099
|
+
var _a, _b, _c, _d;
|
|
17018
18100
|
if (!client.cache) {
|
|
17019
18101
|
// TODO: here we are missing specific properties here!
|
|
17020
18102
|
callback(LinkedObject.comment(payload.comments[0]));
|
|
17021
18103
|
}
|
|
17022
18104
|
else {
|
|
17023
|
-
const processed = payload;
|
|
18105
|
+
const processed = prepareCommentPayload(payload);
|
|
17024
18106
|
ingestInCache(processed);
|
|
17025
18107
|
const { comments } = processed;
|
|
17026
18108
|
if (comments.length > 0) {
|
|
@@ -17029,7 +18111,9 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17029
18111
|
'get',
|
|
17030
18112
|
comments[0].commentId,
|
|
17031
18113
|
]);
|
|
17032
|
-
|
|
18114
|
+
// A pending comment is persisted for its author but never linked into the public
|
|
18115
|
+
// surfaces (parent reply list, post comment list)
|
|
18116
|
+
if (['local.comment.created'].includes(event) && isCommentApproved(comments[0])) {
|
|
17033
18117
|
if (comments[0].parentId) {
|
|
17034
18118
|
const parentComment = pullFromCache([
|
|
17035
18119
|
'comment',
|
|
@@ -17058,11 +18142,11 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17058
18142
|
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
17059
18143
|
const postCache = (_a = pullFromCache(postCacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
17060
18144
|
if (postCache) {
|
|
17061
|
-
const updatedPostCache = Object.assign(Object.assign({}, postCache), { comments:
|
|
18145
|
+
const updatedPostCache = Object.assign(Object.assign({}, postCache), { comments: appendLatestCommentId(postCache, comments[0].commentId) });
|
|
17062
18146
|
pushToCache(postCacheKey, updatedPostCache);
|
|
17063
18147
|
}
|
|
17064
18148
|
}
|
|
17065
|
-
const queries = (
|
|
18149
|
+
const queries = (_b = queryCache(['comment', 'query'])) === null || _b === void 0 ? void 0 : _b.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17066
18150
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17067
18151
|
}
|
|
17068
18152
|
if (['local.comment.deleted'].includes(event)) {
|
|
@@ -17096,13 +18180,13 @@ const createLocalCommentEventSubscriber = (event, callback) => {
|
|
|
17096
18180
|
}
|
|
17097
18181
|
else {
|
|
17098
18182
|
const postCacheKey = ['post', 'get', comments[0].referenceId];
|
|
17099
|
-
const postCache = (
|
|
18183
|
+
const postCache = (_c = pullFromCache(postCacheKey)) === null || _c === void 0 ? void 0 : _c.data;
|
|
17100
18184
|
if (postCache) {
|
|
17101
18185
|
const updatedPost = Object.assign(Object.assign({}, postCache), { comments: postCache === null || postCache === void 0 ? void 0 : postCache.comments.filter(commentId => { var _a; return commentId !== ((_a = comments[0]) === null || _a === void 0 ? void 0 : _a.commentId); }) });
|
|
17102
18186
|
pushToCache(postCacheKey, updatedPost);
|
|
17103
18187
|
}
|
|
17104
18188
|
}
|
|
17105
|
-
const queries = (
|
|
18189
|
+
const queries = (_d = queryCache(['comment', 'query'])) === null || _d === void 0 ? void 0 : _d.filter(({ key }) => { var _a; return ((_a = key[2]) === null || _a === void 0 ? void 0 : _a.referenceId) === comment.data.referenceId; });
|
|
17106
18190
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
17107
18191
|
}
|
|
17108
18192
|
callback(LinkedObject.comment(comment.data));
|
|
@@ -17163,6 +18247,23 @@ const onCommentUpdated = (callback) => createCommentEventSubscriber('comment.upd
|
|
|
17163
18247
|
*/
|
|
17164
18248
|
const onCommentDeleted = (callback) => createCommentEventSubscriber('comment.deleted', callback);
|
|
17165
18249
|
|
|
18250
|
+
/**
|
|
18251
|
+
* ```js
|
|
18252
|
+
* import { onCommentApproved } from '@amityco/ts-sdk'
|
|
18253
|
+
* const dispose = onCommentApproved(comment => {
|
|
18254
|
+
* // ...
|
|
18255
|
+
* })
|
|
18256
|
+
* ```
|
|
18257
|
+
*
|
|
18258
|
+
* Fired when a {@link Amity.InternalComment} held for review has been approved
|
|
18259
|
+
*
|
|
18260
|
+
* @param callback The function to call when the event was fired
|
|
18261
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18262
|
+
*
|
|
18263
|
+
* @category Comment Events
|
|
18264
|
+
*/
|
|
18265
|
+
const onCommentApproved = (callback) => createCommentEventSubscriber('comment.approved', callback);
|
|
18266
|
+
|
|
17166
18267
|
/**
|
|
17167
18268
|
* ```js
|
|
17168
18269
|
* import { onCommentFlagged } from '@amityco/ts-sdk'
|
|
@@ -17795,7 +18896,7 @@ const getReactions$1 = (params, callback, config) => {
|
|
|
17795
18896
|
};
|
|
17796
18897
|
/* end_public_function */
|
|
17797
18898
|
|
|
17798
|
-
var index$
|
|
18899
|
+
var index$p = /*#__PURE__*/Object.freeze({
|
|
17799
18900
|
__proto__: null,
|
|
17800
18901
|
addReaction: addReaction,
|
|
17801
18902
|
removeReaction: removeReaction,
|
|
@@ -17806,17 +18907,6 @@ var index$o = /*#__PURE__*/Object.freeze({
|
|
|
17806
18907
|
getReactions: getReactions$1
|
|
17807
18908
|
});
|
|
17808
18909
|
|
|
17809
|
-
function prepareCommentPayload(commentPayload) {
|
|
17810
|
-
const { comments } = commentPayload;
|
|
17811
|
-
return Object.assign(Object.assign({}, commentPayload), { comments: comments.map(comment => {
|
|
17812
|
-
if (comment.hasOwnProperty('myReactions'))
|
|
17813
|
-
return comment;
|
|
17814
|
-
// Sometimes `myReactions` field will not come with BE response because that field is empty
|
|
17815
|
-
// We need to put it with an empty array manually to make it show up in client side
|
|
17816
|
-
return Object.assign({ myReactions: [] }, comment);
|
|
17817
|
-
}) });
|
|
17818
|
-
}
|
|
17819
|
-
|
|
17820
18910
|
const createMessageReport = async ({ client, referenceId, }) => {
|
|
17821
18911
|
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(referenceId)}/flags`);
|
|
17822
18912
|
if (client.cache) {
|
|
@@ -18280,20 +19370,20 @@ const getArchivedChannelIds = async () => {
|
|
|
18280
19370
|
|
|
18281
19371
|
/**
|
|
18282
19372
|
* ```js
|
|
18283
|
-
* import {
|
|
18284
|
-
* const dispose =
|
|
19373
|
+
* import { onMessageDeleted } from '@amityco/ts-sdk'
|
|
19374
|
+
* const dispose = onMessageDeleted(message => {
|
|
18285
19375
|
* // ...
|
|
18286
19376
|
* })
|
|
18287
19377
|
* ```
|
|
18288
19378
|
*
|
|
18289
|
-
* Fired when an {@link Amity.Message}
|
|
19379
|
+
* Fired when an {@link Amity.Message} was deleted
|
|
18290
19380
|
*
|
|
18291
19381
|
* @param callback The function to call when the event was fired
|
|
18292
19382
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18293
19383
|
*
|
|
18294
19384
|
* @category Message Events
|
|
18295
19385
|
*/
|
|
18296
|
-
const
|
|
19386
|
+
const onMessageDeleted = (callback) => {
|
|
18297
19387
|
const client = getActiveClient();
|
|
18298
19388
|
const filter = async (rawPayload) => {
|
|
18299
19389
|
const payload = await prepareMessagePayload(rawPayload);
|
|
@@ -18301,30 +19391,48 @@ const onMessageUpdated = (callback) => {
|
|
|
18301
19391
|
callback(payload.messages[0]);
|
|
18302
19392
|
};
|
|
18303
19393
|
const disposers = [
|
|
18304
|
-
createEventSubscriber(client, '
|
|
18305
|
-
createEventSubscriber(client, '
|
|
19394
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'message.deleted', filter),
|
|
19395
|
+
createEventSubscriber(client, 'message/onMessageDeleted', 'local.message.deleted', payload => callback(payload.messages[0])),
|
|
18306
19396
|
];
|
|
18307
19397
|
return () => {
|
|
18308
19398
|
disposers.forEach(fn => fn());
|
|
18309
19399
|
};
|
|
18310
19400
|
};
|
|
18311
19401
|
|
|
19402
|
+
/**
|
|
19403
|
+
* Defensive clear of `channel.pinnedMessage` when the pinned message itself is deleted.
|
|
19404
|
+
*
|
|
19405
|
+
* The server also emits `channel.messageUnpinned` in this case, but realtime events are
|
|
19406
|
+
* fire-and-forget and their order is not guaranteed. Clearing on `message.deleted`
|
|
19407
|
+
* (MQTT or local) makes the banner disappear even if the unpin event is lost; the
|
|
19408
|
+
* server's own `messageUnpinned` then becomes a no-op.
|
|
19409
|
+
*
|
|
19410
|
+
* Internal — wired into the `getChannel` live object; not exported publicly.
|
|
19411
|
+
*/
|
|
19412
|
+
const onChannelPinnedMessageDeleted = (callback) => onMessageDeleted(message => {
|
|
19413
|
+
var _a;
|
|
19414
|
+
const channel = findCachedChannelByAnyId(message.channelId);
|
|
19415
|
+
if (!channel || ((_a = channel.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) !== message.messageId)
|
|
19416
|
+
return;
|
|
19417
|
+
callback(updatePinnedMessageCache(channel, null));
|
|
19418
|
+
});
|
|
19419
|
+
|
|
18312
19420
|
/**
|
|
18313
19421
|
* ```js
|
|
18314
|
-
* import {
|
|
18315
|
-
* const dispose =
|
|
19422
|
+
* import { onMessageUpdated } from '@amityco/ts-sdk'
|
|
19423
|
+
* const dispose = onMessageUpdated(message => {
|
|
18316
19424
|
* // ...
|
|
18317
19425
|
* })
|
|
18318
19426
|
* ```
|
|
18319
19427
|
*
|
|
18320
|
-
* Fired when an {@link Amity.Message}
|
|
19428
|
+
* Fired when an {@link Amity.Message} has been updated
|
|
18321
19429
|
*
|
|
18322
19430
|
* @param callback The function to call when the event was fired
|
|
18323
19431
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
18324
19432
|
*
|
|
18325
19433
|
* @category Message Events
|
|
18326
19434
|
*/
|
|
18327
|
-
const
|
|
19435
|
+
const onMessageUpdated = (callback) => {
|
|
18328
19436
|
const client = getActiveClient();
|
|
18329
19437
|
const filter = async (rawPayload) => {
|
|
18330
19438
|
const payload = await prepareMessagePayload(rawPayload);
|
|
@@ -18332,8 +19440,8 @@ const onMessageDeleted = (callback) => {
|
|
|
18332
19440
|
callback(payload.messages[0]);
|
|
18333
19441
|
};
|
|
18334
19442
|
const disposers = [
|
|
18335
|
-
createEventSubscriber(client, '
|
|
18336
|
-
createEventSubscriber(client, '
|
|
19443
|
+
createEventSubscriber(client, 'onMessageUpdated', 'message.updated', filter),
|
|
19444
|
+
createEventSubscriber(client, 'onMessageUpdated', 'local.message.updated', payload => callback(payload.messages[0])),
|
|
18337
19445
|
];
|
|
18338
19446
|
return () => {
|
|
18339
19447
|
disposers.forEach(fn => fn());
|
|
@@ -18914,6 +20022,132 @@ softDeleteMessage.optimistically = (messageId) => {
|
|
|
18914
20022
|
};
|
|
18915
20023
|
/* end_public_function */
|
|
18916
20024
|
|
|
20025
|
+
/**
|
|
20026
|
+
* Fire-and-forget refresh of `channelUsers[...].permissions` for the channel a
|
|
20027
|
+
* message belongs to. Used by `pinMessage` / `unpinMessage` on `403` so the next
|
|
20028
|
+
* `hasPermission(PIN_MESSAGE).channel(channelId)` reflects a revoked role
|
|
20029
|
+
* ([`pinMessage` REQ-010](../../@types/../..) / [`unpinMessage` REQ-008](../../@types/../..)).
|
|
20030
|
+
*
|
|
20031
|
+
* The API only receives a `messageId`, so the channel is resolved through the
|
|
20032
|
+
* local cache: first the message row, then any cached channel whose current pin
|
|
20033
|
+
* is that message. When nothing matches the refresh is skipped — the next
|
|
20034
|
+
* channel read picks up the fresh permissions anyway.
|
|
20035
|
+
*/
|
|
20036
|
+
const refreshChannelPermissionsForMessage = (messageId) => {
|
|
20037
|
+
var _a, _b, _c;
|
|
20038
|
+
const cachedMessage = (_a = getMessage$1.locally(messageId)) === null || _a === void 0 ? void 0 : _a.data;
|
|
20039
|
+
let channelId = cachedMessage === null || cachedMessage === void 0 ? void 0 : cachedMessage.channelId;
|
|
20040
|
+
if (!channelId) {
|
|
20041
|
+
channelId = (_c = (_b = queryCache(['channel', 'get'])) === null || _b === void 0 ? void 0 : _b.find(({ data }) => { var _a; return ((_a = data.pinnedMessage) === null || _a === void 0 ? void 0 : _a.messageId) === messageId; })) === null || _c === void 0 ? void 0 : _c.data.channelId;
|
|
20042
|
+
}
|
|
20043
|
+
if (!channelId)
|
|
20044
|
+
return;
|
|
20045
|
+
getChannel$1(channelId).catch(() => {
|
|
20046
|
+
/* silent per spec; UIKit renders no error toast */
|
|
20047
|
+
});
|
|
20048
|
+
};
|
|
20049
|
+
|
|
20050
|
+
/* begin_public_function
|
|
20051
|
+
id: message.pin
|
|
20052
|
+
*/
|
|
20053
|
+
/**
|
|
20054
|
+
* ```js
|
|
20055
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
20056
|
+
* const channel = await MessageRepository.pinMessage(messageId)
|
|
20057
|
+
* console.log(channel.pinnedMessage)
|
|
20058
|
+
* ```
|
|
20059
|
+
*
|
|
20060
|
+
* Pins a {@link Amity.Message} in its livestream (`live`) channel. A channel holds at
|
|
20061
|
+
* most one pinned message: pinning a different message replaces the current pin in a
|
|
20062
|
+
* single step — no unpin is needed first. Pinning the message that is already pinned is
|
|
20063
|
+
* rejected by the server (400).
|
|
20064
|
+
*
|
|
20065
|
+
* The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
|
|
20066
|
+
* `ModerateChannel`). The server also rejects pinning a deleted message, a message whose
|
|
20067
|
+
* author is banned from the channel or globally banned, and pinning in any channel type
|
|
20068
|
+
* other than `live`. On any error the pin state is left unchanged.
|
|
20069
|
+
*
|
|
20070
|
+
* The response is the affected channel; it is ingested into cache and fires
|
|
20071
|
+
* `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
|
|
20072
|
+
* waiting for the `channel.messagePinned` realtime event.
|
|
20073
|
+
*
|
|
20074
|
+
* @param messageId the **internal** ID of the {@link Amity.Message} to pin
|
|
20075
|
+
* @returns the updated {@link Amity.Channel}, with `pinnedMessage` set
|
|
20076
|
+
*
|
|
20077
|
+
* @category Message API
|
|
20078
|
+
* @async
|
|
20079
|
+
*/
|
|
20080
|
+
const pinMessage = async (messageId) => {
|
|
20081
|
+
const client = getActiveClient();
|
|
20082
|
+
client.log('message/pinMessage', messageId);
|
|
20083
|
+
let payload;
|
|
20084
|
+
try {
|
|
20085
|
+
({ data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
|
|
20086
|
+
}
|
|
20087
|
+
catch (error) {
|
|
20088
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
20089
|
+
refreshChannelPermissionsForMessage(messageId);
|
|
20090
|
+
}
|
|
20091
|
+
throw error;
|
|
20092
|
+
}
|
|
20093
|
+
const data = await prepareChannelPayload(payload);
|
|
20094
|
+
if (client.cache)
|
|
20095
|
+
ingestInCache(data);
|
|
20096
|
+
fireEvent('local.channel.updated', data);
|
|
20097
|
+
return constructChannelObject(data.channels[0]);
|
|
20098
|
+
};
|
|
20099
|
+
/* end_public_function */
|
|
20100
|
+
|
|
20101
|
+
/* begin_public_function
|
|
20102
|
+
id: message.unpin
|
|
20103
|
+
*/
|
|
20104
|
+
/**
|
|
20105
|
+
* ```js
|
|
20106
|
+
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
20107
|
+
* const channel = await MessageRepository.unpinMessage(messageId)
|
|
20108
|
+
* console.log(channel.pinnedMessage) // null
|
|
20109
|
+
* ```
|
|
20110
|
+
*
|
|
20111
|
+
* Removes the pin from a {@link Amity.Message}. `messageId` must be the message that is
|
|
20112
|
+
* **currently** pinned in its channel; otherwise the server answers 400 — this is
|
|
20113
|
+
* deliberate, so a stale client cannot clear a pin that someone else has since replaced.
|
|
20114
|
+
* On that error, re-read the channel (or rely on the `channel.messagePinned` event) to
|
|
20115
|
+
* get the current pin.
|
|
20116
|
+
*
|
|
20117
|
+
* The caller must hold the `PIN_MESSAGE` permission in the channel (or be an admin with
|
|
20118
|
+
* `ModerateChannel`). Unpinning is allowed regardless of channel type and stream state.
|
|
20119
|
+
*
|
|
20120
|
+
* The response is the affected channel; it is ingested into cache and fires
|
|
20121
|
+
* `local.channel.updated`, so `ChannelRepository.getChannel` observers update without
|
|
20122
|
+
* waiting for the `channel.messageUnpinned` realtime event.
|
|
20123
|
+
*
|
|
20124
|
+
* @param messageId the **internal** ID of the currently pinned {@link Amity.Message}
|
|
20125
|
+
* @returns the updated {@link Amity.Channel}, with `pinnedMessage` cleared
|
|
20126
|
+
*
|
|
20127
|
+
* @category Message API
|
|
20128
|
+
* @async
|
|
20129
|
+
*/
|
|
20130
|
+
const unpinMessage = async (messageId) => {
|
|
20131
|
+
const client = getActiveClient();
|
|
20132
|
+
client.log('message/unpinMessage', messageId);
|
|
20133
|
+
let payload;
|
|
20134
|
+
try {
|
|
20135
|
+
({ data: payload } = await client.http.delete(`/api/v5/messages/${encodeURIComponent(messageId)}/pin`));
|
|
20136
|
+
}
|
|
20137
|
+
catch (error) {
|
|
20138
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
20139
|
+
refreshChannelPermissionsForMessage(messageId);
|
|
20140
|
+
}
|
|
20141
|
+
throw error;
|
|
20142
|
+
}
|
|
20143
|
+
const data = await prepareChannelPayload(payload);
|
|
20144
|
+
if (client.cache)
|
|
20145
|
+
ingestInCache(data);
|
|
20146
|
+
fireEvent('local.channel.updated', data);
|
|
20147
|
+
return constructChannelObject(data.channels[0]);
|
|
20148
|
+
};
|
|
20149
|
+
/* end_public_function */
|
|
20150
|
+
|
|
18917
20151
|
/**
|
|
18918
20152
|
* ```js
|
|
18919
20153
|
* import { MessageRepository } from '@amityco/ts-sdk'
|
|
@@ -19102,23 +20336,82 @@ getDeliveredUsers.locally = (query) => {
|
|
|
19102
20336
|
return { data: users, cachedAt, prevPage, nextPage };
|
|
19103
20337
|
};
|
|
19104
20338
|
|
|
19105
|
-
|
|
19106
|
-
id: message.flag
|
|
19107
|
-
*/
|
|
20339
|
+
const CONTENT_FLAG_REASONS = Object.values(exports.ContentFlagReasonEnum);
|
|
19108
20340
|
/**
|
|
19109
|
-
*
|
|
19110
|
-
*
|
|
19111
|
-
*
|
|
19112
|
-
|
|
20341
|
+
* True when a public `flagX(id, input)` argument is the legacy shape (a reason string
|
|
20342
|
+
* or nothing). Anything else is routed to the `Amity.ContentFlagOptions` path, whose
|
|
20343
|
+
* validation rejects malformed values before any request is made.
|
|
20344
|
+
*/
|
|
20345
|
+
const isLegacyContentFlagReason = (input) => input === undefined || typeof input === 'string';
|
|
20346
|
+
/**
|
|
20347
|
+
* Validates an `Amity.ContentFlagOptions` argument. Untyped (plain JS) callers can pass
|
|
20348
|
+
* anything at runtime, so the checks do not trust the declared type: the value must be a
|
|
20349
|
+
* plain object, `reason` must be one of the nine `ContentFlagReasonEnum` values and
|
|
20350
|
+
* `detail`, when supplied, must be a string (`null` is not a valid supplied detail).
|
|
19113
20351
|
*
|
|
19114
|
-
* @param
|
|
19115
|
-
* @
|
|
19116
|
-
|
|
20352
|
+
* @param apiName used in the error message, e.g. `flagPost`
|
|
20353
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when the options are malformed
|
|
20354
|
+
*/
|
|
20355
|
+
const validateContentFlagOptions = (apiName, options) => {
|
|
20356
|
+
if (typeof options !== 'object' || options === null || Array.isArray(options)) {
|
|
20357
|
+
throw new ASCInvalidParameterError(`${apiName}: expected an options object \`{ reason, detail? }\``);
|
|
20358
|
+
}
|
|
20359
|
+
const { reason, detail } = options;
|
|
20360
|
+
if (typeof reason !== 'string' || !CONTENT_FLAG_REASONS.includes(reason)) {
|
|
20361
|
+
throw new ASCInvalidParameterError(`${apiName}: \`reason\` must be a \`ContentFlagReasonEnum\` value`);
|
|
20362
|
+
}
|
|
20363
|
+
if (detail !== undefined && typeof detail !== 'string') {
|
|
20364
|
+
throw new ASCInvalidParameterError(`${apiName}: \`detail\` must be a string when supplied`);
|
|
20365
|
+
}
|
|
20366
|
+
return { reason: reason, detail };
|
|
20367
|
+
};
|
|
20368
|
+
/**
|
|
20369
|
+
* Builds the request body for validated options. `detail` is forwarded unchanged (empty
|
|
20370
|
+
* and whitespace-only strings included) and omitted from the body when `undefined`; the
|
|
20371
|
+
* backend enforces the 300-character limit.
|
|
20372
|
+
*/
|
|
20373
|
+
const toContentFlagBody = ({ reason, detail }) => detail === undefined ? { reason } : { reason, detail };
|
|
20374
|
+
|
|
20375
|
+
/**
|
|
20376
|
+
* New `flagMessage(messageId, { reason, detail? })` implementation. Any category,
|
|
20377
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
20378
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
20379
|
+
* the backend enforces the 300-character limit.
|
|
19117
20380
|
*
|
|
19118
|
-
*
|
|
19119
|
-
*
|
|
19120
|
-
*
|
|
19121
|
-
|
|
20381
|
+
* Not exported from the public API. It is reached through the
|
|
20382
|
+
* `MessageRepository.flagMessage(messageId, options)` overload; see `flagMessage.ts`.
|
|
20383
|
+
*
|
|
20384
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
20385
|
+
*/
|
|
20386
|
+
const flagMessageWithOptions = async (messageId, options) => {
|
|
20387
|
+
const client = getActiveClient();
|
|
20388
|
+
client.log('message/flag', messageId);
|
|
20389
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagMessage', options));
|
|
20390
|
+
const { data: payload } = await client.http.post(`/api/v5/messages/${encodeURIComponent(messageId)}/flags`, body);
|
|
20391
|
+
if (client.cache) {
|
|
20392
|
+
const messagePayload = await prepareMessagePayload(payload);
|
|
20393
|
+
ingestInCache(messagePayload);
|
|
20394
|
+
}
|
|
20395
|
+
fireEvent('message.flagged', payload);
|
|
20396
|
+
return !!payload;
|
|
20397
|
+
};
|
|
20398
|
+
|
|
20399
|
+
/**
|
|
20400
|
+
* Legacy `flagMessage(messageId, reason?)` implementation, kept verbatim so existing
|
|
20401
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
20402
|
+
*
|
|
20403
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
20404
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
20405
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
20406
|
+
* (for `undefined` the message body carries `detail: undefined`, which JSON serialization omits)
|
|
20407
|
+
*
|
|
20408
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
20409
|
+
* `MessageRepository.flagMessage(messageId, reason)` overload; see `flagMessage.ts`.
|
|
20410
|
+
*
|
|
20411
|
+
* @deprecated Use `flagMessageWithOptions` (the `{ reason, detail? }` contract) for new code.
|
|
20412
|
+
* This path stays available throughout the current major version.
|
|
20413
|
+
*/
|
|
20414
|
+
const flagMessageWithReasonString = async (messageId, reason) => {
|
|
19122
20415
|
const client = getActiveClient();
|
|
19123
20416
|
client.log('message/flag', messageId);
|
|
19124
20417
|
const isPredefinedReason = reason &&
|
|
@@ -19135,6 +20428,42 @@ const flagMessage = async (messageId, reason) => {
|
|
|
19135
20428
|
fireEvent('message.flagged', payload);
|
|
19136
20429
|
return !!payload;
|
|
19137
20430
|
};
|
|
20431
|
+
|
|
20432
|
+
/* begin_public_function
|
|
20433
|
+
id: message.flag
|
|
20434
|
+
*/
|
|
20435
|
+
/**
|
|
20436
|
+
* ```js
|
|
20437
|
+
* import { MessageRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
20438
|
+
*
|
|
20439
|
+
* // No reason.
|
|
20440
|
+
* await MessageRepository.flagMessage(messageId)
|
|
20441
|
+
*
|
|
20442
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
20443
|
+
* await MessageRepository.flagMessage(messageId, {
|
|
20444
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
20445
|
+
* detail: 'Repeated promotional links',
|
|
20446
|
+
* })
|
|
20447
|
+
* ```
|
|
20448
|
+
*
|
|
20449
|
+
* Reports a message to moderation. Three call shapes are accepted (see the overloads):
|
|
20450
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
20451
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
20452
|
+
* so the legacy path is untouched by the new contract:
|
|
20453
|
+
*
|
|
20454
|
+
* - `undefined` or a string → `flagMessageWithReasonString` (unchanged legacy mapping)
|
|
20455
|
+
* - anything else → `flagMessageWithOptions` (validated `{ reason, detail? }`)
|
|
20456
|
+
*
|
|
20457
|
+
* @param messageId The ID of the message to flag
|
|
20458
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
20459
|
+
* @returns `true` when the report was created
|
|
20460
|
+
*
|
|
20461
|
+
* @category Message API
|
|
20462
|
+
* @async
|
|
20463
|
+
* */
|
|
20464
|
+
const flagMessage = (messageId, input) => isLegacyContentFlagReason(input)
|
|
20465
|
+
? flagMessageWithReasonString(messageId, input)
|
|
20466
|
+
: flagMessageWithOptions(messageId, input);
|
|
19138
20467
|
/* end_public_function */
|
|
19139
20468
|
|
|
19140
20469
|
/* begin_public_function
|
|
@@ -19810,13 +21139,15 @@ const searchMessage = (params, callback) => {
|
|
|
19810
21139
|
};
|
|
19811
21140
|
/* end_public_function */
|
|
19812
21141
|
|
|
19813
|
-
var index$
|
|
21142
|
+
var index$o = /*#__PURE__*/Object.freeze({
|
|
19814
21143
|
__proto__: null,
|
|
19815
21144
|
createMessage: createMessage,
|
|
19816
21145
|
updateMessage: updateMessage,
|
|
19817
21146
|
editMessage: editMessage,
|
|
19818
21147
|
deleteMessage: deleteMessage,
|
|
19819
21148
|
softDeleteMessage: softDeleteMessage,
|
|
21149
|
+
pinMessage: pinMessage,
|
|
21150
|
+
unpinMessage: unpinMessage,
|
|
19820
21151
|
markAsDelivered: markAsDelivered,
|
|
19821
21152
|
getReadUsers: getReadUsers,
|
|
19822
21153
|
getDeliveredUsers: getDeliveredUsers,
|
|
@@ -20346,7 +21677,7 @@ const stopMessageReceiptSync = (subChannelId) => {
|
|
|
20346
21677
|
};
|
|
20347
21678
|
/* end_public_function */
|
|
20348
21679
|
|
|
20349
|
-
var index$
|
|
21680
|
+
var index$n = /*#__PURE__*/Object.freeze({
|
|
20350
21681
|
__proto__: null,
|
|
20351
21682
|
getSubChannelByIds: getSubChannels$1,
|
|
20352
21683
|
createSubChannel: createSubChannel,
|
|
@@ -20453,7 +21784,12 @@ const getChannel = (channelId, callback) => {
|
|
|
20453
21784
|
onChannelMemberRemoved,
|
|
20454
21785
|
onChannelMemberBanned,
|
|
20455
21786
|
onChannelMemberUnbanned,
|
|
21787
|
+
onChannelMemberRoleAdded,
|
|
21788
|
+
onChannelMemberRoleRemoved,
|
|
20456
21789
|
onChannelSetMuted,
|
|
21790
|
+
onChannelMessagePinned,
|
|
21791
|
+
onChannelMessageUnpinned,
|
|
21792
|
+
onChannelPinnedMessageDeleted,
|
|
20457
21793
|
convertEventPayload(onChannelMarkerFetched, 'entityId', 'channel'),
|
|
20458
21794
|
convertEventPayload(onChannelMarkerUpdated, 'entityId', 'channel'),
|
|
20459
21795
|
convertEventPayload((callback) => {
|
|
@@ -21079,6 +22415,14 @@ class ChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21079
22415
|
return;
|
|
21080
22416
|
if (messagePreviewSetting ===
|
|
21081
22417
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
22418
|
+
// The replacement preview the server sends back is an OLDER
|
|
22419
|
+
// message than the one just deleted, and
|
|
22420
|
+
// updateChannelMessagePreviewCache drops any preview that is not
|
|
22421
|
+
// newer than what is cached — so without clearing the entry
|
|
22422
|
+
// first the refetch is a no-op and the channel keeps showing the
|
|
22423
|
+
// deleted message. getChannel's own live object already does
|
|
22424
|
+
// this; the live collections did not.
|
|
22425
|
+
dropFromCache(['messagePreviewChannel', 'get', message.channelId]);
|
|
21082
22426
|
await getChannel$1(message.channelId);
|
|
21083
22427
|
}
|
|
21084
22428
|
callback(message);
|
|
@@ -21803,6 +23147,14 @@ class SearchChannelLiveCollectionController extends LiveCollectionController {
|
|
|
21803
23147
|
return;
|
|
21804
23148
|
if (messagePreviewSetting ===
|
|
21805
23149
|
"message-preview-not-include-deleted" /* Amity.MessagePreviewSetting.MESSAGE_PREVIEW_NOT_INCLUDE_DELETED */) {
|
|
23150
|
+
// The replacement preview the server sends back is an OLDER
|
|
23151
|
+
// message than the one just deleted, and
|
|
23152
|
+
// updateChannelMessagePreviewCache drops any preview that is not
|
|
23153
|
+
// newer than what is cached — so without clearing the entry
|
|
23154
|
+
// first the refetch is a no-op and the channel keeps showing the
|
|
23155
|
+
// deleted message. getChannel's own live object already does
|
|
23156
|
+
// this; the live collections did not.
|
|
23157
|
+
dropFromCache(['messagePreviewChannel', 'get', message.channelId]);
|
|
21806
23158
|
await getChannel$1(message.channelId);
|
|
21807
23159
|
}
|
|
21808
23160
|
callback(message);
|
|
@@ -22297,7 +23649,7 @@ const searchMembers$1 = (params, callback, config) => {
|
|
|
22297
23649
|
};
|
|
22298
23650
|
/* end_public_function */
|
|
22299
23651
|
|
|
22300
|
-
var index$
|
|
23652
|
+
var index$m = /*#__PURE__*/Object.freeze({
|
|
22301
23653
|
__proto__: null,
|
|
22302
23654
|
addMembers: addMembers$1,
|
|
22303
23655
|
removeMembers: removeMembers$1,
|
|
@@ -22519,7 +23871,7 @@ const unmuteMembers = async (channelId, userIds) => {
|
|
|
22519
23871
|
};
|
|
22520
23872
|
/* end_public_function */
|
|
22521
23873
|
|
|
22522
|
-
var index$
|
|
23874
|
+
var index$l = /*#__PURE__*/Object.freeze({
|
|
22523
23875
|
__proto__: null,
|
|
22524
23876
|
addRole: addRole,
|
|
22525
23877
|
removeRole: removeRole,
|
|
@@ -22529,10 +23881,10 @@ var index$k = /*#__PURE__*/Object.freeze({
|
|
|
22529
23881
|
unmuteMembers: unmuteMembers
|
|
22530
23882
|
});
|
|
22531
23883
|
|
|
22532
|
-
var index$
|
|
23884
|
+
var index$k = /*#__PURE__*/Object.freeze({
|
|
22533
23885
|
__proto__: null,
|
|
22534
|
-
Membership: index$
|
|
22535
|
-
Moderation: index$
|
|
23886
|
+
Membership: index$m,
|
|
23887
|
+
Moderation: index$l,
|
|
22536
23888
|
getChannelByIds: getChannelByIds$1,
|
|
22537
23889
|
createChannel: createChannel,
|
|
22538
23890
|
updateChannel: updateChannel,
|
|
@@ -22550,6 +23902,8 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22550
23902
|
onChannelJoined: onChannelJoined,
|
|
22551
23903
|
onChannelLeft: onChannelLeft,
|
|
22552
23904
|
onChannelSetMuted: onChannelSetMuted,
|
|
23905
|
+
onChannelMessagePinned: onChannelMessagePinned,
|
|
23906
|
+
onChannelMessageUnpinned: onChannelMessageUnpinned,
|
|
22553
23907
|
onChannelMemberAdded: onChannelMemberAdded,
|
|
22554
23908
|
onChannelMemberRemoved: onChannelMemberRemoved,
|
|
22555
23909
|
onChannelMemberBanned: onChannelMemberBanned,
|
|
@@ -22567,7 +23921,11 @@ var index$j = /*#__PURE__*/Object.freeze({
|
|
|
22567
23921
|
isUnreadCountSupport: isUnreadCountSupport,
|
|
22568
23922
|
convertFromRaw: convertFromRaw,
|
|
22569
23923
|
preUpdateChannelCache: preUpdateChannelCache,
|
|
22570
|
-
prepareChannelPayload: prepareChannelPayload
|
|
23924
|
+
prepareChannelPayload: prepareChannelPayload,
|
|
23925
|
+
findCachedChannelByAnyId: findCachedChannelByAnyId,
|
|
23926
|
+
findCachedChannelForPin: findCachedChannelForPin,
|
|
23927
|
+
updatePinnedMessageCache: updatePinnedMessageCache,
|
|
23928
|
+
applyChannelRolePayload: applyChannelRolePayload
|
|
22571
23929
|
});
|
|
22572
23930
|
|
|
22573
23931
|
const saveCommunityUsers = (communities, communityUsers) => {
|
|
@@ -23961,7 +25319,7 @@ const searchMembers = (params, callback, config) => {
|
|
|
23961
25319
|
};
|
|
23962
25320
|
/* end_public_function */
|
|
23963
25321
|
|
|
23964
|
-
var index$
|
|
25322
|
+
var index$j = /*#__PURE__*/Object.freeze({
|
|
23965
25323
|
__proto__: null,
|
|
23966
25324
|
addMembers: addMembers,
|
|
23967
25325
|
removeMembers: removeMembers,
|
|
@@ -25212,7 +26570,7 @@ const unbanMembers = async (communityId, userIds) => {
|
|
|
25212
26570
|
};
|
|
25213
26571
|
/* end_public_function */
|
|
25214
26572
|
|
|
25215
|
-
var index$
|
|
26573
|
+
var index$i = /*#__PURE__*/Object.freeze({
|
|
25216
26574
|
__proto__: null,
|
|
25217
26575
|
addRoles: addRoles,
|
|
25218
26576
|
removeRoles: removeRoles,
|
|
@@ -25220,10 +26578,10 @@ var index$h = /*#__PURE__*/Object.freeze({
|
|
|
25220
26578
|
unbanMembers: unbanMembers
|
|
25221
26579
|
});
|
|
25222
26580
|
|
|
25223
|
-
var index$
|
|
26581
|
+
var index$h = /*#__PURE__*/Object.freeze({
|
|
25224
26582
|
__proto__: null,
|
|
25225
|
-
Moderation: index$
|
|
25226
|
-
Membership: index$
|
|
26583
|
+
Moderation: index$i,
|
|
26584
|
+
Membership: index$j,
|
|
25227
26585
|
getCommunityByIds: getCommunities$1,
|
|
25228
26586
|
createCommunity: createCommunity,
|
|
25229
26587
|
updateCommunity: updateCommunity,
|
|
@@ -25459,7 +26817,7 @@ const getCategories = (params, callback, config) => {
|
|
|
25459
26817
|
};
|
|
25460
26818
|
/* end_public_function */
|
|
25461
26819
|
|
|
25462
|
-
var index$
|
|
26820
|
+
var index$g = /*#__PURE__*/Object.freeze({
|
|
25463
26821
|
__proto__: null,
|
|
25464
26822
|
getCategory: getCategory,
|
|
25465
26823
|
getCategories: getCategories
|
|
@@ -25758,6 +27116,11 @@ const createCommentOptimistic = (bundle) => {
|
|
|
25758
27116
|
targetType: 'community',
|
|
25759
27117
|
dataType: 'text',
|
|
25760
27118
|
syncState: "syncing" /* Amity.SyncState.Syncing */,
|
|
27119
|
+
// In a gated community the optimistic object stays out of public collections until the
|
|
27120
|
+
// response settles the status; the author's own view still updates through the local event
|
|
27121
|
+
approvalStatus: isCommentApprovalRequired(bundle)
|
|
27122
|
+
? "pending" /* Amity.CommentApprovalStatusEnum.Pending */
|
|
27123
|
+
: "approved" /* Amity.CommentApprovalStatusEnum.Approved */,
|
|
25761
27124
|
};
|
|
25762
27125
|
const cachedAt = UNSYNCED_OBJECT_CACHED_AT_VALUE;
|
|
25763
27126
|
pushToCache(['comment', 'get', comment.commentId], comment, { cachedAt });
|
|
@@ -25774,32 +27137,57 @@ const createCommentOptimistic = (bundle) => {
|
|
|
25774
27137
|
* ```js
|
|
25775
27138
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
25776
27139
|
* const newComment = await CommentRepository.createComment(bundle)
|
|
27140
|
+
*
|
|
27141
|
+
* // Server-confirmed only: nothing is shown until the request succeeds
|
|
27142
|
+
* const confirmed = await CommentRepository.createComment(bundle, false)
|
|
25777
27143
|
* ```
|
|
25778
27144
|
*
|
|
25779
27145
|
* Creates an {@link Amity.Comment}
|
|
25780
27146
|
*
|
|
27147
|
+
* With `isOptimistic` (the default) a local comment appears at once with `syncState: 'syncing'`,
|
|
27148
|
+
* moves to `'synced'` when the server confirms it and to `'error'` if the request fails, so the
|
|
27149
|
+
* caller can offer a retry. With `isOptimistic: false` nothing is created locally until the
|
|
27150
|
+
* server answers: on success the comment arrives already `'synced'`; on failure no comment
|
|
27151
|
+
* entity exists anywhere and the promise rejects.
|
|
27152
|
+
*
|
|
25781
27153
|
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
27154
|
+
* @param isOptimistic Show a local comment before the server confirms it. Default `true`.
|
|
27155
|
+
* Ignored when the client cache is disabled, since there is nowhere to hold the local comment.
|
|
25782
27156
|
* @returns The newly created {@link Amity.Comment}
|
|
25783
27157
|
*
|
|
25784
27158
|
* @category Comment API
|
|
25785
27159
|
* @async
|
|
25786
27160
|
*/
|
|
25787
|
-
const createComment = async (bundle) => {
|
|
27161
|
+
const createComment = async (bundle, isOptimistic = true) => {
|
|
25788
27162
|
const client = getActiveClient();
|
|
25789
|
-
client.log('comment/createComment', bundle);
|
|
25790
|
-
|
|
27163
|
+
client.log('comment/createComment', Object.assign(Object.assign({}, bundle), { isOptimistic }));
|
|
27164
|
+
// Without a local comment the server assigns the id; with one, the same id travels through the
|
|
27165
|
+
// optimistic object, the response and every realtime event so each step recognises it.
|
|
27166
|
+
const optimisticData = isOptimistic ? createCommentOptimistic(bundle) : undefined;
|
|
25791
27167
|
const commentId = optimisticData === null || optimisticData === void 0 ? void 0 : optimisticData.commentId;
|
|
25792
27168
|
try {
|
|
25793
|
-
const { data } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
25794
|
-
const { comments } = data;
|
|
27169
|
+
const { data: payload } = await client.http.post('/api/v3/comments', Object.assign(Object.assign({}, bundle), { commentId }));
|
|
25795
27170
|
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
25796
|
-
if (comments.length === 0)
|
|
27171
|
+
if (payload.comments.length === 0)
|
|
25797
27172
|
throw new Error('Comment not created');
|
|
27173
|
+
// Absent `approvalStatus` means approved; the result is the only source of the status.
|
|
27174
|
+
// The confirmed comment is written as `synced` so the cache itself tells the two states apart
|
|
27175
|
+
// (a local-event subscriber is not guaranteed to be listening).
|
|
27176
|
+
const prepared = prepareCommentPayload(payload);
|
|
27177
|
+
const data = Object.assign(Object.assign({}, prepared), { comments: prepared.comments.map(comment => comment.commentId === (commentId !== null && commentId !== void 0 ? commentId : comment.commentId)
|
|
27178
|
+
? Object.assign(Object.assign({}, comment), { syncState: "synced" /* Amity.SyncState.Synced */ }) : comment) });
|
|
27179
|
+
const { comments } = data;
|
|
25798
27180
|
const cachedAt = client.cache && Date.now();
|
|
25799
27181
|
if (client.cache)
|
|
25800
27182
|
ingestInCache(data, { cachedAt });
|
|
25801
27183
|
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
25802
|
-
|
|
27184
|
+
if (isCommentPending(comments[0])) {
|
|
27185
|
+
// Not counted for anyone else until approved; the author sees their own +1
|
|
27186
|
+
recordPendingAuthoredComment(comments[0]);
|
|
27187
|
+
}
|
|
27188
|
+
else {
|
|
27189
|
+
PostCommentCountEngine$1.getInstance().queueCommentChangeTask(new CreateTask(bundle.referenceId, comments[0].commentId, comments[0].createdAt));
|
|
27190
|
+
}
|
|
25803
27191
|
}
|
|
25804
27192
|
else if (bundle.referenceType === 'story') {
|
|
25805
27193
|
const storyIndex = pullFromCache([
|
|
@@ -25820,9 +27208,9 @@ const createComment = async (bundle) => {
|
|
|
25820
27208
|
categories: [],
|
|
25821
27209
|
comments,
|
|
25822
27210
|
communities: [],
|
|
25823
|
-
communityUsers:
|
|
25824
|
-
files:
|
|
25825
|
-
users:
|
|
27211
|
+
communityUsers: payload.communityUsers,
|
|
27212
|
+
files: payload.files,
|
|
27213
|
+
users: payload.users,
|
|
25826
27214
|
});
|
|
25827
27215
|
}
|
|
25828
27216
|
}
|
|
@@ -25830,9 +27218,9 @@ const createComment = async (bundle) => {
|
|
|
25830
27218
|
fireEvent('local.comment.created', {
|
|
25831
27219
|
comments: [Object.assign(Object.assign({}, comments[0]), { syncState: "synced" /* Amity.SyncState.Synced */ })],
|
|
25832
27220
|
commentChildren: data.commentChildren,
|
|
25833
|
-
users:
|
|
25834
|
-
files:
|
|
25835
|
-
communityUsers:
|
|
27221
|
+
users: payload.users,
|
|
27222
|
+
files: payload.files,
|
|
27223
|
+
communityUsers: payload.communityUsers,
|
|
25836
27224
|
});
|
|
25837
27225
|
return {
|
|
25838
27226
|
data: LinkedObject.comment(comments[0]),
|
|
@@ -25840,9 +27228,17 @@ const createComment = async (bundle) => {
|
|
|
25840
27228
|
};
|
|
25841
27229
|
}
|
|
25842
27230
|
catch (e) {
|
|
27231
|
+
// Only a local comment has anything to mark as failed; a server-confirmed-only create leaves
|
|
27232
|
+
// no entity behind
|
|
25843
27233
|
if (optimisticData) {
|
|
27234
|
+
const failed = Object.assign(Object.assign({}, optimisticData), { syncState: "error" /* Amity.SyncState.Error */ });
|
|
27235
|
+
// Write the failure to the cache directly: the local event below only reaches pages that
|
|
27236
|
+
// observe comments, and the caller's retry UI reads the cached state
|
|
27237
|
+
pushToCache(['comment', 'get', failed.commentId], failed, {
|
|
27238
|
+
cachedAt: UNSYNCED_OBJECT_CACHED_AT_VALUE,
|
|
27239
|
+
});
|
|
25844
27240
|
fireEvent('local.comment.created', {
|
|
25845
|
-
comments: [
|
|
27241
|
+
comments: [failed],
|
|
25846
27242
|
commentChildren: [],
|
|
25847
27243
|
users: [],
|
|
25848
27244
|
files: [],
|
|
@@ -25875,16 +27271,26 @@ const createComment = async (bundle) => {
|
|
|
25875
27271
|
* @async
|
|
25876
27272
|
*/
|
|
25877
27273
|
const updateComment = async (commentId, patch) => {
|
|
27274
|
+
var _a;
|
|
25878
27275
|
const client = getActiveClient();
|
|
25879
27276
|
client.log('user/updateComment', patch);
|
|
25880
|
-
const
|
|
27277
|
+
const previous = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27278
|
+
const { data: payload } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
27279
|
+
const data = prepareCommentPayload(payload);
|
|
27280
|
+
const updated = data.comments.find(comment => comment.commentId === commentId);
|
|
25881
27281
|
const cachedAt = client.cache && Date.now();
|
|
25882
27282
|
if (client.cache)
|
|
25883
27283
|
ingestInCache(data, { cachedAt });
|
|
25884
|
-
|
|
25885
|
-
|
|
27284
|
+
// An effective edit in a gated community sends the comment back for review: it leaves the
|
|
27285
|
+
// public reply list and the public count once. The `comment.updated` event below removes it
|
|
27286
|
+
// from the comment collections; the realtime echo finds it already pending and does nothing.
|
|
27287
|
+
if (isCommentPending(updated) && previous && isCommentApproved(previous)) {
|
|
27288
|
+
unlinkCommentFromParent(updated);
|
|
27289
|
+
applyCommentReReviewCount(updated);
|
|
27290
|
+
}
|
|
27291
|
+
fireEvent('comment.updated', payload);
|
|
25886
27292
|
return {
|
|
25887
|
-
data: LinkedObject.comment(
|
|
27293
|
+
data: LinkedObject.comment(updated),
|
|
25888
27294
|
cachedAt,
|
|
25889
27295
|
};
|
|
25890
27296
|
};
|
|
@@ -26024,7 +27430,13 @@ const deleteComment = async (commentId, permanent = false) => {
|
|
|
26024
27430
|
const post = (_b = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _b === void 0 ? void 0 : _b.data;
|
|
26025
27431
|
if (post) {
|
|
26026
27432
|
const engine = PostCommentCountEngine$1.getInstance();
|
|
26027
|
-
|
|
27433
|
+
if (isCommentPending(comment.data)) {
|
|
27434
|
+
// Never counted for anyone else; only the author's own +1 goes away
|
|
27435
|
+
engine.removePendingAuthoredComment(post.postId, commentId);
|
|
27436
|
+
}
|
|
27437
|
+
else {
|
|
27438
|
+
engine.queueCommentChangeTask(new DeleteTask(post.postId, commentId));
|
|
27439
|
+
}
|
|
26028
27440
|
if (!deleted.parentId && ((_c = deleted.children /* c8 ignore next */) === null || _c === void 0 ? void 0 : _c.length) > 0) {
|
|
26029
27441
|
// NOTE: delete the parent comment will also remove all children comments
|
|
26030
27442
|
deleted.children.forEach((childCommentId) => {
|
|
@@ -26095,22 +27507,123 @@ const hardDeleteComment = async (commentId) => {
|
|
|
26095
27507
|
/* end_public_function */
|
|
26096
27508
|
|
|
26097
27509
|
/* begin_public_function
|
|
26098
|
-
id: comment.
|
|
27510
|
+
id: comment.approve
|
|
26099
27511
|
*/
|
|
26100
27512
|
/**
|
|
26101
27513
|
* ```js
|
|
26102
27514
|
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
26103
|
-
*
|
|
27515
|
+
*
|
|
27516
|
+
* const { data: comment } = await CommentRepository.approveComment('commentId')
|
|
26104
27517
|
* ```
|
|
26105
27518
|
*
|
|
26106
|
-
* @
|
|
26107
|
-
*
|
|
26108
|
-
* @
|
|
27519
|
+
* Approves a {@link Amity.Comment} held for review, making it visible to everyone
|
|
27520
|
+
*
|
|
27521
|
+
* @param commentId The {@link Amity.Comment} ID to be approved
|
|
27522
|
+
* @return The {@link Amity.Comment} that was approved
|
|
26109
27523
|
*
|
|
26110
27524
|
* @category Comment API
|
|
26111
27525
|
* @async
|
|
26112
|
-
|
|
26113
|
-
const
|
|
27526
|
+
*/
|
|
27527
|
+
const approveComment = async (commentId) => {
|
|
27528
|
+
const client = getActiveClient();
|
|
27529
|
+
client.log('comment/approveComment', commentId);
|
|
27530
|
+
// No request body, and nothing is revealed before the server confirms
|
|
27531
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/approve`);
|
|
27532
|
+
const data = prepareCommentPayload(prepareMembershipPayload(payload, 'communityUsers'));
|
|
27533
|
+
const approved = data.comments.find(comment => comment.commentId === commentId);
|
|
27534
|
+
const cachedAt = client.cache && Date.now();
|
|
27535
|
+
if (client.cache)
|
|
27536
|
+
ingestInCache(data, { cachedAt });
|
|
27537
|
+
// The reveal path: parent link and exactly one count task. Applied here so it does not depend
|
|
27538
|
+
// on an observer being open; the event below and the realtime `comment.approved` that follows
|
|
27539
|
+
// find the work done and reconcile by comment id (collection insert, queue removal).
|
|
27540
|
+
linkCommentToParent(approved);
|
|
27541
|
+
applyCommentApprovedCount(approved);
|
|
27542
|
+
fireEvent('comment.approved', payload);
|
|
27543
|
+
return {
|
|
27544
|
+
data: LinkedObject.comment(approved),
|
|
27545
|
+
cachedAt,
|
|
27546
|
+
};
|
|
27547
|
+
};
|
|
27548
|
+
/* end_public_function */
|
|
27549
|
+
|
|
27550
|
+
// Rejected is terminal and implies deleted
|
|
27551
|
+
const markRejected = (comment) => (Object.assign(Object.assign({}, comment), { approvalStatus: "rejected" /* Amity.CommentApprovalStatusEnum.Rejected */, isDeleted: true }));
|
|
27552
|
+
/* begin_public_function
|
|
27553
|
+
id: comment.decline
|
|
27554
|
+
*/
|
|
27555
|
+
/**
|
|
27556
|
+
* ```js
|
|
27557
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
27558
|
+
*
|
|
27559
|
+
* const { data: comment } = await CommentRepository.declineComment('commentId', 'Off-topic')
|
|
27560
|
+
* ```
|
|
27561
|
+
*
|
|
27562
|
+
* Declines a {@link Amity.Comment} held for review. A declined comment is also a deleted comment
|
|
27563
|
+
*
|
|
27564
|
+
* @param commentId The {@link Amity.Comment} ID to be declined
|
|
27565
|
+
* @param reason Optional reviewer's note, at most 250 characters, kept for the moderation record only
|
|
27566
|
+
* @return The {@link Amity.Comment} that was declined
|
|
27567
|
+
*
|
|
27568
|
+
* @category Comment API
|
|
27569
|
+
* @async
|
|
27570
|
+
*/
|
|
27571
|
+
const declineComment = async (commentId, reason) => {
|
|
27572
|
+
var _a, _b, _c, _d, _e, _f;
|
|
27573
|
+
const client = getActiveClient();
|
|
27574
|
+
client.log('comment/declineComment', commentId, reason);
|
|
27575
|
+
// Read before the request: the fallback when the response carries no comment
|
|
27576
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27577
|
+
// `reason` is surfaced to nobody; the key is absent from the body when the caller gives none
|
|
27578
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/decline`, reason ? { reason } : undefined);
|
|
27579
|
+
// The BE contract (PDT-5135 §3) states the response body for approve only; for decline the
|
|
27580
|
+
// standard comment payload is assumed. Ingest whatever came back, and when the body carries no
|
|
27581
|
+
// comment fall back to the cached one so the delete path below still runs.
|
|
27582
|
+
const returned = (_b = payload === null || payload === void 0 ? void 0 : payload.comments) === null || _b === void 0 ? void 0 : _b.some(comment => comment.commentId === commentId);
|
|
27583
|
+
if (!returned && !cached)
|
|
27584
|
+
throw new Error('Comment not found after decline');
|
|
27585
|
+
const comments = returned
|
|
27586
|
+
? payload.comments.map(comment => comment.commentId === commentId ? markRejected(comment) : comment)
|
|
27587
|
+
: [markRejected(cached)];
|
|
27588
|
+
const declined = {
|
|
27589
|
+
comments,
|
|
27590
|
+
commentChildren: (_c = payload === null || payload === void 0 ? void 0 : payload.commentChildren) !== null && _c !== void 0 ? _c : [],
|
|
27591
|
+
users: (_d = payload === null || payload === void 0 ? void 0 : payload.users) !== null && _d !== void 0 ? _d : [],
|
|
27592
|
+
files: (_e = payload === null || payload === void 0 ? void 0 : payload.files) !== null && _e !== void 0 ? _e : [],
|
|
27593
|
+
communityUsers: (_f = payload === null || payload === void 0 ? void 0 : payload.communityUsers) !== null && _f !== void 0 ? _f : [],
|
|
27594
|
+
};
|
|
27595
|
+
// There is no `comment.declined` event: the existing delete path drops the comment from every
|
|
27596
|
+
// collection and the review queue, and moves no count because a pending comment was never counted.
|
|
27597
|
+
const data = prepareCommentPayload(prepareMembershipPayload(declined, 'communityUsers'));
|
|
27598
|
+
const rejected = data.comments.find(comment => comment.commentId === commentId);
|
|
27599
|
+
const cachedAt = client.cache && Date.now();
|
|
27600
|
+
if (client.cache)
|
|
27601
|
+
ingestInCache(data, { cachedAt });
|
|
27602
|
+
unlinkCommentFromParent(rejected);
|
|
27603
|
+
releasePendingAuthoredComment(rejected);
|
|
27604
|
+
fireEvent('comment.deleted', declined);
|
|
27605
|
+
return {
|
|
27606
|
+
data: LinkedObject.comment(rejected),
|
|
27607
|
+
cachedAt,
|
|
27608
|
+
};
|
|
27609
|
+
};
|
|
27610
|
+
/* end_public_function */
|
|
27611
|
+
|
|
27612
|
+
/**
|
|
27613
|
+
* Legacy `flagComment(commentId, reason?)` implementation, kept verbatim so existing
|
|
27614
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
27615
|
+
*
|
|
27616
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
27617
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
27618
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
27619
|
+
*
|
|
27620
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
27621
|
+
* `CommentRepository.flagComment(commentId, reason)` overload; see `flagComment.ts`.
|
|
27622
|
+
*
|
|
27623
|
+
* @deprecated Use `flagCommentWithOptions` (the `{ reason, detail? }` contract) for new code.
|
|
27624
|
+
* This path stays available throughout the current major version.
|
|
27625
|
+
*/
|
|
27626
|
+
const flagCommentWithReasonString = async (commentId, reason) => {
|
|
26114
27627
|
const client = getActiveClient();
|
|
26115
27628
|
client.log('comment/flagComment', commentId);
|
|
26116
27629
|
const isPredefinedReason = reason &&
|
|
@@ -26126,6 +27639,65 @@ const flagComment = async (commentId, reason) => {
|
|
|
26126
27639
|
fireEvent('comment.flagged', payload);
|
|
26127
27640
|
return !!payload;
|
|
26128
27641
|
};
|
|
27642
|
+
|
|
27643
|
+
/**
|
|
27644
|
+
* New `flagComment(commentId, { reason, detail? })` implementation. Any category,
|
|
27645
|
+
* including `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
27646
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
27647
|
+
* the backend enforces the 300-character limit.
|
|
27648
|
+
*
|
|
27649
|
+
* Not exported from the public API. It is reached through the
|
|
27650
|
+
* `CommentRepository.flagComment(commentId, options)` overload; see `flagComment.ts`.
|
|
27651
|
+
*
|
|
27652
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
27653
|
+
*/
|
|
27654
|
+
const flagCommentWithOptions = async (commentId, options) => {
|
|
27655
|
+
const client = getActiveClient();
|
|
27656
|
+
client.log('comment/flagComment', commentId);
|
|
27657
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagComment', options));
|
|
27658
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
27659
|
+
if (client.cache) {
|
|
27660
|
+
ingestInCache(payload);
|
|
27661
|
+
}
|
|
27662
|
+
fireEvent('comment.flagged', payload);
|
|
27663
|
+
return !!payload;
|
|
27664
|
+
};
|
|
27665
|
+
|
|
27666
|
+
/* begin_public_function
|
|
27667
|
+
id: comment.flag
|
|
27668
|
+
*/
|
|
27669
|
+
/**
|
|
27670
|
+
* ```js
|
|
27671
|
+
* import { CommentRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
27672
|
+
*
|
|
27673
|
+
* // No reason: sent as Others with an empty detail.
|
|
27674
|
+
* await CommentRepository.flagComment(commentId)
|
|
27675
|
+
*
|
|
27676
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
27677
|
+
* await CommentRepository.flagComment(commentId, {
|
|
27678
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
27679
|
+
* detail: 'Repeated promotional links',
|
|
27680
|
+
* })
|
|
27681
|
+
* ```
|
|
27682
|
+
*
|
|
27683
|
+
* Reports a comment to moderation. Three call shapes are accepted (see the overloads):
|
|
27684
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
27685
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
27686
|
+
* so the legacy path is untouched by the new contract:
|
|
27687
|
+
*
|
|
27688
|
+
* - `undefined` or a string → `flagCommentWithReasonString` (unchanged legacy mapping)
|
|
27689
|
+
* - anything else → `flagCommentWithOptions` (validated `{ reason, detail? }`)
|
|
27690
|
+
*
|
|
27691
|
+
* @param commentId The ID of the comment to flag
|
|
27692
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
27693
|
+
* @returns `true` when the report was created
|
|
27694
|
+
*
|
|
27695
|
+
* @category Comment API
|
|
27696
|
+
* @async
|
|
27697
|
+
* */
|
|
27698
|
+
const flagComment = (commentId, input) => isLegacyContentFlagReason(input)
|
|
27699
|
+
? flagCommentWithReasonString(commentId, input)
|
|
27700
|
+
: flagCommentWithOptions(commentId, input);
|
|
26129
27701
|
/* end_public_function */
|
|
26130
27702
|
|
|
26131
27703
|
/* begin_public_function
|
|
@@ -26179,6 +27751,7 @@ const isCommentFlaggedByMe = async (commentId) => {
|
|
|
26179
27751
|
/* end_public_function */
|
|
26180
27752
|
|
|
26181
27753
|
const getComment$1 = async (commentId) => {
|
|
27754
|
+
var _a;
|
|
26182
27755
|
const client = getActiveClient();
|
|
26183
27756
|
client.log('comment/getComment', commentId);
|
|
26184
27757
|
isInTombstone('comment', commentId);
|
|
@@ -26189,7 +27762,11 @@ const getComment$1 = async (commentId) => {
|
|
|
26189
27762
|
data = response.data;
|
|
26190
27763
|
}
|
|
26191
27764
|
catch (error) {
|
|
26192
|
-
|
|
27765
|
+
// A pending comment answers 404 to anyone but its author and reviewers. That is a
|
|
27766
|
+
// visibility answer, not a deletion — never tombstone a comment known to be pending.
|
|
27767
|
+
const cached = (_a = pullFromCache(['comment', 'get', commentId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
27768
|
+
const isKnownPending = !!cached && isCommentPending(cached);
|
|
27769
|
+
if (!isKnownPending && checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
26193
27770
|
pushToTombstone('comment', commentId);
|
|
26194
27771
|
}
|
|
26195
27772
|
throw error;
|
|
@@ -26316,6 +27893,7 @@ const onLocalCommentReactionRemoved = (callback) => {
|
|
|
26316
27893
|
*/
|
|
26317
27894
|
const getComment = (commentId, callback) => {
|
|
26318
27895
|
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
27896
|
+
onCommentApproved,
|
|
26319
27897
|
onCommentDeleteLocal,
|
|
26320
27898
|
onCommentDeleted,
|
|
26321
27899
|
onCommentFlagged,
|
|
@@ -26329,28 +27907,31 @@ const getComment = (commentId, callback) => {
|
|
|
26329
27907
|
};
|
|
26330
27908
|
/* end_public_function */
|
|
26331
27909
|
|
|
26332
|
-
|
|
26333
|
-
|
|
26334
|
-
|
|
26335
|
-
|
|
26336
|
-
|
|
26337
|
-
|
|
26338
|
-
|
|
26339
|
-
|
|
26340
|
-
|
|
26341
|
-
|
|
26342
|
-
|
|
26343
|
-
|
|
26344
|
-
|
|
26345
|
-
|
|
26346
|
-
|
|
26347
|
-
|
|
27910
|
+
/**
|
|
27911
|
+
* ```js
|
|
27912
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
27913
|
+
* const dispose = onCommentCreated(comment => {
|
|
27914
|
+
* // ...
|
|
27915
|
+
* })
|
|
27916
|
+
* ```
|
|
27917
|
+
*
|
|
27918
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
27919
|
+
*
|
|
27920
|
+
* @param callback The function to call when the event was fired
|
|
27921
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
27922
|
+
*
|
|
27923
|
+
* @category Comment Events
|
|
27924
|
+
*/
|
|
27925
|
+
const onCommentCreatedLocal = (callback) => {
|
|
27926
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
27927
|
+
};
|
|
26348
27928
|
|
|
26349
27929
|
var EnumCommentActions;
|
|
26350
27930
|
(function (EnumCommentActions) {
|
|
26351
27931
|
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
26352
27932
|
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
26353
27933
|
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
27934
|
+
EnumCommentActions["OnCommentApproved"] = "onCommentApproved";
|
|
26354
27935
|
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
26355
27936
|
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
26356
27937
|
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
@@ -26373,15 +27954,17 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26373
27954
|
}
|
|
26374
27955
|
appendToQueryStream(response, direction, refresh = false) {
|
|
26375
27956
|
var _a, _b;
|
|
27957
|
+
// The public list is approved-only even when the server widens the read for a reviewer
|
|
27958
|
+
const commentIds = response.comments.filter(isCommentApproved).map(getResolver('comment'));
|
|
26376
27959
|
if (refresh) {
|
|
26377
27960
|
pushToCache(this.cacheKey, {
|
|
26378
|
-
data:
|
|
27961
|
+
data: commentIds,
|
|
26379
27962
|
});
|
|
26380
27963
|
}
|
|
26381
27964
|
else {
|
|
26382
27965
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
26383
27966
|
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
26384
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...
|
|
27967
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...commentIds])] }));
|
|
26385
27968
|
}
|
|
26386
27969
|
}
|
|
26387
27970
|
reactor(action) {
|
|
@@ -26400,8 +27983,19 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26400
27983
|
return;
|
|
26401
27984
|
}
|
|
26402
27985
|
if (action === EnumCommentActions.OnCommentCreated) {
|
|
27986
|
+
// A pending comment reaches clients over realtime before anyone may see it: persist
|
|
27987
|
+
// only, no insert and no emit. `comment.approved` is the reveal signal.
|
|
27988
|
+
if (!isCommentApproved(comment))
|
|
27989
|
+
return;
|
|
27990
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
27991
|
+
}
|
|
27992
|
+
if (action === EnumCommentActions.OnCommentApproved) {
|
|
26403
27993
|
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
26404
27994
|
}
|
|
27995
|
+
// An effective edit in a gated community returns the comment to review: it leaves the list
|
|
27996
|
+
if (action === EnumCommentActions.OnCommentUpdated && isCommentPending(comment)) {
|
|
27997
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
27998
|
+
}
|
|
26405
27999
|
pushToCache(this.cacheKey, collection);
|
|
26406
28000
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
26407
28001
|
};
|
|
@@ -26411,24 +28005,22 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
26411
28005
|
}
|
|
26412
28006
|
}
|
|
26413
28007
|
|
|
26414
|
-
|
|
26415
|
-
|
|
26416
|
-
|
|
26417
|
-
|
|
26418
|
-
|
|
26419
|
-
|
|
26420
|
-
|
|
26421
|
-
|
|
26422
|
-
|
|
26423
|
-
|
|
26424
|
-
|
|
26425
|
-
|
|
26426
|
-
|
|
26427
|
-
|
|
26428
|
-
|
|
26429
|
-
|
|
26430
|
-
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
26431
|
-
};
|
|
28008
|
+
class CommentPaginationController extends PaginationController {
|
|
28009
|
+
async getRequest(queryParams, token) {
|
|
28010
|
+
var _a;
|
|
28011
|
+
const { pageSize, limit, includeDeleted } = queryParams, params = __rest(queryParams, ["pageSize", "limit", "includeDeleted"]);
|
|
28012
|
+
const effectiveLimit = (_a = pageSize !== null && pageSize !== void 0 ? pageSize : limit) !== null && _a !== void 0 ? _a : COLLECTION_DEFAULT_PAGINATION_LIMIT;
|
|
28013
|
+
const baseOptions = {
|
|
28014
|
+
type: params.sortBy || queryParams.limit || queryParams.pageSize ? 'pagination' : undefined,
|
|
28015
|
+
};
|
|
28016
|
+
const options = token
|
|
28017
|
+
? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { pageSize: effectiveLimit, limit: effectiveLimit });
|
|
28018
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
28019
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
28020
|
+
});
|
|
28021
|
+
return queryResponse;
|
|
28022
|
+
}
|
|
28023
|
+
}
|
|
26432
28024
|
|
|
26433
28025
|
class CommentLiveCollectionController extends LiveCollectionController {
|
|
26434
28026
|
constructor(query, callback) {
|
|
@@ -26464,6 +28056,7 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26464
28056
|
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
26465
28057
|
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
26466
28058
|
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
28059
|
+
{ fn: onCommentApproved, action: EnumCommentActions.OnCommentApproved },
|
|
26467
28060
|
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
26468
28061
|
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
26469
28062
|
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
@@ -26497,7 +28090,8 @@ class CommentLiveCollectionController extends LiveCollectionController {
|
|
|
26497
28090
|
});
|
|
26498
28091
|
}
|
|
26499
28092
|
applyFilter(data) {
|
|
26500
|
-
|
|
28093
|
+
// Approved-only, for every caller including the author of a pending comment
|
|
28094
|
+
let comments = data.filter(isCommentApproved);
|
|
26501
28095
|
if (!this.query.includeDeleted) {
|
|
26502
28096
|
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
26503
28097
|
}
|
|
@@ -26585,7 +28179,202 @@ const getComments = (params, callback, config) => {
|
|
|
26585
28179
|
};
|
|
26586
28180
|
/* end_public_function */
|
|
26587
28181
|
|
|
26588
|
-
|
|
28182
|
+
class CommentReviewQueuePaginationController extends PaginationController {
|
|
28183
|
+
async getRequest(queryParams, token) {
|
|
28184
|
+
const { communityId, limit } = queryParams, params = __rest(queryParams, ["communityId", "limit"]);
|
|
28185
|
+
// The route defaults to 10, not the SDK-wide 20, and rejects anything above 100
|
|
28186
|
+
const effectiveLimit = Math.min(limit !== null && limit !== void 0 ? limit : COMMENT_REVIEW_QUEUE_DEFAULT_PAGINATION_SIZE, COMMENT_REVIEW_QUEUE_MAX_PAGINATION_SIZE);
|
|
28187
|
+
// Token paging only. The route also accepts options[skip], but offset paging over a queue that
|
|
28188
|
+
// drains from the front skips items, so the SDK never sends it.
|
|
28189
|
+
const options = token ? { token } : { limit: effectiveLimit };
|
|
28190
|
+
const { data: queryResponse } = await this.http.get(API_ENDPOINTS.commentReviewQueue(communityId), {
|
|
28191
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
28192
|
+
});
|
|
28193
|
+
return queryResponse;
|
|
28194
|
+
}
|
|
28195
|
+
}
|
|
28196
|
+
|
|
28197
|
+
class CommentReviewQueueQueryStreamController extends QueryStreamController {
|
|
28198
|
+
constructor(query, cacheKey, notifyChange) {
|
|
28199
|
+
super(query, cacheKey);
|
|
28200
|
+
this.notifyChange = notifyChange;
|
|
28201
|
+
}
|
|
28202
|
+
async saveToMainDB(response) {
|
|
28203
|
+
const processedPayload = prepareCommentPayload(response);
|
|
28204
|
+
const client = getActiveClient();
|
|
28205
|
+
const cachedAt = client.cache && Date.now();
|
|
28206
|
+
if (client.cache) {
|
|
28207
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
28208
|
+
}
|
|
28209
|
+
}
|
|
28210
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
28211
|
+
var _a, _b;
|
|
28212
|
+
// Server order is queue-entry order, oldest first. Keep it: later pages append, nothing
|
|
28213
|
+
// re-sorts by createdAt (the two diverge on re-review).
|
|
28214
|
+
const commentIds = response.comments.map(getResolver('comment'));
|
|
28215
|
+
if (refresh) {
|
|
28216
|
+
pushToCache(this.cacheKey, {
|
|
28217
|
+
data: commentIds,
|
|
28218
|
+
});
|
|
28219
|
+
}
|
|
28220
|
+
else {
|
|
28221
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28222
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
28223
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...commentIds])] }));
|
|
28224
|
+
}
|
|
28225
|
+
}
|
|
28226
|
+
matchesQuery(comment) {
|
|
28227
|
+
return (comment.targetType === 'community' &&
|
|
28228
|
+
comment.targetId === this.query.communityId &&
|
|
28229
|
+
(!this.query.postId || comment.referenceId === this.query.postId));
|
|
28230
|
+
}
|
|
28231
|
+
reactor(action) {
|
|
28232
|
+
return (comment) => {
|
|
28233
|
+
var _a;
|
|
28234
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28235
|
+
if (!collection || !this.matchesQuery(comment))
|
|
28236
|
+
return;
|
|
28237
|
+
const isQueued = collection.data.includes(comment.commentId);
|
|
28238
|
+
// A date-filtered queue is the server's to shape; live events only remove from it
|
|
28239
|
+
const acceptsLiveInserts = !this.query.startDate && !this.query.endDate;
|
|
28240
|
+
switch (action) {
|
|
28241
|
+
case EnumCommentActions.OnCommentCreated:
|
|
28242
|
+
case EnumCommentActions.OnCommentUpdated:
|
|
28243
|
+
if (isCommentPending(comment) && !comment.isDeleted) {
|
|
28244
|
+
if (isQueued || !acceptsLiveInserts)
|
|
28245
|
+
return;
|
|
28246
|
+
// Enters (or, after an edit, re-enters) the queue at the end
|
|
28247
|
+
collection.data = [...collection.data, comment.commentId];
|
|
28248
|
+
}
|
|
28249
|
+
else {
|
|
28250
|
+
if (!isQueued)
|
|
28251
|
+
return;
|
|
28252
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
28253
|
+
}
|
|
28254
|
+
break;
|
|
28255
|
+
case EnumCommentActions.OnCommentApproved:
|
|
28256
|
+
case EnumCommentActions.OnCommentDeleted:
|
|
28257
|
+
if (!isQueued)
|
|
28258
|
+
return;
|
|
28259
|
+
collection.data = collection.data.filter(commentId => commentId !== comment.commentId);
|
|
28260
|
+
break;
|
|
28261
|
+
default:
|
|
28262
|
+
return;
|
|
28263
|
+
}
|
|
28264
|
+
pushToCache(this.cacheKey, collection);
|
|
28265
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
28266
|
+
};
|
|
28267
|
+
}
|
|
28268
|
+
subscribeRTE(createSubscriber) {
|
|
28269
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
28270
|
+
}
|
|
28271
|
+
}
|
|
28272
|
+
|
|
28273
|
+
class CommentReviewQueueLiveCollectionController extends LiveCollectionController {
|
|
28274
|
+
constructor(query, callback) {
|
|
28275
|
+
const queryStreamId = hash__default["default"](query);
|
|
28276
|
+
const cacheKey = ['commentReviewQueue', 'collection', queryStreamId];
|
|
28277
|
+
const paginationController = new CommentReviewQueuePaginationController(query);
|
|
28278
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
28279
|
+
this.query = query;
|
|
28280
|
+
this.queryStreamController = new CommentReviewQueueQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this));
|
|
28281
|
+
this.callback = callback.bind(this);
|
|
28282
|
+
this.loadPage({ initial: true });
|
|
28283
|
+
}
|
|
28284
|
+
setup() {
|
|
28285
|
+
var _a;
|
|
28286
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28287
|
+
if (!collection) {
|
|
28288
|
+
pushToCache(this.cacheKey, {
|
|
28289
|
+
data: [],
|
|
28290
|
+
params: {},
|
|
28291
|
+
});
|
|
28292
|
+
}
|
|
28293
|
+
}
|
|
28294
|
+
async persistModel(queryPayload) {
|
|
28295
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
28296
|
+
}
|
|
28297
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
28298
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
28299
|
+
}
|
|
28300
|
+
startSubscription() {
|
|
28301
|
+
// No `comment.declined` exists: a decline arrives as `comment.deleted`
|
|
28302
|
+
return this.queryStreamController.subscribeRTE([
|
|
28303
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
28304
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
28305
|
+
{ fn: onCommentApproved, action: EnumCommentActions.OnCommentApproved },
|
|
28306
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
28307
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
28308
|
+
]);
|
|
28309
|
+
}
|
|
28310
|
+
notifyChange({ origin, loading, error }) {
|
|
28311
|
+
var _a;
|
|
28312
|
+
// A caller who lost REVIEW_COMMUNITY_COMMENT must not keep reading stale pending content
|
|
28313
|
+
if ((error === null || error === void 0 ? void 0 : error.code) === 400301 /* Amity.ServerError.PERMISSION_DENIED */) {
|
|
28314
|
+
pushToCache(this.cacheKey, { data: [], params: {} });
|
|
28315
|
+
}
|
|
28316
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
28317
|
+
if (!collection)
|
|
28318
|
+
return;
|
|
28319
|
+
const data = collection.data
|
|
28320
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
28321
|
+
.filter(isNonNullable)
|
|
28322
|
+
.map(({ data }) => data)
|
|
28323
|
+
.filter(comment => isCommentPending(comment) && !comment.isDeleted)
|
|
28324
|
+
.map(LinkedObject.comment);
|
|
28325
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
28326
|
+
return;
|
|
28327
|
+
this.callback({
|
|
28328
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
28329
|
+
data,
|
|
28330
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
28331
|
+
loading,
|
|
28332
|
+
error,
|
|
28333
|
+
});
|
|
28334
|
+
}
|
|
28335
|
+
}
|
|
28336
|
+
|
|
28337
|
+
/* begin_public_function
|
|
28338
|
+
id: comment.review_queue
|
|
28339
|
+
*/
|
|
28340
|
+
/**
|
|
28341
|
+
* ```js
|
|
28342
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
28343
|
+
*
|
|
28344
|
+
* const unsub = CommentRepository.getCommentReviewQueue(
|
|
28345
|
+
* { communityId: 'communityId' },
|
|
28346
|
+
* ({ data: comments, hasNextPage, onNextPage }) => {
|
|
28347
|
+
* // every comment is awaiting review
|
|
28348
|
+
* },
|
|
28349
|
+
* )
|
|
28350
|
+
* ```
|
|
28351
|
+
*
|
|
28352
|
+
* Observe the {@link Amity.Comment} list awaiting moderator review in a community, oldest first
|
|
28353
|
+
*
|
|
28354
|
+
* @param params the community to read the queue of, optionally narrowed to one post and a date range
|
|
28355
|
+
* @param callback the function to call when new data are available
|
|
28356
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the queue
|
|
28357
|
+
*
|
|
28358
|
+
* @category Comments Live Collection
|
|
28359
|
+
*/
|
|
28360
|
+
const getCommentReviewQueue = (params, callback) => {
|
|
28361
|
+
const { log, cache } = getActiveClient();
|
|
28362
|
+
if (!cache)
|
|
28363
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
28364
|
+
const timestamp = Date.now();
|
|
28365
|
+
log(`getCommentReviewQueue(tmpid: ${timestamp}) > listen`);
|
|
28366
|
+
const commentReviewQueueLiveCollection = new CommentReviewQueueLiveCollectionController(params, callback);
|
|
28367
|
+
const disposers = commentReviewQueueLiveCollection.startSubscription();
|
|
28368
|
+
const cacheKey = commentReviewQueueLiveCollection.getCacheKey();
|
|
28369
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
28370
|
+
return () => {
|
|
28371
|
+
log(`getCommentReviewQueue(tmpid: ${timestamp}) > dispose`);
|
|
28372
|
+
disposers.forEach(fn => fn());
|
|
28373
|
+
};
|
|
28374
|
+
};
|
|
28375
|
+
/* end_public_function */
|
|
28376
|
+
|
|
28377
|
+
var index$f = /*#__PURE__*/Object.freeze({
|
|
26589
28378
|
__proto__: null,
|
|
26590
28379
|
getCommentByIds: getCommentByIds,
|
|
26591
28380
|
createComment: createComment,
|
|
@@ -26593,18 +28382,22 @@ var index$e = /*#__PURE__*/Object.freeze({
|
|
|
26593
28382
|
deleteComment: deleteComment,
|
|
26594
28383
|
softDeleteComment: softDeleteComment,
|
|
26595
28384
|
hardDeleteComment: hardDeleteComment,
|
|
28385
|
+
approveComment: approveComment,
|
|
28386
|
+
declineComment: declineComment,
|
|
26596
28387
|
flagComment: flagComment,
|
|
26597
28388
|
unflagComment: unflagComment,
|
|
26598
28389
|
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
26599
28390
|
onCommentCreated: onCommentCreated,
|
|
26600
28391
|
onCommentUpdated: onCommentUpdated,
|
|
26601
28392
|
onCommentDeleted: onCommentDeleted,
|
|
28393
|
+
onCommentApproved: onCommentApproved,
|
|
26602
28394
|
onCommentFlagged: onCommentFlagged,
|
|
26603
28395
|
onCommentUnflagged: onCommentUnflagged,
|
|
26604
28396
|
onCommentReactionAdded: onCommentReactionAdded,
|
|
26605
28397
|
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
26606
28398
|
getComment: getComment,
|
|
26607
|
-
getComments: getComments
|
|
28399
|
+
getComments: getComments,
|
|
28400
|
+
getCommentReviewQueue: getCommentReviewQueue
|
|
26608
28401
|
});
|
|
26609
28402
|
|
|
26610
28403
|
/**
|
|
@@ -27854,7 +29647,7 @@ const getForYouFeed = (callback) => {
|
|
|
27854
29647
|
};
|
|
27855
29648
|
/* end_public_function */
|
|
27856
29649
|
|
|
27857
|
-
var index$
|
|
29650
|
+
var index$e = /*#__PURE__*/Object.freeze({
|
|
27858
29651
|
__proto__: null,
|
|
27859
29652
|
queryGlobalFeed: queryGlobalFeed,
|
|
27860
29653
|
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
@@ -28258,23 +30051,44 @@ const declinePost = async (postId) => {
|
|
|
28258
30051
|
};
|
|
28259
30052
|
/* end_public_function */
|
|
28260
30053
|
|
|
28261
|
-
/* begin_public_function
|
|
28262
|
-
id: post.flag
|
|
28263
|
-
*/
|
|
28264
30054
|
/**
|
|
28265
|
-
*
|
|
28266
|
-
*
|
|
28267
|
-
*
|
|
28268
|
-
*
|
|
30055
|
+
* New `flagPost(postId, { reason, detail? })` implementation. Any category, including
|
|
30056
|
+
* `Others`, may carry a `detail`. `detail` is forwarded unchanged (empty and
|
|
30057
|
+
* whitespace-only strings included) and omitted from the request body when `undefined`;
|
|
30058
|
+
* the backend enforces the 300-character limit.
|
|
28269
30059
|
*
|
|
28270
|
-
*
|
|
28271
|
-
*
|
|
28272
|
-
* @returns a boolean
|
|
30060
|
+
* Not exported from the public API. It is reached through the
|
|
30061
|
+
* `PostRepository.flagPost(postId, options)` overload; see `flagPost.ts`.
|
|
28273
30062
|
*
|
|
28274
|
-
* @
|
|
28275
|
-
|
|
28276
|
-
|
|
28277
|
-
const
|
|
30063
|
+
* @throws {ASCInvalidParameterError} `INVALID_PARAMETERS` when `options` is malformed, before any request is made
|
|
30064
|
+
*/
|
|
30065
|
+
const flagPostWithOptions = async (postId, options) => {
|
|
30066
|
+
const client = getActiveClient();
|
|
30067
|
+
client.log('post/flagPost', postId);
|
|
30068
|
+
const body = toContentFlagBody(validateContentFlagOptions('flagPost', options));
|
|
30069
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
30070
|
+
if (client.cache) {
|
|
30071
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
30072
|
+
}
|
|
30073
|
+
fireEvent('post.flagged', payload);
|
|
30074
|
+
return !!payload;
|
|
30075
|
+
};
|
|
30076
|
+
|
|
30077
|
+
/**
|
|
30078
|
+
* Legacy `flagPost(postId, reason?)` implementation, kept verbatim so existing
|
|
30079
|
+
* callers keep the exact request body they had before the options contract existed:
|
|
30080
|
+
*
|
|
30081
|
+
* - predefined `ContentFlagReasonEnum` value → `{ reason: <value>, detail: '' }`
|
|
30082
|
+
* - any other non-empty string (including the literal `'Others'`) → `{ reason: 'Others', detail: <string> }`
|
|
30083
|
+
* - `undefined` or `''` → `{ reason: 'Others', detail: '' }`
|
|
30084
|
+
*
|
|
30085
|
+
* Not exported from the public API. It is reached through the deprecated
|
|
30086
|
+
* `PostRepository.flagPost(postId, reason)` overload; see `flagPost.ts`.
|
|
30087
|
+
*
|
|
30088
|
+
* @deprecated Use `flagPostWithOptions` (the `{ reason, detail? }` contract) for new code.
|
|
30089
|
+
* This path stays available throughout the current major version.
|
|
30090
|
+
*/
|
|
30091
|
+
const flagPostWithReasonString = async (postId, reason) => {
|
|
28278
30092
|
const client = getActiveClient();
|
|
28279
30093
|
client.log('post/flagPost', postId);
|
|
28280
30094
|
const isPredefinedReason = reason &&
|
|
@@ -28290,6 +30104,42 @@ const flagPost = async (postId, reason) => {
|
|
|
28290
30104
|
fireEvent('post.flagged', payload);
|
|
28291
30105
|
return !!payload;
|
|
28292
30106
|
};
|
|
30107
|
+
|
|
30108
|
+
/* begin_public_function
|
|
30109
|
+
id: post.flag
|
|
30110
|
+
*/
|
|
30111
|
+
/**
|
|
30112
|
+
* ```js
|
|
30113
|
+
* import { PostRepository, ContentFlagReasonEnum } from '@amityco/ts-sdk'
|
|
30114
|
+
*
|
|
30115
|
+
* // No reason.
|
|
30116
|
+
* await PostRepository.flagPost(postId)
|
|
30117
|
+
*
|
|
30118
|
+
* // Category plus optional reporter context (any category, including Others).
|
|
30119
|
+
* await PostRepository.flagPost(postId, {
|
|
30120
|
+
* reason: ContentFlagReasonEnum.SpamOrScams,
|
|
30121
|
+
* detail: 'Repeated promotional links',
|
|
30122
|
+
* })
|
|
30123
|
+
* ```
|
|
30124
|
+
*
|
|
30125
|
+
* Reports a post to moderation. Three call shapes are accepted (see the overloads):
|
|
30126
|
+
* id-only, an options object, and the deprecated legacy reason string. The public
|
|
30127
|
+
* name only dispatches on the input shape; the two implementations are kept separate
|
|
30128
|
+
* so the legacy path is untouched by the new contract:
|
|
30129
|
+
*
|
|
30130
|
+
* - `undefined` or a string → `flagPostWithReasonString` (unchanged legacy mapping)
|
|
30131
|
+
* - anything else → `flagPostWithOptions` (validated `{ reason, detail? }`)
|
|
30132
|
+
*
|
|
30133
|
+
* @param postId The ID of the post to flag
|
|
30134
|
+
* @param input an options object `{ reason, detail? }`, a legacy reason string, or nothing
|
|
30135
|
+
* @returns `true` when the report was created
|
|
30136
|
+
*
|
|
30137
|
+
* @category Post API
|
|
30138
|
+
* @async
|
|
30139
|
+
* */
|
|
30140
|
+
const flagPost = (postId, input) => isLegacyContentFlagReason(input)
|
|
30141
|
+
? flagPostWithReasonString(postId, input)
|
|
30142
|
+
: flagPostWithOptions(postId, input);
|
|
28293
30143
|
/* end_public_function */
|
|
28294
30144
|
|
|
28295
30145
|
/* begin_public_function
|
|
@@ -30999,7 +32849,7 @@ const getRooms = (params, callback, config) => {
|
|
|
30999
32849
|
};
|
|
31000
32850
|
/* end_public_function */
|
|
31001
32851
|
|
|
31002
|
-
var index$
|
|
32852
|
+
var index$d = /*#__PURE__*/Object.freeze({
|
|
31003
32853
|
__proto__: null,
|
|
31004
32854
|
createRoom: createRoom,
|
|
31005
32855
|
updateRoom: updateRoom,
|
|
@@ -31298,7 +33148,7 @@ const getCommunityLiveRoomPosts = (params, callback, config) => {
|
|
|
31298
33148
|
};
|
|
31299
33149
|
/* end_public_function */
|
|
31300
33150
|
|
|
31301
|
-
var index$
|
|
33151
|
+
var index$c = /*#__PURE__*/Object.freeze({
|
|
31302
33152
|
__proto__: null,
|
|
31303
33153
|
getPostByIds: getPostByIds,
|
|
31304
33154
|
createPost: createPost,
|
|
@@ -31913,7 +33763,7 @@ const getStreams = (params, callback, config) => {
|
|
|
31913
33763
|
};
|
|
31914
33764
|
};
|
|
31915
33765
|
|
|
31916
|
-
var index$
|
|
33766
|
+
var index$b = /*#__PURE__*/Object.freeze({
|
|
31917
33767
|
__proto__: null,
|
|
31918
33768
|
createStream: createStream,
|
|
31919
33769
|
updateStream: updateStream,
|
|
@@ -32216,7 +34066,7 @@ const stopHeartbeat = (roomId) => {
|
|
|
32216
34066
|
};
|
|
32217
34067
|
/* end_public_function */
|
|
32218
34068
|
|
|
32219
|
-
var index$
|
|
34069
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
32220
34070
|
__proto__: null,
|
|
32221
34071
|
getRoomOnlineUsers: getRoomOnlineUsers,
|
|
32222
34072
|
getRoomUserCount: getRoomUserCount,
|
|
@@ -32527,7 +34377,7 @@ const getPoll = (pollId, callback) => {
|
|
|
32527
34377
|
};
|
|
32528
34378
|
/* end_public_function */
|
|
32529
34379
|
|
|
32530
|
-
var index$
|
|
34380
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
32531
34381
|
__proto__: null,
|
|
32532
34382
|
createPoll: createPoll,
|
|
32533
34383
|
closePoll: closePoll,
|
|
@@ -32831,7 +34681,7 @@ const getPlayer = async (parameters) => {
|
|
|
32831
34681
|
return video;
|
|
32832
34682
|
};
|
|
32833
34683
|
|
|
32834
|
-
var index$
|
|
34684
|
+
var index$8 = /*#__PURE__*/Object.freeze({
|
|
32835
34685
|
__proto__: null,
|
|
32836
34686
|
getPlayer: getPlayer
|
|
32837
34687
|
});
|
|
@@ -34004,7 +35854,7 @@ const getGlobalStoryTargets = (params, callback, config) => {
|
|
|
34004
35854
|
};
|
|
34005
35855
|
};
|
|
34006
35856
|
|
|
34007
|
-
var index$
|
|
35857
|
+
var index$7 = /*#__PURE__*/Object.freeze({
|
|
34008
35858
|
__proto__: null,
|
|
34009
35859
|
createImageStory: createImageStory,
|
|
34010
35860
|
createVideoStory: createVideoStory,
|
|
@@ -34041,7 +35891,7 @@ const getNetworkAds = async () => {
|
|
|
34041
35891
|
};
|
|
34042
35892
|
};
|
|
34043
35893
|
|
|
34044
|
-
var index$
|
|
35894
|
+
var index$6 = /*#__PURE__*/Object.freeze({
|
|
34045
35895
|
__proto__: null,
|
|
34046
35896
|
getNetworkAds: getNetworkAds
|
|
34047
35897
|
});
|
|
@@ -34432,7 +36282,7 @@ const markTraySeen = async (lastSeenAt) => {
|
|
|
34432
36282
|
};
|
|
34433
36283
|
/* end_public_function */
|
|
34434
36284
|
|
|
34435
|
-
var index$
|
|
36285
|
+
var index$5 = /*#__PURE__*/Object.freeze({
|
|
34436
36286
|
__proto__: null,
|
|
34437
36287
|
getNotificationTraySeen: getNotificationTraySeen,
|
|
34438
36288
|
getNotificationTrayItems: getNotificationTrayItems,
|
|
@@ -34734,7 +36584,7 @@ const getInvitations = (params, callback) => {
|
|
|
34734
36584
|
};
|
|
34735
36585
|
};
|
|
34736
36586
|
|
|
34737
|
-
var index$
|
|
36587
|
+
var index$4 = /*#__PURE__*/Object.freeze({
|
|
34738
36588
|
__proto__: null,
|
|
34739
36589
|
cancelInvitation: cancelInvitation,
|
|
34740
36590
|
onLocalInvitationCreated: onLocalInvitationCreated,
|
|
@@ -34883,7 +36733,7 @@ const getReactions = (postId, callback) => {
|
|
|
34883
36733
|
};
|
|
34884
36734
|
};
|
|
34885
36735
|
|
|
34886
|
-
var index$
|
|
36736
|
+
var index$3 = /*#__PURE__*/Object.freeze({
|
|
34887
36737
|
__proto__: null,
|
|
34888
36738
|
createReaction: createReaction,
|
|
34889
36739
|
onLiveReactionCreated: onLiveReactionCreated,
|
|
@@ -35366,7 +37216,7 @@ const getMyEvents = (params, callback, config) => {
|
|
|
35366
37216
|
};
|
|
35367
37217
|
};
|
|
35368
37218
|
|
|
35369
|
-
var index$
|
|
37219
|
+
var index$2 = /*#__PURE__*/Object.freeze({
|
|
35370
37220
|
__proto__: null,
|
|
35371
37221
|
createEvent: createEvent,
|
|
35372
37222
|
updateEvent: updateEvent,
|
|
@@ -35593,12 +37443,36 @@ const searchProducts = (params, callback, config) => {
|
|
|
35593
37443
|
};
|
|
35594
37444
|
/* end_public_function */
|
|
35595
37445
|
|
|
35596
|
-
var index = /*#__PURE__*/Object.freeze({
|
|
37446
|
+
var index$1 = /*#__PURE__*/Object.freeze({
|
|
35597
37447
|
__proto__: null,
|
|
35598
37448
|
getProduct: getProduct,
|
|
35599
37449
|
searchProducts: searchProducts
|
|
35600
37450
|
});
|
|
35601
37451
|
|
|
37452
|
+
const getPool = async (topicId, limit) => {
|
|
37453
|
+
const client = getActiveClient();
|
|
37454
|
+
if (!topicId)
|
|
37455
|
+
throw new ASCError('topicId must not be empty', 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
37456
|
+
if (limit !== undefined && (limit < 1 || limit > 100))
|
|
37457
|
+
throw new ASCError('limit must be between 1 and 100', 800110 /* Amity.ClientError.INVALID_PARAMETERS */, "error" /* Amity.ErrorLevel.ERROR */);
|
|
37458
|
+
const { data } = await client.http.get('/api/v5/curated-content/pool', { params: { topicId, limit } });
|
|
37459
|
+
const { topic } = data, payload = __rest(data, ["topic"]);
|
|
37460
|
+
const processedPayload = preparePostPayload(payload);
|
|
37461
|
+
const cachedAt = client.cache && Date.now();
|
|
37462
|
+
if (client.cache) {
|
|
37463
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
37464
|
+
}
|
|
37465
|
+
return {
|
|
37466
|
+
topic: LinkedObject.curatedContentTopic(topic),
|
|
37467
|
+
posts: processedPayload.posts.map(LinkedObject.post),
|
|
37468
|
+
};
|
|
37469
|
+
};
|
|
37470
|
+
|
|
37471
|
+
var index = /*#__PURE__*/Object.freeze({
|
|
37472
|
+
__proto__: null,
|
|
37473
|
+
getPool: getPool
|
|
37474
|
+
});
|
|
37475
|
+
|
|
35602
37476
|
/**
|
|
35603
37477
|
* Helper class for managing product tags per media attachment.
|
|
35604
37478
|
*
|
|
@@ -35647,39 +37521,41 @@ class AmityAttachmentProductTags {
|
|
|
35647
37521
|
}
|
|
35648
37522
|
|
|
35649
37523
|
exports.API_REGIONS = API_REGIONS;
|
|
35650
|
-
exports.AdRepository = index$
|
|
37524
|
+
exports.AdRepository = index$6;
|
|
35651
37525
|
exports.AmityAttachmentProductTags = AmityAttachmentProductTags;
|
|
35652
|
-
exports.
|
|
35653
|
-
exports.
|
|
35654
|
-
exports.
|
|
35655
|
-
exports.
|
|
37526
|
+
exports.AmityModuleNotEntitledError = AmityModuleNotEntitledError;
|
|
37527
|
+
exports.CategoryRepository = index$g;
|
|
37528
|
+
exports.ChannelRepository = index$k;
|
|
37529
|
+
exports.Client = index$t;
|
|
37530
|
+
exports.CommentRepository = index$f;
|
|
35656
37531
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
35657
37532
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
35658
|
-
exports.CommunityRepository = index$
|
|
37533
|
+
exports.CommunityRepository = index$h;
|
|
35659
37534
|
exports.ContentFeedType = ContentFeedType;
|
|
37535
|
+
exports.CuratedContentRepository = index;
|
|
35660
37536
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
35661
|
-
exports.EventRepository = index$
|
|
35662
|
-
exports.FeedRepository = index$
|
|
35663
|
-
exports.FileRepository = index$
|
|
37537
|
+
exports.EventRepository = index$2;
|
|
37538
|
+
exports.FeedRepository = index$e;
|
|
37539
|
+
exports.FileRepository = index$q;
|
|
35664
37540
|
exports.FileType = FileType;
|
|
35665
37541
|
exports.GET_WATCHER_URLS = GET_WATCHER_URLS;
|
|
35666
|
-
exports.InvitationRepository = index$
|
|
35667
|
-
exports.LiveReactionRepository = index$
|
|
35668
|
-
exports.LiveStreamPlayer = index$
|
|
37542
|
+
exports.InvitationRepository = index$4;
|
|
37543
|
+
exports.LiveReactionRepository = index$3;
|
|
37544
|
+
exports.LiveStreamPlayer = index$8;
|
|
35669
37545
|
exports.MessageContentType = MessageContentType;
|
|
35670
|
-
exports.MessageRepository = index$
|
|
35671
|
-
exports.PollRepository = index$
|
|
37546
|
+
exports.MessageRepository = index$o;
|
|
37547
|
+
exports.PollRepository = index$9;
|
|
35672
37548
|
exports.PostContentType = PostContentType;
|
|
35673
|
-
exports.PostRepository = index$
|
|
37549
|
+
exports.PostRepository = index$c;
|
|
35674
37550
|
exports.PostStructureType = PostStructureType;
|
|
35675
|
-
exports.ProductRepository = index;
|
|
35676
|
-
exports.ReactionRepository = index$
|
|
35677
|
-
exports.RoomPresenceRepository = index$
|
|
35678
|
-
exports.RoomRepository = index$
|
|
35679
|
-
exports.StoryRepository = index$
|
|
35680
|
-
exports.StreamRepository = index$
|
|
35681
|
-
exports.SubChannelRepository = index$
|
|
35682
|
-
exports.UserRepository = index$
|
|
37551
|
+
exports.ProductRepository = index$1;
|
|
37552
|
+
exports.ReactionRepository = index$p;
|
|
37553
|
+
exports.RoomPresenceRepository = index$a;
|
|
37554
|
+
exports.RoomRepository = index$d;
|
|
37555
|
+
exports.StoryRepository = index$7;
|
|
37556
|
+
exports.StreamRepository = index$b;
|
|
37557
|
+
exports.SubChannelRepository = index$n;
|
|
37558
|
+
exports.UserRepository = index$r;
|
|
35683
37559
|
exports.VERSION = VERSION;
|
|
35684
37560
|
exports.VideoResolution = VideoResolution;
|
|
35685
37561
|
exports.VideoSize = VideoSize;
|
|
@@ -35741,7 +37617,7 @@ exports.isPaged = isPaged;
|
|
|
35741
37617
|
exports.isReportedByMe = isReportedByMe;
|
|
35742
37618
|
exports.isSkip = isSkip;
|
|
35743
37619
|
exports.mergeInCache = mergeInCache;
|
|
35744
|
-
exports.notificationTray = index$
|
|
37620
|
+
exports.notificationTray = index$5;
|
|
35745
37621
|
exports.onChannelMarkerFetched = onChannelMarkerFetched;
|
|
35746
37622
|
exports.onFeedMarkerFetched = onFeedMarkerFetched;
|
|
35747
37623
|
exports.onFeedMarkerUpdated = onFeedMarkerUpdated;
|
|
@@ -35756,6 +37632,7 @@ exports.pushToCache = pushToCache;
|
|
|
35756
37632
|
exports.queryCache = queryCache;
|
|
35757
37633
|
exports.queryOptions = queryOptions;
|
|
35758
37634
|
exports.queryRoles = queryRoles;
|
|
37635
|
+
exports.resolveModuleAvailability = resolveModuleAvailability;
|
|
35759
37636
|
exports.restoreCache = restoreCache;
|
|
35760
37637
|
exports.runQuery = runQuery;
|
|
35761
37638
|
exports.sortByChannelSegment = sortByChannelSegment;
|