@amityco/ts-sdk 7.7.1-1cf499d.0 → 7.7.1-68d81647.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/.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/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/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 +1607 -1249
- package/dist/index.esm.js +1534 -1176
- 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/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.esm.js
CHANGED
|
@@ -642,7 +642,8 @@ const PAYLOAD2MODEL = {
|
|
|
642
642
|
};
|
|
643
643
|
/** hidden */
|
|
644
644
|
const isOutdated = (prevData, nextData) => {
|
|
645
|
-
|
|
645
|
+
// Check if the new value is outdated.
|
|
646
|
+
if ('updatedAt' in nextData && 'updatedAt' in prevData) {
|
|
646
647
|
return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
|
|
647
648
|
}
|
|
648
649
|
return false;
|
|
@@ -27946,15 +27947,18 @@ function isAmityClipPost(post) {
|
|
|
27946
27947
|
}
|
|
27947
27948
|
|
|
27948
27949
|
const postLinkedObject = (post) => {
|
|
27949
|
-
return
|
|
27950
|
+
return shallowClone(post, {
|
|
27951
|
+
childrenPosts: post.children
|
|
27950
27952
|
.map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
|
|
27951
27953
|
.filter(isNonNullable)
|
|
27952
|
-
.map(postLinkedObject),
|
|
27954
|
+
.map(postLinkedObject),
|
|
27955
|
+
analytics: {
|
|
27953
27956
|
markAsViewed: () => {
|
|
27954
27957
|
const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
|
|
27955
27958
|
analyticsEngineInstance.markPostAsViewed(post.postId);
|
|
27956
27959
|
},
|
|
27957
|
-
},
|
|
27960
|
+
},
|
|
27961
|
+
get latestComments() {
|
|
27958
27962
|
if (!post.comments)
|
|
27959
27963
|
return [];
|
|
27960
27964
|
return (post.comments
|
|
@@ -28028,7 +28032,8 @@ const postLinkedObject = (post) => {
|
|
|
28028
28032
|
return isAmityClipPost(post)
|
|
28029
28033
|
? (_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
|
|
28030
28034
|
: undefined;
|
|
28031
|
-
}
|
|
28035
|
+
},
|
|
28036
|
+
});
|
|
28032
28037
|
};
|
|
28033
28038
|
|
|
28034
28039
|
const getCachedMarker = (message) => {
|
|
@@ -31023,7 +31028,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
31023
31028
|
]);
|
|
31024
31029
|
if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
|
|
31025
31030
|
return true;
|
|
31026
|
-
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 }) });
|
|
31031
|
+
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() });
|
|
31027
31032
|
if (referenceType === 'comment') {
|
|
31028
31033
|
fireEvent('local.comment.addReaction', {
|
|
31029
31034
|
comment: updatedModel,
|
|
@@ -31146,7 +31151,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
|
|
|
31146
31151
|
]);
|
|
31147
31152
|
if (!model)
|
|
31148
31153
|
return true;
|
|
31149
|
-
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) }) });
|
|
31154
|
+
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() });
|
|
31150
31155
|
if (referenceType === 'comment') {
|
|
31151
31156
|
fireEvent('local.comment.removeReaction', {
|
|
31152
31157
|
comment: updatedModel,
|
|
@@ -31260,6 +31265,26 @@ const prepareSemanticSearchPostPayload = (_a) => {
|
|
|
31260
31265
|
return Object.assign(Object.assign({}, processedPostPayload), { polls });
|
|
31261
31266
|
};
|
|
31262
31267
|
|
|
31268
|
+
const processDeleteChildPost = (payload) => {
|
|
31269
|
+
var _a;
|
|
31270
|
+
const post = payload.posts[0];
|
|
31271
|
+
if (!post.parentId)
|
|
31272
|
+
return;
|
|
31273
|
+
const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
31274
|
+
if (!parentPost)
|
|
31275
|
+
return;
|
|
31276
|
+
pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
|
|
31277
|
+
};
|
|
31278
|
+
const processCreateChildPost = (payload) => {
|
|
31279
|
+
var _a;
|
|
31280
|
+
const post = payload.posts[0];
|
|
31281
|
+
if (!post.parentId)
|
|
31282
|
+
return;
|
|
31283
|
+
const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
31284
|
+
if (!parentPost)
|
|
31285
|
+
return;
|
|
31286
|
+
pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
|
|
31287
|
+
};
|
|
31263
31288
|
const createPostEventSubscriber = (event, callback) => {
|
|
31264
31289
|
const client = getActiveClient();
|
|
31265
31290
|
const filter = (payload) => {
|
|
@@ -31284,6 +31309,7 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
31284
31309
|
}
|
|
31285
31310
|
if (event === 'post.deleted') {
|
|
31286
31311
|
const { postId, postedUserId } = payload.posts[0];
|
|
31312
|
+
processDeleteChildPost(payload);
|
|
31287
31313
|
try {
|
|
31288
31314
|
isInTombstone('post', postId);
|
|
31289
31315
|
}
|
|
@@ -31310,6 +31336,8 @@ const createPostEventSubscriber = (event, callback) => {
|
|
|
31310
31336
|
}
|
|
31311
31337
|
queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
|
|
31312
31338
|
}
|
|
31339
|
+
if (event === 'post.created')
|
|
31340
|
+
processCreateChildPost(payload);
|
|
31313
31341
|
callback(post.data);
|
|
31314
31342
|
}
|
|
31315
31343
|
};
|
|
@@ -31336,6 +31364,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
|
|
|
31336
31364
|
});
|
|
31337
31365
|
}
|
|
31338
31366
|
const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
|
|
31367
|
+
if (event === 'local.post.deleted')
|
|
31368
|
+
processDeleteChildPost(payload);
|
|
31339
31369
|
callback(post.data);
|
|
31340
31370
|
}
|
|
31341
31371
|
};
|
|
@@ -39114,6 +39144,9 @@ var index$b = /*#__PURE__*/Object.freeze({
|
|
|
39114
39144
|
id: feed.query.global_feed
|
|
39115
39145
|
*/
|
|
39116
39146
|
/**
|
|
39147
|
+
*
|
|
39148
|
+
* @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
|
|
39149
|
+
*
|
|
39117
39150
|
* ```js
|
|
39118
39151
|
* import { queryGlobalFeed } from '@amityco/ts-sdk'
|
|
39119
39152
|
* const posts = await queryGlobalFeed()
|
|
@@ -39196,1086 +39229,1023 @@ queryGlobalFeed.locally = (query) => {
|
|
|
39196
39229
|
: undefined;
|
|
39197
39230
|
};
|
|
39198
39231
|
|
|
39199
|
-
|
|
39200
|
-
|
|
39201
|
-
|
|
39202
|
-
|
|
39203
|
-
|
|
39204
|
-
|
|
39205
|
-
|
|
39206
|
-
|
|
39207
|
-
*
|
|
39208
|
-
* Queries a paginable list of {@link Amity.Post} objects
|
|
39209
|
-
*
|
|
39210
|
-
* @param query The query parameters
|
|
39211
|
-
* @returns A page of {@link Amity.Post} objects
|
|
39212
|
-
*
|
|
39213
|
-
* @category Feed API
|
|
39214
|
-
* @async
|
|
39215
|
-
* */
|
|
39216
|
-
const getCustomRankingGlobalFeed = async (query) => {
|
|
39217
|
-
const client = getActiveClient();
|
|
39218
|
-
client.log('feed/getCustomRankingGlobalFeed', query);
|
|
39219
|
-
const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
|
|
39220
|
-
const options = (() => {
|
|
39221
|
-
if (queryToken)
|
|
39222
|
-
return { token: queryToken };
|
|
39223
|
-
return undefined;
|
|
39224
|
-
})();
|
|
39225
|
-
const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
|
|
39226
|
-
params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
|
|
39227
|
-
});
|
|
39228
|
-
const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
|
|
39229
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39230
|
-
const { posts } = data;
|
|
39231
|
-
const cachedAt = client.cache && Date.now();
|
|
39232
|
-
if (client.cache) {
|
|
39233
|
-
ingestInCache(data);
|
|
39234
|
-
const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
|
|
39235
|
-
pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
|
|
39232
|
+
class CustomRankingGlobalFeedPaginationController extends PaginationController {
|
|
39233
|
+
async getRequest(queryParams, token) {
|
|
39234
|
+
const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
|
|
39235
|
+
const options = token ? { token } : { limit };
|
|
39236
|
+
const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
|
|
39237
|
+
params: Object.assign(Object.assign({}, params), { options }),
|
|
39238
|
+
});
|
|
39239
|
+
return queryResponse;
|
|
39236
39240
|
}
|
|
39237
|
-
|
|
39238
|
-
};
|
|
39239
|
-
/* end_public_function */
|
|
39240
|
-
/**
|
|
39241
|
-
* ```js
|
|
39242
|
-
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
39243
|
-
* const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
|
|
39244
|
-
* ```
|
|
39245
|
-
*
|
|
39246
|
-
* Queries a paginable list of {@link Amity.Post} objects from cache
|
|
39247
|
-
*
|
|
39248
|
-
* @param query The query parameters
|
|
39249
|
-
* @returns A page of {@link Amity.Post} objects
|
|
39250
|
-
*
|
|
39251
|
-
* @category Feed API
|
|
39252
|
-
* @async
|
|
39253
|
-
* */
|
|
39254
|
-
getCustomRankingGlobalFeed.locally = (query) => {
|
|
39255
|
-
var _a, _b;
|
|
39256
|
-
const client = getActiveClient();
|
|
39257
|
-
client.log('post/getCustomRankingGlobalFeed.locally', query);
|
|
39258
|
-
if (!client.cache)
|
|
39259
|
-
return;
|
|
39260
|
-
const params = __rest(query !== null && query !== void 0 ? query : {}, []);
|
|
39261
|
-
const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
|
|
39262
|
-
const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
|
|
39263
|
-
if (!(data === null || data === void 0 ? void 0 : data.posts.length))
|
|
39264
|
-
return;
|
|
39265
|
-
const posts = data.posts
|
|
39266
|
-
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
39267
|
-
.filter(Boolean)
|
|
39268
|
-
.map(({ data }) => data);
|
|
39269
|
-
const { paging } = data;
|
|
39270
|
-
return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
|
|
39271
|
-
? { data: posts.map(LinkedObject.post), cachedAt, paging }
|
|
39272
|
-
: undefined;
|
|
39273
|
-
};
|
|
39241
|
+
}
|
|
39274
39242
|
|
|
39275
|
-
var
|
|
39276
|
-
|
|
39277
|
-
|
|
39278
|
-
|
|
39279
|
-
|
|
39243
|
+
var EnumPostActions;
|
|
39244
|
+
(function (EnumPostActions) {
|
|
39245
|
+
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
39246
|
+
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
39247
|
+
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
39248
|
+
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
39249
|
+
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
39250
|
+
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
39251
|
+
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
39252
|
+
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
39253
|
+
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
39254
|
+
})(EnumPostActions || (EnumPostActions = {}));
|
|
39255
|
+
|
|
39256
|
+
class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
|
|
39257
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39258
|
+
super(query, cacheKey);
|
|
39259
|
+
this.notifyChange = notifyChange;
|
|
39260
|
+
this.preparePayload = preparePayload;
|
|
39261
|
+
}
|
|
39262
|
+
async saveToMainDB(response) {
|
|
39263
|
+
const processedPayload = await this.preparePayload(response);
|
|
39264
|
+
const client = getActiveClient();
|
|
39265
|
+
const cachedAt = client.cache && Date.now();
|
|
39266
|
+
if (client.cache) {
|
|
39267
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39268
|
+
}
|
|
39269
|
+
}
|
|
39270
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39271
|
+
var _a, _b;
|
|
39272
|
+
if (refresh) {
|
|
39273
|
+
pushToCache(this.cacheKey, {
|
|
39274
|
+
data: response.posts.map(getResolver('post')),
|
|
39275
|
+
});
|
|
39276
|
+
}
|
|
39277
|
+
else {
|
|
39278
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39279
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39280
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
39281
|
+
}
|
|
39282
|
+
}
|
|
39283
|
+
reactor(action) {
|
|
39284
|
+
return (post) => {
|
|
39285
|
+
var _a;
|
|
39286
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39287
|
+
if (!collection)
|
|
39288
|
+
return;
|
|
39289
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
39290
|
+
return;
|
|
39291
|
+
// Delete Action
|
|
39292
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
39293
|
+
// Parent Post - Remove from collection
|
|
39294
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
39295
|
+
}
|
|
39296
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
39297
|
+
// If the query has dataTypes array with value, check if post.dataType is include in the array
|
|
39298
|
+
if (this.query.dataTypes && this.query.dataTypes.length > 0) {
|
|
39299
|
+
if (!this.query.dataTypes.includes(post.dataType))
|
|
39300
|
+
return;
|
|
39301
|
+
}
|
|
39302
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
39303
|
+
}
|
|
39304
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
39305
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
39306
|
+
}
|
|
39307
|
+
pushToCache(this.cacheKey, collection);
|
|
39308
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
39309
|
+
};
|
|
39310
|
+
}
|
|
39311
|
+
subscribeRTE(createSubscriber) {
|
|
39312
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
39313
|
+
}
|
|
39314
|
+
}
|
|
39280
39315
|
|
|
39281
39316
|
/* begin_public_function
|
|
39282
|
-
id:
|
|
39317
|
+
id: comment.get_by_ids
|
|
39283
39318
|
*/
|
|
39284
39319
|
/**
|
|
39285
39320
|
* ```js
|
|
39286
|
-
* import {
|
|
39287
|
-
* const
|
|
39321
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39322
|
+
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
39288
39323
|
* ```
|
|
39289
39324
|
*
|
|
39290
|
-
* Fetches a collection of {@link Amity.
|
|
39325
|
+
* Fetches a collection of {@link Amity.Comment} objects
|
|
39291
39326
|
*
|
|
39292
|
-
* @param
|
|
39293
|
-
* @returns the associated collection of {@link Amity.
|
|
39327
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39328
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39294
39329
|
*
|
|
39295
|
-
* @category
|
|
39330
|
+
* @category Comment API
|
|
39296
39331
|
* @async
|
|
39297
39332
|
*/
|
|
39298
|
-
const
|
|
39333
|
+
const getCommentByIds = async (commentIds) => {
|
|
39299
39334
|
const client = getActiveClient();
|
|
39300
|
-
client.log('
|
|
39301
|
-
const
|
|
39302
|
-
let
|
|
39335
|
+
client.log('comment/getCommentByIds', commentIds);
|
|
39336
|
+
const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
|
|
39337
|
+
let data;
|
|
39303
39338
|
try {
|
|
39304
39339
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
39305
|
-
const response = await client.http.get(`/api/v3/
|
|
39306
|
-
params: {
|
|
39340
|
+
const response = await client.http.get(`/api/v3/comments/list`, {
|
|
39341
|
+
params: { commentIds: encodedCommentIds },
|
|
39307
39342
|
});
|
|
39308
|
-
|
|
39343
|
+
data = response.data;
|
|
39309
39344
|
}
|
|
39310
39345
|
catch (error) {
|
|
39311
|
-
|
|
39346
|
+
commentIds.forEach(commentId => {
|
|
39312
39347
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39313
|
-
pushToTombstone('
|
|
39348
|
+
pushToTombstone('comment', commentId);
|
|
39314
39349
|
}
|
|
39315
39350
|
});
|
|
39316
39351
|
throw error;
|
|
39317
39352
|
}
|
|
39318
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39319
39353
|
const cachedAt = client.cache && Date.now();
|
|
39320
39354
|
if (client.cache)
|
|
39321
39355
|
ingestInCache(data, { cachedAt });
|
|
39322
39356
|
return {
|
|
39323
|
-
data: data.
|
|
39357
|
+
data: data.comments.map(comment => LinkedObject.comment(comment)),
|
|
39324
39358
|
cachedAt,
|
|
39325
39359
|
};
|
|
39326
39360
|
};
|
|
39327
39361
|
/* end_public_function */
|
|
39328
39362
|
/**
|
|
39329
39363
|
* ```js
|
|
39330
|
-
* import {
|
|
39331
|
-
* const
|
|
39364
|
+
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
39365
|
+
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
39332
39366
|
* ```
|
|
39333
39367
|
*
|
|
39334
|
-
* Fetches a collection of {@link Amity.
|
|
39368
|
+
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
39335
39369
|
*
|
|
39336
|
-
* @param
|
|
39337
|
-
* @returns the associated collection of {@link Amity.
|
|
39370
|
+
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39371
|
+
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39338
39372
|
*
|
|
39339
|
-
* @category
|
|
39373
|
+
* @category Comment API
|
|
39340
39374
|
*/
|
|
39341
|
-
|
|
39375
|
+
getCommentByIds.locally = (commentIds) => {
|
|
39342
39376
|
var _a;
|
|
39343
39377
|
const client = getActiveClient();
|
|
39344
|
-
client.log('
|
|
39378
|
+
client.log('comment/getCommentByIds.locally', commentIds);
|
|
39345
39379
|
if (!client.cache)
|
|
39346
39380
|
return;
|
|
39347
|
-
const cached =
|
|
39348
|
-
.map(
|
|
39381
|
+
const cached = commentIds
|
|
39382
|
+
.map(commentId => pullFromCache(['comment', 'get', commentId]))
|
|
39349
39383
|
.filter(Boolean);
|
|
39350
|
-
const
|
|
39384
|
+
const comments = cached.map(({ data }) => data);
|
|
39351
39385
|
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
39352
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) <
|
|
39386
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
39353
39387
|
return;
|
|
39354
39388
|
return {
|
|
39355
|
-
data:
|
|
39389
|
+
data: comments.map(comment => LinkedObject.comment(comment)),
|
|
39356
39390
|
cachedAt: oldest.cachedAt,
|
|
39357
39391
|
};
|
|
39358
39392
|
};
|
|
39359
39393
|
|
|
39360
39394
|
/* begin_public_function
|
|
39361
|
-
id:
|
|
39395
|
+
id: comment.create
|
|
39362
39396
|
*/
|
|
39363
39397
|
/**
|
|
39364
39398
|
* ```js
|
|
39365
|
-
* import {
|
|
39366
|
-
* const
|
|
39367
|
-
* targetType: 'user',
|
|
39368
|
-
* targetId: 'foobar',
|
|
39369
|
-
* data: { text: 'hello world' }
|
|
39370
|
-
* }))
|
|
39399
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39400
|
+
* const newComment = await CommentRepository.createComment(bundle)
|
|
39371
39401
|
* ```
|
|
39372
39402
|
*
|
|
39373
|
-
* Creates an {@link Amity.
|
|
39403
|
+
* Creates an {@link Amity.Comment}
|
|
39374
39404
|
*
|
|
39375
|
-
* @param bundle The data necessary to create a new {@link Amity.
|
|
39376
|
-
* @returns The newly created {@link Amity.
|
|
39405
|
+
* @param bundle The data necessary to create a new {@link Amity.Comment}
|
|
39406
|
+
* @returns The newly created {@link Amity.Comment}
|
|
39377
39407
|
*
|
|
39378
|
-
* @category
|
|
39408
|
+
* @category Comment API
|
|
39379
39409
|
* @async
|
|
39380
39410
|
*/
|
|
39381
|
-
const
|
|
39411
|
+
const createComment = async (bundle) => {
|
|
39412
|
+
var _a;
|
|
39382
39413
|
const client = getActiveClient();
|
|
39383
|
-
client.log('
|
|
39384
|
-
|
|
39385
|
-
|
|
39386
|
-
|
|
39387
|
-
|
|
39388
|
-
|
|
39389
|
-
fireEvent('post.created', payload);
|
|
39390
|
-
const data = preparePostPayload(payload);
|
|
39414
|
+
client.log('comment/createComment', bundle);
|
|
39415
|
+
const { data } = await client.http.post('/api/v3/comments', bundle);
|
|
39416
|
+
const { comments } = data;
|
|
39417
|
+
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
39418
|
+
if (comments.length === 0)
|
|
39419
|
+
throw new Error('Comment not created');
|
|
39391
39420
|
const cachedAt = client.cache && Date.now();
|
|
39392
39421
|
if (client.cache)
|
|
39393
39422
|
ingestInCache(data, { cachedAt });
|
|
39394
|
-
|
|
39423
|
+
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
39424
|
+
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39425
|
+
if (post) {
|
|
39426
|
+
post.commentsCount += 1;
|
|
39427
|
+
fireEvent('local.post.updated', {
|
|
39428
|
+
posts: [post],
|
|
39429
|
+
categories: [],
|
|
39430
|
+
comments: [],
|
|
39431
|
+
communities: [],
|
|
39432
|
+
communityUsers: data.communityUsers,
|
|
39433
|
+
feeds: [],
|
|
39434
|
+
files: data.files,
|
|
39435
|
+
postChildren: [],
|
|
39436
|
+
users: data.users,
|
|
39437
|
+
videoStreamings: [],
|
|
39438
|
+
});
|
|
39439
|
+
}
|
|
39440
|
+
}
|
|
39441
|
+
else if (bundle.referenceType === 'story') {
|
|
39442
|
+
const storyIndex = pullFromCache([
|
|
39443
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39444
|
+
bundle.referenceId,
|
|
39445
|
+
]);
|
|
39446
|
+
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
39447
|
+
const cacheStory = pullFromCache([
|
|
39448
|
+
"story" /* STORY_KEY_CACHE.STORY */,
|
|
39449
|
+
'get',
|
|
39450
|
+
storyIndex.data,
|
|
39451
|
+
]);
|
|
39452
|
+
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
39453
|
+
fireEvent('story.updated', {
|
|
39454
|
+
stories: [
|
|
39455
|
+
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
39456
|
+
],
|
|
39457
|
+
categories: [],
|
|
39458
|
+
comments,
|
|
39459
|
+
communities: [],
|
|
39460
|
+
communityUsers: data.communityUsers,
|
|
39461
|
+
files: data.files,
|
|
39462
|
+
users: data.users,
|
|
39463
|
+
});
|
|
39464
|
+
}
|
|
39465
|
+
}
|
|
39466
|
+
}
|
|
39467
|
+
fireEvent('local.comment.created', data);
|
|
39395
39468
|
return {
|
|
39396
|
-
data: LinkedObject.
|
|
39469
|
+
data: LinkedObject.comment(comments[0]),
|
|
39397
39470
|
cachedAt,
|
|
39398
39471
|
};
|
|
39399
39472
|
};
|
|
39400
39473
|
/* end_public_function */
|
|
39401
39474
|
|
|
39402
39475
|
/* begin_public_function
|
|
39403
|
-
id:
|
|
39476
|
+
id: comment.update_comment
|
|
39404
39477
|
*/
|
|
39405
39478
|
/**
|
|
39406
39479
|
* ```js
|
|
39407
|
-
* import {
|
|
39408
|
-
* const updated = await
|
|
39480
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39481
|
+
* const updated = await CommentRepository.updateComment(commentId, {
|
|
39409
39482
|
* data: { text: 'hello world' }
|
|
39410
39483
|
* })
|
|
39411
39484
|
* ```
|
|
39412
39485
|
*
|
|
39413
|
-
* Updates an {@link Amity.
|
|
39486
|
+
* Updates an {@link Amity.Comment}
|
|
39414
39487
|
*
|
|
39415
|
-
* @param
|
|
39488
|
+
* @param commentId The ID of the {@link Amity.Comment} to edit
|
|
39416
39489
|
* @param patch The patch data to apply
|
|
39417
|
-
* @returns the updated {@link Amity.
|
|
39490
|
+
* @returns the updated {@link Amity.Comment} object
|
|
39418
39491
|
*
|
|
39419
|
-
* @category
|
|
39492
|
+
* @category Comment API
|
|
39420
39493
|
* @async
|
|
39421
39494
|
*/
|
|
39422
|
-
const
|
|
39495
|
+
const updateComment = async (commentId, patch) => {
|
|
39423
39496
|
const client = getActiveClient();
|
|
39424
|
-
client.log('user/
|
|
39425
|
-
const { data
|
|
39426
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39497
|
+
client.log('user/updateComment', patch);
|
|
39498
|
+
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
39427
39499
|
const cachedAt = client.cache && Date.now();
|
|
39428
39500
|
if (client.cache)
|
|
39429
39501
|
ingestInCache(data, { cachedAt });
|
|
39430
|
-
fireEvent('
|
|
39431
|
-
const {
|
|
39502
|
+
fireEvent('comment.updated', data);
|
|
39503
|
+
const { comments } = data;
|
|
39432
39504
|
return {
|
|
39433
|
-
data: LinkedObject.
|
|
39505
|
+
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
39434
39506
|
cachedAt,
|
|
39435
39507
|
};
|
|
39436
39508
|
};
|
|
39437
39509
|
/* end_public_function */
|
|
39438
39510
|
|
|
39511
|
+
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
39512
|
+
const applyMissingField = (rawData, isCreated = false) => {
|
|
39513
|
+
const { storyId, referenceId } = rawData;
|
|
39514
|
+
if (!isCreated) {
|
|
39515
|
+
if (referenceId)
|
|
39516
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
39517
|
+
}
|
|
39518
|
+
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
39519
|
+
};
|
|
39520
|
+
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
39521
|
+
const { stories } = data;
|
|
39522
|
+
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
39523
|
+
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
39524
|
+
};
|
|
39525
|
+
|
|
39526
|
+
const getStoryByStoryId$1 = async (storyId) => {
|
|
39527
|
+
const client = getActiveClient();
|
|
39528
|
+
client.log('story/getStoryByStoryId', storyId);
|
|
39529
|
+
// Get story referenceId from cache
|
|
39530
|
+
const cacheReferenceId = pullFromCache([
|
|
39531
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39532
|
+
storyId,
|
|
39533
|
+
]);
|
|
39534
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39535
|
+
const { data: referenceId } = cacheReferenceId;
|
|
39536
|
+
isInTombstone('story', referenceId);
|
|
39537
|
+
}
|
|
39538
|
+
let data;
|
|
39539
|
+
try {
|
|
39540
|
+
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
39541
|
+
data = convertRawStoryToInternal(response.data);
|
|
39542
|
+
}
|
|
39543
|
+
catch (error) {
|
|
39544
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39545
|
+
pushToTombstone('story', storyId);
|
|
39546
|
+
}
|
|
39547
|
+
throw error;
|
|
39548
|
+
}
|
|
39549
|
+
const cachedAt = client.cache && Date.now();
|
|
39550
|
+
if (client.cache) {
|
|
39551
|
+
ingestInCache(data, { cachedAt });
|
|
39552
|
+
}
|
|
39553
|
+
return {
|
|
39554
|
+
data: data.stories[0],
|
|
39555
|
+
cachedAt,
|
|
39556
|
+
};
|
|
39557
|
+
};
|
|
39558
|
+
getStoryByStoryId$1.locally = (storyId) => {
|
|
39559
|
+
const client = getActiveClient();
|
|
39560
|
+
client.log('story/getStorybyStoryId', storyId);
|
|
39561
|
+
// Get story referenceId from cache
|
|
39562
|
+
const cacheReferenceId = pullFromCache([
|
|
39563
|
+
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39564
|
+
storyId,
|
|
39565
|
+
]);
|
|
39566
|
+
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
39567
|
+
const { data: referenceId } = cacheReferenceId;
|
|
39568
|
+
isInTombstone('story', referenceId);
|
|
39569
|
+
}
|
|
39570
|
+
const cachedAt = client.cache && Date.now();
|
|
39571
|
+
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
39572
|
+
if (!storyCache)
|
|
39573
|
+
return;
|
|
39574
|
+
return {
|
|
39575
|
+
data: storyCache.data,
|
|
39576
|
+
cachedAt,
|
|
39577
|
+
};
|
|
39578
|
+
};
|
|
39579
|
+
|
|
39580
|
+
/* begin_public_function
|
|
39581
|
+
id: comment.soft_delete, comment.hard_delete
|
|
39582
|
+
*/
|
|
39439
39583
|
/**
|
|
39440
39584
|
* ```js
|
|
39441
|
-
* import {
|
|
39442
|
-
* const success = await
|
|
39585
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39586
|
+
* const success = await CommentRepository.deleteComment('foobar')
|
|
39443
39587
|
* ```
|
|
39444
39588
|
*
|
|
39445
|
-
* Deletes a {@link Amity.
|
|
39589
|
+
* Deletes a {@link Amity.Comment}
|
|
39446
39590
|
*
|
|
39447
|
-
* @param
|
|
39448
|
-
* @return A success boolean if the {@link Amity.
|
|
39591
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
39592
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
39449
39593
|
*
|
|
39450
|
-
* @
|
|
39594
|
+
* @category Comment API
|
|
39451
39595
|
* @async
|
|
39452
39596
|
*/
|
|
39453
|
-
const
|
|
39597
|
+
const deleteComment = async (commentId, permanent = false) => {
|
|
39454
39598
|
var _a;
|
|
39455
39599
|
const client = getActiveClient();
|
|
39456
|
-
const
|
|
39457
|
-
|
|
39600
|
+
const comment = await getComment$2(commentId);
|
|
39601
|
+
// API-FIX: This endpoint has not been implemented yet.
|
|
39602
|
+
await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
|
|
39458
39603
|
params: {
|
|
39459
|
-
|
|
39604
|
+
commentId,
|
|
39460
39605
|
permanent,
|
|
39461
39606
|
},
|
|
39462
39607
|
});
|
|
39463
|
-
//
|
|
39464
|
-
|
|
39465
|
-
|
|
39466
|
-
|
|
39467
|
-
|
|
39468
|
-
|
|
39469
|
-
|
|
39470
|
-
|
|
39471
|
-
|
|
39472
|
-
|
|
39473
|
-
|
|
39474
|
-
|
|
39475
|
-
if (key[1] !== 'get')
|
|
39476
|
-
return false;
|
|
39477
|
-
if (typeof key[2] === 'string')
|
|
39478
|
-
return key[2].includes(community.data.communityId);
|
|
39479
|
-
return false;
|
|
39480
|
-
})
|
|
39481
|
-
.map(({ data }) => data);
|
|
39482
|
-
fireEvent('community.updated', {
|
|
39483
|
-
communities: [community.data],
|
|
39608
|
+
// to support hard deletion
|
|
39609
|
+
const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
|
|
39610
|
+
if (permanent) {
|
|
39611
|
+
scheduleTask(() => pushToTombstone('comment', commentId));
|
|
39612
|
+
}
|
|
39613
|
+
else {
|
|
39614
|
+
upsertInCache(['comment', 'get', commentId], { isDeleted: true });
|
|
39615
|
+
}
|
|
39616
|
+
if (comment.data.referenceType === 'story') {
|
|
39617
|
+
const story = await getStoryByStoryId$1(comment.data.referenceId);
|
|
39618
|
+
fireEvent('local.story.updated', {
|
|
39619
|
+
stories: [story.data],
|
|
39484
39620
|
categories: [],
|
|
39485
|
-
|
|
39486
|
-
|
|
39621
|
+
comments: [],
|
|
39622
|
+
communities: [],
|
|
39623
|
+
communityUsers: [],
|
|
39487
39624
|
files: [],
|
|
39488
39625
|
users: [],
|
|
39489
39626
|
});
|
|
39490
39627
|
}
|
|
39491
|
-
// to support hard deletion
|
|
39492
|
-
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
39493
|
-
if (permanent) {
|
|
39494
|
-
setTimeout(() => {
|
|
39495
|
-
pushToTombstone('post', postId);
|
|
39496
|
-
}, 0);
|
|
39497
|
-
}
|
|
39498
39628
|
else {
|
|
39499
|
-
|
|
39629
|
+
const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39630
|
+
if (post) {
|
|
39631
|
+
let removeCount;
|
|
39632
|
+
if (!deleted.parentId) {
|
|
39633
|
+
// NOTE: delete the parent comment will remove all children comments
|
|
39634
|
+
removeCount = deleted.childrenNumber + 1;
|
|
39635
|
+
}
|
|
39636
|
+
else
|
|
39637
|
+
removeCount = 1;
|
|
39638
|
+
post.commentsCount -= removeCount;
|
|
39639
|
+
fireEvent('local.post.updated', {
|
|
39640
|
+
posts: [post],
|
|
39641
|
+
categories: [],
|
|
39642
|
+
comments: [],
|
|
39643
|
+
communities: [],
|
|
39644
|
+
communityUsers: [],
|
|
39645
|
+
feeds: [],
|
|
39646
|
+
files: [],
|
|
39647
|
+
postChildren: [],
|
|
39648
|
+
users: [],
|
|
39649
|
+
videoStreamings: [],
|
|
39650
|
+
});
|
|
39651
|
+
}
|
|
39500
39652
|
}
|
|
39501
|
-
fireEvent('local.
|
|
39502
|
-
|
|
39503
|
-
|
|
39504
|
-
comments: [],
|
|
39505
|
-
communities: [],
|
|
39506
|
-
communityUsers: [],
|
|
39507
|
-
feeds: [],
|
|
39653
|
+
fireEvent('local.comment.deleted', {
|
|
39654
|
+
comments: [deleted],
|
|
39655
|
+
commentChildren: [],
|
|
39508
39656
|
files: [],
|
|
39509
|
-
postChildren: [],
|
|
39510
39657
|
users: [],
|
|
39511
|
-
|
|
39658
|
+
communityUsers: [],
|
|
39512
39659
|
});
|
|
39513
|
-
return
|
|
39660
|
+
return deleted;
|
|
39514
39661
|
};
|
|
39662
|
+
/* end_public_function */
|
|
39515
39663
|
|
|
39516
39664
|
/* begin_public_function
|
|
39517
|
-
id:
|
|
39665
|
+
id: comment.soft_delete
|
|
39518
39666
|
*/
|
|
39519
39667
|
/**
|
|
39520
39668
|
* ```js
|
|
39521
|
-
* import {
|
|
39522
|
-
* const success = await
|
|
39669
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39670
|
+
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
39523
39671
|
* ```
|
|
39524
39672
|
*
|
|
39525
|
-
*
|
|
39673
|
+
* Deletes a {@link Amity.Comment}
|
|
39526
39674
|
*
|
|
39527
|
-
* @param
|
|
39528
|
-
* @return A success boolean if the {@link Amity.
|
|
39675
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
39676
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
39529
39677
|
*
|
|
39530
|
-
* @category
|
|
39531
|
-
* @async
|
|
39532
|
-
*/
|
|
39533
|
-
const softDeletePost = async (postId) => {
|
|
39534
|
-
const client = getActiveClient();
|
|
39535
|
-
client.log('post/softDeletePost', postId);
|
|
39536
|
-
const softDeleted = await deletePost(postId, false);
|
|
39537
|
-
return LinkedObject.post(softDeleted);
|
|
39538
|
-
};
|
|
39539
|
-
/* end_public_function */
|
|
39540
|
-
|
|
39541
|
-
/* begin_public_function
|
|
39542
|
-
id: post.hard_delete
|
|
39543
|
-
*/
|
|
39544
|
-
/**
|
|
39545
|
-
* ```js
|
|
39546
|
-
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
39547
|
-
* const success = await hardDeletePost('foobar')
|
|
39548
|
-
* ```
|
|
39549
|
-
*
|
|
39550
|
-
* Hard deletes a {@link Amity.Post}
|
|
39551
|
-
*
|
|
39552
|
-
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
39553
|
-
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
39554
|
-
*
|
|
39555
|
-
* @category Post API
|
|
39556
|
-
* @async
|
|
39557
|
-
*/
|
|
39558
|
-
const hardDeletePost = async (postId) => {
|
|
39559
|
-
const client = getActiveClient();
|
|
39560
|
-
client.log('post/hardDeletePost', postId);
|
|
39561
|
-
const hardDeleted = await deletePost(postId, true);
|
|
39562
|
-
return LinkedObject.post(hardDeleted);
|
|
39563
|
-
};
|
|
39564
|
-
/* end_public_function */
|
|
39565
|
-
|
|
39566
|
-
/* begin_public_function
|
|
39567
|
-
id: post.approve
|
|
39568
|
-
*/
|
|
39569
|
-
/**
|
|
39570
|
-
* ```js
|
|
39571
|
-
* import { approvePost } from '@amityco/ts-sdk'
|
|
39572
|
-
*
|
|
39573
|
-
* const { data: post } = await approvePost('postId')
|
|
39574
|
-
* ```
|
|
39575
|
-
*
|
|
39576
|
-
* Approves a {@link Amity.Post}
|
|
39577
|
-
*
|
|
39578
|
-
* @param postId The {@link Amity.Post} ID to be approved
|
|
39579
|
-
* @return A {@link Amity.Post} that was approved
|
|
39580
|
-
*
|
|
39581
|
-
* @category Post API
|
|
39678
|
+
* @category Comment API
|
|
39582
39679
|
* @async
|
|
39583
39680
|
*/
|
|
39584
|
-
const
|
|
39681
|
+
const softDeleteComment = async (commentId) => {
|
|
39585
39682
|
const client = getActiveClient();
|
|
39586
|
-
client.log('
|
|
39587
|
-
const
|
|
39588
|
-
|
|
39589
|
-
// fire virtual event for community update
|
|
39590
|
-
if (payload.posts[0].targetType === 'community') {
|
|
39591
|
-
fireEvent('community.updated', payload);
|
|
39592
|
-
}
|
|
39593
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39594
|
-
const cachedAt = client.cache && Date.now();
|
|
39595
|
-
if (client.cache)
|
|
39596
|
-
ingestInCache(data, { cachedAt });
|
|
39597
|
-
return {
|
|
39598
|
-
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
39599
|
-
cachedAt,
|
|
39600
|
-
};
|
|
39683
|
+
client.log('comment/softDeleteComment', commentId);
|
|
39684
|
+
const softDeleted = deleteComment(commentId);
|
|
39685
|
+
return softDeleted;
|
|
39601
39686
|
};
|
|
39602
39687
|
/* end_public_function */
|
|
39603
39688
|
|
|
39604
39689
|
/* begin_public_function
|
|
39605
|
-
id:
|
|
39690
|
+
id: comment.hard_delete
|
|
39606
39691
|
*/
|
|
39607
39692
|
/**
|
|
39608
39693
|
* ```js
|
|
39609
|
-
* import {
|
|
39610
|
-
*
|
|
39611
|
-
* const {data: post} = await declinePost('postId')
|
|
39694
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39695
|
+
* const success = await CommentRepository.hardDeleteComment('foobar')
|
|
39612
39696
|
* ```
|
|
39613
39697
|
*
|
|
39614
|
-
*
|
|
39698
|
+
* Deletes a {@link Amity.Comment}
|
|
39615
39699
|
*
|
|
39616
|
-
* @param
|
|
39617
|
-
* @return A {@link Amity.
|
|
39700
|
+
* @param commentId The {@link Amity.Comment} ID to delete
|
|
39701
|
+
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
39618
39702
|
*
|
|
39619
|
-
* @category
|
|
39703
|
+
* @category Comment API
|
|
39620
39704
|
* @async
|
|
39621
39705
|
*/
|
|
39622
|
-
const
|
|
39706
|
+
const hardDeleteComment = async (commentId) => {
|
|
39623
39707
|
const client = getActiveClient();
|
|
39624
|
-
client.log('
|
|
39625
|
-
const
|
|
39626
|
-
|
|
39627
|
-
if (payload.posts[0].targetType === 'community') {
|
|
39628
|
-
fireEvent('community.updated', payload);
|
|
39629
|
-
}
|
|
39630
|
-
fireEvent('post.declined', payload);
|
|
39631
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39632
|
-
const cachedAt = client.cache && Date.now();
|
|
39633
|
-
if (client.cache)
|
|
39634
|
-
ingestInCache(data, { cachedAt });
|
|
39635
|
-
return {
|
|
39636
|
-
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
39637
|
-
cachedAt,
|
|
39638
|
-
};
|
|
39708
|
+
client.log('comment/hardDeleteComment', commentId);
|
|
39709
|
+
const hardDeleted = deleteComment(commentId, true);
|
|
39710
|
+
return hardDeleted;
|
|
39639
39711
|
};
|
|
39640
39712
|
/* end_public_function */
|
|
39641
39713
|
|
|
39642
39714
|
/* begin_public_function
|
|
39643
|
-
id:
|
|
39715
|
+
id: comment.flag
|
|
39644
39716
|
*/
|
|
39645
39717
|
/**
|
|
39646
39718
|
* ```js
|
|
39647
|
-
* import {
|
|
39648
|
-
* const flagged = await
|
|
39719
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39720
|
+
* const flagged = await CommentRepository.flagComment(commentId, reason)
|
|
39649
39721
|
* ```
|
|
39650
39722
|
*
|
|
39651
|
-
* @param
|
|
39652
|
-
* @param reason the reason to flag the
|
|
39653
|
-
* @returns
|
|
39723
|
+
* @param commentId The ID of the comment to flag
|
|
39724
|
+
* @param reason the reason to flag the comment
|
|
39725
|
+
* @returns the created report result
|
|
39654
39726
|
*
|
|
39655
|
-
* @category
|
|
39727
|
+
* @category Comment API
|
|
39656
39728
|
* @async
|
|
39657
39729
|
* */
|
|
39658
|
-
const
|
|
39730
|
+
const flagComment = async (commentId, reason) => {
|
|
39659
39731
|
const client = getActiveClient();
|
|
39660
|
-
client.log('
|
|
39732
|
+
client.log('comment/flagComment', commentId);
|
|
39661
39733
|
const isPredefinedReason = reason &&
|
|
39662
39734
|
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
39663
39735
|
const body = {
|
|
39664
39736
|
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
39665
39737
|
detail: reason && !isPredefinedReason ? reason : '',
|
|
39666
39738
|
};
|
|
39667
|
-
const { data: payload } = await client.http.post(`/api/v3/
|
|
39739
|
+
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
39668
39740
|
if (client.cache) {
|
|
39669
|
-
ingestInCache(
|
|
39741
|
+
ingestInCache(payload);
|
|
39670
39742
|
}
|
|
39671
|
-
fireEvent('
|
|
39743
|
+
fireEvent('comment.flagged', payload);
|
|
39672
39744
|
return !!payload;
|
|
39673
39745
|
};
|
|
39674
39746
|
/* end_public_function */
|
|
39675
39747
|
|
|
39676
39748
|
/* begin_public_function
|
|
39677
|
-
id:
|
|
39749
|
+
id: comment.unflag
|
|
39678
39750
|
*/
|
|
39679
39751
|
/**
|
|
39680
39752
|
* ```js
|
|
39681
|
-
* import {
|
|
39682
|
-
* const unflagged = await
|
|
39753
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39754
|
+
* const unflagged = await CommentRepository.unflagComment('commentId')
|
|
39683
39755
|
* ```
|
|
39684
39756
|
*
|
|
39685
|
-
* @param
|
|
39686
|
-
* @returns the
|
|
39757
|
+
* @param commentId The ID of comment to unflag
|
|
39758
|
+
* @returns the unflagged result
|
|
39687
39759
|
*
|
|
39688
|
-
* @category
|
|
39760
|
+
* @category Comment API
|
|
39689
39761
|
* @async
|
|
39690
39762
|
* */
|
|
39691
|
-
const
|
|
39763
|
+
const unflagComment = async (commentId) => {
|
|
39692
39764
|
const client = getActiveClient();
|
|
39693
|
-
client.log('
|
|
39694
|
-
const { data: payload } = await client.http.delete(`/api/v3/
|
|
39765
|
+
client.log('comment/unflagComment', commentId);
|
|
39766
|
+
const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
|
|
39695
39767
|
if (client.cache) {
|
|
39696
|
-
ingestInCache(
|
|
39768
|
+
ingestInCache(payload);
|
|
39697
39769
|
}
|
|
39698
|
-
fireEvent('
|
|
39770
|
+
fireEvent('comment.unflagged', payload);
|
|
39699
39771
|
return !!payload;
|
|
39700
39772
|
};
|
|
39701
39773
|
/* end_public_function */
|
|
39702
39774
|
|
|
39703
39775
|
/* begin_public_function
|
|
39704
|
-
id:
|
|
39776
|
+
id: comment.check_flag_by_me
|
|
39705
39777
|
*/
|
|
39706
39778
|
/**
|
|
39707
39779
|
* ```js
|
|
39708
|
-
* import {
|
|
39709
|
-
* const isReported = await
|
|
39780
|
+
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39781
|
+
* const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
|
|
39710
39782
|
* ```
|
|
39711
39783
|
*
|
|
39712
|
-
* @param
|
|
39713
|
-
* @returns `true` if the
|
|
39784
|
+
* @param commentId The ID of the comment to check if flagged by current user
|
|
39785
|
+
* @returns `true` if the comment is flagged by me, `false` if doesn't.
|
|
39714
39786
|
*
|
|
39715
|
-
* @category
|
|
39787
|
+
* @category Comment API
|
|
39716
39788
|
* @async
|
|
39717
39789
|
* */
|
|
39718
|
-
const
|
|
39790
|
+
const isCommentFlaggedByMe = async (commentId) => {
|
|
39719
39791
|
const client = getActiveClient();
|
|
39720
|
-
client.log('
|
|
39721
|
-
const { data: { result }, } = await client.http.get(`/api/v3/
|
|
39792
|
+
client.log('comment/isCommentFlaggedByMe', commentId);
|
|
39793
|
+
const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
|
|
39722
39794
|
return result;
|
|
39723
39795
|
};
|
|
39724
39796
|
/* end_public_function */
|
|
39725
39797
|
|
|
39726
|
-
|
|
39727
|
-
id: post.create.clip_post
|
|
39728
|
-
*/
|
|
39729
|
-
/**
|
|
39730
|
-
* ```js
|
|
39731
|
-
* import { PostRepository } from '@amityco/ts-sdk'
|
|
39732
|
-
* const created = await PostRepository.createClipPost({
|
|
39733
|
-
* targetType: 'user',
|
|
39734
|
-
* targetId: 'foobar',
|
|
39735
|
-
* dataType: 'clip',
|
|
39736
|
-
* data: { text: 'hello world' },
|
|
39737
|
-
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
39738
|
-
* }))
|
|
39739
|
-
* ```
|
|
39740
|
-
*
|
|
39741
|
-
* Creates an {@link Amity.Post}
|
|
39742
|
-
*
|
|
39743
|
-
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
39744
|
-
* @returns The newly created {@link Amity.Post}
|
|
39745
|
-
*
|
|
39746
|
-
* @category Post API
|
|
39747
|
-
* @async
|
|
39748
|
-
*/
|
|
39749
|
-
const createClipPost = async (bundle) => {
|
|
39750
|
-
const client = getActiveClient();
|
|
39751
|
-
client.log('post/createPost', bundle);
|
|
39752
|
-
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
39753
|
-
fireEvent('post.created', payload);
|
|
39754
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
39755
|
-
const cachedAt = client.cache && Date.now();
|
|
39756
|
-
if (client.cache)
|
|
39757
|
-
ingestInCache(data, { cachedAt });
|
|
39758
|
-
const { posts } = data;
|
|
39759
|
-
return {
|
|
39760
|
-
data: LinkedObject.post(posts[0]),
|
|
39761
|
-
cachedAt,
|
|
39762
|
-
};
|
|
39763
|
-
};
|
|
39764
|
-
/* end_public_function */
|
|
39765
|
-
|
|
39766
|
-
/* begin_public_function
|
|
39767
|
-
id: comment.get_by_ids
|
|
39768
|
-
*/
|
|
39769
|
-
/**
|
|
39770
|
-
* ```js
|
|
39771
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
39772
|
-
* const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
|
|
39773
|
-
* ```
|
|
39774
|
-
*
|
|
39775
|
-
* Fetches a collection of {@link Amity.Comment} objects
|
|
39776
|
-
*
|
|
39777
|
-
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39778
|
-
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39779
|
-
*
|
|
39780
|
-
* @category Comment API
|
|
39781
|
-
* @async
|
|
39782
|
-
*/
|
|
39783
|
-
const getCommentByIds = async (commentIds) => {
|
|
39798
|
+
const getComment$1 = async (commentId) => {
|
|
39784
39799
|
const client = getActiveClient();
|
|
39785
|
-
client.log('comment/
|
|
39786
|
-
|
|
39800
|
+
client.log('comment/getComment', commentId);
|
|
39801
|
+
isInTombstone('comment', commentId);
|
|
39787
39802
|
let data;
|
|
39788
39803
|
try {
|
|
39789
39804
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
39790
|
-
const response = await client.http.get(`/api/v3/comments
|
|
39791
|
-
params: { commentIds: encodedCommentIds },
|
|
39792
|
-
});
|
|
39805
|
+
const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
|
|
39793
39806
|
data = response.data;
|
|
39794
39807
|
}
|
|
39795
39808
|
catch (error) {
|
|
39796
|
-
|
|
39797
|
-
|
|
39798
|
-
|
|
39799
|
-
}
|
|
39800
|
-
});
|
|
39809
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39810
|
+
pushToTombstone('comment', commentId);
|
|
39811
|
+
}
|
|
39801
39812
|
throw error;
|
|
39802
39813
|
}
|
|
39803
39814
|
const cachedAt = client.cache && Date.now();
|
|
39804
39815
|
if (client.cache)
|
|
39805
39816
|
ingestInCache(data, { cachedAt });
|
|
39817
|
+
const { comments } = data;
|
|
39806
39818
|
return {
|
|
39807
|
-
data:
|
|
39819
|
+
data: comments.find(comment => comment.commentId === commentId),
|
|
39808
39820
|
cachedAt,
|
|
39809
39821
|
};
|
|
39810
39822
|
};
|
|
39811
|
-
|
|
39812
|
-
/**
|
|
39813
|
-
* ```js
|
|
39814
|
-
* import { getCommentByIds } from '@amityco/ts-sdk'
|
|
39815
|
-
* const comments = getCommentByIds.locally(['foo', 'bar'])
|
|
39816
|
-
* ```
|
|
39817
|
-
*
|
|
39818
|
-
* Fetches a collection of {@link Amity.Comment} objects from cache
|
|
39819
|
-
*
|
|
39820
|
-
* @param commentIds the IDs of the {@link Amity.Comment} to fetch
|
|
39821
|
-
* @returns the associated collection of {@link Amity.Comment} objects
|
|
39822
|
-
*
|
|
39823
|
-
* @category Comment API
|
|
39824
|
-
*/
|
|
39825
|
-
getCommentByIds.locally = (commentIds) => {
|
|
39826
|
-
var _a;
|
|
39823
|
+
getComment$1.locally = (commentId) => {
|
|
39827
39824
|
const client = getActiveClient();
|
|
39828
|
-
client.log('comment/
|
|
39825
|
+
client.log('comment/getComment.locally', commentId);
|
|
39829
39826
|
if (!client.cache)
|
|
39830
39827
|
return;
|
|
39831
|
-
const cached =
|
|
39832
|
-
|
|
39833
|
-
.filter(Boolean);
|
|
39834
|
-
const comments = cached.map(({ data }) => data);
|
|
39835
|
-
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
39836
|
-
if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
|
|
39828
|
+
const cached = pullFromCache(['comment', 'get', commentId]);
|
|
39829
|
+
if (!cached)
|
|
39837
39830
|
return;
|
|
39838
39831
|
return {
|
|
39839
|
-
data:
|
|
39840
|
-
cachedAt:
|
|
39832
|
+
data: cached.data,
|
|
39833
|
+
cachedAt: cached.cachedAt,
|
|
39841
39834
|
};
|
|
39842
39835
|
};
|
|
39843
39836
|
|
|
39844
|
-
/* begin_public_function
|
|
39845
|
-
id: comment.create
|
|
39846
|
-
*/
|
|
39847
39837
|
/**
|
|
39848
39838
|
* ```js
|
|
39849
|
-
* import {
|
|
39850
|
-
* const
|
|
39839
|
+
* import { onCommentDeleteLocal } from '@amityco/ts-sdk'
|
|
39840
|
+
* const dispose = onCommentDeleteLocal(comment => {
|
|
39841
|
+
* // ...
|
|
39842
|
+
* })
|
|
39851
39843
|
* ```
|
|
39852
39844
|
*
|
|
39853
|
-
*
|
|
39845
|
+
* Fired when a {@link Amity.InternalComment} has been deleted
|
|
39854
39846
|
*
|
|
39855
|
-
* @param
|
|
39856
|
-
* @returns
|
|
39847
|
+
* @param callback The function to call when the event was fired
|
|
39848
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39857
39849
|
*
|
|
39858
|
-
* @category Comment
|
|
39859
|
-
* @async
|
|
39850
|
+
* @category Comment Events
|
|
39860
39851
|
*/
|
|
39861
|
-
const
|
|
39862
|
-
|
|
39852
|
+
const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
|
|
39853
|
+
|
|
39854
|
+
/**
|
|
39855
|
+
* ```js
|
|
39856
|
+
* import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
|
|
39857
|
+
* const dispose = onLocalCommentReactionAdded(comment => {
|
|
39858
|
+
* // ...
|
|
39859
|
+
* })
|
|
39860
|
+
* ```
|
|
39861
|
+
*
|
|
39862
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
39863
|
+
*
|
|
39864
|
+
* @param callback The function to call when the event was fired
|
|
39865
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39866
|
+
*
|
|
39867
|
+
* @category Comment Events
|
|
39868
|
+
*/
|
|
39869
|
+
const onLocalCommentReactionAdded = (callback) => {
|
|
39863
39870
|
const client = getActiveClient();
|
|
39864
|
-
|
|
39865
|
-
|
|
39866
|
-
|
|
39867
|
-
// BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
|
|
39868
|
-
if (comments.length === 0)
|
|
39869
|
-
throw new Error('Comment not created');
|
|
39870
|
-
const cachedAt = client.cache && Date.now();
|
|
39871
|
-
if (client.cache)
|
|
39872
|
-
ingestInCache(data, { cachedAt });
|
|
39873
|
-
if (['post', 'content'].includes(bundle.referenceType)) {
|
|
39874
|
-
const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
|
|
39875
|
-
if (post) {
|
|
39876
|
-
post.commentsCount += 1;
|
|
39877
|
-
fireEvent('local.post.updated', {
|
|
39878
|
-
posts: [post],
|
|
39879
|
-
categories: [],
|
|
39880
|
-
comments: [],
|
|
39881
|
-
communities: [],
|
|
39882
|
-
communityUsers: data.communityUsers,
|
|
39883
|
-
feeds: [],
|
|
39884
|
-
files: data.files,
|
|
39885
|
-
postChildren: [],
|
|
39886
|
-
users: data.users,
|
|
39887
|
-
videoStreamings: [],
|
|
39888
|
-
});
|
|
39871
|
+
const filter = ({ comment }) => {
|
|
39872
|
+
if (!client.cache) {
|
|
39873
|
+
callback(comment);
|
|
39889
39874
|
}
|
|
39890
|
-
|
|
39891
|
-
|
|
39892
|
-
|
|
39893
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
39894
|
-
bundle.referenceId,
|
|
39895
|
-
]);
|
|
39896
|
-
if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
|
|
39897
|
-
const cacheStory = pullFromCache([
|
|
39898
|
-
"story" /* STORY_KEY_CACHE.STORY */,
|
|
39899
|
-
'get',
|
|
39900
|
-
storyIndex.data,
|
|
39901
|
-
]);
|
|
39902
|
-
if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
|
|
39903
|
-
fireEvent('story.updated', {
|
|
39904
|
-
stories: [
|
|
39905
|
-
Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
|
|
39906
|
-
],
|
|
39907
|
-
categories: [],
|
|
39908
|
-
comments,
|
|
39909
|
-
communities: [],
|
|
39910
|
-
communityUsers: data.communityUsers,
|
|
39911
|
-
files: data.files,
|
|
39912
|
-
users: data.users,
|
|
39913
|
-
});
|
|
39914
|
-
}
|
|
39875
|
+
else {
|
|
39876
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
39877
|
+
callback(commentLinkedObject(comment));
|
|
39915
39878
|
}
|
|
39916
|
-
}
|
|
39917
|
-
fireEvent('local.comment.created', data);
|
|
39918
|
-
return {
|
|
39919
|
-
data: LinkedObject.comment(comments[0]),
|
|
39920
|
-
cachedAt,
|
|
39921
39879
|
};
|
|
39880
|
+
return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
|
|
39922
39881
|
};
|
|
39923
|
-
/* end_public_function */
|
|
39924
39882
|
|
|
39925
|
-
/* begin_public_function
|
|
39926
|
-
id: comment.update_comment
|
|
39927
|
-
*/
|
|
39928
39883
|
/**
|
|
39929
39884
|
* ```js
|
|
39930
|
-
* import {
|
|
39931
|
-
* const
|
|
39932
|
-
*
|
|
39885
|
+
* import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
|
|
39886
|
+
* const dispose = onLocalCommentReactionRemoved(comment => {
|
|
39887
|
+
* // ...
|
|
39933
39888
|
* })
|
|
39934
39889
|
* ```
|
|
39935
39890
|
*
|
|
39936
|
-
*
|
|
39891
|
+
* Fired when a {@link Amity.InternalComment} has been reacted
|
|
39937
39892
|
*
|
|
39938
|
-
* @param
|
|
39939
|
-
* @
|
|
39940
|
-
* @returns the updated {@link Amity.Comment} object
|
|
39893
|
+
* @param callback The function to call when the event was fired
|
|
39894
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
39941
39895
|
*
|
|
39942
|
-
* @category Comment
|
|
39943
|
-
* @async
|
|
39896
|
+
* @category Comment Events
|
|
39944
39897
|
*/
|
|
39945
|
-
const
|
|
39946
|
-
const client = getActiveClient();
|
|
39947
|
-
client.log('user/updateComment', patch);
|
|
39948
|
-
const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
|
|
39949
|
-
const cachedAt = client.cache && Date.now();
|
|
39950
|
-
if (client.cache)
|
|
39951
|
-
ingestInCache(data, { cachedAt });
|
|
39952
|
-
fireEvent('comment.updated', data);
|
|
39953
|
-
const { comments } = data;
|
|
39954
|
-
return {
|
|
39955
|
-
data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
|
|
39956
|
-
cachedAt,
|
|
39957
|
-
};
|
|
39958
|
-
};
|
|
39959
|
-
/* end_public_function */
|
|
39960
|
-
|
|
39961
|
-
// Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
|
|
39962
|
-
const applyMissingField = (rawData, isCreated = false) => {
|
|
39963
|
-
const { storyId, referenceId } = rawData;
|
|
39964
|
-
if (!isCreated) {
|
|
39965
|
-
if (referenceId)
|
|
39966
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
|
|
39967
|
-
}
|
|
39968
|
-
return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
|
|
39969
|
-
};
|
|
39970
|
-
const convertRawStoryToInternal = (data, isCreated = false) => {
|
|
39971
|
-
const { stories } = data;
|
|
39972
|
-
const storiesData = stories.map(story => applyMissingField(story, isCreated));
|
|
39973
|
-
return Object.assign(Object.assign({}, data), { stories: storiesData });
|
|
39974
|
-
};
|
|
39975
|
-
|
|
39976
|
-
const getStoryByStoryId$1 = async (storyId) => {
|
|
39898
|
+
const onLocalCommentReactionRemoved = (callback) => {
|
|
39977
39899
|
const client = getActiveClient();
|
|
39978
|
-
|
|
39979
|
-
|
|
39980
|
-
|
|
39981
|
-
|
|
39982
|
-
|
|
39983
|
-
|
|
39984
|
-
|
|
39985
|
-
const { data: referenceId } = cacheReferenceId;
|
|
39986
|
-
isInTombstone('story', referenceId);
|
|
39987
|
-
}
|
|
39988
|
-
let data;
|
|
39989
|
-
try {
|
|
39990
|
-
const response = await client.http.get(`/api/v4/stories/${storyId}`);
|
|
39991
|
-
data = convertRawStoryToInternal(response.data);
|
|
39992
|
-
}
|
|
39993
|
-
catch (error) {
|
|
39994
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
39995
|
-
pushToTombstone('story', storyId);
|
|
39900
|
+
const filter = ({ comment }) => {
|
|
39901
|
+
if (!client.cache) {
|
|
39902
|
+
callback(comment);
|
|
39903
|
+
}
|
|
39904
|
+
else {
|
|
39905
|
+
upsertInCache(['comment', 'get', comment.commentId], comment);
|
|
39906
|
+
callback(commentLinkedObject(comment));
|
|
39996
39907
|
}
|
|
39997
|
-
throw error;
|
|
39998
|
-
}
|
|
39999
|
-
const cachedAt = client.cache && Date.now();
|
|
40000
|
-
if (client.cache) {
|
|
40001
|
-
ingestInCache(data, { cachedAt });
|
|
40002
|
-
}
|
|
40003
|
-
return {
|
|
40004
|
-
data: data.stories[0],
|
|
40005
|
-
cachedAt,
|
|
40006
|
-
};
|
|
40007
|
-
};
|
|
40008
|
-
getStoryByStoryId$1.locally = (storyId) => {
|
|
40009
|
-
const client = getActiveClient();
|
|
40010
|
-
client.log('story/getStorybyStoryId', storyId);
|
|
40011
|
-
// Get story referenceId from cache
|
|
40012
|
-
const cacheReferenceId = pullFromCache([
|
|
40013
|
-
"story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
|
|
40014
|
-
storyId,
|
|
40015
|
-
]);
|
|
40016
|
-
if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
|
|
40017
|
-
const { data: referenceId } = cacheReferenceId;
|
|
40018
|
-
isInTombstone('story', referenceId);
|
|
40019
|
-
}
|
|
40020
|
-
const cachedAt = client.cache && Date.now();
|
|
40021
|
-
const storyCache = pullFromCache(['story', 'get', storyId]);
|
|
40022
|
-
if (!storyCache)
|
|
40023
|
-
return;
|
|
40024
|
-
return {
|
|
40025
|
-
data: storyCache.data,
|
|
40026
|
-
cachedAt,
|
|
40027
39908
|
};
|
|
39909
|
+
return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
|
|
40028
39910
|
};
|
|
40029
39911
|
|
|
40030
39912
|
/* begin_public_function
|
|
40031
|
-
id: comment.
|
|
39913
|
+
id: comment.get
|
|
40032
39914
|
*/
|
|
40033
39915
|
/**
|
|
40034
39916
|
* ```js
|
|
40035
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40036
|
-
*
|
|
39917
|
+
* import { CommentRepository } from '@amityco/ts-sdk';
|
|
39918
|
+
*
|
|
39919
|
+
* let comment;
|
|
39920
|
+
*
|
|
39921
|
+
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
39922
|
+
* comment = response.data;
|
|
39923
|
+
* });
|
|
40037
39924
|
* ```
|
|
40038
39925
|
*
|
|
40039
|
-
*
|
|
39926
|
+
* Observe all mutation on a given {@link Amity.Comment}
|
|
40040
39927
|
*
|
|
40041
|
-
* @param commentId
|
|
40042
|
-
* @
|
|
39928
|
+
* @param commentId the ID of the comment to observe
|
|
39929
|
+
* @param callback the function to call when new data are available
|
|
39930
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40043
39931
|
*
|
|
40044
|
-
* @category Comment
|
|
40045
|
-
* @async
|
|
39932
|
+
* @category Comment Live Object
|
|
40046
39933
|
*/
|
|
40047
|
-
const
|
|
40048
|
-
|
|
40049
|
-
|
|
40050
|
-
|
|
40051
|
-
|
|
40052
|
-
|
|
40053
|
-
|
|
40054
|
-
|
|
40055
|
-
|
|
40056
|
-
|
|
40057
|
-
|
|
40058
|
-
|
|
40059
|
-
|
|
40060
|
-
|
|
40061
|
-
|
|
40062
|
-
|
|
40063
|
-
|
|
40064
|
-
|
|
40065
|
-
|
|
40066
|
-
|
|
40067
|
-
|
|
40068
|
-
|
|
40069
|
-
|
|
39934
|
+
const getComment = (commentId, callback) => {
|
|
39935
|
+
return liveObject(commentId, callback, 'commentId', getComment$1, [
|
|
39936
|
+
onCommentDeleteLocal,
|
|
39937
|
+
onCommentDeleted,
|
|
39938
|
+
onCommentFlagged,
|
|
39939
|
+
onCommentReactionAdded,
|
|
39940
|
+
onCommentReactionRemoved,
|
|
39941
|
+
onCommentUnflagged,
|
|
39942
|
+
onCommentUpdated,
|
|
39943
|
+
onLocalCommentReactionAdded,
|
|
39944
|
+
onLocalCommentReactionRemoved,
|
|
39945
|
+
]);
|
|
39946
|
+
};
|
|
39947
|
+
/* end_public_function */
|
|
39948
|
+
|
|
39949
|
+
class CommentPaginationController extends PaginationController {
|
|
39950
|
+
async getRequest(queryParams, token) {
|
|
39951
|
+
const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
|
|
39952
|
+
const baseOptions = {
|
|
39953
|
+
type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
|
|
39954
|
+
};
|
|
39955
|
+
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
39956
|
+
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
39957
|
+
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
40070
39958
|
});
|
|
39959
|
+
return queryResponse;
|
|
40071
39960
|
}
|
|
40072
|
-
|
|
40073
|
-
|
|
40074
|
-
|
|
40075
|
-
|
|
40076
|
-
|
|
40077
|
-
|
|
40078
|
-
|
|
40079
|
-
|
|
40080
|
-
|
|
40081
|
-
|
|
40082
|
-
|
|
40083
|
-
|
|
40084
|
-
|
|
40085
|
-
|
|
40086
|
-
|
|
40087
|
-
|
|
40088
|
-
|
|
40089
|
-
|
|
40090
|
-
|
|
40091
|
-
|
|
40092
|
-
|
|
40093
|
-
|
|
39961
|
+
}
|
|
39962
|
+
|
|
39963
|
+
var EnumCommentActions;
|
|
39964
|
+
(function (EnumCommentActions) {
|
|
39965
|
+
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
39966
|
+
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
39967
|
+
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
39968
|
+
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
39969
|
+
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
39970
|
+
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
39971
|
+
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
39972
|
+
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
39973
|
+
|
|
39974
|
+
class CommentQueryStreamController extends QueryStreamController {
|
|
39975
|
+
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
39976
|
+
super(query, cacheKey);
|
|
39977
|
+
this.notifyChange = notifyChange;
|
|
39978
|
+
this.preparePayload = preparePayload;
|
|
39979
|
+
}
|
|
39980
|
+
async saveToMainDB(response) {
|
|
39981
|
+
const processedPayload = await this.preparePayload(response);
|
|
39982
|
+
const client = getActiveClient();
|
|
39983
|
+
const cachedAt = client.cache && Date.now();
|
|
39984
|
+
if (client.cache) {
|
|
39985
|
+
ingestInCache(processedPayload, { cachedAt });
|
|
39986
|
+
}
|
|
39987
|
+
}
|
|
39988
|
+
appendToQueryStream(response, direction, refresh = false) {
|
|
39989
|
+
var _a, _b;
|
|
39990
|
+
if (refresh) {
|
|
39991
|
+
pushToCache(this.cacheKey, {
|
|
39992
|
+
data: response.comments.map(getResolver('comment')),
|
|
40094
39993
|
});
|
|
40095
39994
|
}
|
|
39995
|
+
else {
|
|
39996
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
39997
|
+
const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
39998
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
|
|
39999
|
+
}
|
|
40096
40000
|
}
|
|
40097
|
-
|
|
40098
|
-
|
|
40099
|
-
|
|
40100
|
-
|
|
40101
|
-
|
|
40102
|
-
|
|
40103
|
-
|
|
40104
|
-
|
|
40105
|
-
|
|
40001
|
+
reactor(action) {
|
|
40002
|
+
return (comment) => {
|
|
40003
|
+
var _a;
|
|
40004
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40005
|
+
if (this.query.referenceId !== comment.referenceId ||
|
|
40006
|
+
this.query.referenceType !== comment.referenceType ||
|
|
40007
|
+
!collection) {
|
|
40008
|
+
return;
|
|
40009
|
+
}
|
|
40010
|
+
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
40011
|
+
return;
|
|
40012
|
+
}
|
|
40013
|
+
if (!this.query.parentId && comment.parentId) {
|
|
40014
|
+
return;
|
|
40015
|
+
}
|
|
40016
|
+
if (action === EnumCommentActions.OnCommentCreated) {
|
|
40017
|
+
collection.data = [...new Set([comment.commentId, ...collection.data])];
|
|
40018
|
+
}
|
|
40019
|
+
pushToCache(this.cacheKey, collection);
|
|
40020
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
40021
|
+
};
|
|
40106
40022
|
}
|
|
40107
|
-
|
|
40108
|
-
|
|
40023
|
+
subscribeRTE(createSubscriber) {
|
|
40024
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
40109
40025
|
}
|
|
40110
|
-
|
|
40111
|
-
};
|
|
40112
|
-
/* end_public_function */
|
|
40113
|
-
|
|
40114
|
-
/* begin_public_function
|
|
40115
|
-
id: comment.soft_delete
|
|
40116
|
-
*/
|
|
40117
|
-
/**
|
|
40118
|
-
* ```js
|
|
40119
|
-
* import { CommentRepository } from '@amityco/ts-sdk'
|
|
40120
|
-
* const success = await CommentRepository.softDeleteComment('foobar')
|
|
40121
|
-
* ```
|
|
40122
|
-
*
|
|
40123
|
-
* Deletes a {@link Amity.Comment}
|
|
40124
|
-
*
|
|
40125
|
-
* @param commentId The {@link Amity.Comment} ID to delete
|
|
40126
|
-
* @return A success boolean if the {@link Amity.Comment} was deleted
|
|
40127
|
-
*
|
|
40128
|
-
* @category Comment API
|
|
40129
|
-
* @async
|
|
40130
|
-
*/
|
|
40131
|
-
const softDeleteComment = async (commentId) => {
|
|
40132
|
-
const client = getActiveClient();
|
|
40133
|
-
client.log('comment/softDeleteComment', commentId);
|
|
40134
|
-
const softDeleted = deleteComment(commentId);
|
|
40135
|
-
return softDeleted;
|
|
40136
|
-
};
|
|
40137
|
-
/* end_public_function */
|
|
40026
|
+
}
|
|
40138
40027
|
|
|
40139
|
-
/* begin_public_function
|
|
40140
|
-
id: comment.hard_delete
|
|
40141
|
-
*/
|
|
40142
40028
|
/**
|
|
40143
40029
|
* ```js
|
|
40144
|
-
* import {
|
|
40145
|
-
* const
|
|
40030
|
+
* import { onCommentCreated } from '@amityco/ts-sdk'
|
|
40031
|
+
* const dispose = onCommentCreated(comment => {
|
|
40032
|
+
* // ...
|
|
40033
|
+
* })
|
|
40146
40034
|
* ```
|
|
40147
40035
|
*
|
|
40148
|
-
*
|
|
40036
|
+
* Fired when a {@link Amity.InternalComment} has been created
|
|
40149
40037
|
*
|
|
40150
|
-
* @param
|
|
40151
|
-
* @
|
|
40038
|
+
* @param callback The function to call when the event was fired
|
|
40039
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40152
40040
|
*
|
|
40153
|
-
* @category Comment
|
|
40154
|
-
* @async
|
|
40041
|
+
* @category Comment Events
|
|
40155
40042
|
*/
|
|
40156
|
-
const
|
|
40157
|
-
|
|
40158
|
-
client.log('comment/hardDeleteComment', commentId);
|
|
40159
|
-
const hardDeleted = deleteComment(commentId, true);
|
|
40160
|
-
return hardDeleted;
|
|
40043
|
+
const onCommentCreatedLocal = (callback) => {
|
|
40044
|
+
return createLocalCommentEventSubscriber('local.comment.created', callback);
|
|
40161
40045
|
};
|
|
40162
|
-
/* end_public_function */
|
|
40163
40046
|
|
|
40164
|
-
|
|
40165
|
-
|
|
40166
|
-
|
|
40167
|
-
|
|
40168
|
-
|
|
40169
|
-
|
|
40170
|
-
|
|
40171
|
-
|
|
40172
|
-
|
|
40173
|
-
|
|
40174
|
-
* @param reason the reason to flag the comment
|
|
40175
|
-
* @returns the created report result
|
|
40176
|
-
*
|
|
40177
|
-
* @category Comment API
|
|
40178
|
-
* @async
|
|
40179
|
-
* */
|
|
40180
|
-
const flagComment = async (commentId, reason) => {
|
|
40181
|
-
const client = getActiveClient();
|
|
40182
|
-
client.log('comment/flagComment', commentId);
|
|
40183
|
-
const isPredefinedReason = reason &&
|
|
40184
|
-
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
40185
|
-
const body = {
|
|
40186
|
-
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
40187
|
-
detail: reason && !isPredefinedReason ? reason : '',
|
|
40188
|
-
};
|
|
40189
|
-
const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
|
|
40190
|
-
if (client.cache) {
|
|
40191
|
-
ingestInCache(payload);
|
|
40047
|
+
class CommentLiveCollectionController extends LiveCollectionController {
|
|
40048
|
+
constructor(query, callback) {
|
|
40049
|
+
const queryStreamId = hash(query);
|
|
40050
|
+
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
40051
|
+
const paginationController = new CommentPaginationController(query);
|
|
40052
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40053
|
+
this.query = query;
|
|
40054
|
+
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
40055
|
+
this.callback = callback.bind(this);
|
|
40056
|
+
this.loadPage({ initial: true });
|
|
40192
40057
|
}
|
|
40193
|
-
|
|
40194
|
-
|
|
40195
|
-
|
|
40196
|
-
|
|
40058
|
+
setup() {
|
|
40059
|
+
var _a;
|
|
40060
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40061
|
+
if (!collection) {
|
|
40062
|
+
pushToCache(this.cacheKey, {
|
|
40063
|
+
data: [],
|
|
40064
|
+
params: {},
|
|
40065
|
+
});
|
|
40066
|
+
}
|
|
40067
|
+
}
|
|
40068
|
+
async persistModel(queryPayload) {
|
|
40069
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
40070
|
+
}
|
|
40071
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
40072
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
40073
|
+
}
|
|
40074
|
+
startSubscription() {
|
|
40075
|
+
return this.queryStreamController.subscribeRTE([
|
|
40076
|
+
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
40077
|
+
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
40078
|
+
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
40079
|
+
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
40080
|
+
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
40081
|
+
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
40082
|
+
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
40083
|
+
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40084
|
+
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40085
|
+
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40086
|
+
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40087
|
+
]);
|
|
40088
|
+
}
|
|
40089
|
+
notifyChange({ origin, loading, error }) {
|
|
40090
|
+
var _a, _b;
|
|
40091
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40092
|
+
if (!collection)
|
|
40093
|
+
return;
|
|
40094
|
+
const data = this.applyFilter((_b = collection.data
|
|
40095
|
+
.map(id => pullFromCache(['comment', 'get', id]))
|
|
40096
|
+
.filter(isNonNullable)
|
|
40097
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
40098
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
40099
|
+
return;
|
|
40100
|
+
this.callback({
|
|
40101
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
40102
|
+
data,
|
|
40103
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
40104
|
+
loading,
|
|
40105
|
+
error,
|
|
40106
|
+
});
|
|
40107
|
+
}
|
|
40108
|
+
applyFilter(data) {
|
|
40109
|
+
let comments = data;
|
|
40110
|
+
if (!this.query.includeDeleted) {
|
|
40111
|
+
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
40112
|
+
}
|
|
40113
|
+
if (this.query.parentId) {
|
|
40114
|
+
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
40115
|
+
}
|
|
40116
|
+
if (typeof this.query.hasFlag === 'boolean') {
|
|
40117
|
+
if (this.query.hasFlag) {
|
|
40118
|
+
comments = comments.filter(comment => comment.hashFlag != null);
|
|
40119
|
+
}
|
|
40120
|
+
else {
|
|
40121
|
+
comments = comments.filter(comment => comment.hashFlag == null);
|
|
40122
|
+
}
|
|
40123
|
+
}
|
|
40124
|
+
if (this.query.dataTypes) {
|
|
40125
|
+
if (this.query.dataTypes.matchType === 'exact') {
|
|
40126
|
+
comments = comments.filter(comment => {
|
|
40127
|
+
var _a, _b;
|
|
40128
|
+
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
40129
|
+
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
40130
|
+
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
40131
|
+
return false;
|
|
40132
|
+
}
|
|
40133
|
+
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
40134
|
+
});
|
|
40135
|
+
}
|
|
40136
|
+
if (this.query.dataTypes.matchType === 'any') {
|
|
40137
|
+
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); }); });
|
|
40138
|
+
}
|
|
40139
|
+
}
|
|
40140
|
+
switch (this.query.sortBy) {
|
|
40141
|
+
case 'firstCreated':
|
|
40142
|
+
comments = comments.sort(sortByFirstCreated);
|
|
40143
|
+
break;
|
|
40144
|
+
case 'lastCreated':
|
|
40145
|
+
default:
|
|
40146
|
+
comments = comments.sort(sortByLastCreated);
|
|
40147
|
+
break;
|
|
40148
|
+
}
|
|
40149
|
+
return comments;
|
|
40150
|
+
}
|
|
40151
|
+
}
|
|
40197
40152
|
|
|
40198
40153
|
/* begin_public_function
|
|
40199
|
-
id: comment.
|
|
40154
|
+
id: comment.query
|
|
40200
40155
|
*/
|
|
40201
40156
|
/**
|
|
40202
40157
|
* ```js
|
|
40203
|
-
* import {
|
|
40204
|
-
*
|
|
40158
|
+
* import { getComments } from '@amityco/ts-sdk'
|
|
40159
|
+
*
|
|
40160
|
+
* let comments = []
|
|
40161
|
+
* const unsub = getComments({
|
|
40162
|
+
* referenceType: Amity.InternalComment['referenceType'];
|
|
40163
|
+
* referenceId: Amity.InternalComment['referenceId'];
|
|
40164
|
+
* }, response => merge(comments, response.data))
|
|
40205
40165
|
* ```
|
|
40206
40166
|
*
|
|
40207
|
-
*
|
|
40208
|
-
* @returns the unflagged result
|
|
40167
|
+
* Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
|
|
40209
40168
|
*
|
|
40210
|
-
* @
|
|
40211
|
-
* @
|
|
40212
|
-
*
|
|
40213
|
-
|
|
40214
|
-
|
|
40215
|
-
|
|
40216
|
-
|
|
40217
|
-
|
|
40218
|
-
|
|
40169
|
+
* @param referenceType the type of the target
|
|
40170
|
+
* @param referenceId the ID of the target
|
|
40171
|
+
* @param callback the function to call when new data are available
|
|
40172
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40173
|
+
*
|
|
40174
|
+
* @category Comments Live Collection
|
|
40175
|
+
*/
|
|
40176
|
+
const getComments = (params, callback, config) => {
|
|
40177
|
+
const { log, cache } = getActiveClient();
|
|
40178
|
+
if (!cache) {
|
|
40179
|
+
console.log('For using Live Collection feature you need to enable Cache!');
|
|
40219
40180
|
}
|
|
40220
|
-
|
|
40221
|
-
|
|
40181
|
+
const timestamp = Date.now();
|
|
40182
|
+
log(`getComments(tmpid: ${timestamp}) > listen`);
|
|
40183
|
+
const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
|
|
40184
|
+
const disposers = commentsLiveCollection.startSubscription();
|
|
40185
|
+
const cacheKey = commentsLiveCollection.getCacheKey();
|
|
40186
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40187
|
+
return () => {
|
|
40188
|
+
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
40189
|
+
disposers.forEach(fn => fn());
|
|
40190
|
+
};
|
|
40222
40191
|
};
|
|
40223
40192
|
/* end_public_function */
|
|
40224
40193
|
|
|
40225
|
-
|
|
40226
|
-
|
|
40227
|
-
|
|
40228
|
-
|
|
40229
|
-
|
|
40230
|
-
|
|
40231
|
-
|
|
40232
|
-
|
|
40233
|
-
|
|
40234
|
-
|
|
40235
|
-
|
|
40236
|
-
|
|
40237
|
-
|
|
40238
|
-
|
|
40239
|
-
|
|
40240
|
-
|
|
40241
|
-
|
|
40242
|
-
|
|
40243
|
-
|
|
40244
|
-
|
|
40245
|
-
};
|
|
40246
|
-
/* end_public_function */
|
|
40194
|
+
var index$a = /*#__PURE__*/Object.freeze({
|
|
40195
|
+
__proto__: null,
|
|
40196
|
+
getCommentByIds: getCommentByIds,
|
|
40197
|
+
createComment: createComment,
|
|
40198
|
+
updateComment: updateComment,
|
|
40199
|
+
deleteComment: deleteComment,
|
|
40200
|
+
softDeleteComment: softDeleteComment,
|
|
40201
|
+
hardDeleteComment: hardDeleteComment,
|
|
40202
|
+
flagComment: flagComment,
|
|
40203
|
+
unflagComment: unflagComment,
|
|
40204
|
+
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
40205
|
+
onCommentCreated: onCommentCreated,
|
|
40206
|
+
onCommentUpdated: onCommentUpdated,
|
|
40207
|
+
onCommentDeleted: onCommentDeleted,
|
|
40208
|
+
onCommentFlagged: onCommentFlagged,
|
|
40209
|
+
onCommentUnflagged: onCommentUnflagged,
|
|
40210
|
+
onCommentReactionAdded: onCommentReactionAdded,
|
|
40211
|
+
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
40212
|
+
getComment: getComment,
|
|
40213
|
+
getComments: getComments
|
|
40214
|
+
});
|
|
40247
40215
|
|
|
40248
|
-
const
|
|
40216
|
+
const getPost$1 = async (postId) => {
|
|
40249
40217
|
const client = getActiveClient();
|
|
40250
|
-
client.log('
|
|
40251
|
-
isInTombstone('
|
|
40252
|
-
let
|
|
40218
|
+
client.log('post/getPost', postId);
|
|
40219
|
+
isInTombstone('post', postId);
|
|
40220
|
+
let payload;
|
|
40253
40221
|
try {
|
|
40254
40222
|
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40255
|
-
const response = await client.http.get(`/api/v3/
|
|
40256
|
-
|
|
40223
|
+
const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
|
|
40224
|
+
payload = response.data;
|
|
40257
40225
|
}
|
|
40258
40226
|
catch (error) {
|
|
40259
40227
|
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40260
|
-
pushToTombstone('
|
|
40228
|
+
pushToTombstone('post', postId);
|
|
40261
40229
|
}
|
|
40262
40230
|
throw error;
|
|
40263
40231
|
}
|
|
40232
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40264
40233
|
const cachedAt = client.cache && Date.now();
|
|
40265
40234
|
if (client.cache)
|
|
40266
40235
|
ingestInCache(data, { cachedAt });
|
|
40267
|
-
const {
|
|
40236
|
+
const { posts } = data;
|
|
40237
|
+
const result = posts.find(post => post.postId === postId);
|
|
40268
40238
|
return {
|
|
40269
|
-
data:
|
|
40239
|
+
data: result,
|
|
40270
40240
|
cachedAt,
|
|
40271
40241
|
};
|
|
40272
40242
|
};
|
|
40273
|
-
|
|
40243
|
+
getPost$1.locally = (postId) => {
|
|
40274
40244
|
const client = getActiveClient();
|
|
40275
|
-
client.log('
|
|
40245
|
+
client.log('post/getPost.locally', postId);
|
|
40276
40246
|
if (!client.cache)
|
|
40277
40247
|
return;
|
|
40278
|
-
const cached = pullFromCache(['
|
|
40248
|
+
const cached = pullFromCache(['post', 'get', postId]);
|
|
40279
40249
|
if (!cached)
|
|
40280
40250
|
return;
|
|
40281
40251
|
return {
|
|
@@ -40286,142 +40256,245 @@ getComment$1.locally = (commentId) => {
|
|
|
40286
40256
|
|
|
40287
40257
|
/**
|
|
40288
40258
|
* ```js
|
|
40289
|
-
* import {
|
|
40290
|
-
* const dispose =
|
|
40259
|
+
* import { onLocalPostDeleted } from '@amityco/ts-sdk'
|
|
40260
|
+
* const dispose = onLocalPostDeleted(post => {
|
|
40291
40261
|
* // ...
|
|
40292
40262
|
* })
|
|
40293
40263
|
* ```
|
|
40294
40264
|
*
|
|
40295
|
-
* Fired when a {@link Amity.
|
|
40265
|
+
* Fired when a {@link Amity.InternalPost} has been deleted
|
|
40296
40266
|
*
|
|
40297
40267
|
* @param callback The function to call when the event was fired
|
|
40298
40268
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40299
40269
|
*
|
|
40300
|
-
* @category
|
|
40270
|
+
* @category Post Events
|
|
40301
40271
|
*/
|
|
40302
|
-
const
|
|
40272
|
+
const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
|
|
40303
40273
|
|
|
40304
40274
|
/**
|
|
40305
40275
|
* ```js
|
|
40306
|
-
* import {
|
|
40307
|
-
* const dispose =
|
|
40276
|
+
* import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
|
|
40277
|
+
* const dispose = onPostReactionAdded(post => {
|
|
40308
40278
|
* // ...
|
|
40309
40279
|
* })
|
|
40310
40280
|
* ```
|
|
40311
40281
|
*
|
|
40312
|
-
* Fired when a {@link Amity.
|
|
40282
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40313
40283
|
*
|
|
40314
40284
|
* @param callback The function to call when the event was fired
|
|
40315
40285
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40316
40286
|
*
|
|
40317
|
-
* @category
|
|
40287
|
+
* @category Post Events
|
|
40318
40288
|
*/
|
|
40319
|
-
const
|
|
40289
|
+
const onLocalPostReactionAdded = (callback) => {
|
|
40320
40290
|
const client = getActiveClient();
|
|
40321
|
-
const filter = ({
|
|
40291
|
+
const filter = ({ post }) => {
|
|
40322
40292
|
if (!client.cache) {
|
|
40323
|
-
callback(
|
|
40293
|
+
callback(post);
|
|
40324
40294
|
}
|
|
40325
40295
|
else {
|
|
40326
|
-
upsertInCache(['
|
|
40327
|
-
callback(
|
|
40296
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40297
|
+
callback(post);
|
|
40328
40298
|
}
|
|
40329
40299
|
};
|
|
40330
|
-
return createEventSubscriber(client, 'local.
|
|
40300
|
+
return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
|
|
40331
40301
|
};
|
|
40332
40302
|
|
|
40333
40303
|
/**
|
|
40334
40304
|
* ```js
|
|
40335
|
-
* import {
|
|
40336
|
-
* const dispose =
|
|
40305
|
+
* import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
|
|
40306
|
+
* const dispose = onPostReactionRemoved(post => {
|
|
40337
40307
|
* // ...
|
|
40338
40308
|
* })
|
|
40339
40309
|
* ```
|
|
40340
40310
|
*
|
|
40341
|
-
* Fired when a {@link Amity.
|
|
40311
|
+
* Fired when a {@link Amity.InternalPost} has been reacted
|
|
40342
40312
|
*
|
|
40343
40313
|
* @param callback The function to call when the event was fired
|
|
40344
40314
|
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40345
40315
|
*
|
|
40346
|
-
* @category
|
|
40316
|
+
* @category Post Events
|
|
40347
40317
|
*/
|
|
40348
|
-
const
|
|
40318
|
+
const onLocalPostReactionRemoved = (callback) => {
|
|
40349
40319
|
const client = getActiveClient();
|
|
40350
|
-
const filter = ({
|
|
40320
|
+
const filter = ({ post }) => {
|
|
40351
40321
|
if (!client.cache) {
|
|
40352
|
-
callback(
|
|
40322
|
+
callback(post);
|
|
40353
40323
|
}
|
|
40354
40324
|
else {
|
|
40355
|
-
upsertInCache(['
|
|
40356
|
-
callback(
|
|
40325
|
+
upsertInCache(['post', 'get', post.postId], post);
|
|
40326
|
+
callback(post);
|
|
40357
40327
|
}
|
|
40358
40328
|
};
|
|
40359
|
-
return createEventSubscriber(client, 'local.
|
|
40329
|
+
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
40360
40330
|
};
|
|
40361
40331
|
|
|
40362
|
-
/* begin_public_function
|
|
40363
|
-
id: comment.get
|
|
40364
|
-
*/
|
|
40365
40332
|
/**
|
|
40366
40333
|
* ```js
|
|
40367
|
-
* import {
|
|
40368
|
-
*
|
|
40369
|
-
*
|
|
40370
|
-
*
|
|
40371
|
-
* const unsub = CommentRepository.getComment(commentId, response => {
|
|
40372
|
-
* comment = response.data;
|
|
40373
|
-
* });
|
|
40334
|
+
* import { onPostUpdatedLocal } from '@amityco/ts-sdk'
|
|
40335
|
+
* const dispose = onPostUpdatedLocal(post => {
|
|
40336
|
+
* // ...
|
|
40337
|
+
* })
|
|
40374
40338
|
* ```
|
|
40375
40339
|
*
|
|
40376
|
-
*
|
|
40340
|
+
* Fired when a {@link Amity.InternalPost} has been updated
|
|
40377
40341
|
*
|
|
40378
|
-
* @param
|
|
40379
|
-
* @
|
|
40380
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
|
|
40342
|
+
* @param callback The function to call when the event was fired
|
|
40343
|
+
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
40381
40344
|
*
|
|
40382
|
-
* @category
|
|
40345
|
+
* @category Post Events
|
|
40383
40346
|
*/
|
|
40384
|
-
const
|
|
40385
|
-
|
|
40386
|
-
|
|
40347
|
+
const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
|
|
40348
|
+
|
|
40349
|
+
const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
|
|
40350
|
+
return eventHandler(async (comment) => {
|
|
40351
|
+
var _a;
|
|
40352
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40353
|
+
if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
|
|
40354
|
+
return;
|
|
40355
|
+
await getPost$1(comment.referenceId);
|
|
40356
|
+
callback(comment);
|
|
40357
|
+
});
|
|
40358
|
+
};
|
|
40359
|
+
const generateCommentSubscriptions$1 = (cacheKey) => {
|
|
40360
|
+
const eventHandlers = [
|
|
40361
|
+
onCommentCreated,
|
|
40387
40362
|
onCommentDeleted,
|
|
40388
|
-
onCommentFlagged,
|
|
40389
40363
|
onCommentReactionAdded,
|
|
40390
40364
|
onCommentReactionRemoved,
|
|
40391
|
-
|
|
40392
|
-
|
|
40365
|
+
onCommentCreatedLocal,
|
|
40366
|
+
onCommentDeleteLocal,
|
|
40393
40367
|
onLocalCommentReactionAdded,
|
|
40394
40368
|
onLocalCommentReactionRemoved,
|
|
40395
|
-
]
|
|
40369
|
+
];
|
|
40370
|
+
return eventHandlers.map(handler => ({
|
|
40371
|
+
fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
|
|
40372
|
+
action: EnumPostActions.OnPostUpdated,
|
|
40373
|
+
}));
|
|
40374
|
+
};
|
|
40375
|
+
const getGlobalFeedSubscriptions = (cacheKey) => {
|
|
40376
|
+
return [
|
|
40377
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
40378
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
40379
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
40380
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
40381
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
40382
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
40383
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
40384
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
40385
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
40386
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
40387
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
40388
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
40389
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
40390
|
+
...generateCommentSubscriptions$1(cacheKey),
|
|
40391
|
+
];
|
|
40392
|
+
};
|
|
40393
|
+
|
|
40394
|
+
class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
|
|
40395
|
+
constructor(query, callback) {
|
|
40396
|
+
const queryStreamId = hash(query);
|
|
40397
|
+
const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
|
|
40398
|
+
const paginationController = new CustomRankingGlobalFeedPaginationController(query);
|
|
40399
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40400
|
+
this.query = query;
|
|
40401
|
+
this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
40402
|
+
this.callback = callback.bind(this);
|
|
40403
|
+
this.loadPage({ initial: true });
|
|
40404
|
+
}
|
|
40405
|
+
setup() {
|
|
40406
|
+
var _a;
|
|
40407
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40408
|
+
if (!collection) {
|
|
40409
|
+
pushToCache(this.cacheKey, {
|
|
40410
|
+
data: [],
|
|
40411
|
+
params: {},
|
|
40412
|
+
});
|
|
40413
|
+
}
|
|
40414
|
+
}
|
|
40415
|
+
async persistModel(queryPayload) {
|
|
40416
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
40417
|
+
}
|
|
40418
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
40419
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
40420
|
+
}
|
|
40421
|
+
startSubscription() {
|
|
40422
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
40423
|
+
}
|
|
40424
|
+
notifyChange({ origin, loading, error }) {
|
|
40425
|
+
var _a, _b;
|
|
40426
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40427
|
+
if (!collection)
|
|
40428
|
+
return;
|
|
40429
|
+
const data = ((_b = collection.data
|
|
40430
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
40431
|
+
.filter(isNonNullable)
|
|
40432
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
40433
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
40434
|
+
return;
|
|
40435
|
+
this.callback({
|
|
40436
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
40437
|
+
data,
|
|
40438
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
40439
|
+
loading,
|
|
40440
|
+
error,
|
|
40441
|
+
});
|
|
40442
|
+
}
|
|
40443
|
+
}
|
|
40444
|
+
|
|
40445
|
+
/* begin_public_function
|
|
40446
|
+
id: feed.query.custom_ranking_feed
|
|
40447
|
+
*/
|
|
40448
|
+
/**
|
|
40449
|
+
* ```js
|
|
40450
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
40451
|
+
*
|
|
40452
|
+
* let posts = []
|
|
40453
|
+
* const unsub = FeedRepository.getGlobalFeed({
|
|
40454
|
+
* dataTypes: ['video','image'],
|
|
40455
|
+
* resolveParent: true,
|
|
40456
|
+
* }, response => processResponse(response))
|
|
40457
|
+
* ```
|
|
40458
|
+
*
|
|
40459
|
+
* Observe all mutations on a list of {@link Amity.Post} for a given target object
|
|
40460
|
+
*
|
|
40461
|
+
* @param params.dataTypes array of data types for the posts
|
|
40462
|
+
* @param callback the function to call when new data are available
|
|
40463
|
+
* @param config
|
|
40464
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40465
|
+
*
|
|
40466
|
+
* @category Posts Live Collection
|
|
40467
|
+
*/
|
|
40468
|
+
const getCustomRankingGlobalFeed = (params, callback, config) => {
|
|
40469
|
+
const { log, cache } = getActiveClient();
|
|
40470
|
+
if (!cache) {
|
|
40471
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
40472
|
+
}
|
|
40473
|
+
const timestamp = Date.now();
|
|
40474
|
+
log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
|
|
40475
|
+
const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
|
|
40476
|
+
const disposers = liveCollection.startSubscription();
|
|
40477
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
40478
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40479
|
+
return () => {
|
|
40480
|
+
log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
|
|
40481
|
+
disposers.forEach(fn => fn());
|
|
40482
|
+
};
|
|
40396
40483
|
};
|
|
40397
40484
|
/* end_public_function */
|
|
40398
40485
|
|
|
40399
|
-
class
|
|
40486
|
+
class GlobalFeedPaginationController extends PaginationController {
|
|
40400
40487
|
async getRequest(queryParams, token) {
|
|
40401
|
-
const { limit
|
|
40402
|
-
const
|
|
40403
|
-
|
|
40404
|
-
|
|
40405
|
-
const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
|
|
40406
|
-
const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
|
|
40407
|
-
params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
|
|
40488
|
+
const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
|
|
40489
|
+
const options = token ? { token } : { limit };
|
|
40490
|
+
const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
|
|
40491
|
+
params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
|
|
40408
40492
|
});
|
|
40409
40493
|
return queryResponse;
|
|
40410
40494
|
}
|
|
40411
40495
|
}
|
|
40412
40496
|
|
|
40413
|
-
|
|
40414
|
-
(function (EnumCommentActions) {
|
|
40415
|
-
EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
|
|
40416
|
-
EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
|
|
40417
|
-
EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
|
|
40418
|
-
EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
|
|
40419
|
-
EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
|
|
40420
|
-
EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
|
|
40421
|
-
EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
|
|
40422
|
-
})(EnumCommentActions || (EnumCommentActions = {}));
|
|
40423
|
-
|
|
40424
|
-
class CommentQueryStreamController extends QueryStreamController {
|
|
40497
|
+
class GlobalFeedQueryStreamController extends QueryStreamController {
|
|
40425
40498
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
40426
40499
|
super(query, cacheKey);
|
|
40427
40500
|
this.notifyChange = notifyChange;
|
|
@@ -40439,32 +40512,38 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
40439
40512
|
var _a, _b;
|
|
40440
40513
|
if (refresh) {
|
|
40441
40514
|
pushToCache(this.cacheKey, {
|
|
40442
|
-
data: response.
|
|
40515
|
+
data: response.posts.map(getResolver('post')),
|
|
40443
40516
|
});
|
|
40444
40517
|
}
|
|
40445
40518
|
else {
|
|
40446
40519
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40447
|
-
const
|
|
40448
|
-
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...
|
|
40520
|
+
const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
|
|
40521
|
+
pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
|
|
40449
40522
|
}
|
|
40450
40523
|
}
|
|
40451
40524
|
reactor(action) {
|
|
40452
|
-
return (
|
|
40525
|
+
return (post) => {
|
|
40453
40526
|
var _a;
|
|
40454
40527
|
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40455
|
-
if (
|
|
40456
|
-
this.query.referenceType !== comment.referenceType ||
|
|
40457
|
-
!collection) {
|
|
40528
|
+
if (!collection)
|
|
40458
40529
|
return;
|
|
40459
|
-
|
|
40460
|
-
if (this.query.parentId && this.query.parentId !== comment.parentId) {
|
|
40530
|
+
if (post.parentPostId && !collection.data.includes(post.parentPostId))
|
|
40461
40531
|
return;
|
|
40532
|
+
// Delete Action
|
|
40533
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
40534
|
+
// Parent Post - Remove from collection
|
|
40535
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
40462
40536
|
}
|
|
40463
|
-
if (
|
|
40464
|
-
|
|
40537
|
+
if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
|
|
40538
|
+
// If the query has dataTypes array with value, check if post.dataType is include in the array
|
|
40539
|
+
if (this.query.dataTypes && this.query.dataTypes.length > 0) {
|
|
40540
|
+
if (!this.query.dataTypes.includes(post.dataType))
|
|
40541
|
+
return;
|
|
40542
|
+
}
|
|
40543
|
+
collection.data = [...new Set([post.postId, ...collection.data])];
|
|
40465
40544
|
}
|
|
40466
|
-
if (action ===
|
|
40467
|
-
collection.data =
|
|
40545
|
+
if (action === EnumPostActions.OnPostDeclined) {
|
|
40546
|
+
collection.data = collection.data.filter(postId => postId !== post.postId);
|
|
40468
40547
|
}
|
|
40469
40548
|
pushToCache(this.cacheKey, collection);
|
|
40470
40549
|
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
@@ -40475,285 +40554,589 @@ class CommentQueryStreamController extends QueryStreamController {
|
|
|
40475
40554
|
}
|
|
40476
40555
|
}
|
|
40477
40556
|
|
|
40557
|
+
class GlobalFeedLiveCollectionController extends LiveCollectionController {
|
|
40558
|
+
constructor(query, callback) {
|
|
40559
|
+
const queryStreamId = hash(query);
|
|
40560
|
+
const cacheKey = ['globalFeed', 'collection', queryStreamId];
|
|
40561
|
+
const paginationController = new GlobalFeedPaginationController(query);
|
|
40562
|
+
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40563
|
+
this.query = query;
|
|
40564
|
+
this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
|
|
40565
|
+
this.callback = callback.bind(this);
|
|
40566
|
+
this.loadPage({ initial: true });
|
|
40567
|
+
}
|
|
40568
|
+
setup() {
|
|
40569
|
+
var _a;
|
|
40570
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40571
|
+
if (!collection) {
|
|
40572
|
+
pushToCache(this.cacheKey, {
|
|
40573
|
+
data: [],
|
|
40574
|
+
params: {},
|
|
40575
|
+
});
|
|
40576
|
+
}
|
|
40577
|
+
}
|
|
40578
|
+
async persistModel(queryPayload) {
|
|
40579
|
+
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
40580
|
+
}
|
|
40581
|
+
persistQueryStream({ response, direction, refresh, }) {
|
|
40582
|
+
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
40583
|
+
}
|
|
40584
|
+
startSubscription() {
|
|
40585
|
+
return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
|
|
40586
|
+
}
|
|
40587
|
+
notifyChange({ origin, loading, error }) {
|
|
40588
|
+
var _a, _b;
|
|
40589
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40590
|
+
if (!collection)
|
|
40591
|
+
return;
|
|
40592
|
+
const data = ((_b = collection.data
|
|
40593
|
+
.map(id => pullFromCache(['post', 'get', id]))
|
|
40594
|
+
.filter(isNonNullable)
|
|
40595
|
+
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
|
|
40596
|
+
if (!this.shouldNotify(data) && origin === 'event')
|
|
40597
|
+
return;
|
|
40598
|
+
this.callback({
|
|
40599
|
+
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
40600
|
+
data,
|
|
40601
|
+
hasNextPage: !!this.paginationController.getNextToken(),
|
|
40602
|
+
loading,
|
|
40603
|
+
error,
|
|
40604
|
+
});
|
|
40605
|
+
}
|
|
40606
|
+
}
|
|
40607
|
+
|
|
40608
|
+
/* begin_public_function
|
|
40609
|
+
id: feed.query.global_feed
|
|
40610
|
+
*/
|
|
40611
|
+
/**
|
|
40612
|
+
* ```js
|
|
40613
|
+
* import { FeedRepository } from '@amityco/ts-sdk'
|
|
40614
|
+
*
|
|
40615
|
+
* let posts = []
|
|
40616
|
+
* const unsub = FeedRepository.getGlobalFeed({
|
|
40617
|
+
* dataTypes: ['video','image'],
|
|
40618
|
+
* resolveParent: true,
|
|
40619
|
+
* }, response => processResponse(response))
|
|
40620
|
+
* ```
|
|
40621
|
+
*
|
|
40622
|
+
* Observe all mutations on a list of {@link Amity.Post} for global feed
|
|
40623
|
+
* @param params.dataTypes array of data types for the posts
|
|
40624
|
+
* @param params.resolveParent
|
|
40625
|
+
* @param callback the function to call when new data are available
|
|
40626
|
+
* @param config
|
|
40627
|
+
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40628
|
+
*
|
|
40629
|
+
* @category Posts Live Collection
|
|
40630
|
+
*/
|
|
40631
|
+
const getGlobalFeed = (params, callback, config) => {
|
|
40632
|
+
const { log, cache } = getActiveClient();
|
|
40633
|
+
if (!cache) {
|
|
40634
|
+
console.log(ENABLE_CACHE_MESSAGE);
|
|
40635
|
+
}
|
|
40636
|
+
const timestamp = Date.now();
|
|
40637
|
+
log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
|
|
40638
|
+
const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
|
|
40639
|
+
const disposers = liveCollection.startSubscription();
|
|
40640
|
+
const cacheKey = liveCollection.getCacheKey();
|
|
40641
|
+
disposers.push(() => dropFromCache(cacheKey));
|
|
40642
|
+
return () => {
|
|
40643
|
+
log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
|
|
40644
|
+
disposers.forEach(fn => fn());
|
|
40645
|
+
};
|
|
40646
|
+
};
|
|
40647
|
+
/* end_public_function */
|
|
40648
|
+
|
|
40649
|
+
var index$9 = /*#__PURE__*/Object.freeze({
|
|
40650
|
+
__proto__: null,
|
|
40651
|
+
queryGlobalFeed: queryGlobalFeed,
|
|
40652
|
+
getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
|
|
40653
|
+
getGlobalFeed: getGlobalFeed
|
|
40654
|
+
});
|
|
40655
|
+
|
|
40656
|
+
/* begin_public_function
|
|
40657
|
+
id: post.get_by_ids
|
|
40658
|
+
*/
|
|
40659
|
+
/**
|
|
40660
|
+
* ```js
|
|
40661
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
40662
|
+
* const { data: posts } = await getPostByIds(['foo', 'bar'])
|
|
40663
|
+
* ```
|
|
40664
|
+
*
|
|
40665
|
+
* Fetches a collection of {@link Amity.Post} objects
|
|
40666
|
+
*
|
|
40667
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
40668
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
40669
|
+
*
|
|
40670
|
+
* @category Post API
|
|
40671
|
+
* @async
|
|
40672
|
+
*/
|
|
40673
|
+
const getPostByIds = async (postIds) => {
|
|
40674
|
+
const client = getActiveClient();
|
|
40675
|
+
client.log('post/getPostByIds', postIds);
|
|
40676
|
+
const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
|
|
40677
|
+
let payload;
|
|
40678
|
+
try {
|
|
40679
|
+
// API-FIX: endpoint should not be /list, parameters should be querystring.
|
|
40680
|
+
const response = await client.http.get(`/api/v3/posts/list`, {
|
|
40681
|
+
params: { postIds: encodedPostIds },
|
|
40682
|
+
});
|
|
40683
|
+
payload = response.data;
|
|
40684
|
+
}
|
|
40685
|
+
catch (error) {
|
|
40686
|
+
postIds.forEach(postId => {
|
|
40687
|
+
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40688
|
+
pushToTombstone('post', postId);
|
|
40689
|
+
}
|
|
40690
|
+
});
|
|
40691
|
+
throw error;
|
|
40692
|
+
}
|
|
40693
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40694
|
+
const cachedAt = client.cache && Date.now();
|
|
40695
|
+
if (client.cache)
|
|
40696
|
+
ingestInCache(data, { cachedAt });
|
|
40697
|
+
return {
|
|
40698
|
+
data: data.posts.map(LinkedObject.post),
|
|
40699
|
+
cachedAt,
|
|
40700
|
+
};
|
|
40701
|
+
};
|
|
40702
|
+
/* end_public_function */
|
|
40703
|
+
/**
|
|
40704
|
+
* ```js
|
|
40705
|
+
* import { getPostByIds } from '@amityco/ts-sdk'
|
|
40706
|
+
* const { data: posts } = getPostByIds.locally(['foo', 'bar'])
|
|
40707
|
+
* ```
|
|
40708
|
+
*
|
|
40709
|
+
* Fetches a collection of {@link Amity.Post} objects from cache
|
|
40710
|
+
*
|
|
40711
|
+
* @param postIds the IDs of the {@link Amity.Post} to fetch
|
|
40712
|
+
* @returns the associated collection of {@link Amity.Post} objects
|
|
40713
|
+
*
|
|
40714
|
+
* @category Post API
|
|
40715
|
+
*/
|
|
40716
|
+
getPostByIds.locally = (postIds) => {
|
|
40717
|
+
var _a;
|
|
40718
|
+
const client = getActiveClient();
|
|
40719
|
+
client.log('post/getPostByIds.locally', postIds);
|
|
40720
|
+
if (!client.cache)
|
|
40721
|
+
return;
|
|
40722
|
+
const cached = postIds
|
|
40723
|
+
.map(postId => pullFromCache(['post', 'get', postId]))
|
|
40724
|
+
.filter(Boolean);
|
|
40725
|
+
const posts = cached.map(({ data }) => data);
|
|
40726
|
+
const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
|
|
40727
|
+
if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
|
|
40728
|
+
return;
|
|
40729
|
+
return {
|
|
40730
|
+
data: posts.map(LinkedObject.post),
|
|
40731
|
+
cachedAt: oldest.cachedAt,
|
|
40732
|
+
};
|
|
40733
|
+
};
|
|
40734
|
+
|
|
40735
|
+
/* begin_public_function
|
|
40736
|
+
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
|
|
40737
|
+
*/
|
|
40738
|
+
/**
|
|
40739
|
+
* ```js
|
|
40740
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40741
|
+
* const created = await PostRepository.createPost({
|
|
40742
|
+
* targetType: 'user',
|
|
40743
|
+
* targetId: 'foobar',
|
|
40744
|
+
* data: { text: 'hello world' }
|
|
40745
|
+
* }))
|
|
40746
|
+
* ```
|
|
40747
|
+
*
|
|
40748
|
+
* Creates an {@link Amity.Post}
|
|
40749
|
+
*
|
|
40750
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
40751
|
+
* @returns The newly created {@link Amity.Post}
|
|
40752
|
+
*
|
|
40753
|
+
* @category Post API
|
|
40754
|
+
* @async
|
|
40755
|
+
*/
|
|
40756
|
+
const createPost = async (bundle) => {
|
|
40757
|
+
const client = getActiveClient();
|
|
40758
|
+
client.log('post/createPost', bundle);
|
|
40759
|
+
if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
|
|
40760
|
+
// eslint-disable-next-line no-param-reassign
|
|
40761
|
+
delete bundle.dataType;
|
|
40762
|
+
}
|
|
40763
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
40764
|
+
fireEvent('post.created', payload);
|
|
40765
|
+
const data = preparePostPayload(payload);
|
|
40766
|
+
const cachedAt = client.cache && Date.now();
|
|
40767
|
+
if (client.cache)
|
|
40768
|
+
ingestInCache(data, { cachedAt });
|
|
40769
|
+
const { posts } = data;
|
|
40770
|
+
return {
|
|
40771
|
+
data: LinkedObject.post(posts[0]),
|
|
40772
|
+
cachedAt,
|
|
40773
|
+
};
|
|
40774
|
+
};
|
|
40775
|
+
/* end_public_function */
|
|
40776
|
+
|
|
40777
|
+
/* begin_public_function
|
|
40778
|
+
id: post.edit, post.edit.custom_post
|
|
40779
|
+
*/
|
|
40780
|
+
/**
|
|
40781
|
+
* ```js
|
|
40782
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40783
|
+
* const updated = await PostRepository.editPost(postId, {
|
|
40784
|
+
* data: { text: 'hello world' }
|
|
40785
|
+
* })
|
|
40786
|
+
* ```
|
|
40787
|
+
*
|
|
40788
|
+
* Updates an {@link Amity.Post}
|
|
40789
|
+
*
|
|
40790
|
+
* @param postId The ID of the {@link Amity.Post} to edit
|
|
40791
|
+
* @param patch The patch data to apply
|
|
40792
|
+
* @returns the updated {@link Amity.Post} object
|
|
40793
|
+
*
|
|
40794
|
+
* @category Post API
|
|
40795
|
+
* @async
|
|
40796
|
+
*/
|
|
40797
|
+
const editPost = async (postId, patch) => {
|
|
40798
|
+
const client = getActiveClient();
|
|
40799
|
+
client.log('user/editPost', patch);
|
|
40800
|
+
const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
|
|
40801
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40802
|
+
const cachedAt = client.cache && Date.now();
|
|
40803
|
+
if (client.cache)
|
|
40804
|
+
ingestInCache(data, { cachedAt });
|
|
40805
|
+
fireEvent('local.post.updated', data);
|
|
40806
|
+
const { posts } = data;
|
|
40807
|
+
return {
|
|
40808
|
+
data: LinkedObject.post(posts.find(post => post.postId === postId)),
|
|
40809
|
+
cachedAt,
|
|
40810
|
+
};
|
|
40811
|
+
};
|
|
40812
|
+
/* end_public_function */
|
|
40813
|
+
|
|
40814
|
+
/**
|
|
40815
|
+
* ```js
|
|
40816
|
+
* import { deletePost } from '@amityco/ts-sdk'
|
|
40817
|
+
* const success = await deletePost('foobar')
|
|
40818
|
+
* ```
|
|
40819
|
+
*
|
|
40820
|
+
* Deletes a {@link Amity.Post}
|
|
40821
|
+
*
|
|
40822
|
+
* @param postId The {@link Amity.Post} ID to delete
|
|
40823
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40824
|
+
*
|
|
40825
|
+
* @private
|
|
40826
|
+
* @async
|
|
40827
|
+
*/
|
|
40828
|
+
const deletePost = async (postId, permanent = false) => {
|
|
40829
|
+
var _a;
|
|
40830
|
+
const client = getActiveClient();
|
|
40831
|
+
const post = await getPost$2(postId);
|
|
40832
|
+
await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
|
|
40833
|
+
params: {
|
|
40834
|
+
postId,
|
|
40835
|
+
permanent,
|
|
40836
|
+
},
|
|
40837
|
+
});
|
|
40838
|
+
// there is currently a limitation which doesn't allow us to fire event to tell that community
|
|
40839
|
+
// has been updated. reason is that, when the object is deleted, we don't have its `communityId`
|
|
40840
|
+
// and so we cannot refetch the community or advertise on events. hopefully this should be solved
|
|
40841
|
+
// later when realtime events covers that for us.
|
|
40842
|
+
if (post.data.targetType === 'community') {
|
|
40843
|
+
const community = await getCommunity$1(post.data.targetId);
|
|
40844
|
+
const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
|
|
40845
|
+
const communityUsers = communityUsersCache
|
|
40846
|
+
.filter(({ key }) => {
|
|
40847
|
+
// cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
|
|
40848
|
+
if (key[0] !== 'communityUsers')
|
|
40849
|
+
return false;
|
|
40850
|
+
if (key[1] !== 'get')
|
|
40851
|
+
return false;
|
|
40852
|
+
if (typeof key[2] === 'string')
|
|
40853
|
+
return key[2].includes(community.data.communityId);
|
|
40854
|
+
return false;
|
|
40855
|
+
})
|
|
40856
|
+
.map(({ data }) => data);
|
|
40857
|
+
fireEvent('community.updated', {
|
|
40858
|
+
communities: [community.data],
|
|
40859
|
+
categories: [],
|
|
40860
|
+
communityUsers,
|
|
40861
|
+
feeds: [],
|
|
40862
|
+
files: [],
|
|
40863
|
+
users: [],
|
|
40864
|
+
});
|
|
40865
|
+
}
|
|
40866
|
+
// to support hard deletion
|
|
40867
|
+
const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
|
|
40868
|
+
if (permanent) {
|
|
40869
|
+
setTimeout(() => {
|
|
40870
|
+
pushToTombstone('post', postId);
|
|
40871
|
+
}, 0);
|
|
40872
|
+
}
|
|
40873
|
+
else {
|
|
40874
|
+
upsertInCache(['post', 'get', postId], { isDeleted: true });
|
|
40875
|
+
}
|
|
40876
|
+
fireEvent('local.post.deleted', {
|
|
40877
|
+
posts: [deleted],
|
|
40878
|
+
categories: [],
|
|
40879
|
+
comments: [],
|
|
40880
|
+
communities: [],
|
|
40881
|
+
communityUsers: [],
|
|
40882
|
+
feeds: [],
|
|
40883
|
+
files: [],
|
|
40884
|
+
postChildren: [],
|
|
40885
|
+
users: [],
|
|
40886
|
+
videoStreamings: [],
|
|
40887
|
+
});
|
|
40888
|
+
return LinkedObject.post(deleted);
|
|
40889
|
+
};
|
|
40890
|
+
|
|
40891
|
+
/* begin_public_function
|
|
40892
|
+
id: post.soft_delete
|
|
40893
|
+
*/
|
|
40894
|
+
/**
|
|
40895
|
+
* ```js
|
|
40896
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
40897
|
+
* const success = await PostRepository.softDeletePost('foobar')
|
|
40898
|
+
* ```
|
|
40899
|
+
*
|
|
40900
|
+
* Soft deletes a {@link Amity.Post}
|
|
40901
|
+
*
|
|
40902
|
+
* @param postId The {@link Amity.Post} ID to soft delete
|
|
40903
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40904
|
+
*
|
|
40905
|
+
* @category Post API
|
|
40906
|
+
* @async
|
|
40907
|
+
*/
|
|
40908
|
+
const softDeletePost = async (postId) => {
|
|
40909
|
+
const client = getActiveClient();
|
|
40910
|
+
client.log('post/softDeletePost', postId);
|
|
40911
|
+
const softDeleted = await deletePost(postId, false);
|
|
40912
|
+
return LinkedObject.post(softDeleted);
|
|
40913
|
+
};
|
|
40914
|
+
/* end_public_function */
|
|
40915
|
+
|
|
40916
|
+
/* begin_public_function
|
|
40917
|
+
id: post.hard_delete
|
|
40918
|
+
*/
|
|
40478
40919
|
/**
|
|
40479
40920
|
* ```js
|
|
40480
|
-
* import {
|
|
40481
|
-
* const
|
|
40482
|
-
* // ...
|
|
40483
|
-
* })
|
|
40921
|
+
* import { hardDeletePost } from '@amityco/ts-sdk'
|
|
40922
|
+
* const success = await hardDeletePost('foobar')
|
|
40484
40923
|
* ```
|
|
40485
40924
|
*
|
|
40486
|
-
*
|
|
40925
|
+
* Hard deletes a {@link Amity.Post}
|
|
40487
40926
|
*
|
|
40488
|
-
* @param
|
|
40489
|
-
* @
|
|
40927
|
+
* @param postId The {@link Amity.Post} ID to be hard delete
|
|
40928
|
+
* @return A success boolean if the {@link Amity.Post} was deleted
|
|
40490
40929
|
*
|
|
40491
|
-
* @category
|
|
40930
|
+
* @category Post API
|
|
40931
|
+
* @async
|
|
40492
40932
|
*/
|
|
40493
|
-
const
|
|
40494
|
-
|
|
40933
|
+
const hardDeletePost = async (postId) => {
|
|
40934
|
+
const client = getActiveClient();
|
|
40935
|
+
client.log('post/hardDeletePost', postId);
|
|
40936
|
+
const hardDeleted = await deletePost(postId, true);
|
|
40937
|
+
return LinkedObject.post(hardDeleted);
|
|
40495
40938
|
};
|
|
40496
|
-
|
|
40497
|
-
class CommentLiveCollectionController extends LiveCollectionController {
|
|
40498
|
-
constructor(query, callback) {
|
|
40499
|
-
const queryStreamId = hash(query);
|
|
40500
|
-
const cacheKey = ['comments', 'collection', queryStreamId];
|
|
40501
|
-
const paginationController = new CommentPaginationController(query);
|
|
40502
|
-
super(paginationController, queryStreamId, cacheKey, callback);
|
|
40503
|
-
this.query = query;
|
|
40504
|
-
this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
|
|
40505
|
-
this.callback = callback.bind(this);
|
|
40506
|
-
this.loadPage({ initial: true });
|
|
40507
|
-
}
|
|
40508
|
-
setup() {
|
|
40509
|
-
var _a;
|
|
40510
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40511
|
-
if (!collection) {
|
|
40512
|
-
pushToCache(this.cacheKey, {
|
|
40513
|
-
data: [],
|
|
40514
|
-
params: {},
|
|
40515
|
-
});
|
|
40516
|
-
}
|
|
40517
|
-
}
|
|
40518
|
-
async persistModel(queryPayload) {
|
|
40519
|
-
await this.queryStreamController.saveToMainDB(queryPayload);
|
|
40520
|
-
}
|
|
40521
|
-
persistQueryStream({ response, direction, refresh, }) {
|
|
40522
|
-
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
40523
|
-
}
|
|
40524
|
-
startSubscription() {
|
|
40525
|
-
return this.queryStreamController.subscribeRTE([
|
|
40526
|
-
{ fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
|
|
40527
|
-
{ fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
|
|
40528
|
-
{ fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
|
|
40529
|
-
{ fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
|
|
40530
|
-
{ fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
|
|
40531
|
-
{ fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
|
|
40532
|
-
{ fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
|
|
40533
|
-
{ fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40534
|
-
{ fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40535
|
-
{ fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
|
|
40536
|
-
{ fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
|
|
40537
|
-
]);
|
|
40538
|
-
}
|
|
40539
|
-
notifyChange({ origin, loading, error }) {
|
|
40540
|
-
var _a, _b;
|
|
40541
|
-
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
40542
|
-
if (!collection)
|
|
40543
|
-
return;
|
|
40544
|
-
const data = this.applyFilter((_b = collection.data
|
|
40545
|
-
.map(id => pullFromCache(['comment', 'get', id]))
|
|
40546
|
-
.filter(isNonNullable)
|
|
40547
|
-
.map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
|
|
40548
|
-
if (!this.shouldNotify(data) && origin === 'event')
|
|
40549
|
-
return;
|
|
40550
|
-
this.callback({
|
|
40551
|
-
onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
|
|
40552
|
-
data,
|
|
40553
|
-
hasNextPage: !!this.paginationController.getNextToken(),
|
|
40554
|
-
loading,
|
|
40555
|
-
error,
|
|
40556
|
-
});
|
|
40557
|
-
}
|
|
40558
|
-
applyFilter(data) {
|
|
40559
|
-
let comments = data;
|
|
40560
|
-
if (!this.query.includeDeleted) {
|
|
40561
|
-
comments = filterByPropEquality(comments, 'isDeleted', false);
|
|
40562
|
-
}
|
|
40563
|
-
if (this.query.parentId) {
|
|
40564
|
-
comments = comments.filter(comment => comment.parentId === this.query.parentId);
|
|
40565
|
-
}
|
|
40566
|
-
if (typeof this.query.hasFlag === 'boolean') {
|
|
40567
|
-
if (this.query.hasFlag) {
|
|
40568
|
-
comments = comments.filter(comment => comment.hashFlag != null);
|
|
40569
|
-
}
|
|
40570
|
-
else {
|
|
40571
|
-
comments = comments.filter(comment => comment.hashFlag == null);
|
|
40572
|
-
}
|
|
40573
|
-
}
|
|
40574
|
-
if (this.query.dataTypes) {
|
|
40575
|
-
if (this.query.dataTypes.matchType === 'exact') {
|
|
40576
|
-
comments = comments.filter(comment => {
|
|
40577
|
-
var _a, _b;
|
|
40578
|
-
const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
|
|
40579
|
-
const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
|
|
40580
|
-
if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
|
|
40581
|
-
return false;
|
|
40582
|
-
}
|
|
40583
|
-
return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
|
|
40584
|
-
});
|
|
40585
|
-
}
|
|
40586
|
-
if (this.query.dataTypes.matchType === 'any') {
|
|
40587
|
-
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); }); });
|
|
40588
|
-
}
|
|
40589
|
-
}
|
|
40590
|
-
switch (this.query.sortBy) {
|
|
40591
|
-
case 'firstCreated':
|
|
40592
|
-
comments = comments.sort(sortByFirstCreated);
|
|
40593
|
-
break;
|
|
40594
|
-
case 'lastCreated':
|
|
40595
|
-
default:
|
|
40596
|
-
comments = comments.sort(sortByLastCreated);
|
|
40597
|
-
break;
|
|
40598
|
-
}
|
|
40599
|
-
return comments;
|
|
40600
|
-
}
|
|
40601
|
-
}
|
|
40939
|
+
/* end_public_function */
|
|
40602
40940
|
|
|
40603
40941
|
/* begin_public_function
|
|
40604
|
-
id:
|
|
40942
|
+
id: post.approve
|
|
40605
40943
|
*/
|
|
40606
40944
|
/**
|
|
40607
40945
|
* ```js
|
|
40608
|
-
* import {
|
|
40946
|
+
* import { approvePost } from '@amityco/ts-sdk'
|
|
40609
40947
|
*
|
|
40610
|
-
*
|
|
40611
|
-
* const unsub = getComments({
|
|
40612
|
-
* referenceType: Amity.InternalComment['referenceType'];
|
|
40613
|
-
* referenceId: Amity.InternalComment['referenceId'];
|
|
40614
|
-
* }, response => merge(comments, response.data))
|
|
40948
|
+
* const { data: post } = await approvePost('postId')
|
|
40615
40949
|
* ```
|
|
40616
40950
|
*
|
|
40617
|
-
*
|
|
40951
|
+
* Approves a {@link Amity.Post}
|
|
40618
40952
|
*
|
|
40619
|
-
* @param
|
|
40620
|
-
* @
|
|
40621
|
-
* @param callback the function to call when new data are available
|
|
40622
|
-
* @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
|
|
40953
|
+
* @param postId The {@link Amity.Post} ID to be approved
|
|
40954
|
+
* @return A {@link Amity.Post} that was approved
|
|
40623
40955
|
*
|
|
40624
|
-
* @category
|
|
40956
|
+
* @category Post API
|
|
40957
|
+
* @async
|
|
40625
40958
|
*/
|
|
40626
|
-
const
|
|
40627
|
-
const
|
|
40628
|
-
|
|
40629
|
-
|
|
40959
|
+
const approvePost = async (postId) => {
|
|
40960
|
+
const client = getActiveClient();
|
|
40961
|
+
client.log('post/approvePost', postId);
|
|
40962
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
|
|
40963
|
+
fireEvent('post.approved', payload);
|
|
40964
|
+
// fire virtual event for community update
|
|
40965
|
+
if (payload.posts[0].targetType === 'community') {
|
|
40966
|
+
fireEvent('community.updated', payload);
|
|
40630
40967
|
}
|
|
40631
|
-
const
|
|
40632
|
-
|
|
40633
|
-
|
|
40634
|
-
|
|
40635
|
-
|
|
40636
|
-
|
|
40637
|
-
|
|
40638
|
-
log(`getComments(tmpid: ${timestamp}) > dispose`);
|
|
40639
|
-
disposers.forEach(fn => fn());
|
|
40968
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40969
|
+
const cachedAt = client.cache && Date.now();
|
|
40970
|
+
if (client.cache)
|
|
40971
|
+
ingestInCache(data, { cachedAt });
|
|
40972
|
+
return {
|
|
40973
|
+
data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
|
|
40974
|
+
cachedAt,
|
|
40640
40975
|
};
|
|
40641
40976
|
};
|
|
40642
40977
|
/* end_public_function */
|
|
40643
40978
|
|
|
40644
|
-
|
|
40645
|
-
|
|
40646
|
-
|
|
40647
|
-
createComment: createComment,
|
|
40648
|
-
updateComment: updateComment,
|
|
40649
|
-
deleteComment: deleteComment,
|
|
40650
|
-
softDeleteComment: softDeleteComment,
|
|
40651
|
-
hardDeleteComment: hardDeleteComment,
|
|
40652
|
-
flagComment: flagComment,
|
|
40653
|
-
unflagComment: unflagComment,
|
|
40654
|
-
isCommentFlaggedByMe: isCommentFlaggedByMe,
|
|
40655
|
-
onCommentCreated: onCommentCreated,
|
|
40656
|
-
onCommentUpdated: onCommentUpdated,
|
|
40657
|
-
onCommentDeleted: onCommentDeleted,
|
|
40658
|
-
onCommentFlagged: onCommentFlagged,
|
|
40659
|
-
onCommentUnflagged: onCommentUnflagged,
|
|
40660
|
-
onCommentReactionAdded: onCommentReactionAdded,
|
|
40661
|
-
onCommentReactionRemoved: onCommentReactionRemoved,
|
|
40662
|
-
getComment: getComment,
|
|
40663
|
-
getComments: getComments
|
|
40664
|
-
});
|
|
40665
|
-
|
|
40979
|
+
/* begin_public_function
|
|
40980
|
+
id: post.decline
|
|
40981
|
+
*/
|
|
40666
40982
|
/**
|
|
40667
40983
|
* ```js
|
|
40668
|
-
* import {
|
|
40669
|
-
*
|
|
40670
|
-
*
|
|
40671
|
-
* })
|
|
40984
|
+
* import { declinePost } from '@amityco/ts-sdk'
|
|
40985
|
+
*
|
|
40986
|
+
* const {data: post} = await declinePost('postId')
|
|
40672
40987
|
* ```
|
|
40673
40988
|
*
|
|
40674
|
-
*
|
|
40989
|
+
* Declines a {@link Amity.Post}
|
|
40675
40990
|
*
|
|
40676
|
-
* @param
|
|
40677
|
-
* @
|
|
40991
|
+
* @param postId The {@link Amity.Post} ID to be declined
|
|
40992
|
+
* @return A {@link Amity.Post} that was declined
|
|
40678
40993
|
*
|
|
40679
|
-
* @category Post
|
|
40994
|
+
* @category Post API
|
|
40995
|
+
* @async
|
|
40680
40996
|
*/
|
|
40681
|
-
const
|
|
40997
|
+
const declinePost = async (postId) => {
|
|
40998
|
+
const client = getActiveClient();
|
|
40999
|
+
client.log('post/declinePost', postId);
|
|
41000
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
|
|
41001
|
+
// fire virtual event
|
|
41002
|
+
if (payload.posts[0].targetType === 'community') {
|
|
41003
|
+
fireEvent('community.updated', payload);
|
|
41004
|
+
}
|
|
41005
|
+
fireEvent('post.declined', payload);
|
|
41006
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
41007
|
+
const cachedAt = client.cache && Date.now();
|
|
41008
|
+
if (client.cache)
|
|
41009
|
+
ingestInCache(data, { cachedAt });
|
|
41010
|
+
return {
|
|
41011
|
+
data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
|
|
41012
|
+
cachedAt,
|
|
41013
|
+
};
|
|
41014
|
+
};
|
|
41015
|
+
/* end_public_function */
|
|
40682
41016
|
|
|
41017
|
+
/* begin_public_function
|
|
41018
|
+
id: post.flag
|
|
41019
|
+
*/
|
|
40683
41020
|
/**
|
|
40684
41021
|
* ```js
|
|
40685
|
-
* import {
|
|
40686
|
-
* const
|
|
40687
|
-
* // ...
|
|
40688
|
-
* })
|
|
41022
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
41023
|
+
* const flagged = await PostRepository.flagPost(postId, reason)
|
|
40689
41024
|
* ```
|
|
40690
41025
|
*
|
|
40691
|
-
*
|
|
40692
|
-
*
|
|
40693
|
-
* @
|
|
40694
|
-
* @returns an {@link Amity.Unsubscriber} function to stop listening
|
|
41026
|
+
* @param postId of the post to flag
|
|
41027
|
+
* @param reason the reason to flag the post
|
|
41028
|
+
* @returns a boolean
|
|
40695
41029
|
*
|
|
40696
|
-
* @category Post
|
|
40697
|
-
|
|
40698
|
-
|
|
41030
|
+
* @category Post API
|
|
41031
|
+
* @async
|
|
41032
|
+
* */
|
|
41033
|
+
const flagPost = async (postId, reason) => {
|
|
40699
41034
|
const client = getActiveClient();
|
|
40700
|
-
|
|
40701
|
-
|
|
40702
|
-
|
|
40703
|
-
|
|
40704
|
-
|
|
40705
|
-
|
|
40706
|
-
callback(post);
|
|
40707
|
-
}
|
|
41035
|
+
client.log('post/flagPost', postId);
|
|
41036
|
+
const isPredefinedReason = reason &&
|
|
41037
|
+
Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
|
|
41038
|
+
const body = {
|
|
41039
|
+
reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
|
|
41040
|
+
detail: reason && !isPredefinedReason ? reason : '',
|
|
40708
41041
|
};
|
|
40709
|
-
|
|
41042
|
+
const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
|
|
41043
|
+
if (client.cache) {
|
|
41044
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
41045
|
+
}
|
|
41046
|
+
fireEvent('post.flagged', payload);
|
|
41047
|
+
return !!payload;
|
|
40710
41048
|
};
|
|
41049
|
+
/* end_public_function */
|
|
40711
41050
|
|
|
41051
|
+
/* begin_public_function
|
|
41052
|
+
id: post.unflag
|
|
41053
|
+
*/
|
|
40712
41054
|
/**
|
|
40713
41055
|
* ```js
|
|
40714
|
-
* import {
|
|
40715
|
-
* const
|
|
40716
|
-
* // ...
|
|
40717
|
-
* })
|
|
41056
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
41057
|
+
* const unflagged = await PostRepository.unflagPost(postId)
|
|
40718
41058
|
* ```
|
|
40719
41059
|
*
|
|
40720
|
-
*
|
|
41060
|
+
* @param postId of the post to unflag
|
|
41061
|
+
* @returns the unflag post result
|
|
40721
41062
|
*
|
|
40722
|
-
* @
|
|
40723
|
-
* @
|
|
41063
|
+
* @category Post API
|
|
41064
|
+
* @async
|
|
41065
|
+
* */
|
|
41066
|
+
const unflagPost = async (postId) => {
|
|
41067
|
+
const client = getActiveClient();
|
|
41068
|
+
client.log('post/unflagPost', postId);
|
|
41069
|
+
const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
|
|
41070
|
+
if (client.cache) {
|
|
41071
|
+
ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
|
|
41072
|
+
}
|
|
41073
|
+
fireEvent('post.unflagged', payload);
|
|
41074
|
+
return !!payload;
|
|
41075
|
+
};
|
|
41076
|
+
/* end_public_function */
|
|
41077
|
+
|
|
41078
|
+
/* begin_public_function
|
|
41079
|
+
id: post.check_flag_by_me
|
|
41080
|
+
*/
|
|
41081
|
+
/**
|
|
41082
|
+
* ```js
|
|
41083
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
41084
|
+
* const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
|
|
41085
|
+
* ```
|
|
40724
41086
|
*
|
|
40725
|
-
* @
|
|
40726
|
-
|
|
40727
|
-
|
|
41087
|
+
* @param postId of the post to check if flagged by current user
|
|
41088
|
+
* @returns `true` if the post is flagged by me, `false` if doesn't.
|
|
41089
|
+
*
|
|
41090
|
+
* @category Post API
|
|
41091
|
+
* @async
|
|
41092
|
+
* */
|
|
41093
|
+
const isPostFlaggedByMe = async (postId) => {
|
|
40728
41094
|
const client = getActiveClient();
|
|
40729
|
-
|
|
40730
|
-
|
|
40731
|
-
|
|
40732
|
-
}
|
|
40733
|
-
else {
|
|
40734
|
-
upsertInCache(['post', 'get', post.postId], post);
|
|
40735
|
-
callback(post);
|
|
40736
|
-
}
|
|
40737
|
-
};
|
|
40738
|
-
return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
|
|
41095
|
+
client.log('post/isPostFlaggedByMe', postId);
|
|
41096
|
+
const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
|
|
41097
|
+
return result;
|
|
40739
41098
|
};
|
|
41099
|
+
/* end_public_function */
|
|
40740
41100
|
|
|
41101
|
+
/* begin_public_function
|
|
41102
|
+
id: post.create.clip_post
|
|
41103
|
+
*/
|
|
40741
41104
|
/**
|
|
40742
41105
|
* ```js
|
|
40743
|
-
* import {
|
|
40744
|
-
* const
|
|
40745
|
-
*
|
|
40746
|
-
*
|
|
41106
|
+
* import { PostRepository } from '@amityco/ts-sdk'
|
|
41107
|
+
* const created = await PostRepository.createClipPost({
|
|
41108
|
+
* targetType: 'user',
|
|
41109
|
+
* targetId: 'foobar',
|
|
41110
|
+
* dataType: 'clip',
|
|
41111
|
+
* data: { text: 'hello world' },
|
|
41112
|
+
* attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
|
|
41113
|
+
* }))
|
|
40747
41114
|
* ```
|
|
40748
41115
|
*
|
|
40749
|
-
*
|
|
41116
|
+
* Creates an {@link Amity.Post}
|
|
40750
41117
|
*
|
|
40751
|
-
* @param
|
|
40752
|
-
* @returns
|
|
41118
|
+
* @param bundle The data necessary to create a new {@link Amity.Post}
|
|
41119
|
+
* @returns The newly created {@link Amity.Post}
|
|
40753
41120
|
*
|
|
40754
|
-
* @category Post
|
|
41121
|
+
* @category Post API
|
|
41122
|
+
* @async
|
|
40755
41123
|
*/
|
|
40756
|
-
const
|
|
41124
|
+
const createClipPost = async (bundle) => {
|
|
41125
|
+
const client = getActiveClient();
|
|
41126
|
+
client.log('post/createPost', bundle);
|
|
41127
|
+
const { data: payload } = await client.http.post('/api/v4/posts', bundle);
|
|
41128
|
+
fireEvent('post.created', payload);
|
|
41129
|
+
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
41130
|
+
const cachedAt = client.cache && Date.now();
|
|
41131
|
+
if (client.cache)
|
|
41132
|
+
ingestInCache(data, { cachedAt });
|
|
41133
|
+
const { posts } = data;
|
|
41134
|
+
return {
|
|
41135
|
+
data: LinkedObject.post(posts[0]),
|
|
41136
|
+
cachedAt,
|
|
41137
|
+
};
|
|
41138
|
+
};
|
|
41139
|
+
/* end_public_function */
|
|
40757
41140
|
|
|
40758
41141
|
/* begin_public_function
|
|
40759
41142
|
id: post.get
|
|
@@ -40777,7 +41160,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
|
|
|
40777
41160
|
*
|
|
40778
41161
|
* @category Post Live Object
|
|
40779
41162
|
*/
|
|
40780
|
-
const getPost
|
|
41163
|
+
const getPost = (postId, callback) => {
|
|
40781
41164
|
const responder = (snapshot) => {
|
|
40782
41165
|
const { data } = snapshot;
|
|
40783
41166
|
callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
|
|
@@ -40866,19 +41249,6 @@ class PostPaginationController extends PaginationController {
|
|
|
40866
41249
|
}
|
|
40867
41250
|
}
|
|
40868
41251
|
|
|
40869
|
-
var EnumPostActions;
|
|
40870
|
-
(function (EnumPostActions) {
|
|
40871
|
-
EnumPostActions["OnPostCreated"] = "onPostCreated";
|
|
40872
|
-
EnumPostActions["OnPostUpdated"] = "onPostUpdated";
|
|
40873
|
-
EnumPostActions["OnPostDeleted"] = "onPostDeleted";
|
|
40874
|
-
EnumPostActions["OnPostFlagged"] = "onPostFlagged";
|
|
40875
|
-
EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
|
|
40876
|
-
EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
|
|
40877
|
-
EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
|
|
40878
|
-
EnumPostActions["OnPostApproved"] = "onPostApproved";
|
|
40879
|
-
EnumPostActions["OnPostDeclined"] = "onPostDeclined";
|
|
40880
|
-
})(EnumPostActions || (EnumPostActions = {}));
|
|
40881
|
-
|
|
40882
41252
|
class PostQueryStreamController extends QueryStreamController {
|
|
40883
41253
|
constructor(query, cacheKey, notifyChange, preparePayload) {
|
|
40884
41254
|
super(query, cacheKey);
|
|
@@ -40944,45 +41314,50 @@ class PostQueryStreamController extends QueryStreamController {
|
|
|
40944
41314
|
}
|
|
40945
41315
|
}
|
|
40946
41316
|
|
|
40947
|
-
const
|
|
40948
|
-
|
|
40949
|
-
|
|
40950
|
-
|
|
40951
|
-
|
|
40952
|
-
|
|
40953
|
-
|
|
40954
|
-
|
|
40955
|
-
|
|
40956
|
-
}
|
|
40957
|
-
catch (error) {
|
|
40958
|
-
if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
|
|
40959
|
-
pushToTombstone('post', postId);
|
|
40960
|
-
}
|
|
40961
|
-
throw error;
|
|
40962
|
-
}
|
|
40963
|
-
const data = prepareMembershipPayload(payload, 'communityUsers');
|
|
40964
|
-
const cachedAt = client.cache && Date.now();
|
|
40965
|
-
if (client.cache)
|
|
40966
|
-
ingestInCache(data, { cachedAt });
|
|
40967
|
-
const { posts } = data;
|
|
40968
|
-
const result = posts.find(post => post.postId === postId);
|
|
40969
|
-
return {
|
|
40970
|
-
data: result,
|
|
40971
|
-
cachedAt,
|
|
40972
|
-
};
|
|
41317
|
+
const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
|
|
41318
|
+
return eventHandler(async (comment) => {
|
|
41319
|
+
var _a;
|
|
41320
|
+
const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41321
|
+
if (!currentCollection ||
|
|
41322
|
+
!currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
|
|
41323
|
+
return;
|
|
41324
|
+
await getPost$1(comment.referenceId);
|
|
41325
|
+
callback(comment);
|
|
41326
|
+
});
|
|
40973
41327
|
};
|
|
40974
|
-
|
|
40975
|
-
const
|
|
40976
|
-
|
|
40977
|
-
|
|
40978
|
-
|
|
40979
|
-
|
|
40980
|
-
|
|
40981
|
-
|
|
40982
|
-
|
|
40983
|
-
|
|
40984
|
-
|
|
40985
|
-
|
|
41328
|
+
const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
|
|
41329
|
+
const eventHandlers = [
|
|
41330
|
+
onCommentCreated,
|
|
41331
|
+
onCommentDeleted,
|
|
41332
|
+
onCommentReactionAdded,
|
|
41333
|
+
onCommentReactionRemoved,
|
|
41334
|
+
onCommentCreatedLocal,
|
|
41335
|
+
onCommentDeleteLocal,
|
|
41336
|
+
onLocalCommentReactionAdded,
|
|
41337
|
+
onLocalCommentReactionRemoved,
|
|
41338
|
+
];
|
|
41339
|
+
return eventHandlers.map(handler => ({
|
|
41340
|
+
fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
|
|
41341
|
+
action: EnumPostActions.OnPostUpdated,
|
|
41342
|
+
}));
|
|
41343
|
+
};
|
|
41344
|
+
const getPostSubscription = (cacheKey) => {
|
|
41345
|
+
return [
|
|
41346
|
+
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
41347
|
+
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
41348
|
+
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
41349
|
+
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41350
|
+
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
41351
|
+
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
41352
|
+
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
41353
|
+
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
41354
|
+
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41355
|
+
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41356
|
+
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41357
|
+
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41358
|
+
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41359
|
+
...generateCommentSubscriptions({ cacheKey }),
|
|
41360
|
+
];
|
|
40986
41361
|
};
|
|
40987
41362
|
|
|
40988
41363
|
class PostLiveCollectionController extends LiveCollectionController {
|
|
@@ -41013,47 +41388,7 @@ class PostLiveCollectionController extends LiveCollectionController {
|
|
|
41013
41388
|
this.queryStreamController.appendToQueryStream(response, direction, refresh);
|
|
41014
41389
|
}
|
|
41015
41390
|
startSubscription() {
|
|
41016
|
-
return this.queryStreamController.subscribeRTE(
|
|
41017
|
-
{ fn: onPostCreated, action: EnumPostActions.OnPostCreated },
|
|
41018
|
-
{ fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
|
|
41019
|
-
{ fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
|
|
41020
|
-
{ fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41021
|
-
{ fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
|
|
41022
|
-
{ fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
|
|
41023
|
-
{ fn: onPostApproved, action: EnumPostActions.OnPostApproved },
|
|
41024
|
-
{ fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
|
|
41025
|
-
{ fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41026
|
-
{ fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41027
|
-
{ fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
|
|
41028
|
-
{ fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
|
|
41029
|
-
{ fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
|
|
41030
|
-
{
|
|
41031
|
-
fn: convertEventPayload((callback) => {
|
|
41032
|
-
return onCommentCreated(async (comment) => {
|
|
41033
|
-
var _a;
|
|
41034
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41035
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41036
|
-
return;
|
|
41037
|
-
await getPost(comment.referenceId);
|
|
41038
|
-
callback(comment);
|
|
41039
|
-
});
|
|
41040
|
-
}, 'referenceId', 'post'),
|
|
41041
|
-
action: EnumPostActions.OnPostUpdated,
|
|
41042
|
-
},
|
|
41043
|
-
{
|
|
41044
|
-
fn: convertEventPayload((callback) => {
|
|
41045
|
-
return onCommentDeleted(async (comment) => {
|
|
41046
|
-
var _a;
|
|
41047
|
-
const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41048
|
-
if (!currentCollection || currentCollection.data.includes(comment.referenceId))
|
|
41049
|
-
return;
|
|
41050
|
-
await getPost(comment.referenceId);
|
|
41051
|
-
callback(comment);
|
|
41052
|
-
});
|
|
41053
|
-
}, 'referenceId', 'post'),
|
|
41054
|
-
action: EnumPostActions.OnPostUpdated,
|
|
41055
|
-
},
|
|
41056
|
-
]);
|
|
41391
|
+
return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
|
|
41057
41392
|
}
|
|
41058
41393
|
notifyChange({ origin, loading, error }) {
|
|
41059
41394
|
var _a, _b;
|
|
@@ -41188,6 +41523,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
|
|
|
41188
41523
|
});
|
|
41189
41524
|
}
|
|
41190
41525
|
}
|
|
41526
|
+
reactor(action) {
|
|
41527
|
+
return (post) => {
|
|
41528
|
+
var _a;
|
|
41529
|
+
const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
|
|
41530
|
+
if (!collection)
|
|
41531
|
+
return;
|
|
41532
|
+
if (action === EnumPostActions.OnPostDeleted) {
|
|
41533
|
+
collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
|
|
41534
|
+
}
|
|
41535
|
+
pushToCache(this.cacheKey, collection);
|
|
41536
|
+
this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
|
|
41537
|
+
};
|
|
41538
|
+
}
|
|
41539
|
+
subscribeRTE(createSubscriber) {
|
|
41540
|
+
return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
|
|
41541
|
+
}
|
|
41191
41542
|
}
|
|
41192
41543
|
|
|
41193
41544
|
class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
@@ -41219,7 +41570,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
|
|
|
41219
41570
|
}
|
|
41220
41571
|
// eslint-disable-next-line class-methods-use-this
|
|
41221
41572
|
startSubscription() {
|
|
41222
|
-
return
|
|
41573
|
+
return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
|
|
41574
|
+
cacheKey: this.cacheKey,
|
|
41575
|
+
resolveId: id => `${this.query.placement}#${id}`,
|
|
41576
|
+
}));
|
|
41223
41577
|
}
|
|
41224
41578
|
notifyChange({ origin, loading, error }) {
|
|
41225
41579
|
var _a, _b;
|
|
@@ -41371,6 +41725,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
|
|
|
41371
41725
|
fn: onPostDeleted,
|
|
41372
41726
|
action: EnumPostActions.OnPostDeleted,
|
|
41373
41727
|
},
|
|
41728
|
+
...generateCommentSubscriptions({
|
|
41729
|
+
cacheKey: this.cacheKey,
|
|
41730
|
+
resolveId: id => `global#${id}`,
|
|
41731
|
+
}),
|
|
41374
41732
|
]);
|
|
41375
41733
|
}
|
|
41376
41734
|
notifyChange({ origin, loading, error }) {
|
|
@@ -41673,7 +42031,7 @@ var index$8 = /*#__PURE__*/Object.freeze({
|
|
|
41673
42031
|
onPostUnflagged: onPostUnflagged,
|
|
41674
42032
|
onPostReactionAdded: onPostReactionAdded,
|
|
41675
42033
|
onPostReactionRemoved: onPostReactionRemoved,
|
|
41676
|
-
getPost: getPost
|
|
42034
|
+
getPost: getPost,
|
|
41677
42035
|
getPosts: getPosts,
|
|
41678
42036
|
getPinnedPosts: getPinnedPosts,
|
|
41679
42037
|
getGlobalPinnedPosts: getGlobalPinnedPosts,
|
|
@@ -44874,4 +45232,4 @@ var index = /*#__PURE__*/Object.freeze({
|
|
|
44874
45232
|
getReactions: getReactions
|
|
44875
45233
|
});
|
|
44876
45234
|
|
|
44877
|
-
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$
|
|
45235
|
+
export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };
|