@amityco/ts-sdk 7.8.0 → 7.8.1-1b0200c.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/.env +26 -26
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +4 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts +2 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js +6 -6
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js +2 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js +3 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +2 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +2 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js +60 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js +13 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js +66 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js +45 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js +60 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js +13 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js +66 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js +45 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +3 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +3 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts +6 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js +60 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js +26 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js +5 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js +5 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js +17 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js +2 -50
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts +13 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js +61 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js.map +1 -0
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js +9 -4
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js.map +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
- package/dist/@types/domains/feed.d.ts +4 -0
- package/dist/@types/domains/feed.d.ts.map +1 -1
- package/dist/@types/domains/notification.d.ts +2 -1
- package/dist/@types/domains/notification.d.ts.map +1 -1
- package/dist/core/model/index.d.ts.map +1 -1
- package/dist/feedRepository/api/index.d.ts +0 -1
- package/dist/feedRepository/api/index.d.ts.map +1 -1
- package/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
- package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
- package/dist/feedRepository/index.d.ts +2 -1
- package/dist/feedRepository/index.d.ts.map +1 -1
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
- package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
- package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
- package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
- package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
- package/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
- package/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
- package/dist/feedRepository/observers/index.d.ts +3 -0
- package/dist/feedRepository/observers/index.d.ts.map +1 -0
- package/dist/feedRepository/observers/utils.d.ts +6 -0
- package/dist/feedRepository/observers/utils.d.ts.map +1 -0
- package/dist/index.cjs.js +1608 -1250
- package/dist/index.esm.js +1535 -1177
- package/dist/index.umd.js +4 -4
- package/dist/postRepository/events/utils.d.ts.map +1 -1
- package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
- package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
- package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
- package/dist/postRepository/observers/utils.d.ts +13 -0
- package/dist/postRepository/observers/utils.d.ts.map +1 -0
- package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
- package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
- package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/@types/domains/feed.ts +16 -0
- package/src/@types/domains/notification.ts +1 -0
- package/src/commentRepository/api/deleteComment.ts +6 -6
- package/src/core/model/index.ts +2 -1
- package/src/feedRepository/api/index.ts +0 -1
- package/src/feedRepository/api/queryGlobalFeed.ts +3 -0
- package/src/feedRepository/index.ts +2 -1
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.ts +95 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.ts +25 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.ts +101 -0
- package/src/feedRepository/observers/getCustomRankingGlobalFeed.ts +56 -0
- package/src/feedRepository/observers/getGlobalFeed/LiveCollectionController.ts +91 -0
- package/src/feedRepository/observers/getGlobalFeed/PaginationController.ts +23 -0
- package/src/feedRepository/observers/getGlobalFeed/QueryStreamController.ts +99 -0
- package/src/feedRepository/observers/getGlobalFeed.ts +56 -0
- package/src/feedRepository/observers/index.ts +2 -0
- package/src/feedRepository/observers/utils.ts +85 -0
- package/src/postRepository/events/utils.ts +35 -1
- package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +5 -0
- package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +7 -1
- package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +27 -0
- package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +2 -74
- package/src/postRepository/observers/utils.ts +97 -0
- package/src/reactionRepository/api/addReaction.ts +1 -0
- package/src/reactionRepository/api/removeReaction.ts +1 -0
- package/src/utils/linkedObject/postLinkedObject.ts +3 -3
- package/tsconfig.tsbuildinfo +1 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js +0 -83
- package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js.map +0 -1
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
- package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
- package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +0 -115
package/dist/index.cjs.js
CHANGED
|
@@ -658,7 +658,8 @@ const PAYLOAD2MODEL = {
|
|
|
658
658
|
};
|
|
659
659
|
/** hidden */
|
|
660
660
|
const isOutdated = (prevData, nextData) => {
|
|
661
|
-
|
|
661
|
+
// Check if the new value is outdated.
|
|
662
|
+
if ('updatedAt' in nextData && 'updatedAt' in prevData) {
|
|
662
663
|
return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
|
|
663
664
|
}
|
|
664
665
|
return false;
|
|
@@ -11853,15 +11854,18 @@ function isAmityClipPost(post) {
|
|
|
11853
11854
|
}
|
|
11854
11855
|
|
|
11855
11856
|
const postLinkedObject = (post) => {
|
|
11856
|
-
return
|
|
11857
|
+
return shallowClone(post, {
|
|
11858
|
+
childrenPosts: post.children
|
|
11857
11859
|
.map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
11858
11860
|
.filter(isNonNullable)
|
|
11859
|
-
.map(postLinkedObject),
|
|
11861
|
+
.map(postLinkedObject),
|
|
11862
|
+
analytics: {
|
|
11860
11863
|
markAsViewed: () => {
|
|
11861
11864
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
11862
11865
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
11863
11866
|
},
|
|
11864
|
-
},
|
|
11867
|
+
},
|
|
11868
|
+
get latestComments() {
|
|
11865
11869
|
if (!post.comments)
|
|
11866
11870
|
return [];
|
|
11867
11871
|
return (post.comments
|
|
@@ -11935,7 +11939,8 @@ const postLinkedObject = (post) => {
|
|
|
11935
11939
|
return isAmityClipPost(post)
|
|
11936
11940
|
? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
|
|
11937
11941
|
: undefined;
|
|
11938
|
-
}
|
|
11942
|
+
},
|
|
11943
|
+
});
|
|
11939
11944
|
};
|
|
11940
11945
|
|
|
11941
11946
|
const getCachedMarker = (message) => {
|
|
@@ -14930,7 +14935,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
14930
14935
|
]);
|
|
14931
14936
|
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
14932
14937
|
return true;
|
|
14933
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
|
|
14938
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
|
|
14934
14939
|
if (referenceType === 'comment') {
|
|
14935
14940
|
fireEvent('local.comment.addReaction', {
|
|
14936
14941
|
comment: updatedModel,
|
|
@@ -15053,7 +15058,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
15053
15058
|
]);
|
|
15054
15059
|
if (!model)
|
|
15055
15060
|
return true;
|
|
15056
|
-
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }) });
|
|
15061
|
+
const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
|
|
15057
15062
|
if (referenceType === 'comment') {
|
|
15058
15063
|
fireEvent('local.comment.removeReaction', {
|
|
15059
15064
|
comment: updatedModel,
|
|
@@ -15167,6 +15172,26 @@ const prepareSemanticSearchPostPayload = (_a) => {
|
|
|
15167
15172
|
return Object.assign(Object.assign({}, processedPostPayload), { polls });
|
|
15168
15173
|
};
|
|
15169
15174
|
|
|
15175
|
+
const processDeleteChildPost = (payload) => {
|
|
15176
|
+
var _a;
|
|
15177
|
+
const post = payload.posts[0];
|
|
15178
|
+
if (!post.parentId)
|
|
15179
|
+
return;
|
|
15180
|
+
const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
15181
|
+
if (!parentPost)
|
|
15182
|
+
return;
|
|
15183
|
+
pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
|
|
15184
|
+
};
|
|
15185
|
+
const processCreateChildPost = (payload) => {
|
|
15186
|
+
var _a;
|
|
15187
|
+
const post = payload.posts[0];
|
|
15188
|
+
if (!post.parentId)
|
|
15189
|
+
return;
|
|
15190
|
+
const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
15191
|
+
if (!parentPost)
|
|
15192
|
+
return;
|
|
15193
|
+
pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
|
|
15194
|
+
};
|
|
15170
15195
|
const createPostEventSubscriber = (event, callback) => {
|
|
15171
15196
|
const client = getActiveClient();
|
|
15172
15197
|
const filter = (payload) => {
|
|
@@ -15191,6 +15216,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
15191
15216
|
}
|
|
15192
15217
|
if (event === 'post.deleted') {
|
|
15193
15218
|
const { postId, postedUserId } = payload.posts[0];
|
|
15219
|
+
processDeleteChildPost(payload);
|
|
15194
15220
|
try {
|
|
15195
15221
|
isInTombstone('post', postId);
|
|
15196
15222
|
}
|
|
@@ -15217,6 +15243,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
15217
15243
|
}
|
|
15218
15244
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
15219
15245
|
}
|
|
15246
|
+
if (event === 'post.created')
|
|
15247
|
+
processCreateChildPost(payload);
|
|
15220
15248
|
callback(post.data);
|
|
15221
15249
|
}
|
|
15222
15250
|
};
|
|
@@ -15243,6 +15271,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
|
|
|
15243
15271
|
});
|
|
15244
15272
|
}
|
|
15245
15273
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
15274
|
+
if (event === 'local.post.deleted')
|
|
15275
|
+
processDeleteChildPost(payload);
|
|
15246
15276
|
callback(post.data);
|
|
15247
15277
|
}
|
|
15248
15278
|
};
|
|
@@ -23018,6 +23048,9 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
23018
23048
|
id: feed.query.global_feed
|
|
23019
23049
|
*/
|
|
23020
23050
|
/**
|
|
23051
|
+
*
|
|
23052
|
+
* @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
|
|
23053
|
+
*
|
|
23021
23054
|
* ```js
|
|
23022
23055
|
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
23023
23056
|
* const posts = await queryGlobalFeed()
|
|
@@ -23100,1564 +23133,1914 @@ queryGlobalFeed.locally = (query) => {
|
|
|
23100
23133
|
: undefined;
|
|
23101
23134
|
};
|
|
23102
23135
|
|
|
23103
|
-
|
|
23104
|
-
|
|
23105
|
-
|
|
23106
|
-
|
|
23107
|
-
|
|
23108
|
-
|
|
23109
|
-
|
|
23110
|
-
|
|
23111
|
-
*
|
|
23112
|
-
* Queries a paginable list of {@link Amity.Post} objects
|
|
23113
|
-
*
|
|
23114
|
-
* @param query The query parameters
|
|
23115
|
-
* @returns A page of {@link Amity.Post} objects
|
|
23116
|
-
*
|
|
23117
|
-
* @category Feed API
|
|
23118
|
-
* @async
|
|
23119
|
-
* */
|
|
23120
|
-
const getCustomRankingGlobalFeed = async (query) => {
|
|
23121
|
-
const client = getActiveClient();
|
|
23122
|
-
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
23123
|
-
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
|
|
23124
|
-
const options = (() => {
|
|
23125
|
-
if (queryToken)
|
|
23126
|
-
return { token: queryToken };
|
|
23127
|
-
return undefined;
|
|
23128
|
-
})();
|
|
23129
|
-
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
23130
|
-
params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
|
|
23131
|
-
});
|
|
23132
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
23133
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23134
|
-
const { posts } = data;
|
|
23135
|
-
const cachedAt = client.cache && Date.now();
|
|
23136
|
-
if (client.cache) {
|
|
23137
|
-
ingestInCache(data);
|
|
23138
|
-
const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
23139
|
-
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
23136
|
+
class CustomRankingGlobalFeedPaginationController extends PaginationController {
|
|
23137
|
+
async getRequest(queryParams, token) {
|
|
23138
|
+
const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
23139
|
+
const options = token ? { token } : { limit };
|
|
23140
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
|
|
23141
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
23142
|
+
});
|
|
23143
|
+
return queryResponse;
|
|
23140
23144
|
}
|
|
23141
|
-
|
|
23142
|
-
};
|
|
23143
|
-
/* end_public_function */
|
|
23144
|
-
/**
|
|
23145
|
-
* ```js
|
|
23146
|
-
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
23147
|
-
* const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
|
|
23148
|
-
* ```
|
|
23149
|
-
*
|
|
23150
|
-
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
23151
|
-
*
|
|
23152
|
-
* @param query The query parameters
|
|
23153
|
-
* @returns A page of {@link Amity.Post} objects
|
|
23154
|
-
*
|
|
23155
|
-
* @category Feed API
|
|
23156
|
-
* @async
|
|
23157
|
-
* */
|
|
23158
|
-
getCustomRankingGlobalFeed.locally = (query) => {
|
|
23159
|
-
var _a, _b;
|
|
23160
|
-
const client = getActiveClient();
|
|
23161
|
-
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
23162
|
-
if (!client.cache)
|
|
23163
|
-
return;
|
|
23164
|
-
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
23165
|
-
const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
|
|
23166
|
-
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
23167
|
-
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
23168
|
-
return;
|
|
23169
|
-
const posts = data.posts
|
|
23170
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
23171
|
-
.filter(Boolean)
|
|
23172
|
-
.map(({ data }) => data);
|
|
23173
|
-
const { paging } = data;
|
|
23174
|
-
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
23175
|
-
? { data: posts.map(LinkedObject.post), cachedAt, paging }
|
|
23176
|
-
: undefined;
|
|
23177
|
-
};
|
|
23145
|
+
}
|
|
23178
23146
|
|
|
23179
|
-
var
|
|
23180
|
-
|
|
23181
|
-
|
|
23182
|
-
|
|
23183
|
-
|
|
23147
|
+
var EnumPostActions;
|
|
23148
|
+
(function (EnumPostActions) {
|
|
23149
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
23150
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
23151
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
23152
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
23153
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
23154
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
23155
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
23156
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
23157
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
23158
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
23159
|
+
|
|
23160
|
+
class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
|
|
23161
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23162
|
+
super(query, cacheKey);
|
|
23163
|
+
this.notifyChange = notifyChange;
|
|
23164
|
+
this.preparePayload = preparePayload;
|
|
23165
|
+
}
|
|
23166
|
+
async saveToMainDB(response) {
|
|
23167
|
+
const processedPayload = await this.preparePayload(response);
|
|
23168
|
+
const client = getActiveClient();
|
|
23169
|
+
const cachedAt = client.cache && Date.now();
|
|
23170
|
+
if (client.cache) {
|
|
23171
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23172
|
+
}
|
|
23173
|
+
}
|
|
23174
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23175
|
+
var _a, _b;
|
|
23176
|
+
if (refresh) {
|
|
23177
|
+
pushToCache(this.cacheKey, {
|
|
23178
|
+
data: response.posts.map(getResolver('post')),
|
|
23179
|
+
});
|
|
23180
|
+
}
|
|
23181
|
+
else {
|
|
23182
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23183
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23184
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
23185
|
+
}
|
|
23186
|
+
}
|
|
23187
|
+
reactor(action) {
|
|
23188
|
+
return (post) => {
|
|
23189
|
+
var _a;
|
|
23190
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23191
|
+
if (!collection)
|
|
23192
|
+
return;
|
|
23193
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
23194
|
+
return;
|
|
23195
|
+
// Delete Action
|
|
23196
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
23197
|
+
// Parent Post - Remove from collection
|
|
23198
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
23199
|
+
}
|
|
23200
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
23201
|
+
// If the query has dataTypes array with value, check if post.dataType is include in the array
|
|
23202
|
+
if (this.query.dataTypes && this.query.dataTypes.length > 0) {
|
|
23203
|
+
if (!this.query.dataTypes.includes(post.dataType))
|
|
23204
|
+
return;
|
|
23205
|
+
}
|
|
23206
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
23207
|
+
}
|
|
23208
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
23209
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
23210
|
+
}
|
|
23211
|
+
pushToCache(this.cacheKey, collection);
|
|
23212
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23213
|
+
};
|
|
23214
|
+
}
|
|
23215
|
+
subscribeRTE(createSubscriber) {
|
|
23216
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23217
|
+
}
|
|
23218
|
+
}
|
|
23184
23219
|
|
|
23185
23220
|
/* begin_public_function
|
|
23186
|
-
id:
|
|
23221
|
+
id: comment.get_by_ids
|
|
23187
23222
|
*/
|
|
23188
23223
|
/**
|
|
23189
23224
|
* ```js
|
|
23190
|
-
* import {
|
|
23191
|
-
* const
|
|
23225
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23226
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
23192
23227
|
* ```
|
|
23193
23228
|
*
|
|
23194
|
-
* Fetches a collection of {@link Amity.
|
|
23229
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
23195
23230
|
*
|
|
23196
|
-
* @param
|
|
23197
|
-
* @returns the associated collection of {@link Amity.
|
|
23231
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23232
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23198
23233
|
*
|
|
23199
|
-
* @category
|
|
23234
|
+
* @category Comment API
|
|
23200
23235
|
* @async
|
|
23201
23236
|
*/
|
|
23202
|
-
const
|
|
23237
|
+
const getCommentByIds = async (commentIds) => {
|
|
23203
23238
|
const client = getActiveClient();
|
|
23204
|
-
client.log('
|
|
23205
|
-
const
|
|
23206
|
-
let
|
|
23239
|
+
client.log('comment/getCommentByIds', commentIds);
|
|
23240
|
+
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
23241
|
+
let data;
|
|
23207
23242
|
try {
|
|
23208
23243
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23209
|
-
const response = await client.http.get(`/api/v3/
|
|
23210
|
-
params: {
|
|
23244
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
23245
|
+
params: { commentIds: encodedCommentIds },
|
|
23211
23246
|
});
|
|
23212
|
-
|
|
23247
|
+
data = response.data;
|
|
23213
23248
|
}
|
|
23214
23249
|
catch (error) {
|
|
23215
|
-
|
|
23250
|
+
commentIds.forEach(commentId => {
|
|
23216
23251
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23217
|
-
pushToTombstone('
|
|
23252
|
+
pushToTombstone('comment', commentId);
|
|
23218
23253
|
}
|
|
23219
23254
|
});
|
|
23220
23255
|
throw error;
|
|
23221
23256
|
}
|
|
23222
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23223
23257
|
const cachedAt = client.cache && Date.now();
|
|
23224
23258
|
if (client.cache)
|
|
23225
23259
|
ingestInCache(data, { cachedAt });
|
|
23226
23260
|
return {
|
|
23227
|
-
data: data.
|
|
23261
|
+
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
23228
23262
|
cachedAt,
|
|
23229
23263
|
};
|
|
23230
23264
|
};
|
|
23231
23265
|
/* end_public_function */
|
|
23232
23266
|
/**
|
|
23233
23267
|
* ```js
|
|
23234
|
-
* import {
|
|
23235
|
-
* const
|
|
23268
|
+
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
23269
|
+
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
23236
23270
|
* ```
|
|
23237
23271
|
*
|
|
23238
|
-
* Fetches a collection of {@link Amity.
|
|
23272
|
+
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
23239
23273
|
*
|
|
23240
|
-
* @param
|
|
23241
|
-
* @returns the associated collection of {@link Amity.
|
|
23274
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
23275
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
23242
23276
|
*
|
|
23243
|
-
* @category
|
|
23277
|
+
* @category Comment API
|
|
23244
23278
|
*/
|
|
23245
|
-
|
|
23279
|
+
getCommentByIds.locally = (commentIds) => {
|
|
23246
23280
|
var _a;
|
|
23247
23281
|
const client = getActiveClient();
|
|
23248
|
-
client.log('
|
|
23282
|
+
client.log('comment/getCommentByIds.locally', commentIds);
|
|
23249
23283
|
if (!client.cache)
|
|
23250
23284
|
return;
|
|
23251
|
-
const cached =
|
|
23252
|
-
.map(
|
|
23285
|
+
const cached = commentIds
|
|
23286
|
+
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
23253
23287
|
.filter(Boolean);
|
|
23254
|
-
const
|
|
23288
|
+
const comments = cached.map(({ data }) => data);
|
|
23255
23289
|
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
23256
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) <
|
|
23290
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
23257
23291
|
return;
|
|
23258
23292
|
return {
|
|
23259
|
-
data:
|
|
23293
|
+
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
23260
23294
|
cachedAt: oldest.cachedAt,
|
|
23261
23295
|
};
|
|
23262
23296
|
};
|
|
23263
23297
|
|
|
23264
23298
|
/* begin_public_function
|
|
23265
|
-
id:
|
|
23299
|
+
id: comment.create
|
|
23266
23300
|
*/
|
|
23267
23301
|
/**
|
|
23268
23302
|
* ```js
|
|
23269
|
-
* import {
|
|
23270
|
-
* const
|
|
23271
|
-
* targetType: 'user',
|
|
23272
|
-
* targetId: 'foobar',
|
|
23273
|
-
* data: { text: 'hello world' }
|
|
23274
|
-
* }))
|
|
23303
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23304
|
+
* const newComment = await CommentRepository.createComment(bundle)
|
|
23275
23305
|
* ```
|
|
23276
23306
|
*
|
|
23277
|
-
* Creates an {@link Amity.
|
|
23307
|
+
* Creates an {@link Amity.Comment}
|
|
23278
23308
|
*
|
|
23279
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
23280
|
-
* @returns The newly created {@link Amity.
|
|
23309
|
+
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
23310
|
+
* @returns The newly created {@link Amity.Comment}
|
|
23281
23311
|
*
|
|
23282
|
-
* @category
|
|
23312
|
+
* @category Comment API
|
|
23283
23313
|
* @async
|
|
23284
23314
|
*/
|
|
23285
|
-
const
|
|
23315
|
+
const createComment = async (bundle) => {
|
|
23316
|
+
var _a;
|
|
23286
23317
|
const client = getActiveClient();
|
|
23287
|
-
client.log('
|
|
23288
|
-
|
|
23289
|
-
|
|
23290
|
-
|
|
23291
|
-
|
|
23292
|
-
|
|
23293
|
-
fireEvent('post.created', payload);
|
|
23294
|
-
const data = preparePostPayload(payload);
|
|
23318
|
+
client.log('comment/createComment', bundle);
|
|
23319
|
+
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
23320
|
+
const { comments } = data;
|
|
23321
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
23322
|
+
if (comments.length === 0)
|
|
23323
|
+
throw new Error('Comment not created');
|
|
23295
23324
|
const cachedAt = client.cache && Date.now();
|
|
23296
23325
|
if (client.cache)
|
|
23297
23326
|
ingestInCache(data, { cachedAt });
|
|
23298
|
-
|
|
23299
|
-
|
|
23300
|
-
|
|
23301
|
-
|
|
23302
|
-
|
|
23303
|
-
|
|
23304
|
-
|
|
23305
|
-
|
|
23306
|
-
|
|
23307
|
-
|
|
23327
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
23328
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23329
|
+
if (post) {
|
|
23330
|
+
post.commentsCount += 1;
|
|
23331
|
+
fireEvent('local.post.updated', {
|
|
23332
|
+
posts: [post],
|
|
23333
|
+
categories: [],
|
|
23334
|
+
comments: [],
|
|
23335
|
+
communities: [],
|
|
23336
|
+
communityUsers: data.communityUsers,
|
|
23337
|
+
feeds: [],
|
|
23338
|
+
files: data.files,
|
|
23339
|
+
postChildren: [],
|
|
23340
|
+
users: data.users,
|
|
23341
|
+
videoStreamings: [],
|
|
23342
|
+
});
|
|
23343
|
+
}
|
|
23344
|
+
}
|
|
23345
|
+
else if (bundle.referenceType === 'story') {
|
|
23346
|
+
const storyIndex = pullFromCache([
|
|
23347
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23348
|
+
bundle.referenceId,
|
|
23349
|
+
]);
|
|
23350
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
23351
|
+
const cacheStory = pullFromCache([
|
|
23352
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
23353
|
+
'get',
|
|
23354
|
+
storyIndex.data,
|
|
23355
|
+
]);
|
|
23356
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
23357
|
+
fireEvent('story.updated', {
|
|
23358
|
+
stories: [
|
|
23359
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
23360
|
+
],
|
|
23361
|
+
categories: [],
|
|
23362
|
+
comments,
|
|
23363
|
+
communities: [],
|
|
23364
|
+
communityUsers: data.communityUsers,
|
|
23365
|
+
files: data.files,
|
|
23366
|
+
users: data.users,
|
|
23367
|
+
});
|
|
23368
|
+
}
|
|
23369
|
+
}
|
|
23370
|
+
}
|
|
23371
|
+
fireEvent('local.comment.created', data);
|
|
23372
|
+
return {
|
|
23373
|
+
data: LinkedObject.comment(comments[0]),
|
|
23374
|
+
cachedAt,
|
|
23375
|
+
};
|
|
23376
|
+
};
|
|
23377
|
+
/* end_public_function */
|
|
23378
|
+
|
|
23379
|
+
/* begin_public_function
|
|
23380
|
+
id: comment.update_comment
|
|
23308
23381
|
*/
|
|
23309
23382
|
/**
|
|
23310
23383
|
* ```js
|
|
23311
|
-
* import {
|
|
23312
|
-
* const updated = await
|
|
23384
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23385
|
+
* const updated = await CommentRepository.updateComment(commentId, {
|
|
23313
23386
|
* data: { text: 'hello world' }
|
|
23314
23387
|
* })
|
|
23315
23388
|
* ```
|
|
23316
23389
|
*
|
|
23317
|
-
* Updates an {@link Amity.
|
|
23390
|
+
* Updates an {@link Amity.Comment}
|
|
23318
23391
|
*
|
|
23319
|
-
* @param
|
|
23392
|
+
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
23320
23393
|
* @param patch The patch data to apply
|
|
23321
|
-
* @returns the updated {@link Amity.
|
|
23394
|
+
* @returns the updated {@link Amity.Comment} object
|
|
23322
23395
|
*
|
|
23323
|
-
* @category
|
|
23396
|
+
* @category Comment API
|
|
23324
23397
|
* @async
|
|
23325
23398
|
*/
|
|
23326
|
-
const
|
|
23399
|
+
const updateComment = async (commentId, patch) => {
|
|
23327
23400
|
const client = getActiveClient();
|
|
23328
|
-
client.log('user/
|
|
23329
|
-
const { data
|
|
23330
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23401
|
+
client.log('user/updateComment', patch);
|
|
23402
|
+
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
23331
23403
|
const cachedAt = client.cache && Date.now();
|
|
23332
23404
|
if (client.cache)
|
|
23333
23405
|
ingestInCache(data, { cachedAt });
|
|
23334
|
-
fireEvent('
|
|
23335
|
-
const {
|
|
23406
|
+
fireEvent('comment.updated', data);
|
|
23407
|
+
const { comments } = data;
|
|
23336
23408
|
return {
|
|
23337
|
-
data: LinkedObject.
|
|
23409
|
+
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
23338
23410
|
cachedAt,
|
|
23339
23411
|
};
|
|
23340
23412
|
};
|
|
23341
23413
|
/* end_public_function */
|
|
23342
23414
|
|
|
23415
|
+
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
23416
|
+
const applyMissingField = (rawData, isCreated = false) => {
|
|
23417
|
+
const { storyId, referenceId } = rawData;
|
|
23418
|
+
if (!isCreated) {
|
|
23419
|
+
if (referenceId)
|
|
23420
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
23421
|
+
}
|
|
23422
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
23423
|
+
};
|
|
23424
|
+
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
23425
|
+
const { stories } = data;
|
|
23426
|
+
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
23427
|
+
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
23428
|
+
};
|
|
23429
|
+
|
|
23430
|
+
const getStoryByStoryId$1 = async (storyId) => {
|
|
23431
|
+
const client = getActiveClient();
|
|
23432
|
+
client.log('story/getStoryByStoryId', storyId);
|
|
23433
|
+
// Get story referenceId from cache
|
|
23434
|
+
const cacheReferenceId = pullFromCache([
|
|
23435
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23436
|
+
storyId,
|
|
23437
|
+
]);
|
|
23438
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
23439
|
+
const { data: referenceId } = cacheReferenceId;
|
|
23440
|
+
isInTombstone('story', referenceId);
|
|
23441
|
+
}
|
|
23442
|
+
let data;
|
|
23443
|
+
try {
|
|
23444
|
+
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
23445
|
+
data = convertRawStoryToInternal(response.data);
|
|
23446
|
+
}
|
|
23447
|
+
catch (error) {
|
|
23448
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23449
|
+
pushToTombstone('story', storyId);
|
|
23450
|
+
}
|
|
23451
|
+
throw error;
|
|
23452
|
+
}
|
|
23453
|
+
const cachedAt = client.cache && Date.now();
|
|
23454
|
+
if (client.cache) {
|
|
23455
|
+
ingestInCache(data, { cachedAt });
|
|
23456
|
+
}
|
|
23457
|
+
return {
|
|
23458
|
+
data: data.stories[0],
|
|
23459
|
+
cachedAt,
|
|
23460
|
+
};
|
|
23461
|
+
};
|
|
23462
|
+
getStoryByStoryId$1.locally = (storyId) => {
|
|
23463
|
+
const client = getActiveClient();
|
|
23464
|
+
client.log('story/getStorybyStoryId', storyId);
|
|
23465
|
+
// Get story referenceId from cache
|
|
23466
|
+
const cacheReferenceId = pullFromCache([
|
|
23467
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23468
|
+
storyId,
|
|
23469
|
+
]);
|
|
23470
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
23471
|
+
const { data: referenceId } = cacheReferenceId;
|
|
23472
|
+
isInTombstone('story', referenceId);
|
|
23473
|
+
}
|
|
23474
|
+
const cachedAt = client.cache && Date.now();
|
|
23475
|
+
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
23476
|
+
if (!storyCache)
|
|
23477
|
+
return;
|
|
23478
|
+
return {
|
|
23479
|
+
data: storyCache.data,
|
|
23480
|
+
cachedAt,
|
|
23481
|
+
};
|
|
23482
|
+
};
|
|
23483
|
+
|
|
23484
|
+
/* begin_public_function
|
|
23485
|
+
id: comment.soft_delete, comment.hard_delete
|
|
23486
|
+
*/
|
|
23343
23487
|
/**
|
|
23344
23488
|
* ```js
|
|
23345
|
-
* import {
|
|
23346
|
-
* const success = await
|
|
23489
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23490
|
+
* const success = await CommentRepository.deleteComment('foobar')
|
|
23347
23491
|
* ```
|
|
23348
23492
|
*
|
|
23349
|
-
* Deletes a {@link Amity.
|
|
23493
|
+
* Deletes a {@link Amity.Comment}
|
|
23350
23494
|
*
|
|
23351
|
-
* @param
|
|
23352
|
-
* @return A success boolean if the {@link Amity.
|
|
23495
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23496
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23353
23497
|
*
|
|
23354
|
-
* @
|
|
23498
|
+
* @category Comment API
|
|
23355
23499
|
* @async
|
|
23356
23500
|
*/
|
|
23357
|
-
const
|
|
23501
|
+
const deleteComment = async (commentId, permanent = false) => {
|
|
23358
23502
|
var _a;
|
|
23359
23503
|
const client = getActiveClient();
|
|
23360
|
-
const
|
|
23361
|
-
|
|
23504
|
+
const comment = await getComment$2(commentId);
|
|
23505
|
+
// API-FIX: This endpoint has not been implemented yet.
|
|
23506
|
+
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
23362
23507
|
params: {
|
|
23363
|
-
|
|
23508
|
+
commentId,
|
|
23364
23509
|
permanent,
|
|
23365
23510
|
},
|
|
23366
23511
|
});
|
|
23367
|
-
//
|
|
23368
|
-
|
|
23369
|
-
|
|
23370
|
-
|
|
23371
|
-
|
|
23372
|
-
|
|
23373
|
-
|
|
23374
|
-
|
|
23375
|
-
|
|
23376
|
-
|
|
23377
|
-
|
|
23378
|
-
|
|
23379
|
-
if (key[1] !== 'get')
|
|
23380
|
-
return false;
|
|
23381
|
-
if (typeof key[2] === 'string')
|
|
23382
|
-
return key[2].includes(community.data.communityId);
|
|
23383
|
-
return false;
|
|
23384
|
-
})
|
|
23385
|
-
.map(({ data }) => data);
|
|
23386
|
-
fireEvent('community.updated', {
|
|
23387
|
-
communities: [community.data],
|
|
23512
|
+
// to support hard deletion
|
|
23513
|
+
const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
|
|
23514
|
+
if (permanent) {
|
|
23515
|
+
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
23516
|
+
}
|
|
23517
|
+
else {
|
|
23518
|
+
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
23519
|
+
}
|
|
23520
|
+
if (comment.data.referenceType === 'story') {
|
|
23521
|
+
const story = await getStoryByStoryId$1(comment.data.referenceId);
|
|
23522
|
+
fireEvent('local.story.updated', {
|
|
23523
|
+
stories: [story.data],
|
|
23388
23524
|
categories: [],
|
|
23389
|
-
|
|
23390
|
-
|
|
23525
|
+
comments: [],
|
|
23526
|
+
communities: [],
|
|
23527
|
+
communityUsers: [],
|
|
23391
23528
|
files: [],
|
|
23392
23529
|
users: [],
|
|
23393
23530
|
});
|
|
23394
23531
|
}
|
|
23395
|
-
// to support hard deletion
|
|
23396
|
-
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
23397
|
-
if (permanent) {
|
|
23398
|
-
setTimeout(() => {
|
|
23399
|
-
pushToTombstone('post', postId);
|
|
23400
|
-
}, 0);
|
|
23401
|
-
}
|
|
23402
23532
|
else {
|
|
23403
|
-
|
|
23533
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23534
|
+
if (post) {
|
|
23535
|
+
let removeCount;
|
|
23536
|
+
if (!deleted.parentId) {
|
|
23537
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
23538
|
+
removeCount = deleted.childrenNumber + 1;
|
|
23539
|
+
}
|
|
23540
|
+
else
|
|
23541
|
+
removeCount = 1;
|
|
23542
|
+
post.commentsCount -= removeCount;
|
|
23543
|
+
fireEvent('local.post.updated', {
|
|
23544
|
+
posts: [post],
|
|
23545
|
+
categories: [],
|
|
23546
|
+
comments: [],
|
|
23547
|
+
communities: [],
|
|
23548
|
+
communityUsers: [],
|
|
23549
|
+
feeds: [],
|
|
23550
|
+
files: [],
|
|
23551
|
+
postChildren: [],
|
|
23552
|
+
users: [],
|
|
23553
|
+
videoStreamings: [],
|
|
23554
|
+
});
|
|
23555
|
+
}
|
|
23404
23556
|
}
|
|
23405
|
-
fireEvent('local.
|
|
23406
|
-
|
|
23407
|
-
|
|
23408
|
-
comments: [],
|
|
23409
|
-
communities: [],
|
|
23410
|
-
communityUsers: [],
|
|
23411
|
-
feeds: [],
|
|
23557
|
+
fireEvent('local.comment.deleted', {
|
|
23558
|
+
comments: [deleted],
|
|
23559
|
+
commentChildren: [],
|
|
23412
23560
|
files: [],
|
|
23413
|
-
postChildren: [],
|
|
23414
23561
|
users: [],
|
|
23415
|
-
|
|
23562
|
+
communityUsers: [],
|
|
23416
23563
|
});
|
|
23417
|
-
return
|
|
23418
|
-
};
|
|
23419
|
-
|
|
23420
|
-
/* begin_public_function
|
|
23421
|
-
id: post.soft_delete
|
|
23422
|
-
*/
|
|
23423
|
-
/**
|
|
23424
|
-
* ```js
|
|
23425
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
23426
|
-
* const success = await PostRepository.softDeletePost('foobar')
|
|
23427
|
-
* ```
|
|
23428
|
-
*
|
|
23429
|
-
* Soft deletes a {@link Amity.Post}
|
|
23430
|
-
*
|
|
23431
|
-
* @param postId The {@link Amity.Post} ID to soft delete
|
|
23432
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
23433
|
-
*
|
|
23434
|
-
* @category Post API
|
|
23435
|
-
* @async
|
|
23436
|
-
*/
|
|
23437
|
-
const softDeletePost = async (postId) => {
|
|
23438
|
-
const client = getActiveClient();
|
|
23439
|
-
client.log('post/softDeletePost', postId);
|
|
23440
|
-
const softDeleted = await deletePost(postId, false);
|
|
23441
|
-
return LinkedObject.post(softDeleted);
|
|
23442
|
-
};
|
|
23443
|
-
/* end_public_function */
|
|
23444
|
-
|
|
23445
|
-
/* begin_public_function
|
|
23446
|
-
id: post.hard_delete
|
|
23447
|
-
*/
|
|
23448
|
-
/**
|
|
23449
|
-
* ```js
|
|
23450
|
-
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
23451
|
-
* const success = await hardDeletePost('foobar')
|
|
23452
|
-
* ```
|
|
23453
|
-
*
|
|
23454
|
-
* Hard deletes a {@link Amity.Post}
|
|
23455
|
-
*
|
|
23456
|
-
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
23457
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
23458
|
-
*
|
|
23459
|
-
* @category Post API
|
|
23460
|
-
* @async
|
|
23461
|
-
*/
|
|
23462
|
-
const hardDeletePost = async (postId) => {
|
|
23463
|
-
const client = getActiveClient();
|
|
23464
|
-
client.log('post/hardDeletePost', postId);
|
|
23465
|
-
const hardDeleted = await deletePost(postId, true);
|
|
23466
|
-
return LinkedObject.post(hardDeleted);
|
|
23564
|
+
return deleted;
|
|
23467
23565
|
};
|
|
23468
23566
|
/* end_public_function */
|
|
23469
23567
|
|
|
23470
23568
|
/* begin_public_function
|
|
23471
|
-
id:
|
|
23569
|
+
id: comment.soft_delete
|
|
23472
23570
|
*/
|
|
23473
23571
|
/**
|
|
23474
23572
|
* ```js
|
|
23475
|
-
* import {
|
|
23476
|
-
*
|
|
23477
|
-
* const { data: post } = await approvePost('postId')
|
|
23573
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23574
|
+
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
23478
23575
|
* ```
|
|
23479
23576
|
*
|
|
23480
|
-
*
|
|
23577
|
+
* Deletes a {@link Amity.Comment}
|
|
23481
23578
|
*
|
|
23482
|
-
* @param
|
|
23483
|
-
* @return A {@link Amity.
|
|
23579
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23580
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23484
23581
|
*
|
|
23485
|
-
* @category
|
|
23582
|
+
* @category Comment API
|
|
23486
23583
|
* @async
|
|
23487
23584
|
*/
|
|
23488
|
-
const
|
|
23585
|
+
const softDeleteComment = async (commentId) => {
|
|
23489
23586
|
const client = getActiveClient();
|
|
23490
|
-
client.log('
|
|
23491
|
-
const
|
|
23492
|
-
|
|
23493
|
-
// fire virtual event for community update
|
|
23494
|
-
if (payload.posts[0].targetType === 'community') {
|
|
23495
|
-
fireEvent('community.updated', payload);
|
|
23496
|
-
}
|
|
23497
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23498
|
-
const cachedAt = client.cache && Date.now();
|
|
23499
|
-
if (client.cache)
|
|
23500
|
-
ingestInCache(data, { cachedAt });
|
|
23501
|
-
return {
|
|
23502
|
-
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
23503
|
-
cachedAt,
|
|
23504
|
-
};
|
|
23587
|
+
client.log('comment/softDeleteComment', commentId);
|
|
23588
|
+
const softDeleted = deleteComment(commentId);
|
|
23589
|
+
return softDeleted;
|
|
23505
23590
|
};
|
|
23506
23591
|
/* end_public_function */
|
|
23507
23592
|
|
|
23508
23593
|
/* begin_public_function
|
|
23509
|
-
id:
|
|
23594
|
+
id: comment.hard_delete
|
|
23510
23595
|
*/
|
|
23511
23596
|
/**
|
|
23512
23597
|
* ```js
|
|
23513
|
-
* import {
|
|
23514
|
-
*
|
|
23515
|
-
* const {data: post} = await declinePost('postId')
|
|
23598
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23599
|
+
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
23516
23600
|
* ```
|
|
23517
23601
|
*
|
|
23518
|
-
*
|
|
23602
|
+
* Deletes a {@link Amity.Comment}
|
|
23519
23603
|
*
|
|
23520
|
-
* @param
|
|
23521
|
-
* @return A {@link Amity.
|
|
23604
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
23605
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
23522
23606
|
*
|
|
23523
|
-
* @category
|
|
23607
|
+
* @category Comment API
|
|
23524
23608
|
* @async
|
|
23525
23609
|
*/
|
|
23526
|
-
const
|
|
23610
|
+
const hardDeleteComment = async (commentId) => {
|
|
23527
23611
|
const client = getActiveClient();
|
|
23528
|
-
client.log('
|
|
23529
|
-
const
|
|
23530
|
-
|
|
23531
|
-
if (payload.posts[0].targetType === 'community') {
|
|
23532
|
-
fireEvent('community.updated', payload);
|
|
23533
|
-
}
|
|
23534
|
-
fireEvent('post.declined', payload);
|
|
23535
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23536
|
-
const cachedAt = client.cache && Date.now();
|
|
23537
|
-
if (client.cache)
|
|
23538
|
-
ingestInCache(data, { cachedAt });
|
|
23539
|
-
return {
|
|
23540
|
-
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
23541
|
-
cachedAt,
|
|
23542
|
-
};
|
|
23612
|
+
client.log('comment/hardDeleteComment', commentId);
|
|
23613
|
+
const hardDeleted = deleteComment(commentId, true);
|
|
23614
|
+
return hardDeleted;
|
|
23543
23615
|
};
|
|
23544
23616
|
/* end_public_function */
|
|
23545
23617
|
|
|
23546
23618
|
/* begin_public_function
|
|
23547
|
-
id:
|
|
23619
|
+
id: comment.flag
|
|
23548
23620
|
*/
|
|
23549
23621
|
/**
|
|
23550
23622
|
* ```js
|
|
23551
|
-
* import {
|
|
23552
|
-
* const flagged = await
|
|
23623
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23624
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
23553
23625
|
* ```
|
|
23554
23626
|
*
|
|
23555
|
-
* @param
|
|
23556
|
-
* @param reason the reason to flag the
|
|
23557
|
-
* @returns
|
|
23627
|
+
* @param commentId The ID of the comment to flag
|
|
23628
|
+
* @param reason the reason to flag the comment
|
|
23629
|
+
* @returns the created report result
|
|
23558
23630
|
*
|
|
23559
|
-
* @category
|
|
23631
|
+
* @category Comment API
|
|
23560
23632
|
* @async
|
|
23561
23633
|
* */
|
|
23562
|
-
const
|
|
23634
|
+
const flagComment = async (commentId, reason) => {
|
|
23563
23635
|
const client = getActiveClient();
|
|
23564
|
-
client.log('
|
|
23636
|
+
client.log('comment/flagComment', commentId);
|
|
23565
23637
|
const isPredefinedReason = reason &&
|
|
23566
23638
|
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
23567
23639
|
const body = {
|
|
23568
23640
|
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
23569
23641
|
detail: reason && !isPredefinedReason ? reason : '',
|
|
23570
23642
|
};
|
|
23571
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
23643
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
23572
23644
|
if (client.cache) {
|
|
23573
|
-
ingestInCache(
|
|
23645
|
+
ingestInCache(payload);
|
|
23574
23646
|
}
|
|
23575
|
-
fireEvent('
|
|
23647
|
+
fireEvent('comment.flagged', payload);
|
|
23576
23648
|
return !!payload;
|
|
23577
23649
|
};
|
|
23578
23650
|
/* end_public_function */
|
|
23579
23651
|
|
|
23580
23652
|
/* begin_public_function
|
|
23581
|
-
id:
|
|
23653
|
+
id: comment.unflag
|
|
23582
23654
|
*/
|
|
23583
23655
|
/**
|
|
23584
23656
|
* ```js
|
|
23585
|
-
* import {
|
|
23586
|
-
* const unflagged = await
|
|
23657
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23658
|
+
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
23587
23659
|
* ```
|
|
23588
23660
|
*
|
|
23589
|
-
* @param
|
|
23590
|
-
* @returns the
|
|
23661
|
+
* @param commentId The ID of comment to unflag
|
|
23662
|
+
* @returns the unflagged result
|
|
23591
23663
|
*
|
|
23592
|
-
* @category
|
|
23664
|
+
* @category Comment API
|
|
23593
23665
|
* @async
|
|
23594
23666
|
* */
|
|
23595
|
-
const
|
|
23667
|
+
const unflagComment = async (commentId) => {
|
|
23596
23668
|
const client = getActiveClient();
|
|
23597
|
-
client.log('
|
|
23598
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
23669
|
+
client.log('comment/unflagComment', commentId);
|
|
23670
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
23599
23671
|
if (client.cache) {
|
|
23600
|
-
ingestInCache(
|
|
23672
|
+
ingestInCache(payload);
|
|
23601
23673
|
}
|
|
23602
|
-
fireEvent('
|
|
23674
|
+
fireEvent('comment.unflagged', payload);
|
|
23603
23675
|
return !!payload;
|
|
23604
23676
|
};
|
|
23605
23677
|
/* end_public_function */
|
|
23606
23678
|
|
|
23607
23679
|
/* begin_public_function
|
|
23608
|
-
id:
|
|
23680
|
+
id: comment.check_flag_by_me
|
|
23609
23681
|
*/
|
|
23610
23682
|
/**
|
|
23611
23683
|
* ```js
|
|
23612
|
-
* import {
|
|
23613
|
-
* const isReported = await
|
|
23684
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23685
|
+
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
23614
23686
|
* ```
|
|
23615
23687
|
*
|
|
23616
|
-
* @param
|
|
23617
|
-
* @returns `true` if the
|
|
23688
|
+
* @param commentId The ID of the comment to check if flagged by current user
|
|
23689
|
+
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
23618
23690
|
*
|
|
23619
|
-
* @category
|
|
23691
|
+
* @category Comment API
|
|
23620
23692
|
* @async
|
|
23621
23693
|
* */
|
|
23622
|
-
const
|
|
23694
|
+
const isCommentFlaggedByMe = async (commentId) => {
|
|
23623
23695
|
const client = getActiveClient();
|
|
23624
|
-
client.log('
|
|
23625
|
-
const { data: { result }, } = await client.http.get(`/api/v3/
|
|
23696
|
+
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
23697
|
+
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
23626
23698
|
return result;
|
|
23627
23699
|
};
|
|
23628
23700
|
/* end_public_function */
|
|
23629
23701
|
|
|
23630
|
-
|
|
23631
|
-
id: post.create.clip_post
|
|
23632
|
-
*/
|
|
23633
|
-
/**
|
|
23634
|
-
* ```js
|
|
23635
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
23636
|
-
* const created = await PostRepository.createClipPost({
|
|
23637
|
-
* targetType: 'user',
|
|
23638
|
-
* targetId: 'foobar',
|
|
23639
|
-
* dataType: 'clip',
|
|
23640
|
-
* data: { text: 'hello world' },
|
|
23641
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
23642
|
-
* }))
|
|
23643
|
-
* ```
|
|
23644
|
-
*
|
|
23645
|
-
* Creates an {@link Amity.Post}
|
|
23646
|
-
*
|
|
23647
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
23648
|
-
* @returns The newly created {@link Amity.Post}
|
|
23649
|
-
*
|
|
23650
|
-
* @category Post API
|
|
23651
|
-
* @async
|
|
23652
|
-
*/
|
|
23653
|
-
const createClipPost = async (bundle) => {
|
|
23702
|
+
const getComment$1 = async (commentId) => {
|
|
23654
23703
|
const client = getActiveClient();
|
|
23655
|
-
client.log('
|
|
23656
|
-
|
|
23657
|
-
|
|
23658
|
-
|
|
23704
|
+
client.log('comment/getComment', commentId);
|
|
23705
|
+
isInTombstone('comment', commentId);
|
|
23706
|
+
let data;
|
|
23707
|
+
try {
|
|
23708
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23709
|
+
const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
|
|
23710
|
+
data = response.data;
|
|
23711
|
+
}
|
|
23712
|
+
catch (error) {
|
|
23713
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23714
|
+
pushToTombstone('comment', commentId);
|
|
23715
|
+
}
|
|
23716
|
+
throw error;
|
|
23717
|
+
}
|
|
23659
23718
|
const cachedAt = client.cache && Date.now();
|
|
23660
23719
|
if (client.cache)
|
|
23661
23720
|
ingestInCache(data, { cachedAt });
|
|
23662
|
-
const {
|
|
23721
|
+
const { comments } = data;
|
|
23663
23722
|
return {
|
|
23664
|
-
data:
|
|
23723
|
+
data: comments.find(comment => comment.commentId === commentId),
|
|
23665
23724
|
cachedAt,
|
|
23666
23725
|
};
|
|
23667
23726
|
};
|
|
23668
|
-
|
|
23727
|
+
getComment$1.locally = (commentId) => {
|
|
23728
|
+
const client = getActiveClient();
|
|
23729
|
+
client.log('comment/getComment.locally', commentId);
|
|
23730
|
+
if (!client.cache)
|
|
23731
|
+
return;
|
|
23732
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
23733
|
+
if (!cached)
|
|
23734
|
+
return;
|
|
23735
|
+
return {
|
|
23736
|
+
data: cached.data,
|
|
23737
|
+
cachedAt: cached.cachedAt,
|
|
23738
|
+
};
|
|
23739
|
+
};
|
|
23669
23740
|
|
|
23670
|
-
/* begin_public_function
|
|
23671
|
-
id: comment.get_by_ids
|
|
23672
|
-
*/
|
|
23673
23741
|
/**
|
|
23674
23742
|
* ```js
|
|
23675
|
-
* import {
|
|
23676
|
-
* const
|
|
23743
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
23744
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
23745
|
+
* // ...
|
|
23746
|
+
* })
|
|
23677
23747
|
* ```
|
|
23678
23748
|
*
|
|
23679
|
-
*
|
|
23749
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
23680
23750
|
*
|
|
23681
|
-
* @param
|
|
23682
|
-
* @returns
|
|
23751
|
+
* @param callback The function to call when the event was fired
|
|
23752
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23683
23753
|
*
|
|
23684
|
-
* @category Comment
|
|
23685
|
-
* @async
|
|
23754
|
+
* @category Comment Events
|
|
23686
23755
|
*/
|
|
23687
|
-
const
|
|
23688
|
-
|
|
23689
|
-
client.log('comment/getCommentByIds', commentIds);
|
|
23690
|
-
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
23691
|
-
let data;
|
|
23692
|
-
try {
|
|
23693
|
-
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
23694
|
-
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
23695
|
-
params: { commentIds: encodedCommentIds },
|
|
23696
|
-
});
|
|
23697
|
-
data = response.data;
|
|
23698
|
-
}
|
|
23699
|
-
catch (error) {
|
|
23700
|
-
commentIds.forEach(commentId => {
|
|
23701
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
23702
|
-
pushToTombstone('comment', commentId);
|
|
23703
|
-
}
|
|
23704
|
-
});
|
|
23705
|
-
throw error;
|
|
23706
|
-
}
|
|
23707
|
-
const cachedAt = client.cache && Date.now();
|
|
23708
|
-
if (client.cache)
|
|
23709
|
-
ingestInCache(data, { cachedAt });
|
|
23710
|
-
return {
|
|
23711
|
-
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
23712
|
-
cachedAt,
|
|
23713
|
-
};
|
|
23714
|
-
};
|
|
23715
|
-
/* end_public_function */
|
|
23756
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
23757
|
+
|
|
23716
23758
|
/**
|
|
23717
23759
|
* ```js
|
|
23718
|
-
* import {
|
|
23719
|
-
* const
|
|
23760
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
23761
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
23762
|
+
* // ...
|
|
23763
|
+
* })
|
|
23720
23764
|
* ```
|
|
23721
23765
|
*
|
|
23722
|
-
*
|
|
23766
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
23723
23767
|
*
|
|
23724
|
-
* @param
|
|
23725
|
-
* @returns
|
|
23768
|
+
* @param callback The function to call when the event was fired
|
|
23769
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23726
23770
|
*
|
|
23727
|
-
* @category Comment
|
|
23771
|
+
* @category Comment Events
|
|
23728
23772
|
*/
|
|
23729
|
-
|
|
23730
|
-
var _a;
|
|
23773
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
23731
23774
|
const client = getActiveClient();
|
|
23732
|
-
|
|
23733
|
-
|
|
23734
|
-
|
|
23735
|
-
|
|
23736
|
-
|
|
23737
|
-
|
|
23738
|
-
|
|
23739
|
-
|
|
23740
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
23741
|
-
return;
|
|
23742
|
-
return {
|
|
23743
|
-
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
23744
|
-
cachedAt: oldest.cachedAt,
|
|
23775
|
+
const filter = ({ comment }) => {
|
|
23776
|
+
if (!client.cache) {
|
|
23777
|
+
callback(comment);
|
|
23778
|
+
}
|
|
23779
|
+
else {
|
|
23780
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
23781
|
+
callback(commentLinkedObject(comment));
|
|
23782
|
+
}
|
|
23745
23783
|
};
|
|
23784
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
23746
23785
|
};
|
|
23747
23786
|
|
|
23748
|
-
/* begin_public_function
|
|
23749
|
-
id: comment.create
|
|
23750
|
-
*/
|
|
23751
23787
|
/**
|
|
23752
23788
|
* ```js
|
|
23753
|
-
* import {
|
|
23754
|
-
* const
|
|
23789
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
23790
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
23791
|
+
* // ...
|
|
23792
|
+
* })
|
|
23755
23793
|
* ```
|
|
23756
23794
|
*
|
|
23757
|
-
*
|
|
23795
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
23758
23796
|
*
|
|
23759
|
-
* @param
|
|
23760
|
-
* @returns
|
|
23797
|
+
* @param callback The function to call when the event was fired
|
|
23798
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23761
23799
|
*
|
|
23762
|
-
* @category Comment
|
|
23763
|
-
* @async
|
|
23800
|
+
* @category Comment Events
|
|
23764
23801
|
*/
|
|
23765
|
-
const
|
|
23766
|
-
var _a;
|
|
23802
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
23767
23803
|
const client = getActiveClient();
|
|
23768
|
-
|
|
23769
|
-
|
|
23770
|
-
|
|
23771
|
-
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
23772
|
-
if (comments.length === 0)
|
|
23773
|
-
throw new Error('Comment not created');
|
|
23774
|
-
const cachedAt = client.cache && Date.now();
|
|
23775
|
-
if (client.cache)
|
|
23776
|
-
ingestInCache(data, { cachedAt });
|
|
23777
|
-
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
23778
|
-
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
23779
|
-
if (post) {
|
|
23780
|
-
post.commentsCount += 1;
|
|
23781
|
-
fireEvent('local.post.updated', {
|
|
23782
|
-
posts: [post],
|
|
23783
|
-
categories: [],
|
|
23784
|
-
comments: [],
|
|
23785
|
-
communities: [],
|
|
23786
|
-
communityUsers: data.communityUsers,
|
|
23787
|
-
feeds: [],
|
|
23788
|
-
files: data.files,
|
|
23789
|
-
postChildren: [],
|
|
23790
|
-
users: data.users,
|
|
23791
|
-
videoStreamings: [],
|
|
23792
|
-
});
|
|
23804
|
+
const filter = ({ comment }) => {
|
|
23805
|
+
if (!client.cache) {
|
|
23806
|
+
callback(comment);
|
|
23793
23807
|
}
|
|
23794
|
-
|
|
23795
|
-
|
|
23796
|
-
|
|
23797
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
23798
|
-
bundle.referenceId,
|
|
23799
|
-
]);
|
|
23800
|
-
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
23801
|
-
const cacheStory = pullFromCache([
|
|
23802
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
23803
|
-
'get',
|
|
23804
|
-
storyIndex.data,
|
|
23805
|
-
]);
|
|
23806
|
-
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
23807
|
-
fireEvent('story.updated', {
|
|
23808
|
-
stories: [
|
|
23809
|
-
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
23810
|
-
],
|
|
23811
|
-
categories: [],
|
|
23812
|
-
comments,
|
|
23813
|
-
communities: [],
|
|
23814
|
-
communityUsers: data.communityUsers,
|
|
23815
|
-
files: data.files,
|
|
23816
|
-
users: data.users,
|
|
23817
|
-
});
|
|
23818
|
-
}
|
|
23808
|
+
else {
|
|
23809
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
23810
|
+
callback(commentLinkedObject(comment));
|
|
23819
23811
|
}
|
|
23820
|
-
}
|
|
23821
|
-
fireEvent('local.comment.created', data);
|
|
23822
|
-
return {
|
|
23823
|
-
data: LinkedObject.comment(comments[0]),
|
|
23824
|
-
cachedAt,
|
|
23825
23812
|
};
|
|
23813
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
23826
23814
|
};
|
|
23827
|
-
/* end_public_function */
|
|
23828
23815
|
|
|
23829
23816
|
/* begin_public_function
|
|
23830
|
-
id: comment.
|
|
23817
|
+
id: comment.get
|
|
23831
23818
|
*/
|
|
23832
23819
|
/**
|
|
23833
23820
|
* ```js
|
|
23834
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
23835
|
-
*
|
|
23836
|
-
*
|
|
23837
|
-
*
|
|
23821
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
23822
|
+
*
|
|
23823
|
+
* let comment;
|
|
23824
|
+
*
|
|
23825
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
23826
|
+
* comment = response.data;
|
|
23827
|
+
* });
|
|
23838
23828
|
* ```
|
|
23839
23829
|
*
|
|
23840
|
-
*
|
|
23830
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
23841
23831
|
*
|
|
23842
|
-
* @param commentId
|
|
23843
|
-
* @param
|
|
23844
|
-
* @returns
|
|
23832
|
+
* @param commentId the ID of the comment to observe
|
|
23833
|
+
* @param callback the function to call when new data are available
|
|
23834
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
23845
23835
|
*
|
|
23846
|
-
* @category Comment
|
|
23847
|
-
* @async
|
|
23836
|
+
* @category Comment Live Object
|
|
23848
23837
|
*/
|
|
23849
|
-
const
|
|
23850
|
-
|
|
23851
|
-
|
|
23852
|
-
|
|
23853
|
-
|
|
23854
|
-
|
|
23855
|
-
|
|
23856
|
-
|
|
23857
|
-
|
|
23858
|
-
|
|
23859
|
-
|
|
23860
|
-
|
|
23861
|
-
};
|
|
23838
|
+
const getComment = (commentId, callback) => {
|
|
23839
|
+
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
23840
|
+
onCommentDeleteLocal,
|
|
23841
|
+
onCommentDeleted,
|
|
23842
|
+
onCommentFlagged,
|
|
23843
|
+
onCommentReactionAdded,
|
|
23844
|
+
onCommentReactionRemoved,
|
|
23845
|
+
onCommentUnflagged,
|
|
23846
|
+
onCommentUpdated,
|
|
23847
|
+
onLocalCommentReactionAdded,
|
|
23848
|
+
onLocalCommentReactionRemoved,
|
|
23849
|
+
]);
|
|
23862
23850
|
};
|
|
23863
23851
|
/* end_public_function */
|
|
23864
23852
|
|
|
23865
|
-
|
|
23866
|
-
|
|
23867
|
-
|
|
23868
|
-
|
|
23869
|
-
|
|
23870
|
-
|
|
23853
|
+
class CommentPaginationController extends PaginationController {
|
|
23854
|
+
async getRequest(queryParams, token) {
|
|
23855
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
23856
|
+
const baseOptions = {
|
|
23857
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
23858
|
+
};
|
|
23859
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
23860
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
23861
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
23862
|
+
});
|
|
23863
|
+
return queryResponse;
|
|
23871
23864
|
}
|
|
23872
|
-
|
|
23873
|
-
};
|
|
23874
|
-
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
23875
|
-
const { stories } = data;
|
|
23876
|
-
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
23877
|
-
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
23878
|
-
};
|
|
23865
|
+
}
|
|
23879
23866
|
|
|
23880
|
-
|
|
23881
|
-
|
|
23882
|
-
|
|
23883
|
-
|
|
23884
|
-
|
|
23885
|
-
|
|
23886
|
-
|
|
23887
|
-
]
|
|
23888
|
-
|
|
23889
|
-
|
|
23890
|
-
|
|
23891
|
-
|
|
23892
|
-
|
|
23893
|
-
|
|
23894
|
-
|
|
23895
|
-
|
|
23896
|
-
}
|
|
23897
|
-
|
|
23898
|
-
|
|
23899
|
-
|
|
23900
|
-
|
|
23901
|
-
|
|
23867
|
+
var EnumCommentActions;
|
|
23868
|
+
(function (EnumCommentActions) {
|
|
23869
|
+
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
23870
|
+
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
23871
|
+
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
23872
|
+
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
23873
|
+
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
23874
|
+
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
23875
|
+
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
23876
|
+
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
23877
|
+
|
|
23878
|
+
class CommentQueryStreamController extends QueryStreamController {
|
|
23879
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
23880
|
+
super(query, cacheKey);
|
|
23881
|
+
this.notifyChange = notifyChange;
|
|
23882
|
+
this.preparePayload = preparePayload;
|
|
23883
|
+
}
|
|
23884
|
+
async saveToMainDB(response) {
|
|
23885
|
+
const processedPayload = await this.preparePayload(response);
|
|
23886
|
+
const client = getActiveClient();
|
|
23887
|
+
const cachedAt = client.cache && Date.now();
|
|
23888
|
+
if (client.cache) {
|
|
23889
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
23890
|
+
}
|
|
23902
23891
|
}
|
|
23892
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
23893
|
+
var _a, _b;
|
|
23894
|
+
if (refresh) {
|
|
23895
|
+
pushToCache(this.cacheKey, {
|
|
23896
|
+
data: response.comments.map(getResolver('comment')),
|
|
23897
|
+
});
|
|
23898
|
+
}
|
|
23899
|
+
else {
|
|
23900
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23901
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
23902
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
23903
|
+
}
|
|
23904
|
+
}
|
|
23905
|
+
reactor(action) {
|
|
23906
|
+
return (comment) => {
|
|
23907
|
+
var _a;
|
|
23908
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23909
|
+
if (this.query.referenceId !== comment.referenceId ||
|
|
23910
|
+
this.query.referenceType !== comment.referenceType ||
|
|
23911
|
+
!collection) {
|
|
23912
|
+
return;
|
|
23913
|
+
}
|
|
23914
|
+
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
23915
|
+
return;
|
|
23916
|
+
}
|
|
23917
|
+
if (!this.query.parentId && comment.parentId) {
|
|
23918
|
+
return;
|
|
23919
|
+
}
|
|
23920
|
+
if (action === EnumCommentActions.OnCommentCreated) {
|
|
23921
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
23922
|
+
}
|
|
23923
|
+
pushToCache(this.cacheKey, collection);
|
|
23924
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
23925
|
+
};
|
|
23926
|
+
}
|
|
23927
|
+
subscribeRTE(createSubscriber) {
|
|
23928
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
23929
|
+
}
|
|
23930
|
+
}
|
|
23931
|
+
|
|
23932
|
+
/**
|
|
23933
|
+
* ```js
|
|
23934
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
23935
|
+
* const dispose = onCommentCreated(comment => {
|
|
23936
|
+
* // ...
|
|
23937
|
+
* })
|
|
23938
|
+
* ```
|
|
23939
|
+
*
|
|
23940
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
23941
|
+
*
|
|
23942
|
+
* @param callback The function to call when the event was fired
|
|
23943
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
23944
|
+
*
|
|
23945
|
+
* @category Comment Events
|
|
23946
|
+
*/
|
|
23947
|
+
const onCommentCreatedLocal = (callback) => {
|
|
23948
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
23949
|
+
};
|
|
23950
|
+
|
|
23951
|
+
class CommentLiveCollectionController extends LiveCollectionController {
|
|
23952
|
+
constructor(query, callback) {
|
|
23953
|
+
const queryStreamId = hash__default["default"](query);
|
|
23954
|
+
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
23955
|
+
const paginationController = new CommentPaginationController(query);
|
|
23956
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
23957
|
+
this.query = query;
|
|
23958
|
+
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
23959
|
+
this.callback = callback.bind(this);
|
|
23960
|
+
this.loadPage({ initial: true });
|
|
23961
|
+
}
|
|
23962
|
+
setup() {
|
|
23963
|
+
var _a;
|
|
23964
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23965
|
+
if (!collection) {
|
|
23966
|
+
pushToCache(this.cacheKey, {
|
|
23967
|
+
data: [],
|
|
23968
|
+
params: {},
|
|
23969
|
+
});
|
|
23970
|
+
}
|
|
23971
|
+
}
|
|
23972
|
+
async persistModel(queryPayload) {
|
|
23973
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
23974
|
+
}
|
|
23975
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
23976
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
23977
|
+
}
|
|
23978
|
+
startSubscription() {
|
|
23979
|
+
return this.queryStreamController.subscribeRTE([
|
|
23980
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
23981
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
23982
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
23983
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
23984
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
23985
|
+
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
23986
|
+
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
23987
|
+
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
23988
|
+
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
23989
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
23990
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
23991
|
+
]);
|
|
23992
|
+
}
|
|
23993
|
+
notifyChange({ origin, loading, error }) {
|
|
23994
|
+
var _a, _b;
|
|
23995
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
23996
|
+
if (!collection)
|
|
23997
|
+
return;
|
|
23998
|
+
const data = this.applyFilter((_b = collection.data
|
|
23999
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
24000
|
+
.filter(isNonNullable)
|
|
24001
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
24002
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24003
|
+
return;
|
|
24004
|
+
this.callback({
|
|
24005
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24006
|
+
data,
|
|
24007
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24008
|
+
loading,
|
|
24009
|
+
error,
|
|
24010
|
+
});
|
|
24011
|
+
}
|
|
24012
|
+
applyFilter(data) {
|
|
24013
|
+
let comments = data;
|
|
24014
|
+
if (!this.query.includeDeleted) {
|
|
24015
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
24016
|
+
}
|
|
24017
|
+
if (this.query.parentId) {
|
|
24018
|
+
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
24019
|
+
}
|
|
24020
|
+
if (typeof this.query.hasFlag === 'boolean') {
|
|
24021
|
+
if (this.query.hasFlag) {
|
|
24022
|
+
comments = comments.filter(comment => comment.hashFlag != null);
|
|
24023
|
+
}
|
|
24024
|
+
else {
|
|
24025
|
+
comments = comments.filter(comment => comment.hashFlag == null);
|
|
24026
|
+
}
|
|
24027
|
+
}
|
|
24028
|
+
if (this.query.dataTypes) {
|
|
24029
|
+
if (this.query.dataTypes.matchType === 'exact') {
|
|
24030
|
+
comments = comments.filter(comment => {
|
|
24031
|
+
var _a, _b;
|
|
24032
|
+
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
24033
|
+
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
24034
|
+
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
24035
|
+
return false;
|
|
24036
|
+
}
|
|
24037
|
+
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
24038
|
+
});
|
|
24039
|
+
}
|
|
24040
|
+
if (this.query.dataTypes.matchType === 'any') {
|
|
24041
|
+
comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
|
|
24042
|
+
}
|
|
24043
|
+
}
|
|
24044
|
+
switch (this.query.sortBy) {
|
|
24045
|
+
case 'firstCreated':
|
|
24046
|
+
comments = comments.sort(sortByFirstCreated);
|
|
24047
|
+
break;
|
|
24048
|
+
case 'lastCreated':
|
|
24049
|
+
default:
|
|
24050
|
+
comments = comments.sort(sortByLastCreated);
|
|
24051
|
+
break;
|
|
24052
|
+
}
|
|
24053
|
+
return comments;
|
|
24054
|
+
}
|
|
24055
|
+
}
|
|
24056
|
+
|
|
24057
|
+
/* begin_public_function
|
|
24058
|
+
id: comment.query
|
|
24059
|
+
*/
|
|
24060
|
+
/**
|
|
24061
|
+
* ```js
|
|
24062
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
24063
|
+
*
|
|
24064
|
+
* let comments = []
|
|
24065
|
+
* const unsub = getComments({
|
|
24066
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
24067
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
24068
|
+
* }, response => merge(comments, response.data))
|
|
24069
|
+
* ```
|
|
24070
|
+
*
|
|
24071
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
24072
|
+
*
|
|
24073
|
+
* @param referenceType the type of the target
|
|
24074
|
+
* @param referenceId the ID of the target
|
|
24075
|
+
* @param callback the function to call when new data are available
|
|
24076
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
24077
|
+
*
|
|
24078
|
+
* @category Comments Live Collection
|
|
24079
|
+
*/
|
|
24080
|
+
const getComments = (params, callback, config) => {
|
|
24081
|
+
const { log, cache } = getActiveClient();
|
|
24082
|
+
if (!cache) {
|
|
24083
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
24084
|
+
}
|
|
24085
|
+
const timestamp = Date.now();
|
|
24086
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
24087
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
24088
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
24089
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
24090
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
24091
|
+
return () => {
|
|
24092
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
24093
|
+
disposers.forEach(fn => fn());
|
|
24094
|
+
};
|
|
24095
|
+
};
|
|
24096
|
+
/* end_public_function */
|
|
24097
|
+
|
|
24098
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
24099
|
+
__proto__: null,
|
|
24100
|
+
getCommentByIds: getCommentByIds,
|
|
24101
|
+
createComment: createComment,
|
|
24102
|
+
updateComment: updateComment,
|
|
24103
|
+
deleteComment: deleteComment,
|
|
24104
|
+
softDeleteComment: softDeleteComment,
|
|
24105
|
+
hardDeleteComment: hardDeleteComment,
|
|
24106
|
+
flagComment: flagComment,
|
|
24107
|
+
unflagComment: unflagComment,
|
|
24108
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
24109
|
+
onCommentCreated: onCommentCreated,
|
|
24110
|
+
onCommentUpdated: onCommentUpdated,
|
|
24111
|
+
onCommentDeleted: onCommentDeleted,
|
|
24112
|
+
onCommentFlagged: onCommentFlagged,
|
|
24113
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
24114
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
24115
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
24116
|
+
getComment: getComment,
|
|
24117
|
+
getComments: getComments
|
|
24118
|
+
});
|
|
24119
|
+
|
|
24120
|
+
const getPost$1 = async (postId) => {
|
|
24121
|
+
const client = getActiveClient();
|
|
24122
|
+
client.log('post/getPost', postId);
|
|
24123
|
+
isInTombstone('post', postId);
|
|
24124
|
+
let payload;
|
|
24125
|
+
try {
|
|
24126
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24127
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
24128
|
+
payload = response.data;
|
|
24129
|
+
}
|
|
24130
|
+
catch (error) {
|
|
24131
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24132
|
+
pushToTombstone('post', postId);
|
|
24133
|
+
}
|
|
24134
|
+
throw error;
|
|
24135
|
+
}
|
|
24136
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
23903
24137
|
const cachedAt = client.cache && Date.now();
|
|
23904
|
-
if (client.cache)
|
|
24138
|
+
if (client.cache)
|
|
23905
24139
|
ingestInCache(data, { cachedAt });
|
|
23906
|
-
}
|
|
24140
|
+
const { posts } = data;
|
|
24141
|
+
const result = posts.find(post => post.postId === postId);
|
|
23907
24142
|
return {
|
|
23908
|
-
data:
|
|
24143
|
+
data: result,
|
|
23909
24144
|
cachedAt,
|
|
23910
24145
|
};
|
|
23911
24146
|
};
|
|
23912
|
-
|
|
23913
|
-
const client = getActiveClient();
|
|
23914
|
-
client.log('
|
|
23915
|
-
|
|
23916
|
-
|
|
23917
|
-
|
|
23918
|
-
|
|
23919
|
-
|
|
23920
|
-
|
|
23921
|
-
|
|
23922
|
-
|
|
23923
|
-
}
|
|
23924
|
-
|
|
23925
|
-
|
|
23926
|
-
|
|
23927
|
-
|
|
23928
|
-
|
|
23929
|
-
|
|
23930
|
-
|
|
23931
|
-
|
|
24147
|
+
getPost$1.locally = (postId) => {
|
|
24148
|
+
const client = getActiveClient();
|
|
24149
|
+
client.log('post/getPost.locally', postId);
|
|
24150
|
+
if (!client.cache)
|
|
24151
|
+
return;
|
|
24152
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
24153
|
+
if (!cached)
|
|
24154
|
+
return;
|
|
24155
|
+
return {
|
|
24156
|
+
data: cached.data,
|
|
24157
|
+
cachedAt: cached.cachedAt,
|
|
24158
|
+
};
|
|
24159
|
+
};
|
|
24160
|
+
|
|
24161
|
+
/**
|
|
24162
|
+
* ```js
|
|
24163
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
24164
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
24165
|
+
* // ...
|
|
24166
|
+
* })
|
|
24167
|
+
* ```
|
|
24168
|
+
*
|
|
24169
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
24170
|
+
*
|
|
24171
|
+
* @param callback The function to call when the event was fired
|
|
24172
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24173
|
+
*
|
|
24174
|
+
* @category Post Events
|
|
24175
|
+
*/
|
|
24176
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
24177
|
+
|
|
24178
|
+
/**
|
|
24179
|
+
* ```js
|
|
24180
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
24181
|
+
* const dispose = onPostReactionAdded(post => {
|
|
24182
|
+
* // ...
|
|
24183
|
+
* })
|
|
24184
|
+
* ```
|
|
24185
|
+
*
|
|
24186
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
24187
|
+
*
|
|
24188
|
+
* @param callback The function to call when the event was fired
|
|
24189
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24190
|
+
*
|
|
24191
|
+
* @category Post Events
|
|
24192
|
+
*/
|
|
24193
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
24194
|
+
const client = getActiveClient();
|
|
24195
|
+
const filter = ({ post }) => {
|
|
24196
|
+
if (!client.cache) {
|
|
24197
|
+
callback(post);
|
|
24198
|
+
}
|
|
24199
|
+
else {
|
|
24200
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
24201
|
+
callback(post);
|
|
24202
|
+
}
|
|
24203
|
+
};
|
|
24204
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
24205
|
+
};
|
|
24206
|
+
|
|
24207
|
+
/**
|
|
24208
|
+
* ```js
|
|
24209
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
24210
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
24211
|
+
* // ...
|
|
24212
|
+
* })
|
|
24213
|
+
* ```
|
|
24214
|
+
*
|
|
24215
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
24216
|
+
*
|
|
24217
|
+
* @param callback The function to call when the event was fired
|
|
24218
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24219
|
+
*
|
|
24220
|
+
* @category Post Events
|
|
24221
|
+
*/
|
|
24222
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
24223
|
+
const client = getActiveClient();
|
|
24224
|
+
const filter = ({ post }) => {
|
|
24225
|
+
if (!client.cache) {
|
|
24226
|
+
callback(post);
|
|
24227
|
+
}
|
|
24228
|
+
else {
|
|
24229
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
24230
|
+
callback(post);
|
|
24231
|
+
}
|
|
24232
|
+
};
|
|
24233
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
24234
|
+
};
|
|
24235
|
+
|
|
24236
|
+
/**
|
|
24237
|
+
* ```js
|
|
24238
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
24239
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
24240
|
+
* // ...
|
|
24241
|
+
* })
|
|
24242
|
+
* ```
|
|
24243
|
+
*
|
|
24244
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
24245
|
+
*
|
|
24246
|
+
* @param callback The function to call when the event was fired
|
|
24247
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24248
|
+
*
|
|
24249
|
+
* @category Post Events
|
|
24250
|
+
*/
|
|
24251
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
24252
|
+
|
|
24253
|
+
const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
|
|
24254
|
+
return eventHandler(async (comment) => {
|
|
24255
|
+
var _a;
|
|
24256
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24257
|
+
if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
|
|
24258
|
+
return;
|
|
24259
|
+
await getPost$1(comment.referenceId);
|
|
24260
|
+
callback(comment);
|
|
24261
|
+
});
|
|
24262
|
+
};
|
|
24263
|
+
const generateCommentSubscriptions$1 = (cacheKey) => {
|
|
24264
|
+
const eventHandlers = [
|
|
24265
|
+
onCommentCreated,
|
|
24266
|
+
onCommentDeleted,
|
|
24267
|
+
onCommentReactionAdded,
|
|
24268
|
+
onCommentReactionRemoved,
|
|
24269
|
+
onCommentCreatedLocal,
|
|
24270
|
+
onCommentDeleteLocal,
|
|
24271
|
+
onLocalCommentReactionAdded,
|
|
24272
|
+
onLocalCommentReactionRemoved,
|
|
24273
|
+
];
|
|
24274
|
+
return eventHandlers.map(handler => ({
|
|
24275
|
+
fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
|
|
24276
|
+
action: EnumPostActions.OnPostUpdated,
|
|
24277
|
+
}));
|
|
24278
|
+
};
|
|
24279
|
+
const getGlobalFeedSubscriptions = (cacheKey) => {
|
|
24280
|
+
return [
|
|
24281
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
24282
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
24283
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
24284
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24285
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
24286
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
24287
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
24288
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
24289
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24290
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24291
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24292
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24293
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24294
|
+
...generateCommentSubscriptions$1(cacheKey),
|
|
24295
|
+
];
|
|
23932
24296
|
};
|
|
23933
24297
|
|
|
24298
|
+
class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
|
|
24299
|
+
constructor(query, callback) {
|
|
24300
|
+
const queryStreamId = hash__default["default"](query);
|
|
24301
|
+
const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
|
|
24302
|
+
const paginationController = new CustomRankingGlobalFeedPaginationController(query);
|
|
24303
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24304
|
+
this.query = query;
|
|
24305
|
+
this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
24306
|
+
this.callback = callback.bind(this);
|
|
24307
|
+
this.loadPage({ initial: true });
|
|
24308
|
+
}
|
|
24309
|
+
setup() {
|
|
24310
|
+
var _a;
|
|
24311
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24312
|
+
if (!collection) {
|
|
24313
|
+
pushToCache(this.cacheKey, {
|
|
24314
|
+
data: [],
|
|
24315
|
+
params: {},
|
|
24316
|
+
});
|
|
24317
|
+
}
|
|
24318
|
+
}
|
|
24319
|
+
async persistModel(queryPayload) {
|
|
24320
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24321
|
+
}
|
|
24322
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24323
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24324
|
+
}
|
|
24325
|
+
startSubscription() {
|
|
24326
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
24327
|
+
}
|
|
24328
|
+
notifyChange({ origin, loading, error }) {
|
|
24329
|
+
var _a, _b;
|
|
24330
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24331
|
+
if (!collection)
|
|
24332
|
+
return;
|
|
24333
|
+
const data = ((_b = collection.data
|
|
24334
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
24335
|
+
.filter(isNonNullable)
|
|
24336
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
24337
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24338
|
+
return;
|
|
24339
|
+
this.callback({
|
|
24340
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24341
|
+
data,
|
|
24342
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24343
|
+
loading,
|
|
24344
|
+
error,
|
|
24345
|
+
});
|
|
24346
|
+
}
|
|
24347
|
+
}
|
|
24348
|
+
|
|
23934
24349
|
/* begin_public_function
|
|
23935
|
-
id:
|
|
24350
|
+
id: feed.query.custom_ranking_feed
|
|
23936
24351
|
*/
|
|
23937
24352
|
/**
|
|
23938
24353
|
* ```js
|
|
23939
|
-
* import {
|
|
23940
|
-
*
|
|
24354
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
24355
|
+
*
|
|
24356
|
+
* let posts = []
|
|
24357
|
+
* const unsub = FeedRepository.getGlobalFeed({
|
|
24358
|
+
* dataTypes: ['video','image'],
|
|
24359
|
+
* resolveParent: true,
|
|
24360
|
+
* }, response => processResponse(response))
|
|
23941
24361
|
* ```
|
|
23942
24362
|
*
|
|
23943
|
-
*
|
|
24363
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
23944
24364
|
*
|
|
23945
|
-
* @param
|
|
23946
|
-
* @
|
|
24365
|
+
* @param params.dataTypes array of data types for the posts
|
|
24366
|
+
* @param callback the function to call when new data are available
|
|
24367
|
+
* @param config
|
|
24368
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
23947
24369
|
*
|
|
23948
|
-
* @category
|
|
23949
|
-
* @async
|
|
24370
|
+
* @category Posts Live Collection
|
|
23950
24371
|
*/
|
|
23951
|
-
const
|
|
23952
|
-
|
|
23953
|
-
|
|
23954
|
-
|
|
23955
|
-
|
|
23956
|
-
|
|
23957
|
-
|
|
23958
|
-
|
|
23959
|
-
|
|
23960
|
-
|
|
23961
|
-
|
|
23962
|
-
|
|
23963
|
-
|
|
23964
|
-
|
|
23965
|
-
|
|
23966
|
-
|
|
23967
|
-
|
|
23968
|
-
|
|
23969
|
-
|
|
23970
|
-
|
|
23971
|
-
|
|
23972
|
-
|
|
23973
|
-
|
|
24372
|
+
const getCustomRankingGlobalFeed = (params, callback, config) => {
|
|
24373
|
+
const { log, cache } = getActiveClient();
|
|
24374
|
+
if (!cache) {
|
|
24375
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24376
|
+
}
|
|
24377
|
+
const timestamp = Date.now();
|
|
24378
|
+
log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
|
|
24379
|
+
const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
|
|
24380
|
+
const disposers = liveCollection.startSubscription();
|
|
24381
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
24382
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
24383
|
+
return () => {
|
|
24384
|
+
log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
|
|
24385
|
+
disposers.forEach(fn => fn());
|
|
24386
|
+
};
|
|
24387
|
+
};
|
|
24388
|
+
/* end_public_function */
|
|
24389
|
+
|
|
24390
|
+
class GlobalFeedPaginationController extends PaginationController {
|
|
24391
|
+
async getRequest(queryParams, token) {
|
|
24392
|
+
const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
|
|
24393
|
+
const options = token ? { token } : { limit };
|
|
24394
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
|
|
24395
|
+
params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
|
|
23974
24396
|
});
|
|
24397
|
+
return queryResponse;
|
|
23975
24398
|
}
|
|
23976
|
-
|
|
23977
|
-
|
|
23978
|
-
|
|
23979
|
-
|
|
23980
|
-
|
|
23981
|
-
|
|
23982
|
-
|
|
24399
|
+
}
|
|
24400
|
+
|
|
24401
|
+
class GlobalFeedQueryStreamController extends QueryStreamController {
|
|
24402
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24403
|
+
super(query, cacheKey);
|
|
24404
|
+
this.notifyChange = notifyChange;
|
|
24405
|
+
this.preparePayload = preparePayload;
|
|
24406
|
+
}
|
|
24407
|
+
async saveToMainDB(response) {
|
|
24408
|
+
const processedPayload = await this.preparePayload(response);
|
|
24409
|
+
const client = getActiveClient();
|
|
24410
|
+
const cachedAt = client.cache && Date.now();
|
|
24411
|
+
if (client.cache) {
|
|
24412
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
24413
|
+
}
|
|
24414
|
+
}
|
|
24415
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
24416
|
+
var _a, _b;
|
|
24417
|
+
if (refresh) {
|
|
24418
|
+
pushToCache(this.cacheKey, {
|
|
24419
|
+
data: response.posts.map(getResolver('post')),
|
|
24420
|
+
});
|
|
24421
|
+
}
|
|
24422
|
+
else {
|
|
24423
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24424
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24425
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
24426
|
+
}
|
|
24427
|
+
}
|
|
24428
|
+
reactor(action) {
|
|
24429
|
+
return (post) => {
|
|
24430
|
+
var _a;
|
|
24431
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24432
|
+
if (!collection)
|
|
24433
|
+
return;
|
|
24434
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
24435
|
+
return;
|
|
24436
|
+
// Delete Action
|
|
24437
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
24438
|
+
// Parent Post - Remove from collection
|
|
24439
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
23983
24440
|
}
|
|
23984
|
-
|
|
23985
|
-
|
|
23986
|
-
|
|
23987
|
-
|
|
23988
|
-
|
|
23989
|
-
|
|
23990
|
-
|
|
23991
|
-
|
|
23992
|
-
|
|
23993
|
-
|
|
23994
|
-
|
|
23995
|
-
|
|
23996
|
-
|
|
23997
|
-
|
|
24441
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
24442
|
+
// If the query has dataTypes array with value, check if post.dataType is include in the array
|
|
24443
|
+
if (this.query.dataTypes && this.query.dataTypes.length > 0) {
|
|
24444
|
+
if (!this.query.dataTypes.includes(post.dataType))
|
|
24445
|
+
return;
|
|
24446
|
+
}
|
|
24447
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
24448
|
+
}
|
|
24449
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
24450
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
24451
|
+
}
|
|
24452
|
+
pushToCache(this.cacheKey, collection);
|
|
24453
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24454
|
+
};
|
|
24455
|
+
}
|
|
24456
|
+
subscribeRTE(createSubscriber) {
|
|
24457
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24458
|
+
}
|
|
24459
|
+
}
|
|
24460
|
+
|
|
24461
|
+
class GlobalFeedLiveCollectionController extends LiveCollectionController {
|
|
24462
|
+
constructor(query, callback) {
|
|
24463
|
+
const queryStreamId = hash__default["default"](query);
|
|
24464
|
+
const cacheKey = ['globalFeed', 'collection', queryStreamId];
|
|
24465
|
+
const paginationController = new GlobalFeedPaginationController(query);
|
|
24466
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
24467
|
+
this.query = query;
|
|
24468
|
+
this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
24469
|
+
this.callback = callback.bind(this);
|
|
24470
|
+
this.loadPage({ initial: true });
|
|
24471
|
+
}
|
|
24472
|
+
setup() {
|
|
24473
|
+
var _a;
|
|
24474
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24475
|
+
if (!collection) {
|
|
24476
|
+
pushToCache(this.cacheKey, {
|
|
24477
|
+
data: [],
|
|
24478
|
+
params: {},
|
|
23998
24479
|
});
|
|
23999
24480
|
}
|
|
24000
24481
|
}
|
|
24001
|
-
|
|
24002
|
-
|
|
24003
|
-
commentChildren: [],
|
|
24004
|
-
files: [],
|
|
24005
|
-
users: [],
|
|
24006
|
-
communityUsers: [],
|
|
24007
|
-
});
|
|
24008
|
-
if (permanent) {
|
|
24009
|
-
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
24482
|
+
async persistModel(queryPayload) {
|
|
24483
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
24010
24484
|
}
|
|
24011
|
-
|
|
24012
|
-
|
|
24485
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
24486
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24013
24487
|
}
|
|
24014
|
-
|
|
24015
|
-
|
|
24016
|
-
|
|
24488
|
+
startSubscription() {
|
|
24489
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
24490
|
+
}
|
|
24491
|
+
notifyChange({ origin, loading, error }) {
|
|
24492
|
+
var _a, _b;
|
|
24493
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24494
|
+
if (!collection)
|
|
24495
|
+
return;
|
|
24496
|
+
const data = ((_b = collection.data
|
|
24497
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
24498
|
+
.filter(isNonNullable)
|
|
24499
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
24500
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
24501
|
+
return;
|
|
24502
|
+
this.callback({
|
|
24503
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24504
|
+
data,
|
|
24505
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24506
|
+
loading,
|
|
24507
|
+
error,
|
|
24508
|
+
});
|
|
24509
|
+
}
|
|
24510
|
+
}
|
|
24017
24511
|
|
|
24018
24512
|
/* begin_public_function
|
|
24019
|
-
id:
|
|
24513
|
+
id: feed.query.global_feed
|
|
24020
24514
|
*/
|
|
24021
24515
|
/**
|
|
24022
24516
|
* ```js
|
|
24023
|
-
* import {
|
|
24024
|
-
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
24025
|
-
* ```
|
|
24026
|
-
*
|
|
24027
|
-
* Deletes a {@link Amity.Comment}
|
|
24028
|
-
*
|
|
24029
|
-
* @param commentId The {@link Amity.Comment} ID to delete
|
|
24030
|
-
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
24517
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
24031
24518
|
*
|
|
24032
|
-
*
|
|
24033
|
-
*
|
|
24034
|
-
|
|
24035
|
-
|
|
24036
|
-
|
|
24037
|
-
client.log('comment/softDeleteComment', commentId);
|
|
24038
|
-
const softDeleted = deleteComment(commentId);
|
|
24039
|
-
return softDeleted;
|
|
24040
|
-
};
|
|
24041
|
-
/* end_public_function */
|
|
24042
|
-
|
|
24043
|
-
/* begin_public_function
|
|
24044
|
-
id: comment.hard_delete
|
|
24045
|
-
*/
|
|
24046
|
-
/**
|
|
24047
|
-
* ```js
|
|
24048
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
24049
|
-
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
24519
|
+
* let posts = []
|
|
24520
|
+
* const unsub = FeedRepository.getGlobalFeed({
|
|
24521
|
+
* dataTypes: ['video','image'],
|
|
24522
|
+
* resolveParent: true,
|
|
24523
|
+
* }, response => processResponse(response))
|
|
24050
24524
|
* ```
|
|
24051
24525
|
*
|
|
24052
|
-
*
|
|
24053
|
-
*
|
|
24054
|
-
* @param
|
|
24055
|
-
* @
|
|
24526
|
+
* Observe all mutations on a list of {@link Amity.Post} for global feed
|
|
24527
|
+
* @param params.dataTypes array of data types for the posts
|
|
24528
|
+
* @param params.resolveParent
|
|
24529
|
+
* @param callback the function to call when new data are available
|
|
24530
|
+
* @param config
|
|
24531
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
24056
24532
|
*
|
|
24057
|
-
* @category
|
|
24058
|
-
* @async
|
|
24533
|
+
* @category Posts Live Collection
|
|
24059
24534
|
*/
|
|
24060
|
-
const
|
|
24061
|
-
const
|
|
24062
|
-
|
|
24063
|
-
|
|
24064
|
-
return hardDeleted;
|
|
24065
|
-
};
|
|
24066
|
-
/* end_public_function */
|
|
24067
|
-
|
|
24068
|
-
/* begin_public_function
|
|
24069
|
-
id: comment.flag
|
|
24070
|
-
*/
|
|
24071
|
-
/**
|
|
24072
|
-
* ```js
|
|
24073
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
24074
|
-
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
24075
|
-
* ```
|
|
24076
|
-
*
|
|
24077
|
-
* @param commentId The ID of the comment to flag
|
|
24078
|
-
* @param reason the reason to flag the comment
|
|
24079
|
-
* @returns the created report result
|
|
24080
|
-
*
|
|
24081
|
-
* @category Comment API
|
|
24082
|
-
* @async
|
|
24083
|
-
* */
|
|
24084
|
-
const flagComment = async (commentId, reason) => {
|
|
24085
|
-
const client = getActiveClient();
|
|
24086
|
-
client.log('comment/flagComment', commentId);
|
|
24087
|
-
const isPredefinedReason = reason &&
|
|
24088
|
-
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
24089
|
-
const body = {
|
|
24090
|
-
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
24091
|
-
detail: reason && !isPredefinedReason ? reason : '',
|
|
24092
|
-
};
|
|
24093
|
-
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
24094
|
-
if (client.cache) {
|
|
24095
|
-
ingestInCache(payload);
|
|
24535
|
+
const getGlobalFeed = (params, callback, config) => {
|
|
24536
|
+
const { log, cache } = getActiveClient();
|
|
24537
|
+
if (!cache) {
|
|
24538
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
24096
24539
|
}
|
|
24097
|
-
|
|
24098
|
-
|
|
24540
|
+
const timestamp = Date.now();
|
|
24541
|
+
log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
|
|
24542
|
+
const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
|
|
24543
|
+
const disposers = liveCollection.startSubscription();
|
|
24544
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
24545
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
24546
|
+
return () => {
|
|
24547
|
+
log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
|
|
24548
|
+
disposers.forEach(fn => fn());
|
|
24549
|
+
};
|
|
24099
24550
|
};
|
|
24100
24551
|
/* end_public_function */
|
|
24101
24552
|
|
|
24102
|
-
|
|
24103
|
-
|
|
24104
|
-
|
|
24105
|
-
|
|
24106
|
-
|
|
24107
|
-
|
|
24108
|
-
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
24109
|
-
* ```
|
|
24110
|
-
*
|
|
24111
|
-
* @param commentId The ID of comment to unflag
|
|
24112
|
-
* @returns the unflagged result
|
|
24113
|
-
*
|
|
24114
|
-
* @category Comment API
|
|
24115
|
-
* @async
|
|
24116
|
-
* */
|
|
24117
|
-
const unflagComment = async (commentId) => {
|
|
24118
|
-
const client = getActiveClient();
|
|
24119
|
-
client.log('comment/unflagComment', commentId);
|
|
24120
|
-
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
24121
|
-
if (client.cache) {
|
|
24122
|
-
ingestInCache(payload);
|
|
24123
|
-
}
|
|
24124
|
-
fireEvent('comment.unflagged', payload);
|
|
24125
|
-
return !!payload;
|
|
24126
|
-
};
|
|
24127
|
-
/* end_public_function */
|
|
24553
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
24554
|
+
__proto__: null,
|
|
24555
|
+
queryGlobalFeed: queryGlobalFeed,
|
|
24556
|
+
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
24557
|
+
getGlobalFeed: getGlobalFeed
|
|
24558
|
+
});
|
|
24128
24559
|
|
|
24129
24560
|
/* begin_public_function
|
|
24130
|
-
id:
|
|
24561
|
+
id: post.get_by_ids
|
|
24131
24562
|
*/
|
|
24132
24563
|
/**
|
|
24133
24564
|
* ```js
|
|
24134
|
-
* import {
|
|
24135
|
-
* const
|
|
24565
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
24566
|
+
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
24136
24567
|
* ```
|
|
24137
24568
|
*
|
|
24138
|
-
*
|
|
24139
|
-
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
24569
|
+
* Fetches a collection of {@link Amity.Post} objects
|
|
24140
24570
|
*
|
|
24141
|
-
* @
|
|
24571
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
24572
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
24573
|
+
*
|
|
24574
|
+
* @category Post API
|
|
24142
24575
|
* @async
|
|
24143
|
-
|
|
24144
|
-
const
|
|
24145
|
-
const client = getActiveClient();
|
|
24146
|
-
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
24147
|
-
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
24148
|
-
return result;
|
|
24149
|
-
};
|
|
24150
|
-
/* end_public_function */
|
|
24151
|
-
|
|
24152
|
-
const getComment$1 = async (commentId) => {
|
|
24576
|
+
*/
|
|
24577
|
+
const getPostByIds = async (postIds) => {
|
|
24153
24578
|
const client = getActiveClient();
|
|
24154
|
-
client.log('
|
|
24155
|
-
|
|
24156
|
-
let
|
|
24579
|
+
client.log('post/getPostByIds', postIds);
|
|
24580
|
+
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
24581
|
+
let payload;
|
|
24157
24582
|
try {
|
|
24158
24583
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
24159
|
-
const response = await client.http.get(`/api/v3/
|
|
24160
|
-
|
|
24584
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
24585
|
+
params: { postIds: encodedPostIds },
|
|
24586
|
+
});
|
|
24587
|
+
payload = response.data;
|
|
24161
24588
|
}
|
|
24162
24589
|
catch (error) {
|
|
24163
|
-
|
|
24164
|
-
|
|
24165
|
-
|
|
24590
|
+
postIds.forEach(postId => {
|
|
24591
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24592
|
+
pushToTombstone('post', postId);
|
|
24593
|
+
}
|
|
24594
|
+
});
|
|
24166
24595
|
throw error;
|
|
24167
24596
|
}
|
|
24597
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24168
24598
|
const cachedAt = client.cache && Date.now();
|
|
24169
24599
|
if (client.cache)
|
|
24170
24600
|
ingestInCache(data, { cachedAt });
|
|
24171
|
-
const { comments } = data;
|
|
24172
24601
|
return {
|
|
24173
|
-
data:
|
|
24602
|
+
data: data.posts.map(LinkedObject.post),
|
|
24174
24603
|
cachedAt,
|
|
24175
24604
|
};
|
|
24176
24605
|
};
|
|
24177
|
-
|
|
24606
|
+
/* end_public_function */
|
|
24607
|
+
/**
|
|
24608
|
+
* ```js
|
|
24609
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
24610
|
+
* const { data: posts } = getPostByIds.locally(['foo', 'bar'])
|
|
24611
|
+
* ```
|
|
24612
|
+
*
|
|
24613
|
+
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
24614
|
+
*
|
|
24615
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
24616
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
24617
|
+
*
|
|
24618
|
+
* @category Post API
|
|
24619
|
+
*/
|
|
24620
|
+
getPostByIds.locally = (postIds) => {
|
|
24621
|
+
var _a;
|
|
24178
24622
|
const client = getActiveClient();
|
|
24179
|
-
client.log('
|
|
24623
|
+
client.log('post/getPostByIds.locally', postIds);
|
|
24180
24624
|
if (!client.cache)
|
|
24181
24625
|
return;
|
|
24182
|
-
const cached =
|
|
24183
|
-
|
|
24626
|
+
const cached = postIds
|
|
24627
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
24628
|
+
.filter(Boolean);
|
|
24629
|
+
const posts = cached.map(({ data }) => data);
|
|
24630
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
24631
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
24184
24632
|
return;
|
|
24185
24633
|
return {
|
|
24186
|
-
data:
|
|
24187
|
-
cachedAt:
|
|
24634
|
+
data: posts.map(LinkedObject.post),
|
|
24635
|
+
cachedAt: oldest.cachedAt,
|
|
24188
24636
|
};
|
|
24189
24637
|
};
|
|
24190
24638
|
|
|
24639
|
+
/* begin_public_function
|
|
24640
|
+
id: post.create.text_post, post.create.image_post, post.create.file_post, post.create.video_post, post.create.poll_post, post.create.livestream_post, post.create.custom_post
|
|
24641
|
+
*/
|
|
24191
24642
|
/**
|
|
24192
24643
|
* ```js
|
|
24193
|
-
* import {
|
|
24194
|
-
* const
|
|
24195
|
-
*
|
|
24196
|
-
*
|
|
24644
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24645
|
+
* const created = await PostRepository.createPost({
|
|
24646
|
+
* targetType: 'user',
|
|
24647
|
+
* targetId: 'foobar',
|
|
24648
|
+
* data: { text: 'hello world' }
|
|
24649
|
+
* }))
|
|
24197
24650
|
* ```
|
|
24198
24651
|
*
|
|
24199
|
-
*
|
|
24652
|
+
* Creates an {@link Amity.Post}
|
|
24200
24653
|
*
|
|
24201
|
-
* @param
|
|
24202
|
-
* @returns
|
|
24654
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
24655
|
+
* @returns The newly created {@link Amity.Post}
|
|
24203
24656
|
*
|
|
24204
|
-
* @category
|
|
24657
|
+
* @category Post API
|
|
24658
|
+
* @async
|
|
24205
24659
|
*/
|
|
24206
|
-
const
|
|
24660
|
+
const createPost = async (bundle) => {
|
|
24661
|
+
const client = getActiveClient();
|
|
24662
|
+
client.log('post/createPost', bundle);
|
|
24663
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
24664
|
+
// eslint-disable-next-line no-param-reassign
|
|
24665
|
+
delete bundle.dataType;
|
|
24666
|
+
}
|
|
24667
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
24668
|
+
fireEvent('post.created', payload);
|
|
24669
|
+
const data = preparePostPayload(payload);
|
|
24670
|
+
const cachedAt = client.cache && Date.now();
|
|
24671
|
+
if (client.cache)
|
|
24672
|
+
ingestInCache(data, { cachedAt });
|
|
24673
|
+
const { posts } = data;
|
|
24674
|
+
return {
|
|
24675
|
+
data: LinkedObject.post(posts[0]),
|
|
24676
|
+
cachedAt,
|
|
24677
|
+
};
|
|
24678
|
+
};
|
|
24679
|
+
/* end_public_function */
|
|
24207
24680
|
|
|
24681
|
+
/* begin_public_function
|
|
24682
|
+
id: post.edit, post.edit.custom_post
|
|
24683
|
+
*/
|
|
24208
24684
|
/**
|
|
24209
24685
|
* ```js
|
|
24210
|
-
* import {
|
|
24211
|
-
* const
|
|
24212
|
-
*
|
|
24686
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24687
|
+
* const updated = await PostRepository.editPost(postId, {
|
|
24688
|
+
* data: { text: 'hello world' }
|
|
24213
24689
|
* })
|
|
24214
24690
|
* ```
|
|
24215
24691
|
*
|
|
24216
|
-
*
|
|
24692
|
+
* Updates an {@link Amity.Post}
|
|
24217
24693
|
*
|
|
24218
|
-
* @param
|
|
24219
|
-
* @
|
|
24694
|
+
* @param postId The ID of the {@link Amity.Post} to edit
|
|
24695
|
+
* @param patch The patch data to apply
|
|
24696
|
+
* @returns the updated {@link Amity.Post} object
|
|
24220
24697
|
*
|
|
24221
|
-
* @category
|
|
24698
|
+
* @category Post API
|
|
24699
|
+
* @async
|
|
24222
24700
|
*/
|
|
24223
|
-
const
|
|
24701
|
+
const editPost = async (postId, patch) => {
|
|
24224
24702
|
const client = getActiveClient();
|
|
24225
|
-
|
|
24226
|
-
|
|
24227
|
-
|
|
24228
|
-
|
|
24229
|
-
|
|
24230
|
-
|
|
24231
|
-
|
|
24232
|
-
|
|
24703
|
+
client.log('user/editPost', patch);
|
|
24704
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
24705
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24706
|
+
const cachedAt = client.cache && Date.now();
|
|
24707
|
+
if (client.cache)
|
|
24708
|
+
ingestInCache(data, { cachedAt });
|
|
24709
|
+
fireEvent('local.post.updated', data);
|
|
24710
|
+
const { posts } = data;
|
|
24711
|
+
return {
|
|
24712
|
+
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
24713
|
+
cachedAt,
|
|
24233
24714
|
};
|
|
24234
|
-
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
24235
24715
|
};
|
|
24716
|
+
/* end_public_function */
|
|
24236
24717
|
|
|
24237
24718
|
/**
|
|
24238
24719
|
* ```js
|
|
24239
|
-
* import {
|
|
24240
|
-
* const
|
|
24241
|
-
* // ...
|
|
24242
|
-
* })
|
|
24720
|
+
* import { deletePost } from '@amityco/ts-sdk'
|
|
24721
|
+
* const success = await deletePost('foobar')
|
|
24243
24722
|
* ```
|
|
24244
24723
|
*
|
|
24245
|
-
*
|
|
24724
|
+
* Deletes a {@link Amity.Post}
|
|
24246
24725
|
*
|
|
24247
|
-
* @param
|
|
24248
|
-
* @
|
|
24726
|
+
* @param postId The {@link Amity.Post} ID to delete
|
|
24727
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24249
24728
|
*
|
|
24250
|
-
* @
|
|
24729
|
+
* @private
|
|
24730
|
+
* @async
|
|
24251
24731
|
*/
|
|
24252
|
-
const
|
|
24732
|
+
const deletePost = async (postId, permanent = false) => {
|
|
24733
|
+
var _a;
|
|
24253
24734
|
const client = getActiveClient();
|
|
24254
|
-
const
|
|
24255
|
-
|
|
24256
|
-
|
|
24257
|
-
|
|
24258
|
-
|
|
24259
|
-
|
|
24260
|
-
|
|
24261
|
-
|
|
24262
|
-
|
|
24263
|
-
|
|
24735
|
+
const post = await getPost$2(postId);
|
|
24736
|
+
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
24737
|
+
params: {
|
|
24738
|
+
postId,
|
|
24739
|
+
permanent,
|
|
24740
|
+
},
|
|
24741
|
+
});
|
|
24742
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
24743
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
24744
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
24745
|
+
// later when realtime events covers that for us.
|
|
24746
|
+
if (post.data.targetType === 'community') {
|
|
24747
|
+
const community = await getCommunity$1(post.data.targetId);
|
|
24748
|
+
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
24749
|
+
const communityUsers = communityUsersCache
|
|
24750
|
+
.filter(({ key }) => {
|
|
24751
|
+
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
24752
|
+
if (key[0] !== 'communityUsers')
|
|
24753
|
+
return false;
|
|
24754
|
+
if (key[1] !== 'get')
|
|
24755
|
+
return false;
|
|
24756
|
+
if (typeof key[2] === 'string')
|
|
24757
|
+
return key[2].includes(community.data.communityId);
|
|
24758
|
+
return false;
|
|
24759
|
+
})
|
|
24760
|
+
.map(({ data }) => data);
|
|
24761
|
+
fireEvent('community.updated', {
|
|
24762
|
+
communities: [community.data],
|
|
24763
|
+
categories: [],
|
|
24764
|
+
communityUsers,
|
|
24765
|
+
feeds: [],
|
|
24766
|
+
files: [],
|
|
24767
|
+
users: [],
|
|
24768
|
+
});
|
|
24769
|
+
}
|
|
24770
|
+
// to support hard deletion
|
|
24771
|
+
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
24772
|
+
if (permanent) {
|
|
24773
|
+
setTimeout(() => {
|
|
24774
|
+
pushToTombstone('post', postId);
|
|
24775
|
+
}, 0);
|
|
24776
|
+
}
|
|
24777
|
+
else {
|
|
24778
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
24779
|
+
}
|
|
24780
|
+
fireEvent('local.post.deleted', {
|
|
24781
|
+
posts: [deleted],
|
|
24782
|
+
categories: [],
|
|
24783
|
+
comments: [],
|
|
24784
|
+
communities: [],
|
|
24785
|
+
communityUsers: [],
|
|
24786
|
+
feeds: [],
|
|
24787
|
+
files: [],
|
|
24788
|
+
postChildren: [],
|
|
24789
|
+
users: [],
|
|
24790
|
+
videoStreamings: [],
|
|
24791
|
+
});
|
|
24792
|
+
return LinkedObject.post(deleted);
|
|
24264
24793
|
};
|
|
24265
24794
|
|
|
24266
24795
|
/* begin_public_function
|
|
24267
|
-
id:
|
|
24796
|
+
id: post.soft_delete
|
|
24268
24797
|
*/
|
|
24269
24798
|
/**
|
|
24270
24799
|
* ```js
|
|
24271
|
-
* import {
|
|
24272
|
-
*
|
|
24273
|
-
* let comment;
|
|
24274
|
-
*
|
|
24275
|
-
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
24276
|
-
* comment = response.data;
|
|
24277
|
-
* });
|
|
24800
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24801
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
24278
24802
|
* ```
|
|
24279
24803
|
*
|
|
24280
|
-
*
|
|
24804
|
+
* Soft deletes a {@link Amity.Post}
|
|
24281
24805
|
*
|
|
24282
|
-
* @param
|
|
24283
|
-
* @
|
|
24284
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
24806
|
+
* @param postId The {@link Amity.Post} ID to soft delete
|
|
24807
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24285
24808
|
*
|
|
24286
|
-
* @category
|
|
24287
|
-
|
|
24288
|
-
|
|
24289
|
-
|
|
24290
|
-
|
|
24291
|
-
|
|
24292
|
-
|
|
24293
|
-
|
|
24294
|
-
|
|
24295
|
-
|
|
24296
|
-
onCommentUpdated,
|
|
24297
|
-
onLocalCommentReactionAdded,
|
|
24298
|
-
onLocalCommentReactionRemoved,
|
|
24299
|
-
]);
|
|
24300
|
-
};
|
|
24301
|
-
/* end_public_function */
|
|
24302
|
-
|
|
24303
|
-
class CommentPaginationController extends PaginationController {
|
|
24304
|
-
async getRequest(queryParams, token) {
|
|
24305
|
-
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
24306
|
-
const baseOptions = {
|
|
24307
|
-
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
24308
|
-
};
|
|
24309
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
24310
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
24311
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
24312
|
-
});
|
|
24313
|
-
return queryResponse;
|
|
24314
|
-
}
|
|
24315
|
-
}
|
|
24316
|
-
|
|
24317
|
-
var EnumCommentActions;
|
|
24318
|
-
(function (EnumCommentActions) {
|
|
24319
|
-
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
24320
|
-
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
24321
|
-
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
24322
|
-
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
24323
|
-
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
24324
|
-
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
24325
|
-
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
24326
|
-
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
24327
|
-
|
|
24328
|
-
class CommentQueryStreamController extends QueryStreamController {
|
|
24329
|
-
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24330
|
-
super(query, cacheKey);
|
|
24331
|
-
this.notifyChange = notifyChange;
|
|
24332
|
-
this.preparePayload = preparePayload;
|
|
24333
|
-
}
|
|
24334
|
-
async saveToMainDB(response) {
|
|
24335
|
-
const processedPayload = await this.preparePayload(response);
|
|
24336
|
-
const client = getActiveClient();
|
|
24337
|
-
const cachedAt = client.cache && Date.now();
|
|
24338
|
-
if (client.cache) {
|
|
24339
|
-
ingestInCache(processedPayload, { cachedAt });
|
|
24340
|
-
}
|
|
24341
|
-
}
|
|
24342
|
-
appendToQueryStream(response, direction, refresh = false) {
|
|
24343
|
-
var _a, _b;
|
|
24344
|
-
if (refresh) {
|
|
24345
|
-
pushToCache(this.cacheKey, {
|
|
24346
|
-
data: response.comments.map(getResolver('comment')),
|
|
24347
|
-
});
|
|
24348
|
-
}
|
|
24349
|
-
else {
|
|
24350
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24351
|
-
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
24352
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
24353
|
-
}
|
|
24354
|
-
}
|
|
24355
|
-
reactor(action) {
|
|
24356
|
-
return (comment) => {
|
|
24357
|
-
var _a;
|
|
24358
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24359
|
-
if (this.query.referenceId !== comment.referenceId ||
|
|
24360
|
-
this.query.referenceType !== comment.referenceType ||
|
|
24361
|
-
!collection) {
|
|
24362
|
-
return;
|
|
24363
|
-
}
|
|
24364
|
-
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
24365
|
-
return;
|
|
24366
|
-
}
|
|
24367
|
-
if (!this.query.parentId && comment.parentId) {
|
|
24368
|
-
return;
|
|
24369
|
-
}
|
|
24370
|
-
if (action === EnumCommentActions.OnCommentCreated) {
|
|
24371
|
-
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
24372
|
-
}
|
|
24373
|
-
pushToCache(this.cacheKey, collection);
|
|
24374
|
-
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
24375
|
-
};
|
|
24376
|
-
}
|
|
24377
|
-
subscribeRTE(createSubscriber) {
|
|
24378
|
-
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
24379
|
-
}
|
|
24380
|
-
}
|
|
24809
|
+
* @category Post API
|
|
24810
|
+
* @async
|
|
24811
|
+
*/
|
|
24812
|
+
const softDeletePost = async (postId) => {
|
|
24813
|
+
const client = getActiveClient();
|
|
24814
|
+
client.log('post/softDeletePost', postId);
|
|
24815
|
+
const softDeleted = await deletePost(postId, false);
|
|
24816
|
+
return LinkedObject.post(softDeleted);
|
|
24817
|
+
};
|
|
24818
|
+
/* end_public_function */
|
|
24381
24819
|
|
|
24820
|
+
/* begin_public_function
|
|
24821
|
+
id: post.hard_delete
|
|
24822
|
+
*/
|
|
24382
24823
|
/**
|
|
24383
24824
|
* ```js
|
|
24384
|
-
* import {
|
|
24385
|
-
* const
|
|
24386
|
-
* // ...
|
|
24387
|
-
* })
|
|
24825
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
24826
|
+
* const success = await hardDeletePost('foobar')
|
|
24388
24827
|
* ```
|
|
24389
24828
|
*
|
|
24390
|
-
*
|
|
24829
|
+
* Hard deletes a {@link Amity.Post}
|
|
24391
24830
|
*
|
|
24392
|
-
* @param
|
|
24393
|
-
* @
|
|
24831
|
+
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
24832
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
24394
24833
|
*
|
|
24395
|
-
* @category
|
|
24834
|
+
* @category Post API
|
|
24835
|
+
* @async
|
|
24396
24836
|
*/
|
|
24397
|
-
const
|
|
24398
|
-
|
|
24837
|
+
const hardDeletePost = async (postId) => {
|
|
24838
|
+
const client = getActiveClient();
|
|
24839
|
+
client.log('post/hardDeletePost', postId);
|
|
24840
|
+
const hardDeleted = await deletePost(postId, true);
|
|
24841
|
+
return LinkedObject.post(hardDeleted);
|
|
24399
24842
|
};
|
|
24843
|
+
/* end_public_function */
|
|
24400
24844
|
|
|
24401
|
-
|
|
24402
|
-
|
|
24403
|
-
|
|
24404
|
-
|
|
24405
|
-
|
|
24406
|
-
|
|
24407
|
-
|
|
24408
|
-
|
|
24409
|
-
|
|
24410
|
-
|
|
24411
|
-
|
|
24412
|
-
|
|
24413
|
-
|
|
24414
|
-
|
|
24415
|
-
|
|
24416
|
-
|
|
24417
|
-
|
|
24418
|
-
|
|
24419
|
-
|
|
24420
|
-
|
|
24421
|
-
|
|
24422
|
-
|
|
24423
|
-
|
|
24424
|
-
|
|
24425
|
-
|
|
24426
|
-
|
|
24427
|
-
}
|
|
24428
|
-
startSubscription() {
|
|
24429
|
-
return this.queryStreamController.subscribeRTE([
|
|
24430
|
-
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
24431
|
-
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
24432
|
-
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
24433
|
-
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
24434
|
-
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
24435
|
-
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
24436
|
-
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
24437
|
-
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
24438
|
-
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
24439
|
-
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
24440
|
-
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
24441
|
-
]);
|
|
24442
|
-
}
|
|
24443
|
-
notifyChange({ origin, loading, error }) {
|
|
24444
|
-
var _a, _b;
|
|
24445
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24446
|
-
if (!collection)
|
|
24447
|
-
return;
|
|
24448
|
-
const data = this.applyFilter((_b = collection.data
|
|
24449
|
-
.map(id => pullFromCache(['comment', 'get', id]))
|
|
24450
|
-
.filter(isNonNullable)
|
|
24451
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
24452
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
24453
|
-
return;
|
|
24454
|
-
this.callback({
|
|
24455
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
24456
|
-
data,
|
|
24457
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
24458
|
-
loading,
|
|
24459
|
-
error,
|
|
24460
|
-
});
|
|
24461
|
-
}
|
|
24462
|
-
applyFilter(data) {
|
|
24463
|
-
let comments = data;
|
|
24464
|
-
if (!this.query.includeDeleted) {
|
|
24465
|
-
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
24466
|
-
}
|
|
24467
|
-
if (this.query.parentId) {
|
|
24468
|
-
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
24469
|
-
}
|
|
24470
|
-
if (typeof this.query.hasFlag === 'boolean') {
|
|
24471
|
-
if (this.query.hasFlag) {
|
|
24472
|
-
comments = comments.filter(comment => comment.hashFlag != null);
|
|
24473
|
-
}
|
|
24474
|
-
else {
|
|
24475
|
-
comments = comments.filter(comment => comment.hashFlag == null);
|
|
24476
|
-
}
|
|
24477
|
-
}
|
|
24478
|
-
if (this.query.dataTypes) {
|
|
24479
|
-
if (this.query.dataTypes.matchType === 'exact') {
|
|
24480
|
-
comments = comments.filter(comment => {
|
|
24481
|
-
var _a, _b;
|
|
24482
|
-
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
24483
|
-
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
24484
|
-
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
24485
|
-
return false;
|
|
24486
|
-
}
|
|
24487
|
-
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
24488
|
-
});
|
|
24489
|
-
}
|
|
24490
|
-
if (this.query.dataTypes.matchType === 'any') {
|
|
24491
|
-
comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
|
|
24492
|
-
}
|
|
24493
|
-
}
|
|
24494
|
-
switch (this.query.sortBy) {
|
|
24495
|
-
case 'firstCreated':
|
|
24496
|
-
comments = comments.sort(sortByFirstCreated);
|
|
24497
|
-
break;
|
|
24498
|
-
case 'lastCreated':
|
|
24499
|
-
default:
|
|
24500
|
-
comments = comments.sort(sortByLastCreated);
|
|
24501
|
-
break;
|
|
24502
|
-
}
|
|
24503
|
-
return comments;
|
|
24845
|
+
/* begin_public_function
|
|
24846
|
+
id: post.approve
|
|
24847
|
+
*/
|
|
24848
|
+
/**
|
|
24849
|
+
* ```js
|
|
24850
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
24851
|
+
*
|
|
24852
|
+
* const { data: post } = await approvePost('postId')
|
|
24853
|
+
* ```
|
|
24854
|
+
*
|
|
24855
|
+
* Approves a {@link Amity.Post}
|
|
24856
|
+
*
|
|
24857
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
24858
|
+
* @return A {@link Amity.Post} that was approved
|
|
24859
|
+
*
|
|
24860
|
+
* @category Post API
|
|
24861
|
+
* @async
|
|
24862
|
+
*/
|
|
24863
|
+
const approvePost = async (postId) => {
|
|
24864
|
+
const client = getActiveClient();
|
|
24865
|
+
client.log('post/approvePost', postId);
|
|
24866
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
24867
|
+
fireEvent('post.approved', payload);
|
|
24868
|
+
// fire virtual event for community update
|
|
24869
|
+
if (payload.posts[0].targetType === 'community') {
|
|
24870
|
+
fireEvent('community.updated', payload);
|
|
24504
24871
|
}
|
|
24505
|
-
|
|
24872
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24873
|
+
const cachedAt = client.cache && Date.now();
|
|
24874
|
+
if (client.cache)
|
|
24875
|
+
ingestInCache(data, { cachedAt });
|
|
24876
|
+
return {
|
|
24877
|
+
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
24878
|
+
cachedAt,
|
|
24879
|
+
};
|
|
24880
|
+
};
|
|
24881
|
+
/* end_public_function */
|
|
24506
24882
|
|
|
24507
24883
|
/* begin_public_function
|
|
24508
|
-
id:
|
|
24884
|
+
id: post.decline
|
|
24509
24885
|
*/
|
|
24510
24886
|
/**
|
|
24511
24887
|
* ```js
|
|
24512
|
-
* import {
|
|
24888
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
24513
24889
|
*
|
|
24514
|
-
*
|
|
24515
|
-
* const unsub = getComments({
|
|
24516
|
-
* referenceType: Amity.InternalComment['referenceType'];
|
|
24517
|
-
* referenceId: Amity.InternalComment['referenceId'];
|
|
24518
|
-
* }, response => merge(comments, response.data))
|
|
24890
|
+
* const {data: post} = await declinePost('postId')
|
|
24519
24891
|
* ```
|
|
24520
24892
|
*
|
|
24521
|
-
*
|
|
24893
|
+
* Declines a {@link Amity.Post}
|
|
24522
24894
|
*
|
|
24523
|
-
* @param
|
|
24524
|
-
* @
|
|
24525
|
-
* @param callback the function to call when new data are available
|
|
24526
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
24895
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
24896
|
+
* @return A {@link Amity.Post} that was declined
|
|
24527
24897
|
*
|
|
24528
|
-
* @category
|
|
24898
|
+
* @category Post API
|
|
24899
|
+
* @async
|
|
24529
24900
|
*/
|
|
24530
|
-
const
|
|
24531
|
-
const
|
|
24532
|
-
|
|
24533
|
-
|
|
24901
|
+
const declinePost = async (postId) => {
|
|
24902
|
+
const client = getActiveClient();
|
|
24903
|
+
client.log('post/declinePost', postId);
|
|
24904
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
24905
|
+
// fire virtual event
|
|
24906
|
+
if (payload.posts[0].targetType === 'community') {
|
|
24907
|
+
fireEvent('community.updated', payload);
|
|
24534
24908
|
}
|
|
24535
|
-
|
|
24536
|
-
|
|
24537
|
-
const
|
|
24538
|
-
|
|
24539
|
-
|
|
24540
|
-
|
|
24541
|
-
|
|
24542
|
-
|
|
24543
|
-
disposers.forEach(fn => fn());
|
|
24909
|
+
fireEvent('post.declined', payload);
|
|
24910
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24911
|
+
const cachedAt = client.cache && Date.now();
|
|
24912
|
+
if (client.cache)
|
|
24913
|
+
ingestInCache(data, { cachedAt });
|
|
24914
|
+
return {
|
|
24915
|
+
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
24916
|
+
cachedAt,
|
|
24544
24917
|
};
|
|
24545
24918
|
};
|
|
24546
24919
|
/* end_public_function */
|
|
24547
24920
|
|
|
24548
|
-
|
|
24549
|
-
|
|
24550
|
-
|
|
24551
|
-
createComment: createComment,
|
|
24552
|
-
updateComment: updateComment,
|
|
24553
|
-
deleteComment: deleteComment,
|
|
24554
|
-
softDeleteComment: softDeleteComment,
|
|
24555
|
-
hardDeleteComment: hardDeleteComment,
|
|
24556
|
-
flagComment: flagComment,
|
|
24557
|
-
unflagComment: unflagComment,
|
|
24558
|
-
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
24559
|
-
onCommentCreated: onCommentCreated,
|
|
24560
|
-
onCommentUpdated: onCommentUpdated,
|
|
24561
|
-
onCommentDeleted: onCommentDeleted,
|
|
24562
|
-
onCommentFlagged: onCommentFlagged,
|
|
24563
|
-
onCommentUnflagged: onCommentUnflagged,
|
|
24564
|
-
onCommentReactionAdded: onCommentReactionAdded,
|
|
24565
|
-
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
24566
|
-
getComment: getComment,
|
|
24567
|
-
getComments: getComments
|
|
24568
|
-
});
|
|
24569
|
-
|
|
24921
|
+
/* begin_public_function
|
|
24922
|
+
id: post.flag
|
|
24923
|
+
*/
|
|
24570
24924
|
/**
|
|
24571
24925
|
* ```js
|
|
24572
|
-
* import {
|
|
24573
|
-
* const
|
|
24574
|
-
* // ...
|
|
24575
|
-
* })
|
|
24926
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24927
|
+
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
24576
24928
|
* ```
|
|
24577
24929
|
*
|
|
24578
|
-
*
|
|
24579
|
-
*
|
|
24580
|
-
* @
|
|
24581
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24930
|
+
* @param postId of the post to flag
|
|
24931
|
+
* @param reason the reason to flag the post
|
|
24932
|
+
* @returns a boolean
|
|
24582
24933
|
*
|
|
24583
|
-
* @category Post
|
|
24584
|
-
|
|
24585
|
-
|
|
24934
|
+
* @category Post API
|
|
24935
|
+
* @async
|
|
24936
|
+
* */
|
|
24937
|
+
const flagPost = async (postId, reason) => {
|
|
24938
|
+
const client = getActiveClient();
|
|
24939
|
+
client.log('post/flagPost', postId);
|
|
24940
|
+
const isPredefinedReason = reason &&
|
|
24941
|
+
Object.entries(exports.ContentFlagReasonEnum).some(([key, value]) => key !== exports.ContentFlagReasonEnum.Others && value === reason);
|
|
24942
|
+
const body = {
|
|
24943
|
+
reason: reason && isPredefinedReason ? reason : exports.ContentFlagReasonEnum.Others,
|
|
24944
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
24945
|
+
};
|
|
24946
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
24947
|
+
if (client.cache) {
|
|
24948
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
24949
|
+
}
|
|
24950
|
+
fireEvent('post.flagged', payload);
|
|
24951
|
+
return !!payload;
|
|
24952
|
+
};
|
|
24953
|
+
/* end_public_function */
|
|
24586
24954
|
|
|
24955
|
+
/* begin_public_function
|
|
24956
|
+
id: post.unflag
|
|
24957
|
+
*/
|
|
24587
24958
|
/**
|
|
24588
24959
|
* ```js
|
|
24589
|
-
* import {
|
|
24590
|
-
* const
|
|
24591
|
-
* // ...
|
|
24592
|
-
* })
|
|
24960
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24961
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
24593
24962
|
* ```
|
|
24594
24963
|
*
|
|
24595
|
-
*
|
|
24596
|
-
*
|
|
24597
|
-
* @param callback The function to call when the event was fired
|
|
24598
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24964
|
+
* @param postId of the post to unflag
|
|
24965
|
+
* @returns the unflag post result
|
|
24599
24966
|
*
|
|
24600
|
-
* @category Post
|
|
24601
|
-
|
|
24602
|
-
|
|
24967
|
+
* @category Post API
|
|
24968
|
+
* @async
|
|
24969
|
+
* */
|
|
24970
|
+
const unflagPost = async (postId) => {
|
|
24603
24971
|
const client = getActiveClient();
|
|
24604
|
-
|
|
24605
|
-
|
|
24606
|
-
|
|
24607
|
-
|
|
24608
|
-
|
|
24609
|
-
|
|
24610
|
-
|
|
24611
|
-
}
|
|
24612
|
-
};
|
|
24613
|
-
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
24972
|
+
client.log('post/unflagPost', postId);
|
|
24973
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
24974
|
+
if (client.cache) {
|
|
24975
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
24976
|
+
}
|
|
24977
|
+
fireEvent('post.unflagged', payload);
|
|
24978
|
+
return !!payload;
|
|
24614
24979
|
};
|
|
24980
|
+
/* end_public_function */
|
|
24615
24981
|
|
|
24982
|
+
/* begin_public_function
|
|
24983
|
+
id: post.check_flag_by_me
|
|
24984
|
+
*/
|
|
24616
24985
|
/**
|
|
24617
24986
|
* ```js
|
|
24618
|
-
* import {
|
|
24619
|
-
* const
|
|
24620
|
-
* // ...
|
|
24621
|
-
* })
|
|
24987
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
24988
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
24622
24989
|
* ```
|
|
24623
24990
|
*
|
|
24624
|
-
*
|
|
24625
|
-
*
|
|
24626
|
-
* @param callback The function to call when the event was fired
|
|
24627
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
24991
|
+
* @param postId of the post to check if flagged by current user
|
|
24992
|
+
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
24628
24993
|
*
|
|
24629
|
-
* @category Post
|
|
24630
|
-
|
|
24631
|
-
|
|
24994
|
+
* @category Post API
|
|
24995
|
+
* @async
|
|
24996
|
+
* */
|
|
24997
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
24632
24998
|
const client = getActiveClient();
|
|
24633
|
-
|
|
24634
|
-
|
|
24635
|
-
|
|
24636
|
-
}
|
|
24637
|
-
else {
|
|
24638
|
-
upsertInCache(['post', 'get', post.postId], post);
|
|
24639
|
-
callback(post);
|
|
24640
|
-
}
|
|
24641
|
-
};
|
|
24642
|
-
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
24999
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
25000
|
+
const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
|
|
25001
|
+
return result;
|
|
24643
25002
|
};
|
|
25003
|
+
/* end_public_function */
|
|
24644
25004
|
|
|
25005
|
+
/* begin_public_function
|
|
25006
|
+
id: post.create.clip_post
|
|
25007
|
+
*/
|
|
24645
25008
|
/**
|
|
24646
25009
|
* ```js
|
|
24647
|
-
* import {
|
|
24648
|
-
* const
|
|
24649
|
-
*
|
|
24650
|
-
*
|
|
25010
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
25011
|
+
* const created = await PostRepository.createClipPost({
|
|
25012
|
+
* targetType: 'user',
|
|
25013
|
+
* targetId: 'foobar',
|
|
25014
|
+
* dataType: 'clip',
|
|
25015
|
+
* data: { text: 'hello world' },
|
|
25016
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
25017
|
+
* }))
|
|
24651
25018
|
* ```
|
|
24652
25019
|
*
|
|
24653
|
-
*
|
|
25020
|
+
* Creates an {@link Amity.Post}
|
|
24654
25021
|
*
|
|
24655
|
-
* @param
|
|
24656
|
-
* @returns
|
|
25022
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
25023
|
+
* @returns The newly created {@link Amity.Post}
|
|
24657
25024
|
*
|
|
24658
|
-
* @category Post
|
|
25025
|
+
* @category Post API
|
|
25026
|
+
* @async
|
|
24659
25027
|
*/
|
|
24660
|
-
const
|
|
25028
|
+
const createClipPost = async (bundle) => {
|
|
25029
|
+
const client = getActiveClient();
|
|
25030
|
+
client.log('post/createPost', bundle);
|
|
25031
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
25032
|
+
fireEvent('post.created', payload);
|
|
25033
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
25034
|
+
const cachedAt = client.cache && Date.now();
|
|
25035
|
+
if (client.cache)
|
|
25036
|
+
ingestInCache(data, { cachedAt });
|
|
25037
|
+
const { posts } = data;
|
|
25038
|
+
return {
|
|
25039
|
+
data: LinkedObject.post(posts[0]),
|
|
25040
|
+
cachedAt,
|
|
25041
|
+
};
|
|
25042
|
+
};
|
|
25043
|
+
/* end_public_function */
|
|
24661
25044
|
|
|
24662
25045
|
/* begin_public_function
|
|
24663
25046
|
id: post.get
|
|
@@ -24681,7 +25064,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
|
|
|
24681
25064
|
*
|
|
24682
25065
|
* @category Post Live Object
|
|
24683
25066
|
*/
|
|
24684
|
-
const getPost
|
|
25067
|
+
const getPost = (postId, callback) => {
|
|
24685
25068
|
const responder = (snapshot) => {
|
|
24686
25069
|
const { data } = snapshot;
|
|
24687
25070
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
@@ -24770,19 +25153,6 @@ class PostPaginationController extends PaginationController {
|
|
|
24770
25153
|
}
|
|
24771
25154
|
}
|
|
24772
25155
|
|
|
24773
|
-
var EnumPostActions;
|
|
24774
|
-
(function (EnumPostActions) {
|
|
24775
|
-
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
24776
|
-
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
24777
|
-
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
24778
|
-
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
24779
|
-
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
24780
|
-
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
24781
|
-
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
24782
|
-
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
24783
|
-
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
24784
|
-
})(EnumPostActions || (EnumPostActions = {}));
|
|
24785
|
-
|
|
24786
25156
|
class PostQueryStreamController extends QueryStreamController {
|
|
24787
25157
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
24788
25158
|
super(query, cacheKey);
|
|
@@ -24848,45 +25218,50 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
24848
25218
|
}
|
|
24849
25219
|
}
|
|
24850
25220
|
|
|
24851
|
-
const
|
|
24852
|
-
|
|
24853
|
-
|
|
24854
|
-
|
|
24855
|
-
|
|
24856
|
-
|
|
24857
|
-
|
|
24858
|
-
|
|
24859
|
-
|
|
24860
|
-
}
|
|
24861
|
-
catch (error) {
|
|
24862
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
24863
|
-
pushToTombstone('post', postId);
|
|
24864
|
-
}
|
|
24865
|
-
throw error;
|
|
24866
|
-
}
|
|
24867
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
24868
|
-
const cachedAt = client.cache && Date.now();
|
|
24869
|
-
if (client.cache)
|
|
24870
|
-
ingestInCache(data, { cachedAt });
|
|
24871
|
-
const { posts } = data;
|
|
24872
|
-
const result = posts.find(post => post.postId === postId);
|
|
24873
|
-
return {
|
|
24874
|
-
data: result,
|
|
24875
|
-
cachedAt,
|
|
24876
|
-
};
|
|
25221
|
+
const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
|
|
25222
|
+
return eventHandler(async (comment) => {
|
|
25223
|
+
var _a;
|
|
25224
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25225
|
+
if (!currentCollection ||
|
|
25226
|
+
!currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
|
|
25227
|
+
return;
|
|
25228
|
+
await getPost$1(comment.referenceId);
|
|
25229
|
+
callback(comment);
|
|
25230
|
+
});
|
|
24877
25231
|
};
|
|
24878
|
-
|
|
24879
|
-
const
|
|
24880
|
-
|
|
24881
|
-
|
|
24882
|
-
|
|
24883
|
-
|
|
24884
|
-
|
|
24885
|
-
|
|
24886
|
-
|
|
24887
|
-
|
|
24888
|
-
|
|
24889
|
-
|
|
25232
|
+
const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
|
|
25233
|
+
const eventHandlers = [
|
|
25234
|
+
onCommentCreated,
|
|
25235
|
+
onCommentDeleted,
|
|
25236
|
+
onCommentReactionAdded,
|
|
25237
|
+
onCommentReactionRemoved,
|
|
25238
|
+
onCommentCreatedLocal,
|
|
25239
|
+
onCommentDeleteLocal,
|
|
25240
|
+
onLocalCommentReactionAdded,
|
|
25241
|
+
onLocalCommentReactionRemoved,
|
|
25242
|
+
];
|
|
25243
|
+
return eventHandlers.map(handler => ({
|
|
25244
|
+
fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
|
|
25245
|
+
action: EnumPostActions.OnPostUpdated,
|
|
25246
|
+
}));
|
|
25247
|
+
};
|
|
25248
|
+
const getPostSubscription = (cacheKey) => {
|
|
25249
|
+
return [
|
|
25250
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
25251
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
25252
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
25253
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
25254
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
25255
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
25256
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
25257
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
25258
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
25259
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
25260
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
25261
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
25262
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
25263
|
+
...generateCommentSubscriptions({ cacheKey }),
|
|
25264
|
+
];
|
|
24890
25265
|
};
|
|
24891
25266
|
|
|
24892
25267
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
@@ -24917,47 +25292,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
24917
25292
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
24918
25293
|
}
|
|
24919
25294
|
startSubscription() {
|
|
24920
|
-
return this.queryStreamController.subscribeRTE(
|
|
24921
|
-
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
24922
|
-
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
24923
|
-
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
24924
|
-
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24925
|
-
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
24926
|
-
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
24927
|
-
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
24928
|
-
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
24929
|
-
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24930
|
-
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24931
|
-
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
24932
|
-
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
24933
|
-
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
24934
|
-
{
|
|
24935
|
-
fn: convertEventPayload((callback) => {
|
|
24936
|
-
return onCommentCreated(async (comment) => {
|
|
24937
|
-
var _a;
|
|
24938
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24939
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24940
|
-
return;
|
|
24941
|
-
await getPost(comment.referenceId);
|
|
24942
|
-
callback(comment);
|
|
24943
|
-
});
|
|
24944
|
-
}, 'referenceId', 'post'),
|
|
24945
|
-
action: EnumPostActions.OnPostUpdated,
|
|
24946
|
-
},
|
|
24947
|
-
{
|
|
24948
|
-
fn: convertEventPayload((callback) => {
|
|
24949
|
-
return onCommentDeleted(async (comment) => {
|
|
24950
|
-
var _a;
|
|
24951
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
24952
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
24953
|
-
return;
|
|
24954
|
-
await getPost(comment.referenceId);
|
|
24955
|
-
callback(comment);
|
|
24956
|
-
});
|
|
24957
|
-
}, 'referenceId', 'post'),
|
|
24958
|
-
action: EnumPostActions.OnPostUpdated,
|
|
24959
|
-
},
|
|
24960
|
-
]);
|
|
25295
|
+
return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
24961
25296
|
}
|
|
24962
25297
|
notifyChange({ origin, loading, error }) {
|
|
24963
25298
|
var _a, _b;
|
|
@@ -25092,6 +25427,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
25092
25427
|
});
|
|
25093
25428
|
}
|
|
25094
25429
|
}
|
|
25430
|
+
reactor(action) {
|
|
25431
|
+
return (post) => {
|
|
25432
|
+
var _a;
|
|
25433
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
25434
|
+
if (!collection)
|
|
25435
|
+
return;
|
|
25436
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
25437
|
+
collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
|
|
25438
|
+
}
|
|
25439
|
+
pushToCache(this.cacheKey, collection);
|
|
25440
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
25441
|
+
};
|
|
25442
|
+
}
|
|
25443
|
+
subscribeRTE(createSubscriber) {
|
|
25444
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
25445
|
+
}
|
|
25095
25446
|
}
|
|
25096
25447
|
|
|
25097
25448
|
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
@@ -25123,7 +25474,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
|
25123
25474
|
}
|
|
25124
25475
|
// eslint-disable-next-line class-methods-use-this
|
|
25125
25476
|
startSubscription() {
|
|
25126
|
-
return
|
|
25477
|
+
return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
|
|
25478
|
+
cacheKey: this.cacheKey,
|
|
25479
|
+
resolveId: id => `${this.query.placement}#${id}`,
|
|
25480
|
+
}));
|
|
25127
25481
|
}
|
|
25128
25482
|
notifyChange({ origin, loading, error }) {
|
|
25129
25483
|
var _a, _b;
|
|
@@ -25275,6 +25629,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
|
|
|
25275
25629
|
fn: onPostDeleted,
|
|
25276
25630
|
action: EnumPostActions.OnPostDeleted,
|
|
25277
25631
|
},
|
|
25632
|
+
...generateCommentSubscriptions({
|
|
25633
|
+
cacheKey: this.cacheKey,
|
|
25634
|
+
resolveId: id => `global#${id}`,
|
|
25635
|
+
}),
|
|
25278
25636
|
]);
|
|
25279
25637
|
}
|
|
25280
25638
|
notifyChange({ origin, loading, error }) {
|
|
@@ -25577,7 +25935,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
25577
25935
|
onPostUnflagged: onPostUnflagged,
|
|
25578
25936
|
onPostReactionAdded: onPostReactionAdded,
|
|
25579
25937
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
25580
|
-
getPost: getPost
|
|
25938
|
+
getPost: getPost,
|
|
25581
25939
|
getPosts: getPosts,
|
|
25582
25940
|
getPinnedPosts: getPinnedPosts,
|
|
25583
25941
|
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
@@ -26460,7 +26818,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
|
|
|
26460
26818
|
getPoll: getPoll
|
|
26461
26819
|
});
|
|
26462
26820
|
|
|
26463
|
-
const privateKey = "-----BEGIN PRIVATE KEY-----\
|
|
26821
|
+
const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
|
|
26464
26822
|
/*
|
|
26465
26823
|
* The crypto algorithm used for importing key and signing string
|
|
26466
26824
|
*/
|
|
@@ -28780,13 +29138,13 @@ exports.AdRepository = index$3;
|
|
|
28780
29138
|
exports.CategoryRepository = index$b;
|
|
28781
29139
|
exports.ChannelRepository = index$f;
|
|
28782
29140
|
exports.Client = index$o;
|
|
28783
|
-
exports.CommentRepository = index$
|
|
29141
|
+
exports.CommentRepository = index$a;
|
|
28784
29142
|
exports.CommunityPostSettingMaps = CommunityPostSettingMaps;
|
|
28785
29143
|
exports.CommunityPostSettings = CommunityPostSettings;
|
|
28786
29144
|
exports.CommunityRepository = index$c;
|
|
28787
29145
|
exports.ContentFeedType = ContentFeedType;
|
|
28788
29146
|
exports.DefaultCommunityPostSetting = DefaultCommunityPostSetting;
|
|
28789
|
-
exports.FeedRepository = index$
|
|
29147
|
+
exports.FeedRepository = index$9;
|
|
28790
29148
|
exports.FileRepository = index$l;
|
|
28791
29149
|
exports.FileType = FileType;
|
|
28792
29150
|
exports.InvitationRepository = index$1;
|