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