@amityco/ts-sdk 7.7.1-1cf499d.0 → 7.7.1-68d81647.0

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