@amityco/ts-sdk 7.8.0 → 7.8.1-1ae26ac.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.
Files changed (260) hide show
  1. package/.env +26 -26
  2. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts +4 -0
  3. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.d.ts.map +1 -1
  4. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/client.js.map +1 -1
  5. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts +4 -0
  6. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.d.ts.map +1 -1
  7. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/feed.js.map +1 -1
  8. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts +11 -0
  9. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.d.ts.map +1 -0
  10. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js +2 -0
  11. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/hashtag.js.map +1 -0
  12. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts +2 -1
  13. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.d.ts.map +1 -1
  14. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/notification.js.map +1 -1
  15. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts +14 -1
  16. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.d.ts.map +1 -1
  17. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/domains/post.js.map +1 -1
  18. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts +1 -0
  19. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.d.ts.map +1 -1
  20. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js +1 -0
  21. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/@types/index.js.map +1 -1
  22. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  23. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  24. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js +21 -0
  25. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/getShareableLinkConfiguration.js.map +1 -0
  26. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts +1 -0
  27. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.d.ts.map +1 -1
  28. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js +1 -0
  29. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/client/api/index.js.map +1 -1
  30. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js +6 -6
  31. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/commentRepository/api/deleteComment.js.map +1 -1
  32. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.d.ts.map +1 -1
  33. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js +2 -1
  34. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/core/model/index.js.map +1 -1
  35. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts +0 -1
  36. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.d.ts.map +1 -1
  37. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js +0 -1
  38. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/index.js.map +1 -1
  39. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  40. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  41. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js +3 -0
  42. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/queryGlobalFeed.js.map +1 -1
  43. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts +2 -1
  44. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.d.ts.map +1 -1
  45. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js +2 -1
  46. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/index.js.map +1 -1
  47. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  48. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  49. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js +60 -0
  50. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.js.map +1 -0
  51. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  52. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  53. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js +13 -0
  54. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.js.map +1 -0
  55. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  56. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  57. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js +66 -0
  58. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.js.map +1 -0
  59. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  60. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  61. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js +45 -0
  62. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getCustomRankingGlobalFeed.js.map +1 -0
  63. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  64. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  65. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js +60 -0
  66. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.js.map +1 -0
  67. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  68. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  69. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js +13 -0
  70. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/PaginationController.js.map +1 -0
  71. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  72. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  73. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js +66 -0
  74. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.js.map +1 -0
  75. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  76. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  77. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js +45 -0
  78. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/getGlobalFeed.js.map +1 -0
  79. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts +3 -0
  80. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.d.ts.map +1 -0
  81. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js +3 -0
  82. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/index.js.map +1 -0
  83. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts +6 -0
  84. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.d.ts.map +1 -0
  85. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js +60 -0
  86. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/observers/utils.js.map +1 -0
  87. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.d.ts +1 -1
  88. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/createPost.js.map +1 -1
  89. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.d.ts +1 -1
  90. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/editPost.js.map +1 -1
  91. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js +2 -2
  92. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/api/queryPosts.js.map +1 -1
  93. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.d.ts.map +1 -1
  94. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js +26 -1
  95. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/events/utils.js.map +1 -1
  96. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  97. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js +5 -0
  98. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.js.map +1 -1
  99. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  100. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js +5 -1
  101. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.js.map +1 -1
  102. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  103. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  104. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js +17 -0
  105. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.js.map +1 -1
  106. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  107. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js +2 -50
  108. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPosts/PostLiveCollectionController.js.map +1 -1
  109. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  110. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  111. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js +126 -0
  112. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.js.map +1 -0
  113. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  114. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  115. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js +27 -0
  116. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.js.map +1 -0
  117. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  118. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  119. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js +65 -0
  120. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.js.map +1 -0
  121. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts +1 -0
  122. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.d.ts.map +1 -1
  123. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js +1 -0
  124. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/index.js.map +1 -1
  125. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  126. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  127. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js +45 -0
  128. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/searchPostsByHashtag.js.map +1 -0
  129. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts +13 -0
  130. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.d.ts.map +1 -0
  131. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js +61 -0
  132. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/postRepository/observers/utils.js.map +1 -0
  133. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  134. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js +1 -1
  135. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/addReaction.js.map +1 -1
  136. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  137. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js +1 -1
  138. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/reactionRepository/api/removeReaction.js.map +1 -1
  139. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  140. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js +9 -4
  141. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/utils/linkedObject/postLinkedObject.js.map +1 -1
  142. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/tsconfig.tsbuildinfo +1 -1
  143. package/dist/@types/domains/client.d.ts +4 -0
  144. package/dist/@types/domains/client.d.ts.map +1 -1
  145. package/dist/@types/domains/feed.d.ts +4 -0
  146. package/dist/@types/domains/feed.d.ts.map +1 -1
  147. package/dist/@types/domains/hashtag.d.ts +11 -0
  148. package/dist/@types/domains/hashtag.d.ts.map +1 -0
  149. package/dist/@types/domains/notification.d.ts +2 -1
  150. package/dist/@types/domains/notification.d.ts.map +1 -1
  151. package/dist/@types/domains/post.d.ts +14 -1
  152. package/dist/@types/domains/post.d.ts.map +1 -1
  153. package/dist/@types/index.d.ts +1 -0
  154. package/dist/@types/index.d.ts.map +1 -1
  155. package/dist/client/api/getShareableLinkConfiguration.d.ts +16 -0
  156. package/dist/client/api/getShareableLinkConfiguration.d.ts.map +1 -0
  157. package/dist/client/api/index.d.ts +1 -0
  158. package/dist/client/api/index.d.ts.map +1 -1
  159. package/dist/core/model/index.d.ts.map +1 -1
  160. package/dist/feedRepository/api/index.d.ts +0 -1
  161. package/dist/feedRepository/api/index.d.ts.map +1 -1
  162. package/dist/feedRepository/api/queryGlobalFeed.d.ts +3 -0
  163. package/dist/feedRepository/api/queryGlobalFeed.d.ts.map +1 -1
  164. package/dist/feedRepository/index.d.ts +2 -1
  165. package/dist/feedRepository/index.d.ts.map +1 -1
  166. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts +13 -0
  167. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  168. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts +5 -0
  169. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.d.ts.map +1 -0
  170. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts +15 -0
  171. package/dist/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.d.ts.map +1 -0
  172. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts +22 -0
  173. package/dist/feedRepository/observers/getCustomRankingGlobalFeed.d.ts.map +1 -0
  174. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts +13 -0
  175. package/dist/feedRepository/observers/getGlobalFeed/LiveCollectionController.d.ts.map +1 -0
  176. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts +5 -0
  177. package/dist/feedRepository/observers/getGlobalFeed/PaginationController.d.ts.map +1 -0
  178. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts +15 -0
  179. package/dist/feedRepository/observers/getGlobalFeed/QueryStreamController.d.ts.map +1 -0
  180. package/dist/feedRepository/observers/getGlobalFeed.d.ts +22 -0
  181. package/dist/feedRepository/observers/getGlobalFeed.d.ts.map +1 -0
  182. package/dist/feedRepository/observers/index.d.ts +3 -0
  183. package/dist/feedRepository/observers/index.d.ts.map +1 -0
  184. package/dist/feedRepository/observers/utils.d.ts +6 -0
  185. package/dist/feedRepository/observers/utils.d.ts.map +1 -0
  186. package/dist/index.cjs.js +1887 -1275
  187. package/dist/index.esm.js +1793 -1181
  188. package/dist/index.umd.js +4 -4
  189. package/dist/postRepository/api/createPost.d.ts +1 -1
  190. package/dist/postRepository/api/editPost.d.ts +1 -1
  191. package/dist/postRepository/events/utils.d.ts.map +1 -1
  192. package/dist/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.d.ts.map +1 -1
  193. package/dist/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.d.ts.map +1 -1
  194. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts +6 -0
  195. package/dist/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.d.ts.map +1 -1
  196. package/dist/postRepository/observers/getPosts/PostLiveCollectionController.d.ts.map +1 -1
  197. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts +14 -0
  198. package/dist/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.d.ts.map +1 -0
  199. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts +5 -0
  200. package/dist/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.d.ts.map +1 -0
  201. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts +15 -0
  202. package/dist/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.d.ts.map +1 -0
  203. package/dist/postRepository/observers/index.d.ts +1 -0
  204. package/dist/postRepository/observers/index.d.ts.map +1 -1
  205. package/dist/postRepository/observers/searchPostsByHashtag.d.ts +22 -0
  206. package/dist/postRepository/observers/searchPostsByHashtag.d.ts.map +1 -0
  207. package/dist/postRepository/observers/utils.d.ts +13 -0
  208. package/dist/postRepository/observers/utils.d.ts.map +1 -0
  209. package/dist/reactionRepository/api/addReaction.d.ts.map +1 -1
  210. package/dist/reactionRepository/api/removeReaction.d.ts.map +1 -1
  211. package/dist/utils/linkedObject/postLinkedObject.d.ts.map +1 -1
  212. package/package.json +1 -1
  213. package/src/@types/domains/client.ts +5 -0
  214. package/src/@types/domains/feed.ts +16 -0
  215. package/src/@types/domains/hashtag.ts +11 -0
  216. package/src/@types/domains/notification.ts +1 -0
  217. package/src/@types/domains/post.ts +18 -1
  218. package/src/@types/index.ts +1 -0
  219. package/src/client/api/getShareableLinkConfiguration.ts +26 -0
  220. package/src/client/api/index.ts +2 -0
  221. package/src/commentRepository/api/deleteComment.ts +6 -6
  222. package/src/core/model/index.ts +2 -1
  223. package/src/feedRepository/api/index.ts +0 -1
  224. package/src/feedRepository/api/queryGlobalFeed.ts +3 -0
  225. package/src/feedRepository/index.ts +2 -1
  226. package/src/feedRepository/observers/getCustomRankingGlobalFeed/LiveCollectionController.ts +95 -0
  227. package/src/feedRepository/observers/getCustomRankingGlobalFeed/PaginationController.ts +25 -0
  228. package/src/feedRepository/observers/getCustomRankingGlobalFeed/QueryStreamController.ts +101 -0
  229. package/src/feedRepository/observers/getCustomRankingGlobalFeed.ts +56 -0
  230. package/src/feedRepository/observers/getGlobalFeed/LiveCollectionController.ts +91 -0
  231. package/src/feedRepository/observers/getGlobalFeed/PaginationController.ts +23 -0
  232. package/src/feedRepository/observers/getGlobalFeed/QueryStreamController.ts +99 -0
  233. package/src/feedRepository/observers/getGlobalFeed.ts +56 -0
  234. package/src/feedRepository/observers/index.ts +2 -0
  235. package/src/feedRepository/observers/utils.ts +85 -0
  236. package/src/postRepository/api/createPost.ts +1 -1
  237. package/src/postRepository/api/editPost.ts +1 -1
  238. package/src/postRepository/api/queryPosts.ts +2 -2
  239. package/src/postRepository/events/utils.ts +35 -1
  240. package/src/postRepository/observers/getGlobalPinnedPosts/GlobalPinnedPostLiveCollectionController.ts +5 -0
  241. package/src/postRepository/observers/getPinnedPosts/PinnedPostLiveCollectionController.ts +7 -1
  242. package/src/postRepository/observers/getPinnedPosts/PinnedPostQueryStreamController.ts +27 -0
  243. package/src/postRepository/observers/getPosts/PostLiveCollectionController.ts +2 -74
  244. package/src/postRepository/observers/getPostsByHashtag/SearchPostLiveCollectionController.ts +183 -0
  245. package/src/postRepository/observers/getPostsByHashtag/SearchPostPaginationController.ts +49 -0
  246. package/src/postRepository/observers/getPostsByHashtag/SearchPostQueryStreamController.ts +99 -0
  247. package/src/postRepository/observers/index.ts +1 -0
  248. package/src/postRepository/observers/searchPostsByHashtag.ts +56 -0
  249. package/src/postRepository/observers/utils.ts +97 -0
  250. package/src/reactionRepository/api/addReaction.ts +1 -0
  251. package/src/reactionRepository/api/removeReaction.ts +1 -0
  252. package/src/utils/linkedObject/postLinkedObject.ts +3 -3
  253. package/tsconfig.tsbuildinfo +1 -1
  254. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  255. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  256. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js +0 -83
  257. package/.rollup.cache/home/runner/work/AmityTypescriptSDK/AmityTypescriptSDK/packages/sdk/dist/feedRepository/api/getCustomRankingGlobalFeed.js.map +0 -1
  258. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts +0 -37
  259. package/dist/feedRepository/api/getCustomRankingGlobalFeed.d.ts.map +0 -1
  260. package/src/feedRepository/api/getCustomRankingGlobalFeed.ts +0 -115
package/dist/index.esm.js CHANGED
@@ -642,7 +642,8 @@ const PAYLOAD2MODEL = {
642
642
  };
643
643
  /** hidden */
644
644
  const isOutdated = (prevData, nextData) => {
645
- if ('updatedAt' in nextData && 'updatedAt' in nextData) {
645
+ // Check if the new value is outdated.
646
+ if ('updatedAt' in nextData && 'updatedAt' in prevData) {
646
647
  return new Date(nextData.updatedAt) < new Date(prevData.updatedAt);
647
648
  }
648
649
  return false;
@@ -25872,6 +25873,26 @@ const fetchLinkPreview = async (url) => {
25872
25873
  return data;
25873
25874
  };
25874
25875
 
25876
+ /**
25877
+ * ```js
25878
+ * import Client from '@amityco/ts-sdk'
25879
+ * const shareableLinkConfiguration = await Client.getShareableLinkConfiguration()
25880
+ * const postLinkPattern = shareableLinkConfiguration.post
25881
+ * ```
25882
+ *
25883
+ * Fetches a {@link Amity.ShareableLinkConfiguration} object
25884
+ *
25885
+ * @returns A Promise of {@link Amity.ShareableLinkConfiguration} object
25886
+ *
25887
+ * @category Client API
25888
+ * @async
25889
+ */
25890
+ const getShareableLinkConfiguration = async () => {
25891
+ const client = getActiveClient();
25892
+ const { data } = await client.http.get(`/api/v3/network-settings/shareable-deep-links`);
25893
+ return data;
25894
+ };
25895
+
25875
25896
  /**
25876
25897
  * ```js
25877
25898
  * import { onChannelMarkerFetched } from '@amityco/ts-sdk'
@@ -26241,6 +26262,7 @@ var index$o = /*#__PURE__*/Object.freeze({
26241
26262
  enableUnreadCount: enableUnreadCount,
26242
26263
  setUploadedFileAccessType: setUploadedFileAccessType,
26243
26264
  fetchLinkPreview: fetchLinkPreview,
26265
+ getShareableLinkConfiguration: getShareableLinkConfiguration,
26244
26266
  onConnectionError: onConnectionError,
26245
26267
  onClientDisconnected: onClientDisconnected,
26246
26268
  onClientBanned: onClientBanned,
@@ -27944,15 +27966,18 @@ function isAmityClipPost(post) {
27944
27966
  }
27945
27967
 
27946
27968
  const postLinkedObject = (post) => {
27947
- return Object.assign(Object.assign({}, post), { childrenPosts: post.children
27969
+ return shallowClone(post, {
27970
+ childrenPosts: post.children
27948
27971
  .map(childPost => { var _a; return (_a = pullFromCache(['post', 'get', childPost])) === null || _a === void 0 ? void 0 : _a.data; })
27949
27972
  .filter(isNonNullable)
27950
- .map(postLinkedObject), analytics: {
27973
+ .map(postLinkedObject),
27974
+ analytics: {
27951
27975
  markAsViewed: () => {
27952
27976
  const analyticsEngineInstance = AnalyticsEngine$1.getInstance();
27953
27977
  analyticsEngineInstance.markPostAsViewed(post.postId);
27954
27978
  },
27955
- }, get latestComments() {
27979
+ },
27980
+ get latestComments() {
27956
27981
  if (!post.comments)
27957
27982
  return [];
27958
27983
  return (post.comments
@@ -28026,7 +28051,8 @@ const postLinkedObject = (post) => {
28026
28051
  return isAmityClipPost(post)
28027
28052
  ? (_b = pullFromCache(['file', 'get', (_a = post === null || post === void 0 ? void 0 : post.data) === null || _a === void 0 ? void 0 : _a.fileId])) === null || _b === void 0 ? void 0 : _b.data
28028
28053
  : undefined;
28029
- } });
28054
+ },
28055
+ });
28030
28056
  };
28031
28057
 
28032
28058
  const getCachedMarker = (message) => {
@@ -31021,7 +31047,7 @@ const addReaction = async (referenceType, referenceId, reactionName) => {
31021
31047
  ]);
31022
31048
  if (!model || ((_a = model.data.myReactions) === null || _a === void 0 ? void 0 : _a.includes(reactionName)))
31023
31049
  return true;
31024
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }) });
31050
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: model.data.reactionsCount + 1, myReactions: [...((_b = model.data.myReactions) !== null && _b !== void 0 ? _b : []), reactionName], reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: ((_c = model.data.reactions[reactionName]) !== null && _c !== void 0 ? _c : 0) + 1 }), updatedAt: new Date().toISOString() });
31025
31051
  if (referenceType === 'comment') {
31026
31052
  fireEvent('local.comment.addReaction', {
31027
31053
  comment: updatedModel,
@@ -31144,7 +31170,7 @@ const removeReaction = async (referenceType, referenceId, reactionName) => {
31144
31170
  ]);
31145
31171
  if (!model)
31146
31172
  return true;
31147
- const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }) });
31173
+ const updatedModel = Object.assign(Object.assign({}, model.data), { reactionsCount: Math.max(0, model.data.reactionsCount - 1), myReactions: ((_a = model.data.myReactions) !== null && _a !== void 0 ? _a : []).filter(item => item !== reactionName), reactions: Object.assign(Object.assign({}, model.data.reactions), { [reactionName]: Math.max(0, ((_b = model.data.reactions[reactionName]) !== null && _b !== void 0 ? _b : 0) - 1) }), updatedAt: new Date().toISOString() });
31148
31174
  if (referenceType === 'comment') {
31149
31175
  fireEvent('local.comment.removeReaction', {
31150
31176
  comment: updatedModel,
@@ -31258,6 +31284,26 @@ const prepareSemanticSearchPostPayload = (_a) => {
31258
31284
  return Object.assign(Object.assign({}, processedPostPayload), { polls });
31259
31285
  };
31260
31286
 
31287
+ const processDeleteChildPost = (payload) => {
31288
+ var _a;
31289
+ const post = payload.posts[0];
31290
+ if (!post.parentId)
31291
+ return;
31292
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
31293
+ if (!parentPost)
31294
+ return;
31295
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: parentPost.children.filter(childId => childId !== post.postId) }));
31296
+ };
31297
+ const processCreateChildPost = (payload) => {
31298
+ var _a;
31299
+ const post = payload.posts[0];
31300
+ if (!post.parentId)
31301
+ return;
31302
+ const parentPost = (_a = pullFromCache(['post', 'get', post.parentPostId])) === null || _a === void 0 ? void 0 : _a.data;
31303
+ if (!parentPost)
31304
+ return;
31305
+ pushToCache(['post', 'get', parentPost.postId], Object.assign(Object.assign({}, parentPost), { children: [...new Set([post.postId, ...parentPost.children])] }));
31306
+ };
31261
31307
  const createPostEventSubscriber = (event, callback) => {
31262
31308
  const client = getActiveClient();
31263
31309
  const filter = (payload) => {
@@ -31282,6 +31328,7 @@ const createPostEventSubscriber = (event, callback) => {
31282
31328
  }
31283
31329
  if (event === 'post.deleted') {
31284
31330
  const { postId, postedUserId } = payload.posts[0];
31331
+ processDeleteChildPost(payload);
31285
31332
  try {
31286
31333
  isInTombstone('post', postId);
31287
31334
  }
@@ -31308,6 +31355,8 @@ const createPostEventSubscriber = (event, callback) => {
31308
31355
  }
31309
31356
  queries === null || queries === void 0 ? void 0 : queries.map(({ key, data }) => upsertInCache(key, data, { cachedAt: -1 }));
31310
31357
  }
31358
+ if (event === 'post.created')
31359
+ processCreateChildPost(payload);
31311
31360
  callback(post.data);
31312
31361
  }
31313
31362
  };
@@ -31334,6 +31383,8 @@ const createLocalPostEventSubscriber = (event, callback) => {
31334
31383
  });
31335
31384
  }
31336
31385
  const post = pullFromCache(['post', 'get', payload.posts[0].postId]);
31386
+ if (event === 'local.post.deleted')
31387
+ processDeleteChildPost(payload);
31337
31388
  callback(post.data);
31338
31389
  }
31339
31390
  };
@@ -39109,6 +39160,9 @@ var index$b = /*#__PURE__*/Object.freeze({
39109
39160
  id: feed.query.global_feed
39110
39161
  */
39111
39162
  /**
39163
+ *
39164
+ * @deprecated This function will to be deprecated. Please use getGlobalFeed instead.
39165
+ *
39112
39166
  * ```js
39113
39167
  * import { queryGlobalFeed } from '@amityco/ts-sdk'
39114
39168
  * const posts = await queryGlobalFeed()
@@ -39191,1086 +39245,1023 @@ queryGlobalFeed.locally = (query) => {
39191
39245
  : undefined;
39192
39246
  };
39193
39247
 
39194
- /* begin_public_function
39195
- id: feed.query.custom_ranking_feed
39196
- */
39197
- /**
39198
- * ```js
39199
- * import { FeedRepository } from '@amityco/ts-sdk'
39200
- * const posts = await FeedRepository.getCustomRankingGlobalFeed()
39201
- * ```
39202
- *
39203
- * Queries a paginable list of {@link Amity.Post} objects
39204
- *
39205
- * @param query The query parameters
39206
- * @returns A page of {@link Amity.Post} objects
39207
- *
39208
- * @category Feed API
39209
- * @async
39210
- * */
39211
- const getCustomRankingGlobalFeed = async (query) => {
39212
- const client = getActiveClient();
39213
- client.log('feed/getCustomRankingGlobalFeed', query);
39214
- const _a = query !== null && query !== void 0 ? query : {}, { queryToken, limit } = _a, params = __rest(_a, ["queryToken", "limit"]);
39215
- const options = (() => {
39216
- if (queryToken)
39217
- return { token: queryToken };
39218
- return undefined;
39219
- })();
39220
- const { data: queryPayload } = await client.http.get(`/api/v5/me/global-feeds`, {
39221
- params: Object.assign(Object.assign({}, params), { limit: !queryToken ? limit : undefined, options }),
39222
- });
39223
- const { paging } = queryPayload, payload = __rest(queryPayload, ["paging"]);
39224
- const data = prepareMembershipPayload(payload, 'communityUsers');
39225
- const { posts } = data;
39226
- const cachedAt = client.cache && Date.now();
39227
- if (client.cache) {
39228
- ingestInCache(data);
39229
- const cacheKey = ['customGlobalFeed', 'query', Object.assign(Object.assign({}, params), { options })];
39230
- pushToCache(cacheKey, { posts: posts.map(getResolver('post')), paging });
39248
+ class CustomRankingGlobalFeedPaginationController extends PaginationController {
39249
+ async getRequest(queryParams, token) {
39250
+ const { limit } = queryParams, params = __rest(queryParams, ["limit"]);
39251
+ const options = token ? { token } : { limit };
39252
+ const { data: queryResponse } = await this.http.get(`/api/v5/me/global-feeds`, {
39253
+ params: Object.assign(Object.assign({}, params), { options }),
39254
+ });
39255
+ return queryResponse;
39231
39256
  }
39232
- return { data: posts.map(LinkedObject.post), cachedAt, paging };
39233
- };
39234
- /* end_public_function */
39235
- /**
39236
- * ```js
39237
- * import { FeedRepository } from '@amityco/ts-sdk'
39238
- * const posts = await FeedRepository.getCustomRankingGlobalFeed.locally()
39239
- * ```
39240
- *
39241
- * Queries a paginable list of {@link Amity.Post} objects from cache
39242
- *
39243
- * @param query The query parameters
39244
- * @returns A page of {@link Amity.Post} objects
39245
- *
39246
- * @category Feed API
39247
- * @async
39248
- * */
39249
- getCustomRankingGlobalFeed.locally = (query) => {
39250
- var _a, _b;
39251
- const client = getActiveClient();
39252
- client.log('post/getCustomRankingGlobalFeed.locally', query);
39253
- if (!client.cache)
39254
- return;
39255
- const params = __rest(query !== null && query !== void 0 ? query : {}, []);
39256
- const queryKey = ['customGlobalFeed', 'query', Object.assign({}, params)];
39257
- const { data, cachedAt } = (_a = pullFromCache(queryKey)) !== null && _a !== void 0 ? _a : {};
39258
- if (!(data === null || data === void 0 ? void 0 : data.posts.length))
39259
- return;
39260
- const posts = data.posts
39261
- .map(postId => pullFromCache(['post', 'get', postId]))
39262
- .filter(Boolean)
39263
- .map(({ data }) => data);
39264
- const { paging } = data;
39265
- return posts.length === ((_b = data === null || data === void 0 ? void 0 : data.posts) === null || _b === void 0 ? void 0 : _b.length)
39266
- ? { data: posts.map(LinkedObject.post), cachedAt, paging }
39267
- : undefined;
39268
- };
39257
+ }
39269
39258
 
39270
- var index$a = /*#__PURE__*/Object.freeze({
39271
- __proto__: null,
39272
- queryGlobalFeed: queryGlobalFeed,
39273
- getCustomRankingGlobalFeed: getCustomRankingGlobalFeed
39274
- });
39259
+ var EnumPostActions;
39260
+ (function (EnumPostActions) {
39261
+ EnumPostActions["OnPostCreated"] = "onPostCreated";
39262
+ EnumPostActions["OnPostUpdated"] = "onPostUpdated";
39263
+ EnumPostActions["OnPostDeleted"] = "onPostDeleted";
39264
+ EnumPostActions["OnPostFlagged"] = "onPostFlagged";
39265
+ EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
39266
+ EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
39267
+ EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
39268
+ EnumPostActions["OnPostApproved"] = "onPostApproved";
39269
+ EnumPostActions["OnPostDeclined"] = "onPostDeclined";
39270
+ })(EnumPostActions || (EnumPostActions = {}));
39271
+
39272
+ class CustomRankingGlobalFeedQueryStreamController extends QueryStreamController {
39273
+ constructor(query, cacheKey, notifyChange, preparePayload) {
39274
+ super(query, cacheKey);
39275
+ this.notifyChange = notifyChange;
39276
+ this.preparePayload = preparePayload;
39277
+ }
39278
+ async saveToMainDB(response) {
39279
+ const processedPayload = await this.preparePayload(response);
39280
+ const client = getActiveClient();
39281
+ const cachedAt = client.cache && Date.now();
39282
+ if (client.cache) {
39283
+ ingestInCache(processedPayload, { cachedAt });
39284
+ }
39285
+ }
39286
+ appendToQueryStream(response, direction, refresh = false) {
39287
+ var _a, _b;
39288
+ if (refresh) {
39289
+ pushToCache(this.cacheKey, {
39290
+ data: response.posts.map(getResolver('post')),
39291
+ });
39292
+ }
39293
+ else {
39294
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39295
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
39296
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
39297
+ }
39298
+ }
39299
+ reactor(action) {
39300
+ return (post) => {
39301
+ var _a;
39302
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
39303
+ if (!collection)
39304
+ return;
39305
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
39306
+ return;
39307
+ // Delete Action
39308
+ if (action === EnumPostActions.OnPostDeleted) {
39309
+ // Parent Post - Remove from collection
39310
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39311
+ }
39312
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
39313
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
39314
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
39315
+ if (!this.query.dataTypes.includes(post.dataType))
39316
+ return;
39317
+ }
39318
+ collection.data = [...new Set([post.postId, ...collection.data])];
39319
+ }
39320
+ if (action === EnumPostActions.OnPostDeclined) {
39321
+ collection.data = collection.data.filter(postId => postId !== post.postId);
39322
+ }
39323
+ pushToCache(this.cacheKey, collection);
39324
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
39325
+ };
39326
+ }
39327
+ subscribeRTE(createSubscriber) {
39328
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
39329
+ }
39330
+ }
39275
39331
 
39276
39332
  /* begin_public_function
39277
- id: post.get_by_ids
39333
+ id: comment.get_by_ids
39278
39334
  */
39279
39335
  /**
39280
39336
  * ```js
39281
- * import { getPostByIds } from '@amityco/ts-sdk'
39282
- * const { data: posts } = await getPostByIds(['foo', 'bar'])
39337
+ * import { CommentRepository } from '@amityco/ts-sdk'
39338
+ * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39283
39339
  * ```
39284
39340
  *
39285
- * Fetches a collection of {@link Amity.Post} objects
39341
+ * Fetches a collection of {@link Amity.Comment} objects
39286
39342
  *
39287
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39288
- * @returns the associated collection of {@link Amity.Post} objects
39343
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39344
+ * @returns the associated collection of {@link Amity.Comment} objects
39289
39345
  *
39290
- * @category Post API
39346
+ * @category Comment API
39291
39347
  * @async
39292
39348
  */
39293
- const getPostByIds = async (postIds) => {
39349
+ const getCommentByIds = async (commentIds) => {
39294
39350
  const client = getActiveClient();
39295
- client.log('post/getPostByIds', postIds);
39296
- const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
39297
- let payload;
39351
+ client.log('comment/getCommentByIds', commentIds);
39352
+ const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39353
+ let data;
39298
39354
  try {
39299
39355
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39300
- const response = await client.http.get(`/api/v3/posts/list`, {
39301
- params: { postIds: encodedPostIds },
39356
+ const response = await client.http.get(`/api/v3/comments/list`, {
39357
+ params: { commentIds: encodedCommentIds },
39302
39358
  });
39303
- payload = response.data;
39359
+ data = response.data;
39304
39360
  }
39305
39361
  catch (error) {
39306
- postIds.forEach(postId => {
39362
+ commentIds.forEach(commentId => {
39307
39363
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39308
- pushToTombstone('post', postId);
39364
+ pushToTombstone('comment', commentId);
39309
39365
  }
39310
39366
  });
39311
39367
  throw error;
39312
39368
  }
39313
- const data = prepareMembershipPayload(payload, 'communityUsers');
39314
39369
  const cachedAt = client.cache && Date.now();
39315
39370
  if (client.cache)
39316
39371
  ingestInCache(data, { cachedAt });
39317
39372
  return {
39318
- data: data.posts.map(LinkedObject.post),
39373
+ data: data.comments.map(comment => LinkedObject.comment(comment)),
39319
39374
  cachedAt,
39320
39375
  };
39321
39376
  };
39322
39377
  /* end_public_function */
39323
39378
  /**
39324
39379
  * ```js
39325
- * import { getPostByIds } from '@amityco/ts-sdk'
39326
- * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
39380
+ * import { getCommentByIds } from '@amityco/ts-sdk'
39381
+ * const comments = getCommentByIds.locally(['foo', 'bar'])
39327
39382
  * ```
39328
39383
  *
39329
- * Fetches a collection of {@link Amity.Post} objects from cache
39384
+ * Fetches a collection of {@link Amity.Comment} objects from cache
39330
39385
  *
39331
- * @param postIds the IDs of the {@link Amity.Post} to fetch
39332
- * @returns the associated collection of {@link Amity.Post} objects
39386
+ * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39387
+ * @returns the associated collection of {@link Amity.Comment} objects
39333
39388
  *
39334
- * @category Post API
39389
+ * @category Comment API
39335
39390
  */
39336
- getPostByIds.locally = (postIds) => {
39391
+ getCommentByIds.locally = (commentIds) => {
39337
39392
  var _a;
39338
39393
  const client = getActiveClient();
39339
- client.log('post/getPostByIds.locally', postIds);
39394
+ client.log('comment/getCommentByIds.locally', commentIds);
39340
39395
  if (!client.cache)
39341
39396
  return;
39342
- const cached = postIds
39343
- .map(postId => pullFromCache(['post', 'get', postId]))
39397
+ const cached = commentIds
39398
+ .map(commentId => pullFromCache(['comment', 'get', commentId]))
39344
39399
  .filter(Boolean);
39345
- const posts = cached.map(({ data }) => data);
39400
+ const comments = cached.map(({ data }) => data);
39346
39401
  const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39347
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
39402
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39348
39403
  return;
39349
39404
  return {
39350
- data: posts.map(LinkedObject.post),
39405
+ data: comments.map(comment => LinkedObject.comment(comment)),
39351
39406
  cachedAt: oldest.cachedAt,
39352
39407
  };
39353
39408
  };
39354
39409
 
39355
39410
  /* begin_public_function
39356
- 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
39411
+ id: comment.create
39357
39412
  */
39358
39413
  /**
39359
39414
  * ```js
39360
- * import { PostRepository } from '@amityco/ts-sdk'
39361
- * const created = await PostRepository.createPost({
39362
- * targetType: 'user',
39363
- * targetId: 'foobar',
39364
- * data: { text: 'hello world' }
39365
- * }))
39415
+ * import { CommentRepository } from '@amityco/ts-sdk'
39416
+ * const newComment = await CommentRepository.createComment(bundle)
39366
39417
  * ```
39367
39418
  *
39368
- * Creates an {@link Amity.Post}
39419
+ * Creates an {@link Amity.Comment}
39369
39420
  *
39370
- * @param bundle The data necessary to create a new {@link Amity.Post}
39371
- * @returns The newly created {@link Amity.Post}
39421
+ * @param bundle The data necessary to create a new {@link Amity.Comment}
39422
+ * @returns The newly created {@link Amity.Comment}
39372
39423
  *
39373
- * @category Post API
39424
+ * @category Comment API
39374
39425
  * @async
39375
39426
  */
39376
- const createPost = async (bundle) => {
39427
+ const createComment = async (bundle) => {
39428
+ var _a;
39377
39429
  const client = getActiveClient();
39378
- client.log('post/createPost', bundle);
39379
- if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
39380
- // eslint-disable-next-line no-param-reassign
39381
- delete bundle.dataType;
39382
- }
39383
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39384
- fireEvent('post.created', payload);
39385
- const data = preparePostPayload(payload);
39430
+ client.log('comment/createComment', bundle);
39431
+ const { data } = await client.http.post('/api/v3/comments', bundle);
39432
+ const { comments } = data;
39433
+ // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39434
+ if (comments.length === 0)
39435
+ throw new Error('Comment not created');
39386
39436
  const cachedAt = client.cache && Date.now();
39387
39437
  if (client.cache)
39388
39438
  ingestInCache(data, { cachedAt });
39389
- const { posts } = data;
39439
+ if (['post', 'content'].includes(bundle.referenceType)) {
39440
+ const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39441
+ if (post) {
39442
+ post.commentsCount += 1;
39443
+ fireEvent('local.post.updated', {
39444
+ posts: [post],
39445
+ categories: [],
39446
+ comments: [],
39447
+ communities: [],
39448
+ communityUsers: data.communityUsers,
39449
+ feeds: [],
39450
+ files: data.files,
39451
+ postChildren: [],
39452
+ users: data.users,
39453
+ videoStreamings: [],
39454
+ });
39455
+ }
39456
+ }
39457
+ else if (bundle.referenceType === 'story') {
39458
+ const storyIndex = pullFromCache([
39459
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39460
+ bundle.referenceId,
39461
+ ]);
39462
+ if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39463
+ const cacheStory = pullFromCache([
39464
+ "story" /* STORY_KEY_CACHE.STORY */,
39465
+ 'get',
39466
+ storyIndex.data,
39467
+ ]);
39468
+ if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39469
+ fireEvent('story.updated', {
39470
+ stories: [
39471
+ Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39472
+ ],
39473
+ categories: [],
39474
+ comments,
39475
+ communities: [],
39476
+ communityUsers: data.communityUsers,
39477
+ files: data.files,
39478
+ users: data.users,
39479
+ });
39480
+ }
39481
+ }
39482
+ }
39483
+ fireEvent('local.comment.created', data);
39390
39484
  return {
39391
- data: LinkedObject.post(posts[0]),
39485
+ data: LinkedObject.comment(comments[0]),
39392
39486
  cachedAt,
39393
39487
  };
39394
39488
  };
39395
39489
  /* end_public_function */
39396
39490
 
39397
39491
  /* begin_public_function
39398
- id: post.edit, post.edit.custom_post
39492
+ id: comment.update_comment
39399
39493
  */
39400
39494
  /**
39401
39495
  * ```js
39402
- * import { PostRepository } from '@amityco/ts-sdk'
39403
- * const updated = await PostRepository.editPost(postId, {
39496
+ * import { CommentRepository } from '@amityco/ts-sdk'
39497
+ * const updated = await CommentRepository.updateComment(commentId, {
39404
39498
  * data: { text: 'hello world' }
39405
39499
  * })
39406
39500
  * ```
39407
39501
  *
39408
- * Updates an {@link Amity.Post}
39502
+ * Updates an {@link Amity.Comment}
39409
39503
  *
39410
- * @param postId The ID of the {@link Amity.Post} to edit
39504
+ * @param commentId The ID of the {@link Amity.Comment} to edit
39411
39505
  * @param patch The patch data to apply
39412
- * @returns the updated {@link Amity.Post} object
39506
+ * @returns the updated {@link Amity.Comment} object
39413
39507
  *
39414
- * @category Post API
39508
+ * @category Comment API
39415
39509
  * @async
39416
39510
  */
39417
- const editPost = async (postId, patch) => {
39511
+ const updateComment = async (commentId, patch) => {
39418
39512
  const client = getActiveClient();
39419
- client.log('user/editPost', patch);
39420
- const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
39421
- const data = prepareMembershipPayload(payload, 'communityUsers');
39513
+ client.log('user/updateComment', patch);
39514
+ const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39422
39515
  const cachedAt = client.cache && Date.now();
39423
39516
  if (client.cache)
39424
39517
  ingestInCache(data, { cachedAt });
39425
- fireEvent('local.post.updated', data);
39426
- const { posts } = data;
39518
+ fireEvent('comment.updated', data);
39519
+ const { comments } = data;
39427
39520
  return {
39428
- data: LinkedObject.post(posts.find(post => post.postId === postId)),
39521
+ data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39429
39522
  cachedAt,
39430
39523
  };
39431
39524
  };
39432
39525
  /* end_public_function */
39433
39526
 
39527
+ // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39528
+ const applyMissingField = (rawData, isCreated = false) => {
39529
+ const { storyId, referenceId } = rawData;
39530
+ if (!isCreated) {
39531
+ if (referenceId)
39532
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39533
+ }
39534
+ return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39535
+ };
39536
+ const convertRawStoryToInternal = (data, isCreated = false) => {
39537
+ const { stories } = data;
39538
+ const storiesData = stories.map(story => applyMissingField(story, isCreated));
39539
+ return Object.assign(Object.assign({}, data), { stories: storiesData });
39540
+ };
39541
+
39542
+ const getStoryByStoryId$1 = async (storyId) => {
39543
+ const client = getActiveClient();
39544
+ client.log('story/getStoryByStoryId', storyId);
39545
+ // Get story referenceId from cache
39546
+ const cacheReferenceId = pullFromCache([
39547
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39548
+ storyId,
39549
+ ]);
39550
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39551
+ const { data: referenceId } = cacheReferenceId;
39552
+ isInTombstone('story', referenceId);
39553
+ }
39554
+ let data;
39555
+ try {
39556
+ const response = await client.http.get(`/api/v4/stories/${storyId}`);
39557
+ data = convertRawStoryToInternal(response.data);
39558
+ }
39559
+ catch (error) {
39560
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39561
+ pushToTombstone('story', storyId);
39562
+ }
39563
+ throw error;
39564
+ }
39565
+ const cachedAt = client.cache && Date.now();
39566
+ if (client.cache) {
39567
+ ingestInCache(data, { cachedAt });
39568
+ }
39569
+ return {
39570
+ data: data.stories[0],
39571
+ cachedAt,
39572
+ };
39573
+ };
39574
+ getStoryByStoryId$1.locally = (storyId) => {
39575
+ const client = getActiveClient();
39576
+ client.log('story/getStorybyStoryId', storyId);
39577
+ // Get story referenceId from cache
39578
+ const cacheReferenceId = pullFromCache([
39579
+ "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39580
+ storyId,
39581
+ ]);
39582
+ if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39583
+ const { data: referenceId } = cacheReferenceId;
39584
+ isInTombstone('story', referenceId);
39585
+ }
39586
+ const cachedAt = client.cache && Date.now();
39587
+ const storyCache = pullFromCache(['story', 'get', storyId]);
39588
+ if (!storyCache)
39589
+ return;
39590
+ return {
39591
+ data: storyCache.data,
39592
+ cachedAt,
39593
+ };
39594
+ };
39595
+
39596
+ /* begin_public_function
39597
+ id: comment.soft_delete, comment.hard_delete
39598
+ */
39434
39599
  /**
39435
39600
  * ```js
39436
- * import { deletePost } from '@amityco/ts-sdk'
39437
- * const success = await deletePost('foobar')
39601
+ * import { CommentRepository } from '@amityco/ts-sdk'
39602
+ * const success = await CommentRepository.deleteComment('foobar')
39438
39603
  * ```
39439
39604
  *
39440
- * Deletes a {@link Amity.Post}
39605
+ * Deletes a {@link Amity.Comment}
39441
39606
  *
39442
- * @param postId The {@link Amity.Post} ID to delete
39443
- * @return A success boolean if the {@link Amity.Post} was deleted
39607
+ * @param commentId The {@link Amity.Comment} ID to delete
39608
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39444
39609
  *
39445
- * @private
39610
+ * @category Comment API
39446
39611
  * @async
39447
39612
  */
39448
- const deletePost = async (postId, permanent = false) => {
39613
+ const deleteComment = async (commentId, permanent = false) => {
39449
39614
  var _a;
39450
39615
  const client = getActiveClient();
39451
- const post = await getPost$2(postId);
39452
- await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
39616
+ const comment = await getComment$2(commentId);
39617
+ // API-FIX: This endpoint has not been implemented yet.
39618
+ await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
39453
39619
  params: {
39454
- postId,
39620
+ commentId,
39455
39621
  permanent,
39456
39622
  },
39457
39623
  });
39458
- // there is currently a limitation which doesn't allow us to fire event to tell that community
39459
- // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
39460
- // and so we cannot refetch the community or advertise on events. hopefully this should be solved
39461
- // later when realtime events covers that for us.
39462
- if (post.data.targetType === 'community') {
39463
- const community = await getCommunity$1(post.data.targetId);
39464
- const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
39465
- const communityUsers = communityUsersCache
39466
- .filter(({ key }) => {
39467
- // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
39468
- if (key[0] !== 'communityUsers')
39469
- return false;
39470
- if (key[1] !== 'get')
39471
- return false;
39472
- if (typeof key[2] === 'string')
39473
- return key[2].includes(community.data.communityId);
39474
- return false;
39475
- })
39476
- .map(({ data }) => data);
39477
- fireEvent('community.updated', {
39478
- communities: [community.data],
39624
+ // to support hard deletion
39625
+ const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
39626
+ if (permanent) {
39627
+ scheduleTask(() => pushToTombstone('comment', commentId));
39628
+ }
39629
+ else {
39630
+ upsertInCache(['comment', 'get', commentId], { isDeleted: true });
39631
+ }
39632
+ if (comment.data.referenceType === 'story') {
39633
+ const story = await getStoryByStoryId$1(comment.data.referenceId);
39634
+ fireEvent('local.story.updated', {
39635
+ stories: [story.data],
39479
39636
  categories: [],
39480
- communityUsers,
39481
- feeds: [],
39637
+ comments: [],
39638
+ communities: [],
39639
+ communityUsers: [],
39482
39640
  files: [],
39483
39641
  users: [],
39484
39642
  });
39485
39643
  }
39486
- // to support hard deletion
39487
- const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
39488
- if (permanent) {
39489
- setTimeout(() => {
39490
- pushToTombstone('post', postId);
39491
- }, 0);
39492
- }
39493
39644
  else {
39494
- upsertInCache(['post', 'get', postId], { isDeleted: true });
39645
+ const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39646
+ if (post) {
39647
+ let removeCount;
39648
+ if (!deleted.parentId) {
39649
+ // NOTE: delete the parent comment will remove all children comments
39650
+ removeCount = deleted.childrenNumber + 1;
39651
+ }
39652
+ else
39653
+ removeCount = 1;
39654
+ post.commentsCount -= removeCount;
39655
+ fireEvent('local.post.updated', {
39656
+ posts: [post],
39657
+ categories: [],
39658
+ comments: [],
39659
+ communities: [],
39660
+ communityUsers: [],
39661
+ feeds: [],
39662
+ files: [],
39663
+ postChildren: [],
39664
+ users: [],
39665
+ videoStreamings: [],
39666
+ });
39667
+ }
39495
39668
  }
39496
- fireEvent('local.post.deleted', {
39497
- posts: [deleted],
39498
- categories: [],
39499
- comments: [],
39500
- communities: [],
39501
- communityUsers: [],
39502
- feeds: [],
39669
+ fireEvent('local.comment.deleted', {
39670
+ comments: [deleted],
39671
+ commentChildren: [],
39503
39672
  files: [],
39504
- postChildren: [],
39505
39673
  users: [],
39506
- videoStreamings: [],
39674
+ communityUsers: [],
39507
39675
  });
39508
- return LinkedObject.post(deleted);
39676
+ return deleted;
39509
39677
  };
39678
+ /* end_public_function */
39510
39679
 
39511
39680
  /* begin_public_function
39512
- id: post.soft_delete
39513
- */
39514
- /**
39515
- * ```js
39516
- * import { PostRepository } from '@amityco/ts-sdk'
39517
- * const success = await PostRepository.softDeletePost('foobar')
39518
- * ```
39519
- *
39520
- * Soft deletes a {@link Amity.Post}
39521
- *
39522
- * @param postId The {@link Amity.Post} ID to soft delete
39523
- * @return A success boolean if the {@link Amity.Post} was deleted
39524
- *
39525
- * @category Post API
39526
- * @async
39527
- */
39528
- const softDeletePost = async (postId) => {
39529
- const client = getActiveClient();
39530
- client.log('post/softDeletePost', postId);
39531
- const softDeleted = await deletePost(postId, false);
39532
- return LinkedObject.post(softDeleted);
39533
- };
39534
- /* end_public_function */
39535
-
39536
- /* begin_public_function
39537
- id: post.hard_delete
39538
- */
39539
- /**
39540
- * ```js
39541
- * import { hardDeletePost } from '@amityco/ts-sdk'
39542
- * const success = await hardDeletePost('foobar')
39543
- * ```
39544
- *
39545
- * Hard deletes a {@link Amity.Post}
39546
- *
39547
- * @param postId The {@link Amity.Post} ID to be hard delete
39548
- * @return A success boolean if the {@link Amity.Post} was deleted
39549
- *
39550
- * @category Post API
39551
- * @async
39552
- */
39553
- const hardDeletePost = async (postId) => {
39554
- const client = getActiveClient();
39555
- client.log('post/hardDeletePost', postId);
39556
- const hardDeleted = await deletePost(postId, true);
39557
- return LinkedObject.post(hardDeleted);
39558
- };
39559
- /* end_public_function */
39560
-
39561
- /* begin_public_function
39562
- id: post.approve
39681
+ id: comment.soft_delete
39563
39682
  */
39564
39683
  /**
39565
39684
  * ```js
39566
- * import { approvePost } from '@amityco/ts-sdk'
39567
- *
39568
- * const { data: post } = await approvePost('postId')
39685
+ * import { CommentRepository } from '@amityco/ts-sdk'
39686
+ * const success = await CommentRepository.softDeleteComment('foobar')
39569
39687
  * ```
39570
39688
  *
39571
- * Approves a {@link Amity.Post}
39689
+ * Deletes a {@link Amity.Comment}
39572
39690
  *
39573
- * @param postId The {@link Amity.Post} ID to be approved
39574
- * @return A {@link Amity.Post} that was approved
39691
+ * @param commentId The {@link Amity.Comment} ID to delete
39692
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39575
39693
  *
39576
- * @category Post API
39694
+ * @category Comment API
39577
39695
  * @async
39578
39696
  */
39579
- const approvePost = async (postId) => {
39697
+ const softDeleteComment = async (commentId) => {
39580
39698
  const client = getActiveClient();
39581
- client.log('post/approvePost', postId);
39582
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
39583
- fireEvent('post.approved', payload);
39584
- // fire virtual event for community update
39585
- if (payload.posts[0].targetType === 'community') {
39586
- fireEvent('community.updated', payload);
39587
- }
39588
- const data = prepareMembershipPayload(payload, 'communityUsers');
39589
- const cachedAt = client.cache && Date.now();
39590
- if (client.cache)
39591
- ingestInCache(data, { cachedAt });
39592
- return {
39593
- data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
39594
- cachedAt,
39595
- };
39699
+ client.log('comment/softDeleteComment', commentId);
39700
+ const softDeleted = deleteComment(commentId);
39701
+ return softDeleted;
39596
39702
  };
39597
39703
  /* end_public_function */
39598
39704
 
39599
39705
  /* begin_public_function
39600
- id: post.decline
39706
+ id: comment.hard_delete
39601
39707
  */
39602
39708
  /**
39603
39709
  * ```js
39604
- * import { declinePost } from '@amityco/ts-sdk'
39605
- *
39606
- * const {data: post} = await declinePost('postId')
39710
+ * import { CommentRepository } from '@amityco/ts-sdk'
39711
+ * const success = await CommentRepository.hardDeleteComment('foobar')
39607
39712
  * ```
39608
39713
  *
39609
- * Declines a {@link Amity.Post}
39714
+ * Deletes a {@link Amity.Comment}
39610
39715
  *
39611
- * @param postId The {@link Amity.Post} ID to be declined
39612
- * @return A {@link Amity.Post} that was declined
39716
+ * @param commentId The {@link Amity.Comment} ID to delete
39717
+ * @return A success boolean if the {@link Amity.Comment} was deleted
39613
39718
  *
39614
- * @category Post API
39719
+ * @category Comment API
39615
39720
  * @async
39616
39721
  */
39617
- const declinePost = async (postId) => {
39722
+ const hardDeleteComment = async (commentId) => {
39618
39723
  const client = getActiveClient();
39619
- client.log('post/declinePost', postId);
39620
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
39621
- // fire virtual event
39622
- if (payload.posts[0].targetType === 'community') {
39623
- fireEvent('community.updated', payload);
39624
- }
39625
- fireEvent('post.declined', payload);
39626
- const data = prepareMembershipPayload(payload, 'communityUsers');
39627
- const cachedAt = client.cache && Date.now();
39628
- if (client.cache)
39629
- ingestInCache(data, { cachedAt });
39630
- return {
39631
- data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
39632
- cachedAt,
39633
- };
39724
+ client.log('comment/hardDeleteComment', commentId);
39725
+ const hardDeleted = deleteComment(commentId, true);
39726
+ return hardDeleted;
39634
39727
  };
39635
39728
  /* end_public_function */
39636
39729
 
39637
39730
  /* begin_public_function
39638
- id: post.flag
39731
+ id: comment.flag
39639
39732
  */
39640
39733
  /**
39641
39734
  * ```js
39642
- * import { PostRepository } from '@amityco/ts-sdk'
39643
- * const flagged = await PostRepository.flagPost(postId, reason)
39735
+ * import { CommentRepository } from '@amityco/ts-sdk'
39736
+ * const flagged = await CommentRepository.flagComment(commentId, reason)
39644
39737
  * ```
39645
39738
  *
39646
- * @param postId of the post to flag
39647
- * @param reason the reason to flag the post
39648
- * @returns a boolean
39739
+ * @param commentId The ID of the comment to flag
39740
+ * @param reason the reason to flag the comment
39741
+ * @returns the created report result
39649
39742
  *
39650
- * @category Post API
39743
+ * @category Comment API
39651
39744
  * @async
39652
39745
  * */
39653
- const flagPost = async (postId, reason) => {
39746
+ const flagComment = async (commentId, reason) => {
39654
39747
  const client = getActiveClient();
39655
- client.log('post/flagPost', postId);
39748
+ client.log('comment/flagComment', commentId);
39656
39749
  const isPredefinedReason = reason &&
39657
39750
  Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
39658
39751
  const body = {
39659
39752
  reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
39660
39753
  detail: reason && !isPredefinedReason ? reason : '',
39661
39754
  };
39662
- const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
39755
+ const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
39663
39756
  if (client.cache) {
39664
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39757
+ ingestInCache(payload);
39665
39758
  }
39666
- fireEvent('post.flagged', payload);
39759
+ fireEvent('comment.flagged', payload);
39667
39760
  return !!payload;
39668
39761
  };
39669
39762
  /* end_public_function */
39670
39763
 
39671
39764
  /* begin_public_function
39672
- id: post.unflag
39765
+ id: comment.unflag
39673
39766
  */
39674
39767
  /**
39675
39768
  * ```js
39676
- * import { PostRepository } from '@amityco/ts-sdk'
39677
- * const unflagged = await PostRepository.unflagPost(postId)
39769
+ * import { CommentRepository } from '@amityco/ts-sdk'
39770
+ * const unflagged = await CommentRepository.unflagComment('commentId')
39678
39771
  * ```
39679
39772
  *
39680
- * @param postId of the post to unflag
39681
- * @returns the unflag post result
39773
+ * @param commentId The ID of comment to unflag
39774
+ * @returns the unflagged result
39682
39775
  *
39683
- * @category Post API
39776
+ * @category Comment API
39684
39777
  * @async
39685
39778
  * */
39686
- const unflagPost = async (postId) => {
39779
+ const unflagComment = async (commentId) => {
39687
39780
  const client = getActiveClient();
39688
- client.log('post/unflagPost', postId);
39689
- const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
39781
+ client.log('comment/unflagComment', commentId);
39782
+ const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
39690
39783
  if (client.cache) {
39691
- ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
39784
+ ingestInCache(payload);
39692
39785
  }
39693
- fireEvent('post.unflagged', payload);
39786
+ fireEvent('comment.unflagged', payload);
39694
39787
  return !!payload;
39695
39788
  };
39696
39789
  /* end_public_function */
39697
39790
 
39698
39791
  /* begin_public_function
39699
- id: post.check_flag_by_me
39792
+ id: comment.check_flag_by_me
39700
39793
  */
39701
39794
  /**
39702
39795
  * ```js
39703
- * import { PostRepository } from '@amityco/ts-sdk'
39704
- * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
39796
+ * import { CommentRepository } from '@amityco/ts-sdk'
39797
+ * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
39705
39798
  * ```
39706
39799
  *
39707
- * @param postId of the post to check if flagged by current user
39708
- * @returns `true` if the post is flagged by me, `false` if doesn't.
39800
+ * @param commentId The ID of the comment to check if flagged by current user
39801
+ * @returns `true` if the comment is flagged by me, `false` if doesn't.
39709
39802
  *
39710
- * @category Post API
39803
+ * @category Comment API
39711
39804
  * @async
39712
39805
  * */
39713
- const isPostFlaggedByMe = async (postId) => {
39806
+ const isCommentFlaggedByMe = async (commentId) => {
39714
39807
  const client = getActiveClient();
39715
- client.log('post/isPostFlaggedByMe', postId);
39716
- const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
39808
+ client.log('comment/isCommentFlaggedByMe', commentId);
39809
+ const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
39717
39810
  return result;
39718
39811
  };
39719
39812
  /* end_public_function */
39720
39813
 
39721
- /* begin_public_function
39722
- id: post.create.clip_post
39723
- */
39724
- /**
39725
- * ```js
39726
- * import { PostRepository } from '@amityco/ts-sdk'
39727
- * const created = await PostRepository.createClipPost({
39728
- * targetType: 'user',
39729
- * targetId: 'foobar',
39730
- * dataType: 'clip',
39731
- * data: { text: 'hello world' },
39732
- * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
39733
- * }))
39734
- * ```
39735
- *
39736
- * Creates an {@link Amity.Post}
39737
- *
39738
- * @param bundle The data necessary to create a new {@link Amity.Post}
39739
- * @returns The newly created {@link Amity.Post}
39740
- *
39741
- * @category Post API
39742
- * @async
39743
- */
39744
- const createClipPost = async (bundle) => {
39745
- const client = getActiveClient();
39746
- client.log('post/createPost', bundle);
39747
- const { data: payload } = await client.http.post('/api/v4/posts', bundle);
39748
- fireEvent('post.created', payload);
39749
- const data = prepareMembershipPayload(payload, 'communityUsers');
39750
- const cachedAt = client.cache && Date.now();
39751
- if (client.cache)
39752
- ingestInCache(data, { cachedAt });
39753
- const { posts } = data;
39754
- return {
39755
- data: LinkedObject.post(posts[0]),
39756
- cachedAt,
39757
- };
39758
- };
39759
- /* end_public_function */
39760
-
39761
- /* begin_public_function
39762
- id: comment.get_by_ids
39763
- */
39764
- /**
39765
- * ```js
39766
- * import { CommentRepository } from '@amityco/ts-sdk'
39767
- * const comments = await CommentRepository.getCommentByIds(['foo', 'bar'])
39768
- * ```
39769
- *
39770
- * Fetches a collection of {@link Amity.Comment} objects
39771
- *
39772
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39773
- * @returns the associated collection of {@link Amity.Comment} objects
39774
- *
39775
- * @category Comment API
39776
- * @async
39777
- */
39778
- const getCommentByIds = async (commentIds) => {
39814
+ const getComment$1 = async (commentId) => {
39779
39815
  const client = getActiveClient();
39780
- client.log('comment/getCommentByIds', commentIds);
39781
- const encodedCommentIds = commentIds.map(commentId => encodeURIComponent(commentId));
39816
+ client.log('comment/getComment', commentId);
39817
+ isInTombstone('comment', commentId);
39782
39818
  let data;
39783
39819
  try {
39784
39820
  // API-FIX: endpoint should not be /list, parameters should be querystring.
39785
- const response = await client.http.get(`/api/v3/comments/list`, {
39786
- params: { commentIds: encodedCommentIds },
39787
- });
39821
+ const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
39788
39822
  data = response.data;
39789
39823
  }
39790
39824
  catch (error) {
39791
- commentIds.forEach(commentId => {
39792
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39793
- pushToTombstone('comment', commentId);
39794
- }
39795
- });
39825
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39826
+ pushToTombstone('comment', commentId);
39827
+ }
39796
39828
  throw error;
39797
39829
  }
39798
39830
  const cachedAt = client.cache && Date.now();
39799
39831
  if (client.cache)
39800
39832
  ingestInCache(data, { cachedAt });
39833
+ const { comments } = data;
39801
39834
  return {
39802
- data: data.comments.map(comment => LinkedObject.comment(comment)),
39835
+ data: comments.find(comment => comment.commentId === commentId),
39803
39836
  cachedAt,
39804
39837
  };
39805
39838
  };
39806
- /* end_public_function */
39807
- /**
39808
- * ```js
39809
- * import { getCommentByIds } from '@amityco/ts-sdk'
39810
- * const comments = getCommentByIds.locally(['foo', 'bar'])
39811
- * ```
39812
- *
39813
- * Fetches a collection of {@link Amity.Comment} objects from cache
39814
- *
39815
- * @param commentIds the IDs of the {@link Amity.Comment} to fetch
39816
- * @returns the associated collection of {@link Amity.Comment} objects
39817
- *
39818
- * @category Comment API
39819
- */
39820
- getCommentByIds.locally = (commentIds) => {
39821
- var _a;
39839
+ getComment$1.locally = (commentId) => {
39822
39840
  const client = getActiveClient();
39823
- client.log('comment/getCommentByIds.locally', commentIds);
39841
+ client.log('comment/getComment.locally', commentId);
39824
39842
  if (!client.cache)
39825
39843
  return;
39826
- const cached = commentIds
39827
- .map(commentId => pullFromCache(['comment', 'get', commentId]))
39828
- .filter(Boolean);
39829
- const comments = cached.map(({ data }) => data);
39830
- const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
39831
- if ((cached === null || cached === void 0 ? void 0 : cached.length) < commentIds.length)
39844
+ const cached = pullFromCache(['comment', 'get', commentId]);
39845
+ if (!cached)
39832
39846
  return;
39833
39847
  return {
39834
- data: comments.map(comment => LinkedObject.comment(comment)),
39835
- cachedAt: oldest.cachedAt,
39848
+ data: cached.data,
39849
+ cachedAt: cached.cachedAt,
39836
39850
  };
39837
39851
  };
39838
39852
 
39839
- /* begin_public_function
39840
- id: comment.create
39841
- */
39842
39853
  /**
39843
39854
  * ```js
39844
- * import { CommentRepository } from '@amityco/ts-sdk'
39845
- * const newComment = await CommentRepository.createComment(bundle)
39855
+ * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
39856
+ * const dispose = onCommentDeleteLocal(comment => {
39857
+ * // ...
39858
+ * })
39846
39859
  * ```
39847
39860
  *
39848
- * Creates an {@link Amity.Comment}
39861
+ * Fired when a {@link Amity.InternalComment} has been deleted
39849
39862
  *
39850
- * @param bundle The data necessary to create a new {@link Amity.Comment}
39851
- * @returns The newly created {@link Amity.Comment}
39863
+ * @param callback The function to call when the event was fired
39864
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39852
39865
  *
39853
- * @category Comment API
39854
- * @async
39866
+ * @category Comment Events
39855
39867
  */
39856
- const createComment = async (bundle) => {
39857
- var _a;
39868
+ const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
39869
+
39870
+ /**
39871
+ * ```js
39872
+ * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
39873
+ * const dispose = onLocalCommentReactionAdded(comment => {
39874
+ * // ...
39875
+ * })
39876
+ * ```
39877
+ *
39878
+ * Fired when a {@link Amity.InternalComment} has been reacted
39879
+ *
39880
+ * @param callback The function to call when the event was fired
39881
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39882
+ *
39883
+ * @category Comment Events
39884
+ */
39885
+ const onLocalCommentReactionAdded = (callback) => {
39858
39886
  const client = getActiveClient();
39859
- client.log('comment/createComment', bundle);
39860
- const { data } = await client.http.post('/api/v3/comments', bundle);
39861
- const { comments } = data;
39862
- // BE always returns an array of comments If it got record 0 from BE it might have a problem on creation logic
39863
- if (comments.length === 0)
39864
- throw new Error('Comment not created');
39865
- const cachedAt = client.cache && Date.now();
39866
- if (client.cache)
39867
- ingestInCache(data, { cachedAt });
39868
- if (['post', 'content'].includes(bundle.referenceType)) {
39869
- const post = (_a = pullFromCache(['post', 'get', bundle.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
39870
- if (post) {
39871
- post.commentsCount += 1;
39872
- fireEvent('local.post.updated', {
39873
- posts: [post],
39874
- categories: [],
39875
- comments: [],
39876
- communities: [],
39877
- communityUsers: data.communityUsers,
39878
- feeds: [],
39879
- files: data.files,
39880
- postChildren: [],
39881
- users: data.users,
39882
- videoStreamings: [],
39883
- });
39887
+ const filter = ({ comment }) => {
39888
+ if (!client.cache) {
39889
+ callback(comment);
39884
39890
  }
39885
- }
39886
- else if (bundle.referenceType === 'story') {
39887
- const storyIndex = pullFromCache([
39888
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39889
- bundle.referenceId,
39890
- ]);
39891
- if (storyIndex === null || storyIndex === void 0 ? void 0 : storyIndex.data) {
39892
- const cacheStory = pullFromCache([
39893
- "story" /* STORY_KEY_CACHE.STORY */,
39894
- 'get',
39895
- storyIndex.data,
39896
- ]);
39897
- if (cacheStory === null || cacheStory === void 0 ? void 0 : cacheStory.data) {
39898
- fireEvent('story.updated', {
39899
- stories: [
39900
- Object.assign(Object.assign({}, cacheStory.data), { commentsCount: cacheStory.data.commentsCount + 1, comments: [...new Set([...cacheStory.data.comments, comments[0].commentId])] }),
39901
- ],
39902
- categories: [],
39903
- comments,
39904
- communities: [],
39905
- communityUsers: data.communityUsers,
39906
- files: data.files,
39907
- users: data.users,
39908
- });
39909
- }
39891
+ else {
39892
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39893
+ callback(commentLinkedObject(comment));
39910
39894
  }
39911
- }
39912
- fireEvent('local.comment.created', data);
39913
- return {
39914
- data: LinkedObject.comment(comments[0]),
39915
- cachedAt,
39916
39895
  };
39896
+ return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
39917
39897
  };
39918
- /* end_public_function */
39919
39898
 
39920
- /* begin_public_function
39921
- id: comment.update_comment
39922
- */
39923
39899
  /**
39924
39900
  * ```js
39925
- * import { CommentRepository } from '@amityco/ts-sdk'
39926
- * const updated = await CommentRepository.updateComment(commentId, {
39927
- * data: { text: 'hello world' }
39901
+ * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
39902
+ * const dispose = onLocalCommentReactionRemoved(comment => {
39903
+ * // ...
39928
39904
  * })
39929
39905
  * ```
39930
39906
  *
39931
- * Updates an {@link Amity.Comment}
39907
+ * Fired when a {@link Amity.InternalComment} has been reacted
39932
39908
  *
39933
- * @param commentId The ID of the {@link Amity.Comment} to edit
39934
- * @param patch The patch data to apply
39935
- * @returns the updated {@link Amity.Comment} object
39909
+ * @param callback The function to call when the event was fired
39910
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
39936
39911
  *
39937
- * @category Comment API
39938
- * @async
39912
+ * @category Comment Events
39939
39913
  */
39940
- const updateComment = async (commentId, patch) => {
39941
- const client = getActiveClient();
39942
- client.log('user/updateComment', patch);
39943
- const { data } = await client.http.put(`/api/v3/comments/${encodeURIComponent(commentId)}`, patch);
39944
- const cachedAt = client.cache && Date.now();
39945
- if (client.cache)
39946
- ingestInCache(data, { cachedAt });
39947
- fireEvent('comment.updated', data);
39948
- const { comments } = data;
39949
- return {
39950
- data: LinkedObject.comment(comments.find(comment => comment.commentId === commentId)),
39951
- cachedAt,
39952
- };
39953
- };
39954
- /* end_public_function */
39955
-
39956
- // Due to we have optimistic logic, we will use referenceId as a id in SDK instead of storyId
39957
- const applyMissingField = (rawData, isCreated = false) => {
39958
- const { storyId, referenceId } = rawData;
39959
- if (!isCreated) {
39960
- if (referenceId)
39961
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */ });
39962
- }
39963
- return Object.assign(Object.assign({}, rawData), { syncState: "synced" /* Amity.SyncState.Synced */, referenceId: storyId });
39964
- };
39965
- const convertRawStoryToInternal = (data, isCreated = false) => {
39966
- const { stories } = data;
39967
- const storiesData = stories.map(story => applyMissingField(story, isCreated));
39968
- return Object.assign(Object.assign({}, data), { stories: storiesData });
39969
- };
39970
-
39971
- const getStoryByStoryId$1 = async (storyId) => {
39914
+ const onLocalCommentReactionRemoved = (callback) => {
39972
39915
  const client = getActiveClient();
39973
- client.log('story/getStoryByStoryId', storyId);
39974
- // Get story referenceId from cache
39975
- const cacheReferenceId = pullFromCache([
39976
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
39977
- storyId,
39978
- ]);
39979
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
39980
- const { data: referenceId } = cacheReferenceId;
39981
- isInTombstone('story', referenceId);
39982
- }
39983
- let data;
39984
- try {
39985
- const response = await client.http.get(`/api/v4/stories/${storyId}`);
39986
- data = convertRawStoryToInternal(response.data);
39987
- }
39988
- catch (error) {
39989
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
39990
- pushToTombstone('story', storyId);
39916
+ const filter = ({ comment }) => {
39917
+ if (!client.cache) {
39918
+ callback(comment);
39919
+ }
39920
+ else {
39921
+ upsertInCache(['comment', 'get', comment.commentId], comment);
39922
+ callback(commentLinkedObject(comment));
39991
39923
  }
39992
- throw error;
39993
- }
39994
- const cachedAt = client.cache && Date.now();
39995
- if (client.cache) {
39996
- ingestInCache(data, { cachedAt });
39997
- }
39998
- return {
39999
- data: data.stories[0],
40000
- cachedAt,
40001
- };
40002
- };
40003
- getStoryByStoryId$1.locally = (storyId) => {
40004
- const client = getActiveClient();
40005
- client.log('story/getStorybyStoryId', storyId);
40006
- // Get story referenceId from cache
40007
- const cacheReferenceId = pullFromCache([
40008
- "story-reference" /* STORY_KEY_CACHE.STORY_ID_TO_REFERENCE_ID */,
40009
- storyId,
40010
- ]);
40011
- if (cacheReferenceId === null || cacheReferenceId === void 0 ? void 0 : cacheReferenceId.data) {
40012
- const { data: referenceId } = cacheReferenceId;
40013
- isInTombstone('story', referenceId);
40014
- }
40015
- const cachedAt = client.cache && Date.now();
40016
- const storyCache = pullFromCache(['story', 'get', storyId]);
40017
- if (!storyCache)
40018
- return;
40019
- return {
40020
- data: storyCache.data,
40021
- cachedAt,
40022
39924
  };
39925
+ return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40023
39926
  };
40024
39927
 
40025
39928
  /* begin_public_function
40026
- id: comment.soft_delete, comment.hard_delete
39929
+ id: comment.get
40027
39930
  */
40028
39931
  /**
40029
39932
  * ```js
40030
- * import { CommentRepository } from '@amityco/ts-sdk'
40031
- * const success = await CommentRepository.deleteComment('foobar')
40032
- * ```
39933
+ * import { CommentRepository } from '@amityco/ts-sdk';
40033
39934
  *
40034
- * Deletes a {@link Amity.Comment}
39935
+ * let comment;
40035
39936
  *
40036
- * @param commentId The {@link Amity.Comment} ID to delete
40037
- * @return A success boolean if the {@link Amity.Comment} was deleted
39937
+ * const unsub = CommentRepository.getComment(commentId, response => {
39938
+ * comment = response.data;
39939
+ * });
39940
+ * ```
40038
39941
  *
40039
- * @category Comment API
40040
- * @async
39942
+ * Observe all mutation on a given {@link Amity.Comment}
39943
+ *
39944
+ * @param commentId the ID of the comment to observe
39945
+ * @param callback the function to call when new data are available
39946
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
39947
+ *
39948
+ * @category Comment Live Object
40041
39949
  */
40042
- const deleteComment = async (commentId, permanent = false) => {
40043
- var _a;
40044
- const client = getActiveClient();
40045
- const comment = await getComment$2(commentId);
40046
- // API-FIX: This endpoint has not been implemented yet.
40047
- await client.http.delete(`/api/v4/comments/${encodeURIComponent(commentId)}`, {
40048
- params: {
40049
- commentId,
40050
- permanent,
40051
- },
40052
- });
40053
- // to support hard deletion
40054
- const deleted = Object.assign(Object.assign({}, comment.data), { isDeleted: true });
40055
- if (comment.data.referenceType === 'story') {
40056
- const story = await getStoryByStoryId$1(comment.data.referenceId);
40057
- fireEvent('local.story.updated', {
40058
- stories: [story.data],
40059
- categories: [],
40060
- comments: [],
40061
- communities: [],
40062
- communityUsers: [],
40063
- files: [],
40064
- users: [],
39950
+ const getComment = (commentId, callback) => {
39951
+ return liveObject(commentId, callback, 'commentId', getComment$1, [
39952
+ onCommentDeleteLocal,
39953
+ onCommentDeleted,
39954
+ onCommentFlagged,
39955
+ onCommentReactionAdded,
39956
+ onCommentReactionRemoved,
39957
+ onCommentUnflagged,
39958
+ onCommentUpdated,
39959
+ onLocalCommentReactionAdded,
39960
+ onLocalCommentReactionRemoved,
39961
+ ]);
39962
+ };
39963
+ /* end_public_function */
39964
+
39965
+ class CommentPaginationController extends PaginationController {
39966
+ async getRequest(queryParams, token) {
39967
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
39968
+ const baseOptions = {
39969
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
39970
+ };
39971
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
39972
+ const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
39973
+ params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40065
39974
  });
39975
+ return queryResponse;
40066
39976
  }
40067
- else {
40068
- const post = (_a = pullFromCache(['post', 'get', comment.data.referenceId])) === null || _a === void 0 ? void 0 : _a.data;
40069
- if (post) {
40070
- let removeCount;
40071
- if (!deleted.parentId) {
40072
- // NOTE: delete the parent comment will remove all children comments
40073
- removeCount = deleted.childrenNumber + 1;
40074
- }
40075
- else
40076
- removeCount = 1;
40077
- post.commentsCount -= removeCount;
40078
- fireEvent('local.post.updated', {
40079
- posts: [post],
40080
- categories: [],
40081
- comments: [],
40082
- communities: [],
40083
- communityUsers: [],
40084
- feeds: [],
40085
- files: [],
40086
- postChildren: [],
40087
- users: [],
40088
- videoStreamings: [],
39977
+ }
39978
+
39979
+ var EnumCommentActions;
39980
+ (function (EnumCommentActions) {
39981
+ EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
39982
+ EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
39983
+ EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
39984
+ EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
39985
+ EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
39986
+ EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
39987
+ EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
39988
+ })(EnumCommentActions || (EnumCommentActions = {}));
39989
+
39990
+ class CommentQueryStreamController extends QueryStreamController {
39991
+ constructor(query, cacheKey, notifyChange, preparePayload) {
39992
+ super(query, cacheKey);
39993
+ this.notifyChange = notifyChange;
39994
+ this.preparePayload = preparePayload;
39995
+ }
39996
+ async saveToMainDB(response) {
39997
+ const processedPayload = await this.preparePayload(response);
39998
+ const client = getActiveClient();
39999
+ const cachedAt = client.cache && Date.now();
40000
+ if (client.cache) {
40001
+ ingestInCache(processedPayload, { cachedAt });
40002
+ }
40003
+ }
40004
+ appendToQueryStream(response, direction, refresh = false) {
40005
+ var _a, _b;
40006
+ if (refresh) {
40007
+ pushToCache(this.cacheKey, {
40008
+ data: response.comments.map(getResolver('comment')),
40089
40009
  });
40090
40010
  }
40011
+ else {
40012
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40013
+ const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40014
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40015
+ }
40091
40016
  }
40092
- fireEvent('local.comment.deleted', {
40093
- comments: [deleted],
40094
- commentChildren: [],
40095
- files: [],
40096
- users: [],
40097
- communityUsers: [],
40098
- });
40099
- if (permanent) {
40100
- scheduleTask(() => pushToTombstone('comment', commentId));
40017
+ reactor(action) {
40018
+ return (comment) => {
40019
+ var _a;
40020
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40021
+ if (this.query.referenceId !== comment.referenceId ||
40022
+ this.query.referenceType !== comment.referenceType ||
40023
+ !collection) {
40024
+ return;
40025
+ }
40026
+ if (this.query.parentId && this.query.parentId !== comment.parentId) {
40027
+ return;
40028
+ }
40029
+ if (!this.query.parentId && comment.parentId) {
40030
+ return;
40031
+ }
40032
+ if (action === EnumCommentActions.OnCommentCreated) {
40033
+ collection.data = [...new Set([comment.commentId, ...collection.data])];
40034
+ }
40035
+ pushToCache(this.cacheKey, collection);
40036
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40037
+ };
40101
40038
  }
40102
- else {
40103
- upsertInCache(['comment', 'get', commentId], { isDeleted: true });
40039
+ subscribeRTE(createSubscriber) {
40040
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40104
40041
  }
40105
- return deleted;
40106
- };
40107
- /* end_public_function */
40108
-
40109
- /* begin_public_function
40110
- id: comment.soft_delete
40111
- */
40112
- /**
40113
- * ```js
40114
- * import { CommentRepository } from '@amityco/ts-sdk'
40115
- * const success = await CommentRepository.softDeleteComment('foobar')
40116
- * ```
40117
- *
40118
- * Deletes a {@link Amity.Comment}
40119
- *
40120
- * @param commentId The {@link Amity.Comment} ID to delete
40121
- * @return A success boolean if the {@link Amity.Comment} was deleted
40122
- *
40123
- * @category Comment API
40124
- * @async
40125
- */
40126
- const softDeleteComment = async (commentId) => {
40127
- const client = getActiveClient();
40128
- client.log('comment/softDeleteComment', commentId);
40129
- const softDeleted = deleteComment(commentId);
40130
- return softDeleted;
40131
- };
40132
- /* end_public_function */
40042
+ }
40133
40043
 
40134
- /* begin_public_function
40135
- id: comment.hard_delete
40136
- */
40137
40044
  /**
40138
40045
  * ```js
40139
- * import { CommentRepository } from '@amityco/ts-sdk'
40140
- * const success = await CommentRepository.hardDeleteComment('foobar')
40046
+ * import { onCommentCreated } from '@amityco/ts-sdk'
40047
+ * const dispose = onCommentCreated(comment => {
40048
+ * // ...
40049
+ * })
40141
40050
  * ```
40142
40051
  *
40143
- * Deletes a {@link Amity.Comment}
40052
+ * Fired when a {@link Amity.InternalComment} has been created
40144
40053
  *
40145
- * @param commentId The {@link Amity.Comment} ID to delete
40146
- * @return A success boolean if the {@link Amity.Comment} was deleted
40054
+ * @param callback The function to call when the event was fired
40055
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40147
40056
  *
40148
- * @category Comment API
40149
- * @async
40057
+ * @category Comment Events
40150
40058
  */
40151
- const hardDeleteComment = async (commentId) => {
40152
- const client = getActiveClient();
40153
- client.log('comment/hardDeleteComment', commentId);
40154
- const hardDeleted = deleteComment(commentId, true);
40155
- return hardDeleted;
40059
+ const onCommentCreatedLocal = (callback) => {
40060
+ return createLocalCommentEventSubscriber('local.comment.created', callback);
40156
40061
  };
40157
- /* end_public_function */
40158
40062
 
40159
- /* begin_public_function
40160
- id: comment.flag
40161
- */
40162
- /**
40163
- * ```js
40164
- * import { CommentRepository } from '@amityco/ts-sdk'
40165
- * const flagged = await CommentRepository.flagComment(commentId, reason)
40166
- * ```
40167
- *
40168
- * @param commentId The ID of the comment to flag
40169
- * @param reason the reason to flag the comment
40170
- * @returns the created report result
40171
- *
40172
- * @category Comment API
40173
- * @async
40174
- * */
40175
- const flagComment = async (commentId, reason) => {
40176
- const client = getActiveClient();
40177
- client.log('comment/flagComment', commentId);
40178
- const isPredefinedReason = reason &&
40179
- Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
40180
- const body = {
40181
- reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
40182
- detail: reason && !isPredefinedReason ? reason : '',
40183
- };
40184
- const { data: payload } = await client.http.post(`/api/v3/comments/${encodeURIComponent(commentId)}/flag`, body);
40185
- if (client.cache) {
40186
- ingestInCache(payload);
40063
+ class CommentLiveCollectionController extends LiveCollectionController {
40064
+ constructor(query, callback) {
40065
+ const queryStreamId = hash(query);
40066
+ const cacheKey = ['comments', 'collection', queryStreamId];
40067
+ const paginationController = new CommentPaginationController(query);
40068
+ super(paginationController, queryStreamId, cacheKey, callback);
40069
+ this.query = query;
40070
+ this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40071
+ this.callback = callback.bind(this);
40072
+ this.loadPage({ initial: true });
40187
40073
  }
40188
- fireEvent('comment.flagged', payload);
40189
- return !!payload;
40190
- };
40191
- /* end_public_function */
40074
+ setup() {
40075
+ var _a;
40076
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40077
+ if (!collection) {
40078
+ pushToCache(this.cacheKey, {
40079
+ data: [],
40080
+ params: {},
40081
+ });
40082
+ }
40083
+ }
40084
+ async persistModel(queryPayload) {
40085
+ await this.queryStreamController.saveToMainDB(queryPayload);
40086
+ }
40087
+ persistQueryStream({ response, direction, refresh, }) {
40088
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40089
+ }
40090
+ startSubscription() {
40091
+ return this.queryStreamController.subscribeRTE([
40092
+ { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40093
+ { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40094
+ { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40095
+ { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40096
+ { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40097
+ { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40098
+ { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40099
+ { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40100
+ { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40101
+ { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40102
+ { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40103
+ ]);
40104
+ }
40105
+ notifyChange({ origin, loading, error }) {
40106
+ var _a, _b;
40107
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40108
+ if (!collection)
40109
+ return;
40110
+ const data = this.applyFilter((_b = collection.data
40111
+ .map(id => pullFromCache(['comment', 'get', id]))
40112
+ .filter(isNonNullable)
40113
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40114
+ if (!this.shouldNotify(data) && origin === 'event')
40115
+ return;
40116
+ this.callback({
40117
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40118
+ data,
40119
+ hasNextPage: !!this.paginationController.getNextToken(),
40120
+ loading,
40121
+ error,
40122
+ });
40123
+ }
40124
+ applyFilter(data) {
40125
+ let comments = data;
40126
+ if (!this.query.includeDeleted) {
40127
+ comments = filterByPropEquality(comments, 'isDeleted', false);
40128
+ }
40129
+ if (this.query.parentId) {
40130
+ comments = comments.filter(comment => comment.parentId === this.query.parentId);
40131
+ }
40132
+ if (typeof this.query.hasFlag === 'boolean') {
40133
+ if (this.query.hasFlag) {
40134
+ comments = comments.filter(comment => comment.hashFlag != null);
40135
+ }
40136
+ else {
40137
+ comments = comments.filter(comment => comment.hashFlag == null);
40138
+ }
40139
+ }
40140
+ if (this.query.dataTypes) {
40141
+ if (this.query.dataTypes.matchType === 'exact') {
40142
+ comments = comments.filter(comment => {
40143
+ var _a, _b;
40144
+ const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40145
+ const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40146
+ if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40147
+ return false;
40148
+ }
40149
+ return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40150
+ });
40151
+ }
40152
+ if (this.query.dataTypes.matchType === 'any') {
40153
+ 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); }); });
40154
+ }
40155
+ }
40156
+ switch (this.query.sortBy) {
40157
+ case 'firstCreated':
40158
+ comments = comments.sort(sortByFirstCreated);
40159
+ break;
40160
+ case 'lastCreated':
40161
+ default:
40162
+ comments = comments.sort(sortByLastCreated);
40163
+ break;
40164
+ }
40165
+ return comments;
40166
+ }
40167
+ }
40192
40168
 
40193
40169
  /* begin_public_function
40194
- id: comment.unflag
40170
+ id: comment.query
40195
40171
  */
40196
40172
  /**
40197
40173
  * ```js
40198
- * import { CommentRepository } from '@amityco/ts-sdk'
40199
- * const unflagged = await CommentRepository.unflagComment('commentId')
40174
+ * import { getComments } from '@amityco/ts-sdk'
40175
+ *
40176
+ * let comments = []
40177
+ * const unsub = getComments({
40178
+ * referenceType: Amity.InternalComment['referenceType'];
40179
+ * referenceId: Amity.InternalComment['referenceId'];
40180
+ * }, response => merge(comments, response.data))
40200
40181
  * ```
40201
40182
  *
40202
- * @param commentId The ID of comment to unflag
40203
- * @returns the unflagged result
40183
+ * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40204
40184
  *
40205
- * @category Comment API
40206
- * @async
40207
- * */
40208
- const unflagComment = async (commentId) => {
40209
- const client = getActiveClient();
40210
- client.log('comment/unflagComment', commentId);
40211
- const { data: payload } = await client.http.delete(`/api/v3/comments/${encodeURIComponent(commentId)}/unflag`);
40212
- if (client.cache) {
40213
- ingestInCache(payload);
40185
+ * @param referenceType the type of the target
40186
+ * @param referenceId the ID of the target
40187
+ * @param callback the function to call when new data are available
40188
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40189
+ *
40190
+ * @category Comments Live Collection
40191
+ */
40192
+ const getComments = (params, callback, config) => {
40193
+ const { log, cache } = getActiveClient();
40194
+ if (!cache) {
40195
+ console.log('For using Live Collection feature you need to enable Cache!');
40214
40196
  }
40215
- fireEvent('comment.unflagged', payload);
40216
- return !!payload;
40197
+ const timestamp = Date.now();
40198
+ log(`getComments(tmpid: ${timestamp}) > listen`);
40199
+ const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40200
+ const disposers = commentsLiveCollection.startSubscription();
40201
+ const cacheKey = commentsLiveCollection.getCacheKey();
40202
+ disposers.push(() => dropFromCache(cacheKey));
40203
+ return () => {
40204
+ log(`getComments(tmpid: ${timestamp}) > dispose`);
40205
+ disposers.forEach(fn => fn());
40206
+ };
40217
40207
  };
40218
40208
  /* end_public_function */
40219
40209
 
40220
- /* begin_public_function
40221
- id: comment.check_flag_by_me
40222
- */
40223
- /**
40224
- * ```js
40225
- * import { CommentRepository } from '@amityco/ts-sdk'
40226
- * const isReported = await CommentRepository.isCommentFlaggedByMe('commentId')
40227
- * ```
40228
- *
40229
- * @param commentId The ID of the comment to check if flagged by current user
40230
- * @returns `true` if the comment is flagged by me, `false` if doesn't.
40231
- *
40232
- * @category Comment API
40233
- * @async
40234
- * */
40235
- const isCommentFlaggedByMe = async (commentId) => {
40236
- const client = getActiveClient();
40237
- client.log('comment/isCommentFlaggedByMe', commentId);
40238
- const { data: { result }, } = await client.http.get(`/api/v3/comments/${commentId}/isflagbyme`);
40239
- return result;
40240
- };
40241
- /* end_public_function */
40210
+ var index$a = /*#__PURE__*/Object.freeze({
40211
+ __proto__: null,
40212
+ getCommentByIds: getCommentByIds,
40213
+ createComment: createComment,
40214
+ updateComment: updateComment,
40215
+ deleteComment: deleteComment,
40216
+ softDeleteComment: softDeleteComment,
40217
+ hardDeleteComment: hardDeleteComment,
40218
+ flagComment: flagComment,
40219
+ unflagComment: unflagComment,
40220
+ isCommentFlaggedByMe: isCommentFlaggedByMe,
40221
+ onCommentCreated: onCommentCreated,
40222
+ onCommentUpdated: onCommentUpdated,
40223
+ onCommentDeleted: onCommentDeleted,
40224
+ onCommentFlagged: onCommentFlagged,
40225
+ onCommentUnflagged: onCommentUnflagged,
40226
+ onCommentReactionAdded: onCommentReactionAdded,
40227
+ onCommentReactionRemoved: onCommentReactionRemoved,
40228
+ getComment: getComment,
40229
+ getComments: getComments
40230
+ });
40242
40231
 
40243
- const getComment$1 = async (commentId) => {
40232
+ const getPost$1 = async (postId) => {
40244
40233
  const client = getActiveClient();
40245
- client.log('comment/getComment', commentId);
40246
- isInTombstone('comment', commentId);
40247
- let data;
40234
+ client.log('post/getPost', postId);
40235
+ isInTombstone('post', postId);
40236
+ let payload;
40248
40237
  try {
40249
40238
  // API-FIX: endpoint should not be /list, parameters should be querystring.
40250
- const response = await client.http.get(`/api/v3/comments/${encodeURIComponent(commentId)}`);
40251
- data = response.data;
40239
+ const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40240
+ payload = response.data;
40252
40241
  }
40253
40242
  catch (error) {
40254
40243
  if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40255
- pushToTombstone('comment', commentId);
40244
+ pushToTombstone('post', postId);
40256
40245
  }
40257
40246
  throw error;
40258
40247
  }
40248
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40259
40249
  const cachedAt = client.cache && Date.now();
40260
40250
  if (client.cache)
40261
40251
  ingestInCache(data, { cachedAt });
40262
- const { comments } = data;
40252
+ const { posts } = data;
40253
+ const result = posts.find(post => post.postId === postId);
40263
40254
  return {
40264
- data: comments.find(comment => comment.commentId === commentId),
40255
+ data: result,
40265
40256
  cachedAt,
40266
40257
  };
40267
40258
  };
40268
- getComment$1.locally = (commentId) => {
40259
+ getPost$1.locally = (postId) => {
40269
40260
  const client = getActiveClient();
40270
- client.log('comment/getComment.locally', commentId);
40261
+ client.log('post/getPost.locally', postId);
40271
40262
  if (!client.cache)
40272
40263
  return;
40273
- const cached = pullFromCache(['comment', 'get', commentId]);
40264
+ const cached = pullFromCache(['post', 'get', postId]);
40274
40265
  if (!cached)
40275
40266
  return;
40276
40267
  return {
@@ -40281,142 +40272,245 @@ getComment$1.locally = (commentId) => {
40281
40272
 
40282
40273
  /**
40283
40274
  * ```js
40284
- * import { onCommentDeleteLocal } from '@amityco/ts-sdk'
40285
- * const dispose = onCommentDeleteLocal(comment => {
40275
+ * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40276
+ * const dispose = onLocalPostDeleted(post => {
40286
40277
  * // ...
40287
40278
  * })
40288
40279
  * ```
40289
40280
  *
40290
- * Fired when a {@link Amity.InternalComment} has been deleted
40281
+ * Fired when a {@link Amity.InternalPost} has been deleted
40291
40282
  *
40292
40283
  * @param callback The function to call when the event was fired
40293
40284
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40294
40285
  *
40295
- * @category Comment Events
40286
+ * @category Post Events
40296
40287
  */
40297
- const onCommentDeleteLocal = (callback) => createLocalCommentEventSubscriber('local.comment.deleted', callback);
40288
+ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
40298
40289
 
40299
40290
  /**
40300
40291
  * ```js
40301
- * import { onLocalCommentReactionAdded } from '@amityco/ts-sdk'
40302
- * const dispose = onLocalCommentReactionAdded(comment => {
40292
+ * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40293
+ * const dispose = onPostReactionAdded(post => {
40303
40294
  * // ...
40304
40295
  * })
40305
40296
  * ```
40306
40297
  *
40307
- * Fired when a {@link Amity.InternalComment} has been reacted
40298
+ * Fired when a {@link Amity.InternalPost} has been reacted
40308
40299
  *
40309
40300
  * @param callback The function to call when the event was fired
40310
40301
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40311
40302
  *
40312
- * @category Comment Events
40303
+ * @category Post Events
40313
40304
  */
40314
- const onLocalCommentReactionAdded = (callback) => {
40305
+ const onLocalPostReactionAdded = (callback) => {
40315
40306
  const client = getActiveClient();
40316
- const filter = ({ comment }) => {
40307
+ const filter = ({ post }) => {
40317
40308
  if (!client.cache) {
40318
- callback(comment);
40309
+ callback(post);
40319
40310
  }
40320
40311
  else {
40321
- upsertInCache(['comment', 'get', comment.commentId], comment);
40322
- callback(commentLinkedObject(comment));
40312
+ upsertInCache(['post', 'get', post.postId], post);
40313
+ callback(post);
40323
40314
  }
40324
40315
  };
40325
- return createEventSubscriber(client, 'local.comment.addReaction', 'local.comment.addReaction', filter);
40316
+ return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
40326
40317
  };
40327
40318
 
40328
40319
  /**
40329
40320
  * ```js
40330
- * import { onLocalCommentReactionRemoved } from '@amityco/ts-sdk'
40331
- * const dispose = onLocalCommentReactionRemoved(comment => {
40321
+ * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40322
+ * const dispose = onPostReactionRemoved(post => {
40332
40323
  * // ...
40333
40324
  * })
40334
40325
  * ```
40335
40326
  *
40336
- * Fired when a {@link Amity.InternalComment} has been reacted
40327
+ * Fired when a {@link Amity.InternalPost} has been reacted
40337
40328
  *
40338
40329
  * @param callback The function to call when the event was fired
40339
40330
  * @returns an {@link Amity.Unsubscriber} function to stop listening
40340
40331
  *
40341
- * @category Comment Events
40332
+ * @category Post Events
40342
40333
  */
40343
- const onLocalCommentReactionRemoved = (callback) => {
40334
+ const onLocalPostReactionRemoved = (callback) => {
40344
40335
  const client = getActiveClient();
40345
- const filter = ({ comment }) => {
40336
+ const filter = ({ post }) => {
40346
40337
  if (!client.cache) {
40347
- callback(comment);
40338
+ callback(post);
40348
40339
  }
40349
40340
  else {
40350
- upsertInCache(['comment', 'get', comment.commentId], comment);
40351
- callback(commentLinkedObject(comment));
40341
+ upsertInCache(['post', 'get', post.postId], post);
40342
+ callback(post);
40352
40343
  }
40353
40344
  };
40354
- return createEventSubscriber(client, 'local.comment.removeReaction', 'local.comment.removeReaction', filter);
40345
+ return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
40355
40346
  };
40356
40347
 
40357
- /* begin_public_function
40358
- id: comment.get
40359
- */
40360
40348
  /**
40361
40349
  * ```js
40362
- * import { CommentRepository } from '@amityco/ts-sdk';
40363
- *
40364
- * let comment;
40365
- *
40366
- * const unsub = CommentRepository.getComment(commentId, response => {
40367
- * comment = response.data;
40368
- * });
40350
+ * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40351
+ * const dispose = onPostUpdatedLocal(post => {
40352
+ * // ...
40353
+ * })
40369
40354
  * ```
40370
40355
  *
40371
- * Observe all mutation on a given {@link Amity.Comment}
40356
+ * Fired when a {@link Amity.InternalPost} has been updated
40372
40357
  *
40373
- * @param commentId the ID of the comment to observe
40374
- * @param callback the function to call when new data are available
40375
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the comment
40358
+ * @param callback The function to call when the event was fired
40359
+ * @returns an {@link Amity.Unsubscriber} function to stop listening
40376
40360
  *
40377
- * @category Comment Live Object
40361
+ * @category Post Events
40378
40362
  */
40379
- const getComment = (commentId, callback) => {
40380
- return liveObject(commentId, callback, 'commentId', getComment$1, [
40381
- onCommentDeleteLocal,
40363
+ const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
40364
+
40365
+ const commentEventHandler$1 = (callback, eventHandler, cacheKey) => {
40366
+ return eventHandler(async (comment) => {
40367
+ var _a;
40368
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40369
+ if (!currentCollection || !currentCollection.data.includes(comment.referenceId))
40370
+ return;
40371
+ await getPost$1(comment.referenceId);
40372
+ callback(comment);
40373
+ });
40374
+ };
40375
+ const generateCommentSubscriptions$1 = (cacheKey) => {
40376
+ const eventHandlers = [
40377
+ onCommentCreated,
40382
40378
  onCommentDeleted,
40383
- onCommentFlagged,
40384
40379
  onCommentReactionAdded,
40385
40380
  onCommentReactionRemoved,
40386
- onCommentUnflagged,
40387
- onCommentUpdated,
40381
+ onCommentCreatedLocal,
40382
+ onCommentDeleteLocal,
40388
40383
  onLocalCommentReactionAdded,
40389
40384
  onLocalCommentReactionRemoved,
40390
- ]);
40385
+ ];
40386
+ return eventHandlers.map(handler => ({
40387
+ fn: convertEventPayload((callback) => commentEventHandler$1(callback, handler, cacheKey), 'referenceId', 'post'),
40388
+ action: EnumPostActions.OnPostUpdated,
40389
+ }));
40390
+ };
40391
+ const getGlobalFeedSubscriptions = (cacheKey) => {
40392
+ return [
40393
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
40394
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
40395
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
40396
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
40397
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
40398
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
40399
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
40400
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
40401
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40402
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40403
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
40404
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
40405
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
40406
+ ...generateCommentSubscriptions$1(cacheKey),
40407
+ ];
40408
+ };
40409
+
40410
+ class CustomRankingGlobalFeedLiveCollectionController extends LiveCollectionController {
40411
+ constructor(query, callback) {
40412
+ const queryStreamId = hash(query);
40413
+ const cacheKey = ['customRankingGlobalFeed', 'collection', queryStreamId];
40414
+ const paginationController = new CustomRankingGlobalFeedPaginationController(query);
40415
+ super(paginationController, queryStreamId, cacheKey, callback);
40416
+ this.query = query;
40417
+ this.queryStreamController = new CustomRankingGlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40418
+ this.callback = callback.bind(this);
40419
+ this.loadPage({ initial: true });
40420
+ }
40421
+ setup() {
40422
+ var _a;
40423
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40424
+ if (!collection) {
40425
+ pushToCache(this.cacheKey, {
40426
+ data: [],
40427
+ params: {},
40428
+ });
40429
+ }
40430
+ }
40431
+ async persistModel(queryPayload) {
40432
+ await this.queryStreamController.saveToMainDB(queryPayload);
40433
+ }
40434
+ persistQueryStream({ response, direction, refresh, }) {
40435
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40436
+ }
40437
+ startSubscription() {
40438
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
40439
+ }
40440
+ notifyChange({ origin, loading, error }) {
40441
+ var _a, _b;
40442
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40443
+ if (!collection)
40444
+ return;
40445
+ const data = ((_b = collection.data
40446
+ .map(id => pullFromCache(['post', 'get', id]))
40447
+ .filter(isNonNullable)
40448
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40449
+ if (!this.shouldNotify(data) && origin === 'event')
40450
+ return;
40451
+ this.callback({
40452
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40453
+ data,
40454
+ hasNextPage: !!this.paginationController.getNextToken(),
40455
+ loading,
40456
+ error,
40457
+ });
40458
+ }
40459
+ }
40460
+
40461
+ /* begin_public_function
40462
+ id: feed.query.custom_ranking_feed
40463
+ */
40464
+ /**
40465
+ * ```js
40466
+ * import { FeedRepository } from '@amityco/ts-sdk'
40467
+ *
40468
+ * let posts = []
40469
+ * const unsub = FeedRepository.getGlobalFeed({
40470
+ * dataTypes: ['video','image'],
40471
+ * resolveParent: true,
40472
+ * }, response => processResponse(response))
40473
+ * ```
40474
+ *
40475
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
40476
+ *
40477
+ * @param params.dataTypes array of data types for the posts
40478
+ * @param callback the function to call when new data are available
40479
+ * @param config
40480
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40481
+ *
40482
+ * @category Posts Live Collection
40483
+ */
40484
+ const getCustomRankingGlobalFeed = (params, callback, config) => {
40485
+ const { log, cache } = getActiveClient();
40486
+ if (!cache) {
40487
+ console.log(ENABLE_CACHE_MESSAGE);
40488
+ }
40489
+ const timestamp = Date.now();
40490
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > listen`);
40491
+ const liveCollection = new CustomRankingGlobalFeedLiveCollectionController(params, callback);
40492
+ const disposers = liveCollection.startSubscription();
40493
+ const cacheKey = liveCollection.getCacheKey();
40494
+ disposers.push(() => dropFromCache(cacheKey));
40495
+ return () => {
40496
+ log(`getCustomRankingGlobalFeed(tmpid: ${timestamp}) > dispose`);
40497
+ disposers.forEach(fn => fn());
40498
+ };
40391
40499
  };
40392
40500
  /* end_public_function */
40393
40501
 
40394
- class CommentPaginationController extends PaginationController {
40502
+ class GlobalFeedPaginationController extends PaginationController {
40395
40503
  async getRequest(queryParams, token) {
40396
- const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, includeDeleted } = queryParams, params = __rest(queryParams, ["limit", "includeDeleted"]);
40397
- const baseOptions = {
40398
- type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
40399
- };
40400
- const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
40401
- const { data: queryResponse } = await this.http.get(`/api/v3/comments`, {
40402
- params: Object.assign(Object.assign({}, params), { isDeleted: inferIsDeleted(includeDeleted), options }),
40504
+ const { limit, resolveParent } = queryParams, params = __rest(queryParams, ["limit", "resolveParent"]);
40505
+ const options = token ? { token } : { limit };
40506
+ const { data: queryResponse } = await this.http.get(`/api/v4/me/global-feeds`, {
40507
+ params: Object.assign(Object.assign({}, params), { resolveParent: resolveParent !== null && resolveParent !== void 0 ? resolveParent : true, options }),
40403
40508
  });
40404
40509
  return queryResponse;
40405
40510
  }
40406
40511
  }
40407
40512
 
40408
- var EnumCommentActions;
40409
- (function (EnumCommentActions) {
40410
- EnumCommentActions["OnCommentCreated"] = "onCommentCreated";
40411
- EnumCommentActions["OnCommentUpdated"] = "onCommentUpdated";
40412
- EnumCommentActions["OnCommentDeleted"] = "onCommentDeleted";
40413
- EnumCommentActions["OnCommentFlagged"] = "onCommentFlagged";
40414
- EnumCommentActions["OnCommentUnflagged"] = "onCommentUnflagged";
40415
- EnumCommentActions["OnCommentReactionAdded"] = "onCommentReactionAdded";
40416
- EnumCommentActions["OnCommentReactionRemoved"] = "onCommentReactionRemoved";
40417
- })(EnumCommentActions || (EnumCommentActions = {}));
40418
-
40419
- class CommentQueryStreamController extends QueryStreamController {
40513
+ class GlobalFeedQueryStreamController extends QueryStreamController {
40420
40514
  constructor(query, cacheKey, notifyChange, preparePayload) {
40421
40515
  super(query, cacheKey);
40422
40516
  this.notifyChange = notifyChange;
@@ -40434,321 +40528,631 @@ class CommentQueryStreamController extends QueryStreamController {
40434
40528
  var _a, _b;
40435
40529
  if (refresh) {
40436
40530
  pushToCache(this.cacheKey, {
40437
- data: response.comments.map(getResolver('comment')),
40531
+ data: response.posts.map(getResolver('post')),
40438
40532
  });
40439
40533
  }
40440
40534
  else {
40441
40535
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40442
- const comments = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40443
- pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...comments, ...response.comments.map(getResolver('comment'))])] }));
40536
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
40537
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
40444
40538
  }
40445
40539
  }
40446
40540
  reactor(action) {
40447
- return (comment) => {
40541
+ return (post) => {
40448
40542
  var _a;
40449
40543
  const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40450
- if (this.query.referenceId !== comment.referenceId ||
40451
- this.query.referenceType !== comment.referenceType ||
40452
- !collection) {
40544
+ if (!collection)
40453
40545
  return;
40454
- }
40455
- if (this.query.parentId && this.query.parentId !== comment.parentId) {
40546
+ if (post.parentPostId && !collection.data.includes(post.parentPostId))
40456
40547
  return;
40548
+ // Delete Action
40549
+ if (action === EnumPostActions.OnPostDeleted) {
40550
+ // Parent Post - Remove from collection
40551
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40457
40552
  }
40458
- if (!this.query.parentId && comment.parentId) {
40459
- return;
40553
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
40554
+ // If the query has dataTypes array with value, check if post.dataType is include in the array
40555
+ if (this.query.dataTypes && this.query.dataTypes.length > 0) {
40556
+ if (!this.query.dataTypes.includes(post.dataType))
40557
+ return;
40558
+ }
40559
+ collection.data = [...new Set([post.postId, ...collection.data])];
40460
40560
  }
40461
- if (action === EnumCommentActions.OnCommentCreated) {
40462
- collection.data = [...new Set([comment.commentId, ...collection.data])];
40561
+ if (action === EnumPostActions.OnPostDeclined) {
40562
+ collection.data = collection.data.filter(postId => postId !== post.postId);
40463
40563
  }
40464
40564
  pushToCache(this.cacheKey, collection);
40465
40565
  this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
40466
40566
  };
40467
40567
  }
40468
- subscribeRTE(createSubscriber) {
40469
- return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40568
+ subscribeRTE(createSubscriber) {
40569
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
40570
+ }
40571
+ }
40572
+
40573
+ class GlobalFeedLiveCollectionController extends LiveCollectionController {
40574
+ constructor(query, callback) {
40575
+ const queryStreamId = hash(query);
40576
+ const cacheKey = ['globalFeed', 'collection', queryStreamId];
40577
+ const paginationController = new GlobalFeedPaginationController(query);
40578
+ super(paginationController, queryStreamId, cacheKey, callback);
40579
+ this.query = query;
40580
+ this.queryStreamController = new GlobalFeedQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
40581
+ this.callback = callback.bind(this);
40582
+ this.loadPage({ initial: true });
40583
+ }
40584
+ setup() {
40585
+ var _a;
40586
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40587
+ if (!collection) {
40588
+ pushToCache(this.cacheKey, {
40589
+ data: [],
40590
+ params: {},
40591
+ });
40592
+ }
40593
+ }
40594
+ async persistModel(queryPayload) {
40595
+ await this.queryStreamController.saveToMainDB(queryPayload);
40596
+ }
40597
+ persistQueryStream({ response, direction, refresh, }) {
40598
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
40599
+ }
40600
+ startSubscription() {
40601
+ return this.queryStreamController.subscribeRTE(getGlobalFeedSubscriptions(this.cacheKey));
40602
+ }
40603
+ notifyChange({ origin, loading, error }) {
40604
+ var _a, _b;
40605
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40606
+ if (!collection)
40607
+ return;
40608
+ const data = ((_b = collection.data
40609
+ .map(id => pullFromCache(['post', 'get', id]))
40610
+ .filter(isNonNullable)
40611
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
40612
+ if (!this.shouldNotify(data) && origin === 'event')
40613
+ return;
40614
+ this.callback({
40615
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40616
+ data,
40617
+ hasNextPage: !!this.paginationController.getNextToken(),
40618
+ loading,
40619
+ error,
40620
+ });
40621
+ }
40622
+ }
40623
+
40624
+ /* begin_public_function
40625
+ id: feed.query.global_feed
40626
+ */
40627
+ /**
40628
+ * ```js
40629
+ * import { FeedRepository } from '@amityco/ts-sdk'
40630
+ *
40631
+ * let posts = []
40632
+ * const unsub = FeedRepository.getGlobalFeed({
40633
+ * dataTypes: ['video','image'],
40634
+ * resolveParent: true,
40635
+ * }, response => processResponse(response))
40636
+ * ```
40637
+ *
40638
+ * Observe all mutations on a list of {@link Amity.Post} for global feed
40639
+ * @param params.dataTypes array of data types for the posts
40640
+ * @param params.resolveParent
40641
+ * @param callback the function to call when new data are available
40642
+ * @param config
40643
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40644
+ *
40645
+ * @category Posts Live Collection
40646
+ */
40647
+ const getGlobalFeed = (params, callback, config) => {
40648
+ const { log, cache } = getActiveClient();
40649
+ if (!cache) {
40650
+ console.log(ENABLE_CACHE_MESSAGE);
40651
+ }
40652
+ const timestamp = Date.now();
40653
+ log(`getGlobalFeed(tmpid: ${timestamp}) > listen`);
40654
+ const liveCollection = new GlobalFeedLiveCollectionController(params, callback);
40655
+ const disposers = liveCollection.startSubscription();
40656
+ const cacheKey = liveCollection.getCacheKey();
40657
+ disposers.push(() => dropFromCache(cacheKey));
40658
+ return () => {
40659
+ log(`getGlobalFeed(tmpid: ${timestamp}) > dispose`);
40660
+ disposers.forEach(fn => fn());
40661
+ };
40662
+ };
40663
+ /* end_public_function */
40664
+
40665
+ var index$9 = /*#__PURE__*/Object.freeze({
40666
+ __proto__: null,
40667
+ queryGlobalFeed: queryGlobalFeed,
40668
+ getCustomRankingGlobalFeed: getCustomRankingGlobalFeed,
40669
+ getGlobalFeed: getGlobalFeed
40670
+ });
40671
+
40672
+ /* begin_public_function
40673
+ id: post.get_by_ids
40674
+ */
40675
+ /**
40676
+ * ```js
40677
+ * import { getPostByIds } from '@amityco/ts-sdk'
40678
+ * const { data: posts } = await getPostByIds(['foo', 'bar'])
40679
+ * ```
40680
+ *
40681
+ * Fetches a collection of {@link Amity.Post} objects
40682
+ *
40683
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40684
+ * @returns the associated collection of {@link Amity.Post} objects
40685
+ *
40686
+ * @category Post API
40687
+ * @async
40688
+ */
40689
+ const getPostByIds = async (postIds) => {
40690
+ const client = getActiveClient();
40691
+ client.log('post/getPostByIds', postIds);
40692
+ const encodedPostIds = postIds.map(postId => encodeURIComponent(postId));
40693
+ let payload;
40694
+ try {
40695
+ // API-FIX: endpoint should not be /list, parameters should be querystring.
40696
+ const response = await client.http.get(`/api/v3/posts/list`, {
40697
+ params: { postIds: encodedPostIds },
40698
+ });
40699
+ payload = response.data;
40700
+ }
40701
+ catch (error) {
40702
+ postIds.forEach(postId => {
40703
+ if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40704
+ pushToTombstone('post', postId);
40705
+ }
40706
+ });
40707
+ throw error;
40708
+ }
40709
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40710
+ const cachedAt = client.cache && Date.now();
40711
+ if (client.cache)
40712
+ ingestInCache(data, { cachedAt });
40713
+ return {
40714
+ data: data.posts.map(LinkedObject.post),
40715
+ cachedAt,
40716
+ };
40717
+ };
40718
+ /* end_public_function */
40719
+ /**
40720
+ * ```js
40721
+ * import { getPostByIds } from '@amityco/ts-sdk'
40722
+ * const { data: posts } = getPostByIds.locally(['foo', 'bar'])
40723
+ * ```
40724
+ *
40725
+ * Fetches a collection of {@link Amity.Post} objects from cache
40726
+ *
40727
+ * @param postIds the IDs of the {@link Amity.Post} to fetch
40728
+ * @returns the associated collection of {@link Amity.Post} objects
40729
+ *
40730
+ * @category Post API
40731
+ */
40732
+ getPostByIds.locally = (postIds) => {
40733
+ var _a;
40734
+ const client = getActiveClient();
40735
+ client.log('post/getPostByIds.locally', postIds);
40736
+ if (!client.cache)
40737
+ return;
40738
+ const cached = postIds
40739
+ .map(postId => pullFromCache(['post', 'get', postId]))
40740
+ .filter(Boolean);
40741
+ const posts = cached.map(({ data }) => data);
40742
+ const oldest = (_a = cached.sort((a, b) => (a.cachedAt < b.cachedAt ? -1 : 1))) === null || _a === void 0 ? void 0 : _a[0];
40743
+ if ((cached === null || cached === void 0 ? void 0 : cached.length) < postIds.length)
40744
+ return;
40745
+ return {
40746
+ data: posts.map(LinkedObject.post),
40747
+ cachedAt: oldest.cachedAt,
40748
+ };
40749
+ };
40750
+
40751
+ /* begin_public_function
40752
+ 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
40753
+ */
40754
+ /**
40755
+ * ```js
40756
+ * import { PostRepository } from '@amityco/ts-sdk'
40757
+ * const created = await PostRepository.createPost({
40758
+ * targetType: 'user',
40759
+ * targetId: 'foobar',
40760
+ * data: { text: 'hello world' }
40761
+ * }))
40762
+ * ```
40763
+ *
40764
+ * Creates an {@link Amity.Post}
40765
+ *
40766
+ * @param bundle The data necessary to create a new {@link Amity.Post}
40767
+ * @returns The newly created {@link Amity.Post}
40768
+ *
40769
+ * @category Post API
40770
+ * @async
40771
+ */
40772
+ const createPost = async (bundle) => {
40773
+ const client = getActiveClient();
40774
+ client.log('post/createPost', bundle);
40775
+ if (!bundle.dataType || ['text', 'image', 'file', 'video'].includes(bundle.dataType)) {
40776
+ // eslint-disable-next-line no-param-reassign
40777
+ delete bundle.dataType;
40778
+ }
40779
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
40780
+ fireEvent('post.created', payload);
40781
+ const data = preparePostPayload(payload);
40782
+ const cachedAt = client.cache && Date.now();
40783
+ if (client.cache)
40784
+ ingestInCache(data, { cachedAt });
40785
+ const { posts } = data;
40786
+ return {
40787
+ data: LinkedObject.post(posts[0]),
40788
+ cachedAt,
40789
+ };
40790
+ };
40791
+ /* end_public_function */
40792
+
40793
+ /* begin_public_function
40794
+ id: post.edit, post.edit.custom_post
40795
+ */
40796
+ /**
40797
+ * ```js
40798
+ * import { PostRepository } from '@amityco/ts-sdk'
40799
+ * const updated = await PostRepository.editPost(postId, {
40800
+ * data: { text: 'hello world' }
40801
+ * })
40802
+ * ```
40803
+ *
40804
+ * Updates an {@link Amity.Post}
40805
+ *
40806
+ * @param postId The ID of the {@link Amity.Post} to edit
40807
+ * @param patch The patch data to apply
40808
+ * @returns the updated {@link Amity.Post} object
40809
+ *
40810
+ * @category Post API
40811
+ * @async
40812
+ */
40813
+ const editPost = async (postId, patch) => {
40814
+ const client = getActiveClient();
40815
+ client.log('user/editPost', patch);
40816
+ const { data: payload } = await client.http.put(`/api/v4/posts/${encodeURIComponent(postId)}`, patch);
40817
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40818
+ const cachedAt = client.cache && Date.now();
40819
+ if (client.cache)
40820
+ ingestInCache(data, { cachedAt });
40821
+ fireEvent('local.post.updated', data);
40822
+ const { posts } = data;
40823
+ return {
40824
+ data: LinkedObject.post(posts.find(post => post.postId === postId)),
40825
+ cachedAt,
40826
+ };
40827
+ };
40828
+ /* end_public_function */
40829
+
40830
+ /**
40831
+ * ```js
40832
+ * import { deletePost } from '@amityco/ts-sdk'
40833
+ * const success = await deletePost('foobar')
40834
+ * ```
40835
+ *
40836
+ * Deletes a {@link Amity.Post}
40837
+ *
40838
+ * @param postId The {@link Amity.Post} ID to delete
40839
+ * @return A success boolean if the {@link Amity.Post} was deleted
40840
+ *
40841
+ * @private
40842
+ * @async
40843
+ */
40844
+ const deletePost = async (postId, permanent = false) => {
40845
+ var _a;
40846
+ const client = getActiveClient();
40847
+ const post = await getPost$2(postId);
40848
+ await client.http.delete(`/api/v4/posts/${encodeURIComponent(postId)}`, {
40849
+ params: {
40850
+ postId,
40851
+ permanent,
40852
+ },
40853
+ });
40854
+ // there is currently a limitation which doesn't allow us to fire event to tell that community
40855
+ // has been updated. reason is that, when the object is deleted, we don't have its `communityId`
40856
+ // and so we cannot refetch the community or advertise on events. hopefully this should be solved
40857
+ // later when realtime events covers that for us.
40858
+ if (post.data.targetType === 'community') {
40859
+ const community = await getCommunity$1(post.data.targetId);
40860
+ const communityUsersCache = (_a = queryCache(['communityUsers', 'get'])) !== null && _a !== void 0 ? _a : [];
40861
+ const communityUsers = communityUsersCache
40862
+ .filter(({ key }) => {
40863
+ // cache key is ['communityUsers', 'get', `${communityId}#`${userId}`}]
40864
+ if (key[0] !== 'communityUsers')
40865
+ return false;
40866
+ if (key[1] !== 'get')
40867
+ return false;
40868
+ if (typeof key[2] === 'string')
40869
+ return key[2].includes(community.data.communityId);
40870
+ return false;
40871
+ })
40872
+ .map(({ data }) => data);
40873
+ fireEvent('community.updated', {
40874
+ communities: [community.data],
40875
+ categories: [],
40876
+ communityUsers,
40877
+ feeds: [],
40878
+ files: [],
40879
+ users: [],
40880
+ });
40881
+ }
40882
+ // to support hard deletion
40883
+ const deleted = Object.assign(Object.assign({}, post.data), { isDeleted: true });
40884
+ if (permanent) {
40885
+ setTimeout(() => {
40886
+ pushToTombstone('post', postId);
40887
+ }, 0);
40470
40888
  }
40471
- }
40889
+ else {
40890
+ upsertInCache(['post', 'get', postId], { isDeleted: true });
40891
+ }
40892
+ fireEvent('local.post.deleted', {
40893
+ posts: [deleted],
40894
+ categories: [],
40895
+ comments: [],
40896
+ communities: [],
40897
+ communityUsers: [],
40898
+ feeds: [],
40899
+ files: [],
40900
+ postChildren: [],
40901
+ users: [],
40902
+ videoStreamings: [],
40903
+ });
40904
+ return LinkedObject.post(deleted);
40905
+ };
40472
40906
 
40907
+ /* begin_public_function
40908
+ id: post.soft_delete
40909
+ */
40473
40910
  /**
40474
40911
  * ```js
40475
- * import { onCommentCreated } from '@amityco/ts-sdk'
40476
- * const dispose = onCommentCreated(comment => {
40477
- * // ...
40478
- * })
40912
+ * import { PostRepository } from '@amityco/ts-sdk'
40913
+ * const success = await PostRepository.softDeletePost('foobar')
40479
40914
  * ```
40480
40915
  *
40481
- * Fired when a {@link Amity.InternalComment} has been created
40916
+ * Soft deletes a {@link Amity.Post}
40482
40917
  *
40483
- * @param callback The function to call when the event was fired
40484
- * @returns an {@link Amity.Unsubscriber} function to stop listening
40918
+ * @param postId The {@link Amity.Post} ID to soft delete
40919
+ * @return A success boolean if the {@link Amity.Post} was deleted
40485
40920
  *
40486
- * @category Comment Events
40921
+ * @category Post API
40922
+ * @async
40487
40923
  */
40488
- const onCommentCreatedLocal = (callback) => {
40489
- return createLocalCommentEventSubscriber('local.comment.created', callback);
40924
+ const softDeletePost = async (postId) => {
40925
+ const client = getActiveClient();
40926
+ client.log('post/softDeletePost', postId);
40927
+ const softDeleted = await deletePost(postId, false);
40928
+ return LinkedObject.post(softDeleted);
40490
40929
  };
40930
+ /* end_public_function */
40491
40931
 
40492
- class CommentLiveCollectionController extends LiveCollectionController {
40493
- constructor(query, callback) {
40494
- const queryStreamId = hash(query);
40495
- const cacheKey = ['comments', 'collection', queryStreamId];
40496
- const paginationController = new CommentPaginationController(query);
40497
- super(paginationController, queryStreamId, cacheKey, callback);
40498
- this.query = query;
40499
- this.queryStreamController = new CommentQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), prepareCommentPayload);
40500
- this.callback = callback.bind(this);
40501
- this.loadPage({ initial: true });
40502
- }
40503
- setup() {
40504
- var _a;
40505
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40506
- if (!collection) {
40507
- pushToCache(this.cacheKey, {
40508
- data: [],
40509
- params: {},
40510
- });
40511
- }
40512
- }
40513
- async persistModel(queryPayload) {
40514
- await this.queryStreamController.saveToMainDB(queryPayload);
40515
- }
40516
- persistQueryStream({ response, direction, refresh, }) {
40517
- this.queryStreamController.appendToQueryStream(response, direction, refresh);
40518
- }
40519
- startSubscription() {
40520
- return this.queryStreamController.subscribeRTE([
40521
- { fn: onCommentCreatedLocal, action: EnumCommentActions.OnCommentCreated },
40522
- { fn: onCommentDeleteLocal, action: EnumCommentActions.OnCommentDeleted },
40523
- { fn: onCommentCreated, action: EnumCommentActions.OnCommentCreated },
40524
- { fn: onCommentUpdated, action: EnumCommentActions.OnCommentUpdated },
40525
- { fn: onCommentDeleted, action: EnumCommentActions.OnCommentDeleted },
40526
- { fn: onCommentFlagged, action: EnumCommentActions.OnCommentFlagged },
40527
- { fn: onCommentUnflagged, action: EnumCommentActions.OnCommentUnflagged },
40528
- { fn: onCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40529
- { fn: onCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40530
- { fn: onLocalCommentReactionAdded, action: EnumCommentActions.OnCommentReactionAdded },
40531
- { fn: onLocalCommentReactionRemoved, action: EnumCommentActions.OnCommentReactionRemoved },
40532
- ]);
40533
- }
40534
- notifyChange({ origin, loading, error }) {
40535
- var _a, _b;
40536
- const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
40537
- if (!collection)
40538
- return;
40539
- const data = this.applyFilter((_b = collection.data
40540
- .map(id => pullFromCache(['comment', 'get', id]))
40541
- .filter(isNonNullable)
40542
- .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.comment);
40543
- if (!this.shouldNotify(data) && origin === 'event')
40544
- return;
40545
- this.callback({
40546
- onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
40547
- data,
40548
- hasNextPage: !!this.paginationController.getNextToken(),
40549
- loading,
40550
- error,
40551
- });
40552
- }
40553
- applyFilter(data) {
40554
- let comments = data;
40555
- if (!this.query.includeDeleted) {
40556
- comments = filterByPropEquality(comments, 'isDeleted', false);
40557
- }
40558
- if (this.query.parentId) {
40559
- comments = comments.filter(comment => comment.parentId === this.query.parentId);
40560
- }
40561
- if (typeof this.query.hasFlag === 'boolean') {
40562
- if (this.query.hasFlag) {
40563
- comments = comments.filter(comment => comment.hashFlag != null);
40564
- }
40565
- else {
40566
- comments = comments.filter(comment => comment.hashFlag == null);
40567
- }
40568
- }
40569
- if (this.query.dataTypes) {
40570
- if (this.query.dataTypes.matchType === 'exact') {
40571
- comments = comments.filter(comment => {
40572
- var _a, _b;
40573
- const sortedDataTypesQueryValue = ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.sort()) || [];
40574
- const sortedDataTypesCommentValue = ((_b = comment.dataTypes) === null || _b === void 0 ? void 0 : _b.sort()) || [];
40575
- if (sortedDataTypesCommentValue.length !== sortedDataTypesQueryValue.length) {
40576
- return false;
40577
- }
40578
- return sortedDataTypesQueryValue.every((value, index) => value === sortedDataTypesCommentValue[index]);
40579
- });
40580
- }
40581
- if (this.query.dataTypes.matchType === 'any') {
40582
- comments = comments.filter(comment => { var _a; return (_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.values.some(value => { var _a; return (_a = comment.dataTypes) === null || _a === void 0 ? void 0 : _a.includes(value); }); });
40583
- }
40584
- }
40585
- switch (this.query.sortBy) {
40586
- case 'firstCreated':
40587
- comments = comments.sort(sortByFirstCreated);
40588
- break;
40589
- case 'lastCreated':
40590
- default:
40591
- comments = comments.sort(sortByLastCreated);
40592
- break;
40593
- }
40594
- return comments;
40595
- }
40596
- }
40932
+ /* begin_public_function
40933
+ id: post.hard_delete
40934
+ */
40935
+ /**
40936
+ * ```js
40937
+ * import { hardDeletePost } from '@amityco/ts-sdk'
40938
+ * const success = await hardDeletePost('foobar')
40939
+ * ```
40940
+ *
40941
+ * Hard deletes a {@link Amity.Post}
40942
+ *
40943
+ * @param postId The {@link Amity.Post} ID to be hard delete
40944
+ * @return A success boolean if the {@link Amity.Post} was deleted
40945
+ *
40946
+ * @category Post API
40947
+ * @async
40948
+ */
40949
+ const hardDeletePost = async (postId) => {
40950
+ const client = getActiveClient();
40951
+ client.log('post/hardDeletePost', postId);
40952
+ const hardDeleted = await deletePost(postId, true);
40953
+ return LinkedObject.post(hardDeleted);
40954
+ };
40955
+ /* end_public_function */
40597
40956
 
40598
40957
  /* begin_public_function
40599
- id: comment.query
40958
+ id: post.approve
40600
40959
  */
40601
40960
  /**
40602
40961
  * ```js
40603
- * import { getComments } from '@amityco/ts-sdk'
40962
+ * import { approvePost } from '@amityco/ts-sdk'
40604
40963
  *
40605
- * let comments = []
40606
- * const unsub = getComments({
40607
- * referenceType: Amity.InternalComment['referenceType'];
40608
- * referenceId: Amity.InternalComment['referenceId'];
40609
- * }, response => merge(comments, response.data))
40964
+ * const { data: post } = await approvePost('postId')
40610
40965
  * ```
40611
40966
  *
40612
- * Observe all mutations on a list of {@link Amity.InternalComment} for a given target object
40967
+ * Approves a {@link Amity.Post}
40613
40968
  *
40614
- * @param referenceType the type of the target
40615
- * @param referenceId the ID of the target
40616
- * @param callback the function to call when new data are available
40617
- * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
40969
+ * @param postId The {@link Amity.Post} ID to be approved
40970
+ * @return A {@link Amity.Post} that was approved
40618
40971
  *
40619
- * @category Comments Live Collection
40972
+ * @category Post API
40973
+ * @async
40620
40974
  */
40621
- const getComments = (params, callback, config) => {
40622
- const { log, cache } = getActiveClient();
40623
- if (!cache) {
40624
- console.log('For using Live Collection feature you need to enable Cache!');
40975
+ const approvePost = async (postId) => {
40976
+ const client = getActiveClient();
40977
+ client.log('post/approvePost', postId);
40978
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/approve`);
40979
+ fireEvent('post.approved', payload);
40980
+ // fire virtual event for community update
40981
+ if (payload.posts[0].targetType === 'community') {
40982
+ fireEvent('community.updated', payload);
40625
40983
  }
40626
- const timestamp = Date.now();
40627
- log(`getComments(tmpid: ${timestamp}) > listen`);
40628
- const commentsLiveCollection = new CommentLiveCollectionController(params, callback);
40629
- const disposers = commentsLiveCollection.startSubscription();
40630
- const cacheKey = commentsLiveCollection.getCacheKey();
40631
- disposers.push(() => dropFromCache(cacheKey));
40632
- return () => {
40633
- log(`getComments(tmpid: ${timestamp}) > dispose`);
40634
- disposers.forEach(fn => fn());
40984
+ const data = prepareMembershipPayload(payload, 'communityUsers');
40985
+ const cachedAt = client.cache && Date.now();
40986
+ if (client.cache)
40987
+ ingestInCache(data, { cachedAt });
40988
+ return {
40989
+ data: LinkedObject.post(data.posts.find(post => post.postId === postId)),
40990
+ cachedAt,
40635
40991
  };
40636
40992
  };
40637
40993
  /* end_public_function */
40638
40994
 
40639
- var index$9 = /*#__PURE__*/Object.freeze({
40640
- __proto__: null,
40641
- getCommentByIds: getCommentByIds,
40642
- createComment: createComment,
40643
- updateComment: updateComment,
40644
- deleteComment: deleteComment,
40645
- softDeleteComment: softDeleteComment,
40646
- hardDeleteComment: hardDeleteComment,
40647
- flagComment: flagComment,
40648
- unflagComment: unflagComment,
40649
- isCommentFlaggedByMe: isCommentFlaggedByMe,
40650
- onCommentCreated: onCommentCreated,
40651
- onCommentUpdated: onCommentUpdated,
40652
- onCommentDeleted: onCommentDeleted,
40653
- onCommentFlagged: onCommentFlagged,
40654
- onCommentUnflagged: onCommentUnflagged,
40655
- onCommentReactionAdded: onCommentReactionAdded,
40656
- onCommentReactionRemoved: onCommentReactionRemoved,
40657
- getComment: getComment,
40658
- getComments: getComments
40659
- });
40660
-
40995
+ /* begin_public_function
40996
+ id: post.decline
40997
+ */
40661
40998
  /**
40662
40999
  * ```js
40663
- * import { onPostUpdatedLocal } from '@amityco/ts-sdk'
40664
- * const dispose = onPostUpdatedLocal(post => {
40665
- * // ...
40666
- * })
41000
+ * import { declinePost } from '@amityco/ts-sdk'
41001
+ *
41002
+ * const {data: post} = await declinePost('postId')
40667
41003
  * ```
40668
41004
  *
40669
- * Fired when a {@link Amity.InternalPost} has been updated
41005
+ * Declines a {@link Amity.Post}
40670
41006
  *
40671
- * @param callback The function to call when the event was fired
40672
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41007
+ * @param postId The {@link Amity.Post} ID to be declined
41008
+ * @return A {@link Amity.Post} that was declined
40673
41009
  *
40674
- * @category Post Events
41010
+ * @category Post API
41011
+ * @async
40675
41012
  */
40676
- const onPostUpdatedLocal = (callback) => createLocalPostEventSubscriber('local.post.updated', callback);
41013
+ const declinePost = async (postId) => {
41014
+ const client = getActiveClient();
41015
+ client.log('post/declinePost', postId);
41016
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/decline`);
41017
+ // fire virtual event
41018
+ if (payload.posts[0].targetType === 'community') {
41019
+ fireEvent('community.updated', payload);
41020
+ }
41021
+ fireEvent('post.declined', payload);
41022
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41023
+ const cachedAt = client.cache && Date.now();
41024
+ if (client.cache)
41025
+ ingestInCache(data, { cachedAt });
41026
+ return {
41027
+ data: LinkedObject.post(payload.posts.find(post => post.postId === postId)),
41028
+ cachedAt,
41029
+ };
41030
+ };
41031
+ /* end_public_function */
40677
41032
 
41033
+ /* begin_public_function
41034
+ id: post.flag
41035
+ */
40678
41036
  /**
40679
41037
  * ```js
40680
- * import { onLocalPostReactionAdded } from '@amityco/ts-sdk'
40681
- * const dispose = onPostReactionAdded(post => {
40682
- * // ...
40683
- * })
41038
+ * import { PostRepository } from '@amityco/ts-sdk'
41039
+ * const flagged = await PostRepository.flagPost(postId, reason)
40684
41040
  * ```
40685
41041
  *
40686
- * Fired when a {@link Amity.InternalPost} has been reacted
40687
- *
40688
- * @param callback The function to call when the event was fired
40689
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41042
+ * @param postId of the post to flag
41043
+ * @param reason the reason to flag the post
41044
+ * @returns a boolean
40690
41045
  *
40691
- * @category Post Events
40692
- */
40693
- const onLocalPostReactionAdded = (callback) => {
41046
+ * @category Post API
41047
+ * @async
41048
+ * */
41049
+ const flagPost = async (postId, reason) => {
40694
41050
  const client = getActiveClient();
40695
- const filter = ({ post }) => {
40696
- if (!client.cache) {
40697
- callback(post);
40698
- }
40699
- else {
40700
- upsertInCache(['post', 'get', post.postId], post);
40701
- callback(post);
40702
- }
41051
+ client.log('post/flagPost', postId);
41052
+ const isPredefinedReason = reason &&
41053
+ Object.entries(ContentFlagReasonEnum).some(([key, value]) => key !== ContentFlagReasonEnum.Others && value === reason);
41054
+ const body = {
41055
+ reason: reason && isPredefinedReason ? reason : ContentFlagReasonEnum.Others,
41056
+ detail: reason && !isPredefinedReason ? reason : '',
40703
41057
  };
40704
- return createEventSubscriber(client, 'local.post.addReaction', 'local.post.addReaction', filter);
41058
+ const { data: payload } = await client.http.post(`/api/v3/posts/${encodeURIComponent(postId)}/flag`, body);
41059
+ if (client.cache) {
41060
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
41061
+ }
41062
+ fireEvent('post.flagged', payload);
41063
+ return !!payload;
40705
41064
  };
41065
+ /* end_public_function */
40706
41066
 
41067
+ /* begin_public_function
41068
+ id: post.unflag
41069
+ */
40707
41070
  /**
40708
41071
  * ```js
40709
- * import { onLocalPostReactionRemoved } from '@amityco/ts-sdk'
40710
- * const dispose = onPostReactionRemoved(post => {
40711
- * // ...
40712
- * })
41072
+ * import { PostRepository } from '@amityco/ts-sdk'
41073
+ * const unflagged = await PostRepository.unflagPost(postId)
40713
41074
  * ```
40714
41075
  *
40715
- * Fired when a {@link Amity.InternalPost} has been reacted
41076
+ * @param postId of the post to unflag
41077
+ * @returns the unflag post result
40716
41078
  *
40717
- * @param callback The function to call when the event was fired
40718
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41079
+ * @category Post API
41080
+ * @async
41081
+ * */
41082
+ const unflagPost = async (postId) => {
41083
+ const client = getActiveClient();
41084
+ client.log('post/unflagPost', postId);
41085
+ const { data: payload } = await client.http.delete(`/api/v3/posts/${encodeURIComponent(postId)}/unflag`);
41086
+ if (client.cache) {
41087
+ ingestInCache(prepareMembershipPayload(payload, 'communityUsers'));
41088
+ }
41089
+ fireEvent('post.unflagged', payload);
41090
+ return !!payload;
41091
+ };
41092
+ /* end_public_function */
41093
+
41094
+ /* begin_public_function
41095
+ id: post.check_flag_by_me
41096
+ */
41097
+ /**
41098
+ * ```js
41099
+ * import { PostRepository } from '@amityco/ts-sdk'
41100
+ * const isReported = await PostRepository.isPostFlaggedByMe('post', postId)
41101
+ * ```
40719
41102
  *
40720
- * @category Post Events
40721
- */
40722
- const onLocalPostReactionRemoved = (callback) => {
41103
+ * @param postId of the post to check if flagged by current user
41104
+ * @returns `true` if the post is flagged by me, `false` if doesn't.
41105
+ *
41106
+ * @category Post API
41107
+ * @async
41108
+ * */
41109
+ const isPostFlaggedByMe = async (postId) => {
40723
41110
  const client = getActiveClient();
40724
- const filter = ({ post }) => {
40725
- if (!client.cache) {
40726
- callback(post);
40727
- }
40728
- else {
40729
- upsertInCache(['post', 'get', post.postId], post);
40730
- callback(post);
40731
- }
40732
- };
40733
- return createEventSubscriber(client, 'local.post.removeReaction', 'local.post.removeReaction', filter);
41111
+ client.log('post/isPostFlaggedByMe', postId);
41112
+ const { data: { result }, } = await client.http.get(`/api/v3/posts/${postId}/isflagbyme`);
41113
+ return result;
40734
41114
  };
41115
+ /* end_public_function */
40735
41116
 
41117
+ /* begin_public_function
41118
+ id: post.create.clip_post
41119
+ */
40736
41120
  /**
40737
41121
  * ```js
40738
- * import { onLocalPostDeleted } from '@amityco/ts-sdk'
40739
- * const dispose = onLocalPostDeleted(post => {
40740
- * // ...
40741
- * })
41122
+ * import { PostRepository } from '@amityco/ts-sdk'
41123
+ * const created = await PostRepository.createClipPost({
41124
+ * targetType: 'user',
41125
+ * targetId: 'foobar',
41126
+ * dataType: 'clip',
41127
+ * data: { text: 'hello world' },
41128
+ * attachments: [{ type: 'clip', fileId: 'fileId123', displayMode: 'fill', isMuted: false }]
41129
+ * }))
40742
41130
  * ```
40743
41131
  *
40744
- * Fired when a {@link Amity.InternalPost} has been deleted
41132
+ * Creates an {@link Amity.Post}
40745
41133
  *
40746
- * @param callback The function to call when the event was fired
40747
- * @returns an {@link Amity.Unsubscriber} function to stop listening
41134
+ * @param bundle The data necessary to create a new {@link Amity.Post}
41135
+ * @returns The newly created {@link Amity.Post}
40748
41136
  *
40749
- * @category Post Events
41137
+ * @category Post API
41138
+ * @async
40750
41139
  */
40751
- const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.post.deleted', callback);
41140
+ const createClipPost = async (bundle) => {
41141
+ const client = getActiveClient();
41142
+ client.log('post/createPost', bundle);
41143
+ const { data: payload } = await client.http.post('/api/v4/posts', bundle);
41144
+ fireEvent('post.created', payload);
41145
+ const data = prepareMembershipPayload(payload, 'communityUsers');
41146
+ const cachedAt = client.cache && Date.now();
41147
+ if (client.cache)
41148
+ ingestInCache(data, { cachedAt });
41149
+ const { posts } = data;
41150
+ return {
41151
+ data: LinkedObject.post(posts[0]),
41152
+ cachedAt,
41153
+ };
41154
+ };
41155
+ /* end_public_function */
40752
41156
 
40753
41157
  /* begin_public_function
40754
41158
  id: post.get
@@ -40772,7 +41176,7 @@ const onLocalPostDeleted = (callback) => createLocalPostEventSubscriber('local.p
40772
41176
  *
40773
41177
  * @category Post Live Object
40774
41178
  */
40775
- const getPost$1 = (postId, callback) => {
41179
+ const getPost = (postId, callback) => {
40776
41180
  const responder = (snapshot) => {
40777
41181
  const { data } = snapshot;
40778
41182
  callback(Object.assign(Object.assign({}, snapshot), { data: data ? LinkedObject.post(snapshot.data) : data }));
@@ -40861,19 +41265,6 @@ class PostPaginationController extends PaginationController {
40861
41265
  }
40862
41266
  }
40863
41267
 
40864
- var EnumPostActions;
40865
- (function (EnumPostActions) {
40866
- EnumPostActions["OnPostCreated"] = "onPostCreated";
40867
- EnumPostActions["OnPostUpdated"] = "onPostUpdated";
40868
- EnumPostActions["OnPostDeleted"] = "onPostDeleted";
40869
- EnumPostActions["OnPostFlagged"] = "onPostFlagged";
40870
- EnumPostActions["OnPostUnflagged"] = "onPostUnflagged";
40871
- EnumPostActions["OnPostReactionAdded"] = "onPostReactionAdded";
40872
- EnumPostActions["OnPostReactionRemoved"] = "onPostReactionRemoved";
40873
- EnumPostActions["OnPostApproved"] = "onPostApproved";
40874
- EnumPostActions["OnPostDeclined"] = "onPostDeclined";
40875
- })(EnumPostActions || (EnumPostActions = {}));
40876
-
40877
41268
  class PostQueryStreamController extends QueryStreamController {
40878
41269
  constructor(query, cacheKey, notifyChange, preparePayload) {
40879
41270
  super(query, cacheKey);
@@ -40939,45 +41330,50 @@ class PostQueryStreamController extends QueryStreamController {
40939
41330
  }
40940
41331
  }
40941
41332
 
40942
- const getPost = async (postId) => {
40943
- const client = getActiveClient();
40944
- client.log('post/getPost', postId);
40945
- isInTombstone('post', postId);
40946
- let payload;
40947
- try {
40948
- // API-FIX: endpoint should not be /list, parameters should be querystring.
40949
- const response = await client.http.get(`/api/v3/posts/${encodeURIComponent(postId)}`);
40950
- payload = response.data;
40951
- }
40952
- catch (error) {
40953
- if (checkIfShouldGoesToTombstone(error === null || error === void 0 ? void 0 : error.code)) {
40954
- pushToTombstone('post', postId);
40955
- }
40956
- throw error;
40957
- }
40958
- const data = prepareMembershipPayload(payload, 'communityUsers');
40959
- const cachedAt = client.cache && Date.now();
40960
- if (client.cache)
40961
- ingestInCache(data, { cachedAt });
40962
- const { posts } = data;
40963
- const result = posts.find(post => post.postId === postId);
40964
- return {
40965
- data: result,
40966
- cachedAt,
40967
- };
41333
+ const commentEventHandler = (callback, eventHandler, cacheKey, resolveId) => {
41334
+ return eventHandler(async (comment) => {
41335
+ var _a;
41336
+ const currentCollection = (_a = pullFromCache(cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41337
+ if (!currentCollection ||
41338
+ !currentCollection.data.includes(resolveId ? resolveId(comment.referenceId) : comment.referenceId))
41339
+ return;
41340
+ await getPost$1(comment.referenceId);
41341
+ callback(comment);
41342
+ });
40968
41343
  };
40969
- getPost.locally = (postId) => {
40970
- const client = getActiveClient();
40971
- client.log('post/getPost.locally', postId);
40972
- if (!client.cache)
40973
- return;
40974
- const cached = pullFromCache(['post', 'get', postId]);
40975
- if (!cached)
40976
- return;
40977
- return {
40978
- data: cached.data,
40979
- cachedAt: cached.cachedAt,
40980
- };
41344
+ const generateCommentSubscriptions = ({ cacheKey, resolveId, }) => {
41345
+ const eventHandlers = [
41346
+ onCommentCreated,
41347
+ onCommentDeleted,
41348
+ onCommentReactionAdded,
41349
+ onCommentReactionRemoved,
41350
+ onCommentCreatedLocal,
41351
+ onCommentDeleteLocal,
41352
+ onLocalCommentReactionAdded,
41353
+ onLocalCommentReactionRemoved,
41354
+ ];
41355
+ return eventHandlers.map(handler => ({
41356
+ fn: convertEventPayload((callback) => commentEventHandler(callback, handler, cacheKey, resolveId), 'referenceId', 'post'),
41357
+ action: EnumPostActions.OnPostUpdated,
41358
+ }));
41359
+ };
41360
+ const getPostSubscription = (cacheKey) => {
41361
+ return [
41362
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
41363
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
41364
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
41365
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
41366
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
41367
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
41368
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
41369
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
41370
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41371
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41372
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41373
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41374
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
41375
+ ...generateCommentSubscriptions({ cacheKey }),
41376
+ ];
40981
41377
  };
40982
41378
 
40983
41379
  class PostLiveCollectionController extends LiveCollectionController {
@@ -41008,47 +41404,7 @@ class PostLiveCollectionController extends LiveCollectionController {
41008
41404
  this.queryStreamController.appendToQueryStream(response, direction, refresh);
41009
41405
  }
41010
41406
  startSubscription() {
41011
- return this.queryStreamController.subscribeRTE([
41012
- { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
41013
- { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
41014
- { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
41015
- { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
41016
- { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
41017
- { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
41018
- { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
41019
- { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
41020
- { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41021
- { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41022
- { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
41023
- { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
41024
- { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
41025
- {
41026
- fn: convertEventPayload((callback) => {
41027
- return onCommentCreated(async (comment) => {
41028
- var _a;
41029
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41030
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41031
- return;
41032
- await getPost(comment.referenceId);
41033
- callback(comment);
41034
- });
41035
- }, 'referenceId', 'post'),
41036
- action: EnumPostActions.OnPostUpdated,
41037
- },
41038
- {
41039
- fn: convertEventPayload((callback) => {
41040
- return onCommentDeleted(async (comment) => {
41041
- var _a;
41042
- const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41043
- if (!currentCollection || currentCollection.data.includes(comment.referenceId))
41044
- return;
41045
- await getPost(comment.referenceId);
41046
- callback(comment);
41047
- });
41048
- }, 'referenceId', 'post'),
41049
- action: EnumPostActions.OnPostUpdated,
41050
- },
41051
- ]);
41407
+ return this.queryStreamController.subscribeRTE(getPostSubscription(this.cacheKey));
41052
41408
  }
41053
41409
  notifyChange({ origin, loading, error }) {
41054
41410
  var _a, _b;
@@ -41183,6 +41539,22 @@ class PinnedPostQueryStreamController extends QueryStreamController {
41183
41539
  });
41184
41540
  }
41185
41541
  }
41542
+ reactor(action) {
41543
+ return (post) => {
41544
+ var _a;
41545
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
41546
+ if (!collection)
41547
+ return;
41548
+ if (action === EnumPostActions.OnPostDeleted) {
41549
+ collection.data = collection.data.filter(referenceId => referenceId !== `global#${post.postId}`);
41550
+ }
41551
+ pushToCache(this.cacheKey, collection);
41552
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
41553
+ };
41554
+ }
41555
+ subscribeRTE(createSubscriber) {
41556
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
41557
+ }
41186
41558
  }
41187
41559
 
41188
41560
  class PinnedPostLiveCollectionController extends LiveCollectionController {
@@ -41214,7 +41586,10 @@ class PinnedPostLiveCollectionController extends LiveCollectionController {
41214
41586
  }
41215
41587
  // eslint-disable-next-line class-methods-use-this
41216
41588
  startSubscription() {
41217
- return [];
41589
+ return this.queryStreamController.subscribeRTE(generateCommentSubscriptions({
41590
+ cacheKey: this.cacheKey,
41591
+ resolveId: id => `${this.query.placement}#${id}`,
41592
+ }));
41218
41593
  }
41219
41594
  notifyChange({ origin, loading, error }) {
41220
41595
  var _a, _b;
@@ -41366,6 +41741,10 @@ class GlobalPinnedPostLiveCollectionController extends LiveCollectionController
41366
41741
  fn: onPostDeleted,
41367
41742
  action: EnumPostActions.OnPostDeleted,
41368
41743
  },
41744
+ ...generateCommentSubscriptions({
41745
+ cacheKey: this.cacheKey,
41746
+ resolveId: id => `global#${id}`,
41747
+ }),
41369
41748
  ]);
41370
41749
  }
41371
41750
  notifyChange({ origin, loading, error }) {
@@ -41645,6 +42024,238 @@ const semanticSearchPosts = (params, callback, config) => {
41645
42024
  };
41646
42025
  };
41647
42026
 
42027
+ class SearchPostPaginationController extends PaginationController {
42028
+ async getRequest(queryParams, token) {
42029
+ const { limit = COLLECTION_DEFAULT_PAGINATION_LIMIT, matchingOnlyParentPost, hashtags, dataTypes, targetType = 'all' } = queryParams, params = __rest(queryParams, ["limit", "matchingOnlyParentPost", "hashtags", "dataTypes", "targetType"]);
42030
+ const baseOptions = {
42031
+ type: params.sortBy || queryParams.limit ? 'pagination' : undefined,
42032
+ };
42033
+ const options = token ? Object.assign(Object.assign({}, baseOptions), { token }) : Object.assign(Object.assign({}, baseOptions), { limit });
42034
+ const { data: queryResponse } = await this.http.get(`/api/v1/search/posts`, {
42035
+ params: Object.assign(Object.assign({}, params), { hashtags,
42036
+ dataTypes,
42037
+ targetType,
42038
+ /*
42039
+ * when creating post like image, file, video BE will create 2 posts
42040
+ * 1. parent post to store text with dataType=text
42041
+ * 2. child post to store dataTypes post data
42042
+ *
42043
+ * By default, BE queries only parent post
42044
+ */
42045
+ matchingOnlyParentPost: matchingOnlyParentPost !== null && matchingOnlyParentPost !== void 0 ? matchingOnlyParentPost : !(dataTypes === null || dataTypes === void 0 ? void 0 : dataTypes.length), options }),
42046
+ });
42047
+ return queryResponse;
42048
+ }
42049
+ }
42050
+
42051
+ class SearchPostQueryStreamController extends QueryStreamController {
42052
+ constructor(query, cacheKey, notifyChange, preparePayload) {
42053
+ super(query, cacheKey);
42054
+ this.notifyChange = notifyChange;
42055
+ this.preparePayload = preparePayload;
42056
+ }
42057
+ async saveToMainDB(response) {
42058
+ const processedPayload = await this.preparePayload(response);
42059
+ const client = getActiveClient();
42060
+ const cachedAt = client.cache && Date.now();
42061
+ if (client.cache) {
42062
+ ingestInCache(processedPayload, { cachedAt });
42063
+ }
42064
+ }
42065
+ appendToQueryStream(response, direction, refresh = false) {
42066
+ var _a, _b;
42067
+ if (refresh) {
42068
+ pushToCache(this.cacheKey, {
42069
+ data: response.posts.map(getResolver('post')),
42070
+ });
42071
+ }
42072
+ else {
42073
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42074
+ const posts = (_b = collection === null || collection === void 0 ? void 0 : collection.data) !== null && _b !== void 0 ? _b : [];
42075
+ pushToCache(this.cacheKey, Object.assign(Object.assign({}, collection), { data: [...new Set([...posts, ...response.posts.map(getResolver('post'))])] }));
42076
+ }
42077
+ }
42078
+ reactor(action) {
42079
+ return (post) => {
42080
+ var _a, _b;
42081
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42082
+ if (!collection)
42083
+ return;
42084
+ if (post.parentPostId && post.isDeleted) {
42085
+ const parentPost = (_b = pullFromCache([
42086
+ 'post',
42087
+ 'get',
42088
+ post.parentPostId,
42089
+ ])) === null || _b === void 0 ? void 0 : _b.data;
42090
+ if (!parentPost)
42091
+ return;
42092
+ parentPost.children = parentPost.children.filter(childId => childId !== post.postId);
42093
+ pushToCache(['post', 'get', parentPost.postId], parentPost);
42094
+ }
42095
+ if (action === EnumPostActions.OnPostDeclined) {
42096
+ collection.data = collection.data.filter(postId => postId !== post.postId);
42097
+ }
42098
+ if (action === EnumPostActions.OnPostCreated || action === EnumPostActions.OnPostApproved) {
42099
+ collection.data = [...new Set([post.postId, ...collection.data])];
42100
+ }
42101
+ pushToCache(this.cacheKey, collection);
42102
+ this.notifyChange({ origin: "event" /* Amity.LiveDataOrigin.EVENT */, loading: false });
42103
+ };
42104
+ }
42105
+ subscribeRTE(createSubscriber) {
42106
+ return createSubscriber.map(subscriber => subscriber.fn(this.reactor(subscriber.action)));
42107
+ }
42108
+ }
42109
+
42110
+ class SearchPostLiveCollectionController extends LiveCollectionController {
42111
+ constructor(query, callback) {
42112
+ const queryStreamId = hash(query);
42113
+ const cacheKey = ['posts', 'collection', queryStreamId];
42114
+ const paginationController = new SearchPostPaginationController(query);
42115
+ super(paginationController, queryStreamId, cacheKey, callback);
42116
+ this.query = query;
42117
+ this.queryStreamController = new SearchPostQueryStreamController(this.query, this.cacheKey, this.notifyChange.bind(this), preparePostPayload);
42118
+ this.callback = callback.bind(this);
42119
+ this.loadPage({ initial: true });
42120
+ }
42121
+ setup() {
42122
+ var _a;
42123
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42124
+ if (!collection) {
42125
+ pushToCache(this.cacheKey, {
42126
+ data: [],
42127
+ params: {},
42128
+ });
42129
+ }
42130
+ }
42131
+ async persistModel(queryPayload) {
42132
+ await this.queryStreamController.saveToMainDB(queryPayload);
42133
+ }
42134
+ persistQueryStream({ response, direction, refresh, }) {
42135
+ this.queryStreamController.appendToQueryStream(response, direction, refresh);
42136
+ }
42137
+ startSubscription() {
42138
+ return this.queryStreamController.subscribeRTE([
42139
+ { fn: onPostCreated, action: EnumPostActions.OnPostCreated },
42140
+ { fn: onPostUpdated, action: EnumPostActions.OnPostUpdated },
42141
+ { fn: onPostUpdatedLocal, action: EnumPostActions.OnPostUpdated },
42142
+ { fn: onPostDeleted, action: EnumPostActions.OnPostDeleted },
42143
+ { fn: onPostFlagged, action: EnumPostActions.OnPostFlagged },
42144
+ { fn: onPostUnflagged, action: EnumPostActions.OnPostUnflagged },
42145
+ { fn: onPostApproved, action: EnumPostActions.OnPostApproved },
42146
+ { fn: onPostDeclined, action: EnumPostActions.OnPostDeclined },
42147
+ { fn: onPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
42148
+ { fn: onPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
42149
+ { fn: onLocalPostReactionAdded, action: EnumPostActions.OnPostReactionAdded },
42150
+ { fn: onLocalPostReactionRemoved, action: EnumPostActions.OnPostReactionRemoved },
42151
+ { fn: onLocalPostDeleted, action: EnumPostActions.OnPostDeleted },
42152
+ {
42153
+ fn: convertEventPayload((callback) => {
42154
+ return onCommentCreated(async (comment) => {
42155
+ var _a;
42156
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42157
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
42158
+ return;
42159
+ await getPost$1(comment.referenceId);
42160
+ callback(comment);
42161
+ });
42162
+ }, 'referenceId', 'post'),
42163
+ action: EnumPostActions.OnPostUpdated,
42164
+ },
42165
+ {
42166
+ fn: convertEventPayload((callback) => {
42167
+ return onCommentDeleted(async (comment) => {
42168
+ var _a;
42169
+ const currentCollection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42170
+ if (!currentCollection || currentCollection.data.includes(comment.referenceId))
42171
+ return;
42172
+ await getPost$1(comment.referenceId);
42173
+ callback(comment);
42174
+ });
42175
+ }, 'referenceId', 'post'),
42176
+ action: EnumPostActions.OnPostUpdated,
42177
+ },
42178
+ ]);
42179
+ }
42180
+ notifyChange({ origin, loading, error }) {
42181
+ var _a, _b;
42182
+ const collection = (_a = pullFromCache(this.cacheKey)) === null || _a === void 0 ? void 0 : _a.data;
42183
+ if (!collection)
42184
+ return;
42185
+ const data = this.applyFilter((_b = collection.data
42186
+ .map(id => pullFromCache(['post', 'get', id]))
42187
+ .filter(isNonNullable)
42188
+ .map(({ data }) => data)) !== null && _b !== void 0 ? _b : []).map(LinkedObject.post);
42189
+ if (!this.shouldNotify(data) && origin === 'event')
42190
+ return;
42191
+ this.callback({
42192
+ onNextPage: () => this.loadPage({ direction: "next" /* Amity.LiveCollectionPageDirection.NEXT */ }),
42193
+ data,
42194
+ hasNextPage: !!this.paginationController.getNextToken(),
42195
+ loading,
42196
+ error,
42197
+ });
42198
+ }
42199
+ applyFilter(data) {
42200
+ var _a;
42201
+ let posts = data;
42202
+ if ((_a = this.query.dataTypes) === null || _a === void 0 ? void 0 : _a.length) {
42203
+ posts = filterByPostDataTypes(posts, this.query.dataTypes);
42204
+ }
42205
+ switch (this.query.sortBy) {
42206
+ case 'firstCreated':
42207
+ posts = posts.sort(sortByFirstCreated);
42208
+ break;
42209
+ case 'lastCreated':
42210
+ default:
42211
+ posts = posts.sort(sortByLastCreated);
42212
+ break;
42213
+ }
42214
+ return posts;
42215
+ }
42216
+ }
42217
+
42218
+ /* begin_public_function
42219
+ id: post.query
42220
+ */
42221
+ /**
42222
+ * ```js
42223
+ * import { PostRepository } from '@amityco/ts-sdk'
42224
+ *
42225
+ * let posts = []
42226
+ * const unsub = PostRepository.searchPostsByHashtag({
42227
+ * hashtags: ['amity'],
42228
+ * limit: 10,
42229
+ * }, response => merge(posts, response.data))
42230
+ * ```
42231
+ *
42232
+ * Observe all mutations on a list of {@link Amity.Post} for a given target object
42233
+ *
42234
+ * @param params.hashtags the hashtags to search for
42235
+ * @param callback the function to call when new data are available
42236
+ * @param config
42237
+ * @returns An {@link Amity.Unsubscriber} function to run when willing to stop observing the messages
42238
+ *
42239
+ * @category Posts Live Collection
42240
+ */
42241
+ const searchPostsByHashtag = (params, callback, config) => {
42242
+ const { log, cache } = getActiveClient();
42243
+ if (!cache) {
42244
+ console.log(ENABLE_CACHE_MESSAGE);
42245
+ }
42246
+ const timestamp = Date.now();
42247
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > listen`);
42248
+ const postsLiveCollection = new SearchPostLiveCollectionController(params, callback);
42249
+ const disposers = postsLiveCollection.startSubscription();
42250
+ const cacheKey = postsLiveCollection.getCacheKey();
42251
+ disposers.push(() => dropFromCache(cacheKey));
42252
+ return () => {
42253
+ log(`searchPostsByHashtag(tmpid: ${timestamp}) > dispose`);
42254
+ disposers.forEach(fn => fn());
42255
+ };
42256
+ };
42257
+ /* end_public_function */
42258
+
41648
42259
  var index$8 = /*#__PURE__*/Object.freeze({
41649
42260
  __proto__: null,
41650
42261
  getPostByIds: getPostByIds,
@@ -41668,11 +42279,12 @@ var index$8 = /*#__PURE__*/Object.freeze({
41668
42279
  onPostUnflagged: onPostUnflagged,
41669
42280
  onPostReactionAdded: onPostReactionAdded,
41670
42281
  onPostReactionRemoved: onPostReactionRemoved,
41671
- getPost: getPost$1,
42282
+ getPost: getPost,
41672
42283
  getPosts: getPosts,
41673
42284
  getPinnedPosts: getPinnedPosts,
41674
42285
  getGlobalPinnedPosts: getGlobalPinnedPosts,
41675
- semanticSearchPosts: semanticSearchPosts
42286
+ semanticSearchPosts: semanticSearchPosts,
42287
+ searchPostsByHashtag: searchPostsByHashtag
41676
42288
  });
41677
42289
 
41678
42290
  /* begin_public_function
@@ -42551,7 +43163,7 @@ var index$6 = /*#__PURE__*/Object.freeze({
42551
43163
  getPoll: getPoll
42552
43164
  });
42553
43165
 
42554
- const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvQIBADANBgkqhkiG9w0BAQEFAASCBKcwggSjAgEAAoIBAQDHo80SecH7FuF2\nhFYnb+l26/VN8UMLXAQFLnxciNTEwkGVFMpdezlH8rU2HtUJL4RETogbAOLVY0XM\njs6sPn8G1nALmh9qeDpUtVqFOVtBHxEZ910TLOtQiunjqJKO5nWdqZ71EC3OFluR\niGQkO84BiIFbv37ub7xl3S8XarbtKoLcyVpkDHi+1wx1pgCAn6gtBUgckPL5NR8j\nLseabl3HAXQfhTCKo4tmOFM2Dxwl1IUMmIJrJg/aIU/U0tj/1Eoo7mG0JcNWX19l\nW3EecCbi0ncCJOrkUdwlBrcjaMayaX/ubEwyUeTGiLdyc4L3GRLHjyK8xgVNXRMH\nbZWJ2a5NAgMBAAECggEASxuE+35zTFO/XydKgmvIGcWL9FbgMlXb7Vcf0nBoG945\nbiz0NVc2paraIhJXc608xbYF3qLmtAE1MVBI0ORyRdBHNxY024l/6H6SH60Ed+uI\nM4ysp5ourY6Vj+DLwpdRiI9YDjqYAQDIUmhNxJP7XPhOMoZI6st+xZQBM34ic/bv\nAMSJm9OZphSp3+qXVkFZztr2mxD2EZSJJLYxi8BCdgM2qhazalbcJ6zDKHCZWVWm\n8RRxDGldyMb/237JxETzP40tAlzOZDmBAbUgEnurDJ93RVDIE3rbZUshwgeQd18a\nem096mWgvB1AIKYgsTAR3pw+V19YWAjq/glP6fz8wQKBgQD/oQq+ukKF0PRgBeM5\ngeTjSwsdGppQLmf5ndujvoiz/TpdjDEPu6R8kigQr1rG2t4K/yfdZoI8RdmJD1al\n3Q7N9hofooSy4rj6E3txzWZCHJjHad2cnCp/O26HiReGAl7wTcfTmNdiFHhZQzm5\nJBkvWAiwuvQMNfEbnXxw6/vIDwKBgQDH7fX8gsc77JLvAWgp1MaQN/sbqVb6JeT1\nFQfR8E/WFCSmzQBtNzd5KgYuCeelwr/8DyYytvN2BzCYZXp73gI1jF3YlW5jVn74\nOY6TwQ095digwo6Z0yuxopdIOApKgAkL9PRKgNrqAf3NAyMua6lOGifzjDojC3KU\nfylQmxMn4wKBgHp2B9O/H0dEBw5JQ8W0+JX6yWQz7mEjGiR2/1W+XXb8hQ1zr709\nw1r6Gb+EghRpnZ3fBpYGGbYOMFx8wKHM+N6qW3F0ReX8v2juFGE8aRSa5oYBrWzt\nU16Idjbv8hj84cZ1PJmdyvDtpYn9rpWHOZl4rxEbPvbqkIsOMyNVqdT5AoGAOSge\nmwIIU2le2FVeohbibXiToWTYKMuMmURZ5/r72AgKMmWJKbAPe+Q3wBG01/7FRBpQ\noU8Ma0HC8s6QJbliiEyIx9JwrJWd1vkdecBHONrtA4ibm/5zD2WcOllLF+FitLhi\n3qnX6+6F0IaFGFBPJrTzlv0P4dTz/OAdv52V7GECgYEA2TttOKBAqWllgOaZOkql\nLVMJVmgR7s6tLi1+cEP8ZcapV9aRbRzTAKXm4f8AEhtlG9F9kCOvHYCYGi6JaiWJ\nZkHjeex3T+eE6Di6y5Bm/Ift5jtVhJ4jCVwHOKTMej79NPUFTJfv8hCo29haBDv6\nRXFrv+T21KCcw8k3sJeJWWQ=\n-----END PRIVATE KEY-----";
43166
+ const privateKey = "-----BEGIN PRIVATE KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQDAARz+hmBgi8pJ\nQb8LeY41gtHhk+ACMwRfhsn7GqpqRQNG2qU0755mzZuVDUqjQMGSo8THJB7O+OJs\nflbZRkFXlFoFOVNw1UpNOgwEQZ6wB9oRwzepTJAfF1sVhm/o/ixvXh1zDFNDy6yZ\npXyiiJHUVxqyjllZhxnwdvjoVtDs6hW6awG09bB9nh/TTejlUKXoAgzqVwu/1QMu\nUVViET495elEe19aUarEy+oL2iKeXCEvqda/pWNBdbieFyJvvZ08HN8dPuT88wq2\njZLEAth1vrwQ2IAa4ktaLcBQdLJgIkrbDvAiVZ8lQAjS/bq5vXQikTGvoPlC5bbn\nvuOM/3eLAgMBAAECggEAVZ+peHAghq2QVj71nX5lxsNCKaCyYwixSJBpfouTt7Rz\nE6PpzMOXFi1W1o+I22jDakuSM2SOQKqI/u0QefB0r0O/KVk5NrZHXk0mkrdYtxOp\nUgaGyf8UvmjB+8VqHrNKyZdk9qtmbnNj01kTTcAtmE4H39zPR7eR/8Rul94vaZbs\nwCnKJS3mLT3JxyGug6lxanveKkjG+CKC1nJQYWaxCJxaFSzbwXQPvDhB+TvrIbee\npd5v4EAyEJohpr+T9oDGGJkb/KARBZCtwLyB976PKJwwBA8MRVL1i5QwawuMiMq5\nUtnOnbGKtCeFzaLbNU0Qi8bqyims84EQxC6DOu1fkQKBgQDdvsoBsEhsOXV7hlIJ\naEd0eSJZVkdqimxH8uGoMM2FeNaOrcB6yBXqTSP0R3OIyf8eaY6yjRvP30ZNXcll\n/gD3O1Mu6YmWQdt1W2WA6pKOsUuPXasf0pdOF7IiFZKlSabz5YHXFqwVuqm8loaj\nsXel3YWqPVdHiankE7tz+3ssnQKBgQDdqi4TNdD1MdEpihx19jr0QjUiXW3939FK\nqp30HESPEGDGQzXdmJgif9HhZb+cJSuWaHEbjgBrYahvgCF+y6LbEpOD+D/dmT+s\nDEAQaR84sah6dokwPjV8fjBSrcVFjCS+doxv0d3p/9OUEeyUhFrY03nxtIEYkLIE\n/Zvn37b4RwKBgQCLENVFe9XfsaVhQ5r9dV2iyTlmh7qgMZG5CbTFs12hQGhm8McO\n+Z7s41YSJCFr/yq1WwP4LJDtrBw99vyQr1zRsG35tNLp3gGRNzGQSQyC2uQFVHw2\np+7mNewsfhUK/gbrXNsyFnDz6635rPlhfbII3sWuP2wWXFqkxE9CbMwR7QKBgQC6\nawDMzxmo2/iYArrkyevSuEuPVxvFwpF1RgAI6C0QVCnPE38dmdN4UB7mfHekje4W\nVEercMURidPp0cxZolCYBQtilUjAyL0vqC3In1/Ogjq6oy3FEMxSop1pKxMY5j+Q\nnoqFD+6deLUrddeNH7J3X4LSr4dSbX4JjG+tlgt+yQKBgQCuwTL4hA6KqeInQ0Ta\n9VQX5Qr8hFlqJz1gpymi/k63tW/Ob8yedbg3WWNWyShwRMFYyY9S81ITFWM95uL6\nvF3x9rmRjwElJw9PMwVu6dmf/CO0Z1wzXSp2VVD12gbrUD/0/d7MUoJ9LgC8X8f/\nn0txLHYGHbx+nf95+JUg6lV3hg==\n-----END PRIVATE KEY-----";
42555
43167
  /*
42556
43168
  * The crypto algorithm used for importing key and signing string
42557
43169
  */
@@ -44866,4 +45478,4 @@ var index = /*#__PURE__*/Object.freeze({
44866
45478
  getReactions: getReactions
44867
45479
  });
44868
45480
 
44869
- 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 };
45481
+ export { API_REGIONS, index$3 as AdRepository, index$b as CategoryRepository, index$f as ChannelRepository, index$o as Client, index$a as CommentRepository, CommunityPostSettingMaps, CommunityPostSettings, index$c as CommunityRepository, ContentFeedType, ContentFlagReasonEnum, DefaultCommunityPostSetting, index$9 as FeedRepository, FileAccessTypeEnum, index$l as FileRepository, FileType, index$1 as InvitationRepository, InvitationSortByEnum, InvitationStatusEnum, InvitationTypeEnum, JoinRequestStatusEnum, JoinResultStatusEnum, index as LiveReactionRepository, index$5 as LiveStreamPlayer, MembershipAcceptanceTypeEnum, MessageContentType, index$j as MessageRepository, index$6 as PollRepository, PostContentType, index$8 as PostRepository, index$k as ReactionRepository, index$4 as StoryRepository, index$7 as StreamRepository, index$i as SubChannelRepository, SubscriptionLevels, index$m as UserRepository, VERSION, VideoResolution, VideoSize, VideoTranscodingStatus, backupCache, createQuery, createReport, createUserToken, deleteReport, disableCache, dropFromCache, enableCache, filterByChannelMembership, filterByCommunityMembership, filterByFeedType, filterByPostDataTypes, filterByPropEquality, filterByPropInclusion, filterByPropIntersection, filterBySearchTerm, filterByStringComparePartially, getChannelTopic, getCommentTopic, getCommunityStoriesTopic, getCommunityTopic, getLiveReactionTopic, getLiveStreamTopic, getMarkedMessageTopic, getMarkerUserFeedTopic, getMessageTopic, getMyFollowersTopic, getMyFollowingsTopic, getNetworkTopic, getPostTopic, getRole, getSmartFeedChannelTopic, getSmartFeedMessageTopic, getSmartFeedSubChannelTopic, getStoryTopic, getSubChannelTopic, getUserTopic, isAfterBefore, isAfterBeforeRaw, isCachable, isFetcher, isFresh, isLocal, isMutator, isOffline, isPaged, isReportedByMe, isSkip, mergeInCache, index$2 as notificationTray, onChannelMarkerFetched, onFeedMarkerFetched, onFeedMarkerUpdated, onMessageMarked, onMessageMarkerFetched, onSubChannelMarkerFetched, onSubChannelMarkerUpdated, onUserMarkerFetched, onUserMarkerFetchedLegacy, pullFromCache, pushToCache, queryCache, queryOptions, queryRoles, restoreCache, runQuery, sortByChannelSegment, sortByDisplayName, sortByFirstCreated, sortByFirstUpdated, sortByLastActivity, sortByLastCreated, sortByLastUpdated, sortByLocalSortingDate, sortByName, sortBySegmentNumber, subscribeTopic, toPage, toPageRaw, toToken, upsertInCache, wipeCache };