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