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